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