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 1b378270363..fecbc4ae2c9 100644 --- a/libffi/src/closures.c +++ b/libffi/src/closures.c @@ -172,6 +172,27 @@ selinux_enabled_check (void) #endif /* !FFI_MMAP_EXEC_SELINUX */ +/* On PaX enable kernels that have MPROTECT enable we can't use PROT_EXEC. */ +#ifdef FFI_MMAP_EXEC_EMUTRAMP_PAX +#include <stdlib.h> + +static int emutramp_enabled = -1; + +static int +emutramp_enabled_check (void) +{ + if (getenv ("FFI_DISABLE_EMUTRAMP") == NULL) + return 1; + else + return 0; +} + +#define is_emutramp_enabled() (emutramp_enabled >= 0 ? emutramp_enabled \ + : (emutramp_enabled = emutramp_enabled_check ())) +#else +#define is_emutramp_enabled() 0 +#endif /* FFI_MMAP_EXEC_EMUTRAMP_PAX */ + #elif defined (__CYGWIN__) || defined(__INTERIX) #include <sys/mman.h> @@ -458,6 +479,12 @@ dlmmap (void *start, size_t length, int prot, printf ("mapping in %zi\n", length); #endif + if (execfd == -1 && is_emutramp_enabled ()) + { + ptr = mmap (start, length, prot & ~PROT_EXEC, flags, fd, offset); + return ptr; + } + if (execfd == -1 && !is_selinux_enabled ()) { ptr = mmap (start, length, prot | PROT_EXEC, flags, fd, offset); |