~ubuntu-branches/ubuntu/vivid/mozjs24/vivid

« back to all changes in this revision

Viewing changes to js/src/ctypes/libffi/testsuite/libffi.call/ffitest.h

  • Committer: Package Import Robot
  • Author(s): Tim Lunn
  • Date: 2014-02-11 21:55:34 UTC
  • Revision ID: package-import@ubuntu.com-20140211215534-m1zyq5aj59md3y07
Tags: upstream-24.2.0
ImportĀ upstreamĀ versionĀ 24.2.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#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 PRId64 "ld"
 
71
#define PRIu64 "lu"
 
72
#define PRIuPTR "lu"
 
73
#endif
 
74
 
 
75
/* PA HP-UX kludge.  */
 
76
#if defined(__hppa__) && defined(__hpux__) && !defined(PRIuPTR)
 
77
#define PRIuPTR "lu"
 
78
#endif
 
79
 
 
80
/* Solaris < 10 kludge.  */
 
81
#if defined(__sun__) && defined(__svr4__) && !defined(PRIuPTR)
 
82
#if defined(__arch64__) || defined (__x86_64__)
 
83
#define PRIuPTR "lu"
 
84
#else
 
85
#define PRIuPTR "u"
 
86
#endif
 
87
#endif
 
88
 
 
89
#ifdef USING_MMAP
 
90
static inline void *
 
91
allocate_mmap (size_t size)
 
92
{
 
93
  void *page;
 
94
#if defined (HAVE_MMAP_DEV_ZERO)
 
95
  static int dev_zero_fd = -1;
 
96
#endif
 
97
 
 
98
#ifdef HAVE_MMAP_DEV_ZERO
 
99
  if (dev_zero_fd == -1)
 
100
    {
 
101
      dev_zero_fd = open ("/dev/zero", O_RDONLY);
 
102
      if (dev_zero_fd == -1)
 
103
        {
 
104
          perror ("open /dev/zero: %m");
 
105
          exit (1);
 
106
        }
 
107
    }
 
108
#endif
 
109
 
 
110
 
 
111
#ifdef HAVE_MMAP_ANON
 
112
  page = mmap (NULL, size, PROT_READ | PROT_WRITE | PROT_EXEC,
 
113
               MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
 
114
#endif
 
115
#ifdef HAVE_MMAP_DEV_ZERO
 
116
  page = mmap (NULL, size, PROT_READ | PROT_WRITE | PROT_EXEC,
 
117
               MAP_PRIVATE, dev_zero_fd, 0);
 
118
#endif
 
119
 
 
120
  if (page == (void *) MAP_FAILED)
 
121
    {
 
122
      perror ("virtual memory exhausted");
 
123
      exit (1);
 
124
    }
 
125
 
 
126
  return page;
 
127
}
 
128
 
 
129
#endif