13 #if defined(MACOSX) || defined(__linux) || defined(__OpenBSD__)
14 #define DONT_USE_FFI_CLOSURE_ALLOC
21 #ifndef DONT_USE_FFI_CLOSURE_ALLOC
22 ffi_closure_free(cls->
pcl);
24 munmap(cls->
pcl,
sizeof(*cls->
pcl));
38 #if !defined(FFI_NO_RAW_API) || !FFI_NO_RAW_API
39 size += ffi_raw_size(&cls->
cif);
41 size +=
sizeof(*cls->
argv);
42 size +=
sizeof(ffi_closure);
66 for (i = 0; i <
argc; i++) {
109 rb_ary_push(params, LL2NUM(*(LONG_LONG *)args[i]));
111 case -TYPE_LONG_LONG:
112 rb_ary_push(params, ULL2NUM(*(
unsigned LONG_LONG *)args[i]));
136 *(ffi_sarg *)resp =
NUM2INT(ret);
147 *(
double *)resp =
NUM2DBL(ret);
150 *(
float *)resp = (
float)
NUM2DBL(ret);
154 *(LONG_LONG *)resp = NUM2LL(ret);
156 case -TYPE_LONG_LONG:
157 *(
unsigned LONG_LONG *)resp = NUM2ULL(ret);
171 &closure_data_type, closure);
173 #ifndef DONT_USE_FFI_CLOSURE_ALLOC
174 closure->
pcl = ffi_closure_alloc(
sizeof(ffi_closure), &closure->
code);
176 closure->
pcl = mmap(
NULL,
sizeof(ffi_closure), PROT_READ | PROT_WRITE,
177 MAP_ANON | MAP_PRIVATE, -1, 0);
195 if (2 ==
rb_scan_args(rbargc, argv,
"21", &ret, &args, &abi))
196 abi =
INT2NUM(FFI_DEFAULT_ABI);
204 cl->
argv = (ffi_type **)
xcalloc(argc + 1,
sizeof(ffi_type *));
206 for (i = 0; i <
argc; i++) {
218 result = ffi_prep_cif(cif,
NUM2INT(abi), argc,
222 if (FFI_OK != result)
225 #ifndef DONT_USE_FFI_CLOSURE_ALLOC
226 result = ffi_prep_closure_loc(pcl, cif,
callback,
227 (
void *)
self, cl->
code);
229 result = ffi_prep_closure(pcl, cif,
callback, (
void *)
self);
230 cl->
code = (
void *)pcl;
231 i = mprotect(pcl,
sizeof(*pcl), PROT_READ | PROT_EXEC);
237 if (FFI_OK != result)