@@ -279,3 +279,42 @@ index 9921b0d..5b60ccc 100755
279279
280280 mkdir_p('darwin_common/include')
281281 for header_name, tag_tuples in platform_headers.items():
282+ diff --git a/src/closures.c b/src/closures.c
283+ index f7bead6..db7ec94 100644
284+ --- a/src/closures.c
285+ +++ b/src/closures.c
286+ @@ -134,7 +134,7 @@ ffi_tramp_is_present (__attribute__((unused)) void *ptr)
287+ # define HAVE_MNTENT 1
288+ # endif
289+ # if defined(_WIN32) || defined(__OS2__)
290+ - /* Windows systems may have Data Execution Protection (DEP) enabled,
291+ + /* Windows systems may have Data Execution Protection (DEP) enabled,
292+ which requires the use of VirtualMalloc/VirtualFree to alloc/free
293+ executable memory. */
294+ # define FFI_MMAP_EXEC_WRIT 1
295+ @@ -230,12 +230,24 @@ ffi_trampoline_table_alloc (void)
296+ kt = vm_remap (mach_task_self (), &trampoline_page, PAGE_MAX_SIZE, 0x0,
297+ VM_FLAGS_OVERWRITE, mach_task_self (), trampoline_page_template,
298+ FALSE, &cur_prot, &max_prot, VM_INHERIT_SHARE);
299+ - if (kt != KERN_SUCCESS || !(cur_prot & VM_PROT_EXECUTE))
300+ + if (kt != KERN_SUCCESS)
301+ {
302+ vm_deallocate (mach_task_self (), config_page, PAGE_MAX_SIZE * 2);
303+ return NULL;
304+ }
305+
306+ + if (!(cur_prot & VM_PROT_EXECUTE))
307+ + {
308+ + /* If VM_PROT_EXECUTE isn't set on the remapped trampoline page, set it */
309+ + kt = vm_protect (mach_task_self (), trampoline_page, PAGE_MAX_SIZE,
310+ + FALSE, cur_prot | VM_PROT_EXECUTE);
311+ + if (kt != KERN_SUCCESS)
312+ + {
313+ + vm_deallocate (mach_task_self (), config_page, PAGE_MAX_SIZE * 2);
314+ + return NULL;
315+ + }
316+ + }
317+ +
318+ /* We have valid trampoline and config pages */
319+ table = calloc (1, sizeof (ffi_trampoline_table));
320+ table->free_count = FFI_TRAMPOLINE_COUNT;
0 commit comments