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
@@ -0,0 +1,624 @@
1
+ /* -----------------------------------------------------------------------
2
+ ffi.c - Copyright (c) 2022 Xu Chenghua <xuchenghua@loongson.cn>
3
+ 2022 Cheng Lulu <chenglulu@loongson.cn>
4
+ Based on RISC-V port
5
+
6
+ LoongArch Foreign Function Interface
7
+
8
+ Permission is hereby granted, free of charge, to any person obtaining
9
+ a copy of this software and associated documentation files (the
10
+ ``Software''), to deal in the Software without restriction, including
11
+ without limitation the rights to use, copy, modify, merge, publish,
12
+ distribute, sublicense, and/or sell copies of the Software, and to
13
+ permit persons to whom the Software is furnished to do so, subject to
14
+ the following conditions:
15
+
16
+ The above copyright notice and this permission notice shall be included
17
+ in all copies or substantial portions of the Software.
18
+
19
+ THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
20
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
23
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
24
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26
+ DEALINGS IN THE SOFTWARE.
27
+ ----------------------------------------------------------------------- */
28
+
29
+ #include <ffi.h>
30
+ #include <ffi_common.h>
31
+ #include <tramp.h>
32
+
33
+ #include <stdlib.h>
34
+ #include <stdint.h>
35
+
36
+ #if defined(__loongarch_soft_float)
37
+ # define ABI_FRLEN 0
38
+ #elif defined(__loongarch_single_float)
39
+ # define ABI_FRLEN 32
40
+ # define ABI_FLOAT float
41
+ #elif defined(__loongarch_double_float)
42
+ # define ABI_FRLEN 64
43
+ # define ABI_FLOAT double
44
+ #else
45
+ #error unsupported LoongArch floating-point ABI
46
+ #endif
47
+
48
+ #define NARGREG 8
49
+ #define STKALIGN 16
50
+ #define MAXCOPYARG (2 * sizeof (double))
51
+
52
+ /* call_context registers
53
+ - 8 floating point parameter/result registers.
54
+ - 8 integer parameter/result registers.
55
+ - 2 registers used by the assembly code to in-place construct its own
56
+ stack frame
57
+ - frame register
58
+ - return register
59
+ */
60
+ typedef struct call_context
61
+ {
62
+ #if !defined(__loongarch_soft_float)
63
+ ABI_FLOAT fa[8];
64
+ #endif
65
+ size_t a[10];
66
+ } call_context;
67
+
68
+ typedef struct call_builder
69
+ {
70
+ call_context *aregs;
71
+ int used_integer;
72
+ int used_float;
73
+ size_t *used_stack;
74
+ size_t *stack;
75
+ size_t next_struct_area;
76
+ } call_builder;
77
+
78
+ /* Integer (not pointer) less than ABI GRLEN. */
79
+ /* FFI_TYPE_INT does not appear to be used. */
80
+ #if __SIZEOF_POINTER__ == 8
81
+ # define IS_INT(type) ((type) >= FFI_TYPE_UINT8 && (type) <= FFI_TYPE_SINT64)
82
+ #else
83
+ # define IS_INT(type) ((type) >= FFI_TYPE_UINT8 && (type) <= FFI_TYPE_SINT32)
84
+ #endif
85
+
86
+ #if ABI_FRLEN
87
+ typedef struct float_struct_info
88
+ {
89
+ char as_elements;
90
+ char type1;
91
+ char offset2;
92
+ char type2;
93
+ } float_struct_info;
94
+
95
+ #if ABI_FRLEN >= 64
96
+ # define IS_FLOAT(type) ((type) >= FFI_TYPE_FLOAT && (type) <= FFI_TYPE_DOUBLE)
97
+ #else
98
+ # define IS_FLOAT(type) ((type) == FFI_TYPE_FLOAT)
99
+ #endif
100
+
101
+ static ffi_type **
102
+ flatten_struct (ffi_type *in, ffi_type **out, ffi_type **out_end)
103
+ {
104
+ int i;
105
+
106
+ if (out == out_end)
107
+ return out;
108
+ if (in->type != FFI_TYPE_STRUCT)
109
+ *(out++) = in;
110
+ else
111
+ for (i = 0; in->elements[i]; i++)
112
+ out = flatten_struct (in->elements[i], out, out_end);
113
+ return out;
114
+ }
115
+
116
+ /* Structs with at most two fields after flattening, one of which is of
117
+ floating point type, are passed in multiple registers if sufficient
118
+ registers are available. */
119
+ static float_struct_info
120
+ struct_passed_as_elements (call_builder *cb, ffi_type *top)
121
+ {
122
+ float_struct_info ret = {0, 0, 0, 0};
123
+ ffi_type *fields[3];
124
+ int num_floats, num_ints;
125
+ int num_fields = flatten_struct (top, fields, fields + 3) - fields;
126
+
127
+ if (num_fields == 1)
128
+ {
129
+ if (IS_FLOAT (fields[0]->type))
130
+ {
131
+ ret.as_elements = 1;
132
+ ret.type1 = fields[0]->type;
133
+ }
134
+ }
135
+ else if (num_fields == 2)
136
+ {
137
+ num_floats = IS_FLOAT (fields[0]->type) + IS_FLOAT (fields[1]->type);
138
+ num_ints = IS_INT (fields[0]->type) + IS_INT (fields[1]->type);
139
+ if (num_floats == 0 || num_floats + num_ints != 2)
140
+ return ret;
141
+ if (cb->used_float + num_floats > NARGREG
142
+ || cb->used_integer + (2 - num_floats) > NARGREG)
143
+ return ret;
144
+ if (!IS_FLOAT (fields[0]->type) && !IS_FLOAT (fields[1]->type))
145
+ return ret;
146
+
147
+ ret.type1 = fields[0]->type;
148
+ ret.type2 = fields[1]->type;
149
+ ret.offset2 = FFI_ALIGN (fields[0]->size, fields[1]->alignment);
150
+ ret.as_elements = 1;
151
+ }
152
+ return ret;
153
+ }
154
+ #endif
155
+
156
+ /* Allocates a single register, float register, or GRLEN-sized stack slot to a
157
+ datum. */
158
+ static void
159
+ marshal_atom (call_builder *cb, int type, void *data)
160
+ {
161
+ size_t value = 0;
162
+ switch (type)
163
+ {
164
+ case FFI_TYPE_UINT8:
165
+ value = *(uint8_t *) data;
166
+ break;
167
+ case FFI_TYPE_SINT8:
168
+ value = *(int8_t *) data;
169
+ break;
170
+ case FFI_TYPE_UINT16:
171
+ value = *(uint16_t *) data;
172
+ break;
173
+ case FFI_TYPE_SINT16:
174
+ value = *(int16_t *) data;
175
+ break;
176
+ /* 32-bit quantities are always sign-extended in the ABI. */
177
+ case FFI_TYPE_UINT32:
178
+ value = *(int32_t *) data;
179
+ break;
180
+ case FFI_TYPE_SINT32:
181
+ value = *(int32_t *) data;
182
+ break;
183
+ #if __SIZEOF_POINTER__ == 8
184
+ case FFI_TYPE_UINT64:
185
+ value = *(uint64_t *) data;
186
+ break;
187
+ case FFI_TYPE_SINT64:
188
+ value = *(int64_t *) data;
189
+ break;
190
+ #endif
191
+ case FFI_TYPE_POINTER:
192
+ value = *(size_t *) data;
193
+ break;
194
+
195
+ #if ABI_FRLEN >= 32
196
+ case FFI_TYPE_FLOAT:
197
+ *(float *)(cb->aregs->fa + cb->used_float++) = *(float *) data;
198
+ return;
199
+ #endif
200
+ #if ABI_FRLEN >= 64
201
+ case FFI_TYPE_DOUBLE:
202
+ (cb->aregs->fa[cb->used_float++]) = *(double *) data;
203
+ return;
204
+ #endif
205
+ default:
206
+ FFI_ASSERT (0);
207
+ break;
208
+ }
209
+
210
+ if (cb->used_integer == NARGREG)
211
+ *cb->used_stack++ = value;
212
+ else
213
+ cb->aregs->a[cb->used_integer++] = value;
214
+ }
215
+
216
+ static void
217
+ unmarshal_atom (call_builder *cb, int type, void *data)
218
+ {
219
+ size_t value;
220
+ switch (type)
221
+ {
222
+ #if ABI_FRLEN >= 32
223
+ case FFI_TYPE_FLOAT:
224
+ *(float *) data = *(float *)(cb->aregs->fa + cb->used_float++);
225
+ return;
226
+ #endif
227
+ #if ABI_FRLEN >= 64
228
+ case FFI_TYPE_DOUBLE:
229
+ *(double *) data = cb->aregs->fa[cb->used_float++];
230
+ return;
231
+ #endif
232
+ }
233
+
234
+ if (cb->used_integer == NARGREG)
235
+ value = *cb->used_stack++;
236
+ else
237
+ value = cb->aregs->a[cb->used_integer++];
238
+
239
+ switch (type)
240
+ {
241
+ case FFI_TYPE_UINT8:
242
+ case FFI_TYPE_SINT8:
243
+ case FFI_TYPE_UINT16:
244
+ case FFI_TYPE_SINT16:
245
+ case FFI_TYPE_UINT32:
246
+ case FFI_TYPE_SINT32:
247
+ #if __SIZEOF_POINTER__ == 8
248
+ case FFI_TYPE_UINT64:
249
+ case FFI_TYPE_SINT64:
250
+ #endif
251
+ case FFI_TYPE_POINTER:
252
+ *(ffi_arg *)data = value;
253
+ break;
254
+ default:
255
+ FFI_ASSERT (0);
256
+ break;
257
+ }
258
+ }
259
+
260
+ /* Allocate and copy a structure that is passed by value on the stack and
261
+ return a pointer to it. */
262
+ static void *
263
+ allocate_and_copy_struct_to_stack (call_builder *cb, void *data,
264
+ ffi_type *type)
265
+ {
266
+ size_t dest = cb->next_struct_area - type->size;
267
+
268
+ dest = FFI_ALIGN_DOWN (dest, type->alignment);
269
+ cb->next_struct_area = dest;
270
+
271
+ return memcpy ((char *)cb->stack + dest, data, type->size);
272
+ }
273
+
274
+ /* Adds an argument to a call, or a not by reference return value. */
275
+ static void
276
+ marshal (call_builder *cb, ffi_type *type, int var, void *data)
277
+ {
278
+ size_t realign[2];
279
+
280
+ #if ABI_FRLEN
281
+ if (!var && type->type == FFI_TYPE_STRUCT)
282
+ {
283
+ float_struct_info fsi = struct_passed_as_elements (cb, type);
284
+ if (fsi.as_elements)
285
+ {
286
+ marshal_atom (cb, fsi.type1, data);
287
+ if (fsi.offset2)
288
+ marshal_atom (cb, fsi.type2, ((char *) data) + fsi.offset2);
289
+ return;
290
+ }
291
+ }
292
+
293
+ if (!var && cb->used_float < NARGREG
294
+ && IS_FLOAT (type->type))
295
+ {
296
+ marshal_atom (cb, type->type, data);
297
+ return;
298
+ }
299
+
300
+ double promoted;
301
+ if (var && type->type == FFI_TYPE_FLOAT)
302
+ {
303
+ /* C standard requires promoting float -> double for variable arg. */
304
+ promoted = *(float *) data;
305
+ type = &ffi_type_double;
306
+ data = &promoted;
307
+ }
308
+ #endif
309
+
310
+ if (type->size > 2 * __SIZEOF_POINTER__)
311
+ /* Pass by reference. */
312
+ {
313
+ allocate_and_copy_struct_to_stack (cb, data, type);
314
+ data = (char *)cb->stack + cb->next_struct_area;
315
+ marshal_atom (cb, FFI_TYPE_POINTER, &data);
316
+ }
317
+ else if (IS_INT (type->type) || type->type == FFI_TYPE_POINTER)
318
+ marshal_atom (cb, type->type, data);
319
+ else
320
+ {
321
+ /* Overlong integers, soft-float floats, and structs without special
322
+ float handling are treated identically from this point on. */
323
+
324
+ /* Variadics are aligned even in registers. */
325
+ if (type->alignment > __SIZEOF_POINTER__)
326
+ {
327
+ if (var)
328
+ cb->used_integer = FFI_ALIGN (cb->used_integer, 2);
329
+ cb->used_stack
330
+ = (size_t *) FFI_ALIGN (cb->used_stack, 2 * __SIZEOF_POINTER__);
331
+ }
332
+
333
+ memcpy (realign, data, type->size);
334
+ if (type->size > 0)
335
+ marshal_atom (cb, FFI_TYPE_POINTER, realign);
336
+ if (type->size > __SIZEOF_POINTER__)
337
+ marshal_atom (cb, FFI_TYPE_POINTER, realign + 1);
338
+ }
339
+ }
340
+
341
+ /* For arguments passed by reference returns the pointer, otherwise the arg
342
+ is copied (up to MAXCOPYARG bytes). */
343
+ static void *
344
+ unmarshal (call_builder *cb, ffi_type *type, int var, void *data)
345
+ {
346
+ size_t realign[2];
347
+ void *pointer;
348
+
349
+ #if ABI_FRLEN
350
+ if (!var && type->type == FFI_TYPE_STRUCT)
351
+ {
352
+ float_struct_info fsi = struct_passed_as_elements (cb, type);
353
+ if (fsi.as_elements)
354
+ {
355
+ unmarshal_atom (cb, fsi.type1, data);
356
+ if (fsi.offset2)
357
+ unmarshal_atom (cb, fsi.type2, ((char *) data) + fsi.offset2);
358
+ return data;
359
+ }
360
+ }
361
+
362
+ if (!var && cb->used_float < NARGREG
363
+ && IS_FLOAT (type->type))
364
+ {
365
+ unmarshal_atom (cb, type->type, data);
366
+ return data;
367
+ }
368
+
369
+ if (var && type->type == FFI_TYPE_FLOAT)
370
+ {
371
+ int m = cb->used_integer;
372
+ void *promoted
373
+ = m < NARGREG ? cb->aregs->a + m : cb->used_stack + m - NARGREG + 1;
374
+ *(float *) promoted = *(double *) promoted;
375
+ }
376
+ #endif
377
+
378
+ if (type->size > 2 * __SIZEOF_POINTER__)
379
+ {
380
+ /* Pass by reference. */
381
+ unmarshal_atom (cb, FFI_TYPE_POINTER, (char *) &pointer);
382
+ return pointer;
383
+ }
384
+ else if (IS_INT (type->type) || type->type == FFI_TYPE_POINTER)
385
+ {
386
+ unmarshal_atom (cb, type->type, data);
387
+ return data;
388
+ }
389
+ else
390
+ {
391
+ /* Overlong integers, soft-float floats, and structs without special
392
+ float handling are treated identically from this point on. */
393
+
394
+ /* Variadics are aligned even in registers. */
395
+ if (type->alignment > __SIZEOF_POINTER__)
396
+ {
397
+ if (var)
398
+ cb->used_integer = FFI_ALIGN (cb->used_integer, 2);
399
+ cb->used_stack
400
+ = (size_t *) FFI_ALIGN (cb->used_stack, 2 * __SIZEOF_POINTER__);
401
+ }
402
+
403
+ if (type->size > 0)
404
+ unmarshal_atom (cb, FFI_TYPE_POINTER, realign);
405
+ if (type->size > __SIZEOF_POINTER__)
406
+ unmarshal_atom (cb, FFI_TYPE_POINTER, realign + 1);
407
+ memcpy (data, realign, type->size);
408
+ return data;
409
+ }
410
+ }
411
+
412
+ static int
413
+ passed_by_ref (call_builder *cb, ffi_type *type, int var)
414
+ {
415
+ #if ABI_FRLEN
416
+ if (!var && type->type == FFI_TYPE_STRUCT)
417
+ {
418
+ float_struct_info fsi = struct_passed_as_elements (cb, type);
419
+ if (fsi.as_elements)
420
+ return 0;
421
+ }
422
+ #endif
423
+
424
+ return type->size > 2 * __SIZEOF_POINTER__;
425
+ }
426
+
427
+ /* Perform machine dependent cif processing. */
428
+ ffi_status
429
+ ffi_prep_cif_machdep (ffi_cif *cif)
430
+ {
431
+ cif->loongarch_nfixedargs = cif->nargs;
432
+ return FFI_OK;
433
+ }
434
+
435
+ /* Perform machine dependent cif processing when we have a variadic
436
+ function. */
437
+ ffi_status
438
+ ffi_prep_cif_machdep_var (ffi_cif *cif, unsigned int nfixedargs,
439
+ unsigned int ntotalargs)
440
+ {
441
+ cif->loongarch_nfixedargs = nfixedargs;
442
+ return FFI_OK;
443
+ }
444
+
445
+ /* Low level routine for calling functions. */
446
+ extern void ffi_call_asm (void *stack, struct call_context *regs,
447
+ void (*fn) (void), void *closure) FFI_HIDDEN;
448
+
449
+ static void
450
+ ffi_call_int (ffi_cif *cif, void (*fn) (void), void *rvalue, void **avalue,
451
+ void *closure)
452
+ {
453
+ /* This is a conservative estimate, assuming a complex return value and
454
+ that all remaining arguments are long long / __int128 */
455
+ size_t arg_bytes = cif->bytes;
456
+ size_t rval_bytes = 0;
457
+ if (rvalue == NULL && cif->rtype->size > 2 * __SIZEOF_POINTER__)
458
+ rval_bytes = FFI_ALIGN (cif->rtype->size, STKALIGN);
459
+ size_t alloc_size = arg_bytes + rval_bytes + sizeof (call_context);
460
+
461
+ /* The assembly code will deallocate all stack data at lower addresses
462
+ than the argument region, so we need to allocate the frame and the
463
+ return value after the arguments in a single allocation. */
464
+ size_t alloc_base;
465
+ /* Argument region must be 16-byte aligned in LP64 ABIs. */
466
+ if (_Alignof(max_align_t) >= STKALIGN)
467
+ /* Since sizeof long double is normally 16, the compiler will
468
+ guarantee alloca alignment to at least that much. */
469
+ alloc_base = (size_t) alloca (alloc_size);
470
+ else
471
+ alloc_base = FFI_ALIGN (alloca (alloc_size + STKALIGN - 1), STKALIGN);
472
+
473
+ if (rval_bytes)
474
+ rvalue = (void *) (alloc_base + arg_bytes);
475
+
476
+ call_builder cb;
477
+ cb.used_float = cb.used_integer = 0;
478
+ cb.aregs = (call_context *) (alloc_base + arg_bytes + rval_bytes);
479
+ cb.used_stack = (void *) alloc_base;
480
+ cb.stack = (void *) alloc_base;
481
+ cb.next_struct_area = arg_bytes;
482
+
483
+ int return_by_ref = passed_by_ref (&cb, cif->rtype, 0);
484
+ if (return_by_ref)
485
+ cb.aregs->a[cb.used_integer++] = (size_t)rvalue;
486
+
487
+ int i;
488
+ for (i = 0; i < cif->nargs; i++)
489
+ marshal (&cb, cif->arg_types[i], i >= cif->loongarch_nfixedargs,
490
+ avalue[i]);
491
+
492
+ ffi_call_asm ((void *) alloc_base, cb.aregs, fn, closure);
493
+
494
+ cb.used_float = cb.used_integer = 0;
495
+ if (!return_by_ref && rvalue)
496
+ unmarshal (&cb, cif->rtype, 0, rvalue);
497
+ }
498
+
499
+ void
500
+ ffi_call (ffi_cif *cif, void (*fn) (void), void *rvalue, void **avalue)
501
+ {
502
+ ffi_call_int (cif, fn, rvalue, avalue, NULL);
503
+ }
504
+
505
+ void
506
+ ffi_call_go (ffi_cif *cif, void (*fn) (void), void *rvalue, void **avalue,
507
+ void *closure)
508
+ {
509
+ ffi_call_int (cif, fn, rvalue, avalue, closure);
510
+ }
511
+
512
+ extern void ffi_closure_asm (void) FFI_HIDDEN;
513
+
514
+ ffi_status
515
+ ffi_prep_closure_loc (ffi_closure *closure, ffi_cif *cif,
516
+ void (*fun) (ffi_cif *, void *, void **, void *),
517
+ void *user_data, void *codeloc)
518
+ {
519
+ uint32_t *tramp = (uint32_t *) &closure->tramp[0];
520
+ uint64_t fn = (uint64_t) (uintptr_t) ffi_closure_asm;
521
+
522
+ if (cif->abi <= FFI_FIRST_ABI || cif->abi >= FFI_LAST_ABI)
523
+ return FFI_BAD_ABI;
524
+
525
+ #if defined(FFI_EXEC_STATIC_TRAMP)
526
+ if (ffi_tramp_is_present(closure))
527
+ {
528
+ ffi_tramp_set_parms (closure->ftramp, ffi_closure_asm, closure);
529
+ goto out;
530
+ }
531
+ #endif
532
+
533
+ /* Fill the dynamic trampoline. We will call ffi_closure_inner with codeloc,
534
+ not closure, but as long as the memory is readable it should work. */
535
+ tramp[0] = 0x1800000c; /* pcaddi $t0, 0 (i.e. $t0 <- tramp) */
536
+ tramp[1] = 0x28c0418d; /* ld.d $t1, $t0, 16 */
537
+ tramp[2] = 0x4c0001a0; /* jirl $zero, $t1, 0 */
538
+ tramp[3] = 0x03400000; /* nop */
539
+ tramp[4] = fn;
540
+ tramp[5] = fn >> 32;
541
+
542
+ __builtin___clear_cache (codeloc, codeloc + FFI_TRAMPOLINE_SIZE);
543
+
544
+ #if defined(FFI_EXEC_STATIC_TRAMP)
545
+ out:
546
+ #endif
547
+ closure->cif = cif;
548
+ closure->fun = fun;
549
+ closure->user_data = user_data;
550
+
551
+ return FFI_OK;
552
+ }
553
+
554
+ extern void ffi_go_closure_asm (void) FFI_HIDDEN;
555
+
556
+ ffi_status
557
+ ffi_prep_go_closure (ffi_go_closure *closure, ffi_cif *cif,
558
+ void (*fun) (ffi_cif *, void *, void **, void *))
559
+ {
560
+ if (cif->abi <= FFI_FIRST_ABI || cif->abi >= FFI_LAST_ABI)
561
+ return FFI_BAD_ABI;
562
+
563
+ closure->tramp = (void *) ffi_go_closure_asm;
564
+ closure->cif = cif;
565
+ closure->fun = fun;
566
+ return FFI_OK;
567
+ }
568
+
569
+ /* Called by the assembly code with aregs pointing to saved argument registers
570
+ and stack pointing to the stacked arguments. Return values passed in
571
+ registers will be reloaded from aregs. */
572
+ void FFI_HIDDEN
573
+ ffi_closure_inner (ffi_cif *cif,
574
+ void (*fun) (ffi_cif *, void *, void **, void *),
575
+ void *user_data, size_t *stack, call_context *aregs)
576
+ {
577
+ void **avalue = alloca (cif->nargs * sizeof (void *));
578
+ /* Storage for arguments which will be copied by unmarshal(). We could
579
+ theoretically avoid the copies in many cases and use at most 128 bytes
580
+ of memory, but allocating disjoint storage for each argument is
581
+ simpler. */
582
+ char *astorage = alloca (cif->nargs * MAXCOPYARG);
583
+ void *rvalue;
584
+ call_builder cb;
585
+ int return_by_ref;
586
+ int i;
587
+
588
+ cb.aregs = aregs;
589
+ cb.used_integer = cb.used_float = 0;
590
+ cb.used_stack = stack;
591
+
592
+ return_by_ref = passed_by_ref (&cb, cif->rtype, 0);
593
+ if (return_by_ref)
594
+ unmarshal (&cb, &ffi_type_pointer, 0, &rvalue);
595
+ else
596
+ rvalue = alloca (cif->rtype->size);
597
+
598
+ for (i = 0; i < cif->nargs; i++)
599
+ avalue[i]
600
+ = unmarshal (&cb, cif->arg_types[i], i >= cif->loongarch_nfixedargs,
601
+ astorage + i * MAXCOPYARG);
602
+
603
+ fun (cif, rvalue, avalue, user_data);
604
+
605
+ if (!return_by_ref && cif->rtype->type != FFI_TYPE_VOID)
606
+ {
607
+ cb.used_integer = cb.used_float = 0;
608
+ marshal (&cb, cif->rtype, 0, rvalue);
609
+ }
610
+ }
611
+
612
+ #if defined(FFI_EXEC_STATIC_TRAMP)
613
+ void *
614
+ ffi_tramp_arch (size_t *tramp_size, size_t *map_size)
615
+ {
616
+ extern void *trampoline_code_table;
617
+
618
+ *tramp_size = 16;
619
+ /* A mapping size of 64K is chosen to cover the page sizes of 4K, 16K, and
620
+ 64K. */
621
+ *map_size = 1 << 16;
622
+ return &trampoline_code_table;
623
+ }
624
+ #endif
@@ -0,0 +1,82 @@
1
+ /* -----------------------------------------------------------------*-C-*-
2
+ ffitarget.h - Copyright (c) 2022 Xu Chenghua <xuchenghua@loongson.cn>
3
+ 2022 Cheng Lulu <chenglulu@loongson.cn>
4
+
5
+ Target configuration macros for LoongArch.
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining
8
+ a copy of this software and associated documentation files (the
9
+ ``Software''), to deal in the Software without restriction, including
10
+ without limitation the rights to use, copy, modify, merge, publish,
11
+ distribute, sublicense, and/or sell copies of the Software, and to
12
+ permit persons to whom the Software is furnished to do so, subject to
13
+ the following conditions:
14
+
15
+ The above copyright notice and this permission notice shall be included
16
+ in all copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
19
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25
+ DEALINGS IN THE SOFTWARE.
26
+
27
+ ----------------------------------------------------------------------- */
28
+
29
+ #ifndef LIBFFI_TARGET_H
30
+ #define LIBFFI_TARGET_H
31
+
32
+ #ifndef LIBFFI_H
33
+ #error \
34
+ "Please do not include ffitarget.h directly into your source. Use ffi.h instead."
35
+ #endif
36
+
37
+ #ifndef __loongarch__
38
+ #error \
39
+ "libffi was configured for a LoongArch target but this does not appear to be a LoongArch compiler."
40
+ #endif
41
+
42
+ #ifndef LIBFFI_ASM
43
+
44
+ typedef unsigned long ffi_arg;
45
+ typedef signed long ffi_sarg;
46
+
47
+ typedef enum ffi_abi
48
+ {
49
+ FFI_FIRST_ABI = 0,
50
+ FFI_LP64S,
51
+ FFI_LP64F,
52
+ FFI_LP64D,
53
+ FFI_LAST_ABI,
54
+
55
+ #if defined(__loongarch64)
56
+ #if defined(__loongarch_soft_float)
57
+ FFI_DEFAULT_ABI = FFI_LP64S
58
+ #elif defined(__loongarch_single_float)
59
+ FFI_DEFAULT_ABI = FFI_LP64F
60
+ #elif defined(__loongarch_double_float)
61
+ FFI_DEFAULT_ABI = FFI_LP64D
62
+ #else
63
+ #error unsupported LoongArch floating-point ABI
64
+ #endif
65
+ #else
66
+ #error unsupported LoongArch base architecture
67
+ #endif
68
+ } ffi_abi;
69
+
70
+ #endif /* LIBFFI_ASM */
71
+
72
+ /* ---- Definitions for closures ----------------------------------------- */
73
+
74
+ #define FFI_CLOSURES 1
75
+ #define FFI_GO_CLOSURES 1
76
+ #define FFI_TRAMPOLINE_SIZE 24
77
+ #define FFI_NATIVE_RAW_API 0
78
+ #define FFI_EXTRA_CIF_FIELDS \
79
+ unsigned loongarch_nfixedargs; \
80
+ unsigned loongarch_unused;
81
+ #define FFI_TARGET_SPECIFIC_VARIADIC
82
+ #endif