diff options
Diffstat (limited to 'libffi/src/closures.c')
-rw-r--r-- | libffi/src/closures.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/libffi/src/closures.c b/libffi/src/closures.c index ff9c174c32e..7692c857162 100644 --- a/libffi/src/closures.c +++ b/libffi/src/closures.c @@ -42,6 +42,13 @@ locations in the virtual memory space, one location writable and another executable. */ # define FFI_MMAP_EXEC_WRIT 1 +# define HAVE_MNTENT 1 +# endif +# if defined(X86_WIN32) || defined(X86_WIN64) +/* Windows systems may have Data Execution Protection (DEP) enabled, + which requires the use of VirtualMalloc/VirtualFree to alloc/free + executable memory. */ +# define FFI_MMAP_EXEC_WRIT 1 # endif #endif @@ -60,7 +67,11 @@ #define USE_LOCKS 1 #define USE_DL_PREFIX 1 +#ifdef __GNUC__ +#ifndef USE_BUILTIN_FFS #define USE_BUILTIN_FFS 1 +#endif +#endif /* We need to use mmap, not sbrk. */ #define HAVE_MORECORE 0 @@ -90,10 +101,15 @@ #include <sys/stat.h> #include <fcntl.h> #include <errno.h> +#ifndef _MSC_VER #include <unistd.h> +#endif #include <string.h> #include <stdio.h> +#if !defined(X86_WIN32) && !defined(X86_WIN64) +#ifdef HAVE_MNTENT #include <mntent.h> +#endif /* HAVE_MNTENT */ #include <sys/param.h> #include <pthread.h> @@ -150,6 +166,7 @@ selinux_enabled_check (void) #define is_selinux_enabled() 0 #endif +#endif /* !defined(X86_WIN32) && !defined(X86_WIN64) */ /* Declare all functions defined in dlmalloc.c as static. */ static void *dlmalloc(size_t); @@ -168,9 +185,11 @@ static int dlmalloc_trim(size_t) MAYBE_UNUSED; static size_t dlmalloc_usable_size(void*) MAYBE_UNUSED; static void dlmalloc_stats(void) MAYBE_UNUSED; +#if !defined(X86_WIN32) && !defined(X86_WIN64) /* Use these for mmap and munmap within dlmalloc.c. */ static void *dlmmap(void *, size_t, int, int, int, off_t); static int dlmunmap(void *, size_t); +#endif /* !defined(X86_WIN32) && !defined(X86_WIN64) */ #define mmap dlmmap #define munmap dlmunmap @@ -180,6 +199,8 @@ static int dlmunmap(void *, size_t); #undef mmap #undef munmap +#if !defined(X86_WIN32) && !defined(X86_WIN64) + /* A mutex used to synchronize access to *exec* variables in this file. */ static pthread_mutex_t open_temp_exec_file_mutex = PTHREAD_MUTEX_INITIALIZER; @@ -232,6 +253,7 @@ open_temp_exec_file_env (const char *envvar) return open_temp_exec_file_dir (value); } +#ifdef HAVE_MNTENT /* Open a temporary file in an executable and writable mount point listed in the mounts file. Subsequent calls with the same mounts keep searching for mount points in the same file. Providing NULL @@ -278,6 +300,7 @@ open_temp_exec_file_mnt (const char *mounts) return fd; } } +#endif /* HAVE_MNTENT */ /* Instructions to look for a location to hold a temporary file that can be mapped in for execution. */ @@ -292,8 +315,10 @@ static struct { open_temp_exec_file_dir, "/var/tmp", 0 }, { open_temp_exec_file_dir, "/dev/shm", 0 }, { open_temp_exec_file_env, "HOME", 0 }, +#ifdef HAVE_MNTENT { open_temp_exec_file_mnt, "/etc/mtab", 1 }, { open_temp_exec_file_mnt, "/proc/mounts", 1 }, +#endif /* HAVE_MNTENT */ }; /* Current index into open_temp_exec_file_opts. */ @@ -489,6 +514,8 @@ segment_holding_code (mstate m, char* addr) } #endif +#endif /* !defined(X86_WIN32) && !defined(X86_WIN64) */ + /* Allocate a chunk of memory with the given size. Returns a pointer to the writable address, and sets *CODE to the executable corresponding virtual address. */ |