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,208 @@
|
|
1
|
+
/* -----------------------------------------------------------------------
|
2
|
+
sysv.S - Copyright (c) 2009 Bradley Smith <brad@brad-smith.co.uk>
|
3
|
+
|
4
|
+
AVR32 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 NONINFRINGEMENT.
|
20
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
21
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
22
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
23
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
24
|
+
--------------------------------------------------------------------- */
|
25
|
+
|
26
|
+
#define LIBFFI_ASM
|
27
|
+
#include <fficonfig.h>
|
28
|
+
#include <ffi.h>
|
29
|
+
|
30
|
+
/* r12: ffi_prep_args
|
31
|
+
* r11: &ecif
|
32
|
+
* r10: size
|
33
|
+
* r9: cif->flags
|
34
|
+
* r8: ecif.rvalue
|
35
|
+
* sp+0: cif->rstruct_flag
|
36
|
+
* sp+4: fn */
|
37
|
+
|
38
|
+
.text
|
39
|
+
.align 1
|
40
|
+
.globl ffi_call_SYSV
|
41
|
+
.type ffi_call_SYSV, @function
|
42
|
+
ffi_call_SYSV:
|
43
|
+
stm --sp, r0,r1,lr
|
44
|
+
stm --sp, r8-r12
|
45
|
+
mov r0, sp
|
46
|
+
|
47
|
+
/* Make room for all of the new args. */
|
48
|
+
sub sp, r10
|
49
|
+
/* Pad to make way for potential skipped registers */
|
50
|
+
sub sp, 20
|
51
|
+
|
52
|
+
/* Call ffi_prep_args(stack, &ecif). */
|
53
|
+
/* r11 already set */
|
54
|
+
mov r1, r12
|
55
|
+
mov r12, sp
|
56
|
+
icall r1
|
57
|
+
|
58
|
+
/* Save new argument size */
|
59
|
+
mov r1, r12
|
60
|
+
|
61
|
+
/* Move first 5 parameters in registers. */
|
62
|
+
ldm sp++, r8-r12
|
63
|
+
|
64
|
+
/* call (fn) (...). */
|
65
|
+
ld.w r1, r0[36]
|
66
|
+
icall r1
|
67
|
+
|
68
|
+
/* Remove the space we pushed for the args. */
|
69
|
+
mov sp, r0
|
70
|
+
|
71
|
+
/* Load r1 with the rstruct flag. */
|
72
|
+
ld.w r1, sp[32]
|
73
|
+
|
74
|
+
/* Load r9 with the return type code. */
|
75
|
+
ld.w r9, sp[12]
|
76
|
+
|
77
|
+
/* Load r8 with the return value pointer. */
|
78
|
+
ld.w r8, sp[16]
|
79
|
+
|
80
|
+
/* If the return value pointer is NULL, assume no return value. */
|
81
|
+
cp.w r8, 0
|
82
|
+
breq .Lend
|
83
|
+
|
84
|
+
/* Check if return type is actually a struct */
|
85
|
+
cp.w r1, 0
|
86
|
+
breq 1f
|
87
|
+
|
88
|
+
/* Return 8bit */
|
89
|
+
cp.w r9, FFI_TYPE_UINT8
|
90
|
+
breq .Lstore8
|
91
|
+
|
92
|
+
/* Return 16bit */
|
93
|
+
cp.w r9, FFI_TYPE_UINT16
|
94
|
+
breq .Lstore16
|
95
|
+
|
96
|
+
1:
|
97
|
+
/* Return 32bit */
|
98
|
+
cp.w r9, FFI_TYPE_UINT32
|
99
|
+
breq .Lstore32
|
100
|
+
cp.w r9, FFI_TYPE_UINT16
|
101
|
+
breq .Lstore32
|
102
|
+
cp.w r9, FFI_TYPE_UINT8
|
103
|
+
breq .Lstore32
|
104
|
+
|
105
|
+
/* Return 64bit */
|
106
|
+
cp.w r9, FFI_TYPE_UINT64
|
107
|
+
breq .Lstore64
|
108
|
+
|
109
|
+
/* Didn't match anything */
|
110
|
+
bral .Lend
|
111
|
+
|
112
|
+
.Lstore64:
|
113
|
+
st.w r8[0], r11
|
114
|
+
st.w r8[4], r10
|
115
|
+
bral .Lend
|
116
|
+
|
117
|
+
.Lstore32:
|
118
|
+
st.w r8[0], r12
|
119
|
+
bral .Lend
|
120
|
+
|
121
|
+
.Lstore16:
|
122
|
+
st.h r8[0], r12
|
123
|
+
bral .Lend
|
124
|
+
|
125
|
+
.Lstore8:
|
126
|
+
st.b r8[0], r12
|
127
|
+
bral .Lend
|
128
|
+
|
129
|
+
.Lend:
|
130
|
+
sub sp, -20
|
131
|
+
ldm sp++, r0,r1,pc
|
132
|
+
|
133
|
+
.size ffi_call_SYSV, . - ffi_call_SYSV
|
134
|
+
|
135
|
+
|
136
|
+
/* r12: __ctx
|
137
|
+
* r11: __rstruct_flag
|
138
|
+
* r10: __inner */
|
139
|
+
|
140
|
+
.align 1
|
141
|
+
.globl ffi_closure_SYSV
|
142
|
+
.type ffi_closure_SYSV, @function
|
143
|
+
ffi_closure_SYSV:
|
144
|
+
stm --sp, r0,lr
|
145
|
+
mov r0, r11
|
146
|
+
mov r8, r10
|
147
|
+
sub r10, sp, -8
|
148
|
+
sub sp, 12
|
149
|
+
st.w sp[8], sp
|
150
|
+
sub r11, sp, -8
|
151
|
+
icall r8
|
152
|
+
|
153
|
+
/* Check if return type is actually a struct */
|
154
|
+
cp.w r0, 0
|
155
|
+
breq 1f
|
156
|
+
|
157
|
+
/* Return 8bit */
|
158
|
+
cp.w r12, FFI_TYPE_UINT8
|
159
|
+
breq .Lget8
|
160
|
+
|
161
|
+
/* Return 16bit */
|
162
|
+
cp.w r12, FFI_TYPE_UINT16
|
163
|
+
breq .Lget16
|
164
|
+
|
165
|
+
1:
|
166
|
+
/* Return 32bit */
|
167
|
+
cp.w r12, FFI_TYPE_UINT32
|
168
|
+
breq .Lget32
|
169
|
+
cp.w r12, FFI_TYPE_UINT16
|
170
|
+
breq .Lget32
|
171
|
+
cp.w r12, FFI_TYPE_UINT8
|
172
|
+
breq .Lget32
|
173
|
+
|
174
|
+
/* Return 64bit */
|
175
|
+
cp.w r12, FFI_TYPE_UINT64
|
176
|
+
breq .Lget64
|
177
|
+
|
178
|
+
/* Didn't match anything */
|
179
|
+
bral .Lclend
|
180
|
+
|
181
|
+
.Lget64:
|
182
|
+
ld.w r11, sp[0]
|
183
|
+
ld.w r10, sp[4]
|
184
|
+
bral .Lclend
|
185
|
+
|
186
|
+
.Lget32:
|
187
|
+
ld.w r12, sp[0]
|
188
|
+
bral .Lclend
|
189
|
+
|
190
|
+
.Lget16:
|
191
|
+
ld.uh r12, sp[0]
|
192
|
+
bral .Lclend
|
193
|
+
|
194
|
+
.Lget8:
|
195
|
+
ld.ub r12, sp[0]
|
196
|
+
bral .Lclend
|
197
|
+
|
198
|
+
.Lclend:
|
199
|
+
sub sp, -12
|
200
|
+
ldm sp++, r0,lr
|
201
|
+
sub sp, -20
|
202
|
+
mov pc, lr
|
203
|
+
|
204
|
+
.size ffi_closure_SYSV, . - ffi_closure_SYSV
|
205
|
+
|
206
|
+
#if defined __ELF__ && defined __linux__
|
207
|
+
.section .note.GNU-stack,"",@progbits
|
208
|
+
#endif
|
@@ -0,0 +1,615 @@
|
|
1
|
+
/* -----------------------------------------------------------------------
|
2
|
+
closures.c - Copyright (c) 2007, 2009, 2010 Red Hat, Inc.
|
3
|
+
Copyright (C) 2007, 2009, 2010 Free Software Foundation, Inc
|
4
|
+
Copyright (c) 2011 Plausible Labs Cooperative, Inc.
|
5
|
+
|
6
|
+
Code to allocate and deallocate memory for closures.
|
7
|
+
|
8
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
9
|
+
a copy of this software and associated documentation files (the
|
10
|
+
``Software''), to deal in the Software without restriction, including
|
11
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
12
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
13
|
+
permit persons to whom the Software is furnished to do so, subject to
|
14
|
+
the following conditions:
|
15
|
+
|
16
|
+
The above copyright notice and this permission notice shall be included
|
17
|
+
in all copies or substantial portions of the Software.
|
18
|
+
|
19
|
+
THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
|
20
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
21
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
22
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
23
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
24
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
26
|
+
DEALINGS IN THE SOFTWARE.
|
27
|
+
----------------------------------------------------------------------- */
|
28
|
+
|
29
|
+
#if defined __linux__ && !defined _GNU_SOURCE
|
30
|
+
#define _GNU_SOURCE 1
|
31
|
+
#endif
|
32
|
+
|
33
|
+
#include <ffi.h>
|
34
|
+
#include <ffi_common.h>
|
35
|
+
|
36
|
+
#if !FFI_MMAP_EXEC_WRIT && !FFI_EXEC_TRAMPOLINE_TABLE
|
37
|
+
# if __gnu_linux__
|
38
|
+
/* This macro indicates it may be forbidden to map anonymous memory
|
39
|
+
with both write and execute permission. Code compiled when this
|
40
|
+
option is defined will attempt to map such pages once, but if it
|
41
|
+
fails, it falls back to creating a temporary file in a writable and
|
42
|
+
executable filesystem and mapping pages from it into separate
|
43
|
+
locations in the virtual memory space, one location writable and
|
44
|
+
another executable. */
|
45
|
+
# define FFI_MMAP_EXEC_WRIT 1
|
46
|
+
# define HAVE_MNTENT 1
|
47
|
+
# endif
|
48
|
+
# if defined(X86_WIN32) || defined(X86_WIN64) || defined(__OS2__)
|
49
|
+
/* Windows systems may have Data Execution Protection (DEP) enabled,
|
50
|
+
which requires the use of VirtualMalloc/VirtualFree to alloc/free
|
51
|
+
executable memory. */
|
52
|
+
# define FFI_MMAP_EXEC_WRIT 1
|
53
|
+
# endif
|
54
|
+
#endif
|
55
|
+
|
56
|
+
#if FFI_MMAP_EXEC_WRIT && !defined FFI_MMAP_EXEC_SELINUX
|
57
|
+
# ifdef __linux__
|
58
|
+
/* When defined to 1 check for SELinux and if SELinux is active,
|
59
|
+
don't attempt PROT_EXEC|PROT_WRITE mapping at all, as that
|
60
|
+
might cause audit messages. */
|
61
|
+
# define FFI_MMAP_EXEC_SELINUX 1
|
62
|
+
# endif
|
63
|
+
#endif
|
64
|
+
|
65
|
+
#if FFI_CLOSURES
|
66
|
+
|
67
|
+
# if FFI_EXEC_TRAMPOLINE_TABLE
|
68
|
+
|
69
|
+
// Per-target implementation; It's unclear what can reasonable be shared between two OS/architecture implementations.
|
70
|
+
|
71
|
+
# elif FFI_MMAP_EXEC_WRIT /* !FFI_EXEC_TRAMPOLINE_TABLE */
|
72
|
+
|
73
|
+
#define USE_LOCKS 1
|
74
|
+
#define USE_DL_PREFIX 1
|
75
|
+
#ifdef __GNUC__
|
76
|
+
#ifndef USE_BUILTIN_FFS
|
77
|
+
#define USE_BUILTIN_FFS 1
|
78
|
+
#endif
|
79
|
+
#endif
|
80
|
+
|
81
|
+
/* We need to use mmap, not sbrk. */
|
82
|
+
#define HAVE_MORECORE 0
|
83
|
+
|
84
|
+
/* We could, in theory, support mremap, but it wouldn't buy us anything. */
|
85
|
+
#define HAVE_MREMAP 0
|
86
|
+
|
87
|
+
/* We have no use for this, so save some code and data. */
|
88
|
+
#define NO_MALLINFO 1
|
89
|
+
|
90
|
+
/* We need all allocations to be in regular segments, otherwise we
|
91
|
+
lose track of the corresponding code address. */
|
92
|
+
#define DEFAULT_MMAP_THRESHOLD MAX_SIZE_T
|
93
|
+
|
94
|
+
/* Don't allocate more than a page unless needed. */
|
95
|
+
#define DEFAULT_GRANULARITY ((size_t)malloc_getpagesize)
|
96
|
+
|
97
|
+
#if FFI_CLOSURE_TEST
|
98
|
+
/* Don't release single pages, to avoid a worst-case scenario of
|
99
|
+
continuously allocating and releasing single pages, but release
|
100
|
+
pairs of pages, which should do just as well given that allocations
|
101
|
+
are likely to be small. */
|
102
|
+
#define DEFAULT_TRIM_THRESHOLD ((size_t)malloc_getpagesize)
|
103
|
+
#endif
|
104
|
+
|
105
|
+
#include <sys/types.h>
|
106
|
+
#include <sys/stat.h>
|
107
|
+
#include <fcntl.h>
|
108
|
+
#include <errno.h>
|
109
|
+
#ifndef _MSC_VER
|
110
|
+
#include <unistd.h>
|
111
|
+
#endif
|
112
|
+
#include <string.h>
|
113
|
+
#include <stdio.h>
|
114
|
+
#if !defined(X86_WIN32) && !defined(X86_WIN64)
|
115
|
+
#ifdef HAVE_MNTENT
|
116
|
+
#include <mntent.h>
|
117
|
+
#endif /* HAVE_MNTENT */
|
118
|
+
#include <sys/param.h>
|
119
|
+
#include <pthread.h>
|
120
|
+
|
121
|
+
/* We don't want sys/mman.h to be included after we redefine mmap and
|
122
|
+
dlmunmap. */
|
123
|
+
#include <sys/mman.h>
|
124
|
+
#define LACKS_SYS_MMAN_H 1
|
125
|
+
|
126
|
+
#if FFI_MMAP_EXEC_SELINUX
|
127
|
+
#include <sys/statfs.h>
|
128
|
+
#include <stdlib.h>
|
129
|
+
|
130
|
+
static int selinux_enabled = -1;
|
131
|
+
|
132
|
+
static int
|
133
|
+
selinux_enabled_check (void)
|
134
|
+
{
|
135
|
+
struct statfs sfs;
|
136
|
+
FILE *f;
|
137
|
+
char *buf = NULL;
|
138
|
+
size_t len = 0;
|
139
|
+
|
140
|
+
if (statfs ("/selinux", &sfs) >= 0
|
141
|
+
&& (unsigned int) sfs.f_type == 0xf97cff8cU)
|
142
|
+
return 1;
|
143
|
+
f = fopen ("/proc/mounts", "r");
|
144
|
+
if (f == NULL)
|
145
|
+
return 0;
|
146
|
+
while (getline (&buf, &len, f) >= 0)
|
147
|
+
{
|
148
|
+
char *p = strchr (buf, ' ');
|
149
|
+
if (p == NULL)
|
150
|
+
break;
|
151
|
+
p = strchr (p + 1, ' ');
|
152
|
+
if (p == NULL)
|
153
|
+
break;
|
154
|
+
if (strncmp (p + 1, "selinuxfs ", 10) == 0)
|
155
|
+
{
|
156
|
+
free (buf);
|
157
|
+
fclose (f);
|
158
|
+
return 1;
|
159
|
+
}
|
160
|
+
}
|
161
|
+
free (buf);
|
162
|
+
fclose (f);
|
163
|
+
return 0;
|
164
|
+
}
|
165
|
+
|
166
|
+
#define is_selinux_enabled() (selinux_enabled >= 0 ? selinux_enabled \
|
167
|
+
: (selinux_enabled = selinux_enabled_check ()))
|
168
|
+
|
169
|
+
#else
|
170
|
+
|
171
|
+
#define is_selinux_enabled() 0
|
172
|
+
|
173
|
+
#endif /* !FFI_MMAP_EXEC_SELINUX */
|
174
|
+
|
175
|
+
#elif defined (__CYGWIN__) || defined(__INTERIX)
|
176
|
+
|
177
|
+
#include <sys/mman.h>
|
178
|
+
|
179
|
+
/* Cygwin is Linux-like, but not quite that Linux-like. */
|
180
|
+
#define is_selinux_enabled() 0
|
181
|
+
|
182
|
+
#endif /* !defined(X86_WIN32) && !defined(X86_WIN64) */
|
183
|
+
|
184
|
+
/* Declare all functions defined in dlmalloc.c as static. */
|
185
|
+
static void *dlmalloc(size_t);
|
186
|
+
static void dlfree(void*);
|
187
|
+
static void *dlcalloc(size_t, size_t) MAYBE_UNUSED;
|
188
|
+
static void *dlrealloc(void *, size_t) MAYBE_UNUSED;
|
189
|
+
static void *dlmemalign(size_t, size_t) MAYBE_UNUSED;
|
190
|
+
static void *dlvalloc(size_t) MAYBE_UNUSED;
|
191
|
+
static int dlmallopt(int, int) MAYBE_UNUSED;
|
192
|
+
static size_t dlmalloc_footprint(void) MAYBE_UNUSED;
|
193
|
+
static size_t dlmalloc_max_footprint(void) MAYBE_UNUSED;
|
194
|
+
static void** dlindependent_calloc(size_t, size_t, void**) MAYBE_UNUSED;
|
195
|
+
static void** dlindependent_comalloc(size_t, size_t*, void**) MAYBE_UNUSED;
|
196
|
+
static void *dlpvalloc(size_t) MAYBE_UNUSED;
|
197
|
+
static int dlmalloc_trim(size_t) MAYBE_UNUSED;
|
198
|
+
static size_t dlmalloc_usable_size(void*) MAYBE_UNUSED;
|
199
|
+
static void dlmalloc_stats(void) MAYBE_UNUSED;
|
200
|
+
|
201
|
+
#if !(defined(X86_WIN32) || defined(X86_WIN64) || defined(__OS2__)) || defined (__CYGWIN__) || defined(__INTERIX)
|
202
|
+
/* Use these for mmap and munmap within dlmalloc.c. */
|
203
|
+
static void *dlmmap(void *, size_t, int, int, int, off_t);
|
204
|
+
static int dlmunmap(void *, size_t);
|
205
|
+
#endif /* !(defined(X86_WIN32) || defined(X86_WIN64) || defined(__OS2__)) || defined (__CYGWIN__) || defined(__INTERIX) */
|
206
|
+
|
207
|
+
#define mmap dlmmap
|
208
|
+
#define munmap dlmunmap
|
209
|
+
|
210
|
+
#include "dlmalloc.c"
|
211
|
+
|
212
|
+
#undef mmap
|
213
|
+
#undef munmap
|
214
|
+
|
215
|
+
#if !(defined(X86_WIN32) || defined(X86_WIN64) || defined(__OS2__)) || defined (__CYGWIN__) || defined(__INTERIX)
|
216
|
+
|
217
|
+
/* A mutex used to synchronize access to *exec* variables in this file. */
|
218
|
+
static pthread_mutex_t open_temp_exec_file_mutex = PTHREAD_MUTEX_INITIALIZER;
|
219
|
+
|
220
|
+
/* A file descriptor of a temporary file from which we'll map
|
221
|
+
executable pages. */
|
222
|
+
static int execfd = -1;
|
223
|
+
|
224
|
+
/* The amount of space already allocated from the temporary file. */
|
225
|
+
static size_t execsize = 0;
|
226
|
+
|
227
|
+
/* Open a temporary file name, and immediately unlink it. */
|
228
|
+
static int
|
229
|
+
open_temp_exec_file_name (char *name)
|
230
|
+
{
|
231
|
+
int fd = mkstemp (name);
|
232
|
+
|
233
|
+
if (fd != -1)
|
234
|
+
unlink (name);
|
235
|
+
|
236
|
+
return fd;
|
237
|
+
}
|
238
|
+
|
239
|
+
/* Open a temporary file in the named directory. */
|
240
|
+
static int
|
241
|
+
open_temp_exec_file_dir (const char *dir)
|
242
|
+
{
|
243
|
+
static const char suffix[] = "/ffiXXXXXX";
|
244
|
+
int lendir = strlen (dir);
|
245
|
+
char *tempname = __builtin_alloca (lendir + sizeof (suffix));
|
246
|
+
|
247
|
+
if (!tempname)
|
248
|
+
return -1;
|
249
|
+
|
250
|
+
memcpy (tempname, dir, lendir);
|
251
|
+
memcpy (tempname + lendir, suffix, sizeof (suffix));
|
252
|
+
|
253
|
+
return open_temp_exec_file_name (tempname);
|
254
|
+
}
|
255
|
+
|
256
|
+
/* Open a temporary file in the directory in the named environment
|
257
|
+
variable. */
|
258
|
+
static int
|
259
|
+
open_temp_exec_file_env (const char *envvar)
|
260
|
+
{
|
261
|
+
const char *value = getenv (envvar);
|
262
|
+
|
263
|
+
if (!value)
|
264
|
+
return -1;
|
265
|
+
|
266
|
+
return open_temp_exec_file_dir (value);
|
267
|
+
}
|
268
|
+
|
269
|
+
#ifdef HAVE_MNTENT
|
270
|
+
/* Open a temporary file in an executable and writable mount point
|
271
|
+
listed in the mounts file. Subsequent calls with the same mounts
|
272
|
+
keep searching for mount points in the same file. Providing NULL
|
273
|
+
as the mounts file closes the file. */
|
274
|
+
static int
|
275
|
+
open_temp_exec_file_mnt (const char *mounts)
|
276
|
+
{
|
277
|
+
static const char *last_mounts;
|
278
|
+
static FILE *last_mntent;
|
279
|
+
|
280
|
+
if (mounts != last_mounts)
|
281
|
+
{
|
282
|
+
if (last_mntent)
|
283
|
+
endmntent (last_mntent);
|
284
|
+
|
285
|
+
last_mounts = mounts;
|
286
|
+
|
287
|
+
if (mounts)
|
288
|
+
last_mntent = setmntent (mounts, "r");
|
289
|
+
else
|
290
|
+
last_mntent = NULL;
|
291
|
+
}
|
292
|
+
|
293
|
+
if (!last_mntent)
|
294
|
+
return -1;
|
295
|
+
|
296
|
+
for (;;)
|
297
|
+
{
|
298
|
+
int fd;
|
299
|
+
struct mntent mnt;
|
300
|
+
char buf[MAXPATHLEN * 3];
|
301
|
+
|
302
|
+
if (getmntent_r (last_mntent, &mnt, buf, sizeof (buf)) == NULL)
|
303
|
+
return -1;
|
304
|
+
|
305
|
+
if (hasmntopt (&mnt, "ro")
|
306
|
+
|| hasmntopt (&mnt, "noexec")
|
307
|
+
|| access (mnt.mnt_dir, W_OK))
|
308
|
+
continue;
|
309
|
+
|
310
|
+
fd = open_temp_exec_file_dir (mnt.mnt_dir);
|
311
|
+
|
312
|
+
if (fd != -1)
|
313
|
+
return fd;
|
314
|
+
}
|
315
|
+
}
|
316
|
+
#endif /* HAVE_MNTENT */
|
317
|
+
|
318
|
+
/* Instructions to look for a location to hold a temporary file that
|
319
|
+
can be mapped in for execution. */
|
320
|
+
static struct
|
321
|
+
{
|
322
|
+
int (*func)(const char *);
|
323
|
+
const char *arg;
|
324
|
+
int repeat;
|
325
|
+
} open_temp_exec_file_opts[] = {
|
326
|
+
{ open_temp_exec_file_env, "TMPDIR", 0 },
|
327
|
+
{ open_temp_exec_file_dir, "/tmp", 0 },
|
328
|
+
{ open_temp_exec_file_dir, "/var/tmp", 0 },
|
329
|
+
{ open_temp_exec_file_dir, "/dev/shm", 0 },
|
330
|
+
{ open_temp_exec_file_env, "HOME", 0 },
|
331
|
+
#ifdef HAVE_MNTENT
|
332
|
+
{ open_temp_exec_file_mnt, "/etc/mtab", 1 },
|
333
|
+
{ open_temp_exec_file_mnt, "/proc/mounts", 1 },
|
334
|
+
#endif /* HAVE_MNTENT */
|
335
|
+
};
|
336
|
+
|
337
|
+
/* Current index into open_temp_exec_file_opts. */
|
338
|
+
static int open_temp_exec_file_opts_idx = 0;
|
339
|
+
|
340
|
+
/* Reset a current multi-call func, then advances to the next entry.
|
341
|
+
If we're at the last, go back to the first and return nonzero,
|
342
|
+
otherwise return zero. */
|
343
|
+
static int
|
344
|
+
open_temp_exec_file_opts_next (void)
|
345
|
+
{
|
346
|
+
if (open_temp_exec_file_opts[open_temp_exec_file_opts_idx].repeat)
|
347
|
+
open_temp_exec_file_opts[open_temp_exec_file_opts_idx].func (NULL);
|
348
|
+
|
349
|
+
open_temp_exec_file_opts_idx++;
|
350
|
+
if (open_temp_exec_file_opts_idx
|
351
|
+
== (sizeof (open_temp_exec_file_opts)
|
352
|
+
/ sizeof (*open_temp_exec_file_opts)))
|
353
|
+
{
|
354
|
+
open_temp_exec_file_opts_idx = 0;
|
355
|
+
return 1;
|
356
|
+
}
|
357
|
+
|
358
|
+
return 0;
|
359
|
+
}
|
360
|
+
|
361
|
+
/* Return a file descriptor of a temporary zero-sized file in a
|
362
|
+
writable and exexutable filesystem. */
|
363
|
+
static int
|
364
|
+
open_temp_exec_file (void)
|
365
|
+
{
|
366
|
+
int fd;
|
367
|
+
|
368
|
+
do
|
369
|
+
{
|
370
|
+
fd = open_temp_exec_file_opts[open_temp_exec_file_opts_idx].func
|
371
|
+
(open_temp_exec_file_opts[open_temp_exec_file_opts_idx].arg);
|
372
|
+
|
373
|
+
if (!open_temp_exec_file_opts[open_temp_exec_file_opts_idx].repeat
|
374
|
+
|| fd == -1)
|
375
|
+
{
|
376
|
+
if (open_temp_exec_file_opts_next ())
|
377
|
+
break;
|
378
|
+
}
|
379
|
+
}
|
380
|
+
while (fd == -1);
|
381
|
+
|
382
|
+
return fd;
|
383
|
+
}
|
384
|
+
|
385
|
+
/* Map in a chunk of memory from the temporary exec file into separate
|
386
|
+
locations in the virtual memory address space, one writable and one
|
387
|
+
executable. Returns the address of the writable portion, after
|
388
|
+
storing an offset to the corresponding executable portion at the
|
389
|
+
last word of the requested chunk. */
|
390
|
+
static void *
|
391
|
+
dlmmap_locked (void *start, size_t length, int prot, int flags, off_t offset)
|
392
|
+
{
|
393
|
+
void *ptr;
|
394
|
+
|
395
|
+
if (execfd == -1)
|
396
|
+
{
|
397
|
+
open_temp_exec_file_opts_idx = 0;
|
398
|
+
retry_open:
|
399
|
+
execfd = open_temp_exec_file ();
|
400
|
+
if (execfd == -1)
|
401
|
+
return MFAIL;
|
402
|
+
}
|
403
|
+
|
404
|
+
offset = execsize;
|
405
|
+
|
406
|
+
if (ftruncate (execfd, offset + length))
|
407
|
+
return MFAIL;
|
408
|
+
|
409
|
+
flags &= ~(MAP_PRIVATE | MAP_ANONYMOUS);
|
410
|
+
flags |= MAP_SHARED;
|
411
|
+
|
412
|
+
ptr = mmap (NULL, length, (prot & ~PROT_WRITE) | PROT_EXEC,
|
413
|
+
flags, execfd, offset);
|
414
|
+
if (ptr == MFAIL)
|
415
|
+
{
|
416
|
+
if (!offset)
|
417
|
+
{
|
418
|
+
close (execfd);
|
419
|
+
goto retry_open;
|
420
|
+
}
|
421
|
+
ftruncate (execfd, offset);
|
422
|
+
return MFAIL;
|
423
|
+
}
|
424
|
+
else if (!offset
|
425
|
+
&& open_temp_exec_file_opts[open_temp_exec_file_opts_idx].repeat)
|
426
|
+
open_temp_exec_file_opts_next ();
|
427
|
+
|
428
|
+
start = mmap (start, length, prot, flags, execfd, offset);
|
429
|
+
|
430
|
+
if (start == MFAIL)
|
431
|
+
{
|
432
|
+
munmap (ptr, length);
|
433
|
+
ftruncate (execfd, offset);
|
434
|
+
return start;
|
435
|
+
}
|
436
|
+
|
437
|
+
mmap_exec_offset ((char *)start, length) = (char*)ptr - (char*)start;
|
438
|
+
|
439
|
+
execsize += length;
|
440
|
+
|
441
|
+
return start;
|
442
|
+
}
|
443
|
+
|
444
|
+
/* Map in a writable and executable chunk of memory if possible.
|
445
|
+
Failing that, fall back to dlmmap_locked. */
|
446
|
+
static void *
|
447
|
+
dlmmap (void *start, size_t length, int prot,
|
448
|
+
int flags, int fd, off_t offset)
|
449
|
+
{
|
450
|
+
void *ptr;
|
451
|
+
|
452
|
+
assert (start == NULL && length % malloc_getpagesize == 0
|
453
|
+
&& prot == (PROT_READ | PROT_WRITE)
|
454
|
+
&& flags == (MAP_PRIVATE | MAP_ANONYMOUS)
|
455
|
+
&& fd == -1 && offset == 0);
|
456
|
+
|
457
|
+
#if FFI_CLOSURE_TEST
|
458
|
+
printf ("mapping in %zi\n", length);
|
459
|
+
#endif
|
460
|
+
|
461
|
+
if (execfd == -1 && !is_selinux_enabled ())
|
462
|
+
{
|
463
|
+
ptr = mmap (start, length, prot | PROT_EXEC, flags, fd, offset);
|
464
|
+
|
465
|
+
if (ptr != MFAIL || (errno != EPERM && errno != EACCES))
|
466
|
+
/* Cool, no need to mess with separate segments. */
|
467
|
+
return ptr;
|
468
|
+
|
469
|
+
/* If MREMAP_DUP is ever introduced and implemented, try mmap
|
470
|
+
with ((prot & ~PROT_WRITE) | PROT_EXEC) and mremap with
|
471
|
+
MREMAP_DUP and prot at this point. */
|
472
|
+
}
|
473
|
+
|
474
|
+
if (execsize == 0 || execfd == -1)
|
475
|
+
{
|
476
|
+
pthread_mutex_lock (&open_temp_exec_file_mutex);
|
477
|
+
ptr = dlmmap_locked (start, length, prot, flags, offset);
|
478
|
+
pthread_mutex_unlock (&open_temp_exec_file_mutex);
|
479
|
+
|
480
|
+
return ptr;
|
481
|
+
}
|
482
|
+
|
483
|
+
return dlmmap_locked (start, length, prot, flags, offset);
|
484
|
+
}
|
485
|
+
|
486
|
+
/* Release memory at the given address, as well as the corresponding
|
487
|
+
executable page if it's separate. */
|
488
|
+
static int
|
489
|
+
dlmunmap (void *start, size_t length)
|
490
|
+
{
|
491
|
+
/* We don't bother decreasing execsize or truncating the file, since
|
492
|
+
we can't quite tell whether we're unmapping the end of the file.
|
493
|
+
We don't expect frequent deallocation anyway. If we did, we
|
494
|
+
could locate pages in the file by writing to the pages being
|
495
|
+
deallocated and checking that the file contents change.
|
496
|
+
Yuck. */
|
497
|
+
msegmentptr seg = segment_holding (gm, start);
|
498
|
+
void *code;
|
499
|
+
|
500
|
+
#if FFI_CLOSURE_TEST
|
501
|
+
printf ("unmapping %zi\n", length);
|
502
|
+
#endif
|
503
|
+
|
504
|
+
if (seg && (code = add_segment_exec_offset (start, seg)) != start)
|
505
|
+
{
|
506
|
+
int ret = munmap (code, length);
|
507
|
+
if (ret)
|
508
|
+
return ret;
|
509
|
+
}
|
510
|
+
|
511
|
+
return munmap (start, length);
|
512
|
+
}
|
513
|
+
|
514
|
+
#if FFI_CLOSURE_FREE_CODE
|
515
|
+
/* Return segment holding given code address. */
|
516
|
+
static msegmentptr
|
517
|
+
segment_holding_code (mstate m, char* addr)
|
518
|
+
{
|
519
|
+
msegmentptr sp = &m->seg;
|
520
|
+
for (;;) {
|
521
|
+
if (addr >= add_segment_exec_offset (sp->base, sp)
|
522
|
+
&& addr < add_segment_exec_offset (sp->base, sp) + sp->size)
|
523
|
+
return sp;
|
524
|
+
if ((sp = sp->next) == 0)
|
525
|
+
return 0;
|
526
|
+
}
|
527
|
+
}
|
528
|
+
#endif
|
529
|
+
|
530
|
+
#endif /* !(defined(X86_WIN32) || defined(X86_WIN64) || defined(__OS2__)) || defined (__CYGWIN__) || defined(__INTERIX) */
|
531
|
+
|
532
|
+
/* Allocate a chunk of memory with the given size. Returns a pointer
|
533
|
+
to the writable address, and sets *CODE to the executable
|
534
|
+
corresponding virtual address. */
|
535
|
+
void *
|
536
|
+
ffi_closure_alloc (size_t size, void **code)
|
537
|
+
{
|
538
|
+
void *ptr;
|
539
|
+
|
540
|
+
if (!code)
|
541
|
+
return NULL;
|
542
|
+
|
543
|
+
ptr = dlmalloc (size);
|
544
|
+
|
545
|
+
if (ptr)
|
546
|
+
{
|
547
|
+
msegmentptr seg = segment_holding (gm, ptr);
|
548
|
+
|
549
|
+
*code = add_segment_exec_offset (ptr, seg);
|
550
|
+
}
|
551
|
+
|
552
|
+
return ptr;
|
553
|
+
}
|
554
|
+
|
555
|
+
/* Release a chunk of memory allocated with ffi_closure_alloc. If
|
556
|
+
FFI_CLOSURE_FREE_CODE is nonzero, the given address can be the
|
557
|
+
writable or the executable address given. Otherwise, only the
|
558
|
+
writable address can be provided here. */
|
559
|
+
void
|
560
|
+
ffi_closure_free (void *ptr)
|
561
|
+
{
|
562
|
+
#if FFI_CLOSURE_FREE_CODE
|
563
|
+
msegmentptr seg = segment_holding_code (gm, ptr);
|
564
|
+
|
565
|
+
if (seg)
|
566
|
+
ptr = sub_segment_exec_offset (ptr, seg);
|
567
|
+
#endif
|
568
|
+
|
569
|
+
dlfree (ptr);
|
570
|
+
}
|
571
|
+
|
572
|
+
|
573
|
+
#if FFI_CLOSURE_TEST
|
574
|
+
/* Do some internal sanity testing to make sure allocation and
|
575
|
+
deallocation of pages are working as intended. */
|
576
|
+
int main ()
|
577
|
+
{
|
578
|
+
void *p[3];
|
579
|
+
#define GET(idx, len) do { p[idx] = dlmalloc (len); printf ("allocated %zi for p[%i]\n", (len), (idx)); } while (0)
|
580
|
+
#define PUT(idx) do { printf ("freeing p[%i]\n", (idx)); dlfree (p[idx]); } while (0)
|
581
|
+
GET (0, malloc_getpagesize / 2);
|
582
|
+
GET (1, 2 * malloc_getpagesize - 64 * sizeof (void*));
|
583
|
+
PUT (1);
|
584
|
+
GET (1, 2 * malloc_getpagesize);
|
585
|
+
GET (2, malloc_getpagesize / 2);
|
586
|
+
PUT (1);
|
587
|
+
PUT (0);
|
588
|
+
PUT (2);
|
589
|
+
return 0;
|
590
|
+
}
|
591
|
+
#endif /* FFI_CLOSURE_TEST */
|
592
|
+
# else /* ! FFI_MMAP_EXEC_WRIT */
|
593
|
+
|
594
|
+
/* On many systems, memory returned by malloc is writable and
|
595
|
+
executable, so just use it. */
|
596
|
+
|
597
|
+
#include <stdlib.h>
|
598
|
+
|
599
|
+
void *
|
600
|
+
ffi_closure_alloc (size_t size, void **code)
|
601
|
+
{
|
602
|
+
if (!code)
|
603
|
+
return NULL;
|
604
|
+
|
605
|
+
return *code = malloc (size);
|
606
|
+
}
|
607
|
+
|
608
|
+
void
|
609
|
+
ffi_closure_free (void *ptr)
|
610
|
+
{
|
611
|
+
free (ptr);
|
612
|
+
}
|
613
|
+
|
614
|
+
# endif /* ! FFI_MMAP_EXEC_WRIT */
|
615
|
+
#endif /* FFI_CLOSURES */
|