13 #if defined(USE_FFI_CLOSURE_ALLOC)
14 #elif defined(__OpenBSD__) || defined(__APPLE__) || defined(__linux__)
15 # define USE_FFI_CLOSURE_ALLOC 0
16 #elif defined(RUBY_LIBFFI_MODVERSION) && RUBY_LIBFFI_MODVERSION < 3000005 && \
17 (defined(__i386__) || defined(__x86_64__) || defined(_M_IX86) || defined(_M_AMD64))
18 # define USE_FFI_CLOSURE_ALLOC 0
20 # define USE_FFI_CLOSURE_ALLOC 1
27 #if USE_FFI_CLOSURE_ALLOC
28 ffi_closure_free(cls->
pcl);
30 munmap(cls->
pcl,
sizeof(*cls->
pcl));
44 #if !defined(FFI_NO_RAW_API) || !FFI_NO_RAW_API
45 size += ffi_raw_size(&cls->
cif);
47 size +=
sizeof(*cls->
argv);
48 size +=
sizeof(ffi_closure);
59 callback(ffi_cif *cif,
void *resp,
void **args,
void *ctx)
72 for (i = 0; i <
argc; i++) {
115 rb_ary_push(params, LL2NUM(*(LONG_LONG *)args[i]));
117 case -TYPE_LONG_LONG:
118 rb_ary_push(params, ULL2NUM(*(
unsigned LONG_LONG *)args[i]));
142 *(ffi_sarg *)resp =
NUM2INT(ret);
153 *(
double *)resp =
NUM2DBL(ret);
156 *(
float *)resp = (
float)
NUM2DBL(ret);
160 *(LONG_LONG *)resp = NUM2LL(ret);
162 case -TYPE_LONG_LONG:
163 *(
unsigned LONG_LONG *)resp = NUM2ULL(ret);
177 &closure_data_type, closure);
179 #if USE_FFI_CLOSURE_ALLOC
180 closure->
pcl = ffi_closure_alloc(
sizeof(ffi_closure), &closure->
code);
182 closure->
pcl = mmap(
NULL,
sizeof(ffi_closure), PROT_READ | PROT_WRITE,
183 MAP_ANON | MAP_PRIVATE, -1, 0);
201 if (2 ==
rb_scan_args(rbargc, argv,
"21", &ret, &args, &abi))
202 abi =
INT2NUM(FFI_DEFAULT_ABI);
210 cl->
argv = (ffi_type **)
xcalloc(argc + 1,
sizeof(ffi_type *));
212 for (i = 0; i <
argc; i++) {
224 result = ffi_prep_cif(cif,
NUM2INT(abi), argc,
228 if (FFI_OK != result)
231 #if USE_FFI_CLOSURE_ALLOC
232 result = ffi_prep_closure_loc(pcl, cif,
callback,
233 (
void *)
self, cl->
code);
235 result = ffi_prep_closure(pcl, cif,
callback, (
void *)
self);
236 cl->
code = (
void *)pcl;
237 i = mprotect(pcl,
sizeof(*pcl), PROT_READ | PROT_EXEC);
243 if (FFI_OK != result)