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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libffi/] [testsuite/] [libffi.special/] [ffitestcxx.h] - Blame information for rev 801

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 <fcntl.h>
4
#include <ffi.h>
5
#include "fficonfig.h"
6
 
7
#define MAX_ARGS 256
8
 
9
 
10
/* Define __UNUSED__ that also other compilers than gcc can run the tests.  */
11
#undef __UNUSED__
12
#if defined(__GNUC__)
13
#define __UNUSED__ __attribute__((__unused__))
14
#else
15
#define __UNUSED__
16
#endif
17
 
18
#define CHECK(x) (!(x) ? abort() : (void)0)
19
 
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
24
 
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
33
 
34
#endif
35
 
36
#ifdef HAVE_MMAP_DEV_ZERO
37
 
38
# include <sys/mman.h>
39
# ifndef MAP_FAILED
40
#  define MAP_FAILED -1
41
# endif
42
# define USING_MMAP
43
 
44
#endif
45
 
46
 
47
/* MinGW kludge.  */
48
#ifdef _WIN64
49
#define PRIdLL "I64d"
50
#define PRIuLL "I64u"
51
#else
52
#define PRIdLL "lld"
53
#define PRIuLL "llu"
54
#endif
55
 
56
#ifdef USING_MMAP
57
static inline void *
58
allocate_mmap (size_t size)
59
{
60
  void *page;
61
#if defined (HAVE_MMAP_DEV_ZERO)
62
  static int dev_zero_fd = -1;
63
#endif
64
 
65
#ifdef HAVE_MMAP_DEV_ZERO
66
  if (dev_zero_fd == -1)
67
    {
68
      dev_zero_fd = open ("/dev/zero", O_RDONLY);
69
      if (dev_zero_fd == -1)
70
        {
71
          perror ("open /dev/zero: %m");
72
          exit (1);
73
        }
74
    }
75
#endif
76
 
77
 
78
#ifdef HAVE_MMAP_ANON
79
  page = mmap (NULL, size, PROT_READ | PROT_WRITE | PROT_EXEC,
80
               MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
81
#endif
82
#ifdef HAVE_MMAP_DEV_ZERO
83
  page = mmap (NULL, size, PROT_READ | PROT_WRITE | PROT_EXEC,
84
               MAP_PRIVATE, dev_zero_fd, 0);
85
#endif
86
 
87
  if (page == (char *) MAP_FAILED)
88
    {
89
      perror ("virtual memory exhausted");
90
      exit (1);
91
    }
92
 
93
  return page;
94
}
95
 
96
#endif

powered by: WebSVN 2.1.0

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