ffi 1.0.0 → 1.17.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (694) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +4 -0
  3. data/CHANGELOG.md +465 -0
  4. data/COPYING +49 -0
  5. data/Gemfile +21 -0
  6. data/LICENSE +21 -11
  7. data/LICENSE.SPECS +22 -0
  8. data/README.md +137 -0
  9. data/Rakefile +165 -148
  10. data/ext/ffi_c/AbstractMemory.c +716 -97
  11. data/ext/ffi_c/AbstractMemory.h +38 -17
  12. data/ext/ffi_c/ArrayType.c +102 -33
  13. data/ext/ffi_c/ArrayType.h +20 -18
  14. data/ext/ffi_c/Buffer.c +229 -54
  15. data/ext/ffi_c/Call.c +211 -100
  16. data/ext/ffi_c/Call.h +46 -28
  17. data/ext/ffi_c/ClosurePool.c +110 -81
  18. data/ext/ffi_c/ClosurePool.h +31 -1
  19. data/ext/ffi_c/DynamicLibrary.c +216 -54
  20. data/ext/ffi_c/DynamicLibrary.h +76 -0
  21. data/ext/ffi_c/Function.c +527 -164
  22. data/ext/ffi_c/Function.h +24 -20
  23. data/ext/ffi_c/FunctionInfo.c +151 -50
  24. data/ext/ffi_c/LastError.c +112 -28
  25. data/ext/ffi_c/LastError.h +29 -0
  26. data/ext/ffi_c/LongDouble.c +65 -0
  27. data/ext/ffi_c/LongDouble.h +47 -0
  28. data/ext/ffi_c/MappedType.c +107 -42
  29. data/ext/ffi_c/MappedType.h +20 -20
  30. data/ext/ffi_c/MemoryPointer.c +108 -46
  31. data/ext/ffi_c/MemoryPointer.h +33 -4
  32. data/ext/ffi_c/MethodHandle.c +71 -67
  33. data/ext/ffi_c/MethodHandle.h +26 -23
  34. data/ext/ffi_c/Platform.c +42 -25
  35. data/ext/ffi_c/Platform.h +32 -3
  36. data/ext/ffi_c/Pointer.c +324 -51
  37. data/ext/ffi_c/Pointer.h +29 -18
  38. data/ext/ffi_c/Struct.c +434 -161
  39. data/ext/ffi_c/Struct.h +47 -27
  40. data/ext/ffi_c/StructByValue.c +74 -37
  41. data/ext/ffi_c/StructByValue.h +20 -18
  42. data/ext/ffi_c/StructLayout.c +358 -87
  43. data/ext/ffi_c/Thread.c +129 -0
  44. data/ext/ffi_c/Thread.h +76 -0
  45. data/ext/ffi_c/Type.c +241 -76
  46. data/ext/ffi_c/Type.h +27 -11
  47. data/ext/ffi_c/Types.c +54 -34
  48. data/ext/ffi_c/Types.h +24 -24
  49. data/ext/ffi_c/Variadic.c +151 -55
  50. data/ext/ffi_c/compat.h +48 -38
  51. data/ext/ffi_c/extconf.rb +106 -34
  52. data/ext/ffi_c/ffi.c +35 -26
  53. data/ext/ffi_c/libffi/.allow-ai-service +0 -0
  54. data/ext/ffi_c/libffi/.appveyor/site.exp +16 -0
  55. data/ext/ffi_c/libffi/.appveyor/unix-noexec.exp +7 -0
  56. data/ext/ffi_c/libffi/.appveyor.yml +84 -0
  57. data/ext/ffi_c/libffi/.ci/ar-lib +270 -0
  58. data/ext/ffi_c/libffi/.ci/bfin-sim.exp +58 -0
  59. data/ext/ffi_c/libffi/.ci/build-cross-in-container.sh +18 -0
  60. data/ext/ffi_c/libffi/.ci/build-in-container.sh +10 -0
  61. data/ext/ffi_c/libffi/.ci/build.sh +124 -0
  62. data/ext/ffi_c/libffi/.ci/compile +351 -0
  63. data/ext/ffi_c/libffi/.ci/install.sh +78 -0
  64. data/ext/ffi_c/libffi/.ci/m32r-sim.exp +58 -0
  65. data/ext/ffi_c/libffi/.ci/moxie-sim.exp +60 -0
  66. data/ext/ffi_c/libffi/.ci/msvs-detect +1103 -0
  67. data/ext/ffi_c/libffi/.ci/or1k-sim.exp +58 -0
  68. data/ext/ffi_c/libffi/.ci/powerpc-eabisim.exp +58 -0
  69. data/ext/ffi_c/libffi/.ci/site.exp +29 -0
  70. data/ext/ffi_c/libffi/.ci/wine-sim.exp +55 -0
  71. data/ext/ffi_c/libffi/.circleci/config.yml +156 -0
  72. data/ext/ffi_c/libffi/.gitattributes +4 -0
  73. data/ext/ffi_c/libffi/.github/issue_template.md +10 -0
  74. data/ext/ffi_c/libffi/.github/workflows/build.yml +479 -0
  75. data/ext/ffi_c/libffi/.github/workflows/emscripten.yml +172 -0
  76. data/ext/ffi_c/libffi/.gitignore +46 -0
  77. data/ext/ffi_c/libffi/{ChangeLog → ChangeLog.old} +6528 -3180
  78. data/ext/ffi_c/libffi/LICENSE +3 -3
  79. data/ext/ffi_c/libffi/LICENSE-BUILDTOOLS +353 -0
  80. data/ext/ffi_c/libffi/Makefile.am +132 -162
  81. data/ext/ffi_c/libffi/Makefile.in +1339 -1003
  82. data/ext/ffi_c/libffi/README.md +531 -0
  83. data/ext/ffi_c/libffi/acinclude.m4 +289 -4
  84. data/ext/ffi_c/libffi/autogen.sh +2 -0
  85. data/ext/ffi_c/libffi/compile +227 -21
  86. data/ext/ffi_c/libffi/config.guess +1034 -778
  87. data/ext/ffi_c/libffi/config.sub +1394 -1204
  88. data/ext/ffi_c/libffi/configure +14327 -8503
  89. data/ext/ffi_c/libffi/configure.ac +294 -247
  90. data/ext/ffi_c/libffi/configure.host +330 -4
  91. data/ext/ffi_c/libffi/doc/Makefile.am +3 -0
  92. data/ext/ffi_c/libffi/doc/Makefile.in +818 -0
  93. data/ext/ffi_c/libffi/doc/libffi.texi +572 -67
  94. data/ext/ffi_c/libffi/doc/version.texi +4 -4
  95. data/ext/ffi_c/libffi/fficonfig.h.in +53 -46
  96. data/ext/ffi_c/libffi/generate-darwin-source-and-headers.py +312 -0
  97. data/ext/ffi_c/libffi/include/Makefile.am +3 -3
  98. data/ext/ffi_c/libffi/include/Makefile.in +219 -79
  99. data/ext/ffi_c/libffi/include/ffi.h.in +230 -111
  100. data/ext/ffi_c/libffi/include/ffi_cfi.h +76 -0
  101. data/ext/ffi_c/libffi/include/ffi_common.h +78 -16
  102. data/ext/ffi_c/libffi/include/tramp.h +45 -0
  103. data/ext/ffi_c/libffi/install-sh +402 -184
  104. data/ext/ffi_c/libffi/libffi.map.in +81 -0
  105. data/ext/ffi_c/libffi/libffi.pc.in +3 -2
  106. data/ext/ffi_c/libffi/libffi.xcodeproj/project.pbxproj +997 -0
  107. data/ext/ffi_c/libffi/libtool-ldflags +106 -0
  108. data/ext/ffi_c/libffi/libtool-version +2 -2
  109. data/ext/ffi_c/libffi/ltmain.sh +5752 -2722
  110. data/ext/ffi_c/libffi/m4/asmcfi.m4 +13 -0
  111. data/ext/ffi_c/libffi/m4/ax_append_flag.m4 +50 -0
  112. data/ext/ffi_c/libffi/m4/ax_cc_maxopt.m4 +198 -0
  113. data/ext/ffi_c/libffi/m4/ax_cflags_warn_all.m4 +158 -0
  114. data/ext/ffi_c/libffi/m4/ax_check_compile_flag.m4 +53 -0
  115. data/ext/ffi_c/libffi/m4/ax_compiler_vendor.m4 +119 -0
  116. data/ext/ffi_c/libffi/m4/ax_configure_args.m4 +49 -0
  117. data/ext/ffi_c/libffi/m4/ax_enable_builddir.m4 +302 -0
  118. data/ext/ffi_c/libffi/m4/ax_gcc_archflag.m4 +267 -0
  119. data/ext/ffi_c/libffi/m4/ax_gcc_x86_cpuid.m4 +89 -0
  120. data/ext/ffi_c/libffi/m4/ax_prepend_flag.m4 +51 -0
  121. data/ext/ffi_c/libffi/m4/ax_require_defined.m4 +37 -0
  122. data/ext/ffi_c/libffi/make_sunver.pl +333 -0
  123. data/ext/ffi_c/libffi/man/Makefile.am +2 -2
  124. data/ext/ffi_c/libffi/man/Makefile.in +174 -57
  125. data/ext/ffi_c/libffi/man/ffi.3 +10 -0
  126. data/ext/ffi_c/libffi/man/ffi_prep_cif.3 +6 -4
  127. data/ext/ffi_c/libffi/man/ffi_prep_cif_var.3 +73 -0
  128. data/ext/ffi_c/libffi/missing +155 -300
  129. data/ext/ffi_c/libffi/msvc_build/aarch64/Ffi_staticLib.sln +33 -0
  130. data/ext/ffi_c/libffi/msvc_build/aarch64/Ffi_staticLib.vcxproj +130 -0
  131. data/ext/ffi_c/libffi/msvc_build/aarch64/Ffi_staticLib.vcxproj.filters +57 -0
  132. data/ext/ffi_c/libffi/msvc_build/aarch64/Ffi_staticLib.vcxproj.user +4 -0
  133. data/ext/ffi_c/libffi/msvc_build/aarch64/aarch64_include/ffi.h +511 -0
  134. data/ext/ffi_c/libffi/msvc_build/aarch64/aarch64_include/fficonfig.h +219 -0
  135. data/ext/ffi_c/libffi/msvcc.sh +353 -0
  136. data/ext/ffi_c/libffi/src/aarch64/ffi.c +1142 -0
  137. data/ext/ffi_c/libffi/src/aarch64/ffitarget.h +97 -0
  138. data/ext/ffi_c/libffi/src/aarch64/internal.h +100 -0
  139. data/ext/ffi_c/libffi/src/aarch64/sysv.S +695 -0
  140. data/ext/ffi_c/libffi/src/aarch64/win64_armasm.S +506 -0
  141. data/ext/ffi_c/libffi/src/alpha/ffi.c +335 -98
  142. data/ext/ffi_c/libffi/src/alpha/ffitarget.h +10 -1
  143. data/ext/ffi_c/libffi/src/alpha/internal.h +23 -0
  144. data/ext/ffi_c/libffi/src/alpha/osf.S +162 -246
  145. data/ext/ffi_c/libffi/src/arc/arcompact.S +210 -0
  146. data/ext/ffi_c/libffi/src/arc/ffi.c +443 -0
  147. data/ext/ffi_c/libffi/src/arc/ffitarget.h +67 -0
  148. data/ext/ffi_c/libffi/src/arm/ffi.c +806 -194
  149. data/ext/ffi_c/libffi/src/arm/ffitarget.h +43 -3
  150. data/ext/ffi_c/libffi/src/arm/internal.h +17 -0
  151. data/ext/ffi_c/libffi/src/arm/sysv.S +381 -231
  152. data/ext/ffi_c/libffi/src/arm/sysv_msvc_arm32.S +311 -0
  153. data/ext/ffi_c/libffi/src/avr32/ffi.c +4 -2
  154. data/ext/ffi_c/libffi/src/avr32/ffitarget.h +8 -3
  155. data/ext/ffi_c/libffi/src/bfin/ffi.c +196 -0
  156. data/ext/ffi_c/libffi/src/bfin/ffitarget.h +43 -0
  157. data/ext/ffi_c/libffi/src/bfin/sysv.S +179 -0
  158. data/ext/ffi_c/libffi/src/closures.c +574 -100
  159. data/ext/ffi_c/libffi/src/cris/ffi.c +11 -8
  160. data/ext/ffi_c/libffi/src/cris/ffitarget.h +8 -3
  161. data/ext/ffi_c/libffi/src/csky/ffi.c +395 -0
  162. data/ext/ffi_c/libffi/src/csky/ffitarget.h +63 -0
  163. data/ext/ffi_c/libffi/src/csky/sysv.S +371 -0
  164. data/ext/ffi_c/libffi/src/debug.c +8 -3
  165. data/ext/ffi_c/libffi/src/dlmalloc.c +89 -17
  166. data/ext/ffi_c/libffi/src/frv/ffi.c +2 -2
  167. data/ext/ffi_c/libffi/src/frv/ffitarget.h +8 -7
  168. data/ext/ffi_c/libffi/src/ia64/ffi.c +48 -12
  169. data/ext/ffi_c/libffi/src/ia64/ffitarget.h +10 -4
  170. data/ext/ffi_c/libffi/src/ia64/unix.S +28 -3
  171. data/ext/ffi_c/libffi/src/java_raw_api.c +24 -6
  172. data/ext/ffi_c/libffi/src/kvx/asm.h +5 -0
  173. data/ext/ffi_c/libffi/src/kvx/ffi.c +273 -0
  174. data/ext/ffi_c/libffi/src/kvx/ffitarget.h +75 -0
  175. data/ext/ffi_c/libffi/src/kvx/sysv.S +127 -0
  176. data/ext/ffi_c/libffi/src/loongarch64/ffi.c +624 -0
  177. data/ext/ffi_c/libffi/src/loongarch64/ffitarget.h +82 -0
  178. data/ext/ffi_c/libffi/src/loongarch64/sysv.S +327 -0
  179. data/ext/ffi_c/libffi/src/m32r/ffi.c +32 -15
  180. data/ext/ffi_c/libffi/src/m32r/ffitarget.h +8 -3
  181. data/ext/ffi_c/libffi/src/m68k/ffi.c +97 -13
  182. data/ext/ffi_c/libffi/src/m68k/ffitarget.h +8 -3
  183. data/ext/ffi_c/libffi/src/m68k/sysv.S +148 -25
  184. data/ext/ffi_c/libffi/src/m88k/ffi.c +400 -0
  185. data/ext/ffi_c/libffi/src/m88k/ffitarget.h +49 -0
  186. data/ext/ffi_c/libffi/src/m88k/obsd.S +209 -0
  187. data/ext/ffi_c/libffi/src/metag/ffi.c +330 -0
  188. data/ext/ffi_c/libffi/src/metag/ffitarget.h +53 -0
  189. data/ext/ffi_c/libffi/src/metag/sysv.S +311 -0
  190. data/ext/ffi_c/libffi/src/microblaze/ffi.c +321 -0
  191. data/ext/ffi_c/libffi/src/microblaze/ffitarget.h +53 -0
  192. data/ext/ffi_c/libffi/src/microblaze/sysv.S +302 -0
  193. data/ext/ffi_c/libffi/src/mips/ffi.c +392 -104
  194. data/ext/ffi_c/libffi/src/mips/ffitarget.h +40 -24
  195. data/ext/ffi_c/libffi/src/mips/n32.S +325 -93
  196. data/ext/ffi_c/libffi/src/mips/o32.S +211 -31
  197. data/ext/ffi_c/libffi/src/moxie/eabi.S +101 -0
  198. data/ext/ffi_c/libffi/src/moxie/ffi.c +310 -0
  199. data/ext/ffi_c/libffi/src/moxie/ffitarget.h +52 -0
  200. data/ext/ffi_c/libffi/src/nios2/ffi.c +304 -0
  201. data/ext/ffi_c/libffi/src/nios2/ffitarget.h +52 -0
  202. data/ext/ffi_c/libffi/src/nios2/sysv.S +136 -0
  203. data/ext/ffi_c/libffi/src/or1k/ffi.c +341 -0
  204. data/ext/ffi_c/libffi/src/or1k/ffitarget.h +58 -0
  205. data/ext/ffi_c/libffi/src/or1k/sysv.S +107 -0
  206. data/ext/ffi_c/libffi/src/pa/ffi.c +68 -111
  207. data/ext/ffi_c/libffi/src/pa/ffi64.c +614 -0
  208. data/ext/ffi_c/libffi/src/pa/ffitarget.h +34 -17
  209. data/ext/ffi_c/libffi/src/pa/hpux32.S +87 -38
  210. data/ext/ffi_c/libffi/src/pa/hpux64.S +681 -0
  211. data/ext/ffi_c/libffi/src/pa/linux.S +109 -39
  212. data/ext/ffi_c/libffi/src/powerpc/aix.S +250 -8
  213. data/ext/ffi_c/libffi/src/powerpc/aix_closure.S +255 -4
  214. data/ext/ffi_c/libffi/src/powerpc/asm.h +3 -3
  215. data/ext/ffi_c/libffi/src/powerpc/darwin.S +211 -78
  216. data/ext/ffi_c/libffi/src/powerpc/darwin_closure.S +356 -102
  217. data/ext/ffi_c/libffi/src/powerpc/ffi.c +108 -1375
  218. data/ext/ffi_c/libffi/src/powerpc/ffi_darwin.c +746 -210
  219. data/ext/ffi_c/libffi/src/powerpc/ffi_linux64.c +1153 -0
  220. data/ext/ffi_c/libffi/src/powerpc/ffi_powerpc.h +105 -0
  221. data/ext/ffi_c/libffi/src/powerpc/ffi_sysv.c +923 -0
  222. data/ext/ffi_c/libffi/src/powerpc/ffitarget.h +126 -48
  223. data/ext/ffi_c/libffi/src/powerpc/linux64.S +191 -85
  224. data/ext/ffi_c/libffi/src/powerpc/linux64_closure.S +438 -108
  225. data/ext/ffi_c/libffi/src/powerpc/ppc_closure.S +138 -68
  226. data/ext/ffi_c/libffi/src/powerpc/sysv.S +73 -119
  227. data/ext/ffi_c/libffi/src/powerpc/t-aix +5 -0
  228. data/ext/ffi_c/libffi/src/prep_cif.c +141 -32
  229. data/ext/ffi_c/libffi/src/raw_api.c +18 -5
  230. data/ext/ffi_c/libffi/src/riscv/ffi.c +514 -0
  231. data/ext/ffi_c/libffi/src/riscv/ffitarget.h +69 -0
  232. data/ext/ffi_c/libffi/src/riscv/sysv.S +293 -0
  233. data/ext/ffi_c/libffi/src/s390/ffi.c +294 -318
  234. data/ext/ffi_c/libffi/src/s390/ffitarget.h +13 -3
  235. data/ext/ffi_c/libffi/src/s390/internal.h +11 -0
  236. data/ext/ffi_c/libffi/src/s390/sysv.S +257 -366
  237. data/ext/ffi_c/libffi/src/sh/ffi.c +4 -3
  238. data/ext/ffi_c/libffi/src/sh/ffitarget.h +8 -3
  239. data/ext/ffi_c/libffi/src/sh64/ffi.c +3 -2
  240. data/ext/ffi_c/libffi/src/sh64/ffitarget.h +8 -3
  241. data/ext/ffi_c/libffi/src/sparc/ffi.c +334 -491
  242. data/ext/ffi_c/libffi/src/sparc/ffi64.c +630 -0
  243. data/ext/ffi_c/libffi/src/sparc/ffitarget.h +20 -5
  244. data/ext/ffi_c/libffi/src/sparc/internal.h +26 -0
  245. data/ext/ffi_c/libffi/src/sparc/v8.S +364 -234
  246. data/ext/ffi_c/libffi/src/sparc/v9.S +340 -207
  247. data/ext/ffi_c/libffi/src/tile/ffi.c +355 -0
  248. data/ext/ffi_c/libffi/src/tile/ffitarget.h +65 -0
  249. data/ext/ffi_c/libffi/src/tile/tile.S +360 -0
  250. data/ext/ffi_c/libffi/src/tramp.c +716 -0
  251. data/ext/ffi_c/libffi/src/types.c +48 -19
  252. data/ext/ffi_c/libffi/src/vax/elfbsd.S +195 -0
  253. data/ext/ffi_c/libffi/src/vax/ffi.c +276 -0
  254. data/ext/ffi_c/libffi/src/vax/ffitarget.h +49 -0
  255. data/ext/ffi_c/libffi/src/wasm32/ffi.c +947 -0
  256. data/ext/ffi_c/libffi/src/wasm32/ffitarget.h +62 -0
  257. data/ext/ffi_c/libffi/src/x86/asmnames.h +30 -0
  258. data/ext/ffi_c/libffi/src/x86/ffi.c +690 -540
  259. data/ext/ffi_c/libffi/src/x86/ffi64.c +450 -126
  260. data/ext/ffi_c/libffi/src/x86/ffitarget.h +86 -42
  261. data/ext/ffi_c/libffi/src/x86/ffiw64.c +361 -0
  262. data/ext/ffi_c/libffi/src/x86/internal.h +43 -0
  263. data/ext/ffi_c/libffi/src/x86/internal64.h +36 -0
  264. data/ext/ffi_c/libffi/src/x86/sysv.S +1199 -381
  265. data/ext/ffi_c/libffi/src/x86/sysv_intel.S +998 -0
  266. data/ext/ffi_c/libffi/src/x86/unix64.S +587 -298
  267. data/ext/ffi_c/libffi/src/x86/win64.S +251 -457
  268. data/ext/ffi_c/libffi/src/x86/win64_intel.S +238 -0
  269. data/ext/ffi_c/libffi/src/xtensa/ffi.c +306 -0
  270. data/ext/ffi_c/libffi/src/xtensa/ffitarget.h +57 -0
  271. data/ext/ffi_c/libffi/src/xtensa/sysv.S +268 -0
  272. data/ext/ffi_c/libffi/stamp-h.in +1 -0
  273. data/ext/ffi_c/libffi/testsuite/Makefile.am +80 -73
  274. data/ext/ffi_c/libffi/testsuite/Makefile.in +251 -117
  275. data/ext/ffi_c/libffi/testsuite/emscripten/build-tests.sh +54 -0
  276. data/ext/ffi_c/libffi/testsuite/emscripten/build.sh +63 -0
  277. data/ext/ffi_c/libffi/testsuite/emscripten/conftest.py +86 -0
  278. data/ext/ffi_c/libffi/testsuite/emscripten/node-tests.sh +48 -0
  279. data/ext/ffi_c/libffi/testsuite/emscripten/test.html +7 -0
  280. data/ext/ffi_c/libffi/testsuite/emscripten/test_libffi.py +51 -0
  281. data/ext/ffi_c/libffi/testsuite/lib/libffi.exp +682 -0
  282. data/ext/ffi_c/libffi/testsuite/lib/target-libpath.exp +22 -2
  283. data/ext/ffi_c/libffi/testsuite/libffi.bhaible/Makefile +28 -0
  284. data/ext/ffi_c/libffi/testsuite/libffi.bhaible/README +78 -0
  285. data/ext/ffi_c/libffi/testsuite/libffi.bhaible/alignof.h +50 -0
  286. data/ext/ffi_c/libffi/testsuite/libffi.bhaible/bhaible.exp +63 -0
  287. data/ext/ffi_c/libffi/testsuite/libffi.bhaible/test-call.c +1746 -0
  288. data/ext/ffi_c/libffi/testsuite/libffi.bhaible/test-callback.c +2885 -0
  289. data/ext/ffi_c/libffi/testsuite/libffi.bhaible/testcases.c +747 -0
  290. data/ext/ffi_c/libffi/testsuite/libffi.call/align_mixed.c +46 -0
  291. data/ext/ffi_c/libffi/testsuite/libffi.call/align_stdcall.c +46 -0
  292. data/ext/ffi_c/libffi/testsuite/libffi.call/bpo_38748.c +41 -0
  293. data/ext/ffi_c/libffi/testsuite/libffi.call/call.exp +28 -10
  294. data/ext/ffi_c/libffi/testsuite/libffi.call/callback.c +99 -0
  295. data/ext/ffi_c/libffi/testsuite/libffi.call/callback2.c +108 -0
  296. data/ext/ffi_c/libffi/testsuite/libffi.call/callback3.c +114 -0
  297. data/ext/ffi_c/libffi/testsuite/libffi.call/callback4.c +119 -0
  298. data/ext/ffi_c/libffi/testsuite/libffi.call/err_bad_typedef.c +4 -3
  299. data/ext/ffi_c/libffi/testsuite/libffi.call/ffitest.h +88 -42
  300. data/ext/ffi_c/libffi/testsuite/libffi.call/float1.c +3 -1
  301. data/ext/ffi_c/libffi/testsuite/libffi.call/float2.c +15 -12
  302. data/ext/ffi_c/libffi/testsuite/libffi.call/float3.c +4 -2
  303. data/ext/ffi_c/libffi/testsuite/libffi.call/float_va.c +110 -0
  304. data/ext/ffi_c/libffi/testsuite/libffi.call/many.c +6 -16
  305. data/ext/ffi_c/libffi/testsuite/libffi.call/many2.c +57 -0
  306. data/ext/ffi_c/libffi/testsuite/libffi.call/many_double.c +70 -0
  307. data/ext/ffi_c/libffi/testsuite/libffi.call/many_mixed.c +78 -0
  308. data/ext/ffi_c/libffi/testsuite/libffi.call/negint.c +0 -1
  309. data/ext/ffi_c/libffi/testsuite/libffi.call/offsets.c +46 -0
  310. data/ext/ffi_c/libffi/testsuite/libffi.call/pr1172638.c +127 -0
  311. data/ext/ffi_c/libffi/testsuite/libffi.call/return_dbl.c +1 -0
  312. data/ext/ffi_c/libffi/testsuite/libffi.call/return_ldl.c +1 -1
  313. data/ext/ffi_c/libffi/testsuite/libffi.call/return_ll1.c +6 -0
  314. data/ext/ffi_c/libffi/testsuite/libffi.call/return_sc.c +1 -1
  315. data/ext/ffi_c/libffi/testsuite/libffi.call/return_sl.c +4 -0
  316. data/ext/ffi_c/libffi/testsuite/libffi.call/return_uc.c +1 -1
  317. data/ext/ffi_c/libffi/testsuite/libffi.call/return_ul.c +4 -0
  318. data/ext/ffi_c/libffi/testsuite/libffi.call/s55.c +60 -0
  319. data/ext/ffi_c/libffi/testsuite/libffi.call/strlen.c +9 -10
  320. data/ext/ffi_c/libffi/testsuite/libffi.call/strlen2.c +49 -0
  321. data/ext/ffi_c/libffi/testsuite/libffi.call/strlen3.c +49 -0
  322. data/ext/ffi_c/libffi/testsuite/libffi.call/strlen4.c +55 -0
  323. data/ext/ffi_c/libffi/testsuite/libffi.call/struct1.c +9 -7
  324. data/ext/ffi_c/libffi/testsuite/libffi.call/struct10.c +57 -0
  325. data/ext/ffi_c/libffi/testsuite/libffi.call/struct2.c +7 -7
  326. data/ext/ffi_c/libffi/testsuite/libffi.call/struct3.c +7 -6
  327. data/ext/ffi_c/libffi/testsuite/libffi.call/struct4.c +9 -8
  328. data/ext/ffi_c/libffi/testsuite/libffi.call/struct5.c +9 -8
  329. data/ext/ffi_c/libffi/testsuite/libffi.call/struct6.c +9 -9
  330. data/ext/ffi_c/libffi/testsuite/libffi.call/struct7.c +9 -9
  331. data/ext/ffi_c/libffi/testsuite/libffi.call/struct8.c +9 -8
  332. data/ext/ffi_c/libffi/testsuite/libffi.call/struct9.c +9 -8
  333. data/ext/ffi_c/libffi/testsuite/libffi.call/struct_by_value_2.c +63 -0
  334. data/ext/ffi_c/libffi/testsuite/libffi.call/struct_by_value_3.c +65 -0
  335. data/ext/ffi_c/libffi/testsuite/libffi.call/struct_by_value_3f.c +65 -0
  336. data/ext/ffi_c/libffi/testsuite/libffi.call/struct_by_value_4.c +67 -0
  337. data/ext/ffi_c/libffi/testsuite/libffi.call/struct_by_value_4f.c +67 -0
  338. data/ext/ffi_c/libffi/testsuite/libffi.call/struct_by_value_big.c +93 -0
  339. data/ext/ffi_c/libffi/testsuite/libffi.call/struct_by_value_small.c +61 -0
  340. data/ext/ffi_c/libffi/testsuite/libffi.call/struct_return_2H.c +63 -0
  341. data/ext/ffi_c/libffi/testsuite/libffi.call/struct_return_8H.c +90 -0
  342. data/ext/ffi_c/libffi/testsuite/libffi.call/uninitialized.c +61 -0
  343. data/ext/ffi_c/libffi/testsuite/libffi.call/va_1.c +78 -0
  344. data/ext/ffi_c/libffi/testsuite/libffi.call/va_2.c +220 -0
  345. data/ext/ffi_c/libffi/testsuite/libffi.call/va_3.c +154 -0
  346. data/ext/ffi_c/libffi/testsuite/libffi.call/va_struct1.c +134 -0
  347. data/ext/ffi_c/libffi/testsuite/libffi.call/va_struct2.c +134 -0
  348. data/ext/ffi_c/libffi/testsuite/libffi.call/va_struct3.c +140 -0
  349. data/ext/ffi_c/libffi/testsuite/libffi.closures/closure.exp +67 -0
  350. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/closure_fn0.c +3 -2
  351. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/closure_fn1.c +2 -0
  352. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/closure_fn2.c +2 -0
  353. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/closure_fn3.c +21 -1
  354. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/closure_fn4.c +2 -0
  355. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/closure_fn5.c +2 -0
  356. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/closure_fn6.c +2 -0
  357. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/closure_loc_fn0.c +7 -6
  358. data/ext/ffi_c/libffi/testsuite/{libffi.call/closure_stdcall.c → libffi.closures/closure_simple.c} +13 -16
  359. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_12byte.c +22 -4
  360. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_16byte.c +26 -4
  361. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_18byte.c +28 -4
  362. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_19byte.c +33 -4
  363. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_1_1byte.c +8 -4
  364. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_20byte.c +23 -5
  365. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_20byte1.c +25 -5
  366. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_24byte.c +40 -8
  367. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_2byte.c +17 -4
  368. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_3_1byte.c +23 -4
  369. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_3byte1.c +17 -4
  370. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_3byte2.c +17 -4
  371. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_3float.c +113 -0
  372. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_4_1byte.c +26 -4
  373. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_4byte.c +17 -4
  374. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_5_1_byte.c +33 -5
  375. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_5byte.c +23 -5
  376. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_64byte.c +29 -5
  377. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_6_1_byte.c +32 -5
  378. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_6byte.c +28 -6
  379. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_7_1_byte.c +43 -5
  380. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_7byte.c +29 -5
  381. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_8byte.c +18 -4
  382. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_9byte1.c +18 -5
  383. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_9byte2.c +18 -6
  384. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_double.c +23 -5
  385. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_float.c +23 -5
  386. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_longdouble.c +24 -5
  387. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_longdouble_split.c +44 -31
  388. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_longdouble_split2.c +44 -9
  389. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_pointer.c +23 -5
  390. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_sint16.c +22 -5
  391. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_sint32.c +22 -7
  392. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_sint64.c +23 -5
  393. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_uint16.c +22 -5
  394. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_uint32.c +23 -5
  395. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_uint64.c +24 -5
  396. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_dbls_struct.c +7 -5
  397. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_double_va.c +21 -9
  398. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_float.c +4 -0
  399. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_longdouble.c +13 -3
  400. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_longdouble_va.c +34 -11
  401. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_many_mixed_args.c +70 -0
  402. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_many_mixed_float_double.c +55 -0
  403. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_multi_schar.c +5 -1
  404. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_multi_sshort.c +6 -1
  405. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_multi_sshortchar.c +9 -1
  406. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_multi_uchar.c +9 -1
  407. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_multi_ushort.c +6 -2
  408. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_multi_ushortchar.c +9 -1
  409. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_pointer.c +7 -2
  410. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_pointer_stack.c +22 -10
  411. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_schar.c +3 -0
  412. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_sint.c +2 -0
  413. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_sshort.c +3 -0
  414. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_struct_va1.c +125 -0
  415. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_uchar.c +3 -0
  416. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_uint.c +4 -0
  417. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_uint_va.c +49 -0
  418. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_ulong_va.c +49 -0
  419. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_ulonglong.c +8 -5
  420. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_ushort.c +3 -0
  421. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/err_bad_abi.c +2 -3
  422. data/ext/ffi_c/libffi/testsuite/libffi.closures/ffitest.h +1 -0
  423. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/huge_struct.c +57 -56
  424. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct.c +38 -15
  425. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct1.c +9 -9
  426. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct10.c +19 -6
  427. data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct11.c +137 -0
  428. data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct12.c +86 -0
  429. data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct13.c +115 -0
  430. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct2.c +15 -6
  431. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct3.c +15 -6
  432. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct4.c +14 -5
  433. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct5.c +14 -5
  434. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct6.c +17 -6
  435. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct7.c +14 -5
  436. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct8.c +17 -6
  437. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct9.c +17 -6
  438. data/ext/ffi_c/libffi/testsuite/libffi.closures/single_entry_structs1.c +86 -0
  439. data/ext/ffi_c/libffi/testsuite/libffi.closures/single_entry_structs2.c +102 -0
  440. data/ext/ffi_c/libffi/testsuite/libffi.closures/single_entry_structs3.c +101 -0
  441. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/stret_large.c +7 -7
  442. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/stret_large2.c +7 -7
  443. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/stret_medium.c +6 -6
  444. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/stret_medium2.c +7 -6
  445. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/testclosure.c +8 -3
  446. data/ext/ffi_c/libffi/testsuite/{libffi.special → libffi.closures}/unwindtest.cc +4 -10
  447. data/ext/ffi_c/libffi/testsuite/{libffi.special → libffi.closures}/unwindtest_ffi_call.cc +4 -2
  448. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_align_complex.inc +91 -0
  449. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_align_complex_double.c +10 -0
  450. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_align_complex_float.c +10 -0
  451. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_align_complex_longdouble.c +10 -0
  452. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex.inc +42 -0
  453. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_double.c +10 -0
  454. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_float.c +10 -0
  455. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_longdouble.c +10 -0
  456. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_struct.inc +71 -0
  457. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_struct_double.c +10 -0
  458. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_struct_float.c +10 -0
  459. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_struct_longdouble.c +10 -0
  460. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_va.inc +80 -0
  461. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_va_double.c +10 -0
  462. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_va_float.c +16 -0
  463. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_va_longdouble.c +10 -0
  464. data/ext/ffi_c/libffi/testsuite/{libffi.special/special.exp → libffi.complex/complex.exp} +9 -10
  465. data/ext/ffi_c/libffi/testsuite/libffi.complex/complex.inc +51 -0
  466. data/ext/ffi_c/libffi/testsuite/libffi.complex/complex_defs_double.inc +7 -0
  467. data/ext/ffi_c/libffi/testsuite/libffi.complex/complex_defs_float.inc +7 -0
  468. data/ext/ffi_c/libffi/testsuite/libffi.complex/complex_defs_longdouble.inc +7 -0
  469. data/ext/ffi_c/libffi/testsuite/libffi.complex/complex_double.c +10 -0
  470. data/ext/ffi_c/libffi/testsuite/libffi.complex/complex_float.c +10 -0
  471. data/ext/ffi_c/libffi/testsuite/libffi.complex/complex_int.c +86 -0
  472. data/ext/ffi_c/libffi/testsuite/libffi.complex/complex_longdouble.c +10 -0
  473. data/ext/ffi_c/libffi/testsuite/libffi.complex/ffitest.h +1 -0
  474. data/ext/ffi_c/libffi/testsuite/libffi.complex/many_complex.inc +78 -0
  475. data/ext/ffi_c/libffi/testsuite/libffi.complex/many_complex_double.c +10 -0
  476. data/ext/ffi_c/libffi/testsuite/libffi.complex/many_complex_float.c +10 -0
  477. data/ext/ffi_c/libffi/testsuite/libffi.complex/many_complex_longdouble.c +10 -0
  478. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex.inc +37 -0
  479. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex1.inc +41 -0
  480. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex1_double.c +10 -0
  481. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex1_float.c +10 -0
  482. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex1_longdouble.c +10 -0
  483. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex2.inc +44 -0
  484. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex2_double.c +10 -0
  485. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex2_float.c +10 -0
  486. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex2_longdouble.c +10 -0
  487. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex_double.c +10 -0
  488. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex_float.c +10 -0
  489. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex_longdouble.c +10 -0
  490. data/ext/ffi_c/libffi/testsuite/libffi.go/aa-direct.c +34 -0
  491. data/ext/ffi_c/libffi/testsuite/libffi.go/closure1.c +28 -0
  492. data/ext/ffi_c/libffi/testsuite/libffi.go/ffitest.h +1 -0
  493. data/ext/ffi_c/libffi/testsuite/libffi.go/go.exp +36 -0
  494. data/ext/ffi_c/libffi/testsuite/libffi.go/static-chain.h +19 -0
  495. data/ext/ffi_c/libffi.bsd.mk +14 -8
  496. data/ext/ffi_c/libffi.darwin.mk +56 -26
  497. data/ext/ffi_c/libffi.gnu.mk +9 -6
  498. data/ext/ffi_c/libffi.mk +13 -8
  499. data/ext/ffi_c/libffi.vc.mk +26 -0
  500. data/ext/ffi_c/libffi.vc64.mk +26 -0
  501. data/ext/ffi_c/rbffi.h +34 -6
  502. data/ext/ffi_c/{endian.h → rbffi_endian.h} +21 -2
  503. data/ffi.gemspec +42 -0
  504. data/lib/ffi/abstract_memory.rb +44 -0
  505. data/lib/ffi/autopointer.rb +111 -52
  506. data/lib/ffi/compat.rb +43 -0
  507. data/lib/ffi/data_converter.rb +67 -0
  508. data/lib/ffi/dynamic_library.rb +118 -0
  509. data/lib/ffi/enum.rb +203 -22
  510. data/lib/ffi/errno.rb +27 -12
  511. data/lib/ffi/ffi.rb +88 -11
  512. data/lib/ffi/function.rb +71 -0
  513. data/lib/ffi/io.rb +35 -14
  514. data/lib/ffi/library.rb +382 -96
  515. data/lib/ffi/library_path.rb +109 -0
  516. data/lib/ffi/managedstruct.rb +64 -35
  517. data/lib/ffi/memorypointer.rb +1 -33
  518. data/lib/ffi/platform/aarch64-darwin/types.conf +130 -0
  519. data/lib/ffi/platform/aarch64-freebsd/types.conf +128 -0
  520. data/lib/ffi/platform/aarch64-freebsd12/types.conf +181 -0
  521. data/lib/ffi/platform/aarch64-linux/types.conf +175 -0
  522. data/lib/ffi/platform/aarch64-openbsd/types.conf +134 -0
  523. data/lib/ffi/platform/aarch64-windows/types.conf +52 -0
  524. data/lib/ffi/platform/arm-freebsd/types.conf +152 -0
  525. data/lib/ffi/platform/arm-freebsd12/types.conf +152 -0
  526. data/lib/ffi/platform/arm-linux/types.conf +132 -0
  527. data/lib/ffi/platform/hppa1.1-linux/types.conf +178 -0
  528. data/lib/ffi/platform/hppa2.0-linux/types.conf +178 -0
  529. data/lib/ffi/platform/i386-cygwin/types.conf +3 -0
  530. data/lib/ffi/platform/i386-darwin/types.conf +100 -0
  531. data/lib/ffi/platform/i386-freebsd/types.conf +152 -0
  532. data/lib/ffi/platform/i386-freebsd12/types.conf +152 -0
  533. data/lib/ffi/platform/i386-gnu/types.conf +107 -0
  534. data/lib/ffi/platform/i386-linux/types.conf +103 -0
  535. data/lib/ffi/platform/i386-netbsd/types.conf +126 -0
  536. data/lib/ffi/platform/i386-openbsd/types.conf +128 -0
  537. data/lib/ffi/platform/i386-solaris/types.conf +122 -0
  538. data/lib/ffi/platform/i386-windows/types.conf +52 -0
  539. data/lib/ffi/platform/ia64-linux/types.conf +104 -0
  540. data/lib/ffi/platform/loongarch64-linux/types.conf +141 -0
  541. data/lib/ffi/platform/mips-linux/types.conf +102 -0
  542. data/lib/ffi/platform/mips64-linux/types.conf +104 -0
  543. data/lib/ffi/platform/mips64el-linux/types.conf +104 -0
  544. data/lib/ffi/platform/mipsel-linux/types.conf +102 -0
  545. data/lib/ffi/platform/mipsisa32r6-linux/types.conf +102 -0
  546. data/lib/ffi/platform/mipsisa32r6el-linux/types.conf +102 -0
  547. data/lib/ffi/platform/mipsisa64r6-linux/types.conf +104 -0
  548. data/lib/ffi/platform/mipsisa64r6el-linux/types.conf +104 -0
  549. data/lib/ffi/platform/powerpc-aix/types.conf +180 -0
  550. data/lib/ffi/platform/powerpc-darwin/types.conf +100 -0
  551. data/lib/ffi/platform/powerpc-linux/types.conf +130 -0
  552. data/lib/ffi/platform/powerpc-openbsd/types.conf +156 -0
  553. data/lib/ffi/platform/powerpc64-linux/types.conf +104 -0
  554. data/lib/ffi/platform/powerpc64le-linux/types.conf +100 -0
  555. data/lib/ffi/platform/riscv64-linux/types.conf +104 -0
  556. data/lib/ffi/platform/s390-linux/types.conf +102 -0
  557. data/lib/ffi/platform/s390x-linux/types.conf +102 -0
  558. data/lib/ffi/platform/sparc-linux/types.conf +102 -0
  559. data/lib/ffi/platform/sparc-solaris/types.conf +128 -0
  560. data/lib/ffi/platform/sparcv9-linux/types.conf +102 -0
  561. data/lib/ffi/platform/sparcv9-openbsd/types.conf +156 -0
  562. data/lib/ffi/platform/sparcv9-solaris/types.conf +128 -0
  563. data/lib/ffi/platform/sw_64-linux/types.conf +141 -0
  564. data/lib/ffi/platform/x86_64-cygwin/types.conf +3 -0
  565. data/lib/ffi/platform/x86_64-darwin/types.conf +130 -0
  566. data/lib/ffi/platform/x86_64-dragonflybsd/types.conf +130 -0
  567. data/lib/ffi/platform/x86_64-freebsd/types.conf +128 -0
  568. data/lib/ffi/platform/x86_64-freebsd12/types.conf +158 -0
  569. data/lib/ffi/platform/x86_64-haiku/types.conf +117 -0
  570. data/lib/ffi/platform/x86_64-linux/types.conf +132 -0
  571. data/lib/ffi/platform/x86_64-msys/types.conf +119 -0
  572. data/lib/ffi/platform/x86_64-netbsd/types.conf +128 -0
  573. data/lib/ffi/platform/x86_64-openbsd/types.conf +134 -0
  574. data/lib/ffi/platform/x86_64-solaris/types.conf +122 -0
  575. data/lib/ffi/platform/x86_64-windows/types.conf +52 -0
  576. data/lib/ffi/platform.rb +110 -34
  577. data/lib/ffi/pointer.rb +117 -90
  578. data/lib/ffi/struct.rb +101 -70
  579. data/lib/ffi/struct_by_reference.rb +72 -0
  580. data/lib/ffi/struct_layout.rb +96 -0
  581. data/lib/ffi/struct_layout_builder.rb +90 -21
  582. data/lib/ffi/tools/const_generator.rb +86 -31
  583. data/lib/ffi/tools/generator.rb +49 -2
  584. data/lib/ffi/tools/generator_task.rb +13 -16
  585. data/lib/ffi/tools/struct_generator.rb +6 -5
  586. data/lib/ffi/tools/types_generator.rb +25 -11
  587. data/lib/ffi/types.rb +105 -36
  588. data/lib/ffi/union.rb +23 -12
  589. data/lib/ffi/variadic.rb +44 -29
  590. data/lib/ffi/version.rb +3 -0
  591. data/lib/ffi.rb +25 -9
  592. data/rakelib/ffi_gem_helper.rb +65 -0
  593. data/samples/getlogin.rb +8 -0
  594. data/samples/getpid.rb +8 -0
  595. data/samples/gettimeofday.rb +18 -0
  596. data/samples/hello.rb +8 -0
  597. data/samples/hello_ractor.rb +11 -0
  598. data/samples/inotify.rb +60 -0
  599. data/samples/pty.rb +75 -0
  600. data/samples/qsort.rb +20 -0
  601. data/samples/qsort_ractor.rb +28 -0
  602. data/sig/ffi/abstract_memory.rbs +165 -0
  603. data/sig/ffi/auto_pointer.rbs +26 -0
  604. data/sig/ffi/buffer.rbs +18 -0
  605. data/sig/ffi/data_converter.rbs +10 -0
  606. data/sig/ffi/dynamic_library.rbs +9 -0
  607. data/sig/ffi/enum.rbs +38 -0
  608. data/sig/ffi/function.rbs +39 -0
  609. data/sig/ffi/library.rbs +42 -0
  610. data/sig/ffi/native_type.rbs +86 -0
  611. data/sig/ffi/pointer.rbs +42 -0
  612. data/sig/ffi/struct.rbs +76 -0
  613. data/sig/ffi/struct_by_reference.rbs +11 -0
  614. data/sig/ffi/struct_by_value.rbs +7 -0
  615. data/sig/ffi/struct_layout.rbs +9 -0
  616. data/sig/ffi/struct_layout_builder.rbs +5 -0
  617. data/sig/ffi/type.rbs +39 -0
  618. data/sig/ffi.rbs +26 -0
  619. data.tar.gz.sig +0 -0
  620. metadata +547 -248
  621. metadata.gz.sig +0 -0
  622. data/History.txt +0 -109
  623. data/README.rdoc +0 -70
  624. data/ext/ffi_c/DataConverter.c +0 -62
  625. data/ext/ffi_c/StructByReference.c +0 -150
  626. data/ext/ffi_c/StructByReference.h +0 -50
  627. data/ext/ffi_c/libffi/ChangeLog.libffi +0 -658
  628. data/ext/ffi_c/libffi/ChangeLog.libgcj +0 -40
  629. data/ext/ffi_c/libffi/ChangeLog.v1 +0 -764
  630. data/ext/ffi_c/libffi/README +0 -306
  631. data/ext/ffi_c/libffi/aclocal.m4 +0 -8998
  632. data/ext/ffi_c/libffi/depcomp +0 -584
  633. data/ext/ffi_c/libffi/doc/libffi.info +0 -533
  634. data/ext/ffi_c/libffi/doc/stamp-vti +0 -4
  635. data/ext/ffi_c/libffi/m4/libtool.m4 +0 -7360
  636. data/ext/ffi_c/libffi/m4/ltoptions.m4 +0 -368
  637. data/ext/ffi_c/libffi/m4/ltsugar.m4 +0 -123
  638. data/ext/ffi_c/libffi/m4/ltversion.m4 +0 -23
  639. data/ext/ffi_c/libffi/m4/lt~obsolete.m4 +0 -92
  640. data/ext/ffi_c/libffi/mdate-sh +0 -201
  641. data/ext/ffi_c/libffi/src/x86/darwin.S +0 -444
  642. data/ext/ffi_c/libffi/src/x86/darwin64.S +0 -416
  643. data/ext/ffi_c/libffi/src/x86/freebsd.S +0 -458
  644. data/ext/ffi_c/libffi/src/x86/win32.S +0 -877
  645. data/ext/ffi_c/libffi/testsuite/lib/libffi-dg.exp +0 -300
  646. data/ext/ffi_c/libffi/testsuite/libffi.call/many_win32.c +0 -63
  647. data/ext/ffi_c/libffi/testsuite/libffi.call/strlen_win32.c +0 -44
  648. data/ext/ffi_c/libffi/testsuite/libffi.special/ffitestcxx.h +0 -96
  649. data/ext/ffi_c/libffi/texinfo.tex +0 -7210
  650. data/gen/Rakefile +0 -14
  651. data/spec/ffi/async_callback_spec.rb +0 -23
  652. data/spec/ffi/bool_spec.rb +0 -24
  653. data/spec/ffi/buffer_spec.rb +0 -202
  654. data/spec/ffi/callback_spec.rb +0 -653
  655. data/spec/ffi/custom_param_type.rb +0 -31
  656. data/spec/ffi/custom_type_spec.rb +0 -73
  657. data/spec/ffi/enum_spec.rb +0 -183
  658. data/spec/ffi/errno_spec.rb +0 -13
  659. data/spec/ffi/ffi_spec.rb +0 -24
  660. data/spec/ffi/function_spec.rb +0 -73
  661. data/spec/ffi/library_spec.rb +0 -174
  662. data/spec/ffi/managed_struct_spec.rb +0 -56
  663. data/spec/ffi/number_spec.rb +0 -231
  664. data/spec/ffi/pointer_spec.rb +0 -210
  665. data/spec/ffi/rbx/attach_function_spec.rb +0 -28
  666. data/spec/ffi/rbx/memory_pointer_spec.rb +0 -109
  667. data/spec/ffi/rbx/spec_helper.rb +0 -1
  668. data/spec/ffi/rbx/struct_spec.rb +0 -13
  669. data/spec/ffi/spec_helper.rb +0 -21
  670. data/spec/ffi/string_spec.rb +0 -103
  671. data/spec/ffi/strptr_spec.rb +0 -36
  672. data/spec/ffi/struct_callback_spec.rb +0 -64
  673. data/spec/ffi/struct_initialize_spec.rb +0 -30
  674. data/spec/ffi/struct_packed_spec.rb +0 -46
  675. data/spec/ffi/struct_spec.rb +0 -638
  676. data/spec/ffi/typedef_spec.rb +0 -62
  677. data/spec/ffi/union_spec.rb +0 -60
  678. data/spec/ffi/variadic_spec.rb +0 -84
  679. data/spec/spec.opts +0 -4
  680. data/tasks/ann.rake +0 -80
  681. data/tasks/extension.rake +0 -25
  682. data/tasks/gem.rake +0 -200
  683. data/tasks/git.rake +0 -41
  684. data/tasks/notes.rake +0 -27
  685. data/tasks/post_load.rake +0 -34
  686. data/tasks/rdoc.rake +0 -50
  687. data/tasks/rubyforge.rake +0 -55
  688. data/tasks/setup.rb +0 -301
  689. data/tasks/spec.rake +0 -54
  690. data/tasks/svn.rake +0 -47
  691. data/tasks/test.rake +0 -40
  692. /data/ext/ffi_c/libffi/testsuite/libffi.call/{pyobjc-tc.c → pyobjc_tc.c} +0 -0
  693. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_double.c +0 -0
  694. /data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/problem1.c +0 -0
@@ -3,7 +3,7 @@
3
3
 
4
4
  Copyright (C) 1998 Geoffrey Keating
5
5
  Copyright (C) 2001 John Hornkvist
6
- Copyright (C) 2002, 2006, 2007, 2009 Free Software Foundation, Inc.
6
+ Copyright (C) 2002, 2006, 2007, 2009, 2010 Free Software Foundation, Inc.
7
7
 
8
8
  FFI support for Darwin and AIX.
9
9
 
@@ -34,12 +34,22 @@
34
34
 
35
35
  extern void ffi_closure_ASM (void);
36
36
 
37
+ #if defined (FFI_GO_CLOSURES)
38
+ extern void ffi_go_closure_ASM (void);
39
+ #endif
40
+
37
41
  enum {
38
- /* The assembly depends on these exact flags. */
39
- FLAG_RETURNS_NOTHING = 1 << (31-30), /* These go in cr7 */
40
- FLAG_RETURNS_FP = 1 << (31-29),
41
- FLAG_RETURNS_64BITS = 1 << (31-28),
42
- FLAG_RETURNS_128BITS = 1 << (31-31),
42
+ /* The assembly depends on these exact flags.
43
+ For Darwin64 (when FLAG_RETURNS_STRUCT is set):
44
+ FLAG_RETURNS_FP indicates that the structure embeds FP data.
45
+ FLAG_RETURNS_128BITS signals a special struct size that is not
46
+ expanded for float content. */
47
+ FLAG_RETURNS_128BITS = 1 << (31-31), /* These go in cr7 */
48
+ FLAG_RETURNS_NOTHING = 1 << (31-30),
49
+ FLAG_RETURNS_FP = 1 << (31-29),
50
+ FLAG_RETURNS_64BITS = 1 << (31-28),
51
+
52
+ FLAG_RETURNS_STRUCT = 1 << (31-27), /* This goes in cr6 */
43
53
 
44
54
  FLAG_ARG_NEEDS_COPY = 1 << (31- 7),
45
55
  FLAG_FP_ARGUMENTS = 1 << (31- 6), /* cr1.eq; specified by ABI */
@@ -50,43 +60,61 @@ enum {
50
60
  /* About the DARWIN ABI. */
51
61
  enum {
52
62
  NUM_GPR_ARG_REGISTERS = 8,
53
- NUM_FPR_ARG_REGISTERS = 13
63
+ NUM_FPR_ARG_REGISTERS = 13,
64
+ LINKAGE_AREA_GPRS = 6
54
65
  };
55
- enum { ASM_NEEDS_REGISTERS = 4 };
66
+
67
+ enum { ASM_NEEDS_REGISTERS = 4 }; /* r28-r31 */
56
68
 
57
69
  /* ffi_prep_args is called by the assembly routine once stack space
58
70
  has been allocated for the function's arguments.
71
+
72
+ m32/m64
59
73
 
60
74
  The stack layout we want looks like this:
61
75
 
62
76
  | Return address from ffi_call_DARWIN | higher addresses
63
77
  |--------------------------------------------|
64
- | Previous backchain pointer 4 | stack pointer here
78
+ | Previous backchain pointer 4/8 | stack pointer here
65
79
  |--------------------------------------------|<+ <<< on entry to
66
- | Saved r28-r31 4*4 | | ffi_call_DARWIN
80
+ | ASM_NEEDS_REGISTERS=r28-r31 4*(4/8) | | ffi_call_DARWIN
67
81
  |--------------------------------------------| |
68
- | Parameters (at least 8*4=32) | |
82
+ | When we have any FP activity... the | |
83
+ | FPRs occupy NUM_FPR_ARG_REGISTERS slots | |
84
+ | here fp13 .. fp1 from high to low addr. | |
85
+ ~ ~ ~
86
+ | Parameters (at least 8*4/8=32/64) | | NUM_GPR_ARG_REGISTERS
69
87
  |--------------------------------------------| |
70
- | Space for GPR2 4 | |
88
+ | TOC=R2 (AIX) Reserved (Darwin) 4/8 | |
71
89
  |--------------------------------------------| | stack |
72
- | Reserved 2*4 | | grows |
90
+ | Reserved 2*4/8 | | grows |
73
91
  |--------------------------------------------| | down V
74
- | Space for callee's LR 4 | |
92
+ | Space for callee's LR 4/8 | |
75
93
  |--------------------------------------------| | lower addresses
76
- | Saved CR 4 | |
94
+ | Saved CR [low word for m64] 4/8 | |
77
95
  |--------------------------------------------| | stack pointer here
78
- | Current backchain pointer 4 |-/ during
96
+ | Current backchain pointer 4/8 |-/ during
79
97
  |--------------------------------------------| <<< ffi_call_DARWIN
80
98
 
81
99
  */
82
100
 
101
+ #if defined(POWERPC_DARWIN64)
102
+ static void
103
+ darwin64_pass_struct_by_value
104
+ (ffi_type *, char *, unsigned, unsigned *, double **, unsigned long **);
105
+ #endif
106
+
107
+ /* This depends on GPR_SIZE = sizeof (unsigned long) */
108
+
83
109
  void
84
110
  ffi_prep_args (extended_cif *ecif, unsigned long *const stack)
85
111
  {
86
112
  const unsigned bytes = ecif->cif->bytes;
87
113
  const unsigned flags = ecif->cif->flags;
88
114
  const unsigned nargs = ecif->cif->nargs;
115
+ #if !defined(POWERPC_DARWIN64)
89
116
  const ffi_abi abi = ecif->cif->abi;
117
+ #endif
90
118
 
91
119
  /* 'stacktop' points at the previous backchain pointer. */
92
120
  unsigned long *const stacktop = stack + (bytes / sizeof(unsigned long));
@@ -94,18 +122,19 @@ ffi_prep_args (extended_cif *ecif, unsigned long *const stack)
94
122
  /* 'fpr_base' points at the space for fpr1, and grows upwards as
95
123
  we use FPR registers. */
96
124
  double *fpr_base = (double *) (stacktop - ASM_NEEDS_REGISTERS) - NUM_FPR_ARG_REGISTERS;
97
- int fparg_count = 0;
98
-
125
+ int gp_count = 0, fparg_count = 0;
99
126
 
100
127
  /* 'next_arg' grows up as we put parameters in it. */
101
- unsigned long *next_arg = stack + 6; /* 6 reserved positions. */
128
+ unsigned long *next_arg = stack + LINKAGE_AREA_GPRS; /* 6 reserved positions. */
102
129
 
103
130
  int i;
104
131
  double double_tmp;
105
132
  void **p_argv = ecif->avalue;
106
133
  unsigned long gprvalue;
107
134
  ffi_type** ptr = ecif->cif->arg_types;
135
+ #if !defined(POWERPC_DARWIN64)
108
136
  char *dest_cpy;
137
+ #endif
109
138
  unsigned size_al = 0;
110
139
 
111
140
  /* Check that everything starts aligned properly. */
@@ -130,25 +159,30 @@ ffi_prep_args (extended_cif *ecif, unsigned long *const stack)
130
159
  the size of the floating-point parameter are skipped. */
131
160
  case FFI_TYPE_FLOAT:
132
161
  double_tmp = *(float *) *p_argv;
133
- if (fparg_count >= NUM_FPR_ARG_REGISTERS)
134
- *(double *)next_arg = double_tmp;
135
- else
162
+ if (fparg_count < NUM_FPR_ARG_REGISTERS)
136
163
  *fpr_base++ = double_tmp;
164
+ #if defined(POWERPC_DARWIN)
165
+ *(float *)next_arg = *(float *) *p_argv;
166
+ #else
167
+ *(double *)next_arg = double_tmp;
168
+ #endif
137
169
  next_arg++;
170
+ gp_count++;
138
171
  fparg_count++;
139
172
  FFI_ASSERT(flags & FLAG_FP_ARGUMENTS);
140
173
  break;
141
174
 
142
175
  case FFI_TYPE_DOUBLE:
143
176
  double_tmp = *(double *) *p_argv;
144
- if (fparg_count >= NUM_FPR_ARG_REGISTERS)
145
- *(double *)next_arg = double_tmp;
146
- else
177
+ if (fparg_count < NUM_FPR_ARG_REGISTERS)
147
178
  *fpr_base++ = double_tmp;
179
+ *(double *)next_arg = double_tmp;
148
180
  #ifdef POWERPC64
149
181
  next_arg++;
182
+ gp_count++;
150
183
  #else
151
184
  next_arg += 2;
185
+ gp_count += 2;
152
186
  #endif
153
187
  fparg_count++;
154
188
  FFI_ASSERT(flags & FLAG_FP_ARGUMENTS);
@@ -157,30 +191,41 @@ ffi_prep_args (extended_cif *ecif, unsigned long *const stack)
157
191
  #if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
158
192
 
159
193
  case FFI_TYPE_LONGDOUBLE:
160
- #ifdef POWERPC64
194
+ # if defined(POWERPC64) && !defined(POWERPC_DARWIN64)
195
+ /* ??? This will exceed the regs count when the value starts at fp13
196
+ and it will not put the extra bit on the stack. */
161
197
  if (fparg_count < NUM_FPR_ARG_REGISTERS)
162
198
  *(long double *) fpr_base++ = *(long double *) *p_argv;
163
199
  else
164
200
  *(long double *) next_arg = *(long double *) *p_argv;
165
201
  next_arg += 2;
166
202
  fparg_count += 2;
167
- #else
203
+ # else
168
204
  double_tmp = ((double *) *p_argv)[0];
169
205
  if (fparg_count < NUM_FPR_ARG_REGISTERS)
170
206
  *fpr_base++ = double_tmp;
171
- else
172
- *(double *) next_arg = double_tmp;
207
+ *(double *) next_arg = double_tmp;
208
+ # if defined(POWERPC_DARWIN64)
209
+ next_arg++;
210
+ gp_count++;
211
+ # else
173
212
  next_arg += 2;
213
+ gp_count += 2;
214
+ # endif
174
215
  fparg_count++;
175
-
176
216
  double_tmp = ((double *) *p_argv)[1];
177
217
  if (fparg_count < NUM_FPR_ARG_REGISTERS)
178
218
  *fpr_base++ = double_tmp;
179
- else
180
- *(double *) next_arg = double_tmp;
219
+ *(double *) next_arg = double_tmp;
220
+ # if defined(POWERPC_DARWIN64)
221
+ next_arg++;
222
+ gp_count++;
223
+ # else
181
224
  next_arg += 2;
225
+ gp_count += 2;
226
+ # endif
182
227
  fparg_count++;
183
- #endif
228
+ # endif
184
229
  FFI_ASSERT(flags & FLAG_FP_ARGUMENTS);
185
230
  break;
186
231
  #endif
@@ -192,6 +237,7 @@ ffi_prep_args (extended_cif *ecif, unsigned long *const stack)
192
237
  #else
193
238
  *(long long *) next_arg = *(long long *) *p_argv;
194
239
  next_arg += 2;
240
+ gp_count += 2;
195
241
  #endif
196
242
  break;
197
243
  case FFI_TYPE_POINTER:
@@ -211,32 +257,35 @@ ffi_prep_args (extended_cif *ecif, unsigned long *const stack)
211
257
  goto putgpr;
212
258
 
213
259
  case FFI_TYPE_STRUCT:
214
- #ifdef POWERPC64
215
- dest_cpy = (char *) next_arg;
216
260
  size_al = (*ptr)->size;
217
- if ((*ptr)->elements[0]->type == 3)
218
- size_al = ALIGN((*ptr)->size, 8);
219
- if (size_al < 3 && abi == FFI_DARWIN)
220
- dest_cpy += 4 - size_al;
221
-
222
- memcpy ((char *) dest_cpy, (char *) *p_argv, size_al);
223
- next_arg += (size_al + 7) / 8;
261
+ #if defined(POWERPC_DARWIN64)
262
+ next_arg = (unsigned long *)FFI_ALIGN((char *)next_arg, (*ptr)->alignment);
263
+ darwin64_pass_struct_by_value (*ptr, (char *) *p_argv,
264
+ (unsigned) size_al,
265
+ (unsigned int *) &fparg_count,
266
+ &fpr_base, &next_arg);
224
267
  #else
225
268
  dest_cpy = (char *) next_arg;
226
269
 
270
+ /* If the first member of the struct is a double, then include enough
271
+ padding in the struct size to align it to double-word. */
272
+ if ((*ptr)->elements[0]->type == FFI_TYPE_DOUBLE)
273
+ size_al = FFI_ALIGN((*ptr)->size, 8);
274
+
275
+ # if defined(POWERPC64)
276
+ FFI_ASSERT (abi != FFI_DARWIN);
277
+ memcpy ((char *) dest_cpy, (char *) *p_argv, size_al);
278
+ next_arg += (size_al + 7) / 8;
279
+ # else
227
280
  /* Structures that match the basic modes (QI 1 byte, HI 2 bytes,
228
281
  SI 4 bytes) are aligned as if they were those modes.
229
282
  Structures with 3 byte in size are padded upwards. */
230
- size_al = (*ptr)->size;
231
- /* If the first member of the struct is a double, then align
232
- the struct to double-word. */
233
- if ((*ptr)->elements[0]->type == FFI_TYPE_DOUBLE)
234
- size_al = ALIGN((*ptr)->size, 8);
235
283
  if (size_al < 3 && abi == FFI_DARWIN)
236
284
  dest_cpy += 4 - size_al;
237
285
 
238
286
  memcpy((char *) dest_cpy, (char *) *p_argv, size_al);
239
287
  next_arg += (size_al + 3) / 4;
288
+ # endif
240
289
  #endif
241
290
  break;
242
291
 
@@ -249,6 +298,7 @@ ffi_prep_args (extended_cif *ecif, unsigned long *const stack)
249
298
  gprvalue = *(unsigned int *) *p_argv;
250
299
  putgpr:
251
300
  *next_arg++ = gprvalue;
301
+ gp_count++;
252
302
  break;
253
303
  default:
254
304
  break;
@@ -256,14 +306,275 @@ ffi_prep_args (extended_cif *ecif, unsigned long *const stack)
256
306
  }
257
307
 
258
308
  /* Check that we didn't overrun the stack... */
259
- //FFI_ASSERT(gpr_base <= stacktop - ASM_NEEDS_REGISTERS);
260
- //FFI_ASSERT((unsigned *)fpr_base
261
- // <= stacktop - ASM_NEEDS_REGISTERS - NUM_GPR_ARG_REGISTERS);
262
- //FFI_ASSERT(flags & FLAG_4_GPR_ARGUMENTS || intarg_count <= 4);
309
+ /* FFI_ASSERT(gpr_base <= stacktop - ASM_NEEDS_REGISTERS);
310
+ FFI_ASSERT((unsigned *)fpr_base
311
+ <= stacktop - ASM_NEEDS_REGISTERS - NUM_GPR_ARG_REGISTERS);
312
+ FFI_ASSERT(flags & FLAG_4_GPR_ARGUMENTS || intarg_count <= 4); */
313
+ }
314
+
315
+ #if defined(POWERPC_DARWIN64)
316
+
317
+ /* See if we can put some of the struct into fprs.
318
+ This should not be called for structures of size 16 bytes, since these are not
319
+ broken out this way. */
320
+ static void
321
+ darwin64_scan_struct_for_floats (ffi_type *s, unsigned *nfpr)
322
+ {
323
+ int i;
324
+
325
+ FFI_ASSERT (s->type == FFI_TYPE_STRUCT)
326
+
327
+ for (i = 0; s->elements[i] != NULL; i++)
328
+ {
329
+ ffi_type *p = s->elements[i];
330
+ switch (p->type)
331
+ {
332
+ case FFI_TYPE_STRUCT:
333
+ darwin64_scan_struct_for_floats (p, nfpr);
334
+ break;
335
+ case FFI_TYPE_LONGDOUBLE:
336
+ (*nfpr) += 2;
337
+ break;
338
+ case FFI_TYPE_DOUBLE:
339
+ case FFI_TYPE_FLOAT:
340
+ (*nfpr) += 1;
341
+ break;
342
+ default:
343
+ break;
344
+ }
345
+ }
346
+ }
347
+
348
+ static int
349
+ darwin64_struct_size_exceeds_gprs_p (ffi_type *s, char *src, unsigned *nfpr)
350
+ {
351
+ unsigned struct_offset=0, i;
352
+
353
+ for (i = 0; s->elements[i] != NULL; i++)
354
+ {
355
+ char *item_base;
356
+ ffi_type *p = s->elements[i];
357
+ /* Find the start of this item (0 for the first one). */
358
+ if (i > 0)
359
+ struct_offset = FFI_ALIGN(struct_offset, p->alignment);
360
+
361
+ item_base = src + struct_offset;
362
+
363
+ switch (p->type)
364
+ {
365
+ case FFI_TYPE_STRUCT:
366
+ if (darwin64_struct_size_exceeds_gprs_p (p, item_base, nfpr))
367
+ return 1;
368
+ break;
369
+ case FFI_TYPE_LONGDOUBLE:
370
+ if (*nfpr >= NUM_FPR_ARG_REGISTERS)
371
+ return 1;
372
+ (*nfpr) += 1;
373
+ item_base += 8;
374
+ /* FALL THROUGH */
375
+ case FFI_TYPE_DOUBLE:
376
+ if (*nfpr >= NUM_FPR_ARG_REGISTERS)
377
+ return 1;
378
+ (*nfpr) += 1;
379
+ break;
380
+ case FFI_TYPE_FLOAT:
381
+ if (*nfpr >= NUM_FPR_ARG_REGISTERS)
382
+ return 1;
383
+ (*nfpr) += 1;
384
+ break;
385
+ default:
386
+ /* If we try and place any item, that is non-float, once we've
387
+ exceeded the 8 GPR mark, then we can't fit the struct. */
388
+ if ((unsigned long)item_base >= 8*8)
389
+ return 1;
390
+ break;
391
+ }
392
+ /* now count the size of what we just used. */
393
+ struct_offset += p->size;
394
+ }
395
+ return 0;
396
+ }
397
+
398
+ /* Can this struct be returned by value? */
399
+ int
400
+ darwin64_struct_ret_by_value_p (ffi_type *s)
401
+ {
402
+ unsigned nfp = 0;
403
+
404
+ FFI_ASSERT (s && s->type == FFI_TYPE_STRUCT);
405
+
406
+ /* The largest structure we can return is 8long + 13 doubles. */
407
+ if (s->size > 168)
408
+ return 0;
409
+
410
+ /* We can't pass more than 13 floats. */
411
+ darwin64_scan_struct_for_floats (s, &nfp);
412
+ if (nfp > 13)
413
+ return 0;
414
+
415
+ /* If there are not too many floats, and the struct is
416
+ small enough to accommodate in the GPRs, then it must be OK. */
417
+ if (s->size <= 64)
418
+ return 1;
419
+
420
+ /* Well, we have to look harder. */
421
+ nfp = 0;
422
+ if (darwin64_struct_size_exceeds_gprs_p (s, NULL, &nfp))
423
+ return 0;
424
+
425
+ return 1;
426
+ }
427
+
428
+ void
429
+ darwin64_pass_struct_floats (ffi_type *s, char *src,
430
+ unsigned *nfpr, double **fprs)
431
+ {
432
+ int i;
433
+ double *fpr_base = *fprs;
434
+ unsigned struct_offset = 0;
435
+
436
+ /* We don't assume anything about the alignment of the source. */
437
+ for (i = 0; s->elements[i] != NULL; i++)
438
+ {
439
+ char *item_base;
440
+ ffi_type *p = s->elements[i];
441
+ /* Find the start of this item (0 for the first one). */
442
+ if (i > 0)
443
+ struct_offset = FFI_ALIGN(struct_offset, p->alignment);
444
+ item_base = src + struct_offset;
445
+
446
+ switch (p->type)
447
+ {
448
+ case FFI_TYPE_STRUCT:
449
+ darwin64_pass_struct_floats (p, item_base, nfpr,
450
+ &fpr_base);
451
+ break;
452
+ case FFI_TYPE_LONGDOUBLE:
453
+ if (*nfpr < NUM_FPR_ARG_REGISTERS)
454
+ *fpr_base++ = *(double *)item_base;
455
+ (*nfpr) += 1;
456
+ item_base += 8;
457
+ /* FALL THROUGH */
458
+ case FFI_TYPE_DOUBLE:
459
+ if (*nfpr < NUM_FPR_ARG_REGISTERS)
460
+ *fpr_base++ = *(double *)item_base;
461
+ (*nfpr) += 1;
462
+ break;
463
+ case FFI_TYPE_FLOAT:
464
+ if (*nfpr < NUM_FPR_ARG_REGISTERS)
465
+ *fpr_base++ = (double) *(float *)item_base;
466
+ (*nfpr) += 1;
467
+ break;
468
+ default:
469
+ break;
470
+ }
471
+ /* now count the size of what we just used. */
472
+ struct_offset += p->size;
473
+ }
474
+ /* Update the scores. */
475
+ *fprs = fpr_base;
476
+ }
477
+
478
+ /* Darwin64 special rules.
479
+ Break out a struct into params and float registers. */
480
+ static void
481
+ darwin64_pass_struct_by_value (ffi_type *s, char *src, unsigned size,
482
+ unsigned *nfpr, double **fprs, unsigned long **arg)
483
+ {
484
+ unsigned long *next_arg = *arg;
485
+ char *dest_cpy = (char *)next_arg;
486
+
487
+ FFI_ASSERT (s->type == FFI_TYPE_STRUCT)
488
+
489
+ if (!size)
490
+ return;
491
+
492
+ /* First... special cases. */
493
+ if (size < 3
494
+ || (size == 4
495
+ && s->elements[0]
496
+ && s->elements[0]->type != FFI_TYPE_FLOAT))
497
+ {
498
+ /* Must be at least one GPR, padding is unspecified in value,
499
+ let's make it zero. */
500
+ *next_arg = 0UL;
501
+ dest_cpy += 8 - size;
502
+ memcpy ((char *) dest_cpy, src, size);
503
+ next_arg++;
504
+ }
505
+ else if (size == 16)
506
+ {
507
+ memcpy ((char *) dest_cpy, src, size);
508
+ next_arg += 2;
509
+ }
510
+ else
511
+ {
512
+ /* now the general case, we consider embedded floats. */
513
+ memcpy ((char *) dest_cpy, src, size);
514
+ darwin64_pass_struct_floats (s, src, nfpr, fprs);
515
+ next_arg += (size+7)/8;
516
+ }
517
+
518
+ *arg = next_arg;
519
+ }
520
+
521
+ double *
522
+ darwin64_struct_floats_to_mem (ffi_type *s, char *dest, double *fprs, unsigned *nf)
523
+ {
524
+ int i;
525
+ unsigned struct_offset = 0;
526
+
527
+ /* We don't assume anything about the alignment of the source. */
528
+ for (i = 0; s->elements[i] != NULL; i++)
529
+ {
530
+ char *item_base;
531
+ ffi_type *p = s->elements[i];
532
+ /* Find the start of this item (0 for the first one). */
533
+ if (i > 0)
534
+ struct_offset = FFI_ALIGN(struct_offset, p->alignment);
535
+ item_base = dest + struct_offset;
536
+
537
+ switch (p->type)
538
+ {
539
+ case FFI_TYPE_STRUCT:
540
+ fprs = darwin64_struct_floats_to_mem (p, item_base, fprs, nf);
541
+ break;
542
+ case FFI_TYPE_LONGDOUBLE:
543
+ if (*nf < NUM_FPR_ARG_REGISTERS)
544
+ {
545
+ *(double *)item_base = *fprs++ ;
546
+ (*nf) += 1;
547
+ }
548
+ item_base += 8;
549
+ /* FALL THROUGH */
550
+ case FFI_TYPE_DOUBLE:
551
+ if (*nf < NUM_FPR_ARG_REGISTERS)
552
+ {
553
+ *(double *)item_base = *fprs++ ;
554
+ (*nf) += 1;
555
+ }
556
+ break;
557
+ case FFI_TYPE_FLOAT:
558
+ if (*nf < NUM_FPR_ARG_REGISTERS)
559
+ {
560
+ *(float *)item_base = (float) *fprs++ ;
561
+ (*nf) += 1;
562
+ }
563
+ break;
564
+ default:
565
+ break;
566
+ }
567
+ /* now count the size of what we just used. */
568
+ struct_offset += p->size;
569
+ }
570
+ return fprs;
263
571
  }
264
572
 
573
+ #endif
574
+
265
575
  /* Adjust the size of S to be correct for Darwin.
266
- On Darwin, the first field of a structure has natural alignment. */
576
+ On Darwin m32, the first field of a structure has natural alignment.
577
+ On Darwin m64, all fields have natural alignment. */
267
578
 
268
579
  static void
269
580
  darwin_adjust_aggregate_sizes (ffi_type *s)
@@ -280,22 +591,29 @@ darwin_adjust_aggregate_sizes (ffi_type *s)
280
591
  int align;
281
592
 
282
593
  p = s->elements[i];
283
- darwin_adjust_aggregate_sizes (p);
284
- if (i == 0
285
- && (p->type == FFI_TYPE_UINT64
286
- || p->type == FFI_TYPE_SINT64
287
- || p->type == FFI_TYPE_DOUBLE
288
- || p->alignment == 8))
289
- align = 8;
594
+ if (p->type == FFI_TYPE_STRUCT)
595
+ darwin_adjust_aggregate_sizes (p);
596
+ #if defined(POWERPC_DARWIN64)
597
+ /* Natural alignment for all items. */
598
+ align = p->alignment;
599
+ #else
600
+ /* Natural alignment for the first item... */
601
+ if (i == 0)
602
+ align = p->alignment;
290
603
  else if (p->alignment == 16 || p->alignment < 4)
604
+ /* .. subsequent items with vector or align < 4 have natural align. */
291
605
  align = p->alignment;
292
606
  else
607
+ /* .. or align is 4. */
293
608
  align = 4;
294
- s->size = ALIGN(s->size, align) + p->size;
609
+ #endif
610
+ /* Pad, if necessary, before adding the current item. */
611
+ s->size = FFI_ALIGN(s->size, align) + p->size;
295
612
  }
296
613
 
297
- s->size = ALIGN(s->size, s->alignment);
614
+ s->size = FFI_ALIGN(s->size, s->alignment);
298
615
 
616
+ /* This should not be necessary on m64, but harmless. */
299
617
  if (s->elements[0]->type == FFI_TYPE_UINT64
300
618
  || s->elements[0]->type == FFI_TYPE_SINT64
301
619
  || s->elements[0]->type == FFI_TYPE_DOUBLE
@@ -305,38 +623,50 @@ darwin_adjust_aggregate_sizes (ffi_type *s)
305
623
  }
306
624
 
307
625
  /* Adjust the size of S to be correct for AIX.
308
- Word-align double unless it is the first member of a structure. */
626
+ Word-align double unless it is the first member of a structure recursively.
627
+ Return non-zero if we found a recursive first member aggregate of interest. */
309
628
 
310
- static void
311
- aix_adjust_aggregate_sizes (ffi_type *s)
629
+ static int
630
+ aix_adjust_aggregate_sizes (ffi_type *s, int outer_most_type_or_first_member)
312
631
  {
313
- int i;
632
+ int i, nested_first_member=0, final_align, rc=0;
314
633
 
315
634
  if (s->type != FFI_TYPE_STRUCT)
316
- return;
635
+ return 0;
317
636
 
318
637
  s->size = 0;
319
638
  for (i = 0; s->elements[i] != NULL; i++)
320
639
  {
321
- ffi_type *p;
640
+ ffi_type p;
322
641
  int align;
323
-
324
- p = s->elements[i];
325
- aix_adjust_aggregate_sizes (p);
326
- align = p->alignment;
327
- if (i != 0 && p->type == FFI_TYPE_DOUBLE)
328
- align = 4;
329
- s->size = ALIGN(s->size, align) + p->size;
642
+
643
+ /* nested aggregates layout differently on AIX, so take a copy of the type */
644
+ p = *(s->elements[i]);
645
+ if (i == 0)
646
+ nested_first_member = aix_adjust_aggregate_sizes(&p, outer_most_type_or_first_member);
647
+ else
648
+ aix_adjust_aggregate_sizes(&p, 0);
649
+ align = p.alignment;
650
+ if (i != 0 && p.type == FFI_TYPE_DOUBLE)
651
+ align = 4;
652
+ s->size = FFI_ALIGN(s->size, align) + p.size;
330
653
  }
331
-
332
- s->size = ALIGN(s->size, s->alignment);
333
-
334
- if (s->elements[0]->type == FFI_TYPE_UINT64
335
- || s->elements[0]->type == FFI_TYPE_SINT64
336
- || s->elements[0]->type == FFI_TYPE_DOUBLE
337
- || s->elements[0]->alignment == 8)
338
- s->alignment = s->alignment > 8 ? s->alignment : 8;
339
- /* Do not add additional tail padding. */
654
+
655
+ final_align=s->alignment;
656
+ if ((s->elements[0]->type == FFI_TYPE_UINT64
657
+ || s->elements[0]->type == FFI_TYPE_SINT64
658
+ || s->elements[0]->type == FFI_TYPE_DOUBLE
659
+ || s->elements[0]->alignment == 8 || nested_first_member)) {
660
+ final_align = s->alignment > 8 ? s->alignment : 8;
661
+ rc=1;
662
+ /* still use the adjusted alignment to calculate tail padding, but don't adjust the types alignment if
663
+ we aren't in the recursive first position */
664
+ if (outer_most_type_or_first_member)
665
+ s->alignment=final_align;
666
+ }
667
+
668
+ s->size = FFI_ALIGN(s->size, final_align);
669
+ return rc;
340
670
  }
341
671
 
342
672
  /* Perform machine dependent cif processing. */
@@ -344,10 +674,10 @@ ffi_status
344
674
  ffi_prep_cif_machdep (ffi_cif *cif)
345
675
  {
346
676
  /* All this is for the DARWIN ABI. */
347
- int i;
677
+ unsigned i;
348
678
  ffi_type **ptr;
349
679
  unsigned bytes;
350
- int fparg_count = 0, intarg_count = 0;
680
+ unsigned fparg_count = 0, intarg_count = 0;
351
681
  unsigned flags = 0;
352
682
  unsigned size_al = 0;
353
683
 
@@ -364,24 +694,33 @@ ffi_prep_cif_machdep (ffi_cif *cif)
364
694
 
365
695
  if (cif->abi == FFI_AIX)
366
696
  {
367
- aix_adjust_aggregate_sizes (cif->rtype);
697
+ aix_adjust_aggregate_sizes (cif->rtype, 1);
368
698
  for (i = 0; i < cif->nargs; i++)
369
- aix_adjust_aggregate_sizes (cif->arg_types[i]);
699
+ aix_adjust_aggregate_sizes (cif->arg_types[i], 1);
370
700
  }
371
701
 
372
702
  /* Space for the frame pointer, callee's LR, CR, etc, and for
373
703
  the asm's temp regs. */
374
704
 
375
- bytes = (6 + ASM_NEEDS_REGISTERS) * sizeof(long);
705
+ bytes = (LINKAGE_AREA_GPRS + ASM_NEEDS_REGISTERS) * sizeof(unsigned long);
376
706
 
377
- /* Return value handling. The rules are as follows:
707
+ /* Return value handling.
708
+ The rules m32 are as follows:
378
709
  - 32-bit (or less) integer values are returned in gpr3;
379
- - Structures of size <= 4 bytes also returned in gpr3;
380
- - 64-bit integer values and structures between 5 and 8 bytes are returned
381
- in gpr3 and gpr4;
710
+ - structures of size <= 4 bytes also returned in gpr3;
711
+ - 64-bit integer values [??? and structures between 5 and 8 bytes] are
712
+ returned in gpr3 and gpr4;
382
713
  - Single/double FP values are returned in fpr1;
383
714
  - Long double FP (if not equivalent to double) values are returned in
384
715
  fpr1 and fpr2;
716
+ m64:
717
+ - 64-bit or smaller integral values are returned in GPR3
718
+ - Single/double FP values are returned in fpr1;
719
+ - Long double FP values are returned in fpr1 and fpr2;
720
+ m64 Structures:
721
+ - If the structure could be accommodated in registers were it to be the
722
+ first argument to a routine, then it is returned in those registers.
723
+ m32/m64 structures otherwise:
385
724
  - Larger structures values are allocated space and a pointer is passed
386
725
  as the first argument. */
387
726
  switch (cif->rtype->type)
@@ -410,9 +749,42 @@ ffi_prep_cif_machdep (ffi_cif *cif)
410
749
  break;
411
750
 
412
751
  case FFI_TYPE_STRUCT:
752
+ #if defined(POWERPC_DARWIN64)
753
+ {
754
+ /* Can we fit the struct into regs? */
755
+ if (darwin64_struct_ret_by_value_p (cif->rtype))
756
+ {
757
+ unsigned nfpr = 0;
758
+ flags |= FLAG_RETURNS_STRUCT;
759
+ if (cif->rtype->size != 16)
760
+ darwin64_scan_struct_for_floats (cif->rtype, &nfpr) ;
761
+ else
762
+ flags |= FLAG_RETURNS_128BITS;
763
+ /* Will be 0 for 16byte struct. */
764
+ if (nfpr)
765
+ flags |= FLAG_RETURNS_FP;
766
+ }
767
+ else /* By ref. */
768
+ {
769
+ flags |= FLAG_RETVAL_REFERENCE;
770
+ flags |= FLAG_RETURNS_NOTHING;
771
+ intarg_count++;
772
+ }
773
+ }
774
+ #elif defined(DARWIN_PPC)
775
+ if (cif->rtype->size <= 4)
776
+ flags |= FLAG_RETURNS_STRUCT;
777
+ else /* else by reference. */
778
+ {
779
+ flags |= FLAG_RETVAL_REFERENCE;
780
+ flags |= FLAG_RETURNS_NOTHING;
781
+ intarg_count++;
782
+ }
783
+ #else /* assume we pass by ref. */
413
784
  flags |= FLAG_RETVAL_REFERENCE;
414
785
  flags |= FLAG_RETURNS_NOTHING;
415
786
  intarg_count++;
787
+ #endif
416
788
  break;
417
789
  case FFI_TYPE_VOID:
418
790
  flags |= FLAG_RETURNS_NOTHING;
@@ -425,57 +797,83 @@ ffi_prep_cif_machdep (ffi_cif *cif)
425
797
 
426
798
  /* The first NUM_GPR_ARG_REGISTERS words of integer arguments, and the
427
799
  first NUM_FPR_ARG_REGISTERS fp arguments, go in registers; the rest
428
- goes on the stack. Structures are passed as a pointer to a copy of
429
- the structure. Stuff on the stack needs to keep proper alignment. */
800
+ goes on the stack.
801
+ ??? Structures are passed as a pointer to a copy of the structure.
802
+ Stuff on the stack needs to keep proper alignment.
803
+ For m64 the count is effectively of half-GPRs. */
430
804
  for (ptr = cif->arg_types, i = cif->nargs; i > 0; i--, ptr++)
431
805
  {
806
+ unsigned align_words;
432
807
  switch ((*ptr)->type)
433
808
  {
434
809
  case FFI_TYPE_FLOAT:
435
810
  case FFI_TYPE_DOUBLE:
436
811
  fparg_count++;
812
+ #if !defined(POWERPC_DARWIN64)
437
813
  /* If this FP arg is going on the stack, it must be
438
814
  8-byte-aligned. */
439
815
  if (fparg_count > NUM_FPR_ARG_REGISTERS
440
- && intarg_count%2 != 0)
816
+ && (intarg_count & 0x01) != 0)
441
817
  intarg_count++;
818
+ #endif
442
819
  break;
443
820
 
444
821
  #if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
445
-
446
822
  case FFI_TYPE_LONGDOUBLE:
447
823
  fparg_count += 2;
448
824
  /* If this FP arg is going on the stack, it must be
449
- 8-byte-aligned. */
450
- if (fparg_count > NUM_FPR_ARG_REGISTERS
451
- && intarg_count%2 != 0)
452
- intarg_count++;
453
- intarg_count +=2;
825
+ 16-byte-aligned. */
826
+ if (fparg_count >= NUM_FPR_ARG_REGISTERS)
827
+ #if defined (POWERPC64)
828
+ intarg_count = FFI_ALIGN(intarg_count, 2);
829
+ #else
830
+ intarg_count = FFI_ALIGN(intarg_count, 4);
831
+ #endif
454
832
  break;
455
833
  #endif
456
834
 
457
835
  case FFI_TYPE_UINT64:
458
836
  case FFI_TYPE_SINT64:
837
+ #if defined(POWERPC64)
838
+ intarg_count++;
839
+ #else
459
840
  /* 'long long' arguments are passed as two words, but
460
841
  either both words must fit in registers or both go
461
842
  on the stack. If they go on the stack, they must
462
843
  be 8-byte-aligned. */
463
844
  if (intarg_count == NUM_GPR_ARG_REGISTERS-1
464
- || (intarg_count >= NUM_GPR_ARG_REGISTERS && intarg_count%2 != 0))
845
+ || (intarg_count >= NUM_GPR_ARG_REGISTERS
846
+ && (intarg_count & 0x01) != 0))
465
847
  intarg_count++;
466
848
  intarg_count += 2;
849
+ #endif
467
850
  break;
468
851
 
469
852
  case FFI_TYPE_STRUCT:
470
853
  size_al = (*ptr)->size;
854
+ #if defined(POWERPC_DARWIN64)
855
+ align_words = (*ptr)->alignment >> 3;
856
+ if (align_words)
857
+ intarg_count = FFI_ALIGN(intarg_count, align_words);
858
+ /* Base size of the struct. */
859
+ intarg_count += (size_al + 7) / 8;
860
+ /* If 16 bytes then don't worry about floats. */
861
+ if (size_al != 16)
862
+ /* Scan through for floats to be placed in regs. */
863
+ darwin64_scan_struct_for_floats (*ptr, &fparg_count) ;
864
+ #else
865
+ align_words = (*ptr)->alignment >> 2;
866
+ if (align_words)
867
+ intarg_count = FFI_ALIGN(intarg_count, align_words);
471
868
  /* If the first member of the struct is a double, then align
472
- the struct to double-word. */
869
+ the struct to double-word.
473
870
  if ((*ptr)->elements[0]->type == FFI_TYPE_DOUBLE)
474
- size_al = ALIGN((*ptr)->size, 8);
475
- #ifdef POWERPC64
871
+ size_al = FFI_ALIGN((*ptr)->size, 8); */
872
+ # ifdef POWERPC64
476
873
  intarg_count += (size_al + 7) / 8;
477
- #else
874
+ # else
478
875
  intarg_count += (size_al + 3) / 4;
876
+ # endif
479
877
  #endif
480
878
  break;
481
879
 
@@ -490,9 +888,18 @@ ffi_prep_cif_machdep (ffi_cif *cif)
490
888
  if (fparg_count != 0)
491
889
  flags |= FLAG_FP_ARGUMENTS;
492
890
 
891
+ #if defined(POWERPC_DARWIN64)
892
+ /* Space to image the FPR registers, if needed - which includes when they might be
893
+ used in a struct return. */
894
+ if (fparg_count != 0
895
+ || ((flags & FLAG_RETURNS_STRUCT)
896
+ && (flags & FLAG_RETURNS_FP)))
897
+ bytes += NUM_FPR_ARG_REGISTERS * sizeof(double);
898
+ #else
493
899
  /* Space for the FPR registers, if needed. */
494
900
  if (fparg_count != 0)
495
901
  bytes += NUM_FPR_ARG_REGISTERS * sizeof(double);
902
+ #endif
496
903
 
497
904
  /* Stack space. */
498
905
  #ifdef POWERPC64
@@ -506,7 +913,7 @@ ffi_prep_cif_machdep (ffi_cif *cif)
506
913
  bytes += NUM_GPR_ARG_REGISTERS * sizeof(long);
507
914
 
508
915
  /* The stack space allocated needs to be a multiple of 16 bytes. */
509
- bytes = (bytes + 15) & ~0xF;
916
+ bytes = FFI_ALIGN(bytes, 16) ;
510
917
 
511
918
  cif->flags = flags;
512
919
  cif->bytes = bytes;
@@ -516,8 +923,14 @@ ffi_prep_cif_machdep (ffi_cif *cif)
516
923
 
517
924
  extern void ffi_call_AIX(extended_cif *, long, unsigned, unsigned *,
518
925
  void (*fn)(void), void (*fn2)(void));
926
+
927
+ #if defined (FFI_GO_CLOSURES)
928
+ extern void ffi_call_go_AIX(extended_cif *, long, unsigned, unsigned *,
929
+ void (*fn)(void), void (*fn2)(void), void *closure);
930
+ #endif
931
+
519
932
  extern void ffi_call_DARWIN(extended_cif *, long, unsigned, unsigned *,
520
- void (*fn)(void), void (*fn2)(void));
933
+ void (*fn)(void), void (*fn2)(void), ffi_type*);
521
934
 
522
935
  void
523
936
  ffi_call (ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue)
@@ -542,17 +955,51 @@ ffi_call (ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue)
542
955
  {
543
956
  case FFI_AIX:
544
957
  ffi_call_AIX(&ecif, -(long)cif->bytes, cif->flags, ecif.rvalue, fn,
545
- ffi_prep_args);
958
+ FFI_FN(ffi_prep_args));
546
959
  break;
547
960
  case FFI_DARWIN:
548
961
  ffi_call_DARWIN(&ecif, -(long)cif->bytes, cif->flags, ecif.rvalue, fn,
549
- ffi_prep_args);
962
+ FFI_FN(ffi_prep_args), cif->rtype);
963
+ break;
964
+ default:
965
+ FFI_ASSERT(0);
966
+ break;
967
+ }
968
+ }
969
+
970
+ #if defined (FFI_GO_CLOSURES)
971
+ void
972
+ ffi_call_go (ffi_cif *cif, void (*fn) (void), void *rvalue, void **avalue,
973
+ void *closure)
974
+ {
975
+ extended_cif ecif;
976
+
977
+ ecif.cif = cif;
978
+ ecif.avalue = avalue;
979
+
980
+ /* If the return value is a struct and we don't have a return
981
+ value address then we need to make one. */
982
+
983
+ if ((rvalue == NULL) &&
984
+ (cif->rtype->type == FFI_TYPE_STRUCT))
985
+ {
986
+ ecif.rvalue = alloca (cif->rtype->size);
987
+ }
988
+ else
989
+ ecif.rvalue = rvalue;
990
+
991
+ switch (cif->abi)
992
+ {
993
+ case FFI_AIX:
994
+ ffi_call_go_AIX(&ecif, -(long)cif->bytes, cif->flags, ecif.rvalue, fn,
995
+ FFI_FN(ffi_prep_args), closure);
550
996
  break;
551
997
  default:
552
998
  FFI_ASSERT(0);
553
999
  break;
554
1000
  }
555
1001
  }
1002
+ #endif
556
1003
 
557
1004
  static void flush_icache(char *);
558
1005
  static void flush_range(char *, int);
@@ -566,58 +1013,48 @@ typedef struct aix_fd_struct {
566
1013
  } aix_fd;
567
1014
 
568
1015
  /* here I'd like to add the stack frame layout we use in darwin_closure.S
569
- and aix_clsoure.S
570
-
571
- SP previous -> +---------------------------------------+ <--- child frame
572
- | back chain to caller 4 |
573
- +---------------------------------------+ 4
574
- | saved CR 4 |
575
- +---------------------------------------+ 8
576
- | saved LR 4 |
577
- +---------------------------------------+ 12
578
- | reserved for compilers 4 |
579
- +---------------------------------------+ 16
580
- | reserved for binders 4 |
581
- +---------------------------------------+ 20
582
- | saved TOC pointer 4 |
583
- +---------------------------------------+ 24
584
- | always reserved 8*4=32 (previous GPRs)|
585
- | according to the linkage convention |
586
- | from AIX |
587
- +---------------------------------------+ 56
588
- | our FPR area 13*8=104 |
589
- | f1 |
590
- | . |
591
- | f13 |
592
- +---------------------------------------+ 160
593
- | result area 8 |
594
- +---------------------------------------+ 168
595
- | alignement to the next multiple of 16 |
596
- SP current --> +---------------------------------------+ 176 <- parent frame
597
- | back chain to caller 4 |
598
- +---------------------------------------+ 180
599
- | saved CR 4 |
600
- +---------------------------------------+ 184
601
- | saved LR 4 |
602
- +---------------------------------------+ 188
603
- | reserved for compilers 4 |
604
- +---------------------------------------+ 192
605
- | reserved for binders 4 |
606
- +---------------------------------------+ 196
607
- | saved TOC pointer 4 |
608
- +---------------------------------------+ 200
609
- | always reserved 8*4=32 we store our |
610
- | GPRs here |
611
- | r3 |
612
- | . |
613
- | r10 |
614
- +---------------------------------------+ 232
615
- | overflow part |
616
- +---------------------------------------+ xxx
617
- | ???? |
618
- +---------------------------------------+ xxx
1016
+ and aix_closure.S
1017
+
1018
+ m32/m64
1019
+
1020
+ The stack layout looks like this:
1021
+
1022
+ | Additional params... | | Higher address
1023
+ ~ ~ ~
1024
+ | Parameters (at least 8*4/8=32/64) | | NUM_GPR_ARG_REGISTERS
1025
+ |--------------------------------------------| |
1026
+ | TOC=R2 (AIX) Reserved (Darwin) 4/8 | |
1027
+ |--------------------------------------------| |
1028
+ | Reserved 2*4/8 | |
1029
+ |--------------------------------------------| |
1030
+ | Space for callee's LR 4/8 | |
1031
+ |--------------------------------------------| |
1032
+ | Saved CR [low word for m64] 4/8 | |
1033
+ |--------------------------------------------| |
1034
+ | Current backchain pointer 4/8 |-/ Parent's frame.
1035
+ |--------------------------------------------| <+ <<< on entry to ffi_closure_ASM
1036
+ | Result Bytes 16 | |
1037
+ |--------------------------------------------| |
1038
+ ~ padding to 16-byte alignment ~ ~
1039
+ |--------------------------------------------| |
1040
+ | NUM_FPR_ARG_REGISTERS slots | |
1041
+ | here fp13 .. fp1 13*8 | |
1042
+ |--------------------------------------------| |
1043
+ | R3..R10 8*4/8=32/64 | | NUM_GPR_ARG_REGISTERS
1044
+ |--------------------------------------------| |
1045
+ | TOC=R2 (AIX) Reserved (Darwin) 4/8 | |
1046
+ |--------------------------------------------| | stack |
1047
+ | Reserved [compiler,binder] 2*4/8 | | grows |
1048
+ |--------------------------------------------| | down V
1049
+ | Space for callee's LR 4/8 | |
1050
+ |--------------------------------------------| | lower addresses
1051
+ | Saved CR [low word for m64] 4/8 | |
1052
+ |--------------------------------------------| | stack pointer here
1053
+ | Current backchain pointer 4/8 |-/ during
1054
+ |--------------------------------------------| <<< ffi_closure_ASM.
619
1055
 
620
1056
  */
1057
+
621
1058
  ffi_status
622
1059
  ffi_prep_closure_loc (ffi_closure* closure,
623
1060
  ffi_cif* cif,
@@ -631,30 +1068,44 @@ ffi_prep_closure_loc (ffi_closure* closure,
631
1068
 
632
1069
  switch (cif->abi)
633
1070
  {
634
- case FFI_DARWIN:
635
-
636
- FFI_ASSERT (cif->abi == FFI_DARWIN);
637
-
638
- tramp = (unsigned int *) &closure->tramp[0];
639
- tramp[0] = 0x7c0802a6; /* mflr r0 */
640
- tramp[1] = 0x429f000d; /* bcl- 20,4*cr7+so,0x10 */
641
- tramp[4] = 0x7d6802a6; /* mflr r11 */
642
- tramp[5] = 0x818b0000; /* lwz r12,0(r11) function address */
643
- tramp[6] = 0x7c0803a6; /* mtlr r0 */
644
- tramp[7] = 0x7d8903a6; /* mtctr r12 */
645
- tramp[8] = 0x816b0004; /* lwz r11,4(r11) static chain */
646
- tramp[9] = 0x4e800420; /* bctr */
647
- tramp[2] = (unsigned long) ffi_closure_ASM; /* function */
648
- tramp[3] = (unsigned long) codeloc; /* context */
649
-
650
- closure->cif = cif;
651
- closure->fun = fun;
652
- closure->user_data = user_data;
1071
+ case FFI_DARWIN:
1072
+
1073
+ FFI_ASSERT (cif->abi == FFI_DARWIN);
1074
+
1075
+ tramp = (unsigned int *) &closure->tramp[0];
1076
+ #if defined(POWERPC_DARWIN64)
1077
+ tramp[0] = 0x7c0802a6; /* mflr r0 */
1078
+ tramp[1] = 0x429f0015; /* bcl- 20,4*cr7+so, +0x18 (L1) */
1079
+ /* We put the addresses here. */
1080
+ tramp[6] = 0x7d6802a6; /*L1: mflr r11 */
1081
+ tramp[7] = 0xe98b0000; /* ld r12,0(r11) function address */
1082
+ tramp[8] = 0x7c0803a6; /* mtlr r0 */
1083
+ tramp[9] = 0x7d8903a6; /* mtctr r12 */
1084
+ tramp[10] = 0xe96b0008; /* lwz r11,8(r11) static chain */
1085
+ tramp[11] = 0x4e800420; /* bctr */
1086
+
1087
+ *((unsigned long *)&tramp[2]) = (unsigned long) ffi_closure_ASM; /* function */
1088
+ *((unsigned long *)&tramp[4]) = (unsigned long) codeloc; /* context */
1089
+ #else
1090
+ tramp[0] = 0x7c0802a6; /* mflr r0 */
1091
+ tramp[1] = 0x429f000d; /* bcl- 20,4*cr7+so,0x10 */
1092
+ tramp[4] = 0x7d6802a6; /* mflr r11 */
1093
+ tramp[5] = 0x818b0000; /* lwz r12,0(r11) function address */
1094
+ tramp[6] = 0x7c0803a6; /* mtlr r0 */
1095
+ tramp[7] = 0x7d8903a6; /* mtctr r12 */
1096
+ tramp[8] = 0x816b0004; /* lwz r11,4(r11) static chain */
1097
+ tramp[9] = 0x4e800420; /* bctr */
1098
+ tramp[2] = (unsigned long) ffi_closure_ASM; /* function */
1099
+ tramp[3] = (unsigned long) codeloc; /* context */
1100
+ #endif
1101
+ closure->cif = cif;
1102
+ closure->fun = fun;
1103
+ closure->user_data = user_data;
653
1104
 
654
- /* Flush the icache. Only necessary on Darwin. */
655
- flush_range(codeloc, FFI_TRAMPOLINE_SIZE);
1105
+ /* Flush the icache. Only necessary on Darwin. */
1106
+ flush_range(codeloc, FFI_TRAMPOLINE_SIZE);
656
1107
 
657
- break;
1108
+ break;
658
1109
 
659
1110
  case FFI_AIX:
660
1111
 
@@ -669,15 +1120,41 @@ ffi_prep_closure_loc (ffi_closure* closure,
669
1120
  closure->cif = cif;
670
1121
  closure->fun = fun;
671
1122
  closure->user_data = user_data;
1123
+ break;
672
1124
 
673
1125
  default:
674
-
675
- FFI_ASSERT(0);
1126
+ return FFI_BAD_ABI;
676
1127
  break;
677
1128
  }
678
1129
  return FFI_OK;
679
1130
  }
680
1131
 
1132
+ #if defined (FFI_GO_CLOSURES)
1133
+ ffi_status
1134
+ ffi_prep_go_closure (ffi_go_closure* closure,
1135
+ ffi_cif* cif,
1136
+ void (*fun)(ffi_cif*, void*, void**, void*))
1137
+ {
1138
+ switch (cif->abi)
1139
+ {
1140
+ case FFI_AIX:
1141
+
1142
+ FFI_ASSERT (cif->abi == FFI_AIX);
1143
+
1144
+ closure->tramp = (void *)ffi_go_closure_ASM;
1145
+ closure->cif = cif;
1146
+ closure->fun = fun;
1147
+ return FFI_OK;
1148
+
1149
+ // For now, ffi_prep_go_closure is only implemented for AIX, not for Darwin
1150
+ default:
1151
+ return FFI_BAD_ABI;
1152
+ break;
1153
+ }
1154
+ return FFI_OK;
1155
+ }
1156
+ #endif
1157
+
681
1158
  static void
682
1159
  flush_icache(char *addr)
683
1160
  {
@@ -708,10 +1185,16 @@ typedef union
708
1185
  double d;
709
1186
  } ffi_dblfl;
710
1187
 
711
- int
1188
+ ffi_type *
712
1189
  ffi_closure_helper_DARWIN (ffi_closure *, void *,
713
1190
  unsigned long *, ffi_dblfl *);
714
1191
 
1192
+ #if defined (FFI_GO_CLOSURES)
1193
+ ffi_type *
1194
+ ffi_go_closure_helper_DARWIN (ffi_go_closure*, void *,
1195
+ unsigned long *, ffi_dblfl *);
1196
+ #endif
1197
+
715
1198
  /* Basically the trampoline invokes ffi_closure_ASM, and on
716
1199
  entry, r11 holds the address of the closure.
717
1200
  After storing the registers that could possibly contain
@@ -719,8 +1202,10 @@ ffi_closure_helper_DARWIN (ffi_closure *, void *,
719
1202
  up space for a return value, ffi_closure_ASM invokes the
720
1203
  following helper function to do most of the work. */
721
1204
 
722
- int
723
- ffi_closure_helper_DARWIN (ffi_closure *closure, void *rvalue,
1205
+ static ffi_type *
1206
+ ffi_closure_helper_common (ffi_cif* cif,
1207
+ void (*fun)(ffi_cif*, void*, void**, void*),
1208
+ void *user_data, void *rvalue,
724
1209
  unsigned long *pgr, ffi_dblfl *pfr)
725
1210
  {
726
1211
  /* rvalue is the pointer to space for return value in closure assembly
@@ -738,19 +1223,33 @@ ffi_closure_helper_DARWIN (ffi_closure *closure, void *rvalue,
738
1223
  void ** avalue;
739
1224
  ffi_type ** arg_types;
740
1225
  long i, avn;
741
- ffi_cif * cif;
742
1226
  ffi_dblfl * end_pfr = pfr + NUM_FPR_ARG_REGISTERS;
743
1227
  unsigned size_al;
1228
+ #if defined(POWERPC_DARWIN64)
1229
+ unsigned fpsused = 0;
1230
+ #endif
744
1231
 
745
- cif = closure->cif;
746
1232
  avalue = alloca (cif->nargs * sizeof(void *));
747
1233
 
748
- /* Copy the caller's structure return value address so that the closure
749
- returns the data directly to the caller. */
750
1234
  if (cif->rtype->type == FFI_TYPE_STRUCT)
751
1235
  {
1236
+ #if defined(POWERPC_DARWIN64)
1237
+ if (!darwin64_struct_ret_by_value_p (cif->rtype))
1238
+ {
1239
+ /* Won't fit into the regs - return by ref. */
1240
+ rvalue = (void *) *pgr;
1241
+ pgr++;
1242
+ }
1243
+ #elif defined(DARWIN_PPC)
1244
+ if (cif->rtype->size > 4)
1245
+ {
1246
+ rvalue = (void *) *pgr;
1247
+ pgr++;
1248
+ }
1249
+ #else /* assume we return by ref. */
752
1250
  rvalue = (void *) *pgr;
753
1251
  pgr++;
1252
+ #endif
754
1253
  }
755
1254
 
756
1255
  i = 0;
@@ -764,7 +1263,7 @@ ffi_closure_helper_DARWIN (ffi_closure *closure, void *rvalue,
764
1263
  {
765
1264
  case FFI_TYPE_SINT8:
766
1265
  case FFI_TYPE_UINT8:
767
- #ifdef POWERPC64
1266
+ #if defined(POWERPC64)
768
1267
  avalue[i] = (char *) pgr + 7;
769
1268
  #else
770
1269
  avalue[i] = (char *) pgr + 3;
@@ -774,7 +1273,7 @@ ffi_closure_helper_DARWIN (ffi_closure *closure, void *rvalue,
774
1273
 
775
1274
  case FFI_TYPE_SINT16:
776
1275
  case FFI_TYPE_UINT16:
777
- #ifdef POWERPC64
1276
+ #if defined(POWERPC64)
778
1277
  avalue[i] = (char *) pgr + 6;
779
1278
  #else
780
1279
  avalue[i] = (char *) pgr + 2;
@@ -784,7 +1283,7 @@ ffi_closure_helper_DARWIN (ffi_closure *closure, void *rvalue,
784
1283
 
785
1284
  case FFI_TYPE_SINT32:
786
1285
  case FFI_TYPE_UINT32:
787
- #ifdef POWERPC64
1286
+ #if defined(POWERPC64)
788
1287
  avalue[i] = (char *) pgr + 4;
789
1288
  #else
790
1289
  case FFI_TYPE_POINTER:
@@ -794,34 +1293,53 @@ ffi_closure_helper_DARWIN (ffi_closure *closure, void *rvalue,
794
1293
  break;
795
1294
 
796
1295
  case FFI_TYPE_STRUCT:
797
- #ifdef POWERPC64
798
1296
  size_al = arg_types[i]->size;
799
- if (arg_types[i]->elements[0]->type == FFI_TYPE_DOUBLE)
800
- size_al = ALIGN (arg_types[i]->size, 8);
801
- if (size_al < 3 && cif->abi == FFI_DARWIN)
802
- avalue[i] = (void *) pgr + 8 - size_al;
803
- else
804
- avalue[i] = (void *) pgr;
1297
+ #if defined(POWERPC_DARWIN64)
1298
+ pgr = (unsigned long *)FFI_ALIGN((char *)pgr, arg_types[i]->alignment);
1299
+ if (size_al < 3 || size_al == 4)
1300
+ {
1301
+ avalue[i] = ((char *)pgr)+8-size_al;
1302
+ if (arg_types[i]->elements[0]->type == FFI_TYPE_FLOAT
1303
+ && fpsused < NUM_FPR_ARG_REGISTERS)
1304
+ {
1305
+ *(float *)pgr = (float) *(double *)pfr;
1306
+ pfr++;
1307
+ fpsused++;
1308
+ }
1309
+ }
1310
+ else
1311
+ {
1312
+ if (size_al != 16)
1313
+ pfr = (ffi_dblfl *)
1314
+ darwin64_struct_floats_to_mem (arg_types[i], (char *)pgr,
1315
+ (double *)pfr, &fpsused);
1316
+ avalue[i] = pgr;
1317
+ }
805
1318
  pgr += (size_al + 7) / 8;
806
1319
  #else
807
- /* Structures that match the basic modes (QI 1 byte, HI 2 bytes,
808
- SI 4 bytes) are aligned as if they were those modes. */
809
- size_al = arg_types[i]->size;
810
1320
  /* If the first member of the struct is a double, then align
811
1321
  the struct to double-word. */
812
1322
  if (arg_types[i]->elements[0]->type == FFI_TYPE_DOUBLE)
813
- size_al = ALIGN(arg_types[i]->size, 8);
1323
+ size_al = FFI_ALIGN(arg_types[i]->size, 8);
1324
+ # if defined(POWERPC64)
1325
+ FFI_ASSERT (cif->abi != FFI_DARWIN);
1326
+ avalue[i] = pgr;
1327
+ pgr += (size_al + 7) / 8;
1328
+ # else
1329
+ /* Structures that match the basic modes (QI 1 byte, HI 2 bytes,
1330
+ SI 4 bytes) are aligned as if they were those modes. */
814
1331
  if (size_al < 3 && cif->abi == FFI_DARWIN)
815
- avalue[i] = (void*) pgr + 4 - size_al;
1332
+ avalue[i] = (char*) pgr + 4 - size_al;
816
1333
  else
817
- avalue[i] = (void*) pgr;
1334
+ avalue[i] = pgr;
818
1335
  pgr += (size_al + 3) / 4;
1336
+ # endif
819
1337
  #endif
820
1338
  break;
821
1339
 
822
1340
  case FFI_TYPE_SINT64:
823
1341
  case FFI_TYPE_UINT64:
824
- #ifdef POWERPC64
1342
+ #if defined(POWERPC64)
825
1343
  case FFI_TYPE_POINTER:
826
1344
  avalue[i] = pgr;
827
1345
  pgr++;
@@ -921,8 +1439,26 @@ ffi_closure_helper_DARWIN (ffi_closure *closure, void *rvalue,
921
1439
  i++;
922
1440
  }
923
1441
 
924
- (closure->fun) (cif, rvalue, avalue, closure->user_data);
1442
+ (fun) (cif, rvalue, avalue, user_data);
925
1443
 
926
1444
  /* Tell ffi_closure_ASM to perform return type promotions. */
927
- return cif->rtype->type;
1445
+ return cif->rtype;
928
1446
  }
1447
+
1448
+ ffi_type *
1449
+ ffi_closure_helper_DARWIN (ffi_closure *closure, void *rvalue,
1450
+ unsigned long *pgr, ffi_dblfl *pfr)
1451
+ {
1452
+ return ffi_closure_helper_common (closure->cif, closure->fun,
1453
+ closure->user_data, rvalue, pgr, pfr);
1454
+ }
1455
+
1456
+ #if defined (FFI_GO_CLOSURES)
1457
+ ffi_type *
1458
+ ffi_go_closure_helper_DARWIN (ffi_go_closure *closure, void *rvalue,
1459
+ unsigned long *pgr, ffi_dblfl *pfr)
1460
+ {
1461
+ return ffi_closure_helper_common (closure->cif, closure->fun,
1462
+ closure, rvalue, pgr, pfr);
1463
+ }
1464
+ #endif