ffi 1.1.5 → 1.15.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (629) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +338 -0
  3. data/COPYING +49 -0
  4. data/Gemfile +14 -0
  5. data/LICENSE +21 -11
  6. data/LICENSE.SPECS +22 -0
  7. data/README.md +136 -0
  8. data/Rakefile +149 -154
  9. data/ext/ffi_c/AbstractMemory.c +133 -57
  10. data/ext/ffi_c/AbstractMemory.h +21 -12
  11. data/ext/ffi_c/ArrayType.c +27 -14
  12. data/ext/ffi_c/ArrayType.h +21 -12
  13. data/ext/ffi_c/Buffer.c +29 -25
  14. data/ext/ffi_c/Call.c +154 -125
  15. data/ext/ffi_c/Call.h +43 -20
  16. data/ext/ffi_c/ClosurePool.c +100 -42
  17. data/ext/ffi_c/ClosurePool.h +24 -13
  18. data/ext/ffi_c/DynamicLibrary.c +47 -28
  19. data/ext/ffi_c/DynamicLibrary.h +70 -12
  20. data/ext/ffi_c/Function.c +119 -167
  21. data/ext/ffi_c/Function.h +23 -19
  22. data/ext/ffi_c/FunctionInfo.c +55 -25
  23. data/ext/ffi_c/LastError.c +70 -21
  24. data/ext/ffi_c/LastError.h +21 -12
  25. data/ext/ffi_c/LongDouble.c +15 -9
  26. data/ext/ffi_c/LongDouble.h +21 -16
  27. data/ext/ffi_c/MappedType.c +22 -15
  28. data/ext/ffi_c/MappedType.h +21 -12
  29. data/ext/ffi_c/MemoryPointer.c +58 -33
  30. data/ext/ffi_c/MemoryPointer.h +22 -19
  31. data/ext/ffi_c/MethodHandle.c +49 -50
  32. data/ext/ffi_c/MethodHandle.h +24 -14
  33. data/ext/ffi_c/Platform.c +28 -62
  34. data/ext/ffi_c/Platform.h +21 -12
  35. data/ext/ffi_c/Pointer.c +63 -46
  36. data/ext/ffi_c/Pointer.h +22 -19
  37. data/ext/ffi_c/Struct.c +198 -80
  38. data/ext/ffi_c/Struct.h +33 -18
  39. data/ext/ffi_c/StructByValue.c +23 -20
  40. data/ext/ffi_c/StructByValue.h +21 -12
  41. data/ext/ffi_c/StructLayout.c +184 -39
  42. data/ext/ffi_c/Thread.c +73 -270
  43. data/ext/ffi_c/Thread.h +32 -35
  44. data/ext/ffi_c/Type.c +26 -32
  45. data/ext/ffi_c/Type.h +24 -10
  46. data/ext/ffi_c/Types.c +28 -20
  47. data/ext/ffi_c/Types.h +25 -16
  48. data/ext/ffi_c/Variadic.c +78 -39
  49. data/ext/ffi_c/compat.h +25 -17
  50. data/ext/ffi_c/extconf.rb +68 -31
  51. data/ext/ffi_c/ffi.c +27 -20
  52. data/ext/ffi_c/libffi/.appveyor.yml +66 -0
  53. data/ext/ffi_c/libffi/.gitattributes +4 -0
  54. data/ext/ffi_c/libffi/.github/issue_template.md +10 -0
  55. data/ext/ffi_c/libffi/.gitignore +38 -0
  56. data/ext/ffi_c/libffi/.travis/ar-lib +270 -0
  57. data/ext/ffi_c/libffi/.travis/bfin-sim.exp +58 -0
  58. data/ext/ffi_c/libffi/.travis/build-cross-in-container.sh +14 -0
  59. data/ext/ffi_c/libffi/.travis/build-in-container.sh +12 -0
  60. data/ext/ffi_c/libffi/.travis/build.sh +142 -0
  61. data/ext/ffi_c/libffi/.travis/compile +351 -0
  62. data/ext/ffi_c/libffi/.travis/install.sh +71 -0
  63. data/ext/ffi_c/libffi/.travis/m32r-sim.exp +58 -0
  64. data/ext/ffi_c/libffi/.travis/moxie-sim.exp +60 -0
  65. data/ext/ffi_c/libffi/.travis/or1k-sim.exp +58 -0
  66. data/ext/ffi_c/libffi/.travis/powerpc-eabisim.exp +58 -0
  67. data/ext/ffi_c/libffi/.travis/site.exp +27 -0
  68. data/ext/ffi_c/libffi/.travis/wine-sim.exp +55 -0
  69. data/ext/ffi_c/libffi/.travis.yml +83 -0
  70. data/ext/ffi_c/libffi/{ChangeLog → ChangeLog.old} +6366 -3559
  71. data/ext/ffi_c/libffi/LICENSE +1 -1
  72. data/ext/ffi_c/libffi/LICENSE-BUILDTOOLS +353 -0
  73. data/ext/ffi_c/libffi/Makefile.am +123 -169
  74. data/ext/ffi_c/libffi/Makefile.in +1243 -1003
  75. data/ext/ffi_c/libffi/README.md +486 -0
  76. data/ext/ffi_c/libffi/acinclude.m4 +387 -0
  77. data/ext/ffi_c/libffi/autogen.sh +2 -0
  78. data/ext/ffi_c/libffi/config.guess +690 -504
  79. data/ext/ffi_c/libffi/config.sub +1353 -1207
  80. data/ext/ffi_c/libffi/configure +7308 -2449
  81. data/ext/ffi_c/libffi/configure.ac +178 -259
  82. data/ext/ffi_c/libffi/configure.host +311 -4
  83. data/ext/ffi_c/libffi/doc/Makefile.am +3 -0
  84. data/ext/ffi_c/libffi/doc/Makefile.in +815 -0
  85. data/ext/ffi_c/libffi/doc/libffi.texi +455 -58
  86. data/ext/ffi_c/libffi/doc/version.texi +4 -4
  87. data/ext/ffi_c/libffi/fficonfig.h.in +37 -13
  88. data/ext/ffi_c/libffi/generate-darwin-source-and-headers.py +201 -0
  89. data/ext/ffi_c/libffi/include/Makefile.am +3 -3
  90. data/ext/ffi_c/libffi/include/Makefile.in +196 -75
  91. data/ext/ffi_c/libffi/include/ffi.h.in +163 -67
  92. data/ext/ffi_c/libffi/include/ffi_cfi.h +55 -0
  93. data/ext/ffi_c/libffi/include/ffi_common.h +39 -12
  94. data/ext/ffi_c/libffi/install-sh +207 -209
  95. data/ext/ffi_c/libffi/libffi.map.in +76 -0
  96. data/ext/ffi_c/libffi/libffi.pc.in +3 -2
  97. data/ext/ffi_c/libffi/libffi.xcodeproj/project.pbxproj +997 -0
  98. data/ext/ffi_c/libffi/libtool-ldflags +106 -0
  99. data/ext/ffi_c/libffi/libtool-version +1 -1
  100. data/ext/ffi_c/libffi/ltmain.sh +3641 -2026
  101. data/ext/ffi_c/libffi/m4/asmcfi.m4 +13 -0
  102. data/ext/ffi_c/libffi/m4/ax_append_flag.m4 +50 -0
  103. data/ext/ffi_c/libffi/m4/ax_cc_maxopt.m4 +32 -14
  104. data/ext/ffi_c/libffi/m4/ax_cflags_warn_all.m4 +33 -106
  105. data/ext/ffi_c/libffi/m4/ax_check_compile_flag.m4 +53 -0
  106. data/ext/ffi_c/libffi/m4/ax_compiler_vendor.m4 +38 -13
  107. data/ext/ffi_c/libffi/m4/ax_configure_args.m4 +8 -29
  108. data/ext/ffi_c/libffi/m4/ax_enable_builddir.m4 +11 -9
  109. data/ext/ffi_c/libffi/m4/ax_gcc_archflag.m4 +104 -52
  110. data/ext/ffi_c/libffi/m4/ax_gcc_x86_cpuid.m4 +18 -8
  111. data/ext/ffi_c/libffi/m4/ax_require_defined.m4 +37 -0
  112. data/ext/ffi_c/libffi/make_sunver.pl +333 -0
  113. data/ext/ffi_c/libffi/man/Makefile.am +2 -2
  114. data/ext/ffi_c/libffi/man/Makefile.in +151 -55
  115. data/ext/ffi_c/libffi/man/ffi.3 +10 -0
  116. data/ext/ffi_c/libffi/man/ffi_prep_cif.3 +6 -4
  117. data/ext/ffi_c/libffi/man/ffi_prep_cif_var.3 +73 -0
  118. data/ext/ffi_c/libffi/missing +153 -314
  119. data/ext/ffi_c/libffi/msvc_build/aarch64/Ffi_staticLib.sln +33 -0
  120. data/ext/ffi_c/libffi/msvc_build/aarch64/Ffi_staticLib.vcxproj +130 -0
  121. data/ext/ffi_c/libffi/msvc_build/aarch64/Ffi_staticLib.vcxproj.filters +57 -0
  122. data/ext/ffi_c/libffi/msvc_build/aarch64/Ffi_staticLib.vcxproj.user +4 -0
  123. data/ext/ffi_c/libffi/{include/ffi.h.vc64 → msvc_build/aarch64/aarch64_include/ffi.h} +151 -67
  124. data/ext/ffi_c/libffi/msvc_build/aarch64/aarch64_include/fficonfig.h +219 -0
  125. data/ext/ffi_c/libffi/msvcc.sh +176 -20
  126. data/ext/ffi_c/libffi/src/aarch64/ffi.c +1025 -0
  127. data/ext/ffi_c/libffi/src/aarch64/ffitarget.h +97 -0
  128. data/ext/ffi_c/libffi/src/aarch64/internal.h +68 -0
  129. data/ext/ffi_c/libffi/src/aarch64/sysv.S +451 -0
  130. data/ext/ffi_c/libffi/src/aarch64/win64_armasm.S +506 -0
  131. data/ext/ffi_c/libffi/src/alpha/ffi.c +335 -98
  132. data/ext/ffi_c/libffi/src/alpha/ffitarget.h +10 -1
  133. data/ext/ffi_c/libffi/src/alpha/internal.h +23 -0
  134. data/ext/ffi_c/libffi/src/alpha/osf.S +161 -266
  135. data/ext/ffi_c/libffi/src/arc/arcompact.S +135 -0
  136. data/ext/ffi_c/libffi/src/arc/ffi.c +266 -0
  137. data/ext/ffi_c/libffi/src/arc/ffitarget.h +53 -0
  138. data/ext/ffi_c/libffi/src/arm/ffi.c +663 -515
  139. data/ext/ffi_c/libffi/src/arm/ffitarget.h +32 -8
  140. data/ext/ffi_c/libffi/src/arm/internal.h +7 -0
  141. data/ext/ffi_c/libffi/src/arm/sysv.S +305 -417
  142. data/ext/ffi_c/libffi/src/arm/sysv_msvc_arm32.S +311 -0
  143. data/ext/ffi_c/libffi/src/avr32/ffitarget.h +6 -1
  144. data/ext/ffi_c/libffi/src/bfin/ffi.c +196 -0
  145. data/ext/ffi_c/libffi/src/bfin/ffitarget.h +43 -0
  146. data/ext/ffi_c/libffi/src/bfin/sysv.S +179 -0
  147. data/ext/ffi_c/libffi/src/closures.c +465 -59
  148. data/ext/ffi_c/libffi/src/cris/ffi.c +10 -7
  149. data/ext/ffi_c/libffi/src/cris/ffitarget.h +6 -1
  150. data/ext/ffi_c/libffi/src/csky/ffi.c +395 -0
  151. data/ext/ffi_c/libffi/src/csky/ffitarget.h +63 -0
  152. data/ext/ffi_c/libffi/src/csky/sysv.S +371 -0
  153. data/ext/ffi_c/libffi/src/debug.c +6 -1
  154. data/ext/ffi_c/libffi/src/dlmalloc.c +17 -12
  155. data/ext/ffi_c/libffi/src/frv/ffi.c +2 -2
  156. data/ext/ffi_c/libffi/src/frv/ffitarget.h +6 -1
  157. data/ext/ffi_c/libffi/src/ia64/ffi.c +35 -13
  158. data/ext/ffi_c/libffi/src/ia64/ffitarget.h +8 -2
  159. data/ext/ffi_c/libffi/src/ia64/unix.S +8 -1
  160. data/ext/ffi_c/libffi/src/java_raw_api.c +23 -5
  161. data/ext/ffi_c/libffi/src/kvx/asm.h +5 -0
  162. data/ext/ffi_c/libffi/src/kvx/ffi.c +273 -0
  163. data/ext/ffi_c/libffi/src/kvx/ffitarget.h +75 -0
  164. data/ext/ffi_c/libffi/src/kvx/sysv.S +127 -0
  165. data/ext/ffi_c/libffi/src/m32r/ffi.c +1 -1
  166. data/ext/ffi_c/libffi/src/m32r/ffitarget.h +6 -1
  167. data/ext/ffi_c/libffi/src/m68k/ffi.c +87 -13
  168. data/ext/ffi_c/libffi/src/m68k/ffitarget.h +6 -1
  169. data/ext/ffi_c/libffi/src/m68k/sysv.S +119 -32
  170. data/ext/ffi_c/libffi/src/m88k/ffi.c +400 -0
  171. data/ext/ffi_c/libffi/src/m88k/ffitarget.h +49 -0
  172. data/ext/ffi_c/libffi/src/m88k/obsd.S +209 -0
  173. data/ext/ffi_c/libffi/src/metag/ffi.c +330 -0
  174. data/ext/ffi_c/libffi/{fficonfig.hw → src/metag/ffitarget.h} +22 -26
  175. data/ext/ffi_c/libffi/src/metag/sysv.S +311 -0
  176. data/ext/ffi_c/libffi/src/microblaze/ffi.c +321 -0
  177. data/ext/ffi_c/libffi/src/microblaze/ffitarget.h +53 -0
  178. data/ext/ffi_c/libffi/src/microblaze/sysv.S +302 -0
  179. data/ext/ffi_c/libffi/src/mips/ffi.c +135 -37
  180. data/ext/ffi_c/libffi/src/mips/ffitarget.h +16 -14
  181. data/ext/ffi_c/libffi/src/mips/n32.S +128 -56
  182. data/ext/ffi_c/libffi/src/mips/o32.S +150 -27
  183. data/ext/ffi_c/libffi/src/moxie/eabi.S +55 -82
  184. data/ext/ffi_c/libffi/src/moxie/ffi.c +55 -46
  185. data/ext/ffi_c/libffi/src/moxie/ffitarget.h +52 -0
  186. data/ext/ffi_c/libffi/src/nios2/ffi.c +304 -0
  187. data/ext/ffi_c/libffi/src/nios2/ffitarget.h +52 -0
  188. data/ext/ffi_c/libffi/src/nios2/sysv.S +136 -0
  189. data/ext/ffi_c/libffi/src/or1k/ffi.c +328 -0
  190. data/ext/ffi_c/libffi/src/or1k/ffitarget.h +58 -0
  191. data/ext/ffi_c/libffi/src/or1k/sysv.S +107 -0
  192. data/ext/ffi_c/libffi/src/pa/ffi.c +46 -91
  193. data/ext/ffi_c/libffi/src/pa/ffitarget.h +9 -7
  194. data/ext/ffi_c/libffi/src/pa/hpux32.S +4 -2
  195. data/ext/ffi_c/libffi/src/pa/linux.S +27 -4
  196. data/ext/ffi_c/libffi/src/powerpc/aix.S +245 -7
  197. data/ext/ffi_c/libffi/src/powerpc/aix_closure.S +253 -4
  198. data/ext/ffi_c/libffi/src/powerpc/asm.h +2 -2
  199. data/ext/ffi_c/libffi/src/powerpc/darwin.S +2 -7
  200. data/ext/ffi_c/libffi/src/powerpc/darwin_closure.S +22 -26
  201. data/ext/ffi_c/libffi/src/powerpc/ffi.c +105 -1378
  202. data/ext/ffi_c/libffi/src/powerpc/ffi_darwin.c +123 -30
  203. data/ext/ffi_c/libffi/src/powerpc/ffi_linux64.c +1153 -0
  204. data/ext/ffi_c/libffi/src/powerpc/ffi_powerpc.h +105 -0
  205. data/ext/ffi_c/libffi/src/powerpc/ffi_sysv.c +923 -0
  206. data/ext/ffi_c/libffi/src/powerpc/ffitarget.h +110 -45
  207. data/ext/ffi_c/libffi/src/powerpc/linux64.S +189 -85
  208. data/ext/ffi_c/libffi/src/powerpc/linux64_closure.S +436 -108
  209. data/ext/ffi_c/libffi/src/powerpc/ppc_closure.S +138 -68
  210. data/ext/ffi_c/libffi/src/powerpc/sysv.S +73 -119
  211. data/ext/ffi_c/libffi/src/prep_cif.c +111 -25
  212. data/ext/ffi_c/libffi/src/raw_api.c +18 -5
  213. data/ext/ffi_c/libffi/src/riscv/ffi.c +481 -0
  214. data/ext/ffi_c/libffi/src/riscv/ffitarget.h +69 -0
  215. data/ext/ffi_c/libffi/src/riscv/sysv.S +293 -0
  216. data/ext/ffi_c/libffi/src/s390/ffi.c +294 -318
  217. data/ext/ffi_c/libffi/src/s390/ffitarget.h +9 -1
  218. data/ext/ffi_c/libffi/src/s390/internal.h +11 -0
  219. data/ext/ffi_c/libffi/src/s390/sysv.S +257 -366
  220. data/ext/ffi_c/libffi/src/sh/ffi.c +4 -3
  221. data/ext/ffi_c/libffi/src/sh/ffitarget.h +6 -1
  222. data/ext/ffi_c/libffi/src/sh64/ffi.c +3 -2
  223. data/ext/ffi_c/libffi/src/sh64/ffitarget.h +6 -1
  224. data/ext/ffi_c/libffi/src/sparc/ffi.c +326 -527
  225. data/ext/ffi_c/libffi/src/sparc/ffi64.c +608 -0
  226. data/ext/ffi_c/libffi/src/sparc/ffitarget.h +20 -7
  227. data/ext/ffi_c/libffi/src/sparc/internal.h +26 -0
  228. data/ext/ffi_c/libffi/src/sparc/v8.S +364 -234
  229. data/ext/ffi_c/libffi/src/sparc/v9.S +340 -207
  230. data/ext/ffi_c/libffi/src/tile/ffi.c +355 -0
  231. data/ext/ffi_c/libffi/src/tile/ffitarget.h +65 -0
  232. data/ext/ffi_c/libffi/src/tile/tile.S +360 -0
  233. data/ext/ffi_c/libffi/src/types.c +46 -15
  234. data/ext/ffi_c/libffi/src/vax/elfbsd.S +195 -0
  235. data/ext/ffi_c/libffi/src/vax/ffi.c +276 -0
  236. data/ext/ffi_c/libffi/src/vax/ffitarget.h +49 -0
  237. data/ext/ffi_c/libffi/src/x86/asmnames.h +30 -0
  238. data/ext/ffi_c/libffi/src/x86/ffi.c +624 -498
  239. data/ext/ffi_c/libffi/src/x86/ffi64.c +379 -119
  240. data/ext/ffi_c/libffi/src/x86/ffitarget.h +74 -35
  241. data/ext/ffi_c/libffi/src/x86/ffiw64.c +318 -0
  242. data/ext/ffi_c/libffi/src/x86/internal.h +29 -0
  243. data/ext/ffi_c/libffi/src/x86/internal64.h +22 -0
  244. data/ext/ffi_c/libffi/src/x86/sysv.S +1070 -400
  245. data/ext/ffi_c/libffi/src/x86/sysv_intel.S +995 -0
  246. data/ext/ffi_c/libffi/src/x86/unix64.S +494 -299
  247. data/ext/ffi_c/libffi/src/x86/win64.S +231 -458
  248. data/ext/ffi_c/libffi/src/x86/win64_intel.S +238 -0
  249. data/ext/ffi_c/libffi/src/xtensa/ffi.c +298 -0
  250. data/ext/ffi_c/libffi/src/xtensa/ffitarget.h +53 -0
  251. data/ext/ffi_c/libffi/src/xtensa/sysv.S +258 -0
  252. data/ext/ffi_c/libffi/stamp-h.in +1 -0
  253. data/ext/ffi_c/libffi/testsuite/Makefile.am +115 -73
  254. data/ext/ffi_c/libffi/testsuite/Makefile.in +262 -114
  255. data/ext/ffi_c/libffi/testsuite/lib/libffi.exp +334 -24
  256. data/ext/ffi_c/libffi/testsuite/lib/target-libpath.exp +21 -1
  257. data/ext/ffi_c/libffi/testsuite/libffi.bhaible/Makefile +28 -0
  258. data/ext/ffi_c/libffi/testsuite/libffi.bhaible/README +78 -0
  259. data/ext/ffi_c/libffi/testsuite/libffi.bhaible/alignof.h +50 -0
  260. data/ext/ffi_c/libffi/testsuite/libffi.bhaible/bhaible.exp +63 -0
  261. data/ext/ffi_c/libffi/testsuite/libffi.bhaible/test-call.c +1745 -0
  262. data/ext/ffi_c/libffi/testsuite/libffi.bhaible/test-callback.c +2885 -0
  263. data/ext/ffi_c/libffi/testsuite/libffi.bhaible/testcases.c +743 -0
  264. data/ext/ffi_c/libffi/testsuite/libffi.call/align_mixed.c +46 -0
  265. data/ext/ffi_c/libffi/testsuite/libffi.call/align_stdcall.c +46 -0
  266. data/ext/ffi_c/libffi/testsuite/libffi.call/call.exp +28 -6
  267. data/ext/ffi_c/libffi/testsuite/libffi.call/err_bad_typedef.c +2 -2
  268. data/ext/ffi_c/libffi/testsuite/libffi.call/ffitest.h +25 -40
  269. data/ext/ffi_c/libffi/testsuite/libffi.call/float1.c +3 -1
  270. data/ext/ffi_c/libffi/testsuite/libffi.call/float2.c +15 -12
  271. data/ext/ffi_c/libffi/testsuite/libffi.call/float3.c +4 -2
  272. data/ext/ffi_c/libffi/testsuite/libffi.call/float_va.c +107 -0
  273. data/ext/ffi_c/libffi/testsuite/libffi.call/many.c +6 -16
  274. data/ext/ffi_c/libffi/testsuite/libffi.call/many2.c +57 -0
  275. data/ext/ffi_c/libffi/testsuite/libffi.call/many_double.c +70 -0
  276. data/ext/ffi_c/libffi/testsuite/libffi.call/many_mixed.c +78 -0
  277. data/ext/ffi_c/libffi/testsuite/libffi.call/negint.c +0 -1
  278. data/ext/ffi_c/libffi/testsuite/libffi.call/offsets.c +46 -0
  279. data/ext/ffi_c/libffi/testsuite/libffi.call/pr1172638.c +127 -0
  280. data/ext/ffi_c/libffi/testsuite/libffi.call/return_dbl.c +1 -0
  281. data/ext/ffi_c/libffi/testsuite/libffi.call/return_ldl.c +1 -1
  282. data/ext/ffi_c/libffi/testsuite/libffi.call/return_sc.c +1 -1
  283. data/ext/ffi_c/libffi/testsuite/libffi.call/return_uc.c +1 -1
  284. data/ext/ffi_c/libffi/testsuite/libffi.call/strlen.c +2 -2
  285. data/ext/ffi_c/libffi/testsuite/libffi.call/strlen2.c +49 -0
  286. data/ext/ffi_c/libffi/testsuite/libffi.call/strlen3.c +49 -0
  287. data/ext/ffi_c/libffi/testsuite/libffi.call/strlen4.c +55 -0
  288. data/ext/ffi_c/libffi/testsuite/libffi.call/struct1.c +9 -7
  289. data/ext/ffi_c/libffi/testsuite/libffi.call/struct10.c +57 -0
  290. data/ext/ffi_c/libffi/testsuite/libffi.call/struct2.c +7 -7
  291. data/ext/ffi_c/libffi/testsuite/libffi.call/struct3.c +7 -6
  292. data/ext/ffi_c/libffi/testsuite/libffi.call/struct4.c +9 -8
  293. data/ext/ffi_c/libffi/testsuite/libffi.call/struct5.c +9 -8
  294. data/ext/ffi_c/libffi/testsuite/libffi.call/struct6.c +9 -9
  295. data/ext/ffi_c/libffi/testsuite/libffi.call/struct7.c +9 -9
  296. data/ext/ffi_c/libffi/testsuite/libffi.call/struct8.c +9 -8
  297. data/ext/ffi_c/libffi/testsuite/libffi.call/struct9.c +9 -8
  298. data/ext/ffi_c/libffi/testsuite/libffi.call/uninitialized.c +61 -0
  299. data/ext/ffi_c/libffi/testsuite/libffi.call/va_1.c +196 -0
  300. data/ext/ffi_c/libffi/testsuite/libffi.call/va_struct1.c +121 -0
  301. data/ext/ffi_c/libffi/testsuite/libffi.call/va_struct2.c +123 -0
  302. data/ext/ffi_c/libffi/testsuite/libffi.call/va_struct3.c +125 -0
  303. data/ext/ffi_c/libffi/testsuite/libffi.closures/closure.exp +67 -0
  304. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/closure_fn0.c +0 -0
  305. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/closure_fn1.c +0 -0
  306. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/closure_fn2.c +0 -0
  307. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/closure_fn3.c +0 -0
  308. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/closure_fn4.c +0 -0
  309. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/closure_fn5.c +0 -0
  310. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/closure_fn6.c +0 -0
  311. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/closure_loc_fn0.c +0 -0
  312. data/ext/ffi_c/libffi/testsuite/{libffi.call/closure_stdcall.c → libffi.closures/closure_simple.c} +7 -16
  313. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_12byte.c +4 -4
  314. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_16byte.c +4 -4
  315. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_18byte.c +4 -4
  316. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_19byte.c +4 -4
  317. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_1_1byte.c +4 -4
  318. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_20byte.c +4 -4
  319. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_20byte1.c +4 -4
  320. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_24byte.c +5 -5
  321. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_2byte.c +4 -4
  322. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_3_1byte.c +4 -4
  323. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_3byte1.c +4 -4
  324. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_3byte2.c +4 -4
  325. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_3float.c +95 -0
  326. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_4_1byte.c +4 -4
  327. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_4byte.c +4 -4
  328. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_5_1_byte.c +4 -4
  329. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_5byte.c +4 -4
  330. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_64byte.c +5 -5
  331. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_6_1_byte.c +4 -4
  332. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_6byte.c +4 -4
  333. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_7_1_byte.c +4 -4
  334. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_7byte.c +4 -4
  335. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_8byte.c +4 -4
  336. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_9byte1.c +4 -4
  337. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_9byte2.c +4 -4
  338. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_double.c +4 -4
  339. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_float.c +4 -4
  340. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_longdouble.c +4 -4
  341. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_longdouble_split.c +4 -6
  342. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_longdouble_split2.c +4 -6
  343. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_pointer.c +4 -4
  344. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_sint16.c +4 -4
  345. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_sint32.c +4 -4
  346. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_sint64.c +4 -4
  347. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_uint16.c +4 -4
  348. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_uint32.c +4 -4
  349. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_align_uint64.c +4 -4
  350. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_dbls_struct.c +4 -4
  351. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_double.c +0 -0
  352. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_double_va.c +10 -9
  353. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_float.c +0 -0
  354. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_longdouble.c +3 -3
  355. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_longdouble_va.c +10 -9
  356. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_many_mixed_args.c +70 -0
  357. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_many_mixed_float_double.c +55 -0
  358. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_multi_schar.c +0 -0
  359. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_multi_sshort.c +0 -0
  360. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_multi_sshortchar.c +0 -0
  361. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_multi_uchar.c +0 -0
  362. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_multi_ushort.c +0 -0
  363. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_multi_ushortchar.c +0 -0
  364. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_pointer.c +1 -1
  365. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_pointer_stack.c +11 -9
  366. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_schar.c +0 -0
  367. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_sint.c +0 -0
  368. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_sshort.c +0 -0
  369. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_struct_va1.c +114 -0
  370. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_uchar.c +0 -0
  371. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_uchar_va.c +44 -0
  372. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_uint.c +0 -0
  373. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_uint_va.c +45 -0
  374. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_ulong_va.c +45 -0
  375. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_ulonglong.c +5 -5
  376. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/cls_ushort.c +0 -0
  377. data/ext/ffi_c/libffi/testsuite/libffi.closures/cls_ushort_va.c +44 -0
  378. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/err_bad_abi.c +0 -0
  379. data/ext/ffi_c/libffi/testsuite/libffi.closures/ffitest.h +138 -0
  380. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/huge_struct.c +20 -19
  381. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct.c +6 -6
  382. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct1.c +8 -8
  383. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct10.c +7 -6
  384. data/ext/ffi_c/libffi/testsuite/libffi.closures/nested_struct11.c +121 -0
  385. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct2.c +5 -5
  386. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct3.c +5 -5
  387. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct4.c +5 -5
  388. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct5.c +5 -5
  389. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct6.c +6 -6
  390. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct7.c +5 -5
  391. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct8.c +6 -6
  392. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/nested_struct9.c +6 -6
  393. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/problem1.c +0 -0
  394. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/stret_large.c +7 -7
  395. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/stret_large2.c +7 -7
  396. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/stret_medium.c +5 -5
  397. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/stret_medium2.c +5 -5
  398. data/ext/ffi_c/libffi/testsuite/{libffi.call → libffi.closures}/testclosure.c +2 -2
  399. data/ext/ffi_c/libffi/testsuite/{libffi.special → libffi.closures}/unwindtest.cc +3 -10
  400. data/ext/ffi_c/libffi/testsuite/{libffi.special → libffi.closures}/unwindtest_ffi_call.cc +3 -2
  401. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_align_complex.inc +91 -0
  402. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_align_complex_double.c +10 -0
  403. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_align_complex_float.c +10 -0
  404. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_align_complex_longdouble.c +10 -0
  405. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex.inc +42 -0
  406. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_double.c +10 -0
  407. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_float.c +10 -0
  408. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_longdouble.c +10 -0
  409. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_struct.inc +71 -0
  410. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_struct_double.c +10 -0
  411. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_struct_float.c +10 -0
  412. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_struct_longdouble.c +10 -0
  413. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_va.inc +80 -0
  414. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_va_double.c +10 -0
  415. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_va_float.c +16 -0
  416. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_va_longdouble.c +10 -0
  417. data/ext/ffi_c/libffi/testsuite/{libffi.special/special.exp → libffi.complex/complex.exp} +9 -8
  418. data/ext/ffi_c/libffi/testsuite/libffi.complex/complex.inc +51 -0
  419. data/ext/ffi_c/libffi/testsuite/libffi.complex/complex_defs_double.inc +7 -0
  420. data/ext/ffi_c/libffi/testsuite/libffi.complex/complex_defs_float.inc +7 -0
  421. data/ext/ffi_c/libffi/testsuite/libffi.complex/complex_defs_longdouble.inc +7 -0
  422. data/ext/ffi_c/libffi/testsuite/libffi.complex/complex_double.c +10 -0
  423. data/ext/ffi_c/libffi/testsuite/libffi.complex/complex_float.c +10 -0
  424. data/ext/ffi_c/libffi/testsuite/libffi.complex/complex_int.c +86 -0
  425. data/ext/ffi_c/libffi/testsuite/libffi.complex/complex_longdouble.c +10 -0
  426. data/ext/ffi_c/libffi/testsuite/libffi.complex/ffitest.h +1 -0
  427. data/ext/ffi_c/libffi/testsuite/libffi.complex/many_complex.inc +78 -0
  428. data/ext/ffi_c/libffi/testsuite/libffi.complex/many_complex_double.c +10 -0
  429. data/ext/ffi_c/libffi/testsuite/libffi.complex/many_complex_float.c +10 -0
  430. data/ext/ffi_c/libffi/testsuite/libffi.complex/many_complex_longdouble.c +10 -0
  431. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex.inc +37 -0
  432. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex1.inc +41 -0
  433. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex1_double.c +10 -0
  434. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex1_float.c +10 -0
  435. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex1_longdouble.c +10 -0
  436. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex2.inc +44 -0
  437. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex2_double.c +10 -0
  438. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex2_float.c +10 -0
  439. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex2_longdouble.c +10 -0
  440. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex_double.c +10 -0
  441. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex_float.c +10 -0
  442. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex_longdouble.c +10 -0
  443. data/ext/ffi_c/libffi/testsuite/libffi.go/aa-direct.c +34 -0
  444. data/ext/ffi_c/libffi/testsuite/libffi.go/closure1.c +28 -0
  445. data/ext/ffi_c/libffi/testsuite/libffi.go/ffitest.h +1 -0
  446. data/ext/ffi_c/libffi/testsuite/libffi.go/go.exp +36 -0
  447. data/ext/ffi_c/libffi/testsuite/libffi.go/static-chain.h +19 -0
  448. data/ext/ffi_c/libffi.bsd.mk +12 -6
  449. data/ext/ffi_c/libffi.darwin.mk +21 -9
  450. data/ext/ffi_c/libffi.gnu.mk +3 -2
  451. data/ext/ffi_c/libffi.mk +11 -6
  452. data/ext/ffi_c/libffi.vc.mk +1 -1
  453. data/ext/ffi_c/libffi.vc64.mk +1 -1
  454. data/ext/ffi_c/rbffi.h +22 -14
  455. data/ext/ffi_c/rbffi_endian.h +11 -2
  456. data/ffi.gemspec +42 -0
  457. data/lib/ffi/abstract_memory.rb +44 -0
  458. data/lib/ffi/autopointer.rb +70 -50
  459. data/lib/ffi/data_converter.rb +67 -0
  460. data/lib/ffi/enum.rb +159 -24
  461. data/lib/ffi/errno.rb +21 -11
  462. data/lib/ffi/ffi.rb +25 -11
  463. data/lib/ffi/io.rb +24 -14
  464. data/lib/ffi/library.rb +174 -67
  465. data/lib/ffi/managedstruct.rb +63 -34
  466. data/lib/ffi/platform/aarch64-darwin/types.conf +130 -0
  467. data/lib/ffi/platform/aarch64-freebsd/types.conf +128 -0
  468. data/lib/ffi/platform/aarch64-freebsd12/types.conf +181 -0
  469. data/lib/ffi/platform/aarch64-linux/types.conf +104 -0
  470. data/lib/ffi/platform/aarch64-openbsd/types.conf +134 -0
  471. data/lib/ffi/platform/arm-freebsd/types.conf +152 -0
  472. data/lib/ffi/platform/arm-freebsd12/types.conf +152 -0
  473. data/lib/ffi/platform/arm-linux/types.conf +110 -82
  474. data/lib/ffi/platform/i386-cygwin/types.conf +3 -0
  475. data/lib/ffi/platform/i386-darwin/types.conf +63 -63
  476. data/lib/ffi/platform/i386-freebsd/types.conf +89 -89
  477. data/lib/ffi/platform/i386-freebsd12/types.conf +152 -0
  478. data/lib/ffi/platform/{i486-gnu → i386-gnu}/types.conf +84 -84
  479. data/lib/ffi/platform/i386-linux/types.conf +77 -77
  480. data/lib/ffi/platform/i386-netbsd/types.conf +87 -87
  481. data/lib/ffi/platform/i386-openbsd/types.conf +89 -87
  482. data/lib/ffi/platform/i386-solaris/types.conf +96 -96
  483. data/lib/ffi/platform/i386-windows/types.conf +43 -96
  484. data/lib/ffi/platform/ia64-linux/types.conf +79 -79
  485. data/lib/ffi/platform/mips-linux/types.conf +79 -79
  486. data/lib/ffi/platform/mips64-linux/types.conf +104 -0
  487. data/lib/ffi/platform/mips64el-linux/types.conf +104 -0
  488. data/lib/ffi/platform/mipsel-linux/types.conf +79 -79
  489. data/lib/ffi/platform/mipsisa32r6-linux/types.conf +102 -0
  490. data/lib/ffi/platform/mipsisa32r6el-linux/types.conf +102 -0
  491. data/lib/ffi/platform/mipsisa64r6-linux/types.conf +104 -0
  492. data/lib/ffi/platform/mipsisa64r6el-linux/types.conf +104 -0
  493. data/lib/ffi/platform/powerpc-aix/types.conf +155 -155
  494. data/lib/ffi/platform/powerpc-darwin/types.conf +63 -63
  495. data/lib/ffi/platform/powerpc-linux/types.conf +108 -78
  496. data/lib/ffi/platform/powerpc-openbsd/types.conf +156 -0
  497. data/lib/ffi/platform/powerpc64-linux/types.conf +104 -0
  498. data/lib/ffi/platform/powerpc64le-linux/types.conf +100 -0
  499. data/lib/ffi/platform/riscv64-linux/types.conf +104 -0
  500. data/lib/ffi/platform/s390-linux/types.conf +79 -79
  501. data/lib/ffi/platform/s390x-linux/types.conf +79 -79
  502. data/lib/ffi/platform/sparc-linux/types.conf +79 -79
  503. data/lib/ffi/platform/sparc-solaris/types.conf +103 -103
  504. data/lib/ffi/platform/sparc64-linux/types.conf +102 -0
  505. data/lib/ffi/platform/sparcv9-openbsd/types.conf +156 -0
  506. data/lib/ffi/platform/sparcv9-solaris/types.conf +103 -103
  507. data/lib/ffi/platform/x86_64-cygwin/types.conf +3 -0
  508. data/lib/ffi/platform/x86_64-darwin/types.conf +93 -63
  509. data/lib/ffi/platform/x86_64-dragonflybsd/types.conf +130 -0
  510. data/lib/ffi/platform/x86_64-freebsd/types.conf +90 -88
  511. data/lib/ffi/platform/x86_64-freebsd12/types.conf +158 -0
  512. data/lib/ffi/platform/x86_64-haiku/types.conf +117 -0
  513. data/lib/ffi/platform/x86_64-linux/types.conf +107 -77
  514. data/lib/ffi/platform/x86_64-msys/types.conf +119 -0
  515. data/lib/ffi/platform/x86_64-netbsd/types.conf +89 -87
  516. data/lib/ffi/platform/x86_64-openbsd/types.conf +100 -92
  517. data/lib/ffi/platform/x86_64-solaris/types.conf +96 -96
  518. data/lib/ffi/platform/x86_64-windows/types.conf +52 -0
  519. data/lib/ffi/platform.rb +81 -26
  520. data/lib/ffi/pointer.rb +72 -27
  521. data/lib/ffi/struct.rb +99 -66
  522. data/lib/ffi/struct_by_reference.rb +72 -0
  523. data/lib/ffi/struct_layout.rb +96 -0
  524. data/lib/ffi/struct_layout_builder.rb +82 -17
  525. data/lib/ffi/tools/const_generator.rb +11 -8
  526. data/lib/ffi/tools/generator.rb +48 -1
  527. data/lib/ffi/tools/generator_task.rb +13 -16
  528. data/lib/ffi/tools/struct_generator.rb +6 -5
  529. data/lib/ffi/tools/types_generator.rb +14 -10
  530. data/lib/ffi/types.rb +31 -14
  531. data/lib/ffi/union.rb +23 -12
  532. data/lib/ffi/variadic.rb +25 -21
  533. data/lib/ffi/version.rb +3 -0
  534. data/lib/ffi.rb +20 -8
  535. data/rakelib/ffi_gem_helper.rb +65 -0
  536. data/samples/getlogin.rb +8 -0
  537. data/samples/getpid.rb +8 -0
  538. data/samples/gettimeofday.rb +18 -0
  539. data/samples/hello.rb +8 -0
  540. data/samples/inotify.rb +60 -0
  541. data/samples/pty.rb +75 -0
  542. data/samples/qsort.rb +20 -0
  543. metadata +413 -263
  544. data/History.txt +0 -1
  545. data/README.rdoc +0 -102
  546. data/ext/ffi_c/DataConverter.c +0 -91
  547. data/ext/ffi_c/Ffi_c.iml +0 -12
  548. data/ext/ffi_c/StructByReference.c +0 -158
  549. data/ext/ffi_c/StructByReference.h +0 -50
  550. data/ext/ffi_c/libffi/ChangeLog.libffi +0 -584
  551. data/ext/ffi_c/libffi/ChangeLog.libgcj +0 -40
  552. data/ext/ffi_c/libffi/ChangeLog.v1 +0 -764
  553. data/ext/ffi_c/libffi/Makefile.vc +0 -141
  554. data/ext/ffi_c/libffi/Makefile.vc64 +0 -141
  555. data/ext/ffi_c/libffi/README +0 -342
  556. data/ext/ffi_c/libffi/aclocal.m4 +0 -1873
  557. data/ext/ffi_c/libffi/build-ios.sh +0 -67
  558. data/ext/ffi_c/libffi/compile +0 -143
  559. data/ext/ffi_c/libffi/depcomp +0 -630
  560. data/ext/ffi_c/libffi/doc/libffi.info +0 -593
  561. data/ext/ffi_c/libffi/doc/stamp-vti +0 -4
  562. data/ext/ffi_c/libffi/include/ffi.h.vc +0 -427
  563. data/ext/ffi_c/libffi/m4/ax_check_compiler_flags.m4 +0 -76
  564. data/ext/ffi_c/libffi/m4/libtool.m4 +0 -7831
  565. data/ext/ffi_c/libffi/m4/ltoptions.m4 +0 -369
  566. data/ext/ffi_c/libffi/m4/ltsugar.m4 +0 -123
  567. data/ext/ffi_c/libffi/m4/ltversion.m4 +0 -23
  568. data/ext/ffi_c/libffi/m4/lt~obsolete.m4 +0 -98
  569. data/ext/ffi_c/libffi/mdate-sh +0 -201
  570. data/ext/ffi_c/libffi/src/arm/gentramp.sh +0 -118
  571. data/ext/ffi_c/libffi/src/arm/trampoline.S +0 -4450
  572. data/ext/ffi_c/libffi/src/x86/darwin.S +0 -444
  573. data/ext/ffi_c/libffi/src/x86/darwin64.S +0 -416
  574. data/ext/ffi_c/libffi/src/x86/freebsd.S +0 -458
  575. data/ext/ffi_c/libffi/src/x86/win32.S +0 -1065
  576. data/ext/ffi_c/libffi/testsuite/lib/libffi-dg.exp +0 -300
  577. data/ext/ffi_c/libffi/testsuite/libffi.call/many_win32.c +0 -63
  578. data/ext/ffi_c/libffi/testsuite/libffi.call/strlen_win32.c +0 -44
  579. data/ext/ffi_c/libffi/testsuite/libffi.special/ffitestcxx.h +0 -96
  580. data/ext/ffi_c/libffi/texinfo.tex +0 -7210
  581. data/ext/ffi_c/win32/stdint.h +0 -199
  582. data/gen/Rakefile +0 -30
  583. data/gen/log +0 -1
  584. data/lib/Lib.iml +0 -13
  585. data/spec/ffi/Ffi.iml +0 -12
  586. data/spec/ffi/async_callback_spec.rb +0 -46
  587. data/spec/ffi/bool_spec.rb +0 -40
  588. data/spec/ffi/buffer_spec.rb +0 -215
  589. data/spec/ffi/callback_spec.rb +0 -668
  590. data/spec/ffi/custom_param_type.rb +0 -47
  591. data/spec/ffi/custom_type_spec.rb +0 -85
  592. data/spec/ffi/dup_spec.rb +0 -65
  593. data/spec/ffi/enum_spec.rb +0 -227
  594. data/spec/ffi/errno_spec.rb +0 -29
  595. data/spec/ffi/ffi_spec.rb +0 -40
  596. data/spec/ffi/function_spec.rb +0 -87
  597. data/spec/ffi/library_spec.rb +0 -208
  598. data/spec/ffi/long_double.rb +0 -41
  599. data/spec/ffi/managed_struct_spec.rb +0 -72
  600. data/spec/ffi/number_spec.rb +0 -247
  601. data/spec/ffi/pointer_spec.rb +0 -214
  602. data/spec/ffi/rbx/attach_function_spec.rb +0 -28
  603. data/spec/ffi/rbx/memory_pointer_spec.rb +0 -115
  604. data/spec/ffi/rbx/spec_helper.rb +0 -1
  605. data/spec/ffi/rbx/struct_spec.rb +0 -13
  606. data/spec/ffi/spec_helper.rb +0 -35
  607. data/spec/ffi/string_spec.rb +0 -119
  608. data/spec/ffi/strptr_spec.rb +0 -61
  609. data/spec/ffi/struct_callback_spec.rb +0 -80
  610. data/spec/ffi/struct_initialize_spec.rb +0 -46
  611. data/spec/ffi/struct_packed_spec.rb +0 -62
  612. data/spec/ffi/struct_spec.rb +0 -719
  613. data/spec/ffi/typedef_spec.rb +0 -89
  614. data/spec/ffi/union_spec.rb +0 -76
  615. data/spec/ffi/variadic_spec.rb +0 -103
  616. data/spec/spec.opts +0 -4
  617. data/tasks/ann.rake +0 -80
  618. data/tasks/extension.rake +0 -32
  619. data/tasks/gem.rake +0 -199
  620. data/tasks/git.rake +0 -41
  621. data/tasks/notes.rake +0 -27
  622. data/tasks/post_load.rake +0 -34
  623. data/tasks/rdoc.rake +0 -50
  624. data/tasks/rubyforge.rake +0 -55
  625. data/tasks/setup.rb +0 -301
  626. data/tasks/spec.rake +0 -54
  627. data/tasks/svn.rake +0 -47
  628. data/tasks/test.rake +0 -40
  629. data/tasks/yard.rake +0 -11
@@ -1,10 +1,11 @@
1
1
  /* -----------------------------------------------------------------------
2
- ffi.c - Copyright (c) 2011 Plausible Labs Cooperative, Inc.
2
+ ffi.c - Copyright (c) 2011 Timothy Wall
3
+ Copyright (c) 2011 Plausible Labs Cooperative, Inc.
3
4
  Copyright (c) 2011 Anthony Green
4
5
  Copyright (c) 2011 Free Software Foundation
5
6
  Copyright (c) 1998, 2008, 2011 Red Hat, Inc.
6
-
7
- ARM Foreign Function Interface
7
+
8
+ ARM Foreign Function Interface
8
9
 
9
10
  Permission is hereby granted, free of charge, to any person obtaining
10
11
  a copy of this software and associated documentation files (the
@@ -27,660 +28,800 @@
27
28
  DEALINGS IN THE SOFTWARE.
28
29
  ----------------------------------------------------------------------- */
29
30
 
31
+ #if defined(__arm__) || defined(_M_ARM)
32
+ #include <fficonfig.h>
30
33
  #include <ffi.h>
31
34
  #include <ffi_common.h>
32
-
35
+ #include <stdint.h>
33
36
  #include <stdlib.h>
37
+ #include "internal.h"
38
+
39
+ #if defined(_MSC_VER) && defined(_M_ARM)
40
+ #define WIN32_LEAN_AND_MEAN
41
+ #include <windows.h>
42
+ #endif
43
+
44
+ #if FFI_EXEC_TRAMPOLINE_TABLE
45
+
46
+ #ifdef __MACH__
47
+ #include <mach/machine/vm_param.h>
48
+ #endif
49
+
50
+ #else
51
+ #ifndef _M_ARM
52
+ extern unsigned int ffi_arm_trampoline[2] FFI_HIDDEN;
53
+ #else
54
+ extern unsigned int ffi_arm_trampoline[3] FFI_HIDDEN;
55
+ #endif
56
+ #endif
57
+
58
+ #if defined(__FreeBSD__) && defined(__arm__)
59
+ #include <sys/types.h>
60
+ #include <machine/sysarch.h>
61
+ #endif
34
62
 
35
63
  /* Forward declares. */
36
- static int vfp_type_p (ffi_type *);
64
+ static int vfp_type_p (const ffi_type *);
37
65
  static void layout_vfp_args (ffi_cif *);
38
66
 
39
- /* ffi_prep_args is called by the assembly routine once stack space
40
- has been allocated for the function's arguments
41
-
67
+ static void *
68
+ ffi_align (ffi_type *ty, void *p)
69
+ {
70
+ /* Align if necessary */
71
+ size_t alignment;
72
+ #ifdef _WIN32_WCE
73
+ alignment = 4;
74
+ #else
75
+ alignment = ty->alignment;
76
+ if (alignment < 4)
77
+ alignment = 4;
78
+ #endif
79
+ return (void *) FFI_ALIGN (p, alignment);
80
+ }
81
+
82
+ static size_t
83
+ ffi_put_arg (ffi_type *ty, void *src, void *dst)
84
+ {
85
+ size_t z = ty->size;
86
+
87
+ switch (ty->type)
88
+ {
89
+ case FFI_TYPE_SINT8:
90
+ *(UINT32 *)dst = *(SINT8 *)src;
91
+ break;
92
+ case FFI_TYPE_UINT8:
93
+ *(UINT32 *)dst = *(UINT8 *)src;
94
+ break;
95
+ case FFI_TYPE_SINT16:
96
+ *(UINT32 *)dst = *(SINT16 *)src;
97
+ break;
98
+ case FFI_TYPE_UINT16:
99
+ *(UINT32 *)dst = *(UINT16 *)src;
100
+ break;
101
+
102
+ case FFI_TYPE_INT:
103
+ case FFI_TYPE_SINT32:
104
+ case FFI_TYPE_UINT32:
105
+ case FFI_TYPE_POINTER:
106
+ #ifndef _MSC_VER
107
+ case FFI_TYPE_FLOAT:
108
+ #endif
109
+ *(UINT32 *)dst = *(UINT32 *)src;
110
+ break;
111
+
112
+ #ifdef _MSC_VER
113
+ // casting a float* to a UINT32* doesn't work on Windows
114
+ case FFI_TYPE_FLOAT:
115
+ *(uintptr_t *)dst = 0;
116
+ *(float *)dst = *(float *)src;
117
+ break;
118
+ #endif
119
+
120
+ case FFI_TYPE_SINT64:
121
+ case FFI_TYPE_UINT64:
122
+ case FFI_TYPE_DOUBLE:
123
+ *(UINT64 *)dst = *(UINT64 *)src;
124
+ break;
125
+
126
+ case FFI_TYPE_STRUCT:
127
+ case FFI_TYPE_COMPLEX:
128
+ memcpy (dst, src, z);
129
+ break;
130
+
131
+ default:
132
+ abort();
133
+ }
134
+
135
+ return FFI_ALIGN (z, 4);
136
+ }
137
+
138
+ /* ffi_prep_args is called once stack space has been allocated
139
+ for the function's arguments.
140
+
42
141
  The vfp_space parameter is the load area for VFP regs, the return
43
142
  value is cif->vfp_used (word bitset of VFP regs used for passing
44
143
  arguments). These are only used for the VFP hard-float ABI.
45
144
  */
46
- int ffi_prep_args(char *stack, extended_cif *ecif, float *vfp_space)
145
+ static void
146
+ ffi_prep_args_SYSV (ffi_cif *cif, int flags, void *rvalue,
147
+ void **avalue, char *argp)
47
148
  {
48
- register unsigned int i, vi = 0;
49
- register void **p_argv;
50
- register char *argp;
51
- register ffi_type **p_arg;
149
+ ffi_type **arg_types = cif->arg_types;
150
+ int i, n;
52
151
 
53
- argp = stack;
152
+ if (flags == ARM_TYPE_STRUCT)
153
+ {
154
+ *(void **) argp = rvalue;
155
+ argp += 4;
156
+ }
54
157
 
55
- if ( ecif->cif->flags == FFI_TYPE_STRUCT ) {
56
- *(void **) argp = ecif->rvalue;
57
- argp += 4;
58
- }
158
+ for (i = 0, n = cif->nargs; i < n; i++)
159
+ {
160
+ ffi_type *ty = arg_types[i];
161
+ argp = ffi_align (ty, argp);
162
+ argp += ffi_put_arg (ty, avalue[i], argp);
163
+ }
164
+ }
59
165
 
60
- p_argv = ecif->avalue;
166
+ static void
167
+ ffi_prep_args_VFP (ffi_cif *cif, int flags, void *rvalue,
168
+ void **avalue, char *stack, char *vfp_space)
169
+ {
170
+ ffi_type **arg_types = cif->arg_types;
171
+ int i, n, vi = 0;
172
+ char *argp, *regp, *eo_regp;
173
+ char stack_used = 0;
174
+ char done_with_regs = 0;
175
+
176
+ /* The first 4 words on the stack are used for values
177
+ passed in core registers. */
178
+ regp = stack;
179
+ eo_regp = argp = regp + 16;
180
+
181
+ /* If the function returns an FFI_TYPE_STRUCT in memory,
182
+ that address is passed in r0 to the function. */
183
+ if (flags == ARM_TYPE_STRUCT)
184
+ {
185
+ *(void **) regp = rvalue;
186
+ regp += 4;
187
+ }
61
188
 
62
- for (i = ecif->cif->nargs, p_arg = ecif->cif->arg_types;
63
- (i != 0);
64
- i--, p_arg++)
189
+ for (i = 0, n = cif->nargs; i < n; i++)
65
190
  {
66
- size_t z;
191
+ ffi_type *ty = arg_types[i];
192
+ void *a = avalue[i];
193
+ int is_vfp_type = vfp_type_p (ty);
67
194
 
68
195
  /* Allocated in VFP registers. */
69
- if (ecif->cif->abi == FFI_VFP
70
- && vi < ecif->cif->vfp_nargs && vfp_type_p (*p_arg))
196
+ if (vi < cif->vfp_nargs && is_vfp_type)
71
197
  {
72
- float* vfp_slot = vfp_space + ecif->cif->vfp_args[vi++];
73
- if ((*p_arg)->type == FFI_TYPE_FLOAT)
74
- *((float*)vfp_slot) = *((float*)*p_argv);
75
- else if ((*p_arg)->type == FFI_TYPE_DOUBLE)
76
- *((double*)vfp_slot) = *((double*)*p_argv);
77
- else
78
- memcpy(vfp_slot, *p_argv, (*p_arg)->size);
79
- p_argv++;
198
+ char *vfp_slot = vfp_space + cif->vfp_args[vi++] * 4;
199
+ ffi_put_arg (ty, a, vfp_slot);
80
200
  continue;
81
201
  }
82
-
83
- /* Align if necessary */
84
- if (((*p_arg)->alignment - 1) & (unsigned) argp) {
85
- argp = (char *) ALIGN(argp, (*p_arg)->alignment);
86
- }
87
-
88
- if ((*p_arg)->type == FFI_TYPE_STRUCT)
89
- argp = (char *) ALIGN(argp, 4);
90
-
91
- z = (*p_arg)->size;
92
- if (z < sizeof(int))
93
- {
94
- z = sizeof(int);
95
- switch ((*p_arg)->type)
96
- {
97
- case FFI_TYPE_SINT8:
98
- *(signed int *) argp = (signed int)*(SINT8 *)(* p_argv);
99
- break;
100
-
101
- case FFI_TYPE_UINT8:
102
- *(unsigned int *) argp = (unsigned int)*(UINT8 *)(* p_argv);
103
- break;
104
-
105
- case FFI_TYPE_SINT16:
106
- *(signed int *) argp = (signed int)*(SINT16 *)(* p_argv);
107
- break;
108
-
109
- case FFI_TYPE_UINT16:
110
- *(unsigned int *) argp = (unsigned int)*(UINT16 *)(* p_argv);
111
- break;
112
-
113
- case FFI_TYPE_STRUCT:
114
- memcpy(argp, *p_argv, (*p_arg)->size);
115
- break;
116
-
117
- default:
118
- FFI_ASSERT(0);
119
- }
120
- }
121
- else if (z == sizeof(int))
202
+ /* Try allocating in core registers. */
203
+ else if (!done_with_regs && !is_vfp_type)
204
+ {
205
+ char *tregp = ffi_align (ty, regp);
206
+ size_t size = ty->size;
207
+ size = (size < 4) ? 4 : size; // pad
208
+ /* Check if there is space left in the aligned register
209
+ area to place the argument. */
210
+ if (tregp + size <= eo_regp)
122
211
  {
123
- *(unsigned int *) argp = (unsigned int)*(UINT32 *)(* p_argv);
212
+ regp = tregp + ffi_put_arg (ty, a, tregp);
213
+ done_with_regs = (regp == argp);
214
+ // ensure we did not write into the stack area
215
+ FFI_ASSERT (regp <= argp);
216
+ continue;
124
217
  }
125
- else
218
+ /* In case there are no arguments in the stack area yet,
219
+ the argument is passed in the remaining core registers
220
+ and on the stack. */
221
+ else if (!stack_used)
126
222
  {
127
- memcpy(argp, *p_argv, z);
223
+ stack_used = 1;
224
+ done_with_regs = 1;
225
+ argp = tregp + ffi_put_arg (ty, a, tregp);
226
+ FFI_ASSERT (eo_regp < argp);
227
+ continue;
128
228
  }
129
- p_argv++;
130
- argp += z;
229
+ }
230
+ /* Base case, arguments are passed on the stack */
231
+ stack_used = 1;
232
+ argp = ffi_align (ty, argp);
233
+ argp += ffi_put_arg (ty, a, argp);
131
234
  }
132
-
133
- /* Indicate the VFP registers used. */
134
- return ecif->cif->vfp_used;
135
235
  }
136
236
 
137
237
  /* Perform machine dependent cif processing */
138
- ffi_status ffi_prep_cif_machdep(ffi_cif *cif)
238
+ ffi_status FFI_HIDDEN
239
+ ffi_prep_cif_machdep (ffi_cif *cif)
139
240
  {
140
- int type_code;
141
- /* Round the stack up to a multiple of 8 bytes. This isn't needed
142
- everywhere, but it is on some platforms, and it doesn't harm anything
143
- when it isn't needed. */
144
- cif->bytes = (cif->bytes + 7) & ~7;
241
+ int flags = 0, cabi = cif->abi;
242
+ size_t bytes = cif->bytes;
243
+
244
+ /* Map out the register placements of VFP register args. The VFP
245
+ hard-float calling conventions are slightly more sophisticated
246
+ than the base calling conventions, so we do it here instead of
247
+ in ffi_prep_args(). */
248
+ if (cabi == FFI_VFP)
249
+ layout_vfp_args (cif);
145
250
 
146
251
  /* Set the return type flag */
147
252
  switch (cif->rtype->type)
148
253
  {
149
254
  case FFI_TYPE_VOID:
150
- case FFI_TYPE_FLOAT:
151
- case FFI_TYPE_DOUBLE:
152
- cif->flags = (unsigned) cif->rtype->type;
255
+ flags = ARM_TYPE_VOID;
256
+ break;
257
+
258
+ case FFI_TYPE_INT:
259
+ case FFI_TYPE_UINT8:
260
+ case FFI_TYPE_SINT8:
261
+ case FFI_TYPE_UINT16:
262
+ case FFI_TYPE_SINT16:
263
+ case FFI_TYPE_UINT32:
264
+ case FFI_TYPE_SINT32:
265
+ case FFI_TYPE_POINTER:
266
+ flags = ARM_TYPE_INT;
153
267
  break;
154
268
 
155
269
  case FFI_TYPE_SINT64:
156
270
  case FFI_TYPE_UINT64:
157
- cif->flags = (unsigned) FFI_TYPE_SINT64;
271
+ flags = ARM_TYPE_INT64;
272
+ break;
273
+
274
+ case FFI_TYPE_FLOAT:
275
+ flags = (cabi == FFI_VFP ? ARM_TYPE_VFP_S : ARM_TYPE_INT);
276
+ break;
277
+ case FFI_TYPE_DOUBLE:
278
+ flags = (cabi == FFI_VFP ? ARM_TYPE_VFP_D : ARM_TYPE_INT64);
158
279
  break;
159
280
 
160
281
  case FFI_TYPE_STRUCT:
161
- if (cif->abi == FFI_VFP
162
- && (type_code = vfp_type_p (cif->rtype)) != 0)
282
+ case FFI_TYPE_COMPLEX:
283
+ if (cabi == FFI_VFP)
163
284
  {
164
- /* A Composite Type passed in VFP registers, either
165
- FFI_TYPE_STRUCT_VFP_FLOAT or FFI_TYPE_STRUCT_VFP_DOUBLE. */
166
- cif->flags = (unsigned) type_code;
285
+ int h = vfp_type_p (cif->rtype);
286
+
287
+ flags = ARM_TYPE_VFP_N;
288
+ if (h == 0x100 + FFI_TYPE_FLOAT)
289
+ flags = ARM_TYPE_VFP_S;
290
+ if (h == 0x100 + FFI_TYPE_DOUBLE)
291
+ flags = ARM_TYPE_VFP_D;
292
+ if (h != 0)
293
+ break;
167
294
  }
168
- else if (cif->rtype->size <= 4)
169
- /* A Composite Type not larger than 4 bytes is returned in r0. */
170
- cif->flags = (unsigned)FFI_TYPE_INT;
295
+
296
+ /* A Composite Type not larger than 4 bytes is returned in r0.
297
+ A Composite Type larger than 4 bytes, or whose size cannot
298
+ be determined statically ... is stored in memory at an
299
+ address passed [in r0]. */
300
+ if (cif->rtype->size <= 4)
301
+ flags = ARM_TYPE_INT;
171
302
  else
172
- /* A Composite Type larger than 4 bytes, or whose size cannot
173
- be determined statically ... is stored in memory at an
174
- address passed [in r0]. */
175
- cif->flags = (unsigned)FFI_TYPE_STRUCT;
303
+ {
304
+ flags = ARM_TYPE_STRUCT;
305
+ bytes += 4;
306
+ }
176
307
  break;
177
308
 
178
309
  default:
179
- cif->flags = FFI_TYPE_INT;
180
- break;
310
+ abort();
181
311
  }
182
312
 
183
- /* Map out the register placements of VFP register args.
184
- The VFP hard-float calling conventions are slightly more sophisticated than
185
- the base calling conventions, so we do it here instead of in ffi_prep_args(). */
186
- if (cif->abi == FFI_VFP)
187
- layout_vfp_args (cif);
313
+ /* Round the stack up to a multiple of 8 bytes. This isn't needed
314
+ everywhere, but it is on some platforms, and it doesn't harm anything
315
+ when it isn't needed. */
316
+ bytes = FFI_ALIGN (bytes, 8);
317
+
318
+ /* Minimum stack space is the 4 register arguments that we pop. */
319
+ if (bytes < 4*4)
320
+ bytes = 4*4;
321
+
322
+ cif->bytes = bytes;
323
+ cif->flags = flags;
188
324
 
189
325
  return FFI_OK;
190
326
  }
191
327
 
192
- /* Prototypes for assembly functions, in sysv.S */
193
- extern void ffi_call_SYSV (void (*fn)(void), extended_cif *, unsigned, unsigned, unsigned *);
194
- extern void ffi_call_VFP (void (*fn)(void), extended_cif *, unsigned, unsigned, unsigned *);
195
-
196
- void ffi_call(ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue)
328
+ /* Perform machine dependent cif processing for variadic calls */
329
+ ffi_status FFI_HIDDEN
330
+ ffi_prep_cif_machdep_var (ffi_cif * cif,
331
+ unsigned int nfixedargs, unsigned int ntotalargs)
197
332
  {
198
- extended_cif ecif;
333
+ /* VFP variadic calls actually use the SYSV ABI */
334
+ if (cif->abi == FFI_VFP)
335
+ cif->abi = FFI_SYSV;
336
+
337
+ return ffi_prep_cif_machdep (cif);
338
+ }
199
339
 
200
- int small_struct = (cif->flags == FFI_TYPE_INT
201
- && cif->rtype->type == FFI_TYPE_STRUCT);
202
- int vfp_struct = (cif->flags == FFI_TYPE_STRUCT_VFP_FLOAT
203
- || cif->flags == FFI_TYPE_STRUCT_VFP_DOUBLE);
340
+ /* Prototypes for assembly functions, in sysv.S. */
204
341
 
205
- ecif.cif = cif;
206
- ecif.avalue = avalue;
342
+ struct call_frame
343
+ {
344
+ void *fp;
345
+ void *lr;
346
+ void *rvalue;
347
+ int flags;
348
+ void *closure;
349
+ };
207
350
 
208
- unsigned int temp;
209
-
210
- /* If the return value is a struct and we don't have a return */
211
- /* value address then we need to make one */
351
+ extern void ffi_call_SYSV (void *stack, struct call_frame *,
352
+ void (*fn) (void)) FFI_HIDDEN;
353
+ extern void ffi_call_VFP (void *vfp_space, struct call_frame *,
354
+ void (*fn) (void), unsigned vfp_used) FFI_HIDDEN;
212
355
 
213
- if ((rvalue == NULL) &&
214
- (cif->flags == FFI_TYPE_STRUCT))
356
+ static void
357
+ ffi_call_int (ffi_cif * cif, void (*fn) (void), void *rvalue,
358
+ void **avalue, void *closure)
359
+ {
360
+ int flags = cif->flags;
361
+ ffi_type *rtype = cif->rtype;
362
+ size_t bytes, rsize, vfp_size;
363
+ char *stack, *vfp_space, *new_rvalue;
364
+ struct call_frame *frame;
365
+
366
+ rsize = 0;
367
+ if (rvalue == NULL)
215
368
  {
216
- ecif.rvalue = alloca(cif->rtype->size);
369
+ /* If the return value is a struct and we don't have a return
370
+ value address then we need to make one. Otherwise the return
371
+ value is in registers and we can ignore them. */
372
+ if (flags == ARM_TYPE_STRUCT)
373
+ rsize = rtype->size;
374
+ else
375
+ flags = ARM_TYPE_VOID;
217
376
  }
218
- else if (small_struct)
219
- ecif.rvalue = &temp;
220
- else if (vfp_struct)
377
+ else if (flags == ARM_TYPE_VFP_N)
221
378
  {
222
379
  /* Largest case is double x 4. */
223
- ecif.rvalue = alloca(32);
380
+ rsize = 32;
224
381
  }
225
- else
226
- ecif.rvalue = rvalue;
382
+ else if (flags == ARM_TYPE_INT && rtype->type == FFI_TYPE_STRUCT)
383
+ rsize = 4;
227
384
 
228
- switch (cif->abi)
229
- {
230
- case FFI_SYSV:
231
- ffi_call_SYSV (fn, &ecif, cif->bytes, cif->flags, ecif.rvalue);
232
- break;
385
+ /* Largest case. */
386
+ vfp_size = (cif->abi == FFI_VFP && cif->vfp_used ? 8*8: 0);
233
387
 
234
- case FFI_VFP:
235
- ffi_call_VFP (fn, &ecif, cif->bytes, cif->flags, ecif.rvalue);
236
- break;
388
+ bytes = cif->bytes;
389
+ stack = alloca (vfp_size + bytes + sizeof(struct call_frame) + rsize);
237
390
 
238
- default:
239
- FFI_ASSERT(0);
240
- break;
391
+ vfp_space = NULL;
392
+ if (vfp_size)
393
+ {
394
+ vfp_space = stack;
395
+ stack += vfp_size;
241
396
  }
242
- if (small_struct)
243
- memcpy (rvalue, &temp, cif->rtype->size);
244
- else if (vfp_struct)
245
- memcpy (rvalue, ecif.rvalue, cif->rtype->size);
246
- }
247
397
 
248
- /** private members **/
398
+ frame = (struct call_frame *)(stack + bytes);
399
+
400
+ new_rvalue = rvalue;
401
+ if (rsize)
402
+ new_rvalue = (void *)(frame + 1);
249
403
 
250
- static void ffi_prep_incoming_args_SYSV (char *stack, void **ret,
251
- void** args, ffi_cif* cif, float *vfp_stack);
404
+ frame->rvalue = new_rvalue;
405
+ frame->flags = flags;
406
+ frame->closure = closure;
252
407
 
253
- void ffi_closure_SYSV (ffi_closure *);
408
+ if (vfp_space)
409
+ {
410
+ ffi_prep_args_VFP (cif, flags, new_rvalue, avalue, stack, vfp_space);
411
+ ffi_call_VFP (vfp_space, frame, fn, cif->vfp_used);
412
+ }
413
+ else
414
+ {
415
+ ffi_prep_args_SYSV (cif, flags, new_rvalue, avalue, stack);
416
+ ffi_call_SYSV (stack, frame, fn);
417
+ }
254
418
 
255
- void ffi_closure_VFP (ffi_closure *);
419
+ if (rvalue && rvalue != new_rvalue)
420
+ memcpy (rvalue, new_rvalue, rtype->size);
421
+ }
256
422
 
257
- /* This function is jumped to by the trampoline */
423
+ void
424
+ ffi_call (ffi_cif *cif, void (*fn) (void), void *rvalue, void **avalue)
425
+ {
426
+ ffi_call_int (cif, fn, rvalue, avalue, NULL);
427
+ }
258
428
 
259
- unsigned int
260
- ffi_closure_SYSV_inner (closure, respp, args, vfp_args)
261
- ffi_closure *closure;
262
- void **respp;
263
- void *args;
264
- void *vfp_args;
429
+ #ifdef FFI_GO_CLOSURES
430
+ void
431
+ ffi_call_go (ffi_cif *cif, void (*fn) (void), void *rvalue,
432
+ void **avalue, void *closure)
265
433
  {
266
- // our various things...
267
- ffi_cif *cif;
268
- void **arg_area;
434
+ ffi_call_int (cif, fn, rvalue, avalue, closure);
435
+ }
436
+ #endif
269
437
 
270
- cif = closure->cif;
271
- arg_area = (void**) alloca (cif->nargs * sizeof (void*));
438
+ static void *
439
+ ffi_prep_incoming_args_SYSV (ffi_cif *cif, void *rvalue,
440
+ char *argp, void **avalue)
441
+ {
442
+ ffi_type **arg_types = cif->arg_types;
443
+ int i, n;
272
444
 
273
- /* this call will initialize ARG_AREA, such that each
274
- * element in that array points to the corresponding
275
- * value on the stack; and if the function returns
276
- * a structure, it will re-set RESP to point to the
277
- * structure return address. */
445
+ if (cif->flags == ARM_TYPE_STRUCT)
446
+ {
447
+ rvalue = *(void **) argp;
448
+ argp += 4;
449
+ }
450
+ else
451
+ {
452
+ if (cif->rtype->size && cif->rtype->size < 4)
453
+ *(uint32_t *) rvalue = 0;
454
+ }
278
455
 
279
- ffi_prep_incoming_args_SYSV(args, respp, arg_area, cif, vfp_args);
456
+ for (i = 0, n = cif->nargs; i < n; i++)
457
+ {
458
+ ffi_type *ty = arg_types[i];
459
+ size_t z = ty->size;
280
460
 
281
- (closure->fun) (cif, *respp, arg_area, closure->user_data);
461
+ argp = ffi_align (ty, argp);
462
+ avalue[i] = (void *) argp;
463
+ argp += z;
464
+ }
282
465
 
283
- return cif->flags;
466
+ return rvalue;
284
467
  }
285
468
 
286
- /*@-exportheader@*/
287
- static void
288
- ffi_prep_incoming_args_SYSV(char *stack, void **rvalue,
289
- void **avalue, ffi_cif *cif,
290
- /* Used only under VFP hard-float ABI. */
291
- float *vfp_stack)
292
- /*@=exportheader@*/
469
+ static void *
470
+ ffi_prep_incoming_args_VFP (ffi_cif *cif, void *rvalue, char *stack,
471
+ char *vfp_space, void **avalue)
293
472
  {
294
- register unsigned int i, vi = 0;
295
- register void **p_argv;
296
- register char *argp;
297
- register ffi_type **p_arg;
473
+ ffi_type **arg_types = cif->arg_types;
474
+ int i, n, vi = 0;
475
+ char *argp, *regp, *eo_regp;
476
+ char done_with_regs = 0;
477
+ char stack_used = 0;
298
478
 
299
- argp = stack;
479
+ regp = stack;
480
+ eo_regp = argp = regp + 16;
300
481
 
301
- if ( cif->flags == FFI_TYPE_STRUCT ) {
302
- *rvalue = *(void **) argp;
303
- argp += 4;
304
- }
305
-
306
- p_argv = avalue;
482
+ if (cif->flags == ARM_TYPE_STRUCT)
483
+ {
484
+ rvalue = *(void **) regp;
485
+ regp += 4;
486
+ }
307
487
 
308
- for (i = cif->nargs, p_arg = cif->arg_types; (i != 0); i--, p_arg++)
488
+ for (i = 0, n = cif->nargs; i < n; i++)
309
489
  {
310
- size_t z;
311
- size_t alignment;
312
-
313
- if (cif->abi == FFI_VFP
314
- && vi < cif->vfp_nargs && vfp_type_p (*p_arg))
490
+ ffi_type *ty = arg_types[i];
491
+ int is_vfp_type = vfp_type_p (ty);
492
+ size_t z = ty->size;
493
+
494
+ if (vi < cif->vfp_nargs && is_vfp_type)
315
495
  {
316
- *p_argv++ = (void*)(vfp_stack + cif->vfp_args[vi++]);
496
+ avalue[i] = vfp_space + cif->vfp_args[vi++] * 4;
317
497
  continue;
318
498
  }
499
+ else if (!done_with_regs && !is_vfp_type)
500
+ {
501
+ char *tregp = ffi_align (ty, regp);
319
502
 
320
- alignment = (*p_arg)->alignment;
321
- if (alignment < 4)
322
- alignment = 4;
323
- /* Align if necessary */
324
- if ((alignment - 1) & (unsigned) argp) {
325
- argp = (char *) ALIGN(argp, alignment);
326
- }
327
-
328
- z = (*p_arg)->size;
329
-
330
- /* because we're little endian, this is what it turns into. */
503
+ z = (z < 4) ? 4 : z; // pad
331
504
 
332
- *p_argv = (void*) argp;
505
+ /* If the arguments either fits into the registers or uses registers
506
+ and stack, while we haven't read other things from the stack */
507
+ if (tregp + z <= eo_regp || !stack_used)
508
+ {
509
+ /* Because we're little endian, this is what it turns into. */
510
+ avalue[i] = (void *) tregp;
511
+ regp = tregp + z;
512
+
513
+ /* If we read past the last core register, make sure we
514
+ have not read from the stack before and continue
515
+ reading after regp. */
516
+ if (regp > eo_regp)
517
+ {
518
+ FFI_ASSERT (!stack_used);
519
+ argp = regp;
520
+ }
521
+ if (regp >= eo_regp)
522
+ {
523
+ done_with_regs = 1;
524
+ stack_used = 1;
525
+ }
526
+ continue;
527
+ }
528
+ }
333
529
 
334
- p_argv++;
530
+ stack_used = 1;
531
+ argp = ffi_align (ty, argp);
532
+ avalue[i] = (void *) argp;
335
533
  argp += z;
336
534
  }
337
-
338
- return;
339
- }
340
535
 
341
- /* How to make a trampoline. */
342
-
343
- #if FFI_EXEC_TRAMPOLINE_TABLE
344
-
345
- #include <mach/mach.h>
346
- #include <pthread.h>
347
- #include <stdio.h>
348
- #include <stdlib.h>
349
-
350
- extern void *ffi_closure_trampoline_table_page;
351
-
352
- typedef struct ffi_trampoline_table ffi_trampoline_table;
353
- typedef struct ffi_trampoline_table_entry ffi_trampoline_table_entry;
354
-
355
- struct ffi_trampoline_table {
356
- /* contigious writable and executable pages */
357
- vm_address_t config_page;
358
- vm_address_t trampoline_page;
359
-
360
- /* free list tracking */
361
- uint16_t free_count;
362
- ffi_trampoline_table_entry *free_list;
363
- ffi_trampoline_table_entry *free_list_pool;
364
-
365
- ffi_trampoline_table *prev;
366
- ffi_trampoline_table *next;
367
- };
536
+ return rvalue;
537
+ }
368
538
 
369
- struct ffi_trampoline_table_entry {
370
- void *(*trampoline)();
371
- ffi_trampoline_table_entry *next;
539
+ struct closure_frame
540
+ {
541
+ char vfp_space[8*8] __attribute__((aligned(8)));
542
+ char result[8*4];
543
+ char argp[];
372
544
  };
373
545
 
374
- /* Override the standard architecture trampoline size */
375
- // XXX TODO - Fix
376
- #undef FFI_TRAMPOLINE_SIZE
377
- #define FFI_TRAMPOLINE_SIZE 12
378
-
379
- /* The trampoline configuration is placed at 4080 bytes prior to the trampoline's entry point */
380
- #define FFI_TRAMPOLINE_CODELOC_CONFIG(codeloc) ((void **) (((uint8_t *) codeloc) - 4080));
381
-
382
- /* The first 16 bytes of the config page are unused, as they are unaddressable from the trampoline page. */
383
- #define FFI_TRAMPOLINE_CONFIG_PAGE_OFFSET 16
384
-
385
- /* Total number of trampolines that fit in one trampoline table */
386
- #define FFI_TRAMPOLINE_COUNT ((PAGE_SIZE - FFI_TRAMPOLINE_CONFIG_PAGE_OFFSET) / FFI_TRAMPOLINE_SIZE)
387
-
388
- static pthread_mutex_t ffi_trampoline_lock = PTHREAD_MUTEX_INITIALIZER;
389
- static ffi_trampoline_table *ffi_trampoline_tables = NULL;
390
-
391
- static ffi_trampoline_table *
392
- ffi_trampoline_table_alloc ()
546
+ int FFI_HIDDEN
547
+ ffi_closure_inner_SYSV (ffi_cif *cif,
548
+ void (*fun) (ffi_cif *, void *, void **, void *),
549
+ void *user_data,
550
+ struct closure_frame *frame)
393
551
  {
394
- ffi_trampoline_table *table = NULL;
552
+ void **avalue = (void **) alloca (cif->nargs * sizeof (void *));
553
+ void *rvalue = ffi_prep_incoming_args_SYSV (cif, frame->result,
554
+ frame->argp, avalue);
555
+ fun (cif, rvalue, avalue, user_data);
556
+ return cif->flags;
557
+ }
395
558
 
396
- /* Loop until we can allocate two contigious pages */
397
- while (table == NULL) {
398
- vm_address_t config_page = 0x0;
399
- kern_return_t kt;
559
+ int FFI_HIDDEN
560
+ ffi_closure_inner_VFP (ffi_cif *cif,
561
+ void (*fun) (ffi_cif *, void *, void **, void *),
562
+ void *user_data,
563
+ struct closure_frame *frame)
564
+ {
565
+ void **avalue = (void **) alloca (cif->nargs * sizeof (void *));
566
+ void *rvalue = ffi_prep_incoming_args_VFP (cif, frame->result, frame->argp,
567
+ frame->vfp_space, avalue);
568
+ fun (cif, rvalue, avalue, user_data);
569
+ return cif->flags;
570
+ }
400
571
 
401
- /* Try to allocate two pages */
402
- kt = vm_allocate (mach_task_self (), &config_page, PAGE_SIZE*2, VM_FLAGS_ANYWHERE);
403
- if (kt != KERN_SUCCESS) {
404
- fprintf(stderr, "vm_allocate() failure: %d at %s:%d\n", kt, __FILE__, __LINE__);
405
- break;
406
- }
572
+ void ffi_closure_SYSV (void) FFI_HIDDEN;
573
+ void ffi_closure_VFP (void) FFI_HIDDEN;
407
574
 
408
- /* Now drop the second half of the allocation to make room for the trampoline table */
409
- vm_address_t trampoline_page = config_page+PAGE_SIZE;
410
- kt = vm_deallocate (mach_task_self (), trampoline_page, PAGE_SIZE);
411
- if (kt != KERN_SUCCESS) {
412
- fprintf(stderr, "vm_deallocate() failure: %d at %s:%d\n", kt, __FILE__, __LINE__);
413
- break;
414
- }
575
+ #ifdef FFI_GO_CLOSURES
576
+ void ffi_go_closure_SYSV (void) FFI_HIDDEN;
577
+ void ffi_go_closure_VFP (void) FFI_HIDDEN;
578
+ #endif
415
579
 
416
- /* Remap the trampoline table to directly follow the config page */
417
- vm_prot_t cur_prot;
418
- vm_prot_t max_prot;
580
+ /* the cif must already be prep'ed */
419
581
 
420
- kt = vm_remap (mach_task_self (), &trampoline_page, PAGE_SIZE, 0x0, FALSE, mach_task_self (), (vm_address_t) &ffi_closure_trampoline_table_page, FALSE, &cur_prot, &max_prot, VM_INHERIT_SHARE);
582
+ #if defined(__FreeBSD__) && defined(__arm__)
583
+ #define __clear_cache(start, end) do { \
584
+ struct arm_sync_icache_args ua; \
585
+ \
586
+ ua.addr = (uintptr_t)(start); \
587
+ ua.len = (char *)(end) - (char *)start; \
588
+ sysarch(ARM_SYNC_ICACHE, &ua); \
589
+ } while (0);
590
+ #endif
421
591
 
422
- /* If we lost access to the destination trampoline page, drop our config allocation mapping and retry */
423
- if (kt != KERN_SUCCESS) {
424
- /* Log unexpected failures */
425
- if (kt != KERN_NO_SPACE) {
426
- fprintf(stderr, "vm_remap() failure: %d at %s:%d\n", kt, __FILE__, __LINE__);
427
- }
592
+ ffi_status
593
+ ffi_prep_closure_loc (ffi_closure * closure,
594
+ ffi_cif * cif,
595
+ void (*fun) (ffi_cif *, void *, void **, void *),
596
+ void *user_data, void *codeloc)
597
+ {
598
+ void (*closure_func) (void) = ffi_closure_SYSV;
428
599
 
429
- vm_deallocate (mach_task_self (), config_page, PAGE_SIZE);
430
- continue;
600
+ if (cif->abi == FFI_VFP)
601
+ {
602
+ /* We only need take the vfp path if there are vfp arguments. */
603
+ if (cif->vfp_used)
604
+ closure_func = ffi_closure_VFP;
431
605
  }
606
+ else if (cif->abi != FFI_SYSV)
607
+ return FFI_BAD_ABI;
432
608
 
433
- /* We have valid trampoline and config pages */
434
- table = calloc (1, sizeof(ffi_trampoline_table));
435
- table->free_count = FFI_TRAMPOLINE_COUNT;
436
- table->config_page = config_page;
437
- table->trampoline_page = trampoline_page;
438
-
439
- /* Create and initialize the free list */
440
- table->free_list_pool = calloc(FFI_TRAMPOLINE_COUNT, sizeof(ffi_trampoline_table_entry));
609
+ #if FFI_EXEC_TRAMPOLINE_TABLE
610
+ void **config = (void **)((uint8_t *)codeloc - PAGE_MAX_SIZE);
611
+ config[0] = closure;
612
+ config[1] = closure_func;
613
+ #else
441
614
 
442
- uint16_t i;
443
- for (i = 0; i < table->free_count; i++) {
444
- ffi_trampoline_table_entry *entry = &table->free_list_pool[i];
445
- entry->trampoline = (void *) (table->trampoline_page + (i * FFI_TRAMPOLINE_SIZE));
615
+ #ifndef _M_ARM
616
+ memcpy(closure->tramp, ffi_arm_trampoline, 8);
617
+ #else
618
+ // cast away function type so MSVC doesn't set the lower bit of the function pointer
619
+ memcpy(closure->tramp, (void*)((uintptr_t)ffi_arm_trampoline & 0xFFFFFFFE), FFI_TRAMPOLINE_CLOSURE_OFFSET);
620
+ #endif
446
621
 
447
- if (i < table->free_count - 1)
448
- entry->next = &table->free_list_pool[i+1];
449
- }
622
+ #if defined (__QNX__)
623
+ msync(closure->tramp, 8, 0x1000000); /* clear data map */
624
+ msync(codeloc, 8, 0x1000000); /* clear insn map */
625
+ #elif defined(_MSC_VER)
626
+ FlushInstructionCache(GetCurrentProcess(), closure->tramp, FFI_TRAMPOLINE_SIZE);
627
+ #else
628
+ __clear_cache(closure->tramp, closure->tramp + 8); /* clear data map */
629
+ __clear_cache(codeloc, codeloc + 8); /* clear insn map */
630
+ #endif
631
+ #ifdef _M_ARM
632
+ *(void(**)(void))(closure->tramp + FFI_TRAMPOLINE_CLOSURE_FUNCTION) = closure_func;
633
+ #else
634
+ *(void (**)(void))(closure->tramp + 8) = closure_func;
635
+ #endif
636
+ #endif
450
637
 
451
- table->free_list = table->free_list_pool;
452
- }
638
+ closure->cif = cif;
639
+ closure->fun = fun;
640
+ closure->user_data = user_data;
453
641
 
454
- return table;
642
+ return FFI_OK;
455
643
  }
456
644
 
457
- void *
458
- ffi_closure_alloc (size_t size, void **code)
645
+ #ifdef FFI_GO_CLOSURES
646
+ ffi_status
647
+ ffi_prep_go_closure (ffi_go_closure *closure, ffi_cif *cif,
648
+ void (*fun) (ffi_cif *, void *, void **, void *))
459
649
  {
460
- /* Create the closure */
461
- ffi_closure *closure = malloc(size);
462
- if (closure == NULL)
463
- return NULL;
464
-
465
- pthread_mutex_lock(&ffi_trampoline_lock);
466
-
467
- /* Check for an active trampoline table with available entries. */
468
- ffi_trampoline_table *table = ffi_trampoline_tables;
469
- if (table == NULL || table->free_list == NULL) {
470
- table = ffi_trampoline_table_alloc ();
471
- if (table == NULL) {
472
- free(closure);
473
- return NULL;
474
- }
650
+ void (*closure_func) (void) = ffi_go_closure_SYSV;
475
651
 
476
- /* Insert the new table at the top of the list */
477
- table->next = ffi_trampoline_tables;
478
- if (table->next != NULL)
479
- table->next->prev = table;
480
-
481
- ffi_trampoline_tables = table;
482
- }
652
+ if (cif->abi == FFI_VFP)
653
+ {
654
+ /* We only need take the vfp path if there are vfp arguments. */
655
+ if (cif->vfp_used)
656
+ closure_func = ffi_go_closure_VFP;
657
+ }
658
+ else if (cif->abi != FFI_SYSV)
659
+ return FFI_BAD_ABI;
483
660
 
484
- /* Claim the free entry */
485
- ffi_trampoline_table_entry *entry = ffi_trampoline_tables->free_list;
486
- ffi_trampoline_tables->free_list = entry->next;
487
- ffi_trampoline_tables->free_count--;
488
- entry->next = NULL;
661
+ closure->tramp = closure_func;
662
+ closure->cif = cif;
663
+ closure->fun = fun;
489
664
 
490
- pthread_mutex_unlock(&ffi_trampoline_lock);
665
+ return FFI_OK;
666
+ }
667
+ #endif
491
668
 
492
- /* Initialize the return values */
493
- *code = entry->trampoline;
494
- closure->trampoline_table = table;
495
- closure->trampoline_table_entry = entry;
669
+ /* Below are routines for VFP hard-float support. */
496
670
 
497
- return closure;
498
- }
671
+ /* A subroutine of vfp_type_p. Given a structure type, return the type code
672
+ of the first non-structure element. Recurse for structure elements.
673
+ Return -1 if the structure is in fact empty, i.e. no nested elements. */
499
674
 
500
- void
501
- ffi_closure_free (void *ptr)
675
+ static int
676
+ is_hfa0 (const ffi_type *ty)
502
677
  {
503
- ffi_closure *closure = ptr;
504
-
505
- pthread_mutex_lock(&ffi_trampoline_lock);
506
-
507
- /* Fetch the table and entry references */
508
- ffi_trampoline_table *table = closure->trampoline_table;
509
- ffi_trampoline_table_entry *entry = closure->trampoline_table_entry;
510
-
511
- /* Return the entry to the free list */
512
- entry->next = table->free_list;
513
- table->free_list = entry;
514
- table->free_count++;
515
-
516
- /* If all trampolines within this table are free, and at least one other table exists, deallocate
517
- * the table */
518
- if (table->free_count == FFI_TRAMPOLINE_COUNT && ffi_trampoline_tables != table) {
519
- /* Remove from the list */
520
- if (table->prev != NULL)
521
- table->prev->next = table->next;
522
-
523
- if (table->next != NULL)
524
- table->next->prev = table->prev;
525
-
526
- /* Deallocate pages */
527
- kern_return_t kt;
528
- kt = vm_deallocate (mach_task_self (), table->config_page, PAGE_SIZE);
529
- if (kt != KERN_SUCCESS)
530
- fprintf(stderr, "vm_deallocate() failure: %d at %s:%d\n", kt, __FILE__, __LINE__);
531
-
532
- kt = vm_deallocate (mach_task_self (), table->trampoline_page, PAGE_SIZE);
533
- if (kt != KERN_SUCCESS)
534
- fprintf(stderr, "vm_deallocate() failure: %d at %s:%d\n", kt, __FILE__, __LINE__);
535
-
536
- /* Deallocate free list */
537
- free (table->free_list_pool);
538
- free (table);
539
- } else if (ffi_trampoline_tables != table) {
540
- /* Otherwise, bump this table to the top of the list */
541
- table->prev = NULL;
542
- table->next = ffi_trampoline_tables;
543
- if (ffi_trampoline_tables != NULL)
544
- ffi_trampoline_tables->prev = table;
545
-
546
- ffi_trampoline_tables = table;
547
- }
548
-
549
- pthread_mutex_unlock (&ffi_trampoline_lock);
550
-
551
- /* Free the closure */
552
- free (closure);
553
- }
678
+ ffi_type **elements = ty->elements;
679
+ int i, ret = -1;
554
680
 
555
- #else
556
-
557
- #define FFI_INIT_TRAMPOLINE(TRAMP,FUN,CTX) \
558
- ({ unsigned char *__tramp = (unsigned char*)(TRAMP); \
559
- unsigned int __fun = (unsigned int)(FUN); \
560
- unsigned int __ctx = (unsigned int)(CTX); \
561
- unsigned char *insns = (unsigned char *)(CTX); \
562
- *(unsigned int*) &__tramp[0] = 0xe92d000f; /* stmfd sp!, {r0-r3} */ \
563
- *(unsigned int*) &__tramp[4] = 0xe59f0000; /* ldr r0, [pc] */ \
564
- *(unsigned int*) &__tramp[8] = 0xe59ff000; /* ldr pc, [pc] */ \
565
- *(unsigned int*) &__tramp[12] = __ctx; \
566
- *(unsigned int*) &__tramp[16] = __fun; \
567
- __clear_cache((&__tramp[0]), (&__tramp[19])); /* Clear data mapping. */ \
568
- __clear_cache(insns, insns + 3 * sizeof (unsigned int)); \
569
- /* Clear instruction \
570
- mapping. */ \
571
- })
681
+ if (elements != NULL)
682
+ for (i = 0; elements[i]; ++i)
683
+ {
684
+ ret = elements[i]->type;
685
+ if (ret == FFI_TYPE_STRUCT || ret == FFI_TYPE_COMPLEX)
686
+ {
687
+ ret = is_hfa0 (elements[i]);
688
+ if (ret < 0)
689
+ continue;
690
+ }
691
+ break;
692
+ }
572
693
 
573
- #endif
694
+ return ret;
695
+ }
574
696
 
575
- /* the cif must already be prep'ed */
697
+ /* A subroutine of vfp_type_p. Given a structure type, return true if all
698
+ of the non-structure elements are the same as CANDIDATE. */
576
699
 
577
- ffi_status
578
- ffi_prep_closure_loc (ffi_closure* closure,
579
- ffi_cif* cif,
580
- void (*fun)(ffi_cif*,void*,void**,void*),
581
- void *user_data,
582
- void *codeloc)
700
+ static int
701
+ is_hfa1 (const ffi_type *ty, int candidate)
583
702
  {
584
- void (*closure_func)(ffi_closure*) = NULL;
585
-
586
- if (cif->abi == FFI_SYSV)
587
- closure_func = &ffi_closure_SYSV;
588
- else if (cif->abi == FFI_VFP)
589
- closure_func = &ffi_closure_VFP;
590
- else
591
- return FFI_BAD_ABI;
592
-
593
- #if FFI_EXEC_TRAMPOLINE_TABLE
594
- void **config = FFI_TRAMPOLINE_CODELOC_CONFIG(codeloc);
595
- config[0] = closure;
596
- config[1] = closure_func;
597
- #else
598
- FFI_INIT_TRAMPOLINE (&closure->tramp[0], \
599
- closure_func, \
600
- codeloc);
601
- #endif
703
+ ffi_type **elements = ty->elements;
704
+ int i;
602
705
 
603
- closure->cif = cif;
604
- closure->user_data = user_data;
605
- closure->fun = fun;
706
+ if (elements != NULL)
707
+ for (i = 0; elements[i]; ++i)
708
+ {
709
+ int t = elements[i]->type;
710
+ if (t == FFI_TYPE_STRUCT || t == FFI_TYPE_COMPLEX)
711
+ {
712
+ if (!is_hfa1 (elements[i], candidate))
713
+ return 0;
714
+ }
715
+ else if (t != candidate)
716
+ return 0;
717
+ }
606
718
 
607
- return FFI_OK;
719
+ return 1;
608
720
  }
609
721
 
610
- /* Below are routines for VFP hard-float support. */
722
+ /* Determine if TY is an homogenous floating point aggregate (HFA).
723
+ That is, a structure consisting of 1 to 4 members of all the same type,
724
+ where that type is a floating point scalar.
611
725
 
612
- static int rec_vfp_type_p (ffi_type *t, int *elt, int *elnum)
726
+ Returns non-zero iff TY is an HFA. The result is an encoded value where
727
+ bits 0-7 contain the type code, and bits 8-10 contain the element count. */
728
+
729
+ static int
730
+ vfp_type_p (const ffi_type *ty)
613
731
  {
614
- switch (t->type)
732
+ ffi_type **elements;
733
+ int candidate, i;
734
+ size_t size, ele_count;
735
+
736
+ /* Quickest tests first. */
737
+ candidate = ty->type;
738
+ switch (ty->type)
615
739
  {
740
+ default:
741
+ return 0;
616
742
  case FFI_TYPE_FLOAT:
617
743
  case FFI_TYPE_DOUBLE:
618
- *elt = (int) t->type;
619
- *elnum = 1;
620
- return 1;
744
+ ele_count = 1;
745
+ goto done;
746
+ case FFI_TYPE_COMPLEX:
747
+ candidate = ty->elements[0]->type;
748
+ if (candidate != FFI_TYPE_FLOAT && candidate != FFI_TYPE_DOUBLE)
749
+ return 0;
750
+ ele_count = 2;
751
+ goto done;
752
+ case FFI_TYPE_STRUCT:
753
+ break;
754
+ }
621
755
 
622
- case FFI_TYPE_STRUCT_VFP_FLOAT:
623
- *elt = FFI_TYPE_FLOAT;
624
- *elnum = t->size / sizeof (float);
625
- return 1;
756
+ /* No HFA types are smaller than 4 bytes, or larger than 32 bytes. */
757
+ size = ty->size;
758
+ if (size < 4 || size > 32)
759
+ return 0;
626
760
 
627
- case FFI_TYPE_STRUCT_VFP_DOUBLE:
628
- *elt = FFI_TYPE_DOUBLE;
629
- *elnum = t->size / sizeof (double);
630
- return 1;
761
+ /* Find the type of the first non-structure member. */
762
+ elements = ty->elements;
763
+ candidate = elements[0]->type;
764
+ if (candidate == FFI_TYPE_STRUCT || candidate == FFI_TYPE_COMPLEX)
765
+ {
766
+ for (i = 0; ; ++i)
767
+ {
768
+ candidate = is_hfa0 (elements[i]);
769
+ if (candidate >= 0)
770
+ break;
771
+ }
772
+ }
631
773
 
632
- case FFI_TYPE_STRUCT:;
633
- {
634
- int base_elt = 0, total_elnum = 0;
635
- ffi_type **el = t->elements;
636
- while (*el)
637
- {
638
- int el_elt = 0, el_elnum = 0;
639
- if (! rec_vfp_type_p (*el, &el_elt, &el_elnum)
640
- || (base_elt && base_elt != el_elt)
641
- || total_elnum + el_elnum > 4)
642
- return 0;
643
- base_elt = el_elt;
644
- total_elnum += el_elnum;
645
- el++;
646
- }
647
- *elnum = total_elnum;
648
- *elt = base_elt;
649
- return 1;
650
- }
651
- default: ;
774
+ /* If the first member is not a floating point type, it's not an HFA.
775
+ Also quickly re-check the size of the structure. */
776
+ switch (candidate)
777
+ {
778
+ case FFI_TYPE_FLOAT:
779
+ ele_count = size / sizeof(float);
780
+ if (size != ele_count * sizeof(float))
781
+ return 0;
782
+ break;
783
+ case FFI_TYPE_DOUBLE:
784
+ ele_count = size / sizeof(double);
785
+ if (size != ele_count * sizeof(double))
786
+ return 0;
787
+ break;
788
+ default:
789
+ return 0;
652
790
  }
653
- return 0;
654
- }
791
+ if (ele_count > 4)
792
+ return 0;
655
793
 
656
- static int vfp_type_p (ffi_type *t)
657
- {
658
- int elt, elnum;
659
- if (rec_vfp_type_p (t, &elt, &elnum))
794
+ /* Finally, make sure that all scalar elements are the same type. */
795
+ for (i = 0; elements[i]; ++i)
660
796
  {
661
- if (t->type == FFI_TYPE_STRUCT)
662
- {
663
- if (elnum == 1)
664
- t->type = elt;
665
- else
666
- t->type = (elt == FFI_TYPE_FLOAT
667
- ? FFI_TYPE_STRUCT_VFP_FLOAT
668
- : FFI_TYPE_STRUCT_VFP_DOUBLE);
669
- }
670
- return (int) t->type;
797
+ int t = elements[i]->type;
798
+ if (t == FFI_TYPE_STRUCT || t == FFI_TYPE_COMPLEX)
799
+ {
800
+ if (!is_hfa1 (elements[i], candidate))
801
+ return 0;
802
+ }
803
+ else if (t != candidate)
804
+ return 0;
671
805
  }
672
- return 0;
806
+
807
+ /* All tests succeeded. Encode the result. */
808
+ done:
809
+ return (ele_count << 8) | candidate;
673
810
  }
674
811
 
675
- static void place_vfp_arg (ffi_cif *cif, ffi_type *t)
812
+ static int
813
+ place_vfp_arg (ffi_cif *cif, int h)
676
814
  {
677
- int reg = cif->vfp_reg_free;
678
- int nregs = t->size / sizeof (float);
679
- int align = ((t->type == FFI_TYPE_STRUCT_VFP_FLOAT
680
- || t->type == FFI_TYPE_FLOAT) ? 1 : 2);
815
+ unsigned short reg = cif->vfp_reg_free;
816
+ int align = 1, nregs = h >> 8;
817
+
818
+ if ((h & 0xff) == FFI_TYPE_DOUBLE)
819
+ align = 2, nregs *= 2;
820
+
681
821
  /* Align register number. */
682
822
  if ((reg & 1) && align == 2)
683
823
  reg++;
824
+
684
825
  while (reg + nregs <= 16)
685
826
  {
686
827
  int s, new_used = 0;
@@ -695,7 +836,7 @@ static void place_vfp_arg (ffi_cif *cif, ffi_type *t)
695
836
  }
696
837
  /* Found regs to allocate. */
697
838
  cif->vfp_used |= new_used;
698
- cif->vfp_args[cif->vfp_nargs++] = reg;
839
+ cif->vfp_args[cif->vfp_nargs++] = (signed char)reg;
699
840
 
700
841
  /* Update vfp_reg_free. */
701
842
  if (cif->vfp_used & (1 << cif->vfp_reg_free))
@@ -705,24 +846,31 @@ static void place_vfp_arg (ffi_cif *cif, ffi_type *t)
705
846
  reg += 1;
706
847
  cif->vfp_reg_free = reg;
707
848
  }
708
- return;
709
- next_reg: ;
849
+ return 0;
850
+ next_reg:;
710
851
  }
852
+ // done, mark all regs as used
853
+ cif->vfp_reg_free = 16;
854
+ cif->vfp_used = 0xFFFF;
855
+ return 1;
711
856
  }
712
857
 
713
- static void layout_vfp_args (ffi_cif *cif)
858
+ static void
859
+ layout_vfp_args (ffi_cif * cif)
714
860
  {
715
- int i;
861
+ unsigned int i;
716
862
  /* Init VFP fields */
717
863
  cif->vfp_used = 0;
718
864
  cif->vfp_nargs = 0;
719
865
  cif->vfp_reg_free = 0;
720
- memset (cif->vfp_args, -1, 16); /* Init to -1. */
866
+ memset (cif->vfp_args, -1, 16); /* Init to -1. */
721
867
 
722
868
  for (i = 0; i < cif->nargs; i++)
723
869
  {
724
- ffi_type *t = cif->arg_types[i];
725
- if (vfp_type_p (t))
726
- place_vfp_arg (cif, t);
870
+ int h = vfp_type_p (cif->arg_types[i]);
871
+ if (h && place_vfp_arg (cif, h) == 1)
872
+ break;
727
873
  }
728
874
  }
875
+
876
+ #endif /* __arm__ or _M_ARM */