ffi 1.11.3 → 1.15.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (276) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +184 -0
  3. data/Gemfile +3 -4
  4. data/README.md +24 -3
  5. data/Rakefile +64 -69
  6. data/ext/ffi_c/AbstractMemory.c +24 -25
  7. data/ext/ffi_c/Buffer.c +4 -9
  8. data/ext/ffi_c/Call.c +4 -16
  9. data/ext/ffi_c/ClosurePool.c +75 -25
  10. data/ext/ffi_c/ClosurePool.h +3 -1
  11. data/ext/ffi_c/DynamicLibrary.c +1 -6
  12. data/ext/ffi_c/Function.c +38 -38
  13. data/ext/ffi_c/Function.h +0 -4
  14. data/ext/ffi_c/FunctionInfo.c +3 -8
  15. data/ext/ffi_c/LastError.c +2 -6
  16. data/ext/ffi_c/LongDouble.c +5 -3
  17. data/ext/ffi_c/LongDouble.h +0 -4
  18. data/ext/ffi_c/MemoryPointer.c +3 -8
  19. data/ext/ffi_c/MemoryPointer.h +0 -4
  20. data/ext/ffi_c/MethodHandle.c +21 -31
  21. data/ext/ffi_c/MethodHandle.h +3 -2
  22. data/ext/ffi_c/Platform.c +5 -9
  23. data/ext/ffi_c/Pointer.c +25 -26
  24. data/ext/ffi_c/Pointer.h +0 -4
  25. data/ext/ffi_c/Struct.c +49 -56
  26. data/ext/ffi_c/Struct.h +12 -6
  27. data/ext/ffi_c/StructByValue.c +2 -7
  28. data/ext/ffi_c/StructLayout.c +22 -20
  29. data/ext/ffi_c/Thread.c +0 -8
  30. data/ext/ffi_c/Thread.h +1 -9
  31. data/ext/ffi_c/Type.c +1 -1
  32. data/ext/ffi_c/Types.c +6 -7
  33. data/ext/ffi_c/Types.h +3 -4
  34. data/ext/ffi_c/Variadic.c +14 -9
  35. data/ext/ffi_c/compat.h +4 -0
  36. data/ext/ffi_c/extconf.rb +36 -24
  37. data/ext/ffi_c/libffi/.travis/bfin-sim.exp +58 -0
  38. data/ext/ffi_c/libffi/.travis/build-cross-in-container.sh +14 -0
  39. data/ext/ffi_c/libffi/.travis/build-in-container.sh +2 -12
  40. data/ext/ffi_c/libffi/.travis/build.sh +62 -30
  41. data/ext/ffi_c/libffi/.travis/install.sh +65 -37
  42. data/ext/ffi_c/libffi/.travis/m32r-sim.exp +58 -0
  43. data/ext/ffi_c/libffi/.travis/moxie-sim.exp +1 -1
  44. data/ext/ffi_c/libffi/.travis/or1k-sim.exp +58 -0
  45. data/ext/ffi_c/libffi/.travis/powerpc-eabisim.exp +58 -0
  46. data/ext/ffi_c/libffi/.travis/site.exp +10 -1
  47. data/ext/ffi_c/libffi/.travis/wine-sim.exp +55 -0
  48. data/ext/ffi_c/libffi/.travis.yml +32 -12
  49. data/ext/ffi_c/libffi/{ChangeLog.libffi-3.1 → ChangeLog.old} +1407 -0
  50. data/ext/ffi_c/libffi/LICENSE +1 -1
  51. data/ext/ffi_c/libffi/Makefile.am +53 -61
  52. data/ext/ffi_c/libffi/Makefile.in +458 -207
  53. data/ext/ffi_c/libffi/README.md +22 -6
  54. data/ext/ffi_c/libffi/config.guess +552 -331
  55. data/ext/ffi_c/libffi/config.sub +1321 -1306
  56. data/ext/ffi_c/libffi/configure +414 -342
  57. data/ext/ffi_c/libffi/configure.ac +32 -11
  58. data/ext/ffi_c/libffi/configure.host +37 -22
  59. data/ext/ffi_c/libffi/doc/Makefile.in +9 -5
  60. data/ext/ffi_c/libffi/doc/libffi.texi +26 -14
  61. data/ext/ffi_c/libffi/doc/version.texi +4 -4
  62. data/ext/ffi_c/libffi/fficonfig.h.in +13 -0
  63. data/ext/ffi_c/libffi/generate-darwin-source-and-headers.py +2 -4
  64. data/ext/ffi_c/libffi/include/Makefile.in +10 -6
  65. data/ext/ffi_c/libffi/include/ffi.h.in +15 -7
  66. data/ext/ffi_c/libffi/install-sh +23 -13
  67. data/ext/ffi_c/libffi/libffi.map.in +8 -12
  68. data/ext/ffi_c/libffi/libffi.xcodeproj/project.pbxproj +2 -48
  69. data/ext/ffi_c/libffi/libtool-version +1 -1
  70. data/ext/ffi_c/libffi/ltmain.sh +156 -61
  71. data/ext/ffi_c/libffi/m4/ax_append_flag.m4 +5 -26
  72. data/ext/ffi_c/libffi/m4/ax_check_compile_flag.m4 +5 -26
  73. data/ext/ffi_c/libffi/m4/ax_compiler_vendor.m4 +2 -1
  74. data/ext/ffi_c/libffi/m4/ax_configure_args.m4 +5 -26
  75. data/ext/ffi_c/libffi/m4/ax_gcc_archflag.m4 +7 -3
  76. data/ext/ffi_c/libffi/man/Makefile.in +9 -5
  77. data/ext/ffi_c/libffi/missing +8 -8
  78. data/ext/ffi_c/libffi/msvcc.sh +11 -11
  79. data/ext/ffi_c/libffi/src/aarch64/ffi.c +51 -35
  80. data/ext/ffi_c/libffi/src/aarch64/ffitarget.h +10 -5
  81. data/ext/ffi_c/libffi/src/aarch64/internal.h +1 -0
  82. data/ext/ffi_c/libffi/src/aarch64/sysv.S +14 -3
  83. data/ext/ffi_c/libffi/src/aarch64/win64_armasm.S +1 -1
  84. data/ext/ffi_c/libffi/src/arm/ffi.c +22 -0
  85. data/ext/ffi_c/libffi/src/arm/sysv.S +4 -4
  86. data/ext/ffi_c/libffi/src/closures.c +43 -12
  87. data/ext/ffi_c/libffi/src/csky/ffi.c +395 -0
  88. data/ext/ffi_c/libffi/src/csky/ffitarget.h +63 -0
  89. data/ext/ffi_c/libffi/src/csky/sysv.S +371 -0
  90. data/ext/ffi_c/libffi/src/dlmalloc.c +1 -1
  91. data/ext/ffi_c/libffi/src/kvx/asm.h +5 -0
  92. data/ext/ffi_c/libffi/src/kvx/ffi.c +273 -0
  93. data/ext/ffi_c/libffi/src/kvx/ffitarget.h +75 -0
  94. data/ext/ffi_c/libffi/src/kvx/sysv.S +127 -0
  95. data/ext/ffi_c/libffi/src/mips/ffi.c +5 -1
  96. data/ext/ffi_c/libffi/src/mips/ffitarget.h +1 -1
  97. data/ext/ffi_c/libffi/src/mips/o32.S +2 -0
  98. data/ext/ffi_c/libffi/src/pa/ffi.c +46 -91
  99. data/ext/ffi_c/libffi/src/pa/ffitarget.h +1 -6
  100. data/ext/ffi_c/libffi/src/pa/hpux32.S +4 -2
  101. data/ext/ffi_c/libffi/src/pa/linux.S +4 -2
  102. data/ext/ffi_c/libffi/src/powerpc/ffi.c +3 -2
  103. data/ext/ffi_c/libffi/src/powerpc/ffi_darwin.c +13 -1
  104. data/ext/ffi_c/libffi/src/powerpc/ffi_linux64.c +154 -8
  105. data/ext/ffi_c/libffi/src/powerpc/ffi_powerpc.h +18 -7
  106. data/ext/ffi_c/libffi/src/powerpc/ffitarget.h +10 -4
  107. data/ext/ffi_c/libffi/src/powerpc/linux64.S +91 -28
  108. data/ext/ffi_c/libffi/src/powerpc/linux64_closure.S +80 -4
  109. data/ext/ffi_c/libffi/src/powerpc/sysv.S +5 -7
  110. data/ext/ffi_c/libffi/src/prep_cif.c +1 -1
  111. data/ext/ffi_c/libffi/src/x86/ffi.c +15 -6
  112. data/ext/ffi_c/libffi/src/x86/ffi64.c +17 -8
  113. data/ext/ffi_c/libffi/src/x86/ffitarget.h +15 -2
  114. data/ext/ffi_c/libffi/src/x86/ffiw64.c +15 -8
  115. data/ext/ffi_c/libffi/src/x86/sysv.S +15 -6
  116. data/ext/ffi_c/libffi/src/x86/unix64.S +59 -4
  117. data/ext/ffi_c/libffi/src/x86/win64.S +7 -3
  118. data/ext/ffi_c/libffi/src/x86/win64_intel.S +3 -2
  119. data/ext/ffi_c/libffi/testsuite/Makefile.am +78 -75
  120. data/ext/ffi_c/libffi/testsuite/Makefile.in +124 -84
  121. data/ext/ffi_c/libffi/testsuite/lib/libffi.exp +7 -4
  122. data/ext/ffi_c/libffi/testsuite/libffi.bhaible/bhaible.exp +7 -2
  123. data/ext/ffi_c/libffi/testsuite/libffi.bhaible/test-call.c +4 -4
  124. data/ext/ffi_c/libffi/testsuite/libffi.bhaible/test-callback.c +2 -2
  125. data/ext/ffi_c/libffi/testsuite/libffi.call/call.exp +12 -1
  126. data/ext/ffi_c/libffi/testsuite/libffi.closures/closure.exp +67 -0
  127. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/closure_fn0.c +0 -0
  128. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/closure_fn1.c +0 -0
  129. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/closure_fn2.c +0 -0
  130. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/closure_fn3.c +0 -0
  131. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/closure_fn4.c +0 -0
  132. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/closure_fn5.c +0 -0
  133. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/closure_fn6.c +0 -0
  134. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/closure_loc_fn0.c +0 -0
  135. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/closure_simple.c +0 -0
  136. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_12byte.c +0 -0
  137. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_16byte.c +0 -0
  138. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_18byte.c +0 -0
  139. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_19byte.c +0 -0
  140. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_1_1byte.c +0 -0
  141. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_20byte.c +0 -0
  142. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_20byte1.c +0 -0
  143. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_24byte.c +0 -0
  144. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_2byte.c +0 -0
  145. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_3_1byte.c +0 -0
  146. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_3byte1.c +0 -0
  147. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_3byte2.c +0 -0
  148. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_3float.c +0 -0
  149. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_4_1byte.c +0 -0
  150. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_4byte.c +0 -0
  151. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_5_1_byte.c +0 -0
  152. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_5byte.c +0 -0
  153. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_64byte.c +0 -0
  154. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_6_1_byte.c +0 -0
  155. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_6byte.c +0 -0
  156. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_7_1_byte.c +0 -0
  157. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_7byte.c +0 -0
  158. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_8byte.c +0 -0
  159. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_9byte1.c +0 -0
  160. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_9byte2.c +0 -0
  161. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_double.c +0 -0
  162. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_float.c +0 -0
  163. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_longdouble.c +0 -0
  164. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_longdouble_split.c +0 -0
  165. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_longdouble_split2.c +0 -0
  166. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_pointer.c +0 -0
  167. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_sint16.c +0 -0
  168. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_sint32.c +0 -0
  169. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_sint64.c +0 -0
  170. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_uint16.c +0 -0
  171. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_uint32.c +0 -0
  172. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_uint64.c +0 -0
  173. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_dbls_struct.c +0 -0
  174. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_double.c +0 -0
  175. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_double_va.c +0 -0
  176. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_float.c +0 -0
  177. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_longdouble.c +0 -0
  178. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_longdouble_va.c +0 -0
  179. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_many_mixed_args.c +0 -0
  180. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_many_mixed_float_double.c +0 -0
  181. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_multi_schar.c +0 -0
  182. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_multi_sshort.c +0 -0
  183. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_multi_sshortchar.c +0 -0
  184. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_multi_uchar.c +0 -0
  185. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_multi_ushort.c +0 -0
  186. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_multi_ushortchar.c +0 -0
  187. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_pointer.c +0 -0
  188. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_pointer_stack.c +0 -0
  189. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_schar.c +0 -0
  190. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_sint.c +0 -0
  191. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_sshort.c +0 -0
  192. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_struct_va1.c +0 -0
  193. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_uchar.c +0 -0
  194. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_uchar_va.c +0 -0
  195. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_uint.c +0 -0
  196. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_uint_va.c +0 -0
  197. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_ulong_va.c +0 -0
  198. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_ulonglong.c +0 -0
  199. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_ushort.c +0 -0
  200. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_ushort_va.c +0 -0
  201. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/err_bad_abi.c +0 -0
  202. data/ext/ffi_c/libffi/testsuite/libffi.closures/ffitest.h +138 -0
  203. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/huge_struct.c +3 -1
  204. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct.c +0 -0
  205. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct1.c +0 -0
  206. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct10.c +0 -0
  207. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct11.c +0 -0
  208. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct2.c +0 -0
  209. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct3.c +0 -0
  210. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct4.c +0 -0
  211. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct5.c +0 -0
  212. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct6.c +0 -0
  213. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct7.c +0 -0
  214. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct8.c +0 -0
  215. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct9.c +0 -0
  216. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/problem1.c +0 -0
  217. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/stret_large.c +0 -0
  218. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/stret_large2.c +0 -0
  219. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/stret_medium.c +0 -0
  220. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/stret_medium2.c +0 -0
  221. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/testclosure.c +0 -0
  222. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/unwindtest.cc +0 -0
  223. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/unwindtest_ffi_call.cc +0 -0
  224. data/ffi.gemspec +4 -5
  225. data/lib/ffi/abstract_memory.rb +44 -0
  226. data/lib/ffi/autopointer.rb +1 -1
  227. data/lib/ffi/ffi.rb +2 -0
  228. data/lib/ffi/io.rb +3 -3
  229. data/lib/ffi/library.rb +8 -4
  230. data/lib/ffi/managedstruct.rb +2 -2
  231. data/lib/ffi/platform/aarch64-darwin/types.conf +130 -0
  232. data/lib/ffi/platform/aarch64-freebsd/types.conf +2 -2
  233. data/lib/ffi/platform/aarch64-freebsd12/types.conf +113 -60
  234. data/lib/ffi/platform/aarch64-openbsd/types.conf +134 -0
  235. data/lib/ffi/platform/arm-linux/types.conf +32 -4
  236. data/lib/ffi/platform/i386-windows/types.conf +26 -79
  237. data/lib/ffi/platform/powerpc-linux/types.conf +32 -2
  238. data/lib/ffi/platform/powerpc-openbsd/types.conf +156 -0
  239. data/lib/ffi/platform/powerpc64le-linux/types.conf +100 -0
  240. data/lib/ffi/platform/riscv64-linux/types.conf +104 -0
  241. data/lib/ffi/platform/sparcv9-openbsd/types.conf +156 -0
  242. data/lib/ffi/platform/x86_64-darwin/types.conf +4 -0
  243. data/lib/ffi/platform/x86_64-dragonflybsd/types.conf +4 -22
  244. data/lib/ffi/platform/x86_64-haiku/types.conf +117 -0
  245. data/lib/ffi/platform/x86_64-linux/types.conf +21 -0
  246. data/lib/ffi/platform/x86_64-msys/types.conf +119 -0
  247. data/lib/ffi/platform/x86_64-windows/types.conf +10 -78
  248. data/lib/ffi/platform.rb +18 -8
  249. data/lib/ffi/pointer.rb +21 -14
  250. data/lib/ffi/struct.rb +10 -5
  251. data/lib/ffi/tools/const_generator.rb +6 -4
  252. data/lib/ffi/tools/struct_generator.rb +2 -1
  253. data/lib/ffi/tools/types_generator.rb +2 -0
  254. data/lib/ffi/variadic.rb +1 -10
  255. data/lib/ffi/version.rb +1 -1
  256. data/lib/ffi.rb +10 -3
  257. data/rakelib/ffi_gem_helper.rb +65 -0
  258. data/samples/getlogin.rb +1 -1
  259. data/samples/getpid.rb +1 -1
  260. data/samples/gettimeofday.rb +8 -8
  261. data/samples/hello.rb +2 -1
  262. data/samples/inotify.rb +1 -1
  263. data/samples/pty.rb +1 -2
  264. data/samples/qsort.rb +0 -1
  265. metadata +133 -134
  266. data/.appveyor.yml +0 -27
  267. data/.gitignore +0 -25
  268. data/.gitmodules +0 -4
  269. data/.travis.yml +0 -42
  270. data/.yardopts +0 -5
  271. data/ext/ffi_c/libffi/ChangeLog.libffi +0 -584
  272. data/ext/ffi_c/libffi/ChangeLog.libgcj +0 -40
  273. data/ext/ffi_c/libffi/ChangeLog.v1 +0 -764
  274. data/ext/ffi_c/win32/stdbool.h +0 -8
  275. data/ext/ffi_c/win32/stdint.h +0 -201
  276. data/samples/sample_helper.rb +0 -6
@@ -1,9 +1,9 @@
1
1
  #! /bin/sh
2
2
  # Common wrapper for a few potentially missing GNU programs.
3
3
 
4
- scriptversion=2013-10-28.13; # UTC
4
+ scriptversion=2018-03-07.03; # UTC
5
5
 
6
- # Copyright (C) 1996-2014 Free Software Foundation, Inc.
6
+ # Copyright (C) 1996-2018 Free Software Foundation, Inc.
7
7
  # Originally written by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
8
8
 
9
9
  # This program is free software; you can redistribute it and/or modify
@@ -17,7 +17,7 @@ scriptversion=2013-10-28.13; # UTC
17
17
  # GNU General Public License for more details.
18
18
 
19
19
  # You should have received a copy of the GNU General Public License
20
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
20
+ # along with this program. If not, see <https://www.gnu.org/licenses/>.
21
21
 
22
22
  # As a special exception to the GNU General Public License, if you
23
23
  # distribute this file as part of a program that contains a
@@ -101,9 +101,9 @@ else
101
101
  exit $st
102
102
  fi
103
103
 
104
- perl_URL=http://www.perl.org/
105
- flex_URL=http://flex.sourceforge.net/
106
- gnu_software_URL=http://www.gnu.org/software
104
+ perl_URL=https://www.perl.org/
105
+ flex_URL=https://github.com/westes/flex
106
+ gnu_software_URL=https://www.gnu.org/software
107
107
 
108
108
  program_details ()
109
109
  {
@@ -207,9 +207,9 @@ give_advice "$1" | sed -e '1s/^/WARNING: /' \
207
207
  exit $st
208
208
 
209
209
  # Local variables:
210
- # eval: (add-hook 'write-file-hooks 'time-stamp)
210
+ # eval: (add-hook 'before-save-hook 'time-stamp)
211
211
  # time-stamp-start: "scriptversion="
212
212
  # time-stamp-format: "%:y-%02m-%02d.%02H"
213
- # time-stamp-time-zone: "UTC"
213
+ # time-stamp-time-zone: "UTC0"
214
214
  # time-stamp-end: "; # UTC"
215
215
  # End:
@@ -165,24 +165,24 @@ do
165
165
  shift 1
166
166
  ;;
167
167
  -I)
168
- p=$(cygpath -m $2)
169
- args="$args -I$p"
170
- includes="$includes -I$p"
168
+ p=$(cygpath -ma "$2")
169
+ args="$args -I\"$p\""
170
+ includes="$includes -I\"$p\""
171
171
  shift 2
172
172
  ;;
173
173
  -I*)
174
- p=$(cygpath -m ${1#-I})
175
- args="$args -I$p"
176
- includes="$includes -I$p"
174
+ p=$(cygpath -ma "${1#-I}")
175
+ args="$args -I\"$p\""
176
+ includes="$includes -I\"$p\""
177
177
  shift 1
178
178
  ;;
179
179
  -L)
180
- p=$(cygpath -m $2)
180
+ p=$(cygpath -ma $2)
181
181
  linkargs="$linkargs -LIBPATH:$p"
182
182
  shift 2
183
183
  ;;
184
184
  -L*)
185
- p=$(cygpath -m ${1#-L})
185
+ p=$(cygpath -ma ${1#-L})
186
186
  linkargs="$linkargs -LIBPATH:$p"
187
187
  shift 1
188
188
  ;;
@@ -256,12 +256,12 @@ do
256
256
  shift 2
257
257
  ;;
258
258
  *.S)
259
- src=$1
259
+ src="$(cygpath -ma $1)"
260
260
  assembly="true"
261
261
  shift 1
262
262
  ;;
263
263
  *.c)
264
- args="$args $1"
264
+ args="$args $(cygpath -ma $1)"
265
265
  shift 1
266
266
  ;;
267
267
  *)
@@ -312,7 +312,7 @@ if [ -n "$assembly" ]; then
312
312
  echo "$cl -nologo -EP $includes $defines $src > $ppsrc"
313
313
  fi
314
314
 
315
- "$cl" -nologo -EP $includes $defines $src > $ppsrc || exit $?
315
+ eval "\"$cl\" -nologo -EP $includes $defines $src" > $ppsrc || exit $?
316
316
  output="$(echo $output | sed 's%/F[dpa][^ ]*%%g')"
317
317
  if [ $ml = "armasm" ]; then
318
318
  args="-nologo -g -oldit $armasm_output $ppsrc -errorReport:prompt"
@@ -27,7 +27,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
27
27
  #include <ffi.h>
28
28
  #include <ffi_common.h>
29
29
  #include "internal.h"
30
- #ifdef _M_ARM64
30
+ #ifdef _WIN32
31
31
  #include <windows.h> /* FlushInstructionCache */
32
32
  #endif
33
33
 
@@ -62,6 +62,9 @@ struct call_context
62
62
  #if FFI_EXEC_TRAMPOLINE_TABLE
63
63
 
64
64
  #ifdef __MACH__
65
+ #ifdef HAVE_PTRAUTH
66
+ #include <ptrauth.h>
67
+ #endif
65
68
  #include <mach/vm_param.h>
66
69
  #endif
67
70
 
@@ -78,7 +81,7 @@ ffi_clear_cache (void *start, void *end)
78
81
  sys_icache_invalidate (start, (char *)end - (char *)start);
79
82
  #elif defined (__GNUC__)
80
83
  __builtin___clear_cache (start, end);
81
- #elif defined (_M_ARM64)
84
+ #elif defined (_WIN32)
82
85
  FlushInstructionCache(GetCurrentProcess(), start, (char*)end - (char*)start);
83
86
  #else
84
87
  #error "Missing builtin to flush instruction cache"
@@ -561,6 +564,14 @@ ffi_prep_cif_machdep_var(ffi_cif *cif, unsigned int nfixedargs,
561
564
  cif->aarch64_nfixedargs = nfixedargs;
562
565
  return status;
563
566
  }
567
+ #else
568
+ ffi_status FFI_HIDDEN
569
+ ffi_prep_cif_machdep_var(ffi_cif *cif, unsigned int nfixedargs, unsigned int ntotalargs)
570
+ {
571
+ ffi_status status = ffi_prep_cif_machdep (cif);
572
+ cif->flags |= AARCH64_FLAG_VARARG;
573
+ return status;
574
+ }
564
575
  #endif /* __APPLE__ */
565
576
 
566
577
  extern void ffi_call_SYSV (struct call_context *context, void *frame,
@@ -577,7 +588,7 @@ ffi_call_int (ffi_cif *cif, void (*fn)(void), void *orig_rvalue,
577
588
  void *stack, *frame, *rvalue;
578
589
  struct arg_state state;
579
590
  size_t stack_bytes, rtype_size, rsize;
580
- int i, nargs, flags;
591
+ int i, nargs, flags, isvariadic = 0;
581
592
  ffi_type *rtype;
582
593
 
583
594
  flags = cif->flags;
@@ -585,6 +596,12 @@ ffi_call_int (ffi_cif *cif, void (*fn)(void), void *orig_rvalue,
585
596
  rtype_size = rtype->size;
586
597
  stack_bytes = cif->bytes;
587
598
 
599
+ if (flags & AARCH64_FLAG_VARARG)
600
+ {
601
+ isvariadic = 1;
602
+ flags &= ~AARCH64_FLAG_VARARG;
603
+ }
604
+
588
605
  /* If the target function returns a structure via hidden pointer,
589
606
  then we cannot allow a null rvalue. Otherwise, mash a null
590
607
  rvalue to void return type. */
@@ -664,35 +681,31 @@ ffi_call_int (ffi_cif *cif, void (*fn)(void), void *orig_rvalue,
664
681
  h = is_vfp_type (ty);
665
682
  if (h)
666
683
  {
667
- int elems = 4 - (h & 3);
668
- #ifdef _M_ARM64 /* for handling armasm calling convention */
669
- if (cif->is_variadic)
670
- {
671
- if (state.ngrn + elems <= N_X_ARG_REG)
672
- {
673
- dest = &context->x[state.ngrn];
674
- state.ngrn += elems;
675
- extend_hfa_type(dest, a, h);
676
- break;
677
- }
678
- state.nsrn = N_X_ARG_REG;
679
- dest = allocate_to_stack(&state, stack, ty->alignment, s);
680
- }
681
- else
682
- {
683
- #endif /* for handling armasm calling convention */
684
- if (state.nsrn + elems <= N_V_ARG_REG)
685
- {
686
- dest = &context->v[state.nsrn];
687
- state.nsrn += elems;
688
- extend_hfa_type (dest, a, h);
689
- break;
690
- }
691
- state.nsrn = N_V_ARG_REG;
692
- dest = allocate_to_stack (&state, stack, ty->alignment, s);
693
- #ifdef _M_ARM64 /* for handling armasm calling convention */
694
- }
695
- #endif /* for handling armasm calling convention */
684
+ int elems = 4 - (h & 3);
685
+ if (cif->abi == FFI_WIN64 && isvariadic)
686
+ {
687
+ if (state.ngrn + elems <= N_X_ARG_REG)
688
+ {
689
+ dest = &context->x[state.ngrn];
690
+ state.ngrn += elems;
691
+ extend_hfa_type(dest, a, h);
692
+ break;
693
+ }
694
+ state.nsrn = N_X_ARG_REG;
695
+ dest = allocate_to_stack(&state, stack, ty->alignment, s);
696
+ }
697
+ else
698
+ {
699
+ if (state.nsrn + elems <= N_V_ARG_REG)
700
+ {
701
+ dest = &context->v[state.nsrn];
702
+ state.nsrn += elems;
703
+ extend_hfa_type (dest, a, h);
704
+ break;
705
+ }
706
+ state.nsrn = N_V_ARG_REG;
707
+ dest = allocate_to_stack (&state, stack, ty->alignment, s);
708
+ }
696
709
  }
697
710
  else if (s > 16)
698
711
  {
@@ -789,6 +802,9 @@ ffi_prep_closure_loc (ffi_closure *closure,
789
802
 
790
803
  #if FFI_EXEC_TRAMPOLINE_TABLE
791
804
  #ifdef __MACH__
805
+ #ifdef HAVE_PTRAUTH
806
+ codeloc = ptrauth_strip (codeloc, ptrauth_key_asia);
807
+ #endif
792
808
  void **config = (void **)((uint8_t *)codeloc - PAGE_MAX_SIZE);
793
809
  config[0] = closure;
794
810
  config[1] = start;
@@ -808,7 +824,7 @@ ffi_prep_closure_loc (ffi_closure *closure,
808
824
  ffi_clear_cache(tramp, tramp + FFI_TRAMPOLINE_SIZE);
809
825
 
810
826
  /* Also flush the cache for code mapping. */
811
- #ifdef _M_ARM64
827
+ #ifdef _WIN32
812
828
  // Not using dlmalloc.c for Windows ARM64 builds
813
829
  // so calling ffi_data_to_code_pointer() isn't necessary
814
830
  unsigned char *tramp_code = tramp;
@@ -914,7 +930,7 @@ ffi_closure_SYSV_inner (ffi_cif *cif,
914
930
  if (h)
915
931
  {
916
932
  n = 4 - (h & 3);
917
- #ifdef _M_ARM64 /* for handling armasm calling convention */
933
+ #ifdef _WIN32 /* for handling armasm calling convention */
918
934
  if (cif->is_variadic)
919
935
  {
920
936
  if (state.ngrn + n <= N_X_ARG_REG)
@@ -954,7 +970,7 @@ ffi_closure_SYSV_inner (ffi_cif *cif,
954
970
  avalue[i] = allocate_to_stack(&state, stack,
955
971
  ty->alignment, s);
956
972
  }
957
- #ifdef _M_ARM64 /* for handling armasm calling convention */
973
+ #ifdef _WIN32 /* for handling armasm calling convention */
958
974
  }
959
975
  #endif /* for handling armasm calling convention */
960
976
  }
@@ -32,7 +32,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
32
32
  #define FFI_SIZEOF_JAVA_RAW 4
33
33
  typedef unsigned long long ffi_arg;
34
34
  typedef signed long long ffi_sarg;
35
- #elif defined(_M_ARM64)
35
+ #elif defined(_WIN32)
36
36
  #define FFI_SIZEOF_ARG 8
37
37
  typedef unsigned long long ffi_arg;
38
38
  typedef signed long long ffi_sarg;
@@ -45,8 +45,13 @@ typedef enum ffi_abi
45
45
  {
46
46
  FFI_FIRST_ABI = 0,
47
47
  FFI_SYSV,
48
+ FFI_WIN64,
48
49
  FFI_LAST_ABI,
50
+ #if defined(_WIN32)
51
+ FFI_DEFAULT_ABI = FFI_WIN64
52
+ #else
49
53
  FFI_DEFAULT_ABI = FFI_SYSV
54
+ #endif
50
55
  } ffi_abi;
51
56
  #endif
52
57
 
@@ -69,22 +74,22 @@ typedef enum ffi_abi
69
74
  #define FFI_TRAMPOLINE_CLOSURE_OFFSET FFI_TRAMPOLINE_SIZE
70
75
  #endif
71
76
 
72
- #ifdef _M_ARM64
77
+ #ifdef _WIN32
73
78
  #define FFI_EXTRA_CIF_FIELDS unsigned is_variadic
74
79
  #endif
80
+ #define FFI_TARGET_SPECIFIC_VARIADIC
75
81
 
76
82
  /* ---- Internal ---- */
77
83
 
78
84
  #if defined (__APPLE__)
79
- #define FFI_TARGET_SPECIFIC_VARIADIC
80
85
  #define FFI_EXTRA_CIF_FIELDS unsigned aarch64_nfixedargs
81
- #elif !defined(_M_ARM64)
86
+ #elif !defined(_WIN32)
82
87
  /* iOS and Windows reserve x18 for the system. Disable Go closures until
83
88
  a new static chain is chosen. */
84
89
  #define FFI_GO_CLOSURES 1
85
90
  #endif
86
91
 
87
- #ifndef _M_ARM64
92
+ #ifndef _WIN32
88
93
  /* No complex type on Windows */
89
94
  #define FFI_TARGET_HAS_COMPLEX_TYPE
90
95
  #endif
@@ -61,6 +61,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
61
61
 
62
62
  #define AARCH64_FLAG_ARG_V_BIT 7
63
63
  #define AARCH64_FLAG_ARG_V (1 << AARCH64_FLAG_ARG_V_BIT)
64
+ #define AARCH64_FLAG_VARARG (1 << 8)
64
65
 
65
66
  #define N_X_ARG_REG 8
66
67
  #define N_V_ARG_REG 8
@@ -56,6 +56,14 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
56
56
  #define PTR_SIZE 4
57
57
  #else
58
58
  #define PTR_SIZE 8
59
+ #endif
60
+
61
+ #if FFI_EXEC_TRAMPOLINE_TABLE && defined(__MACH__) && defined(HAVE_PTRAUTH)
62
+ # define BR(r) braaz r
63
+ # define BLR(r) blraaz r
64
+ #else
65
+ # define BR(r) br r
66
+ # define BLR(r) blr r
59
67
  #endif
60
68
 
61
69
  .text
@@ -111,7 +119,7 @@ CNAME(ffi_call_SYSV):
111
119
  /* Deallocate the context, leaving the stacked arguments. */
112
120
  add sp, sp, #CALL_CONTEXT_SIZE
113
121
 
114
- blr x9 /* call fn */
122
+ BLR(x9) /* call fn */
115
123
 
116
124
  ldp x3, x4, [x29, #16] /* reload rvalue and flags */
117
125
 
@@ -271,6 +279,9 @@ CNAME(ffi_closure_SYSV):
271
279
  bl CNAME(ffi_closure_SYSV_inner)
272
280
 
273
281
  /* Load the return value as directed. */
282
+ #if FFI_EXEC_TRAMPOLINE_TABLE && defined(__MACH__) && defined(HAVE_PTRAUTH)
283
+ autiza x1
284
+ #endif
274
285
  adr x1, 0f
275
286
  and w0, w0, #AARCH64_RET_MASK
276
287
  add x1, x1, x0, lsl #3
@@ -365,8 +376,8 @@ CNAME(ffi_closure_trampoline_table_page):
365
376
  .rept PAGE_MAX_SIZE / FFI_TRAMPOLINE_SIZE
366
377
  adr x16, -PAGE_MAX_SIZE
367
378
  ldp x17, x16, [x16]
368
- br x16
369
- nop /* each entry in the trampoline config page is 2*sizeof(void*) so the trampoline itself cannot be smaller that 16 bytes */
379
+ BR(x16)
380
+ nop /* each entry in the trampoline config page is 2*sizeof(void*) so the trampoline itself cannot be smaller than 16 bytes */
370
381
  .endr
371
382
 
372
383
  .globl CNAME(ffi_closure_trampoline_table_page)
@@ -42,7 +42,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
42
42
  EXPORT ffi_go_closure_SYSV
43
43
  #endif
44
44
 
45
- TEXTAREA, ALLIGN=8
45
+ TEXTAREA, ALIGN=8
46
46
 
47
47
  /* ffi_call_SYSV
48
48
  extern void ffi_call_SYSV (void *stack, void *frame,
@@ -55,6 +55,11 @@ extern unsigned int ffi_arm_trampoline[3] FFI_HIDDEN;
55
55
  #endif
56
56
  #endif
57
57
 
58
+ #if defined(__FreeBSD__) && defined(__arm__)
59
+ #include <sys/types.h>
60
+ #include <machine/sysarch.h>
61
+ #endif
62
+
58
63
  /* Forward declares. */
59
64
  static int vfp_type_p (const ffi_type *);
60
65
  static void layout_vfp_args (ffi_cif *);
@@ -421,12 +426,14 @@ ffi_call (ffi_cif *cif, void (*fn) (void), void *rvalue, void **avalue)
421
426
  ffi_call_int (cif, fn, rvalue, avalue, NULL);
422
427
  }
423
428
 
429
+ #ifdef FFI_GO_CLOSURES
424
430
  void
425
431
  ffi_call_go (ffi_cif *cif, void (*fn) (void), void *rvalue,
426
432
  void **avalue, void *closure)
427
433
  {
428
434
  ffi_call_int (cif, fn, rvalue, avalue, closure);
429
435
  }
436
+ #endif
430
437
 
431
438
  static void *
432
439
  ffi_prep_incoming_args_SYSV (ffi_cif *cif, void *rvalue,
@@ -564,11 +571,24 @@ ffi_closure_inner_VFP (ffi_cif *cif,
564
571
 
565
572
  void ffi_closure_SYSV (void) FFI_HIDDEN;
566
573
  void ffi_closure_VFP (void) FFI_HIDDEN;
574
+
575
+ #ifdef FFI_GO_CLOSURES
567
576
  void ffi_go_closure_SYSV (void) FFI_HIDDEN;
568
577
  void ffi_go_closure_VFP (void) FFI_HIDDEN;
578
+ #endif
569
579
 
570
580
  /* the cif must already be prep'ed */
571
581
 
582
+ #if defined(__FreeBSD__) && defined(__arm__)
583
+ #define __clear_cache(start, end) do { \
584
+ struct arm_sync_icache_args ua; \
585
+ \
586
+ ua.addr = (uintptr_t)(start); \
587
+ ua.len = (char *)(end) - (char *)start; \
588
+ sysarch(ARM_SYNC_ICACHE, &ua); \
589
+ } while (0);
590
+ #endif
591
+
572
592
  ffi_status
573
593
  ffi_prep_closure_loc (ffi_closure * closure,
574
594
  ffi_cif * cif,
@@ -622,6 +642,7 @@ ffi_prep_closure_loc (ffi_closure * closure,
622
642
  return FFI_OK;
623
643
  }
624
644
 
645
+ #ifdef FFI_GO_CLOSURES
625
646
  ffi_status
626
647
  ffi_prep_go_closure (ffi_go_closure *closure, ffi_cif *cif,
627
648
  void (*fun) (ffi_cif *, void *, void **, void *))
@@ -643,6 +664,7 @@ ffi_prep_go_closure (ffi_go_closure *closure, ffi_cif *cif,
643
664
 
644
665
  return FFI_OK;
645
666
  }
667
+ #endif
646
668
 
647
669
  /* Below are routines for VFP hard-float support. */
648
670
 
@@ -129,11 +129,11 @@ ARM_FUNC_START(ffi_call_VFP)
129
129
 
130
130
  cmp r3, #3 @ load only d0 if possible
131
131
  #ifdef __clang__
132
- vldrle d0, [sp]
133
- vldmgt sp, {d0-d7}
132
+ vldrle d0, [r0]
133
+ vldmgt r0, {d0-d7}
134
134
  #else
135
- ldcle p11, cr0, [r0] @ vldrle d0, [sp]
136
- ldcgt p11, cr0, [r0], {16} @ vldmgt sp, {d0-d7}
135
+ ldcle p11, cr0, [r0] @ vldrle d0, [r0]
136
+ ldcgt p11, cr0, [r0], {16} @ vldmgt r0, {d0-d7}
137
137
  #endif
138
138
  add r0, r0, #64 @ discard the vfp register args
139
139
  /* FALLTHRU */
@@ -1,5 +1,6 @@
1
1
  /* -----------------------------------------------------------------------
2
- closures.c - Copyright (c) 2007, 2009, 2010 Red Hat, Inc.
2
+ closures.c - Copyright (c) 2019 Anthony Green
3
+ Copyright (c) 2007, 2009, 2010 Red Hat, Inc.
3
4
  Copyright (C) 2007, 2009, 2010 Free Software Foundation, Inc
4
5
  Copyright (c) 2011 Plausible Labs Cooperative, Inc.
5
6
 
@@ -44,6 +45,9 @@
44
45
 
45
46
  #include <stddef.h>
46
47
  #include <unistd.h>
48
+ #ifdef HAVE_SYS_MEMFD_H
49
+ #include <sys/memfd.h>
50
+ #endif
47
51
 
48
52
  static const size_t overhead =
49
53
  (sizeof(max_align_t) > sizeof(void *) + sizeof(size_t)) ?
@@ -122,7 +126,7 @@ ffi_closure_free (void *ptr)
122
126
  # define FFI_MMAP_EXEC_WRIT 1
123
127
  # define HAVE_MNTENT 1
124
128
  # endif
125
- # if defined(X86_WIN32) || defined(X86_WIN64) || defined(_M_ARM64) || defined(__OS2__)
129
+ # if defined(_WIN32) || defined(__OS2__)
126
130
  /* Windows systems may have Data Execution Protection (DEP) enabled,
127
131
  which requires the use of VirtualMalloc/VirtualFree to alloc/free
128
132
  executable memory. */
@@ -147,6 +151,9 @@ ffi_closure_free (void *ptr)
147
151
 
148
152
  #include <mach/mach.h>
149
153
  #include <pthread.h>
154
+ #ifdef HAVE_PTRAUTH
155
+ #include <ptrauth.h>
156
+ #endif
150
157
  #include <stdio.h>
151
158
  #include <stdlib.h>
152
159
 
@@ -300,6 +307,9 @@ ffi_closure_alloc (size_t size, void **code)
300
307
 
301
308
  /* Initialize the return values */
302
309
  *code = entry->trampoline;
310
+ #ifdef HAVE_PTRAUTH
311
+ *code = ptrauth_sign_unauthenticated (*code, ptrauth_key_asia, 0);
312
+ #endif
303
313
  closure->trampoline_table = table;
304
314
  closure->trampoline_table_entry = entry;
305
315
 
@@ -385,7 +395,7 @@ ffi_closure_free (void *ptr)
385
395
  #endif
386
396
  #include <string.h>
387
397
  #include <stdio.h>
388
- #if !defined(X86_WIN32) && !defined(X86_WIN64) && !defined(_M_ARM64)
398
+ #if !defined(_WIN32)
389
399
  #ifdef HAVE_MNTENT
390
400
  #include <mntent.h>
391
401
  #endif /* HAVE_MNTENT */
@@ -511,11 +521,11 @@ static int dlmalloc_trim(size_t) MAYBE_UNUSED;
511
521
  static size_t dlmalloc_usable_size(void*) MAYBE_UNUSED;
512
522
  static void dlmalloc_stats(void) MAYBE_UNUSED;
513
523
 
514
- #if !(defined(X86_WIN32) || defined(X86_WIN64) || defined(_M_ARM64) || defined(__OS2__)) || defined (__CYGWIN__) || defined(__INTERIX)
524
+ #if !(defined(_WIN32) || defined(__OS2__)) || defined (__CYGWIN__) || defined(__INTERIX)
515
525
  /* Use these for mmap and munmap within dlmalloc.c. */
516
526
  static void *dlmmap(void *, size_t, int, int, int, off_t);
517
527
  static int dlmunmap(void *, size_t);
518
- #endif /* !(defined(X86_WIN32) || defined(X86_WIN64) || defined(__OS2__)) || defined (__CYGWIN__) || defined(__INTERIX) */
528
+ #endif /* !(defined(_WIN32) || defined(__OS2__)) || defined (__CYGWIN__) || defined(__INTERIX) */
519
529
 
520
530
  #define mmap dlmmap
521
531
  #define munmap dlmunmap
@@ -525,7 +535,7 @@ static int dlmunmap(void *, size_t);
525
535
  #undef mmap
526
536
  #undef munmap
527
537
 
528
- #if !(defined(X86_WIN32) || defined(X86_WIN64) || defined(_M_ARM64) || defined(__OS2__)) || defined (__CYGWIN__) || defined(__INTERIX)
538
+ #if !(defined(_WIN32) || defined(__OS2__)) || defined (__CYGWIN__) || defined(__INTERIX)
529
539
 
530
540
  /* A mutex used to synchronize access to *exec* variables in this file. */
531
541
  static pthread_mutex_t open_temp_exec_file_mutex = PTHREAD_MUTEX_INITIALIZER;
@@ -537,6 +547,17 @@ static int execfd = -1;
537
547
  /* The amount of space already allocated from the temporary file. */
538
548
  static size_t execsize = 0;
539
549
 
550
+ #ifdef HAVE_MEMFD_CREATE
551
+ /* Open a temporary file name, and immediately unlink it. */
552
+ static int
553
+ open_temp_exec_file_memfd (const char *name)
554
+ {
555
+ int fd;
556
+ fd = memfd_create (name, MFD_CLOEXEC);
557
+ return fd;
558
+ }
559
+ #endif
560
+
540
561
  /* Open a temporary file name, and immediately unlink it. */
541
562
  static int
542
563
  open_temp_exec_file_name (char *name, int flags)
@@ -664,6 +685,9 @@ static struct
664
685
  const char *arg;
665
686
  int repeat;
666
687
  } open_temp_exec_file_opts[] = {
688
+ #ifdef HAVE_MEMFD_CREATE
689
+ { open_temp_exec_file_memfd, "libffi", 0 },
690
+ #endif
667
691
  { open_temp_exec_file_env, "TMPDIR", 0 },
668
692
  { open_temp_exec_file_dir, "/tmp", 0 },
669
693
  { open_temp_exec_file_dir, "/var/tmp", 0 },
@@ -907,7 +931,7 @@ segment_holding_code (mstate m, char* addr)
907
931
  }
908
932
  #endif
909
933
 
910
- #endif /* !(defined(X86_WIN32) || defined(X86_WIN64) || defined(_M_ARM64) || defined(__OS2__)) || defined (__CYGWIN__) || defined(__INTERIX) */
934
+ #endif /* !(defined(_WIN32) || defined(__OS2__)) || defined (__CYGWIN__) || defined(__INTERIX) */
911
935
 
912
936
  /* Allocate a chunk of memory with the given size. Returns a pointer
913
937
  to the writable address, and sets *CODE to the executable
@@ -920,7 +944,7 @@ ffi_closure_alloc (size_t size, void **code)
920
944
  if (!code)
921
945
  return NULL;
922
946
 
923
- ptr = dlmalloc (size);
947
+ ptr = FFI_CLOSURE_PTR (dlmalloc (size));
924
948
 
925
949
  if (ptr)
926
950
  {
@@ -936,7 +960,14 @@ void *
936
960
  ffi_data_to_code_pointer (void *data)
937
961
  {
938
962
  msegmentptr seg = segment_holding (gm, data);
939
- return add_segment_exec_offset (data, seg);
963
+ /* We expect closures to be allocated with ffi_closure_alloc(), in
964
+ which case seg will be non-NULL. However, some users take on the
965
+ burden of managing this memory themselves, in which case this
966
+ we'll just return data. */
967
+ if (seg)
968
+ return add_segment_exec_offset (data, seg);
969
+ else
970
+ return data;
940
971
  }
941
972
 
942
973
  /* Release a chunk of memory allocated with ffi_closure_alloc. If
@@ -953,7 +984,7 @@ ffi_closure_free (void *ptr)
953
984
  ptr = sub_segment_exec_offset (ptr, seg);
954
985
  #endif
955
986
 
956
- dlfree (ptr);
987
+ dlfree (FFI_RESTORE_PTR (ptr));
957
988
  }
958
989
 
959
990
  # else /* ! FFI_MMAP_EXEC_WRIT */
@@ -969,13 +1000,13 @@ ffi_closure_alloc (size_t size, void **code)
969
1000
  if (!code)
970
1001
  return NULL;
971
1002
 
972
- return *code = malloc (size);
1003
+ return *code = FFI_CLOSURE_PTR (malloc (size));
973
1004
  }
974
1005
 
975
1006
  void
976
1007
  ffi_closure_free (void *ptr)
977
1008
  {
978
- free (ptr);
1009
+ free (FFI_RESTORE_PTR (ptr));
979
1010
  }
980
1011
 
981
1012
  void *