Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Anthony Green
committed
Dec 29, 2009
1 parent
14e2e92
commit 0cfe60e
Showing
51 changed files
with
1,237 additions
and
756 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
#include <stdlib.h> | ||
#include <stdio.h> | ||
#include <string.h> | ||
#include <fcntl.h> | ||
#include <stdint.h> | ||
#include <inttypes.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 | ||
|
||
/* MinGW kludge. */ | ||
#ifdef WIN64 | ||
#define PRIdLL "PRId64" | ||
#define PRIuLL "PRIu64" | ||
#else | ||
#define PRIdLL "lld" | ||
#define PRIuLL "llu" | ||
#endif | ||
|
||
/* PA HP-UX kludge. */ | ||
#if defined(__hppa__) && defined(__hpux__) && !defined(PRIuPTR) | ||
#define PRIuPTR "lu" | ||
#endif | ||
|
||
/* Solaris < 10 kludge. */ | ||
#if defined(__sun__) && defined(__svr4__) && !defined(PRIuPTR) | ||
#if defined(__arch64__) || defined (__x86_64__) | ||
#define PRIuPTR "lu" | ||
#else | ||
#define PRIuPTR "u" | ||
#endif | ||
#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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
#include <stdlib.h> | ||
#include <stdio.h> | ||
#include <fcntl.h> | ||
#include <ffi.h> | ||
#include "fficonfig.h" | ||
|
||
#define MAX_ARGS 256 | ||
|
||
|
||
/* 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 | ||
|
||
#define CHECK(x) (!(x) ? abort() : (void)0) | ||
|
||
/* 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 | ||
|
||
|
||
/* MinGW kludge. */ | ||
#ifdef WIN64 | ||
#define PRIdLL "PRId64" | ||
#define PRIuLL "PRIu64" | ||
#else | ||
#define PRIdLL "lld" | ||
#define PRIuLL "llu" | ||
#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 == MAP_FAILED) | ||
{ | ||
perror ("virtual memory exhausted"); | ||
exit (1); | ||
} | ||
|
||
return page; | ||
} | ||
|
||
#endif |
Oops, something went wrong.