15 #if defined(USE_FFI_CLOSURE_ALLOC) 16 #elif defined(__OpenBSD__) || defined(__APPLE__) || defined(__linux__) 17 # define USE_FFI_CLOSURE_ALLOC 0 18 #elif defined(RUBY_LIBFFI_MODVERSION) && RUBY_LIBFFI_MODVERSION < 3000005 && \ 19 (defined(__i386__) || defined(__x86_64__) || defined(_M_IX86) || defined(_M_AMD64)) 20 # define USE_FFI_CLOSURE_ALLOC 0 22 # define USE_FFI_CLOSURE_ALLOC 1 29 #if USE_FFI_CLOSURE_ALLOC 30 ffi_closure_free(cls->
pcl);
32 munmap(cls->
pcl,
sizeof(*cls->
pcl));
45 #if !defined(FFI_NO_RAW_API) || !FFI_NO_RAW_API 48 size +=
sizeof(*cls->
argv);
49 size +=
sizeof(ffi_closure);
82 for (i = 0; i <
argc; i++) {
127 case -TYPE_LONG_LONG:
170 *(LONG_LONG *)x->
resp = NUM2LL(ret);
172 case -TYPE_LONG_LONG:
173 *(
unsigned LONG_LONG *)x->
resp = NUM2ULL(ret);
205 &closure_data_type, closure);
207 #if USE_FFI_CLOSURE_ALLOC 208 closure->
pcl = ffi_closure_alloc(
sizeof(ffi_closure), &closure->
code);
210 closure->
pcl = mmap(
NULL,
sizeof(ffi_closure), PROT_READ | PROT_WRITE,
211 MAP_ANON | MAP_PRIVATE, -1, 0);
229 if (2 ==
rb_scan_args(rbargc, argv,
"21", &ret, &args, &abi))
238 cl->
argv = (ffi_type **)
xcalloc(argc + 1,
sizeof(ffi_type *));
240 for (i = 0; i <
argc; i++) {
256 if (FFI_OK != result)
259 #if USE_FFI_CLOSURE_ALLOC 261 (
void *)
self, cl->
code);
263 result = ffi_prep_closure(pcl, cif,
callback, (
void *)
self);
264 cl->
code = (
void *)pcl;
265 i = mprotect(pcl,
sizeof(*pcl), PROT_READ | PROT_EXEC);
271 if (FFI_OK != result)
#define TypedData_Get_Struct(obj, type, data_type, sval)
VALUE rb_ary_push(VALUE ary, VALUE item)
VALUE rb_ary_tmp_new(long capa)
VALUE rb_funcall(VALUE, ID, int,...)
Calls a method.
VALUE rb_iv_set(VALUE, const char *, VALUE)
VALUE rb_iv_get(VALUE, const char *)
VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super)
Defines a class under the namespace of outer.
void rb_raise(VALUE exc, const char *fmt,...)
void rb_define_alloc_func(VALUE, rb_alloc_func_t)
int ruby_thread_has_gvl_p(void)
static void * with_gvl_callback(void *ptr)
RUBY_EXTERN VALUE rb_cObject
static VALUE to_i(VALUE self)
const rb_data_type_t closure_data_type
static void callback(ffi_cif *cif, void *resp, void **args, void *ctx)
#define INT2FFI_TYPE(_type)
ffi_status ffi_prep_closure_loc(ffi_closure *closure, ffi_cif *cif, void(*fun)(ffi_cif *, void *, void **, void *), void *user_data, void *codeloc)
static void dealloc(void *ptr)
VALUE rb_const_get(VALUE, ID)
#define RARRAY_CONST_PTR(a)
static VALUE initialize(int rbargc, VALUE argv[], VALUE self)
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
#define RARRAY_LENINT(ary)
void rb_sys_fail(const char *mesg)
static VALUE allocate(VALUE klass)
#define RARRAY_AREF(a, i)
RUBY_SYMBOL_EXPORT_BEGIN void * rb_thread_call_with_gvl(void *(*func)(void *), void *data1)
#define TypedData_Make_Struct(klass, type, data_type, sval)
void Init_fiddle_closure(void)
VALUE rb_define_module(const char *name)
size_t ffi_raw_size(ffi_cif *cif)
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
static size_t closure_memsize(const void *ptr)
ffi_status ffi_prep_cif(ffi_cif *cif, ffi_abi abi, unsigned int nargs, ffi_type *rtype, ffi_type **atypes)