ffi_status ffi_prep_raw_closure_loc (ffi_raw_closure* closure, ffi_cif* cif, void (*fun)(ffi_cif*,void*,ffi_raw*,void*), void *user_data, void *codeloc) { int i; if (cif->abi != FFI_SYSV) { #ifdef X86_WIN32 if (cif->abi != FFI_THISCALL) #endif return FFI_BAD_ABI; } /* we currently don't support certain kinds of arguments for raw closures. This should be implemented by a separate assembly language routine, since it would require argument processing, something we don't do now for performance. */ for (i = cif->nargs-1; i >= 0; i--) { FFI_ASSERT (cif->arg_types[i]->type != FFI_TYPE_STRUCT); FFI_ASSERT (cif->arg_types[i]->type != FFI_TYPE_LONGDOUBLE); } #ifdef X86_WIN32 if (cif->abi == FFI_SYSV) { #endif FFI_INIT_TRAMPOLINE (&closure->tramp[0], &ffi_closure_raw_SYSV, codeloc); #ifdef X86_WIN32 } else if (cif->abi == FFI_THISCALL) { FFI_INIT_TRAMPOLINE_THISCALL (&closure->tramp[0], &ffi_closure_raw_THISCALL, codeloc, cif->bytes); } #endif closure->cif = cif; closure->user_data = user_data; closure->fun = fun; return FFI_OK; }
ffi_status ffi_prep_closure_loc (ffi_closure* closure, ffi_cif* cif, void (*fun)(ffi_cif*,void*,void**,void*), void *user_data, void *codeloc) { #ifdef X86_WIN64 #define ISFLOAT(IDX) (cif->arg_types[IDX]->type == FFI_TYPE_FLOAT || cif->arg_types[IDX]->type == FFI_TYPE_DOUBLE) #define FLAG(IDX) (cif->nargs>(IDX)&&ISFLOAT(IDX)?(1<<(IDX)):0) if (cif->abi == FFI_WIN64) { int mask = FLAG(0)|FLAG(1)|FLAG(2)|FLAG(3); FFI_INIT_TRAMPOLINE_WIN64 (&closure->tramp[0], &ffi_closure_win64, codeloc, mask); /* make sure we can execute here */ } #else if (cif->abi == FFI_SYSV) { FFI_INIT_TRAMPOLINE (&closure->tramp[0], &ffi_closure_SYSV, (void*)codeloc); } #ifdef X86_WIN32 else if (cif->abi == FFI_STDCALL) { FFI_INIT_TRAMPOLINE_STDCALL (&closure->tramp[0], &ffi_closure_STDCALL, (void*)codeloc, cif->bytes); } #endif /* X86_WIN32 */ #endif /* !X86_WIN64 */ else { return FFI_BAD_ABI; } closure->cif = cif; closure->user_data = user_data; closure->fun = fun; return FFI_OK; }
ffi_status ffi_prep_closure_loc (ffi_closure* closure, ffi_cif* cif, void (*fun)(ffi_cif*,void*,void**,void*), void *user_data, void *codeloc) { if (cif->abi != FFI_SYSV) return FFI_BAD_ABI; FFI_INIT_TRAMPOLINE (&closure->tramp[0], &ffi_closure_SYSV, codeloc, cif->aarch64_flags); closure->cif = cif; closure->user_data = user_data; closure->fun = fun; return FFI_OK; }