ffi 1.9.24 → 1.16.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/CHANGELOG.md +348 -0
- data/Gemfile +4 -5
- data/README.md +44 -17
- data/Rakefile +74 -148
- data/ext/ffi_c/AbstractMemory.c +89 -70
- data/ext/ffi_c/AbstractMemory.h +3 -2
- data/ext/ffi_c/ArrayType.c +49 -13
- data/ext/ffi_c/ArrayType.h +1 -0
- data/ext/ffi_c/Buffer.c +90 -38
- data/ext/ffi_c/Call.c +55 -56
- data/ext/ffi_c/Call.h +12 -6
- data/ext/ffi_c/ClosurePool.c +333 -0
- data/ext/ffi_c/{Closure.h → ClosurePool.h} +25 -13
- data/ext/ffi_c/DynamicLibrary.c +91 -33
- data/ext/ffi_c/Function.c +306 -235
- data/ext/ffi_c/Function.h +3 -5
- data/ext/ffi_c/FunctionInfo.c +87 -32
- data/ext/ffi_c/LastError.c +74 -15
- data/ext/ffi_c/LongDouble.c +12 -10
- data/ext/ffi_c/LongDouble.h +0 -4
- data/ext/ffi_c/MappedType.c +66 -23
- data/ext/ffi_c/MappedType.h +0 -2
- data/ext/ffi_c/MemoryPointer.c +37 -15
- data/ext/ffi_c/MemoryPointer.h +0 -4
- data/ext/ffi_c/MethodHandle.c +265 -38
- data/ext/ffi_c/MethodHandle.h +3 -2
- data/ext/ffi_c/Platform.c +5 -56
- data/ext/ffi_c/Pointer.c +93 -55
- data/ext/ffi_c/Pointer.h +1 -4
- data/ext/ffi_c/Struct.c +202 -134
- data/ext/ffi_c/Struct.h +18 -9
- data/ext/ffi_c/StructByValue.c +50 -23
- data/ext/ffi_c/StructLayout.c +135 -64
- data/ext/ffi_c/Thread.c +4 -228
- data/ext/ffi_c/Thread.h +1 -20
- data/ext/ffi_c/Type.c +105 -55
- data/ext/ffi_c/Type.h +3 -2
- data/ext/ffi_c/Types.c +8 -9
- data/ext/ffi_c/Types.h +3 -4
- data/ext/ffi_c/Variadic.c +88 -47
- data/ext/ffi_c/compat.h +26 -22
- data/ext/ffi_c/extconf.rb +75 -32
- data/ext/ffi_c/ffi.c +9 -10
- data/ext/ffi_c/libffi/.appveyor/site.exp +16 -0
- data/ext/ffi_c/libffi/.appveyor/unix-noexec.exp +7 -0
- data/ext/ffi_c/libffi/.appveyor.yml +53 -19
- data/ext/ffi_c/libffi/.ci/bfin-sim.exp +58 -0
- data/ext/ffi_c/libffi/.ci/build-cross-in-container.sh +18 -0
- data/ext/ffi_c/libffi/.ci/build-in-container.sh +10 -0
- data/ext/ffi_c/libffi/.ci/build.sh +124 -0
- data/ext/ffi_c/libffi/.ci/install.sh +78 -0
- data/ext/ffi_c/libffi/.ci/m32r-sim.exp +58 -0
- data/ext/ffi_c/libffi/{.travis → .ci}/moxie-sim.exp +1 -1
- data/ext/ffi_c/libffi/.ci/msvs-detect +1103 -0
- data/ext/ffi_c/libffi/.ci/or1k-sim.exp +58 -0
- data/ext/ffi_c/libffi/.ci/powerpc-eabisim.exp +58 -0
- data/ext/ffi_c/libffi/.ci/site.exp +29 -0
- data/ext/ffi_c/libffi/.ci/wine-sim.exp +55 -0
- data/ext/ffi_c/libffi/.circleci/config.yml +156 -0
- data/ext/ffi_c/libffi/.gitattributes +4 -0
- data/ext/ffi_c/libffi/.github/workflows/build.yml +460 -0
- data/ext/ffi_c/libffi/.github/workflows/emscripten.yml +171 -0
- data/ext/ffi_c/libffi/.gitignore +10 -2
- data/ext/ffi_c/libffi/{ChangeLog.libffi-3.1 → ChangeLog.old} +1407 -0
- data/ext/ffi_c/libffi/LICENSE +1 -1
- data/ext/ffi_c/libffi/LICENSE-BUILDTOOLS +5 -4
- data/ext/ffi_c/libffi/Makefile.am +64 -73
- data/ext/ffi_c/libffi/Makefile.in +553 -235
- data/ext/ffi_c/libffi/README.md +165 -100
- data/ext/ffi_c/libffi/acinclude.m4 +10 -112
- data/ext/ffi_c/libffi/compile +348 -0
- data/ext/ffi_c/libffi/config.guess +950 -662
- data/ext/ffi_c/libffi/config.sub +1362 -1306
- data/ext/ffi_c/libffi/configure +4909 -4096
- data/ext/ffi_c/libffi/configure.ac +93 -32
- data/ext/ffi_c/libffi/configure.host +76 -28
- data/ext/ffi_c/libffi/doc/Makefile.in +15 -8
- data/ext/ffi_c/libffi/doc/libffi.texi +107 -46
- data/ext/ffi_c/libffi/doc/version.texi +4 -4
- data/ext/ffi_c/libffi/fficonfig.h.in +22 -44
- data/ext/ffi_c/libffi/generate-darwin-source-and-headers.py +165 -56
- data/ext/ffi_c/libffi/include/Makefile.am +1 -1
- data/ext/ffi_c/libffi/include/Makefile.in +17 -12
- data/ext/ffi_c/libffi/include/ffi.h.in +64 -48
- data/ext/ffi_c/libffi/include/ffi_cfi.h +21 -0
- data/ext/ffi_c/libffi/include/ffi_common.h +34 -1
- data/ext/ffi_c/libffi/include/tramp.h +45 -0
- data/ext/ffi_c/libffi/install-sh +107 -74
- data/ext/ffi_c/libffi/libffi.map.in +8 -12
- data/ext/ffi_c/libffi/libffi.xcodeproj/project.pbxproj +2 -48
- data/ext/ffi_c/libffi/libtool-version +2 -2
- data/ext/ffi_c/libffi/ltmain.sh +576 -284
- data/ext/ffi_c/libffi/m4/asmcfi.m4 +1 -1
- data/ext/ffi_c/libffi/m4/ax_append_flag.m4 +5 -26
- data/ext/ffi_c/libffi/m4/ax_cc_maxopt.m4 +18 -14
- data/ext/ffi_c/libffi/m4/ax_cflags_warn_all.m4 +108 -72
- data/ext/ffi_c/libffi/m4/ax_check_compile_flag.m4 +5 -26
- data/ext/ffi_c/libffi/m4/ax_compiler_vendor.m4 +76 -44
- data/ext/ffi_c/libffi/m4/ax_configure_args.m4 +5 -26
- data/ext/ffi_c/libffi/m4/ax_gcc_archflag.m4 +7 -3
- data/ext/ffi_c/libffi/m4/ax_prepend_flag.m4 +51 -0
- data/ext/ffi_c/libffi/make_sunver.pl +333 -0
- data/ext/ffi_c/libffi/man/Makefile.in +15 -8
- data/ext/ffi_c/libffi/missing +8 -8
- data/ext/ffi_c/libffi/msvc_build/aarch64/Ffi_staticLib.sln +33 -0
- data/ext/ffi_c/libffi/msvc_build/aarch64/Ffi_staticLib.vcxproj +130 -0
- data/ext/ffi_c/libffi/msvc_build/aarch64/Ffi_staticLib.vcxproj.filters +57 -0
- data/ext/ffi_c/libffi/msvc_build/aarch64/Ffi_staticLib.vcxproj.user +4 -0
- data/ext/ffi_c/libffi/msvc_build/aarch64/aarch64_include/ffi.h +511 -0
- data/ext/ffi_c/libffi/msvc_build/aarch64/aarch64_include/fficonfig.h +219 -0
- data/ext/ffi_c/libffi/msvcc.sh +39 -14
- data/ext/ffi_c/libffi/src/aarch64/ffi.c +286 -98
- data/ext/ffi_c/libffi/src/aarch64/ffitarget.h +19 -3
- data/ext/ffi_c/libffi/src/aarch64/internal.h +33 -0
- data/ext/ffi_c/libffi/src/aarch64/sysv.S +142 -37
- data/ext/ffi_c/libffi/src/aarch64/win64_armasm.S +506 -0
- data/ext/ffi_c/libffi/src/arc/arcompact.S +169 -94
- data/ext/ffi_c/libffi/src/arc/ffi.c +325 -148
- data/ext/ffi_c/libffi/src/arc/ffitarget.h +14 -0
- data/ext/ffi_c/libffi/src/arm/ffi.c +112 -10
- data/ext/ffi_c/libffi/src/arm/ffitarget.h +8 -1
- data/ext/ffi_c/libffi/src/arm/internal.h +10 -0
- data/ext/ffi_c/libffi/src/arm/sysv.S +117 -44
- data/ext/ffi_c/libffi/src/arm/sysv_msvc_arm32.S +311 -0
- data/ext/ffi_c/libffi/src/closures.c +189 -48
- data/ext/ffi_c/libffi/src/csky/ffi.c +395 -0
- data/ext/ffi_c/libffi/src/csky/ffitarget.h +63 -0
- data/ext/ffi_c/libffi/src/csky/sysv.S +371 -0
- data/ext/ffi_c/libffi/src/dlmalloc.c +6 -1
- data/ext/ffi_c/libffi/src/frv/ffi.c +1 -1
- data/ext/ffi_c/libffi/src/ia64/ffi.c +12 -0
- data/ext/ffi_c/libffi/src/ia64/unix.S +20 -2
- data/ext/ffi_c/libffi/src/kvx/asm.h +5 -0
- data/ext/ffi_c/libffi/src/kvx/ffi.c +273 -0
- data/ext/ffi_c/libffi/src/kvx/ffitarget.h +75 -0
- data/ext/ffi_c/libffi/src/kvx/sysv.S +127 -0
- data/ext/ffi_c/libffi/src/loongarch64/ffi.c +621 -0
- data/ext/ffi_c/libffi/src/loongarch64/ffitarget.h +82 -0
- data/ext/ffi_c/libffi/src/loongarch64/sysv.S +327 -0
- data/ext/ffi_c/libffi/src/m32r/ffi.c +31 -14
- data/ext/ffi_c/libffi/src/metag/ffi.c +1 -1
- data/ext/ffi_c/libffi/src/mips/ffi.c +245 -66
- data/ext/ffi_c/libffi/src/mips/ffitarget.h +8 -1
- data/ext/ffi_c/libffi/src/mips/n32.S +137 -28
- data/ext/ffi_c/libffi/src/mips/o32.S +63 -4
- data/ext/ffi_c/libffi/src/moxie/ffi.c +48 -23
- data/ext/ffi_c/libffi/src/or1k/ffi.c +25 -12
- data/ext/ffi_c/libffi/src/pa/ffi.c +62 -108
- data/ext/ffi_c/libffi/src/pa/ffi64.c +614 -0
- data/ext/ffi_c/libffi/src/pa/ffitarget.h +20 -11
- data/ext/ffi_c/libffi/src/pa/hpux32.S +87 -38
- data/ext/ffi_c/libffi/src/pa/hpux64.S +681 -0
- data/ext/ffi_c/libffi/src/pa/linux.S +109 -39
- data/ext/ffi_c/libffi/src/powerpc/ffi.c +6 -4
- data/ext/ffi_c/libffi/src/powerpc/ffi_darwin.c +13 -1
- data/ext/ffi_c/libffi/src/powerpc/ffi_linux64.c +211 -32
- data/ext/ffi_c/libffi/src/powerpc/ffi_powerpc.h +18 -7
- data/ext/ffi_c/libffi/src/powerpc/ffitarget.h +10 -4
- data/ext/ffi_c/libffi/src/powerpc/linux64.S +93 -28
- data/ext/ffi_c/libffi/src/powerpc/linux64_closure.S +83 -5
- data/ext/ffi_c/libffi/src/powerpc/sysv.S +5 -7
- data/ext/ffi_c/libffi/src/powerpc/t-aix +5 -0
- data/ext/ffi_c/libffi/src/prep_cif.c +26 -4
- data/ext/ffi_c/libffi/src/riscv/ffi.c +79 -10
- data/ext/ffi_c/libffi/src/riscv/ffitarget.h +1 -0
- data/ext/ffi_c/libffi/src/riscv/sysv.S +86 -7
- data/ext/ffi_c/libffi/src/sparc/ffi64.c +16 -0
- data/ext/ffi_c/libffi/src/tramp.c +716 -0
- data/ext/ffi_c/libffi/src/wasm32/ffi.c +934 -0
- data/ext/ffi_c/libffi/src/wasm32/ffitarget.h +62 -0
- data/ext/ffi_c/libffi/src/x86/ffi.c +128 -49
- data/ext/ffi_c/libffi/src/x86/ffi64.c +89 -23
- data/ext/ffi_c/libffi/src/x86/ffitarget.h +21 -4
- data/ext/ffi_c/libffi/src/x86/ffiw64.c +63 -10
- data/ext/ffi_c/libffi/src/x86/internal.h +14 -0
- data/ext/ffi_c/libffi/src/x86/internal64.h +14 -0
- data/ext/ffi_c/libffi/src/x86/sysv.S +274 -45
- data/ext/ffi_c/libffi/src/x86/sysv_intel.S +998 -0
- data/ext/ffi_c/libffi/src/x86/unix64.S +190 -4
- data/ext/ffi_c/libffi/src/x86/win64.S +32 -10
- data/ext/ffi_c/libffi/src/x86/win64_intel.S +3 -2
- data/ext/ffi_c/libffi/src/xtensa/ffi.c +16 -8
- data/ext/ffi_c/libffi/src/xtensa/ffitarget.h +4 -0
- data/ext/ffi_c/libffi/src/xtensa/sysv.S +26 -16
- data/ext/ffi_c/libffi/testsuite/Makefile.am +127 -109
- data/ext/ffi_c/libffi/testsuite/Makefile.in +144 -88
- data/ext/ffi_c/libffi/testsuite/emscripten/build-tests.sh +54 -0
- data/ext/ffi_c/libffi/testsuite/emscripten/build.sh +63 -0
- data/ext/ffi_c/libffi/testsuite/emscripten/conftest.py +80 -0
- data/ext/ffi_c/libffi/testsuite/emscripten/node-tests.sh +48 -0
- data/ext/ffi_c/libffi/testsuite/emscripten/test.html +7 -0
- data/ext/ffi_c/libffi/testsuite/emscripten/test_libffi.py +51 -0
- data/ext/ffi_c/libffi/testsuite/lib/libffi.exp +71 -25
- data/ext/ffi_c/libffi/testsuite/lib/target-libpath.exp +2 -2
- data/ext/ffi_c/libffi/testsuite/libffi.bhaible/bhaible.exp +7 -2
- data/ext/ffi_c/libffi/testsuite/libffi.bhaible/test-call.c +5 -4
- data/ext/ffi_c/libffi/testsuite/libffi.bhaible/test-callback.c +2 -2
- data/ext/ffi_c/libffi/testsuite/libffi.bhaible/testcases.c +5 -1
- data/ext/ffi_c/libffi/testsuite/libffi.call/bpo_38748.c +41 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/call.exp +12 -1
- data/ext/ffi_c/libffi/testsuite/libffi.call/ffitest.h +28 -3
- data/ext/ffi_c/libffi/testsuite/libffi.call/float2.c +9 -8
- data/ext/ffi_c/libffi/testsuite/libffi.call/float_va.c +3 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/return_ll1.c +5 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/return_sl.c +4 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/return_ul.c +4 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/s55.c +60 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/strlen.c +8 -9
- data/ext/ffi_c/libffi/testsuite/libffi.call/strlen2.c +2 -2
- data/ext/ffi_c/libffi/testsuite/libffi.call/strlen3.c +2 -2
- data/ext/ffi_c/libffi/testsuite/libffi.call/strlen4.c +2 -2
- data/ext/ffi_c/libffi/testsuite/libffi.call/struct10.c +1 -1
- data/ext/ffi_c/libffi/testsuite/libffi.call/struct_by_value_2.c +63 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/struct_by_value_3.c +65 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/struct_by_value_3f.c +65 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/struct_by_value_4.c +67 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/struct_by_value_4f.c +67 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/struct_by_value_big.c +93 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/struct_by_value_small.c +61 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/struct_return_2H.c +63 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/struct_return_8H.c +90 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/va_1.c +1 -119
- data/ext/ffi_c/libffi/testsuite/libffi.call/va_2.c +220 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/va_3.c +154 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/va_struct1.c +13 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/va_struct2.c +11 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/va_struct3.c +15 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/closure.exp +67 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/closure_fn0.c +3 -2
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/closure_fn1.c +2 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/closure_fn2.c +2 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/closure_fn3.c +21 -1
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/closure_fn4.c +2 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/closure_fn5.c +2 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/closure_fn6.c +2 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/closure_loc_fn0.c +7 -6
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/closure_simple.c +6 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_12byte.c +18 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_16byte.c +22 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_18byte.c +24 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_19byte.c +29 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_1_1byte.c +4 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_20byte.c +19 -1
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_20byte1.c +21 -1
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_24byte.c +35 -3
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_2byte.c +13 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_3_1byte.c +19 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_3byte1.c +13 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_3byte2.c +13 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_3float.c +18 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_4_1byte.c +22 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_4byte.c +13 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_5_1_byte.c +29 -1
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_5byte.c +19 -1
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_64byte.c +24 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_6_1_byte.c +28 -1
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_6byte.c +24 -2
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_7_1_byte.c +39 -1
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_7byte.c +25 -1
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_8byte.c +14 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_9byte1.c +14 -1
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_9byte2.c +14 -2
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_double.c +19 -1
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_float.c +19 -1
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_longdouble.c +20 -1
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_longdouble_split.c +40 -25
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_longdouble_split2.c +40 -3
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_pointer.c +19 -1
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_sint16.c +18 -1
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_sint32.c +18 -3
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_sint64.c +18 -1
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_uint16.c +18 -1
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_uint32.c +19 -1
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_uint64.c +19 -1
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_dbls_struct.c +3 -1
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_double_va.c +9 -1
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_float.c +4 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_longdouble.c +11 -1
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_longdouble_va.c +22 -3
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_multi_schar.c +5 -1
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_multi_sshort.c +6 -1
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_multi_sshortchar.c +9 -1
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_multi_uchar.c +9 -1
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_multi_ushort.c +6 -2
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_multi_ushortchar.c +9 -1
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_pointer.c +5 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_pointer_stack.c +10 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_schar.c +3 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_sint.c +2 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_sshort.c +3 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_struct_va1.c +11 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_uchar.c +3 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_uint.c +4 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_uint_va.c +4 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_ulong_va.c +4 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_ulonglong.c +2 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_ushort.c +3 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/ffitest.h +1 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/huge_struct.c +24 -22
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct.c +32 -9
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct1.c +1 -1
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct10.c +12 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct11.c +21 -5
- data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct12.c +86 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct13.c +115 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct2.c +10 -1
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct3.c +10 -1
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct4.c +9 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct5.c +9 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct6.c +11 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct7.c +9 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct8.c +11 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct9.c +11 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/single_entry_structs1.c +86 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/single_entry_structs2.c +102 -0
- data/ext/ffi_c/libffi/testsuite/libffi.closures/single_entry_structs3.c +101 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/stret_medium.c +1 -1
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/stret_medium2.c +1 -1
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/testclosure.c +6 -1
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/unwindtest.cc +2 -1
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/unwindtest_ffi_call.cc +1 -0
- data/ext/ffi_c/libffi.bsd.mk +2 -2
- data/ext/ffi_c/libffi.darwin.mk +1 -1
- data/ext/ffi_c/libffi.gnu.mk +2 -2
- data/ext/ffi_c/rbffi.h +1 -3
- data/ffi.gemspec +15 -9
- data/lib/ffi/abstract_memory.rb +44 -0
- data/lib/ffi/autopointer.rb +8 -23
- data/lib/ffi/compat.rb +43 -0
- data/lib/ffi/data_converter.rb +67 -0
- data/lib/ffi/dynamic_library.rb +89 -0
- data/lib/ffi/enum.rb +18 -11
- data/lib/ffi/ffi.rb +6 -0
- data/lib/ffi/function.rb +71 -0
- data/lib/ffi/io.rb +3 -3
- data/lib/ffi/library.rb +65 -77
- data/lib/ffi/library_path.rb +109 -0
- data/lib/ffi/managedstruct.rb +3 -3
- data/lib/ffi/platform/aarch64-darwin/types.conf +130 -0
- data/lib/ffi/platform/aarch64-freebsd/types.conf +128 -0
- data/lib/ffi/platform/aarch64-freebsd12/types.conf +181 -0
- data/lib/ffi/platform/aarch64-linux/types.conf +81 -81
- data/lib/ffi/platform/aarch64-openbsd/types.conf +134 -0
- data/lib/ffi/platform/aarch64-windows/types.conf +52 -0
- data/lib/ffi/platform/arm-freebsd/types.conf +152 -0
- data/lib/ffi/platform/arm-freebsd12/types.conf +152 -0
- data/lib/ffi/platform/arm-linux/types.conf +110 -82
- data/lib/ffi/platform/hppa1.1-linux/types.conf +178 -0
- data/lib/ffi/platform/hppa2.0-linux/types.conf +178 -0
- data/lib/ffi/platform/i386-cygwin/types.conf +1 -1
- data/lib/ffi/platform/i386-darwin/types.conf +63 -63
- data/lib/ffi/platform/i386-freebsd/types.conf +89 -89
- data/lib/ffi/platform/i386-freebsd12/types.conf +152 -0
- data/lib/ffi/platform/i386-gnu/types.conf +84 -84
- data/lib/ffi/platform/i386-linux/types.conf +77 -77
- data/lib/ffi/platform/i386-netbsd/types.conf +87 -87
- data/lib/ffi/platform/i386-openbsd/types.conf +89 -89
- data/lib/ffi/platform/i386-solaris/types.conf +96 -96
- data/lib/ffi/platform/i386-windows/types.conf +43 -96
- data/lib/ffi/platform/ia64-linux/types.conf +79 -79
- data/lib/ffi/platform/loongarch64-linux/types.conf +141 -0
- data/lib/ffi/platform/mips-linux/types.conf +79 -79
- data/lib/ffi/platform/mips64-linux/types.conf +81 -81
- data/lib/ffi/platform/mips64el-linux/types.conf +81 -81
- data/lib/ffi/platform/mipsel-linux/types.conf +79 -79
- data/lib/ffi/platform/mipsisa32r6-linux/types.conf +79 -79
- data/lib/ffi/platform/mipsisa32r6el-linux/types.conf +79 -79
- data/lib/ffi/platform/mipsisa64r6-linux/types.conf +81 -81
- data/lib/ffi/platform/mipsisa64r6el-linux/types.conf +81 -81
- data/lib/ffi/platform/powerpc-aix/types.conf +155 -155
- data/lib/ffi/platform/powerpc-darwin/types.conf +63 -63
- data/lib/ffi/platform/powerpc-linux/types.conf +108 -78
- data/lib/ffi/platform/powerpc-openbsd/types.conf +156 -0
- data/lib/ffi/platform/powerpc64-linux/types.conf +81 -81
- data/lib/ffi/platform/powerpc64le-linux/types.conf +100 -0
- data/lib/ffi/platform/riscv64-linux/types.conf +104 -0
- data/lib/ffi/platform/s390-linux/types.conf +79 -79
- data/lib/ffi/platform/s390x-linux/types.conf +79 -79
- data/lib/ffi/platform/sparc-linux/types.conf +79 -79
- data/lib/ffi/platform/sparc-solaris/types.conf +103 -103
- data/lib/ffi/platform/sparcv9-openbsd/types.conf +156 -0
- data/lib/ffi/platform/sparcv9-solaris/types.conf +103 -103
- data/lib/ffi/platform/sw_64-linux/types.conf +141 -0
- data/lib/ffi/platform/x86_64-cygwin/types.conf +1 -1
- data/lib/ffi/platform/x86_64-darwin/types.conf +88 -84
- data/lib/ffi/platform/x86_64-dragonflybsd/types.conf +130 -0
- data/lib/ffi/platform/x86_64-freebsd/types.conf +90 -90
- data/lib/ffi/platform/x86_64-freebsd12/types.conf +158 -0
- data/lib/ffi/platform/x86_64-haiku/types.conf +117 -0
- data/lib/ffi/platform/x86_64-linux/types.conf +107 -77
- data/lib/ffi/platform/x86_64-msys/types.conf +119 -0
- data/lib/ffi/platform/x86_64-netbsd/types.conf +89 -89
- data/lib/ffi/platform/x86_64-openbsd/types.conf +86 -86
- data/lib/ffi/platform/x86_64-solaris/types.conf +96 -96
- data/lib/ffi/platform/x86_64-windows/types.conf +42 -110
- data/lib/ffi/platform.rb +43 -20
- data/lib/ffi/pointer.rb +26 -20
- data/lib/ffi/struct.rb +14 -68
- data/lib/ffi/struct_by_reference.rb +72 -0
- data/lib/ffi/struct_layout.rb +96 -0
- data/lib/ffi/struct_layout_builder.rb +1 -1
- data/lib/ffi/tools/const_generator.rb +11 -8
- data/lib/ffi/tools/generator.rb +47 -2
- data/lib/ffi/tools/generator_task.rb +13 -17
- data/lib/ffi/tools/struct_generator.rb +6 -5
- data/lib/ffi/tools/types_generator.rb +7 -4
- data/lib/ffi/types.rb +33 -7
- data/lib/ffi/variadic.rb +20 -18
- data/lib/ffi/version.rb +1 -1
- data/lib/ffi.rb +10 -3
- data/rakelib/ffi_gem_helper.rb +65 -0
- data/samples/getlogin.rb +1 -1
- data/samples/getpid.rb +1 -1
- data/samples/gettimeofday.rb +8 -8
- data/samples/hello.rb +2 -1
- data/samples/hello_ractor.rb +11 -0
- data/samples/inotify.rb +1 -1
- data/samples/pty.rb +1 -2
- data/samples/qsort.rb +0 -1
- data/samples/qsort_ractor.rb +28 -0
- data.tar.gz.sig +0 -0
- metadata +252 -153
- metadata.gz.sig +0 -0
- data/.gitignore +0 -22
- data/.gitmodules +0 -3
- data/.travis.yml +0 -52
- data/.yardopts +0 -5
- data/appveyor.yml +0 -22
- data/ext/ffi_c/Closure.c +0 -54
- data/ext/ffi_c/DataConverter.c +0 -91
- data/ext/ffi_c/StructByReference.c +0 -190
- data/ext/ffi_c/StructByReference.h +0 -50
- data/ext/ffi_c/libffi/.travis/build.sh +0 -34
- data/ext/ffi_c/libffi/.travis/install.sh +0 -22
- data/ext/ffi_c/libffi/.travis/site.exp +0 -18
- data/ext/ffi_c/libffi/.travis.yml +0 -34
- data/ext/ffi_c/libffi/ChangeLog.libffi +0 -584
- data/ext/ffi_c/libffi/ChangeLog.libgcj +0 -40
- data/ext/ffi_c/libffi/ChangeLog.v1 +0 -764
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_uchar_va.c +0 -44
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_ushort_va.c +0 -44
- data/ext/ffi_c/win32/stdbool.h +0 -8
- data/ext/ffi_c/win32/stdint.h +0 -201
- data/samples/sample_helper.rb +0 -6
- data/ext/ffi_c/libffi/{.travis → .ci}/ar-lib +0 -0
- data/ext/ffi_c/libffi/{.travis → .ci}/compile +0 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/{pyobjc-tc.c → pyobjc_tc.c} +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_double.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_many_mixed_args.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_many_mixed_float_double.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/err_bad_abi.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/problem1.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/stret_large.c +0 -0
- data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/stret_large2.c +0 -0
- data/lib/ffi/platform/{sparc64-linux → sparcv9-linux}/types.conf +79 -79
@@ -0,0 +1,333 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2009, 2010 Wayne Meissner
|
3
|
+
* Copyright (c) 2008-2013, Ruby FFI project contributors
|
4
|
+
* All rights reserved.
|
5
|
+
*
|
6
|
+
* Redistribution and use in source and binary forms, with or without
|
7
|
+
* modification, are permitted provided that the following conditions are met:
|
8
|
+
* * Redistributions of source code must retain the above copyright
|
9
|
+
* notice, this list of conditions and the following disclaimer.
|
10
|
+
* * Redistributions in binary form must reproduce the above copyright
|
11
|
+
* notice, this list of conditions and the following disclaimer in the
|
12
|
+
* documentation and/or other materials provided with the distribution.
|
13
|
+
* * Neither the name of the Ruby FFI project nor the
|
14
|
+
* names of its contributors may be used to endorse or promote products
|
15
|
+
* derived from this software without specific prior written permission.
|
16
|
+
*
|
17
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
18
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
19
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
20
|
+
* DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
21
|
+
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
22
|
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
23
|
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
24
|
+
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
25
|
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
26
|
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
27
|
+
*/
|
28
|
+
|
29
|
+
#ifndef _MSC_VER
|
30
|
+
#include <sys/param.h>
|
31
|
+
#endif
|
32
|
+
#include <sys/types.h>
|
33
|
+
#if defined(__CYGWIN__) || !defined(_WIN32)
|
34
|
+
# include <sys/mman.h>
|
35
|
+
#endif
|
36
|
+
#include <stdio.h>
|
37
|
+
#include <stdint.h>
|
38
|
+
#include <stdbool.h>
|
39
|
+
#if defined(__CYGWIN__) || !defined(_WIN32)
|
40
|
+
# include <unistd.h>
|
41
|
+
#else
|
42
|
+
# include <winsock2.h>
|
43
|
+
# define _WINSOCKAPI_
|
44
|
+
# include <windows.h>
|
45
|
+
#endif
|
46
|
+
#include <errno.h>
|
47
|
+
#include <ruby.h>
|
48
|
+
|
49
|
+
#include <ffi.h>
|
50
|
+
#include "rbffi.h"
|
51
|
+
#include "compat.h"
|
52
|
+
|
53
|
+
#include "Function.h"
|
54
|
+
#include "Types.h"
|
55
|
+
#include "Type.h"
|
56
|
+
#include "LastError.h"
|
57
|
+
#include "Call.h"
|
58
|
+
|
59
|
+
#include "ClosurePool.h"
|
60
|
+
|
61
|
+
#ifndef roundup
|
62
|
+
# define roundup(x, y) ((((x)+((y)-1))/(y))*(y))
|
63
|
+
#endif
|
64
|
+
|
65
|
+
typedef struct Memory {
|
66
|
+
void* code;
|
67
|
+
void* data;
|
68
|
+
struct Memory* next;
|
69
|
+
} Memory;
|
70
|
+
|
71
|
+
struct ClosurePool_ {
|
72
|
+
void* ctx;
|
73
|
+
int closureSize;
|
74
|
+
bool (*prep)(void* ctx, void *code, Closure* closure, char* errbuf, size_t errbufsize);
|
75
|
+
struct Memory* blocks; /* Keeps track of all the allocated memory for this pool */
|
76
|
+
Closure* list;
|
77
|
+
long refcnt;
|
78
|
+
};
|
79
|
+
|
80
|
+
static long pageSize;
|
81
|
+
|
82
|
+
static void* allocatePage(void);
|
83
|
+
static bool freePage(void *);
|
84
|
+
static bool protectPage(void *);
|
85
|
+
|
86
|
+
ClosurePool*
|
87
|
+
rbffi_ClosurePool_New(int closureSize,
|
88
|
+
bool (*prep)(void* ctx, void *code, Closure* closure, char* errbuf, size_t errbufsize),
|
89
|
+
void* ctx)
|
90
|
+
{
|
91
|
+
ClosurePool* pool;
|
92
|
+
|
93
|
+
pool = xcalloc(1, sizeof(*pool));
|
94
|
+
pool->closureSize = closureSize;
|
95
|
+
pool->ctx = ctx;
|
96
|
+
pool->prep = prep;
|
97
|
+
pool->refcnt = 1;
|
98
|
+
|
99
|
+
return pool;
|
100
|
+
}
|
101
|
+
|
102
|
+
void
|
103
|
+
cleanup_closure_pool(ClosurePool* pool)
|
104
|
+
{
|
105
|
+
Memory* memory;
|
106
|
+
|
107
|
+
for (memory = pool->blocks; memory != NULL; ) {
|
108
|
+
Memory* next = memory->next;
|
109
|
+
#if !USE_FFI_ALLOC
|
110
|
+
freePage(memory->code);
|
111
|
+
#else
|
112
|
+
ffi_closure_free(memory->code);
|
113
|
+
#endif
|
114
|
+
free(memory->data);
|
115
|
+
free(memory);
|
116
|
+
memory = next;
|
117
|
+
}
|
118
|
+
xfree(pool);
|
119
|
+
}
|
120
|
+
|
121
|
+
void
|
122
|
+
rbffi_ClosurePool_Free(ClosurePool* pool)
|
123
|
+
{
|
124
|
+
if (pool != NULL) {
|
125
|
+
long refcnt = --(pool->refcnt);
|
126
|
+
if (refcnt == 0) {
|
127
|
+
cleanup_closure_pool(pool);
|
128
|
+
}
|
129
|
+
}
|
130
|
+
}
|
131
|
+
|
132
|
+
#if !USE_FFI_ALLOC
|
133
|
+
|
134
|
+
Closure*
|
135
|
+
rbffi_Closure_Alloc(ClosurePool* pool)
|
136
|
+
{
|
137
|
+
Closure *list = NULL;
|
138
|
+
Memory* block = NULL;
|
139
|
+
void *code = NULL;
|
140
|
+
char errmsg[256];
|
141
|
+
int nclosures;
|
142
|
+
long trampolineSize;
|
143
|
+
int i;
|
144
|
+
|
145
|
+
if (pool->list != NULL) {
|
146
|
+
Closure* closure = pool->list;
|
147
|
+
pool->list = pool->list->next;
|
148
|
+
pool->refcnt++;
|
149
|
+
|
150
|
+
return closure;
|
151
|
+
}
|
152
|
+
|
153
|
+
trampolineSize = roundup(pool->closureSize, 8);
|
154
|
+
nclosures = (int) (pageSize / trampolineSize);
|
155
|
+
block = calloc(1, sizeof(*block));
|
156
|
+
list = calloc(nclosures, sizeof(*list));
|
157
|
+
code = allocatePage();
|
158
|
+
|
159
|
+
if (block == NULL || list == NULL || code == NULL) {
|
160
|
+
snprintf(errmsg, sizeof(errmsg), "failed to allocate a page. errno=%d (%s)", errno, strerror(errno));
|
161
|
+
goto error;
|
162
|
+
}
|
163
|
+
|
164
|
+
for (i = 0; i < nclosures; ++i) {
|
165
|
+
Closure* closure = &list[i];
|
166
|
+
closure->next = &list[i + 1];
|
167
|
+
closure->pool = pool;
|
168
|
+
closure->code = ((char *)code + (i * trampolineSize));
|
169
|
+
closure->pcl = closure->code;
|
170
|
+
|
171
|
+
if (!(*pool->prep)(pool->ctx, closure->code, closure, errmsg, sizeof(errmsg))) {
|
172
|
+
goto error;
|
173
|
+
}
|
174
|
+
}
|
175
|
+
|
176
|
+
if (!protectPage(code)) {
|
177
|
+
goto error;
|
178
|
+
}
|
179
|
+
|
180
|
+
/* Track the allocated page + Closure memory area */
|
181
|
+
block->data = list;
|
182
|
+
block->code = code;
|
183
|
+
block->next = pool->blocks;
|
184
|
+
pool->blocks = block;
|
185
|
+
|
186
|
+
/* Thread the new block onto the free list, apart from the first one. */
|
187
|
+
list[nclosures - 1].next = pool->list;
|
188
|
+
pool->list = list->next;
|
189
|
+
pool->refcnt++;
|
190
|
+
|
191
|
+
/* Use the first one as the new handle */
|
192
|
+
return list;
|
193
|
+
|
194
|
+
error:
|
195
|
+
free(block);
|
196
|
+
free(list);
|
197
|
+
if (code != NULL) {
|
198
|
+
freePage(code);
|
199
|
+
}
|
200
|
+
|
201
|
+
|
202
|
+
rb_raise(rb_eRuntimeError, "%s", errmsg);
|
203
|
+
return NULL;
|
204
|
+
}
|
205
|
+
|
206
|
+
#else
|
207
|
+
|
208
|
+
Closure*
|
209
|
+
rbffi_Closure_Alloc(ClosurePool* pool)
|
210
|
+
{
|
211
|
+
Closure *closure = NULL;
|
212
|
+
Memory* block = NULL;
|
213
|
+
void *code = NULL;
|
214
|
+
void *pcl = NULL;
|
215
|
+
char errmsg[256];
|
216
|
+
|
217
|
+
block = calloc(1, sizeof(*block));
|
218
|
+
closure = calloc(1, sizeof(*closure));
|
219
|
+
pcl = ffi_closure_alloc(sizeof(ffi_closure), &code);
|
220
|
+
|
221
|
+
if (block == NULL || closure == NULL || pcl == NULL) {
|
222
|
+
snprintf(errmsg, sizeof(errmsg), "failed to allocate a page. errno=%d (%s)", errno, strerror(errno));
|
223
|
+
goto error;
|
224
|
+
}
|
225
|
+
|
226
|
+
closure->pool = pool;
|
227
|
+
closure->code = code;
|
228
|
+
closure->pcl = pcl;
|
229
|
+
|
230
|
+
if (!(*pool->prep)(pool->ctx, closure->code, closure, errmsg, sizeof(errmsg))) {
|
231
|
+
goto error;
|
232
|
+
}
|
233
|
+
|
234
|
+
/* Track the allocated page + Closure memory area */
|
235
|
+
block->data = closure;
|
236
|
+
block->code = pcl;
|
237
|
+
pool->blocks = block;
|
238
|
+
|
239
|
+
/* Thread the new block onto the free list, apart from the first one. */
|
240
|
+
pool->refcnt++;
|
241
|
+
|
242
|
+
return closure;
|
243
|
+
|
244
|
+
error:
|
245
|
+
free(block);
|
246
|
+
free(closure);
|
247
|
+
if (pcl != NULL) {
|
248
|
+
ffi_closure_free(pcl);
|
249
|
+
}
|
250
|
+
|
251
|
+
rb_raise(rb_eRuntimeError, "%s", errmsg);
|
252
|
+
return NULL;
|
253
|
+
}
|
254
|
+
|
255
|
+
#endif /* !USE_FFI_ALLOC */
|
256
|
+
|
257
|
+
void
|
258
|
+
rbffi_Closure_Free(Closure* closure)
|
259
|
+
{
|
260
|
+
if (closure != NULL) {
|
261
|
+
ClosurePool* pool = closure->pool;
|
262
|
+
long refcnt;
|
263
|
+
/* Just push it on the front of the free list */
|
264
|
+
closure->next = pool->list;
|
265
|
+
pool->list = closure;
|
266
|
+
refcnt = --(pool->refcnt);
|
267
|
+
if (refcnt == 0) {
|
268
|
+
cleanup_closure_pool(pool);
|
269
|
+
}
|
270
|
+
}
|
271
|
+
}
|
272
|
+
|
273
|
+
void*
|
274
|
+
rbffi_Closure_CodeAddress(Closure* handle)
|
275
|
+
{
|
276
|
+
return handle->code;
|
277
|
+
}
|
278
|
+
|
279
|
+
|
280
|
+
static long
|
281
|
+
getPageSize()
|
282
|
+
{
|
283
|
+
#if !defined(__CYGWIN__) && (defined(_WIN32) || defined(__WIN32__))
|
284
|
+
SYSTEM_INFO si;
|
285
|
+
GetSystemInfo(&si);
|
286
|
+
return si.dwPageSize;
|
287
|
+
#else
|
288
|
+
return sysconf(_SC_PAGESIZE);
|
289
|
+
#endif
|
290
|
+
}
|
291
|
+
|
292
|
+
#if !USE_FFI_ALLOC
|
293
|
+
|
294
|
+
static void*
|
295
|
+
allocatePage(void)
|
296
|
+
{
|
297
|
+
#if !defined(__CYGWIN__) && (defined(_WIN32) || defined(__WIN32__))
|
298
|
+
return VirtualAlloc(NULL, pageSize, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
|
299
|
+
#else
|
300
|
+
void *page = mmap(NULL, pageSize, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0);
|
301
|
+
return (page != (void *) -1) ? page : NULL;
|
302
|
+
#endif
|
303
|
+
}
|
304
|
+
|
305
|
+
static bool
|
306
|
+
freePage(void *addr)
|
307
|
+
{
|
308
|
+
#if !defined(__CYGWIN__) && (defined(_WIN32) || defined(__WIN32__))
|
309
|
+
return VirtualFree(addr, 0, MEM_RELEASE);
|
310
|
+
#else
|
311
|
+
return munmap(addr, pageSize) == 0;
|
312
|
+
#endif
|
313
|
+
}
|
314
|
+
|
315
|
+
static bool
|
316
|
+
protectPage(void* page)
|
317
|
+
{
|
318
|
+
#if !defined(__CYGWIN__) && (defined(_WIN32) || defined(__WIN32__))
|
319
|
+
DWORD oldProtect;
|
320
|
+
return VirtualProtect(page, pageSize, PAGE_EXECUTE_READ, &oldProtect);
|
321
|
+
#else
|
322
|
+
return mprotect(page, pageSize, PROT_READ | PROT_EXEC) == 0;
|
323
|
+
#endif
|
324
|
+
}
|
325
|
+
|
326
|
+
#endif /* !USE_FFI_ALLOC */
|
327
|
+
|
328
|
+
void
|
329
|
+
rbffi_ClosurePool_Init(VALUE module)
|
330
|
+
{
|
331
|
+
pageSize = getPageSize();
|
332
|
+
}
|
333
|
+
|
@@ -1,6 +1,6 @@
|
|
1
1
|
/*
|
2
2
|
* Copyright (c) 2009, 2010 Wayne Meissner
|
3
|
-
* Copyright (c) 2008-
|
3
|
+
* Copyright (c) 2008-2013, Ruby FFI project contributors
|
4
4
|
* All rights reserved.
|
5
5
|
*
|
6
6
|
* Redistribution and use in source and binary forms, with or without
|
@@ -26,22 +26,34 @@
|
|
26
26
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
27
27
|
*/
|
28
28
|
|
29
|
-
#ifndef
|
30
|
-
#define
|
29
|
+
#ifndef RUBYFFI_CLOSUREPOOL_H
|
30
|
+
#define RUBYFFI_CLOSUREPOOL_H
|
31
31
|
|
32
|
-
|
32
|
+
typedef struct ClosurePool_ ClosurePool;
|
33
|
+
typedef struct Closure_ Closure;
|
33
34
|
|
34
|
-
|
35
|
-
void* info;
|
36
|
-
void* function;
|
37
|
-
void*
|
38
|
-
void
|
39
|
-
} Closure;
|
35
|
+
struct Closure_ {
|
36
|
+
void* info; /* opaque handle for storing closure-instance specific data */
|
37
|
+
void* function; /* closure-instance specific function, called by custom trampoline */
|
38
|
+
void* code; /* Executable address for the native trampoline code location */
|
39
|
+
void* pcl; /* Writeable address for the native trampoline code location */
|
40
40
|
|
41
|
-
|
41
|
+
struct ClosurePool_* pool;
|
42
|
+
Closure* next;
|
43
|
+
};
|
44
|
+
|
45
|
+
void rbffi_ClosurePool_Init(VALUE module);
|
46
|
+
|
47
|
+
ClosurePool* rbffi_ClosurePool_New(int closureSize,
|
48
|
+
bool (*prep)(void* ctx, void *code, Closure* closure, char* errbuf, size_t errbufsize),
|
49
|
+
void* ctx);
|
50
|
+
|
51
|
+
void rbffi_ClosurePool_Free(ClosurePool *);
|
52
|
+
|
53
|
+
Closure* rbffi_Closure_Alloc(ClosurePool *);
|
42
54
|
void rbffi_Closure_Free(Closure *);
|
43
55
|
|
44
|
-
void
|
56
|
+
void* rbffi_Closure_GetCodeAddress(Closure *);
|
45
57
|
|
46
|
-
#endif /*
|
58
|
+
#endif /* RUBYFFI_CLOSUREPOOL_H */
|
47
59
|
|
data/ext/ffi_c/DynamicLibrary.c
CHANGED
@@ -29,9 +29,7 @@
|
|
29
29
|
|
30
30
|
#include <sys/types.h>
|
31
31
|
#include <stdio.h>
|
32
|
-
#
|
33
|
-
# include <stdint.h>
|
34
|
-
#endif
|
32
|
+
#include <stdint.h>
|
35
33
|
#if (defined(_WIN32) || defined(__WIN32__)) && !defined(__CYGWIN__)
|
36
34
|
# include <winsock2.h>
|
37
35
|
# define _WINSOCKAPI_
|
@@ -41,9 +39,6 @@
|
|
41
39
|
# include <dlfcn.h>
|
42
40
|
#endif
|
43
41
|
#include <ruby.h>
|
44
|
-
#if defined(_MSC_VER) && !defined(INT8_MIN)
|
45
|
-
# include "win32/stdint.h"
|
46
|
-
#endif
|
47
42
|
|
48
43
|
#include <ffi.h>
|
49
44
|
|
@@ -55,17 +50,45 @@
|
|
55
50
|
|
56
51
|
typedef struct LibrarySymbol_ {
|
57
52
|
Pointer base;
|
58
|
-
VALUE library;
|
59
53
|
VALUE name;
|
60
54
|
} LibrarySymbol;
|
61
55
|
|
62
|
-
static VALUE library_initialize(VALUE self, VALUE libname, VALUE libflags);
|
63
|
-
static void library_free(Library* lib);
|
64
56
|
|
57
|
+
static VALUE library_initialize(VALUE self, VALUE libname, VALUE libflags);
|
58
|
+
static void library_free(void *);
|
59
|
+
static size_t library_memsize(const void *);
|
65
60
|
|
66
61
|
static VALUE symbol_allocate(VALUE klass);
|
67
62
|
static VALUE symbol_new(VALUE library, void* address, VALUE name);
|
68
|
-
static void symbol_mark(
|
63
|
+
static void symbol_mark(void *data);
|
64
|
+
static void symbol_compact(void *data);
|
65
|
+
static size_t symbol_memsize(const void *data);
|
66
|
+
|
67
|
+
static const rb_data_type_t rbffi_library_data_type = {
|
68
|
+
.wrap_struct_name = "FFI::DynamicLibrary",
|
69
|
+
.function = {
|
70
|
+
.dmark = NULL,
|
71
|
+
.dfree = library_free,
|
72
|
+
.dsize = library_memsize,
|
73
|
+
},
|
74
|
+
// IMPORTANT: WB_PROTECTED objects must only use the RB_OBJ_WRITE()
|
75
|
+
// macro to update VALUE references, as to trigger write barriers.
|
76
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED | FFI_RUBY_TYPED_FROZEN_SHAREABLE
|
77
|
+
};
|
78
|
+
|
79
|
+
static const rb_data_type_t library_symbol_data_type = {
|
80
|
+
.wrap_struct_name = "FFI::DynamicLibrary::Symbol",
|
81
|
+
.function = {
|
82
|
+
.dmark = symbol_mark,
|
83
|
+
.dfree = RUBY_TYPED_DEFAULT_FREE,
|
84
|
+
.dsize = symbol_memsize,
|
85
|
+
ffi_compact_callback( symbol_compact )
|
86
|
+
},
|
87
|
+
.parent = &rbffi_pointer_data_type,
|
88
|
+
// IMPORTANT: WB_PROTECTED objects must only use the RB_OBJ_WRITE()
|
89
|
+
// macro to update VALUE references, as to trigger write barriers.
|
90
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED | FFI_RUBY_TYPED_FROZEN_SHAREABLE
|
91
|
+
};
|
69
92
|
|
70
93
|
static VALUE LibraryClass = Qnil, SymbolClass = Qnil;
|
71
94
|
|
@@ -85,7 +108,7 @@ static VALUE
|
|
85
108
|
library_allocate(VALUE klass)
|
86
109
|
{
|
87
110
|
Library* library;
|
88
|
-
return
|
111
|
+
return TypedData_Make_Struct(klass, Library, &rbffi_library_data_type, library);
|
89
112
|
}
|
90
113
|
|
91
114
|
/*
|
@@ -118,9 +141,9 @@ library_initialize(VALUE self, VALUE libname, VALUE libflags)
|
|
118
141
|
|
119
142
|
Check_Type(libflags, T_FIXNUM);
|
120
143
|
|
121
|
-
|
144
|
+
TypedData_Get_Struct(self, Library, &rbffi_library_data_type, library);
|
122
145
|
flags = libflags != Qnil ? NUM2UINT(libflags) : 0;
|
123
|
-
|
146
|
+
|
124
147
|
library->handle = dl_open(libname != Qnil ? StringValueCStr(libname) : NULL, flags);
|
125
148
|
if (library->handle == NULL) {
|
126
149
|
char errmsg[1024];
|
@@ -138,7 +161,9 @@ library_initialize(VALUE self, VALUE libname, VALUE libflags)
|
|
138
161
|
library->handle = RTLD_DEFAULT;
|
139
162
|
}
|
140
163
|
#endif
|
141
|
-
rb_iv_set(self, "@name", libname != Qnil ? libname : rb_str_new2("[current process]"));
|
164
|
+
rb_iv_set(self, "@name", libname != Qnil ? rb_str_new_frozen(libname) : rb_str_new2("[current process]"));
|
165
|
+
|
166
|
+
rb_obj_freeze(self);
|
142
167
|
return self;
|
143
168
|
}
|
144
169
|
|
@@ -149,9 +174,9 @@ library_dlsym(VALUE self, VALUE name)
|
|
149
174
|
void* address = NULL;
|
150
175
|
Check_Type(name, T_STRING);
|
151
176
|
|
152
|
-
|
177
|
+
TypedData_Get_Struct(self, Library, &rbffi_library_data_type, library);
|
153
178
|
address = dl_sym(library->handle, StringValueCStr(name));
|
154
|
-
|
179
|
+
|
155
180
|
return address != NULL ? symbol_new(self, address, name) : Qnil;
|
156
181
|
}
|
157
182
|
|
@@ -164,12 +189,14 @@ library_dlerror(VALUE self)
|
|
164
189
|
{
|
165
190
|
char errmsg[1024];
|
166
191
|
dl_error(errmsg, sizeof(errmsg));
|
167
|
-
return
|
192
|
+
return rb_str_new2(errmsg);
|
168
193
|
}
|
169
194
|
|
170
195
|
static void
|
171
|
-
library_free(
|
196
|
+
library_free(void *data)
|
172
197
|
{
|
198
|
+
Library *library = (Library*)data;
|
199
|
+
|
173
200
|
/* dlclose() on MacOS tends to segfault - avoid it */
|
174
201
|
#ifndef __APPLE__
|
175
202
|
if (library->handle != NULL) {
|
@@ -179,6 +206,12 @@ library_free(Library* library)
|
|
179
206
|
xfree(library);
|
180
207
|
}
|
181
208
|
|
209
|
+
static size_t
|
210
|
+
library_memsize(const void *data)
|
211
|
+
{
|
212
|
+
return sizeof(Library);
|
213
|
+
}
|
214
|
+
|
182
215
|
#if (defined(_WIN32) || defined(__WIN32__)) && !defined(__CYGWIN__)
|
183
216
|
static void*
|
184
217
|
dl_open(const char* name, int flags)
|
@@ -194,8 +227,19 @@ dl_open(const char* name, int flags)
|
|
194
227
|
static void
|
195
228
|
dl_error(char* buf, int size)
|
196
229
|
{
|
197
|
-
|
198
|
-
|
230
|
+
// Get the last error code
|
231
|
+
DWORD error = GetLastError();
|
232
|
+
|
233
|
+
// Get the associated message
|
234
|
+
LPSTR message = NULL;
|
235
|
+
FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER,
|
236
|
+
NULL, error, 0, (LPSTR)&message, 0, NULL);
|
237
|
+
|
238
|
+
// Update the passed in buffer
|
239
|
+
snprintf(buf, size, "Failed with error %d: %s", error, message);
|
240
|
+
|
241
|
+
// Free the allocated message
|
242
|
+
LocalFree(message);
|
199
243
|
}
|
200
244
|
#endif
|
201
245
|
|
@@ -203,10 +247,9 @@ static VALUE
|
|
203
247
|
symbol_allocate(VALUE klass)
|
204
248
|
{
|
205
249
|
LibrarySymbol* sym;
|
206
|
-
VALUE obj =
|
207
|
-
sym->
|
208
|
-
sym->
|
209
|
-
sym->base.rbParent = Qnil;
|
250
|
+
VALUE obj = TypedData_Make_Struct(klass, LibrarySymbol, &library_symbol_data_type, sym);
|
251
|
+
RB_OBJ_WRITE(obj, &sym->base.rbParent, Qnil);
|
252
|
+
RB_OBJ_WRITE(obj, &sym->name, Qnil);
|
210
253
|
|
211
254
|
return obj;
|
212
255
|
}
|
@@ -229,23 +272,39 @@ static VALUE
|
|
229
272
|
symbol_new(VALUE library, void* address, VALUE name)
|
230
273
|
{
|
231
274
|
LibrarySymbol* sym;
|
232
|
-
VALUE obj =
|
275
|
+
VALUE obj = TypedData_Make_Struct(SymbolClass, LibrarySymbol, &library_symbol_data_type, sym);
|
233
276
|
|
234
277
|
sym->base.memory.address = address;
|
235
278
|
sym->base.memory.size = LONG_MAX;
|
236
279
|
sym->base.memory.typeSize = 1;
|
237
280
|
sym->base.memory.flags = MEM_RD | MEM_WR;
|
238
|
-
sym->
|
239
|
-
sym->name
|
281
|
+
RB_OBJ_WRITE(obj, &sym->base.rbParent, library);
|
282
|
+
RB_OBJ_WRITE(obj, &sym->name, rb_str_new_frozen(name));
|
240
283
|
|
284
|
+
rb_obj_freeze(obj);
|
241
285
|
return obj;
|
242
286
|
}
|
243
287
|
|
244
288
|
static void
|
245
|
-
symbol_mark(
|
289
|
+
symbol_mark(void *data)
|
246
290
|
{
|
247
|
-
|
248
|
-
|
291
|
+
LibrarySymbol *sym = (LibrarySymbol *)data;
|
292
|
+
rb_gc_mark_movable(sym->base.rbParent);
|
293
|
+
rb_gc_mark_movable(sym->name);
|
294
|
+
}
|
295
|
+
|
296
|
+
static void
|
297
|
+
symbol_compact(void *data)
|
298
|
+
{
|
299
|
+
LibrarySymbol *sym = (LibrarySymbol *)data;
|
300
|
+
ffi_gc_location(sym->base.rbParent);
|
301
|
+
ffi_gc_location(sym->name);
|
302
|
+
}
|
303
|
+
|
304
|
+
static size_t
|
305
|
+
symbol_memsize(const void *data)
|
306
|
+
{
|
307
|
+
return sizeof(LibrarySymbol);
|
249
308
|
}
|
250
309
|
|
251
310
|
/*
|
@@ -259,8 +318,8 @@ symbol_inspect(VALUE self)
|
|
259
318
|
LibrarySymbol* sym;
|
260
319
|
char buf[256];
|
261
320
|
|
262
|
-
|
263
|
-
snprintf(buf, sizeof(buf), "#<FFI::
|
321
|
+
TypedData_Get_Struct(self, LibrarySymbol, &library_symbol_data_type, sym);
|
322
|
+
snprintf(buf, sizeof(buf), "#<FFI::DynamicLibrary::Symbol name=%s address=%p>",
|
264
323
|
StringValueCStr(sym->name), sym->base.memory.address);
|
265
324
|
return rb_str_new2(buf);
|
266
325
|
}
|
@@ -336,4 +395,3 @@ rbffi_DynamicLibrary_Init(VALUE moduleFFI)
|
|
336
395
|
#undef DEF
|
337
396
|
|
338
397
|
}
|
339
|
-
|