ffi 1.9.3-x64-mingw32
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of ffi might be problematic. Click here for more details.
- data/COPYING +49 -0
- data/LICENSE +24 -0
- data/README.md +109 -0
- data/Rakefile +220 -0
- data/ext/ffi_c/AbstractMemory.c +1032 -0
- data/ext/ffi_c/AbstractMemory.h +175 -0
- data/ext/ffi_c/ArrayType.c +162 -0
- data/ext/ffi_c/ArrayType.h +59 -0
- data/ext/ffi_c/Buffer.c +365 -0
- data/ext/ffi_c/Call.c +465 -0
- data/ext/ffi_c/Call.h +93 -0
- data/ext/ffi_c/ClosurePool.c +283 -0
- data/ext/ffi_c/ClosurePool.h +57 -0
- data/ext/ffi_c/DataConverter.c +91 -0
- data/ext/ffi_c/DynamicLibrary.c +333 -0
- data/ext/ffi_c/DynamicLibrary.h +49 -0
- data/ext/ffi_c/Function.c +999 -0
- data/ext/ffi_c/Function.h +87 -0
- data/ext/ffi_c/FunctionInfo.c +271 -0
- data/ext/ffi_c/LastError.c +184 -0
- data/ext/ffi_c/LastError.h +47 -0
- data/ext/ffi_c/LongDouble.c +63 -0
- data/ext/ffi_c/LongDouble.h +51 -0
- data/ext/ffi_c/MappedType.c +168 -0
- data/ext/ffi_c/MappedType.h +59 -0
- data/ext/ffi_c/MemoryPointer.c +197 -0
- data/ext/ffi_c/MemoryPointer.h +53 -0
- data/ext/ffi_c/MethodHandle.c +360 -0
- data/ext/ffi_c/MethodHandle.h +55 -0
- data/ext/ffi_c/Platform.c +121 -0
- data/ext/ffi_c/Platform.h +45 -0
- data/ext/ffi_c/Pointer.c +508 -0
- data/ext/ffi_c/Pointer.h +63 -0
- data/ext/ffi_c/Struct.c +828 -0
- data/ext/ffi_c/Struct.h +106 -0
- data/ext/ffi_c/StructByReference.c +190 -0
- data/ext/ffi_c/StructByReference.h +50 -0
- data/ext/ffi_c/StructByValue.c +150 -0
- data/ext/ffi_c/StructByValue.h +55 -0
- data/ext/ffi_c/StructLayout.c +698 -0
- data/ext/ffi_c/Thread.c +352 -0
- data/ext/ffi_c/Thread.h +95 -0
- data/ext/ffi_c/Type.c +397 -0
- data/ext/ffi_c/Type.h +62 -0
- data/ext/ffi_c/Types.c +139 -0
- data/ext/ffi_c/Types.h +89 -0
- data/ext/ffi_c/Variadic.c +276 -0
- data/ext/ffi_c/compat.h +83 -0
- data/ext/ffi_c/extconf.rb +64 -0
- data/ext/ffi_c/ffi.c +98 -0
- data/ext/ffi_c/libffi.bsd.mk +34 -0
- data/ext/ffi_c/libffi.darwin.mk +95 -0
- data/ext/ffi_c/libffi.gnu.mk +31 -0
- data/ext/ffi_c/libffi.mk +13 -0
- data/ext/ffi_c/libffi.vc.mk +26 -0
- data/ext/ffi_c/libffi.vc64.mk +26 -0
- data/ext/ffi_c/libffi/ChangeLog +4600 -0
- data/ext/ffi_c/libffi/ChangeLog.libffi +584 -0
- data/ext/ffi_c/libffi/ChangeLog.libgcj +40 -0
- data/ext/ffi_c/libffi/ChangeLog.v1 +764 -0
- data/ext/ffi_c/libffi/LICENSE +21 -0
- data/ext/ffi_c/libffi/Makefile.am +196 -0
- data/ext/ffi_c/libffi/Makefile.in +1820 -0
- data/ext/ffi_c/libffi/Makefile.vc +141 -0
- data/ext/ffi_c/libffi/Makefile.vc64 +141 -0
- data/ext/ffi_c/libffi/README +342 -0
- data/ext/ffi_c/libffi/acinclude.m4 +92 -0
- data/ext/ffi_c/libffi/aclocal.m4 +1873 -0
- data/ext/ffi_c/libffi/build-ios.sh +67 -0
- data/ext/ffi_c/libffi/compile +143 -0
- data/ext/ffi_c/libffi/config.guess +1501 -0
- data/ext/ffi_c/libffi/config.sub +1705 -0
- data/ext/ffi_c/libffi/configure +17191 -0
- data/ext/ffi_c/libffi/configure.ac +496 -0
- data/ext/ffi_c/libffi/configure.host +11 -0
- data/ext/ffi_c/libffi/depcomp +630 -0
- data/ext/ffi_c/libffi/doc/libffi.info +593 -0
- data/ext/ffi_c/libffi/doc/libffi.texi +600 -0
- data/ext/ffi_c/libffi/doc/stamp-vti +4 -0
- data/ext/ffi_c/libffi/doc/version.texi +4 -0
- data/ext/ffi_c/libffi/fficonfig.h.in +199 -0
- data/ext/ffi_c/libffi/fficonfig.hw +57 -0
- data/ext/ffi_c/libffi/include/Makefile.am +9 -0
- data/ext/ffi_c/libffi/include/Makefile.in +487 -0
- data/ext/ffi_c/libffi/include/ffi.h.in +427 -0
- data/ext/ffi_c/libffi/include/ffi.h.vc +427 -0
- data/ext/ffi_c/libffi/include/ffi.h.vc64 +427 -0
- data/ext/ffi_c/libffi/include/ffi_common.h +126 -0
- data/ext/ffi_c/libffi/install-sh +520 -0
- data/ext/ffi_c/libffi/libffi.pc.in +10 -0
- data/ext/ffi_c/libffi/libtool-version +29 -0
- data/ext/ffi_c/libffi/ltmain.sh +9636 -0
- data/ext/ffi_c/libffi/m4/ax_cc_maxopt.m4 +176 -0
- data/ext/ffi_c/libffi/m4/ax_cflags_warn_all.m4 +195 -0
- data/ext/ffi_c/libffi/m4/ax_check_compiler_flags.m4 +76 -0
- data/ext/ffi_c/libffi/m4/ax_compiler_vendor.m4 +63 -0
- data/ext/ffi_c/libffi/m4/ax_configure_args.m4 +70 -0
- data/ext/ffi_c/libffi/m4/ax_enable_builddir.m4 +300 -0
- data/ext/ffi_c/libffi/m4/ax_gcc_archflag.m4 +215 -0
- data/ext/ffi_c/libffi/m4/ax_gcc_x86_cpuid.m4 +79 -0
- data/ext/ffi_c/libffi/m4/libtool.m4 +7831 -0
- data/ext/ffi_c/libffi/m4/ltoptions.m4 +369 -0
- data/ext/ffi_c/libffi/m4/ltsugar.m4 +123 -0
- data/ext/ffi_c/libffi/m4/ltversion.m4 +23 -0
- data/ext/ffi_c/libffi/m4/lt~obsolete.m4 +98 -0
- data/ext/ffi_c/libffi/man/Makefile.am +8 -0
- data/ext/ffi_c/libffi/man/Makefile.in +466 -0
- data/ext/ffi_c/libffi/man/ffi.3 +31 -0
- data/ext/ffi_c/libffi/man/ffi_call.3 +103 -0
- data/ext/ffi_c/libffi/man/ffi_prep_cif.3 +66 -0
- data/ext/ffi_c/libffi/mdate-sh +201 -0
- data/ext/ffi_c/libffi/missing +376 -0
- data/ext/ffi_c/libffi/msvcc.sh +197 -0
- data/ext/ffi_c/libffi/src/alpha/ffi.c +284 -0
- data/ext/ffi_c/libffi/src/alpha/ffitarget.h +48 -0
- data/ext/ffi_c/libffi/src/alpha/osf.S +387 -0
- data/ext/ffi_c/libffi/src/arm/ffi.c +728 -0
- data/ext/ffi_c/libffi/src/arm/ffitarget.h +65 -0
- data/ext/ffi_c/libffi/src/arm/gentramp.sh +118 -0
- data/ext/ffi_c/libffi/src/arm/sysv.S +497 -0
- data/ext/ffi_c/libffi/src/arm/trampoline.S +4450 -0
- data/ext/ffi_c/libffi/src/avr32/ffi.c +423 -0
- data/ext/ffi_c/libffi/src/avr32/ffitarget.h +50 -0
- data/ext/ffi_c/libffi/src/avr32/sysv.S +208 -0
- data/ext/ffi_c/libffi/src/closures.c +615 -0
- data/ext/ffi_c/libffi/src/cris/ffi.c +383 -0
- data/ext/ffi_c/libffi/src/cris/ffitarget.h +51 -0
- data/ext/ffi_c/libffi/src/cris/sysv.S +215 -0
- data/ext/ffi_c/libffi/src/debug.c +59 -0
- data/ext/ffi_c/libffi/src/dlmalloc.c +5161 -0
- data/ext/ffi_c/libffi/src/frv/eabi.S +128 -0
- data/ext/ffi_c/libffi/src/frv/ffi.c +292 -0
- data/ext/ffi_c/libffi/src/frv/ffitarget.h +57 -0
- data/ext/ffi_c/libffi/src/ia64/ffi.c +582 -0
- data/ext/ffi_c/libffi/src/ia64/ffitarget.h +50 -0
- data/ext/ffi_c/libffi/src/ia64/ia64_flags.h +40 -0
- data/ext/ffi_c/libffi/src/ia64/unix.S +560 -0
- data/ext/ffi_c/libffi/src/java_raw_api.c +356 -0
- data/ext/ffi_c/libffi/src/m32r/ffi.c +232 -0
- data/ext/ffi_c/libffi/src/m32r/ffitarget.h +48 -0
- data/ext/ffi_c/libffi/src/m32r/sysv.S +121 -0
- data/ext/ffi_c/libffi/src/m68k/ffi.c +288 -0
- data/ext/ffi_c/libffi/src/m68k/ffitarget.h +49 -0
- data/ext/ffi_c/libffi/src/m68k/sysv.S +270 -0
- data/ext/ffi_c/libffi/src/mips/ffi.c +1036 -0
- data/ext/ffi_c/libffi/src/mips/ffitarget.h +242 -0
- data/ext/ffi_c/libffi/src/mips/n32.S +591 -0
- data/ext/ffi_c/libffi/src/mips/o32.S +381 -0
- data/ext/ffi_c/libffi/src/moxie/eabi.S +128 -0
- data/ext/ffi_c/libffi/src/moxie/ffi.c +276 -0
- data/ext/ffi_c/libffi/src/pa/ffi.c +719 -0
- data/ext/ffi_c/libffi/src/pa/ffitarget.h +78 -0
- data/ext/ffi_c/libffi/src/pa/hpux32.S +368 -0
- data/ext/ffi_c/libffi/src/pa/linux.S +357 -0
- data/ext/ffi_c/libffi/src/powerpc/aix.S +328 -0
- data/ext/ffi_c/libffi/src/powerpc/aix_closure.S +445 -0
- data/ext/ffi_c/libffi/src/powerpc/asm.h +125 -0
- data/ext/ffi_c/libffi/src/powerpc/darwin.S +383 -0
- data/ext/ffi_c/libffi/src/powerpc/darwin_closure.S +575 -0
- data/ext/ffi_c/libffi/src/powerpc/ffi.c +1448 -0
- data/ext/ffi_c/libffi/src/powerpc/ffi_darwin.c +1359 -0
- data/ext/ffi_c/libffi/src/powerpc/ffitarget.h +139 -0
- data/ext/ffi_c/libffi/src/powerpc/linux64.S +187 -0
- data/ext/ffi_c/libffi/src/powerpc/linux64_closure.S +236 -0
- data/ext/ffi_c/libffi/src/powerpc/ppc_closure.S +327 -0
- data/ext/ffi_c/libffi/src/powerpc/sysv.S +219 -0
- data/ext/ffi_c/libffi/src/prep_cif.c +177 -0
- data/ext/ffi_c/libffi/src/raw_api.c +254 -0
- data/ext/ffi_c/libffi/src/s390/ffi.c +780 -0
- data/ext/ffi_c/libffi/src/s390/ffitarget.h +62 -0
- data/ext/ffi_c/libffi/src/s390/sysv.S +434 -0
- data/ext/ffi_c/libffi/src/sh/ffi.c +716 -0
- data/ext/ffi_c/libffi/src/sh/ffitarget.h +49 -0
- data/ext/ffi_c/libffi/src/sh/sysv.S +850 -0
- data/ext/ffi_c/libffi/src/sh64/ffi.c +468 -0
- data/ext/ffi_c/libffi/src/sh64/ffitarget.h +53 -0
- data/ext/ffi_c/libffi/src/sh64/sysv.S +539 -0
- data/ext/ffi_c/libffi/src/sparc/ffi.c +669 -0
- data/ext/ffi_c/libffi/src/sparc/ffitarget.h +68 -0
- data/ext/ffi_c/libffi/src/sparc/v8.S +313 -0
- data/ext/ffi_c/libffi/src/sparc/v9.S +307 -0
- data/ext/ffi_c/libffi/src/types.c +77 -0
- data/ext/ffi_c/libffi/src/x86/darwin.S +444 -0
- data/ext/ffi_c/libffi/src/x86/darwin64.S +416 -0
- data/ext/ffi_c/libffi/src/x86/ffi.c +644 -0
- data/ext/ffi_c/libffi/src/x86/ffi64.c +635 -0
- data/ext/ffi_c/libffi/src/x86/ffitarget.h +121 -0
- data/ext/ffi_c/libffi/src/x86/freebsd.S +458 -0
- data/ext/ffi_c/libffi/src/x86/sysv.S +468 -0
- data/ext/ffi_c/libffi/src/x86/unix64.S +426 -0
- data/ext/ffi_c/libffi/src/x86/win32.S +1065 -0
- data/ext/ffi_c/libffi/src/x86/win64.S +468 -0
- data/ext/ffi_c/libffi/testsuite/Makefile.am +80 -0
- data/ext/ffi_c/libffi/testsuite/Makefile.in +500 -0
- data/ext/ffi_c/libffi/testsuite/config/default.exp +1 -0
- data/ext/ffi_c/libffi/testsuite/lib/libffi-dg.exp +300 -0
- data/ext/ffi_c/libffi/testsuite/lib/libffi.exp +350 -0
- data/ext/ffi_c/libffi/testsuite/lib/target-libpath.exp +263 -0
- data/ext/ffi_c/libffi/testsuite/lib/wrapper.exp +45 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/call.exp +32 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn0.c +89 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn1.c +81 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn2.c +81 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn3.c +82 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn4.c +89 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn5.c +92 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn6.c +90 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/closure_loc_fn0.c +95 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/closure_stdcall.c +64 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_12byte.c +94 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_16byte.c +95 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_18byte.c +96 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_19byte.c +102 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_1_1byte.c +89 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_20byte.c +91 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_20byte1.c +93 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_24byte.c +113 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_2byte.c +90 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_3_1byte.c +95 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_3byte1.c +90 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_3byte2.c +90 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_4_1byte.c +98 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_4byte.c +90 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_5_1_byte.c +109 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_5byte.c +98 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_64byte.c +124 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_6_1_byte.c +113 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_6byte.c +99 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_7_1_byte.c +117 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_7byte.c +97 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_8byte.c +88 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_9byte1.c +90 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_9byte2.c +91 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_double.c +93 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_float.c +91 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_longdouble.c +92 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_longdouble_split.c +134 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_longdouble_split2.c +117 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_pointer.c +95 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_sint16.c +91 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_sint32.c +91 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_sint64.c +92 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_uint16.c +91 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_uint32.c +91 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_uint64.c +93 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_dbls_struct.c +66 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_double.c +43 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_double_va.c +60 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_float.c +42 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_longdouble.c +105 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_longdouble_va.c +60 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_schar.c +74 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_sshort.c +74 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_sshortchar.c +86 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_uchar.c +91 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_ushort.c +74 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_ushortchar.c +86 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_pointer.c +74 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_pointer_stack.c +140 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_schar.c +44 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_sint.c +42 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_sshort.c +42 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_uchar.c +42 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_uint.c +43 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_ulonglong.c +47 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_ushort.c +43 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/err_bad_abi.c +36 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/err_bad_typedef.c +26 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/ffitest.h +153 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/float.c +59 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/float1.c +58 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/float2.c +58 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/float3.c +72 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/float4.c +62 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/huge_struct.c +342 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/many.c +69 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/many_win32.c +63 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/negint.c +53 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct.c +152 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct1.c +161 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct10.c +133 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct2.c +110 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct3.c +111 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct4.c +111 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct5.c +112 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct6.c +131 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct7.c +111 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct8.c +131 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct9.c +131 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/problem1.c +90 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/promotion.c +59 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/pyobjc-tc.c +114 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/return_dbl.c +35 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/return_dbl1.c +43 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/return_dbl2.c +42 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/return_fl.c +35 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/return_fl1.c +36 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/return_fl2.c +49 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/return_fl3.c +42 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/return_ldl.c +34 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/return_ll.c +41 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/return_ll1.c +43 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/return_sc.c +36 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/return_sl.c +38 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/return_uc.c +38 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/return_ul.c +38 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/stret_large.c +145 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/stret_large2.c +148 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/stret_medium.c +124 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/stret_medium2.c +125 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/strlen.c +44 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/strlen_win32.c +44 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/struct1.c +65 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/struct2.c +67 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/struct3.c +59 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/struct4.c +63 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/struct5.c +65 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/struct6.c +64 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/struct7.c +74 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/struct8.c +80 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/struct9.c +67 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/testclosure.c +70 -0
- data/ext/ffi_c/libffi/testsuite/libffi.special/ffitestcxx.h +96 -0
- data/ext/ffi_c/libffi/testsuite/libffi.special/special.exp +35 -0
- data/ext/ffi_c/libffi/testsuite/libffi.special/unwindtest.cc +124 -0
- data/ext/ffi_c/libffi/testsuite/libffi.special/unwindtest_ffi_call.cc +53 -0
- data/ext/ffi_c/libffi/texinfo.tex +7210 -0
- data/ext/ffi_c/rbffi.h +57 -0
- data/ext/ffi_c/rbffi_endian.h +59 -0
- data/ext/ffi_c/win32/stdbool.h +8 -0
- data/ext/ffi_c/win32/stdint.h +201 -0
- data/ffi.gemspec +22 -0
- data/gen/Rakefile +30 -0
- data/lib/ffi.rb +28 -0
- data/lib/ffi/autopointer.rb +194 -0
- data/lib/ffi/buffer.rb +4 -0
- data/lib/ffi/callback.rb +4 -0
- data/lib/ffi/enum.rb +173 -0
- data/lib/ffi/errno.rb +43 -0
- data/lib/ffi/ffi.rb +44 -0
- data/lib/ffi/io.rb +62 -0
- data/lib/ffi/library.rb +499 -0
- data/lib/ffi/managedstruct.rb +84 -0
- data/lib/ffi/memorypointer.rb +1 -0
- data/lib/ffi/platform.rb +148 -0
- data/lib/ffi/platform/arm-linux/types.conf +104 -0
- data/lib/ffi/platform/i386-cygwin/types.conf +3 -0
- data/lib/ffi/platform/i386-darwin/types.conf +100 -0
- data/lib/ffi/platform/i386-freebsd/types.conf +152 -0
- data/lib/ffi/platform/i386-gnu/types.conf +107 -0
- data/lib/ffi/platform/i386-linux/types.conf +103 -0
- data/lib/ffi/platform/i386-netbsd/types.conf +126 -0
- data/lib/ffi/platform/i386-openbsd/types.conf +128 -0
- data/lib/ffi/platform/i386-solaris/types.conf +122 -0
- data/lib/ffi/platform/i386-windows/types.conf +105 -0
- data/lib/ffi/platform/ia64-linux/types.conf +104 -0
- data/lib/ffi/platform/mips-linux/types.conf +102 -0
- data/lib/ffi/platform/mipsel-linux/types.conf +102 -0
- data/lib/ffi/platform/powerpc-aix/types.conf +180 -0
- data/lib/ffi/platform/powerpc-darwin/types.conf +100 -0
- data/lib/ffi/platform/powerpc-linux/types.conf +100 -0
- data/lib/ffi/platform/s390-linux/types.conf +102 -0
- data/lib/ffi/platform/s390x-linux/types.conf +102 -0
- data/lib/ffi/platform/sparc-linux/types.conf +102 -0
- data/lib/ffi/platform/sparc-solaris/types.conf +128 -0
- data/lib/ffi/platform/sparcv9-solaris/types.conf +128 -0
- data/lib/ffi/platform/x86_64-cygwin/types.conf +3 -0
- data/lib/ffi/platform/x86_64-darwin/types.conf +100 -0
- data/lib/ffi/platform/x86_64-freebsd/types.conf +128 -0
- data/lib/ffi/platform/x86_64-linux/types.conf +102 -0
- data/lib/ffi/platform/x86_64-netbsd/types.conf +126 -0
- data/lib/ffi/platform/x86_64-openbsd/types.conf +128 -0
- data/lib/ffi/platform/x86_64-solaris/types.conf +122 -0
- data/lib/ffi/platform/x86_64-windows/types.conf +27 -0
- data/lib/ffi/pointer.rb +134 -0
- data/lib/ffi/struct.rb +367 -0
- data/lib/ffi/struct_layout_builder.rb +222 -0
- data/lib/ffi/tools/const_generator.rb +229 -0
- data/lib/ffi/tools/generator.rb +60 -0
- data/lib/ffi/tools/generator_task.rb +36 -0
- data/lib/ffi/tools/struct_generator.rb +194 -0
- data/lib/ffi/tools/types_generator.rb +135 -0
- data/lib/ffi/types.rb +190 -0
- data/lib/ffi/union.rb +43 -0
- data/lib/ffi/variadic.rb +78 -0
- data/lib/ffi/version.rb +4 -0
- data/lib/ffi_c.so +0 -0
- data/libtest/Benchmark.c +52 -0
- data/libtest/BoolTest.c +34 -0
- data/libtest/BufferTest.c +31 -0
- data/libtest/ClosureTest.c +190 -0
- data/libtest/EnumTest.c +34 -0
- data/libtest/FunctionTest.c +58 -0
- data/libtest/GNUmakefile +149 -0
- data/libtest/GlobalVariable.c +62 -0
- data/libtest/LastErrorTest.c +21 -0
- data/libtest/NumberTest.c +132 -0
- data/libtest/PointerTest.c +63 -0
- data/libtest/ReferenceTest.c +23 -0
- data/libtest/StringTest.c +34 -0
- data/libtest/StructTest.c +243 -0
- data/libtest/UnionTest.c +43 -0
- data/libtest/VariadicTest.c +62 -0
- data/spec/ffi/async_callback_spec.rb +35 -0
- data/spec/ffi/bool_spec.rb +29 -0
- data/spec/ffi/buffer_spec.rb +251 -0
- data/spec/ffi/callback_spec.rb +667 -0
- data/spec/ffi/custom_param_type.rb +36 -0
- data/spec/ffi/custom_type_spec.rb +74 -0
- data/spec/ffi/dup_spec.rb +54 -0
- data/spec/ffi/enum_spec.rb +220 -0
- data/spec/ffi/errno_spec.rb +18 -0
- data/spec/ffi/ffi_spec.rb +29 -0
- data/spec/ffi/function_spec.rb +76 -0
- data/spec/ffi/library_spec.rb +216 -0
- data/spec/ffi/long_double.rb +30 -0
- data/spec/ffi/managed_struct_spec.rb +57 -0
- data/spec/ffi/number_spec.rb +236 -0
- data/spec/ffi/pointer_spec.rb +265 -0
- data/spec/ffi/rbx/attach_function_spec.rb +28 -0
- data/spec/ffi/rbx/memory_pointer_spec.rb +123 -0
- data/spec/ffi/rbx/spec_helper.rb +1 -0
- data/spec/ffi/rbx/struct_spec.rb +13 -0
- data/spec/ffi/spec_helper.rb +33 -0
- data/spec/ffi/string_spec.rb +108 -0
- data/spec/ffi/strptr_spec.rb +50 -0
- data/spec/ffi/struct_by_ref_spec.rb +43 -0
- data/spec/ffi/struct_callback_spec.rb +69 -0
- data/spec/ffi/struct_initialize_spec.rb +35 -0
- data/spec/ffi/struct_packed_spec.rb +51 -0
- data/spec/ffi/struct_spec.rb +748 -0
- data/spec/ffi/typedef_spec.rb +78 -0
- data/spec/ffi/union_spec.rb +65 -0
- data/spec/ffi/variadic_spec.rb +92 -0
- data/spec/spec.opts +4 -0
- metadata +562 -0
@@ -0,0 +1,48 @@
|
|
1
|
+
/* -----------------------------------------------------------------*-C-*-
|
2
|
+
ffitarget.h - Copyright (c) 1996-2003 Red Hat, Inc.
|
3
|
+
Target configuration macros for Alpha.
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
``Software''), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be included
|
14
|
+
in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
20
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
21
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
22
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
23
|
+
DEALINGS IN THE SOFTWARE.
|
24
|
+
|
25
|
+
----------------------------------------------------------------------- */
|
26
|
+
|
27
|
+
#ifndef LIBFFI_TARGET_H
|
28
|
+
#define LIBFFI_TARGET_H
|
29
|
+
|
30
|
+
#ifndef LIBFFI_ASM
|
31
|
+
typedef unsigned long ffi_arg;
|
32
|
+
typedef signed long ffi_sarg;
|
33
|
+
|
34
|
+
typedef enum ffi_abi {
|
35
|
+
FFI_FIRST_ABI = 0,
|
36
|
+
FFI_OSF,
|
37
|
+
FFI_LAST_ABI,
|
38
|
+
FFI_DEFAULT_ABI = FFI_OSF
|
39
|
+
} ffi_abi;
|
40
|
+
#endif
|
41
|
+
|
42
|
+
/* ---- Definitions for closures ----------------------------------------- */
|
43
|
+
|
44
|
+
#define FFI_CLOSURES 1
|
45
|
+
#define FFI_TRAMPOLINE_SIZE 24
|
46
|
+
#define FFI_NATIVE_RAW_API 0
|
47
|
+
|
48
|
+
#endif
|
@@ -0,0 +1,387 @@
|
|
1
|
+
/* -----------------------------------------------------------------------
|
2
|
+
osf.S - Copyright (c) 1998, 2001, 2007, 2008, 2011 Red Hat
|
3
|
+
|
4
|
+
Alpha/OSF Foreign Function Interface
|
5
|
+
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
7
|
+
a copy of this software and associated documentation files (the
|
8
|
+
``Software''), to deal in the Software without restriction, including
|
9
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
10
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
11
|
+
permit persons to whom the Software is furnished to do so, subject to
|
12
|
+
the following conditions:
|
13
|
+
|
14
|
+
The above copyright notice and this permission notice shall be included
|
15
|
+
in all copies or substantial portions of the Software.
|
16
|
+
|
17
|
+
THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
|
18
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
19
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
20
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
21
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
22
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
23
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
24
|
+
DEALINGS IN THE SOFTWARE.
|
25
|
+
----------------------------------------------------------------------- */
|
26
|
+
|
27
|
+
#define LIBFFI_ASM
|
28
|
+
#include <fficonfig.h>
|
29
|
+
#include <ffi.h>
|
30
|
+
|
31
|
+
.arch ev6
|
32
|
+
.text
|
33
|
+
|
34
|
+
/* ffi_call_osf (void *args, unsigned long bytes, unsigned flags,
|
35
|
+
void *raddr, void (*fnaddr)(void));
|
36
|
+
|
37
|
+
Bit o trickiness here -- ARGS+BYTES is the base of the stack frame
|
38
|
+
for this function. This has been allocated by ffi_call. We also
|
39
|
+
deallocate some of the stack that has been alloca'd. */
|
40
|
+
|
41
|
+
.align 3
|
42
|
+
.globl ffi_call_osf
|
43
|
+
.ent ffi_call_osf
|
44
|
+
FFI_HIDDEN(ffi_call_osf)
|
45
|
+
|
46
|
+
ffi_call_osf:
|
47
|
+
.frame $15, 32, $26, 0
|
48
|
+
.mask 0x4008000, -32
|
49
|
+
$LFB1:
|
50
|
+
addq $16,$17,$1
|
51
|
+
mov $16, $30
|
52
|
+
stq $26, 0($1)
|
53
|
+
stq $15, 8($1)
|
54
|
+
stq $18, 16($1)
|
55
|
+
mov $1, $15
|
56
|
+
$LCFI1:
|
57
|
+
.prologue 0
|
58
|
+
|
59
|
+
stq $19, 24($1)
|
60
|
+
mov $20, $27
|
61
|
+
|
62
|
+
# Load up all of the (potential) argument registers.
|
63
|
+
ldq $16, 0($30)
|
64
|
+
ldt $f16, 0($30)
|
65
|
+
ldt $f17, 8($30)
|
66
|
+
ldq $17, 8($30)
|
67
|
+
ldt $f18, 16($30)
|
68
|
+
ldq $18, 16($30)
|
69
|
+
ldt $f19, 24($30)
|
70
|
+
ldq $19, 24($30)
|
71
|
+
ldt $f20, 32($30)
|
72
|
+
ldq $20, 32($30)
|
73
|
+
ldt $f21, 40($30)
|
74
|
+
ldq $21, 40($30)
|
75
|
+
|
76
|
+
# Deallocate the register argument area.
|
77
|
+
lda $30, 48($30)
|
78
|
+
|
79
|
+
jsr $26, ($27), 0
|
80
|
+
ldgp $29, 0($26)
|
81
|
+
|
82
|
+
# If the return value pointer is NULL, assume no return value.
|
83
|
+
ldq $19, 24($15)
|
84
|
+
ldq $18, 16($15)
|
85
|
+
ldq $26, 0($15)
|
86
|
+
$LCFI2:
|
87
|
+
beq $19, $noretval
|
88
|
+
|
89
|
+
# Store the return value out in the proper type.
|
90
|
+
cmpeq $18, FFI_TYPE_INT, $1
|
91
|
+
bne $1, $retint
|
92
|
+
cmpeq $18, FFI_TYPE_FLOAT, $2
|
93
|
+
bne $2, $retfloat
|
94
|
+
cmpeq $18, FFI_TYPE_DOUBLE, $3
|
95
|
+
bne $3, $retdouble
|
96
|
+
|
97
|
+
.align 3
|
98
|
+
$noretval:
|
99
|
+
ldq $15, 8($15)
|
100
|
+
ret
|
101
|
+
|
102
|
+
.align 4
|
103
|
+
$retint:
|
104
|
+
stq $0, 0($19)
|
105
|
+
nop
|
106
|
+
ldq $15, 8($15)
|
107
|
+
ret
|
108
|
+
|
109
|
+
.align 4
|
110
|
+
$retfloat:
|
111
|
+
sts $f0, 0($19)
|
112
|
+
nop
|
113
|
+
ldq $15, 8($15)
|
114
|
+
ret
|
115
|
+
|
116
|
+
.align 4
|
117
|
+
$retdouble:
|
118
|
+
stt $f0, 0($19)
|
119
|
+
nop
|
120
|
+
ldq $15, 8($15)
|
121
|
+
ret
|
122
|
+
$LFE1:
|
123
|
+
|
124
|
+
.end ffi_call_osf
|
125
|
+
|
126
|
+
/* ffi_closure_osf(...)
|
127
|
+
|
128
|
+
Receives the closure argument in $1. */
|
129
|
+
|
130
|
+
.align 3
|
131
|
+
.globl ffi_closure_osf
|
132
|
+
.ent ffi_closure_osf
|
133
|
+
FFI_HIDDEN(ffi_closure_osf)
|
134
|
+
|
135
|
+
ffi_closure_osf:
|
136
|
+
.frame $30, 16*8, $26, 0
|
137
|
+
.mask 0x4000000, -16*8
|
138
|
+
$LFB2:
|
139
|
+
ldgp $29, 0($27)
|
140
|
+
subq $30, 16*8, $30
|
141
|
+
$LCFI5:
|
142
|
+
stq $26, 0($30)
|
143
|
+
$LCFI6:
|
144
|
+
.prologue 1
|
145
|
+
|
146
|
+
# Store all of the potential argument registers in va_list format.
|
147
|
+
stt $f16, 4*8($30)
|
148
|
+
stt $f17, 5*8($30)
|
149
|
+
stt $f18, 6*8($30)
|
150
|
+
stt $f19, 7*8($30)
|
151
|
+
stt $f20, 8*8($30)
|
152
|
+
stt $f21, 9*8($30)
|
153
|
+
stq $16, 10*8($30)
|
154
|
+
stq $17, 11*8($30)
|
155
|
+
stq $18, 12*8($30)
|
156
|
+
stq $19, 13*8($30)
|
157
|
+
stq $20, 14*8($30)
|
158
|
+
stq $21, 15*8($30)
|
159
|
+
|
160
|
+
# Call ffi_closure_osf_inner to do the bulk of the work.
|
161
|
+
mov $1, $16
|
162
|
+
lda $17, 2*8($30)
|
163
|
+
lda $18, 10*8($30)
|
164
|
+
jsr $26, ffi_closure_osf_inner
|
165
|
+
ldgp $29, 0($26)
|
166
|
+
ldq $26, 0($30)
|
167
|
+
|
168
|
+
# Load up the return value in the proper type.
|
169
|
+
lda $1, $load_table
|
170
|
+
s4addq $0, $1, $1
|
171
|
+
ldl $1, 0($1)
|
172
|
+
addq $1, $29, $1
|
173
|
+
jmp $31, ($1), $load_32
|
174
|
+
|
175
|
+
.align 4
|
176
|
+
$load_none:
|
177
|
+
addq $30, 16*8, $30
|
178
|
+
ret
|
179
|
+
|
180
|
+
.align 4
|
181
|
+
$load_float:
|
182
|
+
lds $f0, 16($30)
|
183
|
+
nop
|
184
|
+
addq $30, 16*8, $30
|
185
|
+
ret
|
186
|
+
|
187
|
+
.align 4
|
188
|
+
$load_double:
|
189
|
+
ldt $f0, 16($30)
|
190
|
+
nop
|
191
|
+
addq $30, 16*8, $30
|
192
|
+
ret
|
193
|
+
|
194
|
+
.align 4
|
195
|
+
$load_u8:
|
196
|
+
#ifdef __alpha_bwx__
|
197
|
+
ldbu $0, 16($30)
|
198
|
+
nop
|
199
|
+
#else
|
200
|
+
ldq $0, 16($30)
|
201
|
+
and $0, 255, $0
|
202
|
+
#endif
|
203
|
+
addq $30, 16*8, $30
|
204
|
+
ret
|
205
|
+
|
206
|
+
.align 4
|
207
|
+
$load_s8:
|
208
|
+
#ifdef __alpha_bwx__
|
209
|
+
ldbu $0, 16($30)
|
210
|
+
sextb $0, $0
|
211
|
+
#else
|
212
|
+
ldq $0, 16($30)
|
213
|
+
sll $0, 56, $0
|
214
|
+
sra $0, 56, $0
|
215
|
+
#endif
|
216
|
+
addq $30, 16*8, $30
|
217
|
+
ret
|
218
|
+
|
219
|
+
.align 4
|
220
|
+
$load_u16:
|
221
|
+
#ifdef __alpha_bwx__
|
222
|
+
ldwu $0, 16($30)
|
223
|
+
nop
|
224
|
+
#else
|
225
|
+
ldq $0, 16($30)
|
226
|
+
zapnot $0, 3, $0
|
227
|
+
#endif
|
228
|
+
addq $30, 16*8, $30
|
229
|
+
ret
|
230
|
+
|
231
|
+
.align 4
|
232
|
+
$load_s16:
|
233
|
+
#ifdef __alpha_bwx__
|
234
|
+
ldwu $0, 16($30)
|
235
|
+
sextw $0, $0
|
236
|
+
#else
|
237
|
+
ldq $0, 16($30)
|
238
|
+
sll $0, 48, $0
|
239
|
+
sra $0, 48, $0
|
240
|
+
#endif
|
241
|
+
addq $30, 16*8, $30
|
242
|
+
ret
|
243
|
+
|
244
|
+
.align 4
|
245
|
+
$load_32:
|
246
|
+
ldl $0, 16($30)
|
247
|
+
nop
|
248
|
+
addq $30, 16*8, $30
|
249
|
+
ret
|
250
|
+
|
251
|
+
.align 4
|
252
|
+
$load_64:
|
253
|
+
ldq $0, 16($30)
|
254
|
+
nop
|
255
|
+
addq $30, 16*8, $30
|
256
|
+
ret
|
257
|
+
$LFE2:
|
258
|
+
|
259
|
+
.end ffi_closure_osf
|
260
|
+
|
261
|
+
#ifdef __ELF__
|
262
|
+
.section .rodata
|
263
|
+
#else
|
264
|
+
.rdata
|
265
|
+
#endif
|
266
|
+
$load_table:
|
267
|
+
.gprel32 $load_none # FFI_TYPE_VOID
|
268
|
+
.gprel32 $load_32 # FFI_TYPE_INT
|
269
|
+
.gprel32 $load_float # FFI_TYPE_FLOAT
|
270
|
+
.gprel32 $load_double # FFI_TYPE_DOUBLE
|
271
|
+
.gprel32 $load_none # FFI_TYPE_LONGDOUBLE
|
272
|
+
.gprel32 $load_u8 # FFI_TYPE_UINT8
|
273
|
+
.gprel32 $load_s8 # FFI_TYPE_SINT8
|
274
|
+
.gprel32 $load_u16 # FFI_TYPE_UINT16
|
275
|
+
.gprel32 $load_s16 # FFI_TYPE_SINT16
|
276
|
+
.gprel32 $load_32 # FFI_TYPE_UINT32
|
277
|
+
.gprel32 $load_32 # FFI_TYPE_SINT32
|
278
|
+
.gprel32 $load_64 # FFI_TYPE_UINT64
|
279
|
+
.gprel32 $load_64 # FFI_TYPE_SINT64
|
280
|
+
.gprel32 $load_none # FFI_TYPE_STRUCT
|
281
|
+
.gprel32 $load_64 # FFI_TYPE_POINTER
|
282
|
+
|
283
|
+
/* Assert that the table above is in sync with ffi.h. */
|
284
|
+
|
285
|
+
#if FFI_TYPE_FLOAT != 2 \
|
286
|
+
|| FFI_TYPE_DOUBLE != 3 \
|
287
|
+
|| FFI_TYPE_UINT8 != 5 \
|
288
|
+
|| FFI_TYPE_SINT8 != 6 \
|
289
|
+
|| FFI_TYPE_UINT16 != 7 \
|
290
|
+
|| FFI_TYPE_SINT16 != 8 \
|
291
|
+
|| FFI_TYPE_UINT32 != 9 \
|
292
|
+
|| FFI_TYPE_SINT32 != 10 \
|
293
|
+
|| FFI_TYPE_UINT64 != 11 \
|
294
|
+
|| FFI_TYPE_SINT64 != 12 \
|
295
|
+
|| FFI_TYPE_STRUCT != 13 \
|
296
|
+
|| FFI_TYPE_POINTER != 14 \
|
297
|
+
|| FFI_TYPE_LAST != 14
|
298
|
+
#error "osf.S out of sync with ffi.h"
|
299
|
+
#endif
|
300
|
+
|
301
|
+
#ifdef __ELF__
|
302
|
+
# define UA_SI .4byte
|
303
|
+
# define FDE_ENCODING 0x1b /* pcrel sdata4 */
|
304
|
+
# define FDE_ENCODE(X) .4byte X-.
|
305
|
+
# define FDE_ARANGE(X) .4byte X
|
306
|
+
#elif defined __osf__
|
307
|
+
# define UA_SI .align 0; .long
|
308
|
+
# define FDE_ENCODING 0x50 /* aligned absolute */
|
309
|
+
# define FDE_ENCODE(X) .align 3; .quad X
|
310
|
+
# define FDE_ARANGE(X) .align 0; .quad X
|
311
|
+
#endif
|
312
|
+
|
313
|
+
#ifdef __ELF__
|
314
|
+
.section .eh_frame,EH_FRAME_FLAGS,@progbits
|
315
|
+
#elif defined __osf__
|
316
|
+
.data
|
317
|
+
.align 3
|
318
|
+
.globl _GLOBAL__F_ffi_call_osf
|
319
|
+
_GLOBAL__F_ffi_call_osf:
|
320
|
+
#endif
|
321
|
+
__FRAME_BEGIN__:
|
322
|
+
UA_SI $LECIE1-$LSCIE1 # Length of Common Information Entry
|
323
|
+
$LSCIE1:
|
324
|
+
UA_SI 0x0 # CIE Identifier Tag
|
325
|
+
.byte 0x1 # CIE Version
|
326
|
+
.ascii "zR\0" # CIE Augmentation
|
327
|
+
.byte 0x1 # uleb128 0x1; CIE Code Alignment Factor
|
328
|
+
.byte 0x78 # sleb128 -8; CIE Data Alignment Factor
|
329
|
+
.byte 26 # CIE RA Column
|
330
|
+
.byte 0x1 # uleb128 0x1; Augmentation size
|
331
|
+
.byte FDE_ENCODING # FDE Encoding
|
332
|
+
.byte 0xc # DW_CFA_def_cfa
|
333
|
+
.byte 30 # uleb128 column 30
|
334
|
+
.byte 0 # uleb128 offset 0
|
335
|
+
.align 3
|
336
|
+
$LECIE1:
|
337
|
+
$LSFDE1:
|
338
|
+
UA_SI $LEFDE1-$LASFDE1 # FDE Length
|
339
|
+
$LASFDE1:
|
340
|
+
UA_SI $LASFDE1-__FRAME_BEGIN__ # FDE CIE offset
|
341
|
+
FDE_ENCODE($LFB1) # FDE initial location
|
342
|
+
FDE_ARANGE($LFE1-$LFB1) # FDE address range
|
343
|
+
.byte 0x0 # uleb128 0x0; Augmentation size
|
344
|
+
|
345
|
+
.byte 0x4 # DW_CFA_advance_loc4
|
346
|
+
UA_SI $LCFI1-$LFB1
|
347
|
+
.byte 0x9a # DW_CFA_offset, column 26
|
348
|
+
.byte 4 # uleb128 4*-8
|
349
|
+
.byte 0x8f # DW_CFA_offset, column 15
|
350
|
+
.byte 0x3 # uleb128 3*-8
|
351
|
+
.byte 0xc # DW_CFA_def_cfa
|
352
|
+
.byte 15 # uleb128 column 15
|
353
|
+
.byte 32 # uleb128 offset 32
|
354
|
+
|
355
|
+
.byte 0x4 # DW_CFA_advance_loc4
|
356
|
+
UA_SI $LCFI2-$LCFI1
|
357
|
+
.byte 0xda # DW_CFA_restore, column 26
|
358
|
+
.align 3
|
359
|
+
$LEFDE1:
|
360
|
+
|
361
|
+
$LSFDE3:
|
362
|
+
UA_SI $LEFDE3-$LASFDE3 # FDE Length
|
363
|
+
$LASFDE3:
|
364
|
+
UA_SI $LASFDE3-__FRAME_BEGIN__ # FDE CIE offset
|
365
|
+
FDE_ENCODE($LFB2) # FDE initial location
|
366
|
+
FDE_ARANGE($LFE2-$LFB2) # FDE address range
|
367
|
+
.byte 0x0 # uleb128 0x0; Augmentation size
|
368
|
+
|
369
|
+
.byte 0x4 # DW_CFA_advance_loc4
|
370
|
+
UA_SI $LCFI5-$LFB2
|
371
|
+
.byte 0xe # DW_CFA_def_cfa_offset
|
372
|
+
.byte 0x80,0x1 # uleb128 128
|
373
|
+
|
374
|
+
.byte 0x4 # DW_CFA_advance_loc4
|
375
|
+
UA_SI $LCFI6-$LCFI5
|
376
|
+
.byte 0x9a # DW_CFA_offset, column 26
|
377
|
+
.byte 16 # uleb128 offset 16*-8
|
378
|
+
.align 3
|
379
|
+
$LEFDE3:
|
380
|
+
#if defined __osf__
|
381
|
+
.align 0
|
382
|
+
.long 0 # End of Table
|
383
|
+
#endif
|
384
|
+
|
385
|
+
#if defined __ELF__ && defined __linux__
|
386
|
+
.section .note.GNU-stack,"",@progbits
|
387
|
+
#endif
|
@@ -0,0 +1,728 @@
|
|
1
|
+
/* -----------------------------------------------------------------------
|
2
|
+
ffi.c - Copyright (c) 2011 Plausible Labs Cooperative, Inc.
|
3
|
+
Copyright (c) 2011 Anthony Green
|
4
|
+
Copyright (c) 2011 Free Software Foundation
|
5
|
+
Copyright (c) 1998, 2008, 2011 Red Hat, Inc.
|
6
|
+
|
7
|
+
ARM Foreign Function Interface
|
8
|
+
|
9
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
10
|
+
a copy of this software and associated documentation files (the
|
11
|
+
``Software''), to deal in the Software without restriction, including
|
12
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
13
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
14
|
+
permit persons to whom the Software is furnished to do so, subject to
|
15
|
+
the following conditions:
|
16
|
+
|
17
|
+
The above copyright notice and this permission notice shall be included
|
18
|
+
in all copies or substantial portions of the Software.
|
19
|
+
|
20
|
+
THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
|
21
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
22
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
23
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
24
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
25
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
26
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
27
|
+
DEALINGS IN THE SOFTWARE.
|
28
|
+
----------------------------------------------------------------------- */
|
29
|
+
|
30
|
+
#include <ffi.h>
|
31
|
+
#include <ffi_common.h>
|
32
|
+
|
33
|
+
#include <stdlib.h>
|
34
|
+
|
35
|
+
/* Forward declares. */
|
36
|
+
static int vfp_type_p (ffi_type *);
|
37
|
+
static void layout_vfp_args (ffi_cif *);
|
38
|
+
|
39
|
+
/* ffi_prep_args is called by the assembly routine once stack space
|
40
|
+
has been allocated for the function's arguments
|
41
|
+
|
42
|
+
The vfp_space parameter is the load area for VFP regs, the return
|
43
|
+
value is cif->vfp_used (word bitset of VFP regs used for passing
|
44
|
+
arguments). These are only used for the VFP hard-float ABI.
|
45
|
+
*/
|
46
|
+
int ffi_prep_args(char *stack, extended_cif *ecif, float *vfp_space)
|
47
|
+
{
|
48
|
+
register unsigned int i, vi = 0;
|
49
|
+
register void **p_argv;
|
50
|
+
register char *argp;
|
51
|
+
register ffi_type **p_arg;
|
52
|
+
|
53
|
+
argp = stack;
|
54
|
+
|
55
|
+
if ( ecif->cif->flags == FFI_TYPE_STRUCT ) {
|
56
|
+
*(void **) argp = ecif->rvalue;
|
57
|
+
argp += 4;
|
58
|
+
}
|
59
|
+
|
60
|
+
p_argv = ecif->avalue;
|
61
|
+
|
62
|
+
for (i = ecif->cif->nargs, p_arg = ecif->cif->arg_types;
|
63
|
+
(i != 0);
|
64
|
+
i--, p_arg++)
|
65
|
+
{
|
66
|
+
size_t z;
|
67
|
+
|
68
|
+
/* Allocated in VFP registers. */
|
69
|
+
if (ecif->cif->abi == FFI_VFP
|
70
|
+
&& vi < ecif->cif->vfp_nargs && vfp_type_p (*p_arg))
|
71
|
+
{
|
72
|
+
float* vfp_slot = vfp_space + ecif->cif->vfp_args[vi++];
|
73
|
+
if ((*p_arg)->type == FFI_TYPE_FLOAT)
|
74
|
+
*((float*)vfp_slot) = *((float*)*p_argv);
|
75
|
+
else if ((*p_arg)->type == FFI_TYPE_DOUBLE)
|
76
|
+
*((double*)vfp_slot) = *((double*)*p_argv);
|
77
|
+
else
|
78
|
+
memcpy(vfp_slot, *p_argv, (*p_arg)->size);
|
79
|
+
p_argv++;
|
80
|
+
continue;
|
81
|
+
}
|
82
|
+
|
83
|
+
/* Align if necessary */
|
84
|
+
if (((*p_arg)->alignment - 1) & (unsigned) argp) {
|
85
|
+
argp = (char *) ALIGN(argp, (*p_arg)->alignment);
|
86
|
+
}
|
87
|
+
|
88
|
+
if ((*p_arg)->type == FFI_TYPE_STRUCT)
|
89
|
+
argp = (char *) ALIGN(argp, 4);
|
90
|
+
|
91
|
+
z = (*p_arg)->size;
|
92
|
+
if (z < sizeof(int))
|
93
|
+
{
|
94
|
+
z = sizeof(int);
|
95
|
+
switch ((*p_arg)->type)
|
96
|
+
{
|
97
|
+
case FFI_TYPE_SINT8:
|
98
|
+
*(signed int *) argp = (signed int)*(SINT8 *)(* p_argv);
|
99
|
+
break;
|
100
|
+
|
101
|
+
case FFI_TYPE_UINT8:
|
102
|
+
*(unsigned int *) argp = (unsigned int)*(UINT8 *)(* p_argv);
|
103
|
+
break;
|
104
|
+
|
105
|
+
case FFI_TYPE_SINT16:
|
106
|
+
*(signed int *) argp = (signed int)*(SINT16 *)(* p_argv);
|
107
|
+
break;
|
108
|
+
|
109
|
+
case FFI_TYPE_UINT16:
|
110
|
+
*(unsigned int *) argp = (unsigned int)*(UINT16 *)(* p_argv);
|
111
|
+
break;
|
112
|
+
|
113
|
+
case FFI_TYPE_STRUCT:
|
114
|
+
memcpy(argp, *p_argv, (*p_arg)->size);
|
115
|
+
break;
|
116
|
+
|
117
|
+
default:
|
118
|
+
FFI_ASSERT(0);
|
119
|
+
}
|
120
|
+
}
|
121
|
+
else if (z == sizeof(int))
|
122
|
+
{
|
123
|
+
*(unsigned int *) argp = (unsigned int)*(UINT32 *)(* p_argv);
|
124
|
+
}
|
125
|
+
else
|
126
|
+
{
|
127
|
+
memcpy(argp, *p_argv, z);
|
128
|
+
}
|
129
|
+
p_argv++;
|
130
|
+
argp += z;
|
131
|
+
}
|
132
|
+
|
133
|
+
/* Indicate the VFP registers used. */
|
134
|
+
return ecif->cif->vfp_used;
|
135
|
+
}
|
136
|
+
|
137
|
+
/* Perform machine dependent cif processing */
|
138
|
+
ffi_status ffi_prep_cif_machdep(ffi_cif *cif)
|
139
|
+
{
|
140
|
+
int type_code;
|
141
|
+
/* Round the stack up to a multiple of 8 bytes. This isn't needed
|
142
|
+
everywhere, but it is on some platforms, and it doesn't harm anything
|
143
|
+
when it isn't needed. */
|
144
|
+
cif->bytes = (cif->bytes + 7) & ~7;
|
145
|
+
|
146
|
+
/* Set the return type flag */
|
147
|
+
switch (cif->rtype->type)
|
148
|
+
{
|
149
|
+
case FFI_TYPE_VOID:
|
150
|
+
case FFI_TYPE_FLOAT:
|
151
|
+
case FFI_TYPE_DOUBLE:
|
152
|
+
cif->flags = (unsigned) cif->rtype->type;
|
153
|
+
break;
|
154
|
+
|
155
|
+
case FFI_TYPE_SINT64:
|
156
|
+
case FFI_TYPE_UINT64:
|
157
|
+
cif->flags = (unsigned) FFI_TYPE_SINT64;
|
158
|
+
break;
|
159
|
+
|
160
|
+
case FFI_TYPE_STRUCT:
|
161
|
+
if (cif->abi == FFI_VFP
|
162
|
+
&& (type_code = vfp_type_p (cif->rtype)) != 0)
|
163
|
+
{
|
164
|
+
/* A Composite Type passed in VFP registers, either
|
165
|
+
FFI_TYPE_STRUCT_VFP_FLOAT or FFI_TYPE_STRUCT_VFP_DOUBLE. */
|
166
|
+
cif->flags = (unsigned) type_code;
|
167
|
+
}
|
168
|
+
else if (cif->rtype->size <= 4)
|
169
|
+
/* A Composite Type not larger than 4 bytes is returned in r0. */
|
170
|
+
cif->flags = (unsigned)FFI_TYPE_INT;
|
171
|
+
else
|
172
|
+
/* A Composite Type larger than 4 bytes, or whose size cannot
|
173
|
+
be determined statically ... is stored in memory at an
|
174
|
+
address passed [in r0]. */
|
175
|
+
cif->flags = (unsigned)FFI_TYPE_STRUCT;
|
176
|
+
break;
|
177
|
+
|
178
|
+
default:
|
179
|
+
cif->flags = FFI_TYPE_INT;
|
180
|
+
break;
|
181
|
+
}
|
182
|
+
|
183
|
+
/* Map out the register placements of VFP register args.
|
184
|
+
The VFP hard-float calling conventions are slightly more sophisticated than
|
185
|
+
the base calling conventions, so we do it here instead of in ffi_prep_args(). */
|
186
|
+
if (cif->abi == FFI_VFP)
|
187
|
+
layout_vfp_args (cif);
|
188
|
+
|
189
|
+
return FFI_OK;
|
190
|
+
}
|
191
|
+
|
192
|
+
/* Prototypes for assembly functions, in sysv.S */
|
193
|
+
extern void ffi_call_SYSV (void (*fn)(void), extended_cif *, unsigned, unsigned, unsigned *);
|
194
|
+
extern void ffi_call_VFP (void (*fn)(void), extended_cif *, unsigned, unsigned, unsigned *);
|
195
|
+
|
196
|
+
void ffi_call(ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue)
|
197
|
+
{
|
198
|
+
extended_cif ecif;
|
199
|
+
|
200
|
+
int small_struct = (cif->flags == FFI_TYPE_INT
|
201
|
+
&& cif->rtype->type == FFI_TYPE_STRUCT);
|
202
|
+
int vfp_struct = (cif->flags == FFI_TYPE_STRUCT_VFP_FLOAT
|
203
|
+
|| cif->flags == FFI_TYPE_STRUCT_VFP_DOUBLE);
|
204
|
+
|
205
|
+
ecif.cif = cif;
|
206
|
+
ecif.avalue = avalue;
|
207
|
+
|
208
|
+
unsigned int temp;
|
209
|
+
|
210
|
+
/* If the return value is a struct and we don't have a return */
|
211
|
+
/* value address then we need to make one */
|
212
|
+
|
213
|
+
if ((rvalue == NULL) &&
|
214
|
+
(cif->flags == FFI_TYPE_STRUCT))
|
215
|
+
{
|
216
|
+
ecif.rvalue = alloca(cif->rtype->size);
|
217
|
+
}
|
218
|
+
else if (small_struct)
|
219
|
+
ecif.rvalue = &temp;
|
220
|
+
else if (vfp_struct)
|
221
|
+
{
|
222
|
+
/* Largest case is double x 4. */
|
223
|
+
ecif.rvalue = alloca(32);
|
224
|
+
}
|
225
|
+
else
|
226
|
+
ecif.rvalue = rvalue;
|
227
|
+
|
228
|
+
switch (cif->abi)
|
229
|
+
{
|
230
|
+
case FFI_SYSV:
|
231
|
+
ffi_call_SYSV (fn, &ecif, cif->bytes, cif->flags, ecif.rvalue);
|
232
|
+
break;
|
233
|
+
|
234
|
+
case FFI_VFP:
|
235
|
+
ffi_call_VFP (fn, &ecif, cif->bytes, cif->flags, ecif.rvalue);
|
236
|
+
break;
|
237
|
+
|
238
|
+
default:
|
239
|
+
FFI_ASSERT(0);
|
240
|
+
break;
|
241
|
+
}
|
242
|
+
if (small_struct)
|
243
|
+
memcpy (rvalue, &temp, cif->rtype->size);
|
244
|
+
else if (vfp_struct)
|
245
|
+
memcpy (rvalue, ecif.rvalue, cif->rtype->size);
|
246
|
+
}
|
247
|
+
|
248
|
+
/** private members **/
|
249
|
+
|
250
|
+
static void ffi_prep_incoming_args_SYSV (char *stack, void **ret,
|
251
|
+
void** args, ffi_cif* cif, float *vfp_stack);
|
252
|
+
|
253
|
+
void ffi_closure_SYSV (ffi_closure *);
|
254
|
+
|
255
|
+
void ffi_closure_VFP (ffi_closure *);
|
256
|
+
|
257
|
+
/* This function is jumped to by the trampoline */
|
258
|
+
|
259
|
+
unsigned int
|
260
|
+
ffi_closure_SYSV_inner (closure, respp, args, vfp_args)
|
261
|
+
ffi_closure *closure;
|
262
|
+
void **respp;
|
263
|
+
void *args;
|
264
|
+
void *vfp_args;
|
265
|
+
{
|
266
|
+
// our various things...
|
267
|
+
ffi_cif *cif;
|
268
|
+
void **arg_area;
|
269
|
+
|
270
|
+
cif = closure->cif;
|
271
|
+
arg_area = (void**) alloca (cif->nargs * sizeof (void*));
|
272
|
+
|
273
|
+
/* this call will initialize ARG_AREA, such that each
|
274
|
+
* element in that array points to the corresponding
|
275
|
+
* value on the stack; and if the function returns
|
276
|
+
* a structure, it will re-set RESP to point to the
|
277
|
+
* structure return address. */
|
278
|
+
|
279
|
+
ffi_prep_incoming_args_SYSV(args, respp, arg_area, cif, vfp_args);
|
280
|
+
|
281
|
+
(closure->fun) (cif, *respp, arg_area, closure->user_data);
|
282
|
+
|
283
|
+
return cif->flags;
|
284
|
+
}
|
285
|
+
|
286
|
+
/*@-exportheader@*/
|
287
|
+
static void
|
288
|
+
ffi_prep_incoming_args_SYSV(char *stack, void **rvalue,
|
289
|
+
void **avalue, ffi_cif *cif,
|
290
|
+
/* Used only under VFP hard-float ABI. */
|
291
|
+
float *vfp_stack)
|
292
|
+
/*@=exportheader@*/
|
293
|
+
{
|
294
|
+
register unsigned int i, vi = 0;
|
295
|
+
register void **p_argv;
|
296
|
+
register char *argp;
|
297
|
+
register ffi_type **p_arg;
|
298
|
+
|
299
|
+
argp = stack;
|
300
|
+
|
301
|
+
if ( cif->flags == FFI_TYPE_STRUCT ) {
|
302
|
+
*rvalue = *(void **) argp;
|
303
|
+
argp += 4;
|
304
|
+
}
|
305
|
+
|
306
|
+
p_argv = avalue;
|
307
|
+
|
308
|
+
for (i = cif->nargs, p_arg = cif->arg_types; (i != 0); i--, p_arg++)
|
309
|
+
{
|
310
|
+
size_t z;
|
311
|
+
size_t alignment;
|
312
|
+
|
313
|
+
if (cif->abi == FFI_VFP
|
314
|
+
&& vi < cif->vfp_nargs && vfp_type_p (*p_arg))
|
315
|
+
{
|
316
|
+
*p_argv++ = (void*)(vfp_stack + cif->vfp_args[vi++]);
|
317
|
+
continue;
|
318
|
+
}
|
319
|
+
|
320
|
+
alignment = (*p_arg)->alignment;
|
321
|
+
if (alignment < 4)
|
322
|
+
alignment = 4;
|
323
|
+
/* Align if necessary */
|
324
|
+
if ((alignment - 1) & (unsigned) argp) {
|
325
|
+
argp = (char *) ALIGN(argp, alignment);
|
326
|
+
}
|
327
|
+
|
328
|
+
z = (*p_arg)->size;
|
329
|
+
|
330
|
+
/* because we're little endian, this is what it turns into. */
|
331
|
+
|
332
|
+
*p_argv = (void*) argp;
|
333
|
+
|
334
|
+
p_argv++;
|
335
|
+
argp += z;
|
336
|
+
}
|
337
|
+
|
338
|
+
return;
|
339
|
+
}
|
340
|
+
|
341
|
+
/* How to make a trampoline. */
|
342
|
+
|
343
|
+
#if FFI_EXEC_TRAMPOLINE_TABLE
|
344
|
+
|
345
|
+
#include <mach/mach.h>
|
346
|
+
#include <pthread.h>
|
347
|
+
#include <stdio.h>
|
348
|
+
#include <stdlib.h>
|
349
|
+
|
350
|
+
extern void *ffi_closure_trampoline_table_page;
|
351
|
+
|
352
|
+
typedef struct ffi_trampoline_table ffi_trampoline_table;
|
353
|
+
typedef struct ffi_trampoline_table_entry ffi_trampoline_table_entry;
|
354
|
+
|
355
|
+
struct ffi_trampoline_table {
|
356
|
+
/* contigious writable and executable pages */
|
357
|
+
vm_address_t config_page;
|
358
|
+
vm_address_t trampoline_page;
|
359
|
+
|
360
|
+
/* free list tracking */
|
361
|
+
uint16_t free_count;
|
362
|
+
ffi_trampoline_table_entry *free_list;
|
363
|
+
ffi_trampoline_table_entry *free_list_pool;
|
364
|
+
|
365
|
+
ffi_trampoline_table *prev;
|
366
|
+
ffi_trampoline_table *next;
|
367
|
+
};
|
368
|
+
|
369
|
+
struct ffi_trampoline_table_entry {
|
370
|
+
void *(*trampoline)();
|
371
|
+
ffi_trampoline_table_entry *next;
|
372
|
+
};
|
373
|
+
|
374
|
+
/* Override the standard architecture trampoline size */
|
375
|
+
// XXX TODO - Fix
|
376
|
+
#undef FFI_TRAMPOLINE_SIZE
|
377
|
+
#define FFI_TRAMPOLINE_SIZE 12
|
378
|
+
|
379
|
+
/* The trampoline configuration is placed at 4080 bytes prior to the trampoline's entry point */
|
380
|
+
#define FFI_TRAMPOLINE_CODELOC_CONFIG(codeloc) ((void **) (((uint8_t *) codeloc) - 4080));
|
381
|
+
|
382
|
+
/* The first 16 bytes of the config page are unused, as they are unaddressable from the trampoline page. */
|
383
|
+
#define FFI_TRAMPOLINE_CONFIG_PAGE_OFFSET 16
|
384
|
+
|
385
|
+
/* Total number of trampolines that fit in one trampoline table */
|
386
|
+
#define FFI_TRAMPOLINE_COUNT ((PAGE_SIZE - FFI_TRAMPOLINE_CONFIG_PAGE_OFFSET) / FFI_TRAMPOLINE_SIZE)
|
387
|
+
|
388
|
+
static pthread_mutex_t ffi_trampoline_lock = PTHREAD_MUTEX_INITIALIZER;
|
389
|
+
static ffi_trampoline_table *ffi_trampoline_tables = NULL;
|
390
|
+
|
391
|
+
static ffi_trampoline_table *
|
392
|
+
ffi_trampoline_table_alloc ()
|
393
|
+
{
|
394
|
+
ffi_trampoline_table *table = NULL;
|
395
|
+
|
396
|
+
/* Loop until we can allocate two contigious pages */
|
397
|
+
while (table == NULL) {
|
398
|
+
vm_address_t config_page = 0x0;
|
399
|
+
kern_return_t kt;
|
400
|
+
|
401
|
+
/* Try to allocate two pages */
|
402
|
+
kt = vm_allocate (mach_task_self (), &config_page, PAGE_SIZE*2, VM_FLAGS_ANYWHERE);
|
403
|
+
if (kt != KERN_SUCCESS) {
|
404
|
+
fprintf(stderr, "vm_allocate() failure: %d at %s:%d\n", kt, __FILE__, __LINE__);
|
405
|
+
break;
|
406
|
+
}
|
407
|
+
|
408
|
+
/* Now drop the second half of the allocation to make room for the trampoline table */
|
409
|
+
vm_address_t trampoline_page = config_page+PAGE_SIZE;
|
410
|
+
kt = vm_deallocate (mach_task_self (), trampoline_page, PAGE_SIZE);
|
411
|
+
if (kt != KERN_SUCCESS) {
|
412
|
+
fprintf(stderr, "vm_deallocate() failure: %d at %s:%d\n", kt, __FILE__, __LINE__);
|
413
|
+
break;
|
414
|
+
}
|
415
|
+
|
416
|
+
/* Remap the trampoline table to directly follow the config page */
|
417
|
+
vm_prot_t cur_prot;
|
418
|
+
vm_prot_t max_prot;
|
419
|
+
|
420
|
+
kt = vm_remap (mach_task_self (), &trampoline_page, PAGE_SIZE, 0x0, FALSE, mach_task_self (), (vm_address_t) &ffi_closure_trampoline_table_page, FALSE, &cur_prot, &max_prot, VM_INHERIT_SHARE);
|
421
|
+
|
422
|
+
/* If we lost access to the destination trampoline page, drop our config allocation mapping and retry */
|
423
|
+
if (kt != KERN_SUCCESS) {
|
424
|
+
/* Log unexpected failures */
|
425
|
+
if (kt != KERN_NO_SPACE) {
|
426
|
+
fprintf(stderr, "vm_remap() failure: %d at %s:%d\n", kt, __FILE__, __LINE__);
|
427
|
+
}
|
428
|
+
|
429
|
+
vm_deallocate (mach_task_self (), config_page, PAGE_SIZE);
|
430
|
+
continue;
|
431
|
+
}
|
432
|
+
|
433
|
+
/* We have valid trampoline and config pages */
|
434
|
+
table = calloc (1, sizeof(ffi_trampoline_table));
|
435
|
+
table->free_count = FFI_TRAMPOLINE_COUNT;
|
436
|
+
table->config_page = config_page;
|
437
|
+
table->trampoline_page = trampoline_page;
|
438
|
+
|
439
|
+
/* Create and initialize the free list */
|
440
|
+
table->free_list_pool = calloc(FFI_TRAMPOLINE_COUNT, sizeof(ffi_trampoline_table_entry));
|
441
|
+
|
442
|
+
uint16_t i;
|
443
|
+
for (i = 0; i < table->free_count; i++) {
|
444
|
+
ffi_trampoline_table_entry *entry = &table->free_list_pool[i];
|
445
|
+
entry->trampoline = (void *) (table->trampoline_page + (i * FFI_TRAMPOLINE_SIZE));
|
446
|
+
|
447
|
+
if (i < table->free_count - 1)
|
448
|
+
entry->next = &table->free_list_pool[i+1];
|
449
|
+
}
|
450
|
+
|
451
|
+
table->free_list = table->free_list_pool;
|
452
|
+
}
|
453
|
+
|
454
|
+
return table;
|
455
|
+
}
|
456
|
+
|
457
|
+
void *
|
458
|
+
ffi_closure_alloc (size_t size, void **code)
|
459
|
+
{
|
460
|
+
/* Create the closure */
|
461
|
+
ffi_closure *closure = malloc(size);
|
462
|
+
if (closure == NULL)
|
463
|
+
return NULL;
|
464
|
+
|
465
|
+
pthread_mutex_lock(&ffi_trampoline_lock);
|
466
|
+
|
467
|
+
/* Check for an active trampoline table with available entries. */
|
468
|
+
ffi_trampoline_table *table = ffi_trampoline_tables;
|
469
|
+
if (table == NULL || table->free_list == NULL) {
|
470
|
+
table = ffi_trampoline_table_alloc ();
|
471
|
+
if (table == NULL) {
|
472
|
+
free(closure);
|
473
|
+
return NULL;
|
474
|
+
}
|
475
|
+
|
476
|
+
/* Insert the new table at the top of the list */
|
477
|
+
table->next = ffi_trampoline_tables;
|
478
|
+
if (table->next != NULL)
|
479
|
+
table->next->prev = table;
|
480
|
+
|
481
|
+
ffi_trampoline_tables = table;
|
482
|
+
}
|
483
|
+
|
484
|
+
/* Claim the free entry */
|
485
|
+
ffi_trampoline_table_entry *entry = ffi_trampoline_tables->free_list;
|
486
|
+
ffi_trampoline_tables->free_list = entry->next;
|
487
|
+
ffi_trampoline_tables->free_count--;
|
488
|
+
entry->next = NULL;
|
489
|
+
|
490
|
+
pthread_mutex_unlock(&ffi_trampoline_lock);
|
491
|
+
|
492
|
+
/* Initialize the return values */
|
493
|
+
*code = entry->trampoline;
|
494
|
+
closure->trampoline_table = table;
|
495
|
+
closure->trampoline_table_entry = entry;
|
496
|
+
|
497
|
+
return closure;
|
498
|
+
}
|
499
|
+
|
500
|
+
void
|
501
|
+
ffi_closure_free (void *ptr)
|
502
|
+
{
|
503
|
+
ffi_closure *closure = ptr;
|
504
|
+
|
505
|
+
pthread_mutex_lock(&ffi_trampoline_lock);
|
506
|
+
|
507
|
+
/* Fetch the table and entry references */
|
508
|
+
ffi_trampoline_table *table = closure->trampoline_table;
|
509
|
+
ffi_trampoline_table_entry *entry = closure->trampoline_table_entry;
|
510
|
+
|
511
|
+
/* Return the entry to the free list */
|
512
|
+
entry->next = table->free_list;
|
513
|
+
table->free_list = entry;
|
514
|
+
table->free_count++;
|
515
|
+
|
516
|
+
/* If all trampolines within this table are free, and at least one other table exists, deallocate
|
517
|
+
* the table */
|
518
|
+
if (table->free_count == FFI_TRAMPOLINE_COUNT && ffi_trampoline_tables != table) {
|
519
|
+
/* Remove from the list */
|
520
|
+
if (table->prev != NULL)
|
521
|
+
table->prev->next = table->next;
|
522
|
+
|
523
|
+
if (table->next != NULL)
|
524
|
+
table->next->prev = table->prev;
|
525
|
+
|
526
|
+
/* Deallocate pages */
|
527
|
+
kern_return_t kt;
|
528
|
+
kt = vm_deallocate (mach_task_self (), table->config_page, PAGE_SIZE);
|
529
|
+
if (kt != KERN_SUCCESS)
|
530
|
+
fprintf(stderr, "vm_deallocate() failure: %d at %s:%d\n", kt, __FILE__, __LINE__);
|
531
|
+
|
532
|
+
kt = vm_deallocate (mach_task_self (), table->trampoline_page, PAGE_SIZE);
|
533
|
+
if (kt != KERN_SUCCESS)
|
534
|
+
fprintf(stderr, "vm_deallocate() failure: %d at %s:%d\n", kt, __FILE__, __LINE__);
|
535
|
+
|
536
|
+
/* Deallocate free list */
|
537
|
+
free (table->free_list_pool);
|
538
|
+
free (table);
|
539
|
+
} else if (ffi_trampoline_tables != table) {
|
540
|
+
/* Otherwise, bump this table to the top of the list */
|
541
|
+
table->prev = NULL;
|
542
|
+
table->next = ffi_trampoline_tables;
|
543
|
+
if (ffi_trampoline_tables != NULL)
|
544
|
+
ffi_trampoline_tables->prev = table;
|
545
|
+
|
546
|
+
ffi_trampoline_tables = table;
|
547
|
+
}
|
548
|
+
|
549
|
+
pthread_mutex_unlock (&ffi_trampoline_lock);
|
550
|
+
|
551
|
+
/* Free the closure */
|
552
|
+
free (closure);
|
553
|
+
}
|
554
|
+
|
555
|
+
#else
|
556
|
+
|
557
|
+
#define FFI_INIT_TRAMPOLINE(TRAMP,FUN,CTX) \
|
558
|
+
({ unsigned char *__tramp = (unsigned char*)(TRAMP); \
|
559
|
+
unsigned int __fun = (unsigned int)(FUN); \
|
560
|
+
unsigned int __ctx = (unsigned int)(CTX); \
|
561
|
+
unsigned char *insns = (unsigned char *)(CTX); \
|
562
|
+
*(unsigned int*) &__tramp[0] = 0xe92d000f; /* stmfd sp!, {r0-r3} */ \
|
563
|
+
*(unsigned int*) &__tramp[4] = 0xe59f0000; /* ldr r0, [pc] */ \
|
564
|
+
*(unsigned int*) &__tramp[8] = 0xe59ff000; /* ldr pc, [pc] */ \
|
565
|
+
*(unsigned int*) &__tramp[12] = __ctx; \
|
566
|
+
*(unsigned int*) &__tramp[16] = __fun; \
|
567
|
+
__clear_cache((&__tramp[0]), (&__tramp[19])); /* Clear data mapping. */ \
|
568
|
+
__clear_cache(insns, insns + 3 * sizeof (unsigned int)); \
|
569
|
+
/* Clear instruction \
|
570
|
+
mapping. */ \
|
571
|
+
})
|
572
|
+
|
573
|
+
#endif
|
574
|
+
|
575
|
+
/* the cif must already be prep'ed */
|
576
|
+
|
577
|
+
ffi_status
|
578
|
+
ffi_prep_closure_loc (ffi_closure* closure,
|
579
|
+
ffi_cif* cif,
|
580
|
+
void (*fun)(ffi_cif*,void*,void**,void*),
|
581
|
+
void *user_data,
|
582
|
+
void *codeloc)
|
583
|
+
{
|
584
|
+
void (*closure_func)(ffi_closure*) = NULL;
|
585
|
+
|
586
|
+
if (cif->abi == FFI_SYSV)
|
587
|
+
closure_func = &ffi_closure_SYSV;
|
588
|
+
else if (cif->abi == FFI_VFP)
|
589
|
+
closure_func = &ffi_closure_VFP;
|
590
|
+
else
|
591
|
+
return FFI_BAD_ABI;
|
592
|
+
|
593
|
+
#if FFI_EXEC_TRAMPOLINE_TABLE
|
594
|
+
void **config = FFI_TRAMPOLINE_CODELOC_CONFIG(codeloc);
|
595
|
+
config[0] = closure;
|
596
|
+
config[1] = closure_func;
|
597
|
+
#else
|
598
|
+
FFI_INIT_TRAMPOLINE (&closure->tramp[0], \
|
599
|
+
closure_func, \
|
600
|
+
codeloc);
|
601
|
+
#endif
|
602
|
+
|
603
|
+
closure->cif = cif;
|
604
|
+
closure->user_data = user_data;
|
605
|
+
closure->fun = fun;
|
606
|
+
|
607
|
+
return FFI_OK;
|
608
|
+
}
|
609
|
+
|
610
|
+
/* Below are routines for VFP hard-float support. */
|
611
|
+
|
612
|
+
static int rec_vfp_type_p (ffi_type *t, int *elt, int *elnum)
|
613
|
+
{
|
614
|
+
switch (t->type)
|
615
|
+
{
|
616
|
+
case FFI_TYPE_FLOAT:
|
617
|
+
case FFI_TYPE_DOUBLE:
|
618
|
+
*elt = (int) t->type;
|
619
|
+
*elnum = 1;
|
620
|
+
return 1;
|
621
|
+
|
622
|
+
case FFI_TYPE_STRUCT_VFP_FLOAT:
|
623
|
+
*elt = FFI_TYPE_FLOAT;
|
624
|
+
*elnum = t->size / sizeof (float);
|
625
|
+
return 1;
|
626
|
+
|
627
|
+
case FFI_TYPE_STRUCT_VFP_DOUBLE:
|
628
|
+
*elt = FFI_TYPE_DOUBLE;
|
629
|
+
*elnum = t->size / sizeof (double);
|
630
|
+
return 1;
|
631
|
+
|
632
|
+
case FFI_TYPE_STRUCT:;
|
633
|
+
{
|
634
|
+
int base_elt = 0, total_elnum = 0;
|
635
|
+
ffi_type **el = t->elements;
|
636
|
+
while (*el)
|
637
|
+
{
|
638
|
+
int el_elt = 0, el_elnum = 0;
|
639
|
+
if (! rec_vfp_type_p (*el, &el_elt, &el_elnum)
|
640
|
+
|| (base_elt && base_elt != el_elt)
|
641
|
+
|| total_elnum + el_elnum > 4)
|
642
|
+
return 0;
|
643
|
+
base_elt = el_elt;
|
644
|
+
total_elnum += el_elnum;
|
645
|
+
el++;
|
646
|
+
}
|
647
|
+
*elnum = total_elnum;
|
648
|
+
*elt = base_elt;
|
649
|
+
return 1;
|
650
|
+
}
|
651
|
+
default: ;
|
652
|
+
}
|
653
|
+
return 0;
|
654
|
+
}
|
655
|
+
|
656
|
+
static int vfp_type_p (ffi_type *t)
|
657
|
+
{
|
658
|
+
int elt, elnum;
|
659
|
+
if (rec_vfp_type_p (t, &elt, &elnum))
|
660
|
+
{
|
661
|
+
if (t->type == FFI_TYPE_STRUCT)
|
662
|
+
{
|
663
|
+
if (elnum == 1)
|
664
|
+
t->type = elt;
|
665
|
+
else
|
666
|
+
t->type = (elt == FFI_TYPE_FLOAT
|
667
|
+
? FFI_TYPE_STRUCT_VFP_FLOAT
|
668
|
+
: FFI_TYPE_STRUCT_VFP_DOUBLE);
|
669
|
+
}
|
670
|
+
return (int) t->type;
|
671
|
+
}
|
672
|
+
return 0;
|
673
|
+
}
|
674
|
+
|
675
|
+
static void place_vfp_arg (ffi_cif *cif, ffi_type *t)
|
676
|
+
{
|
677
|
+
int reg = cif->vfp_reg_free;
|
678
|
+
int nregs = t->size / sizeof (float);
|
679
|
+
int align = ((t->type == FFI_TYPE_STRUCT_VFP_FLOAT
|
680
|
+
|| t->type == FFI_TYPE_FLOAT) ? 1 : 2);
|
681
|
+
/* Align register number. */
|
682
|
+
if ((reg & 1) && align == 2)
|
683
|
+
reg++;
|
684
|
+
while (reg + nregs <= 16)
|
685
|
+
{
|
686
|
+
int s, new_used = 0;
|
687
|
+
for (s = reg; s < reg + nregs; s++)
|
688
|
+
{
|
689
|
+
new_used |= (1 << s);
|
690
|
+
if (cif->vfp_used & (1 << s))
|
691
|
+
{
|
692
|
+
reg += align;
|
693
|
+
goto next_reg;
|
694
|
+
}
|
695
|
+
}
|
696
|
+
/* Found regs to allocate. */
|
697
|
+
cif->vfp_used |= new_used;
|
698
|
+
cif->vfp_args[cif->vfp_nargs++] = reg;
|
699
|
+
|
700
|
+
/* Update vfp_reg_free. */
|
701
|
+
if (cif->vfp_used & (1 << cif->vfp_reg_free))
|
702
|
+
{
|
703
|
+
reg += nregs;
|
704
|
+
while (cif->vfp_used & (1 << reg))
|
705
|
+
reg += 1;
|
706
|
+
cif->vfp_reg_free = reg;
|
707
|
+
}
|
708
|
+
return;
|
709
|
+
next_reg: ;
|
710
|
+
}
|
711
|
+
}
|
712
|
+
|
713
|
+
static void layout_vfp_args (ffi_cif *cif)
|
714
|
+
{
|
715
|
+
int i;
|
716
|
+
/* Init VFP fields */
|
717
|
+
cif->vfp_used = 0;
|
718
|
+
cif->vfp_nargs = 0;
|
719
|
+
cif->vfp_reg_free = 0;
|
720
|
+
memset (cif->vfp_args, -1, 16); /* Init to -1. */
|
721
|
+
|
722
|
+
for (i = 0; i < cif->nargs; i++)
|
723
|
+
{
|
724
|
+
ffi_type *t = cif->arg_types[i];
|
725
|
+
if (vfp_type_p (t))
|
726
|
+
place_vfp_arg (cif, t);
|
727
|
+
}
|
728
|
+
}
|