ffi 1.15.5 → 1.17.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (343) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/CHANGELOG.md +118 -0
  4. data/Gemfile +10 -3
  5. data/README.md +4 -3
  6. data/Rakefile +25 -10
  7. data/ext/ffi_c/AbstractMemory.c +99 -74
  8. data/ext/ffi_c/AbstractMemory.h +3 -2
  9. data/ext/ffi_c/ArrayType.c +51 -15
  10. data/ext/ffi_c/ArrayType.h +1 -0
  11. data/ext/ffi_c/Buffer.c +90 -33
  12. data/ext/ffi_c/Call.c +29 -12
  13. data/ext/ffi_c/Call.h +3 -2
  14. data/ext/ffi_c/DynamicLibrary.c +90 -27
  15. data/ext/ffi_c/Function.c +244 -98
  16. data/ext/ffi_c/Function.h +1 -0
  17. data/ext/ffi_c/FunctionInfo.c +81 -25
  18. data/ext/ffi_c/LastError.c +29 -11
  19. data/ext/ffi_c/MappedType.c +66 -23
  20. data/ext/ffi_c/MappedType.h +0 -2
  21. data/ext/ffi_c/MemoryPointer.c +36 -9
  22. data/ext/ffi_c/MethodHandle.c +3 -1
  23. data/ext/ffi_c/Pointer.c +82 -40
  24. data/ext/ffi_c/Pointer.h +1 -0
  25. data/ext/ffi_c/Struct.c +166 -84
  26. data/ext/ffi_c/Struct.h +7 -4
  27. data/ext/ffi_c/StructByValue.c +48 -16
  28. data/ext/ffi_c/StructLayout.c +130 -61
  29. data/ext/ffi_c/Type.c +120 -51
  30. data/ext/ffi_c/Type.h +3 -1
  31. data/ext/ffi_c/Types.c +8 -2
  32. data/ext/ffi_c/Types.h +0 -1
  33. data/ext/ffi_c/Variadic.c +71 -26
  34. data/ext/ffi_c/compat.h +22 -22
  35. data/ext/ffi_c/extconf.rb +19 -2
  36. data/ext/ffi_c/ffi.c +4 -0
  37. data/ext/ffi_c/libffi/.allow-ai-service +0 -0
  38. data/ext/ffi_c/libffi/.appveyor/site.exp +16 -0
  39. data/ext/ffi_c/libffi/.appveyor/unix-noexec.exp +7 -0
  40. data/ext/ffi_c/libffi/.appveyor.yml +27 -9
  41. data/ext/ffi_c/libffi/.ci/build-cross-in-container.sh +18 -0
  42. data/ext/ffi_c/libffi/{.travis → .ci}/build-in-container.sh +4 -6
  43. data/ext/ffi_c/libffi/.ci/build.sh +124 -0
  44. data/ext/ffi_c/libffi/{.travis → .ci}/install.sh +14 -7
  45. data/ext/ffi_c/libffi/.ci/msvs-detect +1103 -0
  46. data/ext/ffi_c/libffi/{.travis → .ci}/site.exp +5 -3
  47. data/ext/ffi_c/libffi/.circleci/config.yml +156 -0
  48. data/ext/ffi_c/libffi/.github/workflows/build.yml +479 -0
  49. data/ext/ffi_c/libffi/.github/workflows/emscripten.yml +172 -0
  50. data/ext/ffi_c/libffi/.gitignore +10 -2
  51. data/ext/ffi_c/libffi/LICENSE +1 -1
  52. data/ext/ffi_c/libffi/Makefile.am +12 -5
  53. data/ext/ffi_c/libffi/Makefile.in +118 -51
  54. data/ext/ffi_c/libffi/README.md +150 -105
  55. data/ext/ffi_c/libffi/acinclude.m4 +10 -112
  56. data/ext/ffi_c/libffi/compile +348 -0
  57. data/ext/ffi_c/libffi/config.guess +623 -556
  58. data/ext/ffi_c/libffi/config.sub +75 -34
  59. data/ext/ffi_c/libffi/configure +4571 -3830
  60. data/ext/ffi_c/libffi/configure.ac +64 -28
  61. data/ext/ffi_c/libffi/configure.host +26 -7
  62. data/ext/ffi_c/libffi/doc/Makefile.in +9 -6
  63. data/ext/ffi_c/libffi/doc/libffi.texi +82 -33
  64. data/ext/ffi_c/libffi/doc/version.texi +4 -4
  65. data/ext/ffi_c/libffi/fficonfig.h.in +12 -47
  66. data/ext/ffi_c/libffi/generate-darwin-source-and-headers.py +163 -52
  67. data/ext/ffi_c/libffi/include/Makefile.am +1 -1
  68. data/ext/ffi_c/libffi/include/Makefile.in +10 -9
  69. data/ext/ffi_c/libffi/include/ffi.h.in +55 -60
  70. data/ext/ffi_c/libffi/include/ffi_cfi.h +21 -0
  71. data/ext/ffi_c/libffi/include/ffi_common.h +33 -2
  72. data/ext/ffi_c/libffi/include/tramp.h +45 -0
  73. data/ext/ffi_c/libffi/install-sh +92 -69
  74. data/ext/ffi_c/libffi/libffi.map.in +5 -0
  75. data/ext/ffi_c/libffi/libtool-version +2 -2
  76. data/ext/ffi_c/libffi/ltmain.sh +518 -333
  77. data/ext/ffi_c/libffi/m4/ax_cc_maxopt.m4 +18 -14
  78. data/ext/ffi_c/libffi/m4/ax_cflags_warn_all.m4 +108 -72
  79. data/ext/ffi_c/libffi/m4/ax_compiler_vendor.m4 +76 -45
  80. data/ext/ffi_c/libffi/m4/ax_prepend_flag.m4 +51 -0
  81. data/ext/ffi_c/libffi/man/Makefile.in +9 -6
  82. data/ext/ffi_c/libffi/missing +1 -1
  83. data/ext/ffi_c/libffi/msvc_build/aarch64/aarch64_include/ffi.h +2 -2
  84. data/ext/ffi_c/libffi/msvcc.sh +1 -1
  85. data/ext/ffi_c/libffi/src/aarch64/ffi.c +172 -55
  86. data/ext/ffi_c/libffi/src/aarch64/internal.h +32 -0
  87. data/ext/ffi_c/libffi/src/aarch64/sysv.S +331 -87
  88. data/ext/ffi_c/libffi/src/arc/arcompact.S +169 -94
  89. data/ext/ffi_c/libffi/src/arc/ffi.c +325 -148
  90. data/ext/ffi_c/libffi/src/arc/ffitarget.h +14 -0
  91. data/ext/ffi_c/libffi/src/arm/ffi.c +62 -17
  92. data/ext/ffi_c/libffi/src/arm/ffitarget.h +3 -3
  93. data/ext/ffi_c/libffi/src/arm/internal.h +10 -0
  94. data/ext/ffi_c/libffi/src/arm/sysv.S +113 -42
  95. data/ext/ffi_c/libffi/src/closures.c +136 -50
  96. data/ext/ffi_c/libffi/src/debug.c +2 -2
  97. data/ext/ffi_c/libffi/src/dlmalloc.c +6 -1
  98. data/ext/ffi_c/libffi/src/ia64/ffi.c +12 -0
  99. data/ext/ffi_c/libffi/src/ia64/unix.S +20 -2
  100. data/ext/ffi_c/libffi/src/loongarch64/ffi.c +624 -0
  101. data/ext/ffi_c/libffi/src/loongarch64/ffitarget.h +82 -0
  102. data/ext/ffi_c/libffi/src/loongarch64/sysv.S +327 -0
  103. data/ext/ffi_c/libffi/src/m32r/ffi.c +31 -14
  104. data/ext/ffi_c/libffi/src/mips/ffi.c +250 -67
  105. data/ext/ffi_c/libffi/src/mips/ffitarget.h +7 -0
  106. data/ext/ffi_c/libffi/src/mips/n32.S +193 -33
  107. data/ext/ffi_c/libffi/src/mips/o32.S +61 -4
  108. data/ext/ffi_c/libffi/src/moxie/ffi.c +47 -22
  109. data/ext/ffi_c/libffi/src/or1k/ffi.c +25 -12
  110. data/ext/ffi_c/libffi/src/pa/ffi.c +32 -33
  111. data/ext/ffi_c/libffi/src/pa/ffi64.c +614 -0
  112. data/ext/ffi_c/libffi/src/pa/ffitarget.h +22 -8
  113. data/ext/ffi_c/libffi/src/pa/hpux32.S +83 -36
  114. data/ext/ffi_c/libffi/src/pa/hpux64.S +681 -0
  115. data/ext/ffi_c/libffi/src/pa/linux.S +82 -35
  116. data/ext/ffi_c/libffi/src/powerpc/ffi_darwin.c +36 -24
  117. data/ext/ffi_c/libffi/src/powerpc/ffi_linux64.c +1 -1
  118. data/ext/ffi_c/libffi/src/powerpc/linux64.S +2 -0
  119. data/ext/ffi_c/libffi/src/powerpc/linux64_closure.S +2 -0
  120. data/ext/ffi_c/libffi/src/powerpc/t-aix +5 -0
  121. data/ext/ffi_c/libffi/src/prep_cif.c +22 -2
  122. data/ext/ffi_c/libffi/src/riscv/ffi.c +37 -4
  123. data/ext/ffi_c/libffi/src/sparc/ffi64.c +23 -1
  124. data/ext/ffi_c/libffi/src/tramp.c +716 -0
  125. data/ext/ffi_c/libffi/src/types.c +4 -6
  126. data/ext/ffi_c/libffi/src/wasm32/ffi.c +947 -0
  127. data/ext/ffi_c/libffi/src/wasm32/ffitarget.h +62 -0
  128. data/ext/ffi_c/libffi/src/x86/ffi.c +99 -37
  129. data/ext/ffi_c/libffi/src/x86/ffi64.c +67 -12
  130. data/ext/ffi_c/libffi/src/x86/ffitarget.h +9 -5
  131. data/ext/ffi_c/libffi/src/x86/ffiw64.c +44 -1
  132. data/ext/ffi_c/libffi/src/x86/internal.h +14 -0
  133. data/ext/ffi_c/libffi/src/x86/internal64.h +14 -0
  134. data/ext/ffi_c/libffi/src/x86/sysv.S +172 -38
  135. data/ext/ffi_c/libffi/src/x86/sysv_intel.S +91 -88
  136. data/ext/ffi_c/libffi/src/x86/unix64.S +96 -6
  137. data/ext/ffi_c/libffi/src/x86/win64.S +20 -7
  138. data/ext/ffi_c/libffi/src/xtensa/ffi.c +16 -8
  139. data/ext/ffi_c/libffi/src/xtensa/ffitarget.h +4 -0
  140. data/ext/ffi_c/libffi/src/xtensa/sysv.S +26 -16
  141. data/ext/ffi_c/libffi/testsuite/Makefile.am +79 -114
  142. data/ext/ffi_c/libffi/testsuite/Makefile.in +89 -121
  143. data/ext/ffi_c/libffi/testsuite/emscripten/build-tests.sh +54 -0
  144. data/ext/ffi_c/libffi/testsuite/emscripten/build.sh +63 -0
  145. data/ext/ffi_c/libffi/testsuite/emscripten/conftest.py +86 -0
  146. data/ext/ffi_c/libffi/testsuite/emscripten/node-tests.sh +48 -0
  147. data/ext/ffi_c/libffi/testsuite/emscripten/test.html +7 -0
  148. data/ext/ffi_c/libffi/testsuite/emscripten/test_libffi.py +51 -0
  149. data/ext/ffi_c/libffi/testsuite/lib/libffi.exp +43 -21
  150. data/ext/ffi_c/libffi/testsuite/lib/target-libpath.exp +2 -2
  151. data/ext/ffi_c/libffi/testsuite/libffi.bhaible/test-call.c +1 -0
  152. data/ext/ffi_c/libffi/testsuite/libffi.bhaible/testcases.c +5 -1
  153. data/ext/ffi_c/libffi/testsuite/libffi.call/bpo_38748.c +41 -0
  154. data/ext/ffi_c/libffi/testsuite/libffi.call/callback.c +99 -0
  155. data/ext/ffi_c/libffi/testsuite/libffi.call/callback2.c +108 -0
  156. data/ext/ffi_c/libffi/testsuite/libffi.call/callback3.c +114 -0
  157. data/ext/ffi_c/libffi/testsuite/libffi.call/callback4.c +119 -0
  158. data/ext/ffi_c/libffi/testsuite/libffi.call/ffitest.h +28 -3
  159. data/ext/ffi_c/libffi/testsuite/libffi.call/float_va.c +3 -0
  160. data/ext/ffi_c/libffi/testsuite/libffi.call/return_ll1.c +5 -0
  161. data/ext/ffi_c/libffi/testsuite/libffi.call/return_sl.c +4 -0
  162. data/ext/ffi_c/libffi/testsuite/libffi.call/return_ul.c +4 -0
  163. data/ext/ffi_c/libffi/testsuite/libffi.call/s55.c +60 -0
  164. data/ext/ffi_c/libffi/testsuite/libffi.call/strlen.c +8 -9
  165. data/ext/ffi_c/libffi/testsuite/libffi.call/strlen2.c +2 -2
  166. data/ext/ffi_c/libffi/testsuite/libffi.call/strlen3.c +2 -2
  167. data/ext/ffi_c/libffi/testsuite/libffi.call/strlen4.c +2 -2
  168. data/ext/ffi_c/libffi/testsuite/libffi.call/struct10.c +1 -1
  169. data/ext/ffi_c/libffi/testsuite/libffi.call/struct_by_value_2.c +63 -0
  170. data/ext/ffi_c/libffi/testsuite/libffi.call/struct_by_value_3.c +65 -0
  171. data/ext/ffi_c/libffi/testsuite/libffi.call/struct_by_value_3f.c +65 -0
  172. data/ext/ffi_c/libffi/testsuite/libffi.call/struct_by_value_4.c +67 -0
  173. data/ext/ffi_c/libffi/testsuite/libffi.call/struct_by_value_4f.c +67 -0
  174. data/ext/ffi_c/libffi/testsuite/libffi.call/struct_by_value_big.c +93 -0
  175. data/ext/ffi_c/libffi/testsuite/libffi.call/struct_by_value_small.c +61 -0
  176. data/ext/ffi_c/libffi/testsuite/libffi.call/struct_return_2H.c +63 -0
  177. data/ext/ffi_c/libffi/testsuite/libffi.call/struct_return_8H.c +90 -0
  178. data/ext/ffi_c/libffi/testsuite/libffi.call/va_1.c +1 -119
  179. data/ext/ffi_c/libffi/testsuite/libffi.call/va_2.c +220 -0
  180. data/ext/ffi_c/libffi/testsuite/libffi.call/va_3.c +154 -0
  181. data/ext/ffi_c/libffi/testsuite/libffi.call/va_struct1.c +13 -0
  182. data/ext/ffi_c/libffi/testsuite/libffi.call/va_struct2.c +11 -0
  183. data/ext/ffi_c/libffi/testsuite/libffi.call/va_struct3.c +15 -0
  184. data/ext/ffi_c/libffi/testsuite/libffi.closures/closure_fn0.c +3 -2
  185. data/ext/ffi_c/libffi/testsuite/libffi.closures/closure_fn1.c +2 -0
  186. data/ext/ffi_c/libffi/testsuite/libffi.closures/closure_fn2.c +2 -0
  187. data/ext/ffi_c/libffi/testsuite/libffi.closures/closure_fn3.c +21 -1
  188. data/ext/ffi_c/libffi/testsuite/libffi.closures/closure_fn4.c +2 -0
  189. data/ext/ffi_c/libffi/testsuite/libffi.closures/closure_fn5.c +2 -0
  190. data/ext/ffi_c/libffi/testsuite/libffi.closures/closure_fn6.c +2 -0
  191. data/ext/ffi_c/libffi/testsuite/libffi.closures/closure_loc_fn0.c +7 -6
  192. data/ext/ffi_c/libffi/testsuite/libffi.closures/closure_simple.c +6 -0
  193. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_12byte.c +18 -0
  194. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_16byte.c +22 -0
  195. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_18byte.c +24 -0
  196. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_19byte.c +29 -0
  197. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_1_1byte.c +4 -0
  198. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_20byte.c +19 -1
  199. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_20byte1.c +21 -1
  200. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_24byte.c +35 -3
  201. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_2byte.c +13 -0
  202. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_3_1byte.c +19 -0
  203. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_3byte1.c +13 -0
  204. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_3byte2.c +13 -0
  205. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_3float.c +18 -0
  206. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_4_1byte.c +22 -0
  207. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_4byte.c +13 -0
  208. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_5_1_byte.c +29 -1
  209. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_5byte.c +19 -1
  210. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_64byte.c +24 -0
  211. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_6_1_byte.c +28 -1
  212. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_6byte.c +24 -2
  213. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_7_1_byte.c +39 -1
  214. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_7byte.c +25 -1
  215. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_8byte.c +14 -0
  216. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_9byte1.c +14 -1
  217. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_9byte2.c +14 -2
  218. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_double.c +19 -1
  219. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_float.c +19 -1
  220. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_longdouble.c +20 -1
  221. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_longdouble_split.c +40 -25
  222. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_longdouble_split2.c +40 -3
  223. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_pointer.c +19 -1
  224. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_sint16.c +18 -1
  225. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_sint32.c +18 -3
  226. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_sint64.c +18 -1
  227. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_uint16.c +18 -1
  228. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_uint32.c +19 -1
  229. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_align_uint64.c +19 -1
  230. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_dbls_struct.c +3 -1
  231. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_double_va.c +9 -1
  232. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_float.c +4 -0
  233. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_longdouble.c +11 -1
  234. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_longdouble_va.c +22 -3
  235. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_multi_schar.c +5 -1
  236. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_multi_sshort.c +6 -1
  237. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_multi_sshortchar.c +9 -1
  238. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_multi_uchar.c +9 -1
  239. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_multi_ushort.c +6 -2
  240. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_multi_ushortchar.c +9 -1
  241. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_pointer.c +5 -0
  242. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_pointer_stack.c +10 -0
  243. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_schar.c +3 -0
  244. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_sint.c +2 -0
  245. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_sshort.c +3 -0
  246. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_struct_va1.c +11 -0
  247. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_uchar.c +3 -0
  248. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_uint.c +4 -0
  249. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_uint_va.c +4 -0
  250. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_ulong_va.c +4 -0
  251. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_ulonglong.c +2 -0
  252. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_ushort.c +3 -0
  253. data/ext/ffi_c/libffi/testsuite/libffi.closures/ffitest.h +1 -138
  254. data/ext/ffi_c/libffi/testsuite/libffi.closures/huge_struct.c +21 -21
  255. data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct.c +32 -9
  256. data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct1.c +1 -1
  257. data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct10.c +12 -0
  258. data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct11.c +21 -5
  259. data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct12.c +86 -0
  260. data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct13.c +115 -0
  261. data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct2.c +10 -1
  262. data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct3.c +10 -1
  263. data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct4.c +9 -0
  264. data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct5.c +9 -0
  265. data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct6.c +11 -0
  266. data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct7.c +9 -0
  267. data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct8.c +11 -0
  268. data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct9.c +11 -0
  269. data/ext/ffi_c/libffi/testsuite/libffi.closures/single_entry_structs1.c +86 -0
  270. data/ext/ffi_c/libffi/testsuite/libffi.closures/single_entry_structs2.c +102 -0
  271. data/ext/ffi_c/libffi/testsuite/libffi.closures/single_entry_structs3.c +101 -0
  272. data/ext/ffi_c/libffi/testsuite/libffi.closures/stret_medium.c +1 -1
  273. data/ext/ffi_c/libffi/testsuite/libffi.closures/stret_medium2.c +1 -1
  274. data/ext/ffi_c/libffi/testsuite/libffi.closures/testclosure.c +6 -1
  275. data/ext/ffi_c/libffi/testsuite/libffi.closures/unwindtest.cc +2 -1
  276. data/ext/ffi_c/libffi/testsuite/libffi.closures/unwindtest_ffi_call.cc +1 -0
  277. data/ext/ffi_c/libffi.bsd.mk +2 -2
  278. data/ext/ffi_c/libffi.darwin.mk +2 -2
  279. data/ext/ffi_c/libffi.gnu.mk +2 -2
  280. data/ext/ffi_c/rbffi.h +1 -1
  281. data/ffi.gemspec +3 -3
  282. data/lib/ffi/autopointer.rb +8 -31
  283. data/lib/ffi/compat.rb +43 -0
  284. data/lib/ffi/data_converter.rb +2 -2
  285. data/lib/ffi/dynamic_library.rb +118 -0
  286. data/lib/ffi/enum.rb +18 -12
  287. data/lib/ffi/ffi.rb +3 -0
  288. data/lib/ffi/function.rb +71 -0
  289. data/lib/ffi/io.rb +2 -2
  290. data/lib/ffi/library.rb +72 -88
  291. data/lib/ffi/library_path.rb +109 -0
  292. data/lib/ffi/managedstruct.rb +1 -1
  293. data/lib/ffi/platform/aarch64-linux/types.conf +74 -3
  294. data/lib/ffi/platform/aarch64-windows/types.conf +52 -0
  295. data/lib/ffi/platform/hppa1.1-linux/types.conf +178 -0
  296. data/lib/ffi/platform/hppa2.0-linux/types.conf +178 -0
  297. data/lib/ffi/platform/loongarch64-linux/types.conf +141 -0
  298. data/lib/ffi/platform/sw_64-linux/types.conf +141 -0
  299. data/lib/ffi/platform.rb +15 -13
  300. data/lib/ffi/pointer.rb +6 -6
  301. data/lib/ffi/struct.rb +6 -5
  302. data/lib/ffi/struct_layout.rb +3 -3
  303. data/lib/ffi/struct_layout_builder.rb +9 -9
  304. data/lib/ffi/types.rb +65 -37
  305. data/lib/ffi/variadic.rb +19 -8
  306. data/lib/ffi/version.rb +1 -1
  307. data/samples/hello_ractor.rb +11 -0
  308. data/samples/qsort_ractor.rb +28 -0
  309. data/sig/ffi/abstract_memory.rbs +165 -0
  310. data/sig/ffi/auto_pointer.rbs +27 -0
  311. data/sig/ffi/buffer.rbs +18 -0
  312. data/sig/ffi/data_converter.rbs +10 -0
  313. data/sig/ffi/dynamic_library.rbs +9 -0
  314. data/sig/ffi/enum.rbs +38 -0
  315. data/sig/ffi/function.rbs +39 -0
  316. data/sig/ffi/library.rbs +42 -0
  317. data/sig/ffi/native_type.rbs +86 -0
  318. data/sig/ffi/pointer.rbs +42 -0
  319. data/sig/ffi/struct.rbs +76 -0
  320. data/sig/ffi/struct_by_reference.rbs +11 -0
  321. data/sig/ffi/struct_by_value.rbs +7 -0
  322. data/sig/ffi/struct_layout.rbs +9 -0
  323. data/sig/ffi/struct_layout_builder.rbs +5 -0
  324. data/sig/ffi/type.rbs +39 -0
  325. data/sig/ffi.rbs +26 -0
  326. data.tar.gz.sig +0 -0
  327. metadata +122 -28
  328. metadata.gz.sig +1 -0
  329. data/ext/ffi_c/libffi/.travis/build-cross-in-container.sh +0 -14
  330. data/ext/ffi_c/libffi/.travis/build.sh +0 -142
  331. data/ext/ffi_c/libffi/.travis.yml +0 -83
  332. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_uchar_va.c +0 -44
  333. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_ushort_va.c +0 -44
  334. /data/ext/ffi_c/libffi/{.travis → .ci}/ar-lib +0 -0
  335. /data/ext/ffi_c/libffi/{.travis → .ci}/bfin-sim.exp +0 -0
  336. /data/ext/ffi_c/libffi/{.travis → .ci}/compile +0 -0
  337. /data/ext/ffi_c/libffi/{.travis → .ci}/m32r-sim.exp +0 -0
  338. /data/ext/ffi_c/libffi/{.travis → .ci}/moxie-sim.exp +0 -0
  339. /data/ext/ffi_c/libffi/{.travis → .ci}/or1k-sim.exp +0 -0
  340. /data/ext/ffi_c/libffi/{.travis → .ci}/powerpc-eabisim.exp +0 -0
  341. /data/ext/ffi_c/libffi/{.travis → .ci}/wine-sim.exp +0 -0
  342. /data/ext/ffi_c/libffi/testsuite/libffi.call/{pyobjc-tc.c → pyobjc_tc.c} +0 -0
  343. /data/lib/ffi/platform/{sparc64-linux → sparcv9-linux}/types.conf +0 -0
@@ -1,5 +1,5 @@
1
1
  /* -----------------------------------------------------------------------
2
- closures.c - Copyright (c) 2019 Anthony Green
2
+ closures.c - Copyright (c) 2019, 2022 Anthony Green
3
3
  Copyright (c) 2007, 2009, 2010 Red Hat, Inc.
4
4
  Copyright (C) 2007, 2009, 2010 Free Software Foundation, Inc
5
5
  Copyright (c) 2011 Plausible Labs Cooperative, Inc.
@@ -27,13 +27,16 @@
27
27
  DEALINGS IN THE SOFTWARE.
28
28
  ----------------------------------------------------------------------- */
29
29
 
30
- #if defined __linux__ && !defined _GNU_SOURCE
30
+ #if (defined __linux__ || defined __CYGWIN__) && !defined _GNU_SOURCE
31
31
  #define _GNU_SOURCE 1
32
32
  #endif
33
33
 
34
+ #ifndef __EMSCRIPTEN__
35
+
34
36
  #include <fficonfig.h>
35
37
  #include <ffi.h>
36
38
  #include <ffi_common.h>
39
+ #include <tramp.h>
37
40
 
38
41
  #ifdef __NetBSD__
39
42
  #include <sys/param.h>
@@ -112,6 +115,12 @@ ffi_closure_free (void *ptr)
112
115
  munmap(dataseg, rounded_size);
113
116
  munmap(codeseg, rounded_size);
114
117
  }
118
+
119
+ int
120
+ ffi_tramp_is_present (__attribute__((unused)) void *ptr)
121
+ {
122
+ return 0;
123
+ }
115
124
  #else /* !NetBSD with PROT_MPROTECT */
116
125
 
117
126
  #if !FFI_MMAP_EXEC_WRIT && !FFI_EXEC_TRAMPOLINE_TABLE
@@ -126,22 +135,26 @@ ffi_closure_free (void *ptr)
126
135
  # define FFI_MMAP_EXEC_WRIT 1
127
136
  # define HAVE_MNTENT 1
128
137
  # endif
129
- # if defined(_WIN32) || defined(__OS2__)
130
- /* Windows systems may have Data Execution Protection (DEP) enabled,
138
+ # if defined(__CYGWIN__) || defined(_WIN32) || defined(__OS2__)
139
+ /* Windows systems may have Data Execution Protection (DEP) enabled,
131
140
  which requires the use of VirtualMalloc/VirtualFree to alloc/free
132
141
  executable memory. */
133
142
  # define FFI_MMAP_EXEC_WRIT 1
134
143
  # endif
135
144
  #endif
136
145
 
137
- #if FFI_MMAP_EXEC_WRIT && !defined FFI_MMAP_EXEC_SELINUX
138
- # if defined(__linux__) && !defined(__ANDROID__)
146
+ #if FFI_MMAP_EXEC_WRIT && defined(__linux__) && !defined(__ANDROID__)
147
+ # if !defined FFI_MMAP_EXEC_SELINUX
139
148
  /* When defined to 1 check for SELinux and if SELinux is active,
140
149
  don't attempt PROT_EXEC|PROT_WRITE mapping at all, as that
141
150
  might cause audit messages. */
142
151
  # define FFI_MMAP_EXEC_SELINUX 1
143
- # endif
144
- #endif
152
+ # endif /* !defined FFI_MMAP_EXEC_SELINUX */
153
+ # if !defined FFI_MMAP_PAX
154
+ /* Also check for PaX MPROTECT */
155
+ # define FFI_MMAP_PAX 1
156
+ # endif /* !defined FFI_MMAP_PAX */
157
+ #endif /* FFI_MMAP_EXEC_WRIT && defined(__linux__) && !defined(__ANDROID__) */
145
158
 
146
159
  #if FFI_CLOSURES
147
160
 
@@ -166,7 +179,6 @@ struct ffi_trampoline_table
166
179
  {
167
180
  /* contiguous writable and executable pages */
168
181
  vm_address_t config_page;
169
- vm_address_t trampoline_page;
170
182
 
171
183
  /* free list tracking */
172
184
  uint16_t free_count;
@@ -210,7 +222,13 @@ ffi_trampoline_table_alloc (void)
210
222
 
211
223
  /* Remap the trampoline table on top of the placeholder page */
212
224
  trampoline_page = config_page + PAGE_MAX_SIZE;
225
+
226
+ #ifdef HAVE_PTRAUTH
227
+ trampoline_page_template = (vm_address_t)(uintptr_t)ptrauth_auth_data((void *)&ffi_closure_trampoline_table_page, ptrauth_key_function_pointer, 0);
228
+ #else
213
229
  trampoline_page_template = (vm_address_t)&ffi_closure_trampoline_table_page;
230
+ #endif
231
+
214
232
  #ifdef __arm__
215
233
  /* ffi_closure_trampoline_table_page can be thumb-biased on some ARM archs */
216
234
  trampoline_page_template &= ~1UL;
@@ -224,11 +242,22 @@ ffi_trampoline_table_alloc (void)
224
242
  return NULL;
225
243
  }
226
244
 
245
+ if (!(cur_prot & VM_PROT_EXECUTE))
246
+ {
247
+ /* If VM_PROT_EXECUTE isn't set on the remapped trampoline page, set it */
248
+ kt = vm_protect (mach_task_self (), trampoline_page, PAGE_MAX_SIZE,
249
+ FALSE, cur_prot | VM_PROT_EXECUTE);
250
+ if (kt != KERN_SUCCESS)
251
+ {
252
+ vm_deallocate (mach_task_self (), config_page, PAGE_MAX_SIZE * 2);
253
+ return NULL;
254
+ }
255
+ }
256
+
227
257
  /* We have valid trampoline and config pages */
228
258
  table = calloc (1, sizeof (ffi_trampoline_table));
229
259
  table->free_count = FFI_TRAMPOLINE_COUNT;
230
260
  table->config_page = config_page;
231
- table->trampoline_page = trampoline_page;
232
261
 
233
262
  /* Create and initialize the free list */
234
263
  table->free_list_pool =
@@ -238,7 +267,10 @@ ffi_trampoline_table_alloc (void)
238
267
  {
239
268
  ffi_trampoline_table_entry *entry = &table->free_list_pool[i];
240
269
  entry->trampoline =
241
- (void *) (table->trampoline_page + (i * FFI_TRAMPOLINE_SIZE));
270
+ (void *) (trampoline_page + (i * FFI_TRAMPOLINE_SIZE));
271
+ #ifdef HAVE_PTRAUTH
272
+ entry->trampoline = ptrauth_sign_unauthenticated(entry->trampoline, ptrauth_key_function_pointer, 0);
273
+ #endif
242
274
 
243
275
  if (i < table->free_count - 1)
244
276
  entry->next = &table->free_list_pool[i + 1];
@@ -307,9 +339,6 @@ ffi_closure_alloc (size_t size, void **code)
307
339
 
308
340
  /* Initialize the return values */
309
341
  *code = entry->trampoline;
310
- #ifdef HAVE_PTRAUTH
311
- *code = ptrauth_sign_unauthenticated (*code, ptrauth_key_asia, 0);
312
- #endif
313
342
  closure->trampoline_table = table;
314
343
  closure->trampoline_table_entry = entry;
315
344
 
@@ -456,14 +485,18 @@ selinux_enabled_check (void)
456
485
 
457
486
  #endif /* !FFI_MMAP_EXEC_SELINUX */
458
487
 
459
- /* On PaX enable kernels that have MPROTECT enable we can't use PROT_EXEC. */
460
- #ifdef FFI_MMAP_EXEC_EMUTRAMP_PAX
488
+ /* On PaX enable kernels that have MPROTECT enabled we can't use PROT_EXEC. */
489
+ #if defined FFI_MMAP_PAX
461
490
  #include <stdlib.h>
462
491
 
463
- static int emutramp_enabled = -1;
492
+ enum {
493
+ PAX_MPROTECT = (1 << 0),
494
+ PAX_EMUTRAMP = (1 << 1),
495
+ };
496
+ static int cached_pax_flags = -1;
464
497
 
465
498
  static int
466
- emutramp_enabled_check (void)
499
+ pax_flags_check (void)
467
500
  {
468
501
  char *buf = NULL;
469
502
  size_t len = 0;
@@ -477,9 +510,10 @@ emutramp_enabled_check (void)
477
510
  while (getline (&buf, &len, f) != -1)
478
511
  if (!strncmp (buf, "PaX:", 4))
479
512
  {
480
- char emutramp;
481
- if (sscanf (buf, "%*s %*c%c", &emutramp) == 1)
482
- ret = (emutramp == 'E');
513
+ if (NULL != strchr (buf + 4, 'M'))
514
+ ret |= PAX_MPROTECT;
515
+ if (NULL != strchr (buf + 4, 'E'))
516
+ ret |= PAX_EMUTRAMP;
483
517
  break;
484
518
  }
485
519
  free (buf);
@@ -487,9 +521,13 @@ emutramp_enabled_check (void)
487
521
  return ret;
488
522
  }
489
523
 
490
- #define is_emutramp_enabled() (emutramp_enabled >= 0 ? emutramp_enabled \
491
- : (emutramp_enabled = emutramp_enabled_check ()))
492
- #endif /* FFI_MMAP_EXEC_EMUTRAMP_PAX */
524
+ #define get_pax_flags() (cached_pax_flags >= 0 ? cached_pax_flags \
525
+ : (cached_pax_flags = pax_flags_check ()))
526
+ #define has_pax_flags(flags) ((flags) == ((flags) & get_pax_flags ()))
527
+ #define is_mprotect_enabled() (has_pax_flags (PAX_MPROTECT))
528
+ #define is_emutramp_enabled() (has_pax_flags (PAX_EMUTRAMP))
529
+
530
+ #endif /* defined FFI_MMAP_PAX */
493
531
 
494
532
  #elif defined (__CYGWIN__) || defined(__INTERIX)
495
533
 
@@ -500,9 +538,10 @@ emutramp_enabled_check (void)
500
538
 
501
539
  #endif /* !defined(X86_WIN32) && !defined(X86_WIN64) */
502
540
 
503
- #ifndef FFI_MMAP_EXEC_EMUTRAMP_PAX
504
- #define is_emutramp_enabled() 0
505
- #endif /* FFI_MMAP_EXEC_EMUTRAMP_PAX */
541
+ #if !defined FFI_MMAP_PAX
542
+ # define is_mprotect_enabled() 0
543
+ # define is_emutramp_enabled() 0
544
+ #endif /* !defined FFI_MMAP_PAX */
506
545
 
507
546
  /* Declare all functions defined in dlmalloc.c as static. */
508
547
  static void *dlmalloc(size_t);
@@ -560,7 +599,7 @@ open_temp_exec_file_memfd (const char *name)
560
599
 
561
600
  /* Open a temporary file name, and immediately unlink it. */
562
601
  static int
563
- open_temp_exec_file_name (char *name, int flags)
602
+ open_temp_exec_file_name (char *name, int flags MAYBE_UNUSED)
564
603
  {
565
604
  int fd;
566
605
 
@@ -688,6 +727,7 @@ static struct
688
727
  #ifdef HAVE_MEMFD_CREATE
689
728
  { open_temp_exec_file_memfd, "libffi", 0 },
690
729
  #endif
730
+ { open_temp_exec_file_env, "LIBFFI_TMPDIR", 0 },
691
731
  { open_temp_exec_file_env, "TMPDIR", 0 },
692
732
  { open_temp_exec_file_dir, "/tmp", 0 },
693
733
  { open_temp_exec_file_dir, "/var/tmp", 0 },
@@ -725,7 +765,7 @@ open_temp_exec_file_opts_next (void)
725
765
 
726
766
  /* Return a file descriptor of a temporary zero-sized file in a
727
767
  writable and executable filesystem. */
728
- static int
768
+ int
729
769
  open_temp_exec_file (void)
730
770
  {
731
771
  int fd;
@@ -755,9 +795,9 @@ open_temp_exec_file (void)
755
795
  Failure to allocate the space will cause SIGBUS to be thrown when
756
796
  the mapping is subsequently written to. */
757
797
  static int
758
- allocate_space (int fd, off_t offset, off_t len)
798
+ allocate_space (int fd, off_t len)
759
799
  {
760
- static size_t page_size;
800
+ static long page_size;
761
801
 
762
802
  /* Obtain system page size. */
763
803
  if (!page_size)
@@ -798,7 +838,7 @@ dlmmap_locked (void *start, size_t length, int prot, int flags, off_t offset)
798
838
 
799
839
  offset = execsize;
800
840
 
801
- if (allocate_space (execfd, offset, length))
841
+ if (allocate_space (execfd, length))
802
842
  return MFAIL;
803
843
 
804
844
  flags &= ~(MAP_PRIVATE | MAP_ANONYMOUS);
@@ -860,13 +900,29 @@ dlmmap (void *start, size_t length, int prot,
860
900
  && flags == (MAP_PRIVATE | MAP_ANONYMOUS)
861
901
  && fd == -1 && offset == 0);
862
902
 
863
- if (execfd == -1 && is_emutramp_enabled ())
903
+ if (execfd == -1 && ffi_tramp_is_supported ())
864
904
  {
865
905
  ptr = mmap (start, length, prot & ~PROT_EXEC, flags, fd, offset);
866
906
  return ptr;
867
907
  }
868
908
 
869
- if (execfd == -1 && !is_selinux_enabled ())
909
+ /* -1 != execfd hints that we already decided to use dlmmap_locked
910
+ last time. */
911
+ if (execfd == -1 && is_mprotect_enabled ())
912
+ {
913
+ #ifdef FFI_MMAP_EXEC_EMUTRAMP_PAX
914
+ if (is_emutramp_enabled ())
915
+ {
916
+ /* emutramp requires the kernel recognizing the trampoline pattern
917
+ generated by ffi_prep_closure_loc; there is no way to test
918
+ in advance whether this will work, so this is experimental. */
919
+ ptr = mmap (start, length, prot & ~PROT_EXEC, flags, fd, offset);
920
+ return ptr;
921
+ }
922
+ #endif
923
+ /* fallback to dlmmap_locked. */
924
+ }
925
+ else if (execfd == -1 && !is_selinux_enabled ())
870
926
  {
871
927
  ptr = mmap (start, length, prot | PROT_EXEC, flags, fd, offset);
872
928
 
@@ -879,16 +935,11 @@ dlmmap (void *start, size_t length, int prot,
879
935
  MREMAP_DUP and prot at this point. */
880
936
  }
881
937
 
882
- if (execsize == 0 || execfd == -1)
883
- {
884
- pthread_mutex_lock (&open_temp_exec_file_mutex);
885
- ptr = dlmmap_locked (start, length, prot, flags, offset);
886
- pthread_mutex_unlock (&open_temp_exec_file_mutex);
887
-
888
- return ptr;
889
- }
938
+ pthread_mutex_lock (&open_temp_exec_file_mutex);
939
+ ptr = dlmmap_locked (start, length, prot, flags, offset);
940
+ pthread_mutex_unlock (&open_temp_exec_file_mutex);
890
941
 
891
- return dlmmap_locked (start, length, prot, flags, offset);
942
+ return ptr;
892
943
  }
893
944
 
894
945
  /* Release memory at the given address, as well as the corresponding
@@ -939,18 +990,29 @@ segment_holding_code (mstate m, char* addr)
939
990
  void *
940
991
  ffi_closure_alloc (size_t size, void **code)
941
992
  {
942
- void *ptr;
993
+ void *ptr, *ftramp;
943
994
 
944
995
  if (!code)
945
996
  return NULL;
946
997
 
947
- ptr = FFI_CLOSURE_PTR (dlmalloc (size));
998
+ ptr = dlmalloc (size);
948
999
 
949
1000
  if (ptr)
950
1001
  {
951
1002
  msegmentptr seg = segment_holding (gm, ptr);
952
1003
 
953
- *code = add_segment_exec_offset (ptr, seg);
1004
+ *code = FFI_FN (add_segment_exec_offset (ptr, seg));
1005
+ if (!ffi_tramp_is_supported ())
1006
+ return ptr;
1007
+
1008
+ ftramp = ffi_tramp_alloc (0);
1009
+ if (ftramp == NULL)
1010
+ {
1011
+ dlfree (ptr);
1012
+ return NULL;
1013
+ }
1014
+ *code = FFI_FN (ffi_tramp_get_addr (ftramp));
1015
+ ((ffi_closure *) ptr)->ftramp = ftramp;
954
1016
  }
955
1017
 
956
1018
  return ptr;
@@ -965,7 +1027,11 @@ ffi_data_to_code_pointer (void *data)
965
1027
  burden of managing this memory themselves, in which case this
966
1028
  we'll just return data. */
967
1029
  if (seg)
968
- return add_segment_exec_offset (data, seg);
1030
+ {
1031
+ if (!ffi_tramp_is_supported ())
1032
+ return add_segment_exec_offset (data, seg);
1033
+ return ffi_tramp_get_addr (((ffi_closure *) data)->ftramp);
1034
+ }
969
1035
  else
970
1036
  return data;
971
1037
  }
@@ -983,8 +1049,17 @@ ffi_closure_free (void *ptr)
983
1049
  if (seg)
984
1050
  ptr = sub_segment_exec_offset (ptr, seg);
985
1051
  #endif
1052
+ if (ffi_tramp_is_supported ())
1053
+ ffi_tramp_free (((ffi_closure *) ptr)->ftramp);
986
1054
 
987
- dlfree (FFI_RESTORE_PTR (ptr));
1055
+ dlfree (ptr);
1056
+ }
1057
+
1058
+ int
1059
+ ffi_tramp_is_present (void *ptr)
1060
+ {
1061
+ msegmentptr seg = segment_holding (gm, ptr);
1062
+ return seg != NULL && ffi_tramp_is_supported();
988
1063
  }
989
1064
 
990
1065
  # else /* ! FFI_MMAP_EXEC_WRIT */
@@ -997,16 +1072,20 @@ ffi_closure_free (void *ptr)
997
1072
  void *
998
1073
  ffi_closure_alloc (size_t size, void **code)
999
1074
  {
1075
+ void *c;
1076
+
1000
1077
  if (!code)
1001
1078
  return NULL;
1002
1079
 
1003
- return *code = FFI_CLOSURE_PTR (malloc (size));
1080
+ c = malloc (size);
1081
+ *code = FFI_FN (c);
1082
+ return c;
1004
1083
  }
1005
1084
 
1006
1085
  void
1007
1086
  ffi_closure_free (void *ptr)
1008
1087
  {
1009
- free (FFI_RESTORE_PTR (ptr));
1088
+ free (ptr);
1010
1089
  }
1011
1090
 
1012
1091
  void *
@@ -1015,7 +1094,14 @@ ffi_data_to_code_pointer (void *data)
1015
1094
  return data;
1016
1095
  }
1017
1096
 
1097
+ int
1098
+ ffi_tramp_is_present (__attribute__((unused)) void *ptr)
1099
+ {
1100
+ return 0;
1101
+ }
1102
+
1018
1103
  # endif /* ! FFI_MMAP_EXEC_WRIT */
1019
1104
  #endif /* FFI_CLOSURES */
1020
1105
 
1021
1106
  #endif /* NetBSD with PROT_MPROTECT */
1107
+ #endif /* __EMSCRIPTEN__ */
@@ -38,7 +38,7 @@ void ffi_stop_here(void)
38
38
 
39
39
  /* This function should only be called via the FFI_ASSERT() macro */
40
40
 
41
- void ffi_assert(char *expr, char *file, int line)
41
+ NORETURN void ffi_assert(const char *expr, const char *file, int line)
42
42
  {
43
43
  fprintf(stderr, "ASSERTION FAILURE: %s at %s:%d\n", expr, file, line);
44
44
  ffi_stop_here();
@@ -47,7 +47,7 @@ void ffi_assert(char *expr, char *file, int line)
47
47
 
48
48
  /* Perform a sanity check on an ffi_type structure */
49
49
 
50
- void ffi_type_test(ffi_type *a, char *file, int line)
50
+ void ffi_type_test(ffi_type *a, const char *file, int line)
51
51
  {
52
52
  FFI_ASSERT_AT(a != NULL, file, line);
53
53
 
@@ -592,6 +592,11 @@ DEFAULT_MMAP_THRESHOLD default: 256K
592
592
  malloc does support the following options.
593
593
  */
594
594
 
595
+ /* The system's malloc.h may have conflicting defines. */
596
+ #undef M_TRIM_THRESHOLD
597
+ #undef M_GRANULARITY
598
+ #undef M_MMAP_THRESHOLD
599
+
595
600
  #define M_TRIM_THRESHOLD (-1)
596
601
  #define M_GRANULARITY (-2)
597
602
  #define M_MMAP_THRESHOLD (-3)
@@ -4447,7 +4452,7 @@ struct mallinfo dlmallinfo(void) {
4447
4452
  }
4448
4453
  #endif /* NO_MALLINFO */
4449
4454
 
4450
- void dlmalloc_stats() {
4455
+ void dlmalloc_stats(void) {
4451
4456
  internal_malloc_stats(gm);
4452
4457
  }
4453
4458
 
@@ -38,7 +38,11 @@
38
38
  /* A 64-bit pointer value. In LP64 mode, this is effectively a plain
39
39
  pointer. In ILP32 mode, it's a pointer that's been extended to
40
40
  64 bits by "addp4". */
41
+ #ifdef __hpux
42
+ typedef void *PTR64;
43
+ #else // some other unix
41
44
  typedef void *PTR64 __attribute__((mode(DI)));
45
+ #endif
42
46
 
43
47
  /* Memory image of fp register contents. This is the implementation
44
48
  specific format used by ldf.fill/stf.spill. All we care about is
@@ -76,14 +80,22 @@ endian_adjust (void *addr, size_t len)
76
80
  point types without type conversions. Type conversion to long double breaks
77
81
  the denorm support. */
78
82
 
83
+ #ifdef __hpux
84
+ #define stf_spill(addr, value)
85
+ #else
79
86
  #define stf_spill(addr, value) \
80
87
  asm ("stf.spill %0 = %1%P0" : "=m" (*addr) : "f"(value));
88
+ #endif
81
89
 
82
90
  /* Load a value from ADDR, which is in the current cpu implementation's
83
91
  fp spill format. As above, this must also be a macro. */
84
92
 
93
+ #ifdef __hpux
94
+ #define ldf_fill(result, addr)
95
+ #else
85
96
  #define ldf_fill(result, addr) \
86
97
  asm ("ldf.fill %0 = %1%P1" : "=f"(result) : "m"(*addr));
98
+ #endif
87
99
 
88
100
  /* Return the size of the C type associated with with TYPE. Which will
89
101
  be one of the FFI_IA64_TYPE_HFA_* values. */
@@ -36,6 +36,12 @@
36
36
 
37
37
  .pred.safe_across_calls p1-p5,p16-p63
38
38
  .text
39
+ /* HPUX assembler needs to see these symbols, otherwise compilation
40
+ fails */
41
+ #ifdef __hpux
42
+ .global memcpy
43
+ .global ffi_closure_unix_inner
44
+ #endif
39
45
 
40
46
  /* int ffi_call_unix (struct ia64_args *stack, PTR64 rvalue,
41
47
  void (*fn)(void), int flags);
@@ -104,7 +110,12 @@ ffi_call_unix:
104
110
  mov ar.pfs = loc0
105
111
  addl r18 = @ltoffx(.Lst_table), gp
106
112
  ;;
113
+ /* default assembler on HP-UX does not support LDXMOV */
114
+ #ifdef __hpux
115
+ ld8 r18 = [r18]
116
+ #else
107
117
  ld8.mov r18 = [r18], .Lst_table
118
+ #endif
108
119
  mov b0 = loc1
109
120
  ;;
110
121
  shladd r18 = r16, 3, r18
@@ -357,7 +368,11 @@ ffi_closure_unix:
357
368
  addl r18 = @ltoffx(.Lld_table), gp
358
369
  mov ar.pfs = loc0
359
370
  ;;
360
- ld8.mov r18 = [r18], .Lld_table
371
+ #ifdef __hpux
372
+ ld8 r18 = [r18]
373
+ #else
374
+ ld8.mov r18 = [r18], .Lst_table
375
+ #endif
361
376
  mov b0 = loc1
362
377
  ;;
363
378
  shladd r18 = r16, 3, r18
@@ -515,8 +530,11 @@ ffi_closure_unix:
515
530
  ;;
516
531
 
517
532
  .endp ffi_closure_unix
518
-
533
+ #ifdef __hpux
534
+ .rodata
535
+ #else
519
536
  .section .rodata
537
+ #endif
520
538
  .align 8
521
539
  .Lst_table:
522
540
  data8 @pcrel(.Lst_void) // FFI_TYPE_VOID