ffi 1.15.5 → 1.16.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (309) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/CHANGELOG.md +61 -0
  4. data/Gemfile +1 -1
  5. data/README.md +3 -2
  6. data/Rakefile +10 -7
  7. data/ext/ffi_c/AbstractMemory.c +56 -34
  8. data/ext/ffi_c/AbstractMemory.h +3 -2
  9. data/ext/ffi_c/ArrayType.c +49 -13
  10. data/ext/ffi_c/ArrayType.h +1 -0
  11. data/ext/ffi_c/Buffer.c +86 -29
  12. data/ext/ffi_c/Call.c +13 -5
  13. data/ext/ffi_c/DynamicLibrary.c +89 -26
  14. data/ext/ffi_c/Function.c +238 -98
  15. data/ext/ffi_c/Function.h +1 -0
  16. data/ext/ffi_c/FunctionInfo.c +78 -24
  17. data/ext/ffi_c/LastError.c +25 -7
  18. data/ext/ffi_c/MappedType.c +66 -23
  19. data/ext/ffi_c/MappedType.h +0 -2
  20. data/ext/ffi_c/MemoryPointer.c +34 -7
  21. data/ext/ffi_c/MethodHandle.c +3 -1
  22. data/ext/ffi_c/Pointer.c +68 -29
  23. data/ext/ffi_c/Pointer.h +1 -0
  24. data/ext/ffi_c/Struct.c +151 -80
  25. data/ext/ffi_c/Struct.h +7 -4
  26. data/ext/ffi_c/StructByValue.c +48 -16
  27. data/ext/ffi_c/StructLayout.c +117 -48
  28. data/ext/ffi_c/Type.c +104 -36
  29. data/ext/ffi_c/Type.h +3 -1
  30. data/ext/ffi_c/Types.c +1 -1
  31. data/ext/ffi_c/Variadic.c +65 -23
  32. data/ext/ffi_c/compat.h +22 -22
  33. data/ext/ffi_c/extconf.rb +19 -2
  34. data/ext/ffi_c/ffi.c +4 -0
  35. data/ext/ffi_c/libffi/.appveyor/site.exp +16 -0
  36. data/ext/ffi_c/libffi/.appveyor/unix-noexec.exp +7 -0
  37. data/ext/ffi_c/libffi/.appveyor.yml +27 -9
  38. data/ext/ffi_c/libffi/.ci/build-cross-in-container.sh +18 -0
  39. data/ext/ffi_c/libffi/{.travis → .ci}/build-in-container.sh +4 -6
  40. data/ext/ffi_c/libffi/.ci/build.sh +124 -0
  41. data/ext/ffi_c/libffi/{.travis → .ci}/install.sh +14 -7
  42. data/ext/ffi_c/libffi/.ci/msvs-detect +1103 -0
  43. data/ext/ffi_c/libffi/{.travis → .ci}/site.exp +5 -3
  44. data/ext/ffi_c/libffi/.circleci/config.yml +156 -0
  45. data/ext/ffi_c/libffi/.github/workflows/build.yml +460 -0
  46. data/ext/ffi_c/libffi/.github/workflows/emscripten.yml +171 -0
  47. data/ext/ffi_c/libffi/.gitignore +10 -2
  48. data/ext/ffi_c/libffi/LICENSE +1 -1
  49. data/ext/ffi_c/libffi/Makefile.am +12 -5
  50. data/ext/ffi_c/libffi/Makefile.in +118 -51
  51. data/ext/ffi_c/libffi/README.md +144 -104
  52. data/ext/ffi_c/libffi/acinclude.m4 +10 -112
  53. data/ext/ffi_c/libffi/compile +347 -0
  54. data/ext/ffi_c/libffi/config.guess +623 -556
  55. data/ext/ffi_c/libffi/config.sub +75 -34
  56. data/ext/ffi_c/libffi/configure +4571 -3830
  57. data/ext/ffi_c/libffi/configure.ac +64 -28
  58. data/ext/ffi_c/libffi/configure.host +25 -6
  59. data/ext/ffi_c/libffi/doc/Makefile.in +9 -6
  60. data/ext/ffi_c/libffi/doc/libffi.texi +82 -33
  61. data/ext/ffi_c/libffi/doc/version.texi +4 -4
  62. data/ext/ffi_c/libffi/fficonfig.h.in +12 -47
  63. data/ext/ffi_c/libffi/generate-darwin-source-and-headers.py +163 -52
  64. data/ext/ffi_c/libffi/include/Makefile.am +1 -1
  65. data/ext/ffi_c/libffi/include/Makefile.in +10 -9
  66. data/ext/ffi_c/libffi/include/ffi.h.in +54 -50
  67. data/ext/ffi_c/libffi/include/ffi_cfi.h +21 -0
  68. data/ext/ffi_c/libffi/include/ffi_common.h +29 -0
  69. data/ext/ffi_c/libffi/include/tramp.h +45 -0
  70. data/ext/ffi_c/libffi/install-sh +92 -69
  71. data/ext/ffi_c/libffi/libtool-version +2 -2
  72. data/ext/ffi_c/libffi/ltmain.sh +512 -315
  73. data/ext/ffi_c/libffi/m4/ax_cc_maxopt.m4 +18 -14
  74. data/ext/ffi_c/libffi/m4/ax_cflags_warn_all.m4 +108 -72
  75. data/ext/ffi_c/libffi/m4/ax_compiler_vendor.m4 +76 -45
  76. data/ext/ffi_c/libffi/m4/ax_prepend_flag.m4 +51 -0
  77. data/ext/ffi_c/libffi/man/Makefile.in +9 -6
  78. data/ext/ffi_c/libffi/missing +1 -1
  79. data/ext/ffi_c/libffi/msvc_build/aarch64/aarch64_include/ffi.h +1 -1
  80. data/ext/ffi_c/libffi/msvcc.sh +1 -1
  81. data/ext/ffi_c/libffi/src/aarch64/ffi.c +146 -42
  82. data/ext/ffi_c/libffi/src/aarch64/internal.h +32 -0
  83. data/ext/ffi_c/libffi/src/aarch64/sysv.S +134 -42
  84. data/ext/ffi_c/libffi/src/arc/arcompact.S +169 -94
  85. data/ext/ffi_c/libffi/src/arc/ffi.c +325 -148
  86. data/ext/ffi_c/libffi/src/arc/ffitarget.h +14 -0
  87. data/ext/ffi_c/libffi/src/arm/ffi.c +62 -17
  88. data/ext/ffi_c/libffi/src/arm/ffitarget.h +3 -3
  89. data/ext/ffi_c/libffi/src/arm/internal.h +10 -0
  90. data/ext/ffi_c/libffi/src/arm/sysv.S +113 -42
  91. data/ext/ffi_c/libffi/src/closures.c +133 -47
  92. data/ext/ffi_c/libffi/src/dlmalloc.c +5 -0
  93. data/ext/ffi_c/libffi/src/ia64/ffi.c +12 -0
  94. data/ext/ffi_c/libffi/src/ia64/unix.S +20 -2
  95. data/ext/ffi_c/libffi/src/loongarch64/ffi.c +621 -0
  96. data/ext/ffi_c/libffi/src/loongarch64/ffitarget.h +82 -0
  97. data/ext/ffi_c/libffi/src/loongarch64/sysv.S +327 -0
  98. data/ext/ffi_c/libffi/src/m32r/ffi.c +31 -14
  99. data/ext/ffi_c/libffi/src/mips/ffi.c +240 -65
  100. data/ext/ffi_c/libffi/src/mips/ffitarget.h +7 -0
  101. data/ext/ffi_c/libffi/src/mips/n32.S +137 -28
  102. data/ext/ffi_c/libffi/src/mips/o32.S +61 -4
  103. data/ext/ffi_c/libffi/src/moxie/ffi.c +47 -22
  104. data/ext/ffi_c/libffi/src/or1k/ffi.c +25 -12
  105. data/ext/ffi_c/libffi/src/pa/ffi.c +32 -33
  106. data/ext/ffi_c/libffi/src/pa/ffi64.c +614 -0
  107. data/ext/ffi_c/libffi/src/pa/ffitarget.h +22 -8
  108. data/ext/ffi_c/libffi/src/pa/hpux32.S +83 -36
  109. data/ext/ffi_c/libffi/src/pa/hpux64.S +681 -0
  110. data/ext/ffi_c/libffi/src/pa/linux.S +82 -35
  111. data/ext/ffi_c/libffi/src/powerpc/ffi_linux64.c +1 -1
  112. data/ext/ffi_c/libffi/src/powerpc/linux64.S +2 -0
  113. data/ext/ffi_c/libffi/src/powerpc/linux64_closure.S +2 -0
  114. data/ext/ffi_c/libffi/src/powerpc/t-aix +5 -0
  115. data/ext/ffi_c/libffi/src/prep_cif.c +22 -2
  116. data/ext/ffi_c/libffi/src/riscv/ffi.c +37 -4
  117. data/ext/ffi_c/libffi/src/sparc/ffi64.c +16 -0
  118. data/ext/ffi_c/libffi/src/tramp.c +716 -0
  119. data/ext/ffi_c/libffi/src/wasm32/ffi.c +934 -0
  120. data/ext/ffi_c/libffi/src/wasm32/ffitarget.h +62 -0
  121. data/ext/ffi_c/libffi/src/x86/ffi.c +99 -37
  122. data/ext/ffi_c/libffi/src/x86/ffi64.c +67 -12
  123. data/ext/ffi_c/libffi/src/x86/ffitarget.h +9 -5
  124. data/ext/ffi_c/libffi/src/x86/ffiw64.c +43 -0
  125. data/ext/ffi_c/libffi/src/x86/internal.h +14 -0
  126. data/ext/ffi_c/libffi/src/x86/internal64.h +14 -0
  127. data/ext/ffi_c/libffi/src/x86/sysv.S +172 -38
  128. data/ext/ffi_c/libffi/src/x86/sysv_intel.S +91 -88
  129. data/ext/ffi_c/libffi/src/x86/unix64.S +96 -6
  130. data/ext/ffi_c/libffi/src/x86/win64.S +20 -7
  131. data/ext/ffi_c/libffi/src/xtensa/ffi.c +16 -8
  132. data/ext/ffi_c/libffi/src/xtensa/ffitarget.h +4 -0
  133. data/ext/ffi_c/libffi/src/xtensa/sysv.S +26 -16
  134. data/ext/ffi_c/libffi/testsuite/Makefile.am +127 -114
  135. data/ext/ffi_c/libffi/testsuite/Makefile.in +137 -121
  136. data/ext/ffi_c/libffi/testsuite/emscripten/build-tests.sh +54 -0
  137. data/ext/ffi_c/libffi/testsuite/emscripten/build.sh +63 -0
  138. data/ext/ffi_c/libffi/testsuite/emscripten/conftest.py +80 -0
  139. data/ext/ffi_c/libffi/testsuite/emscripten/node-tests.sh +48 -0
  140. data/ext/ffi_c/libffi/testsuite/emscripten/test.html +7 -0
  141. data/ext/ffi_c/libffi/testsuite/emscripten/test_libffi.py +51 -0
  142. data/ext/ffi_c/libffi/testsuite/lib/libffi.exp +43 -21
  143. data/ext/ffi_c/libffi/testsuite/lib/target-libpath.exp +2 -2
  144. data/ext/ffi_c/libffi/testsuite/libffi.bhaible/test-call.c +1 -0
  145. data/ext/ffi_c/libffi/testsuite/libffi.bhaible/testcases.c +5 -1
  146. data/ext/ffi_c/libffi/testsuite/libffi.call/bpo_38748.c +41 -0
  147. data/ext/ffi_c/libffi/testsuite/libffi.call/ffitest.h +28 -3
  148. data/ext/ffi_c/libffi/testsuite/libffi.call/float_va.c +3 -0
  149. data/ext/ffi_c/libffi/testsuite/libffi.call/return_ll1.c +5 -0
  150. data/ext/ffi_c/libffi/testsuite/libffi.call/return_sl.c +4 -0
  151. data/ext/ffi_c/libffi/testsuite/libffi.call/return_ul.c +4 -0
  152. data/ext/ffi_c/libffi/testsuite/libffi.call/s55.c +60 -0
  153. data/ext/ffi_c/libffi/testsuite/libffi.call/strlen.c +8 -9
  154. data/ext/ffi_c/libffi/testsuite/libffi.call/strlen2.c +2 -2
  155. data/ext/ffi_c/libffi/testsuite/libffi.call/strlen3.c +2 -2
  156. data/ext/ffi_c/libffi/testsuite/libffi.call/strlen4.c +2 -2
  157. data/ext/ffi_c/libffi/testsuite/libffi.call/struct10.c +1 -1
  158. data/ext/ffi_c/libffi/testsuite/libffi.call/struct_by_value_2.c +63 -0
  159. data/ext/ffi_c/libffi/testsuite/libffi.call/struct_by_value_3.c +65 -0
  160. data/ext/ffi_c/libffi/testsuite/libffi.call/struct_by_value_3f.c +65 -0
  161. data/ext/ffi_c/libffi/testsuite/libffi.call/struct_by_value_4.c +67 -0
  162. data/ext/ffi_c/libffi/testsuite/libffi.call/struct_by_value_4f.c +67 -0
  163. data/ext/ffi_c/libffi/testsuite/libffi.call/struct_by_value_big.c +93 -0
  164. data/ext/ffi_c/libffi/testsuite/libffi.call/struct_by_value_small.c +61 -0
  165. data/ext/ffi_c/libffi/testsuite/libffi.call/struct_return_2H.c +63 -0
  166. data/ext/ffi_c/libffi/testsuite/libffi.call/struct_return_8H.c +90 -0
  167. data/ext/ffi_c/libffi/testsuite/libffi.call/va_1.c +1 -119
  168. data/ext/ffi_c/libffi/testsuite/libffi.call/va_2.c +220 -0
  169. data/ext/ffi_c/libffi/testsuite/libffi.call/va_3.c +154 -0
  170. data/ext/ffi_c/libffi/testsuite/libffi.call/va_struct1.c +13 -0
  171. data/ext/ffi_c/libffi/testsuite/libffi.call/va_struct2.c +11 -0
  172. data/ext/ffi_c/libffi/testsuite/libffi.call/va_struct3.c +15 -0
  173. data/ext/ffi_c/libffi/testsuite/libffi.closures/closure_fn0.c +3 -2
  174. data/ext/ffi_c/libffi/testsuite/libffi.closures/closure_fn1.c +2 -0
  175. data/ext/ffi_c/libffi/testsuite/libffi.closures/closure_fn2.c +2 -0
  176. data/ext/ffi_c/libffi/testsuite/libffi.closures/closure_fn3.c +21 -1
  177. data/ext/ffi_c/libffi/testsuite/libffi.closures/closure_fn4.c +2 -0
  178. data/ext/ffi_c/libffi/testsuite/libffi.closures/closure_fn5.c +2 -0
  179. data/ext/ffi_c/libffi/testsuite/libffi.closures/closure_fn6.c +2 -0
  180. data/ext/ffi_c/libffi/testsuite/libffi.closures/closure_loc_fn0.c +7 -6
  181. data/ext/ffi_c/libffi/testsuite/libffi.closures/closure_simple.c +6 -0
  182. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_12byte.c +18 -0
  183. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_16byte.c +22 -0
  184. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_18byte.c +24 -0
  185. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_19byte.c +29 -0
  186. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_1_1byte.c +4 -0
  187. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_20byte.c +19 -1
  188. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_20byte1.c +21 -1
  189. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_24byte.c +35 -3
  190. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_2byte.c +13 -0
  191. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_3_1byte.c +19 -0
  192. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_3byte1.c +13 -0
  193. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_3byte2.c +13 -0
  194. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_3float.c +18 -0
  195. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_4_1byte.c +22 -0
  196. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_4byte.c +13 -0
  197. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_5_1_byte.c +29 -1
  198. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_5byte.c +19 -1
  199. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_64byte.c +24 -0
  200. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_6_1_byte.c +28 -1
  201. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_6byte.c +24 -2
  202. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_7_1_byte.c +39 -1
  203. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_7byte.c +25 -1
  204. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_8byte.c +14 -0
  205. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_9byte1.c +14 -1
  206. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_9byte2.c +14 -2
  207. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_double.c +19 -1
  208. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_float.c +19 -1
  209. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_longdouble.c +20 -1
  210. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_longdouble_split.c +40 -25
  211. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_longdouble_split2.c +40 -3
  212. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_pointer.c +19 -1
  213. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_sint16.c +18 -1
  214. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_sint32.c +18 -3
  215. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_sint64.c +18 -1
  216. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_uint16.c +18 -1
  217. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_uint32.c +19 -1
  218. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_uint64.c +19 -1
  219. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_dbls_struct.c +3 -1
  220. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_double_va.c +9 -1
  221. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_float.c +4 -0
  222. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_longdouble.c +11 -1
  223. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_longdouble_va.c +22 -3
  224. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_multi_schar.c +5 -1
  225. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_multi_sshort.c +6 -1
  226. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_multi_sshortchar.c +9 -1
  227. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_multi_uchar.c +9 -1
  228. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_multi_ushort.c +6 -2
  229. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_multi_ushortchar.c +9 -1
  230. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_pointer.c +5 -0
  231. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_pointer_stack.c +10 -0
  232. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_schar.c +3 -0
  233. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_sint.c +2 -0
  234. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_sshort.c +3 -0
  235. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_struct_va1.c +11 -0
  236. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_uchar.c +3 -0
  237. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_uint.c +4 -0
  238. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_uint_va.c +4 -0
  239. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_ulong_va.c +4 -0
  240. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_ulonglong.c +2 -0
  241. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_ushort.c +3 -0
  242. data/ext/ffi_c/libffi/testsuite/libffi.closures/ffitest.h +1 -138
  243. data/ext/ffi_c/libffi/testsuite/libffi.closures/huge_struct.c +21 -21
  244. data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct.c +32 -9
  245. data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct1.c +1 -1
  246. data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct10.c +12 -0
  247. data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct11.c +21 -5
  248. data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct12.c +86 -0
  249. data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct13.c +115 -0
  250. data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct2.c +10 -1
  251. data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct3.c +10 -1
  252. data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct4.c +9 -0
  253. data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct5.c +9 -0
  254. data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct6.c +11 -0
  255. data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct7.c +9 -0
  256. data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct8.c +11 -0
  257. data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct9.c +11 -0
  258. data/ext/ffi_c/libffi/testsuite/libffi.closures/single_entry_structs1.c +86 -0
  259. data/ext/ffi_c/libffi/testsuite/libffi.closures/single_entry_structs2.c +102 -0
  260. data/ext/ffi_c/libffi/testsuite/libffi.closures/single_entry_structs3.c +101 -0
  261. data/ext/ffi_c/libffi/testsuite/libffi.closures/stret_medium.c +1 -1
  262. data/ext/ffi_c/libffi/testsuite/libffi.closures/stret_medium2.c +1 -1
  263. data/ext/ffi_c/libffi/testsuite/libffi.closures/testclosure.c +6 -1
  264. data/ext/ffi_c/libffi/testsuite/libffi.closures/unwindtest.cc +2 -1
  265. data/ext/ffi_c/libffi/testsuite/libffi.closures/unwindtest_ffi_call.cc +1 -0
  266. data/ext/ffi_c/libffi.bsd.mk +2 -2
  267. data/ext/ffi_c/libffi.gnu.mk +2 -2
  268. data/ext/ffi_c/rbffi.h +1 -1
  269. data/ffi.gemspec +3 -3
  270. data/lib/ffi/autopointer.rb +7 -22
  271. data/lib/ffi/compat.rb +43 -0
  272. data/lib/ffi/data_converter.rb +2 -2
  273. data/lib/ffi/dynamic_library.rb +89 -0
  274. data/lib/ffi/enum.rb +18 -11
  275. data/lib/ffi/ffi.rb +3 -0
  276. data/lib/ffi/function.rb +71 -0
  277. data/lib/ffi/library.rb +55 -71
  278. data/lib/ffi/library_path.rb +109 -0
  279. data/lib/ffi/managedstruct.rb +1 -1
  280. data/lib/ffi/platform/aarch64-windows/types.conf +52 -0
  281. data/lib/ffi/platform/hppa1.1-linux/types.conf +178 -0
  282. data/lib/ffi/platform/hppa2.0-linux/types.conf +178 -0
  283. data/lib/ffi/platform/loongarch64-linux/types.conf +141 -0
  284. data/lib/ffi/platform/sw_64-linux/types.conf +141 -0
  285. data/lib/ffi/platform.rb +15 -13
  286. data/lib/ffi/struct.rb +2 -1
  287. data/lib/ffi/struct_layout.rb +1 -1
  288. data/lib/ffi/struct_layout_builder.rb +1 -1
  289. data/lib/ffi/types.rb +30 -5
  290. data/lib/ffi/variadic.rb +19 -8
  291. data/lib/ffi/version.rb +1 -1
  292. data.tar.gz.sig +3 -0
  293. metadata +98 -25
  294. metadata.gz.sig +3 -0
  295. data/ext/ffi_c/libffi/.travis/build-cross-in-container.sh +0 -14
  296. data/ext/ffi_c/libffi/.travis/build.sh +0 -142
  297. data/ext/ffi_c/libffi/.travis.yml +0 -83
  298. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_uchar_va.c +0 -44
  299. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_ushort_va.c +0 -44
  300. /data/ext/ffi_c/libffi/{.travis → .ci}/ar-lib +0 -0
  301. /data/ext/ffi_c/libffi/{.travis → .ci}/bfin-sim.exp +0 -0
  302. /data/ext/ffi_c/libffi/{.travis → .ci}/compile +0 -0
  303. /data/ext/ffi_c/libffi/{.travis → .ci}/m32r-sim.exp +0 -0
  304. /data/ext/ffi_c/libffi/{.travis → .ci}/moxie-sim.exp +0 -0
  305. /data/ext/ffi_c/libffi/{.travis → .ci}/or1k-sim.exp +0 -0
  306. /data/ext/ffi_c/libffi/{.travis → .ci}/powerpc-eabisim.exp +0 -0
  307. /data/ext/ffi_c/libffi/{.travis → .ci}/wine-sim.exp +0 -0
  308. /data/ext/ffi_c/libffi/testsuite/libffi.call/{pyobjc-tc.c → pyobjc_tc.c} +0 -0
  309. /data/lib/ffi/platform/{sparc64-linux → sparcv9-linux}/types.conf +0 -0
@@ -1,9 +1,9 @@
1
1
  /* -----------------------------------------------------------------------
2
- sysv.S - Copyright (c) 2017 Anthony Green
2
+ sysv.S - Copyright (c) 2017, 2022 Anthony Green
3
3
  - Copyright (c) 2013 The Written Word, Inc.
4
4
  - Copyright (c) 1996,1998,2001-2003,2005,2008,2010 Red Hat, Inc.
5
-
6
- X86 Foreign Function Interface
5
+
6
+ X86 Foreign Function Interface
7
7
 
8
8
  Permission is hereby granted, free of charge, to any person obtaining
9
9
  a copy of this software and associated documentation files (the
@@ -29,11 +29,11 @@
29
29
  #ifndef __x86_64__
30
30
  #ifdef _MSC_VER
31
31
 
32
- #define LIBFFI_ASM
32
+ #define LIBFFI_ASM
33
33
  #include <fficonfig.h>
34
34
  #include <ffi.h>
35
35
  #include <ffi_cfi.h>
36
- #include "internal.h"
36
+ #include "internal.h"
37
37
 
38
38
  #define C2(X, Y) X ## Y
39
39
  #define C1(X, Y) C2(X, Y)
@@ -89,8 +89,8 @@ L(UW0):
89
89
  perspective of the unwind info, it hasn't moved. */
90
90
  mov ebp, ecx
91
91
  L(UW1):
92
- // cfi_def_cfa(%ebp, 8)
93
- // cfi_rel_offset(%ebp, 0)
92
+ /* cfi_def_cfa(%ebp, 8) */
93
+ /* cfi_rel_offset(%ebp, 0) */
94
94
 
95
95
  mov esp, edx /* set outgoing argument stack */
96
96
  mov eax, [20+R_EAX*4+ebp] /* set register arguments */
@@ -102,7 +102,7 @@ L(UW1):
102
102
  mov ecx, [12+ebp] /* load return type code */
103
103
  mov [ebp+8], ebx /* preserve %ebx */
104
104
  L(UW2):
105
- // cfi_rel_offset(%ebx, 8)
105
+ /* cfi_rel_offset(%ebx, 8) */
106
106
 
107
107
  and ecx, X86_RET_TYPE_MASK
108
108
  lea ebx, [L(store_table) + ecx * 8]
@@ -148,13 +148,13 @@ L(e1):
148
148
  mov esp, ebp
149
149
  pop ebp
150
150
  L(UW3):
151
- // cfi_remember_state
152
- // cfi_def_cfa(%esp, 4)
153
- // cfi_restore(%ebx)
154
- // cfi_restore(%ebp)
151
+ /* cfi_remember_state */
152
+ /* cfi_def_cfa(%esp, 4) */
153
+ /* cfi_restore(%ebx) */
154
+ /* cfi_restore(%ebp) */
155
155
  ret
156
156
  L(UW4):
157
- // cfi_restore_state
157
+ /* cfi_restore_state */
158
158
 
159
159
  E(L(store_table), X86_RET_STRUCTPOP)
160
160
  jmp L(e1)
@@ -174,7 +174,7 @@ E(L(store_table), X86_RET_UNUSED15)
174
174
  int 3
175
175
 
176
176
  L(UW5):
177
- // cfi_endproc
177
+ /* cfi_endproc */
178
178
  ENDF(@ffi_call_i386@8)
179
179
 
180
180
  /* The inner helper is declared as
@@ -242,10 +242,10 @@ ALIGN 16
242
242
  PUBLIC ffi_go_closure_EAX
243
243
  ffi_go_closure_EAX PROC C
244
244
  L(UW6):
245
- // cfi_startproc
245
+ /* cfi_startproc */
246
246
  sub esp, closure_FS
247
247
  L(UW7):
248
- // cfi_def_cfa_offset(closure_FS + 4)
248
+ /* cfi_def_cfa_offset(closure_FS + 4) */
249
249
  FFI_CLOSURE_SAVE_REGS
250
250
  mov edx, [eax+4] /* copy cif */
251
251
  mov ecx, [eax +8] /* copy fun */
@@ -254,17 +254,17 @@ L(UW7):
254
254
  mov [esp+closure_CF+36], eax /* closure is user_data */
255
255
  jmp L(do_closure_i386)
256
256
  L(UW8):
257
- // cfi_endproc
257
+ /* cfi_endproc */
258
258
  ENDF(ffi_go_closure_EAX)
259
259
 
260
260
  ALIGN 16
261
261
  PUBLIC ffi_go_closure_ECX
262
262
  ffi_go_closure_ECX PROC C
263
263
  L(UW9):
264
- // cfi_startproc
264
+ /* cfi_startproc */
265
265
  sub esp, closure_FS
266
266
  L(UW10):
267
- // cfi_def_cfa_offset(closure_FS + 4)
267
+ /* cfi_def_cfa_offset(closure_FS + 4) */
268
268
  FFI_CLOSURE_SAVE_REGS
269
269
  mov edx, [ecx+4] /* copy cif */
270
270
  mov eax, [ecx+8] /* copy fun */
@@ -273,7 +273,7 @@ L(UW10):
273
273
  mov [esp+closure_CF+36], ecx /* closure is user_data */
274
274
  jmp L(do_closure_i386)
275
275
  L(UW11):
276
- // cfi_endproc
276
+ /* cfi_endproc */
277
277
  ENDF(ffi_go_closure_ECX)
278
278
 
279
279
  /* The closure entry points are reached from the ffi_closure trampoline.
@@ -283,10 +283,10 @@ ALIGN 16
283
283
  PUBLIC ffi_closure_i386
284
284
  ffi_closure_i386 PROC C
285
285
  L(UW12):
286
- // cfi_startproc
286
+ /* cfi_startproc */
287
287
  sub esp, closure_FS
288
288
  L(UW13):
289
- // cfi_def_cfa_offset(closure_FS + 4)
289
+ /* cfi_def_cfa_offset(closure_FS + 4) */
290
290
 
291
291
  FFI_CLOSURE_SAVE_REGS
292
292
  FFI_CLOSURE_COPY_TRAMP_DATA
@@ -331,17 +331,17 @@ E(L(load_table2), X86_RET_VOID)
331
331
  L(e2):
332
332
  add esp, closure_FS
333
333
  L(UW16):
334
- // cfi_adjust_cfa_offset(-closure_FS)
334
+ /* cfi_adjust_cfa_offset(-closure_FS) */
335
335
  ret
336
336
  L(UW17):
337
- // cfi_adjust_cfa_offset(closure_FS)
337
+ /* cfi_adjust_cfa_offset(closure_FS) */
338
338
  E(L(load_table2), X86_RET_STRUCTPOP)
339
339
  add esp, closure_FS
340
340
  L(UW18):
341
- // cfi_adjust_cfa_offset(-closure_FS)
341
+ /* cfi_adjust_cfa_offset(-closure_FS) */
342
342
  ret 4
343
343
  L(UW19):
344
- // cfi_adjust_cfa_offset(closure_FS)
344
+ /* cfi_adjust_cfa_offset(closure_FS) */
345
345
  E(L(load_table2), X86_RET_STRUCTARG)
346
346
  jmp L(e2)
347
347
  E(L(load_table2), X86_RET_STRUCT_1B)
@@ -358,17 +358,17 @@ E(L(load_table2), X86_RET_UNUSED15)
358
358
  int 3
359
359
 
360
360
  L(UW20):
361
- // cfi_endproc
361
+ /* cfi_endproc */
362
362
  ENDF(ffi_closure_i386)
363
363
 
364
364
  ALIGN 16
365
365
  PUBLIC ffi_go_closure_STDCALL
366
366
  ffi_go_closure_STDCALL PROC C
367
367
  L(UW21):
368
- // cfi_startproc
368
+ /* cfi_startproc */
369
369
  sub esp, closure_FS
370
370
  L(UW22):
371
- // cfi_def_cfa_offset(closure_FS + 4)
371
+ /* cfi_def_cfa_offset(closure_FS + 4) */
372
372
  FFI_CLOSURE_SAVE_REGS
373
373
  mov edx, [ecx+4] /* copy cif */
374
374
  mov eax, [ecx+8] /* copy fun */
@@ -377,7 +377,7 @@ L(UW22):
377
377
  mov [esp+closure_CF+36], ecx /* closure is user_data */
378
378
  jmp L(do_closure_STDCALL)
379
379
  L(UW23):
380
- // cfi_endproc
380
+ /* cfi_endproc */
381
381
  ENDF(ffi_go_closure_STDCALL)
382
382
 
383
383
  /* For REGISTER, we have no available parameter registers, and so we
@@ -387,19 +387,19 @@ ALIGN 16
387
387
  PUBLIC ffi_closure_REGISTER
388
388
  ffi_closure_REGISTER PROC C
389
389
  L(UW24):
390
- // cfi_startproc
391
- // cfi_def_cfa(%esp, 8)
392
- // cfi_offset(%eip, -8)
390
+ /* cfi_startproc */
391
+ /* cfi_def_cfa(%esp, 8) */
392
+ /* cfi_offset(%eip, -8) */
393
393
  sub esp, closure_FS-4
394
394
  L(UW25):
395
- // cfi_def_cfa_offset(closure_FS + 4)
395
+ /* cfi_def_cfa_offset(closure_FS + 4) */
396
396
  FFI_CLOSURE_SAVE_REGS
397
397
  mov ecx, [esp+closure_FS-4] /* load retaddr */
398
398
  mov eax, [esp+closure_FS] /* load closure */
399
399
  mov [esp+closure_FS], ecx /* move retaddr */
400
400
  jmp L(do_closure_REGISTER)
401
401
  L(UW26):
402
- // cfi_endproc
402
+ /* cfi_endproc */
403
403
  ENDF(ffi_closure_REGISTER)
404
404
 
405
405
  /* For STDCALL (and others), we need to pop N bytes of arguments off
@@ -410,10 +410,10 @@ ALIGN 16
410
410
  PUBLIC ffi_closure_STDCALL
411
411
  ffi_closure_STDCALL PROC C
412
412
  L(UW27):
413
- // cfi_startproc
413
+ /* cfi_startproc */
414
414
  sub esp, closure_FS
415
415
  L(UW28):
416
- // cfi_def_cfa_offset(closure_FS + 4)
416
+ /* cfi_def_cfa_offset(closure_FS + 4) */
417
417
 
418
418
  FFI_CLOSURE_SAVE_REGS
419
419
 
@@ -504,7 +504,7 @@ E(L(load_table3), X86_RET_UNUSED15)
504
504
  int 3
505
505
 
506
506
  L(UW31):
507
- // cfi_endproc
507
+ /* cfi_endproc */
508
508
  ENDF(ffi_closure_STDCALL)
509
509
 
510
510
  #if !FFI_NO_RAW_API
@@ -515,13 +515,13 @@ ALIGN 16
515
515
  PUBLIC ffi_closure_raw_SYSV
516
516
  ffi_closure_raw_SYSV PROC C
517
517
  L(UW32):
518
- // cfi_startproc
518
+ /* cfi_startproc */
519
519
  sub esp, raw_closure_S_FS
520
520
  L(UW33):
521
- // cfi_def_cfa_offset(raw_closure_S_FS + 4)
521
+ /* cfi_def_cfa_offset(raw_closure_S_FS + 4) */
522
522
  mov [esp+raw_closure_S_FS-4], ebx
523
523
  L(UW34):
524
- // cfi_rel_offset(%ebx, raw_closure_S_FS-4)
524
+ /* cfi_rel_offset(%ebx, raw_closure_S_FS-4) */
525
525
 
526
526
  mov edx, [eax+FFI_TRAMPOLINE_SIZE+8] /* load cl->user_data */
527
527
  mov [esp+12], edx
@@ -535,16 +535,16 @@ L(UW34):
535
535
 
536
536
  mov eax, [ebx+20] /* load cif->flags */
537
537
  and eax, X86_RET_TYPE_MASK
538
- // #ifdef __PIC__
539
- // call __x86.get_pc_thunk.bx
540
- // L(pc4):
541
- // lea ecx, L(load_table4)-L(pc4)(%ebx, %eax, 8), %ecx
542
- // #else
538
+ /* #ifdef __PIC__ */
539
+ /* call __x86.get_pc_thunk.bx */
540
+ /* L(pc4): */
541
+ /* lea ecx, L(load_table4)-L(pc4)(%ebx, %eax, 8), %ecx */
542
+ /* #else */
543
543
  lea ecx, [L(load_table4)+eax+8]
544
- // #endif
544
+ /* #endif */
545
545
  mov ebx, [esp+raw_closure_S_FS-4]
546
546
  L(UW35):
547
- // cfi_restore(%ebx)
547
+ /* cfi_restore(%ebx) */
548
548
  mov eax, [esp+16] /* Optimistic load */
549
549
  jmp dword ptr [ecx]
550
550
 
@@ -581,17 +581,17 @@ E(L(load_table4), X86_RET_VOID)
581
581
  L(e4):
582
582
  add esp, raw_closure_S_FS
583
583
  L(UW36):
584
- // cfi_adjust_cfa_offset(-raw_closure_S_FS)
584
+ /* cfi_adjust_cfa_offset(-raw_closure_S_FS) */
585
585
  ret
586
586
  L(UW37):
587
- // cfi_adjust_cfa_offset(raw_closure_S_FS)
587
+ /* cfi_adjust_cfa_offset(raw_closure_S_FS) */
588
588
  E(L(load_table4), X86_RET_STRUCTPOP)
589
589
  add esp, raw_closure_S_FS
590
590
  L(UW38):
591
- // cfi_adjust_cfa_offset(-raw_closure_S_FS)
591
+ /* cfi_adjust_cfa_offset(-raw_closure_S_FS) */
592
592
  ret 4
593
593
  L(UW39):
594
- // cfi_adjust_cfa_offset(raw_closure_S_FS)
594
+ /* cfi_adjust_cfa_offset(raw_closure_S_FS) */
595
595
  E(L(load_table4), X86_RET_STRUCTARG)
596
596
  jmp L(e4)
597
597
  E(L(load_table4), X86_RET_STRUCT_1B)
@@ -608,7 +608,7 @@ E(L(load_table4), X86_RET_UNUSED15)
608
608
  int 3
609
609
 
610
610
  L(UW40):
611
- // cfi_endproc
611
+ /* cfi_endproc */
612
612
  ENDF(ffi_closure_raw_SYSV)
613
613
 
614
614
  #define raw_closure_T_FS (16+16+8)
@@ -617,26 +617,26 @@ ALIGN 16
617
617
  PUBLIC ffi_closure_raw_THISCALL
618
618
  ffi_closure_raw_THISCALL PROC C
619
619
  L(UW41):
620
- // cfi_startproc
620
+ /* cfi_startproc */
621
621
  /* Rearrange the stack such that %ecx is the first argument.
622
622
  This means moving the return address. */
623
623
  pop edx
624
624
  L(UW42):
625
- // cfi_def_cfa_offset(0)
626
- // cfi_register(%eip, %edx)
625
+ /* cfi_def_cfa_offset(0) */
626
+ /* cfi_register(%eip, %edx) */
627
627
  push ecx
628
628
  L(UW43):
629
- // cfi_adjust_cfa_offset(4)
629
+ /* cfi_adjust_cfa_offset(4) */
630
630
  push edx
631
631
  L(UW44):
632
- // cfi_adjust_cfa_offset(4)
633
- // cfi_rel_offset(%eip, 0)
632
+ /* cfi_adjust_cfa_offset(4) */
633
+ /* cfi_rel_offset(%eip, 0) */
634
634
  sub esp, raw_closure_T_FS
635
635
  L(UW45):
636
- // cfi_adjust_cfa_offset(raw_closure_T_FS)
636
+ /* cfi_adjust_cfa_offset(raw_closure_T_FS) */
637
637
  mov [esp+raw_closure_T_FS-4], ebx
638
638
  L(UW46):
639
- // cfi_rel_offset(%ebx, raw_closure_T_FS-4)
639
+ /* cfi_rel_offset(%ebx, raw_closure_T_FS-4) */
640
640
 
641
641
  mov edx, [eax+FFI_TRAMPOLINE_SIZE+8] /* load cl->user_data */
642
642
  mov [esp+12], edx
@@ -650,16 +650,16 @@ L(UW46):
650
650
 
651
651
  mov eax, [ebx+20] /* load cif->flags */
652
652
  and eax, X86_RET_TYPE_MASK
653
- // #ifdef __PIC__
654
- // call __x86.get_pc_thunk.bx
655
- // L(pc5):
656
- // leal L(load_table5)-L(pc5)(%ebx, %eax, 8), %ecx
657
- // #else
653
+ /* #ifdef __PIC__ */
654
+ /* call __x86.get_pc_thunk.bx */
655
+ /* L(pc5): */
656
+ /* leal L(load_table5)-L(pc5)(%ebx, %eax, 8), %ecx */
657
+ /* #else */
658
658
  lea ecx, [L(load_table5)+eax*8]
659
- //#endif
659
+ /*#endif */
660
660
  mov ebx, [esp+raw_closure_T_FS-4]
661
661
  L(UW47):
662
- // cfi_restore(%ebx)
662
+ /* cfi_restore(%ebx) */
663
663
  mov eax, [esp+16] /* Optimistic load */
664
664
  jmp DWORD PTR [ecx]
665
665
 
@@ -696,18 +696,18 @@ E(L(load_table5), X86_RET_VOID)
696
696
  L(e5):
697
697
  add esp, raw_closure_T_FS
698
698
  L(UW48):
699
- // cfi_adjust_cfa_offset(-raw_closure_T_FS)
699
+ /* cfi_adjust_cfa_offset(-raw_closure_T_FS) */
700
700
  /* Remove the extra %ecx argument we pushed. */
701
701
  ret 4
702
702
  L(UW49):
703
- // cfi_adjust_cfa_offset(raw_closure_T_FS)
703
+ /* cfi_adjust_cfa_offset(raw_closure_T_FS) */
704
704
  E(L(load_table5), X86_RET_STRUCTPOP)
705
705
  add esp, raw_closure_T_FS
706
706
  L(UW50):
707
- // cfi_adjust_cfa_offset(-raw_closure_T_FS)
707
+ /* cfi_adjust_cfa_offset(-raw_closure_T_FS) */
708
708
  ret 8
709
709
  L(UW51):
710
- // cfi_adjust_cfa_offset(raw_closure_T_FS)
710
+ /* cfi_adjust_cfa_offset(raw_closure_T_FS) */
711
711
  E(L(load_table5), X86_RET_STRUCTARG)
712
712
  jmp L(e5)
713
713
  E(L(load_table5), X86_RET_STRUCT_1B)
@@ -724,7 +724,7 @@ E(L(load_table5), X86_RET_UNUSED15)
724
724
  int 3
725
725
 
726
726
  L(UW52):
727
- // cfi_endproc
727
+ /* cfi_endproc */
728
728
  ENDF(ffi_closure_raw_THISCALL)
729
729
 
730
730
  #endif /* !FFI_NO_RAW_API */
@@ -743,20 +743,23 @@ ENDF(ffi_closure_raw_THISCALL)
743
743
  # define COMDAT(X)
744
744
  #endif
745
745
 
746
- // #if defined(__PIC__)
747
- // COMDAT(C(__x86.get_pc_thunk.bx))
748
- // C(__x86.get_pc_thunk.bx):
749
- // movl (%esp), %ebx
750
- // ret
751
- // ENDF(C(__x86.get_pc_thunk.bx))
752
- // # if defined X86_DARWIN || defined HAVE_HIDDEN_VISIBILITY_ATTRIBUTE
753
- // COMDAT(C(__x86.get_pc_thunk.dx))
754
- // C(__x86.get_pc_thunk.dx):
755
- // movl (%esp), %edx
756
- // ret
757
- // ENDF(C(__x86.get_pc_thunk.dx))
758
- // #endif /* DARWIN || HIDDEN */
759
- // #endif /* __PIC__ */
746
+ #if 0
747
+ #if defined(__PIC__)
748
+ COMDAT(C(__x86.get_pc_thunk.bx))
749
+ C(__x86.get_pc_thunk.bx):
750
+ movl (%esp), %ebx
751
+ ret
752
+ ENDF(C(__x86.get_pc_thunk.bx))
753
+ # if defined X86_DARWIN || defined HAVE_HIDDEN_VISIBILITY_ATTRIBUTE
754
+ COMDAT(C(__x86.get_pc_thunk.dx))
755
+ C(__x86.get_pc_thunk.dx):
756
+ movl (%esp), %edx
757
+ ret
758
+ ENDF(C(__x86.get_pc_thunk.dx))
759
+ #endif /* DARWIN || HIDDEN */
760
+ #endif /* __PIC__ */
761
+ #endif
762
+
760
763
 
761
764
  #if 0
762
765
  /* Sadly, OSX cctools-as doesn't understand .cfi directives at all. */
@@ -992,4 +995,4 @@ L(EFDE9):
992
995
  #endif
993
996
  #endif
994
997
 
995
- END
998
+ END
@@ -39,14 +39,13 @@
39
39
  actual table. The entry points into the table are all 8 bytes.
40
40
  The use of ORG asserts that we're at the correct location. */
41
41
  /* ??? The clang assembler doesn't handle .org with symbolic expressions. */
42
- #if defined(__clang__) || defined(__APPLE__) || (defined (__sun__) && defined(__svr4__))
42
+ #ifdef __CET__
43
+ /* Double slot size to 16 byte to add 4 bytes of ENDBR64. */
44
+ # define E(BASE, X) .balign 8; .org BASE + X * 16
45
+ #elif defined(__clang__) || defined(__APPLE__) || (defined (__sun__) && defined(__svr4__))
43
46
  # define E(BASE, X) .balign 8
44
47
  #else
45
- # ifdef __CET__
46
- # define E(BASE, X) .balign 8; .org BASE + X * 16
47
- # else
48
- # define E(BASE, X) .balign 8; .org BASE + X * 8
49
- # endif
48
+ # define E(BASE, X) .balign 8; .org BASE + X * 8
50
49
  #endif
51
50
 
52
51
  /* ffi_call_unix64 (void *args, unsigned long bytes, unsigned flags,
@@ -456,6 +455,97 @@ L(sse_entry2):
456
455
  L(UW17):
457
456
  ENDF(C(ffi_go_closure_unix64))
458
457
 
458
+ #if defined(FFI_EXEC_STATIC_TRAMP)
459
+ .balign 8
460
+ .globl C(ffi_closure_unix64_sse_alt)
461
+ FFI_HIDDEN(C(ffi_closure_unix64_sse_alt))
462
+
463
+ C(ffi_closure_unix64_sse_alt):
464
+ /* See the comments above trampoline_code_table. */
465
+ _CET_ENDBR
466
+ movq 8(%rsp), %r10 /* Load closure in r10 */
467
+ addq $16, %rsp /* Restore the stack */
468
+ jmp C(ffi_closure_unix64_sse)
469
+ ENDF(C(ffi_closure_unix64_sse_alt))
470
+
471
+ .balign 8
472
+ .globl C(ffi_closure_unix64_alt)
473
+ FFI_HIDDEN(C(ffi_closure_unix64_alt))
474
+
475
+ C(ffi_closure_unix64_alt):
476
+ /* See the comments above trampoline_code_table. */
477
+ _CET_ENDBR
478
+ movq 8(%rsp), %r10 /* Load closure in r10 */
479
+ addq $16, %rsp /* Restore the stack */
480
+ jmp C(ffi_closure_unix64)
481
+ ENDF(C(ffi_closure_unix64_alt))
482
+
483
+ /*
484
+ * Below is the definition of the trampoline code table. Each element in
485
+ * the code table is a trampoline.
486
+ *
487
+ * Because we jump to the trampoline, we place a _CET_ENDBR at the
488
+ * beginning of the trampoline to mark it as a valid branch target. This is
489
+ * part of the the Intel CET (Control Flow Enforcement Technology).
490
+ */
491
+ /*
492
+ * The trampoline uses register r10. It saves the original value of r10 on
493
+ * the stack.
494
+ *
495
+ * The trampoline has two parameters - target code to jump to and data for
496
+ * the target code. The trampoline extracts the parameters from its parameter
497
+ * block (see tramp_table_map()). The trampoline saves the data address on
498
+ * the stack. Finally, it jumps to the target code.
499
+ *
500
+ * The target code can choose to:
501
+ *
502
+ * - restore the value of r10
503
+ * - load the data address in a register
504
+ * - restore the stack pointer to what it was when the trampoline was invoked.
505
+ */
506
+ #ifdef ENDBR_PRESENT
507
+ # define X86_DATA_OFFSET 4077
508
+ # ifdef __ILP32__
509
+ # define X86_CODE_OFFSET 4069
510
+ # else
511
+ # define X86_CODE_OFFSET 4073
512
+ # endif
513
+ #else
514
+ # define X86_DATA_OFFSET 4081
515
+ # ifdef __ILP32__
516
+ # define X86_CODE_OFFSET 4073
517
+ # else
518
+ # define X86_CODE_OFFSET 4077
519
+ # endif
520
+ #endif
521
+
522
+ .align UNIX64_TRAMP_MAP_SIZE
523
+ .globl trampoline_code_table
524
+ FFI_HIDDEN(C(trampoline_code_table))
525
+
526
+ C(trampoline_code_table):
527
+ .rept UNIX64_TRAMP_MAP_SIZE / UNIX64_TRAMP_SIZE
528
+ _CET_ENDBR
529
+ subq $16, %rsp /* Make space on the stack */
530
+ movq %r10, (%rsp) /* Save %r10 on stack */
531
+ #ifdef __ILP32__
532
+ movl X86_DATA_OFFSET(%rip), %r10d /* Copy data into %r10 */
533
+ #else
534
+ movq X86_DATA_OFFSET(%rip), %r10 /* Copy data into %r10 */
535
+ #endif
536
+ movq %r10, 8(%rsp) /* Save data on stack */
537
+ #ifdef __ILP32__
538
+ movl X86_CODE_OFFSET(%rip), %r10d /* Copy code into %r10 */
539
+ #else
540
+ movq X86_CODE_OFFSET(%rip), %r10 /* Copy code into %r10 */
541
+ #endif
542
+ jmp *%r10 /* Jump to code */
543
+ .align 8
544
+ .endr
545
+ ENDF(C(trampoline_code_table))
546
+ .align UNIX64_TRAMP_MAP_SIZE
547
+ #endif /* FFI_EXEC_STATIC_TRAMP */
548
+
459
549
  /* Sadly, OSX cctools-as doesn't understand .cfi directives at all. */
460
550
 
461
551
  #ifdef __APPLE__
@@ -85,14 +85,13 @@ C(ffi_call_win64):
85
85
 
86
86
  /* Below, we're space constrained most of the time. Thus we eschew the
87
87
  modern "mov, pop, ret" sequence (5 bytes) for "leave, ret" (2 bytes). */
88
- .macro epilogue
89
- leaveq
90
- cfi_remember_state
91
- cfi_def_cfa(%rsp, 8)
92
- cfi_restore(%rbp)
93
- ret
88
+ #define epilogue \
89
+ leaveq; \
90
+ cfi_remember_state; \
91
+ cfi_def_cfa(%rsp, 8); \
92
+ cfi_restore(%rbp); \
93
+ ret; \
94
94
  cfi_restore_state
95
- .endm
96
95
 
97
96
  .align 8
98
97
  0:
@@ -234,6 +233,20 @@ C(ffi_closure_win64):
234
233
 
235
234
  cfi_endproc
236
235
  SEH(.seh_endproc)
236
+
237
+ #if defined(FFI_EXEC_STATIC_TRAMP)
238
+ .align 8
239
+ .globl C(ffi_closure_win64_alt)
240
+ FFI_HIDDEN(C(ffi_closure_win64_alt))
241
+
242
+ SEH(.seh_proc ffi_closure_win64_alt)
243
+ C(ffi_closure_win64_alt):
244
+ _CET_ENDBR
245
+ movq 8(%rsp), %r10
246
+ addq $16, %rsp
247
+ jmp C(ffi_closure_win64)
248
+ SEH(.seh_endproc)
249
+ #endif
237
250
  #endif /* __x86_64__ */
238
251
 
239
252
  #if defined __ELF__ && defined __linux__
@@ -86,11 +86,16 @@ ffi_status ffi_prep_cif_machdep(ffi_cif *cif)
86
86
  break;
87
87
  }
88
88
 
89
- /* Round the stack up to a full 4 register frame, just in case
90
- (we use this size in movsp). This way, it's also a multiple of
91
- 8 bytes for 64-bit arguments. */
92
- cif->bytes = FFI_ALIGN(cif->bytes, 16);
93
-
89
+ /* Round up stack size needed for arguments.
90
+ Allocate FFI_REGISTER_ARGS_SPACE bytes when there are only arguments
91
+ passed in registers, round space reserved for arguments passed on stack
92
+ up to ABI-specified alignment. */
93
+ if (cif->bytes < FFI_REGISTER_NARGS * 4)
94
+ cif->bytes = FFI_REGISTER_ARGS_SPACE;
95
+ else
96
+ cif->bytes = FFI_REGISTER_ARGS_SPACE +
97
+ FFI_ALIGN(cif->bytes - FFI_REGISTER_NARGS * 4,
98
+ XTENSA_STACK_ALIGNMENT);
94
99
  return FFI_OK;
95
100
  }
96
101
 
@@ -232,6 +237,9 @@ ffi_prep_closure_loc (ffi_closure* closure,
232
237
  void *user_data,
233
238
  void *codeloc)
234
239
  {
240
+ if (cif->abi != FFI_SYSV)
241
+ return FFI_BAD_ABI;
242
+
235
243
  /* copye trampoline to stack and patch 'ffi_closure_SYSV' pointer */
236
244
  memcpy(closure->tramp, ffi_trampoline, FFI_TRAMPOLINE_SIZE);
237
245
  *(unsigned int*)(&closure->tramp[8]) = (unsigned int)ffi_closure_SYSV;
@@ -277,15 +285,15 @@ ffi_closure_SYSV_inner(ffi_closure *closure, void **values, void *rvalue)
277
285
  if (arg_types[i]->alignment == 8 && (areg & 1) != 0)
278
286
  areg++;
279
287
 
280
- // skip the entry 16,a1 framework, add 16 bytes (4 registers)
288
+ // skip the entry a1, * framework, see ffi_trampoline
281
289
  if (areg == FFI_REGISTER_NARGS)
282
- areg += 4;
290
+ areg = (FFI_REGISTER_ARGS_SPACE + 32) / 4;
283
291
 
284
292
  if (arg_types[i]->type == FFI_TYPE_STRUCT)
285
293
  {
286
294
  int numregs = ((arg_types[i]->size + 3) & ~3) / 4;
287
295
  if (areg < FFI_REGISTER_NARGS && areg + numregs > FFI_REGISTER_NARGS)
288
- areg = FFI_REGISTER_NARGS + 4;
296
+ areg = (FFI_REGISTER_ARGS_SPACE + 32) / 4;
289
297
  }
290
298
 
291
299
  avalue[i] = &values[areg];
@@ -43,6 +43,10 @@ typedef enum ffi_abi {
43
43
  #endif
44
44
 
45
45
  #define FFI_REGISTER_NARGS 6
46
+ #define XTENSA_STACK_ALIGNMENT 16
47
+ #define FFI_REGISTER_ARGS_SPACE ((FFI_REGISTER_NARGS * 4 + \
48
+ XTENSA_STACK_ALIGNMENT - 1) & \
49
+ -XTENSA_STACK_ALIGNMENT)
46
50
 
47
51
  /* ---- Definitions for closures ----------------------------------------- */
48
52