]> git.ipfire.org Git - thirdparty/gcc.git/blame - libffi/testsuite/libffi.call/ffitest.h
ffitest.h [__sgi] (PRId64, PRIu64): Define.
[thirdparty/gcc.git] / libffi / testsuite / libffi.call / ffitest.h
CommitLineData
8a6b509e
AT
1#include <stdlib.h>
2#include <stdio.h>
3#include <string.h>
88096b2a 4#include <fcntl.h>
8a6b509e 5#include <ffi.h>
5196736e 6#include "fficonfig.h"
8a6b509e 7
d7e9538e
AT
8#if defined HAVE_STDINT_H
9#include <stdint.h>
10#endif
11
12#if defined HAVE_INTTYPES_H
13#include <inttypes.h>
14#endif
15
8a6b509e
AT
16#define MAX_ARGS 256
17
5196736e 18#define CHECK(x) !(x) ? abort() : 0
8a6b509e 19
9fdeb13b
AT
20/* Define __UNUSED__ that also other compilers than gcc can run the tests. */
21#undef __UNUSED__
22#if defined(__GNUC__)
23#define __UNUSED__ __attribute__((__unused__))
24#else
25#define __UNUSED__
26#endif
27
5196736e
AJ
28/* Prefer MAP_ANON(YMOUS) to /dev/zero, since we don't need to keep a
29 file open. */
30#ifdef HAVE_MMAP_ANON
31# undef HAVE_MMAP_DEV_ZERO
32
33# include <sys/mman.h>
34# ifndef MAP_FAILED
35# define MAP_FAILED -1
36# endif
37# if !defined (MAP_ANONYMOUS) && defined (MAP_ANON)
38# define MAP_ANONYMOUS MAP_ANON
39# endif
40# define USING_MMAP
41
42#endif
43
44#ifdef HAVE_MMAP_DEV_ZERO
45
46# include <sys/mman.h>
47# ifndef MAP_FAILED
48# define MAP_FAILED -1
49# endif
50# define USING_MMAP
51
52#endif
53
3bc462c2 54/* MinGW kludge. */
a761df3d
AG
55#ifdef _WIN64
56#define PRIdLL "I64d"
57#define PRIuLL "I64u"
3bc462c2
AH
58#else
59#define PRIdLL "lld"
60#define PRIuLL "llu"
61#endif
62
ec168029
RO
63/* Tru64 UNIX kludge. */
64#if defined(__alpha__) && defined(__osf__)
65/* Tru64 UNIX V4.0 doesn't support %lld/%lld, but long is 64-bit. */
66#undef PRIdLL
67#define PRIdLL "ld"
68#undef PRIuLL
69#define PRIuLL "lu"
70#define PRId64 "ld"
71#define PRIu64 "lu"
72#define PRIuPTR "lu"
73#endif
74
2516c7cd
JDA
75/* PA HP-UX kludge. */
76#if defined(__hppa__) && defined(__hpux__) && !defined(PRIuPTR)
77#define PRIuPTR "lu"
78#endif
79
ce9315a9
RO
80/* IRIX kludge. */
81#if defined(__sgi)
82/* IRIX 6.5 <inttypes.h> provides all definitions, but only for C99
83 compilations. */
84#if (_MIPS_SZLONG == 32)
85#define PRId64 "lld"
86#define PRIu64 "llu"
87#endif
88/* This doesn't match <inttypes.h>, which always has "lld" here, but the
89 arguments are uint64_t, int64_t, which are unsigned long, long for
90 64-bit in <sgidefs.h>. */
91#if (_MIPS_SZLONG == 64)
92#define PRId64 "ld"
93#define PRIu64 "lu"
94#endif
95/* This doesn't match <inttypes.h>, which has "u" here, but the arguments
96 are uintptr_t, which is always unsigned long. */
97#define PRIuPTR "lu"
98#endif
99
2ea54b81
EB
100/* Solaris < 10 kludge. */
101#if defined(__sun__) && defined(__svr4__) && !defined(PRIuPTR)
102#if defined(__arch64__) || defined (__x86_64__)
103#define PRIuPTR "lu"
104#else
105#define PRIuPTR "u"
106#endif
107#endif
108
5196736e
AJ
109#ifdef USING_MMAP
110static inline void *
111allocate_mmap (size_t size)
112{
113 void *page;
114#if defined (HAVE_MMAP_DEV_ZERO)
115 static int dev_zero_fd = -1;
116#endif
117
118#ifdef HAVE_MMAP_DEV_ZERO
119 if (dev_zero_fd == -1)
120 {
121 dev_zero_fd = open ("/dev/zero", O_RDONLY);
122 if (dev_zero_fd == -1)
123 {
124 perror ("open /dev/zero: %m");
125 exit (1);
126 }
127 }
128#endif
129
130
131#ifdef HAVE_MMAP_ANON
132 page = mmap (NULL, size, PROT_READ | PROT_WRITE | PROT_EXEC,
133 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
134#endif
135#ifdef HAVE_MMAP_DEV_ZERO
136 page = mmap (NULL, size, PROT_READ | PROT_WRITE | PROT_EXEC,
137 MAP_PRIVATE, dev_zero_fd, 0);
138#endif
139
2e89756b 140 if (page == (void *) MAP_FAILED)
5196736e
AJ
141 {
142 perror ("virtual memory exhausted");
143 exit (1);
144 }
145
146 return page;
147}
148
149#endif