|
Lines 14-19
Link Here
|
| 14 |
# endif |
14 |
# endif |
| 15 |
#endif |
15 |
#endif |
| 16 |
|
16 |
|
|
|
17 |
/* On PaX enable kernels that have MPROTECT enable we can't use PROT_EXEC. */ |
| 18 |
#ifndef MS_WIN32 |
| 19 |
#include <stdlib.h> |
| 20 |
|
| 21 |
static int emutramp_enabled = -1; |
| 22 |
|
| 23 |
static int |
| 24 |
emutramp_enabled_check (void) |
| 25 |
{ |
| 26 |
char *buf = NULL; |
| 27 |
size_t len = 0; |
| 28 |
FILE *f; |
| 29 |
int ret; |
| 30 |
f = fopen ("/proc/self/status", "r"); |
| 31 |
if (f == NULL) |
| 32 |
return 0; |
| 33 |
ret = 0; |
| 34 |
|
| 35 |
while (getline (&buf, &len, f) != -1) |
| 36 |
if (!strncmp (buf, "PaX:", 4)) |
| 37 |
{ |
| 38 |
char emutramp; |
| 39 |
if (sscanf (buf, "%*s %*c%c", &emutramp) == 1) |
| 40 |
ret = (emutramp == 'E'); |
| 41 |
break; |
| 42 |
} |
| 43 |
free (buf); |
| 44 |
fclose (f); |
| 45 |
return ret; |
| 46 |
} |
| 47 |
|
| 48 |
#define is_emutramp_enabled() (emutramp_enabled >= 0 ? emutramp_enabled \ |
| 49 |
: (emutramp_enabled = emutramp_enabled_check ())) |
| 50 |
#else |
| 51 |
#define is_emutramp_enabled() 0 |
| 52 |
#endif /* FFI_MMAP_EXEC_EMUTRAMP_PAX */ |
| 53 |
|
| 17 |
/* 'allocate_num_pages' is dynamically adjusted starting from one |
54 |
/* 'allocate_num_pages' is dynamically adjusted starting from one |
| 18 |
page. It grows by a factor of PAGE_ALLOCATION_GROWTH_RATE. This is |
55 |
page. It grows by a factor of PAGE_ALLOCATION_GROWTH_RATE. This is |
| 19 |
meant to handle both the common case of not needing a lot of pages, |
56 |
meant to handle both the common case of not needing a lot of pages, |
|
Lines 77-83
static void more_core(void)
Link Here
|
| 77 |
if (item == NULL) |
114 |
if (item == NULL) |
| 78 |
return; |
115 |
return; |
| 79 |
#else |
116 |
#else |
| 80 |
item = (union mmaped_block *)mmap(NULL, |
117 |
if (is_emutramp_enabled ()) |
|
|
118 |
item = (union mmaped_block *)mmap(NULL, |
| 119 |
allocate_num_pages * _pagesize, |
| 120 |
PROT_READ | PROT_WRITE, |
| 121 |
MAP_PRIVATE | MAP_ANONYMOUS, |
| 122 |
-1, |
| 123 |
0); |
| 124 |
else |
| 125 |
item = (union mmaped_block *)mmap(NULL, |
| 81 |
allocate_num_pages * _pagesize, |
126 |
allocate_num_pages * _pagesize, |
| 82 |
PROT_READ | PROT_WRITE | PROT_EXEC, |
127 |
PROT_READ | PROT_WRITE | PROT_EXEC, |
| 83 |
MAP_PRIVATE | MAP_ANONYMOUS, |
128 |
MAP_PRIVATE | MAP_ANONYMOUS, |