OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gcc/] [gcc-4.1.1/] [libffi/] [testsuite/] [libffi.special/] [ffitestcxx.h] - Blame information for rev 22

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 14 jlechner
#include <stdlib.h>
2
#include <stdio.h>
3
#include <fcntl.h>
4
#include <ffi.h>
5
#include "fficonfig.h"
6
 
7
#define MAX_ARGS 256
8
 
9
#define CHECK(x) (!(x) ? abort() : (void)0)
10
 
11
/* Prefer MAP_ANON(YMOUS) to /dev/zero, since we don't need to keep a
12
   file open.  */
13
#ifdef HAVE_MMAP_ANON
14
# undef HAVE_MMAP_DEV_ZERO
15
 
16
# include <sys/mman.h>
17
# ifndef MAP_FAILED
18
#  define MAP_FAILED -1
19
# endif
20
# if !defined (MAP_ANONYMOUS) && defined (MAP_ANON)
21
#  define MAP_ANONYMOUS MAP_ANON
22
# endif
23
# define USING_MMAP
24
 
25
#endif
26
 
27
#ifdef HAVE_MMAP_DEV_ZERO
28
 
29
# include <sys/mman.h>
30
# ifndef MAP_FAILED
31
#  define MAP_FAILED -1
32
# endif
33
# define USING_MMAP
34
 
35
#endif
36
 
37
#ifdef USING_MMAP
38
static inline void *
39
allocate_mmap (size_t size)
40
{
41
  void *page;
42
#if defined (HAVE_MMAP_DEV_ZERO)
43
  static int dev_zero_fd = -1;
44
#endif
45
 
46
#ifdef HAVE_MMAP_DEV_ZERO
47
  if (dev_zero_fd == -1)
48
    {
49
      dev_zero_fd = open ("/dev/zero", O_RDONLY);
50
      if (dev_zero_fd == -1)
51
        {
52
          perror ("open /dev/zero: %m");
53
          exit (1);
54
        }
55
    }
56
#endif
57
 
58
 
59
#ifdef HAVE_MMAP_ANON
60
  page = mmap (NULL, size, PROT_READ | PROT_WRITE | PROT_EXEC,
61
               MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
62
#endif
63
#ifdef HAVE_MMAP_DEV_ZERO
64
  page = mmap (NULL, size, PROT_READ | PROT_WRITE | PROT_EXEC,
65
               MAP_PRIVATE, dev_zero_fd, 0);
66
#endif
67
 
68
  if (page == MAP_FAILED)
69
    {
70
      perror ("virtual memory exhausted");
71
      exit (1);
72
    }
73
 
74
  return page;
75
}
76
 
77
#endif

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.