Sha256: 880cd3b96bd46776a5272b0e8f08cdfc87917c51eded14f19a93d7f18577d1c5

Contents?: true

Size: 1.57 KB

Versions: 26

Compression:

Stored size: 1.57 KB

Contents

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <ffi.h>
#include "fficonfig.h"

#define MAX_ARGS 256

#define CHECK(x) !(x) ? abort() : 0

/* Define __UNUSED__ that also other compilers than gcc can run the tests.  */
#undef __UNUSED__
#if defined(__GNUC__)
#define __UNUSED__ __attribute__((__unused__))
#else
#define __UNUSED__
#endif

/* Prefer MAP_ANON(YMOUS) to /dev/zero, since we don't need to keep a
   file open.  */
#ifdef HAVE_MMAP_ANON
# undef HAVE_MMAP_DEV_ZERO

# include <sys/mman.h>
# ifndef MAP_FAILED
#  define MAP_FAILED -1
# endif
# if !defined (MAP_ANONYMOUS) && defined (MAP_ANON)
#  define MAP_ANONYMOUS MAP_ANON
# endif
# define USING_MMAP

#endif

#ifdef HAVE_MMAP_DEV_ZERO

# include <sys/mman.h>
# ifndef MAP_FAILED
#  define MAP_FAILED -1
# endif
# define USING_MMAP

#endif

#ifdef USING_MMAP
static inline void *
allocate_mmap (size_t size)
{
  void *page;
#if defined (HAVE_MMAP_DEV_ZERO)
  static int dev_zero_fd = -1;
#endif

#ifdef HAVE_MMAP_DEV_ZERO
  if (dev_zero_fd == -1)
    {
      dev_zero_fd = open ("/dev/zero", O_RDONLY);
      if (dev_zero_fd == -1)
	{
	  perror ("open /dev/zero: %m");
	  exit (1);
	}
    }
#endif


#ifdef HAVE_MMAP_ANON
  page = mmap (NULL, size, PROT_READ | PROT_WRITE | PROT_EXEC,
	       MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
#endif
#ifdef HAVE_MMAP_DEV_ZERO
  page = mmap (NULL, size, PROT_READ | PROT_WRITE | PROT_EXEC,
	       MAP_PRIVATE, dev_zero_fd, 0);
#endif

  if (page == (void *) MAP_FAILED)
    {
      perror ("virtual memory exhausted");
      exit (1);
    }

  return page;
}

#endif

Version data entries

26 entries across 26 versions & 4 rubygems

Version Path
ffi-ffi-0.5.0 ext/ffi_c/libffi/testsuite/libffi.call/ffitest.h
remogatto-ffi-0.5.0 ext/ffi_c/libffi/testsuite/libffi.call/ffitest.h
ffi-0.5.4-x86-mswin32 ext/ffi_c/libffi/testsuite/libffi.call/ffitest.h
ffi-0.5.4-x86-mingw32 ext/ffi_c/libffi/testsuite/libffi.call/ffitest.h
ffi-0.5.4 ext/ffi_c/libffi/testsuite/libffi.call/ffitest.h
ffi-0.5.3-x86-mswin32 ext/ffi_c/libffi/testsuite/libffi.call/ffitest.h
ffi-0.5.3 ext/ffi_c/libffi/testsuite/libffi.call/ffitest.h
ffi-0.5.3-x86-mingw32 ext/ffi_c/libffi/testsuite/libffi.call/ffitest.h
minilab-1.1.0-x86-mswin32-60 vendor/ffi-0.4.0-x86-mswin32/ext/ffi_c/libffi/testsuite/libffi.call/ffitest.h
ffi-0.5.1-x86-mswin32 ext/ffi_c/libffi/testsuite/libffi.call/ffitest.h
ffi-0.5.1 ext/ffi_c/libffi/testsuite/libffi.call/ffitest.h
ffi-0.5.1-x86-mingw32 ext/ffi_c/libffi/testsuite/libffi.call/ffitest.h
ffi-0.5.0-x86-mswin32 ext/ffi_c/libffi/testsuite/libffi.call/ffitest.h
ffi-0.5.0-x86-mingw32 ext/ffi_c/libffi/testsuite/libffi.call/ffitest.h
ffi-0.5.0 ext/ffi_c/libffi/testsuite/libffi.call/ffitest.h
ffi-0.4.0-x86-mswin32 ext/ffi_c/libffi/testsuite/libffi.call/ffitest.h
ffi-0.4.0 ext/ffi_c/libffi/testsuite/libffi.call/ffitest.h
ffi-0.1.1 ext/libffi/testsuite/libffi.call/ffitest.h
ffi-0.1.0 ext/libffi/testsuite/libffi.call/ffitest.h
ffi-0.3.0 ext/ffi_c/libffi/testsuite/libffi.call/ffitest.h