Imported File#ftype spec from rubyspecs.
[rbx.git] / shotgun / external_libs / libffi / testsuite / libffi.call / ffitest.h
blobe73f758f586883329b7bfa07cffe6c4c0732cdba
1 #include <stdlib.h>
2 #include <stdio.h>
3 #include <string.h>
4 #include <fcntl.h>
5 #include <ffi.h>
6 #include "fficonfig.h"
8 #define MAX_ARGS 256
10 #define CHECK(x) !(x) ? abort() : 0
12 /* Define __UNUSED__ that also other compilers than gcc can run the tests. */
13 #undef __UNUSED__
14 #if defined(__GNUC__)
15 #define __UNUSED__ __attribute__((__unused__))
16 #else
17 #define __UNUSED__
18 #endif
20 /* Prefer MAP_ANON(YMOUS) to /dev/zero, since we don't need to keep a
21 file open. */
22 #ifdef HAVE_MMAP_ANON
23 # undef HAVE_MMAP_DEV_ZERO
25 # include <sys/mman.h>
26 # ifndef MAP_FAILED
27 # define MAP_FAILED -1
28 # endif
29 # if !defined (MAP_ANONYMOUS) && defined (MAP_ANON)
30 # define MAP_ANONYMOUS MAP_ANON
31 # endif
32 # define USING_MMAP
34 #endif
36 #ifdef HAVE_MMAP_DEV_ZERO
38 # include <sys/mman.h>
39 # ifndef MAP_FAILED
40 # define MAP_FAILED -1
41 # endif
42 # define USING_MMAP
44 #endif
46 #ifdef USING_MMAP
47 static inline void *
48 allocate_mmap (size_t size)
50 void *page;
51 #if defined (HAVE_MMAP_DEV_ZERO)
52 static int dev_zero_fd = -1;
53 #endif
55 #ifdef HAVE_MMAP_DEV_ZERO
56 if (dev_zero_fd == -1)
58 dev_zero_fd = open ("/dev/zero", O_RDONLY);
59 if (dev_zero_fd == -1)
61 perror ("open /dev/zero: %m");
62 exit (1);
65 #endif
68 #ifdef HAVE_MMAP_ANON
69 page = mmap (NULL, size, PROT_READ | PROT_WRITE | PROT_EXEC,
70 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
71 #endif
72 #ifdef HAVE_MMAP_DEV_ZERO
73 page = mmap (NULL, size, PROT_READ | PROT_WRITE | PROT_EXEC,
74 MAP_PRIVATE, dev_zero_fd, 0);
75 #endif
77 if (page == (void *) MAP_FAILED)
79 perror ("virtual memory exhausted");
80 exit (1);
83 return page;
86 #endif