|
|
0e321a |
diff --git a/ext/fiddle/closure.c b/ext/fiddle/closure.c
|
|
|
0e321a |
index 1a80b2b..b997e23 100644
|
|
|
0e321a |
--- a/ext/fiddle/closure.c
|
|
|
0e321a |
+++ b/ext/fiddle/closure.c
|
|
|
0e321a |
@@ -13,25 +13,11 @@ typedef struct {
|
|
|
0e321a |
ffi_type **argv;
|
|
|
0e321a |
} fiddle_closure;
|
|
|
0e321a |
|
|
|
0e321a |
-#if defined(USE_FFI_CLOSURE_ALLOC)
|
|
|
0e321a |
-#elif defined(__OpenBSD__) || defined(__APPLE__) || defined(__linux__)
|
|
|
0e321a |
-# define USE_FFI_CLOSURE_ALLOC 0
|
|
|
0e321a |
-#elif defined(RUBY_LIBFFI_MODVERSION) && RUBY_LIBFFI_MODVERSION < 3000005 && \
|
|
|
0e321a |
- (defined(__i386__) || defined(__x86_64__) || defined(_M_IX86) || defined(_M_AMD64))
|
|
|
0e321a |
-# define USE_FFI_CLOSURE_ALLOC 0
|
|
|
0e321a |
-#else
|
|
|
0e321a |
-# define USE_FFI_CLOSURE_ALLOC 1
|
|
|
0e321a |
-#endif
|
|
|
0e321a |
-
|
|
|
0e321a |
static void
|
|
|
0e321a |
dealloc(void * ptr)
|
|
|
0e321a |
{
|
|
|
0e321a |
fiddle_closure * cls = (fiddle_closure *)ptr;
|
|
|
0e321a |
-#if USE_FFI_CLOSURE_ALLOC
|
|
|
0e321a |
ffi_closure_free(cls->pcl);
|
|
|
0e321a |
-#else
|
|
|
0e321a |
- munmap(cls->pcl, sizeof(*cls->pcl));
|
|
|
0e321a |
-#endif
|
|
|
0e321a |
if (cls->argv) xfree(cls->argv);
|
|
|
0e321a |
xfree(cls);
|
|
|
0e321a |
}
|
|
|
0e321a |
@@ -205,12 +191,7 @@ allocate(VALUE klass)
|
|
|
0e321a |
VALUE i = TypedData_Make_Struct(klass, fiddle_closure,
|
|
|
0e321a |
&closure_data_type, closure);
|
|
|
0e321a |
|
|
|
0e321a |
-#if USE_FFI_CLOSURE_ALLOC
|
|
|
0e321a |
closure->pcl = ffi_closure_alloc(sizeof(ffi_closure), &closure->code);
|
|
|
0e321a |
-#else
|
|
|
0e321a |
- closure->pcl = mmap(NULL, sizeof(ffi_closure), PROT_READ | PROT_WRITE,
|
|
|
0e321a |
- MAP_ANON | MAP_PRIVATE, -1, 0);
|
|
|
0e321a |
-#endif
|
|
|
0e321a |
|
|
|
0e321a |
return i;
|
|
|
0e321a |
}
|
|
|
0e321a |
@@ -257,17 +238,8 @@ initialize(int rbargc, VALUE argv[], VALUE self)
|
|
|
0e321a |
if (FFI_OK != result)
|
|
|
0e321a |
rb_raise(rb_eRuntimeError, "error prepping CIF %d", result);
|
|
|
0e321a |
|
|
|
0e321a |
-#if USE_FFI_CLOSURE_ALLOC
|
|
|
0e321a |
result = ffi_prep_closure_loc(pcl, cif, callback,
|
|
|
0e321a |
(void *)self, cl->code);
|
|
|
0e321a |
-#else
|
|
|
0e321a |
- result = ffi_prep_closure(pcl, cif, callback, (void *)self);
|
|
|
0e321a |
- cl->code = (void *)pcl;
|
|
|
0e321a |
- i = mprotect(pcl, sizeof(*pcl), PROT_READ | PROT_EXEC);
|
|
|
0e321a |
- if (i) {
|
|
|
0e321a |
- rb_sys_fail("mprotect");
|
|
|
0e321a |
- }
|
|
|
0e321a |
-#endif
|
|
|
0e321a |
|
|
|
0e321a |
if (FFI_OK != result)
|
|
|
0e321a |
rb_raise(rb_eRuntimeError, "error prepping closure %d", result);
|