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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libffi/] [testsuite/] [libffi.call/] [ffitest.h] - Blame information for rev 751

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

Line No. Rev Author Line
1 732 jeremybenn
#include <stdlib.h>
2
#include <stdio.h>
3
#include <string.h>
4
#include <fcntl.h>
5
#include <ffi.h>
6
#include "fficonfig.h"
7
 
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
 
16
#define MAX_ARGS 256
17
 
18
#define CHECK(x) !(x) ? abort() : 0
19
 
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
 
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
 
54
/* MinGW kludge.  */
55
#ifdef _WIN64
56
#define PRIdLL "I64d"
57
#define PRIuLL "I64u"
58
#else
59
#define PRIdLL "lld"
60
#define PRIuLL "llu"
61
#endif
62
 
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 PRId8 "hd"
71
#define PRIu8 "hu"
72
#define PRId64 "ld"
73
#define PRIu64 "lu"
74
#define PRIuPTR "lu"
75
#endif
76
 
77
/* PA HP-UX kludge.  */
78
#if defined(__hppa__) && defined(__hpux__) && !defined(PRIuPTR)
79
#define PRIuPTR "lu"
80
#endif
81
 
82
/* IRIX kludge.  */
83
#if defined(__sgi)
84
/* IRIX 6.5 <inttypes.h> provides all definitions, but only for C99
85
   compilations.  */
86
#define PRId8 "hhd"
87
#define PRIu8 "hhu"
88
#if (_MIPS_SZLONG == 32)
89
#define PRId64 "lld"
90
#define PRIu64 "llu"
91
#endif
92
/* This doesn't match <inttypes.h>, which always has "lld" here, but the
93
   arguments are uint64_t, int64_t, which are unsigned long, long for
94
   64-bit in <sgidefs.h>.  */
95
#if (_MIPS_SZLONG == 64)
96
#define PRId64 "ld"
97
#define PRIu64 "lu"
98
#endif
99
/* This doesn't match <inttypes.h>, which has "u" here, but the arguments
100
   are uintptr_t, which is always unsigned long.  */
101
#define PRIuPTR "lu"
102
#endif
103
 
104
/* Solaris < 10 kludge.  */
105
#if defined(__sun__) && defined(__svr4__) && !defined(PRIuPTR)
106
#if defined(__arch64__) || defined (__x86_64__)
107
#define PRIuPTR "lu"
108
#else
109
#define PRIuPTR "u"
110
#endif
111
#endif
112
 
113
#ifdef USING_MMAP
114
static inline void *
115
allocate_mmap (size_t size)
116
{
117
  void *page;
118
#if defined (HAVE_MMAP_DEV_ZERO)
119
  static int dev_zero_fd = -1;
120
#endif
121
 
122
#ifdef HAVE_MMAP_DEV_ZERO
123
  if (dev_zero_fd == -1)
124
    {
125
      dev_zero_fd = open ("/dev/zero", O_RDONLY);
126
      if (dev_zero_fd == -1)
127
        {
128
          perror ("open /dev/zero: %m");
129
          exit (1);
130
        }
131
    }
132
#endif
133
 
134
 
135
#ifdef HAVE_MMAP_ANON
136
  page = mmap (NULL, size, PROT_READ | PROT_WRITE | PROT_EXEC,
137
               MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
138
#endif
139
#ifdef HAVE_MMAP_DEV_ZERO
140
  page = mmap (NULL, size, PROT_READ | PROT_WRITE | PROT_EXEC,
141
               MAP_PRIVATE, dev_zero_fd, 0);
142
#endif
143
 
144
  if (page == (void *) MAP_FAILED)
145
    {
146
      perror ("virtual memory exhausted");
147
      exit (1);
148
    }
149
 
150
  return page;
151
}
152
 
153
#endif

powered by: WebSVN 2.1.0

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