ffi 1.11.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (542) hide show
  1. checksums.yaml +7 -0
  2. data/.appveyor.yml +27 -0
  3. data/.gitignore +25 -0
  4. data/.gitmodules +4 -0
  5. data/.travis.yml +42 -0
  6. data/.yardopts +5 -0
  7. data/CHANGELOG.md +147 -0
  8. data/COPYING +49 -0
  9. data/Gemfile +15 -0
  10. data/LICENSE +24 -0
  11. data/LICENSE.SPECS +22 -0
  12. data/README.md +115 -0
  13. data/Rakefile +196 -0
  14. data/ext/ffi_c/AbstractMemory.c +1109 -0
  15. data/ext/ffi_c/AbstractMemory.h +175 -0
  16. data/ext/ffi_c/ArrayType.c +162 -0
  17. data/ext/ffi_c/ArrayType.h +59 -0
  18. data/ext/ffi_c/Buffer.c +365 -0
  19. data/ext/ffi_c/Call.c +503 -0
  20. data/ext/ffi_c/Call.h +107 -0
  21. data/ext/ffi_c/ClosurePool.c +283 -0
  22. data/ext/ffi_c/ClosurePool.h +57 -0
  23. data/ext/ffi_c/DynamicLibrary.c +339 -0
  24. data/ext/ffi_c/DynamicLibrary.h +98 -0
  25. data/ext/ffi_c/Function.c +917 -0
  26. data/ext/ffi_c/Function.h +87 -0
  27. data/ext/ffi_c/FunctionInfo.c +271 -0
  28. data/ext/ffi_c/LastError.c +229 -0
  29. data/ext/ffi_c/LastError.h +47 -0
  30. data/ext/ffi_c/LongDouble.c +63 -0
  31. data/ext/ffi_c/LongDouble.h +51 -0
  32. data/ext/ffi_c/MappedType.c +168 -0
  33. data/ext/ffi_c/MappedType.h +59 -0
  34. data/ext/ffi_c/MemoryPointer.c +197 -0
  35. data/ext/ffi_c/MemoryPointer.h +53 -0
  36. data/ext/ffi_c/MethodHandle.c +358 -0
  37. data/ext/ffi_c/MethodHandle.h +55 -0
  38. data/ext/ffi_c/Platform.c +82 -0
  39. data/ext/ffi_c/Platform.h +45 -0
  40. data/ext/ffi_c/Pointer.c +508 -0
  41. data/ext/ffi_c/Pointer.h +63 -0
  42. data/ext/ffi_c/Struct.c +829 -0
  43. data/ext/ffi_c/Struct.h +106 -0
  44. data/ext/ffi_c/StructByValue.c +150 -0
  45. data/ext/ffi_c/StructByValue.h +55 -0
  46. data/ext/ffi_c/StructLayout.c +698 -0
  47. data/ext/ffi_c/Thread.c +137 -0
  48. data/ext/ffi_c/Thread.h +84 -0
  49. data/ext/ffi_c/Type.c +379 -0
  50. data/ext/ffi_c/Type.h +61 -0
  51. data/ext/ffi_c/Types.c +139 -0
  52. data/ext/ffi_c/Types.h +89 -0
  53. data/ext/ffi_c/Variadic.c +298 -0
  54. data/ext/ffi_c/compat.h +78 -0
  55. data/ext/ffi_c/extconf.rb +86 -0
  56. data/ext/ffi_c/ffi.c +93 -0
  57. data/ext/ffi_c/libffi.bsd.mk +40 -0
  58. data/ext/ffi_c/libffi.darwin.mk +105 -0
  59. data/ext/ffi_c/libffi.gnu.mk +32 -0
  60. data/ext/ffi_c/libffi.mk +18 -0
  61. data/ext/ffi_c/libffi.vc.mk +26 -0
  62. data/ext/ffi_c/libffi.vc64.mk +26 -0
  63. data/ext/ffi_c/libffi/.appveyor.yml +66 -0
  64. data/ext/ffi_c/libffi/.gitattributes +4 -0
  65. data/ext/ffi_c/libffi/.github/issue_template.md +10 -0
  66. data/ext/ffi_c/libffi/.gitignore +38 -0
  67. data/ext/ffi_c/libffi/.travis.yml +63 -0
  68. data/ext/ffi_c/libffi/.travis/ar-lib +270 -0
  69. data/ext/ffi_c/libffi/.travis/build-in-container.sh +22 -0
  70. data/ext/ffi_c/libffi/.travis/build.sh +110 -0
  71. data/ext/ffi_c/libffi/.travis/compile +351 -0
  72. data/ext/ffi_c/libffi/.travis/install.sh +43 -0
  73. data/ext/ffi_c/libffi/.travis/moxie-sim.exp +60 -0
  74. data/ext/ffi_c/libffi/.travis/site.exp +18 -0
  75. data/ext/ffi_c/libffi/ChangeLog.libffi +584 -0
  76. data/ext/ffi_c/libffi/ChangeLog.libffi-3.1 +6000 -0
  77. data/ext/ffi_c/libffi/ChangeLog.libgcj +40 -0
  78. data/ext/ffi_c/libffi/ChangeLog.v1 +764 -0
  79. data/ext/ffi_c/libffi/LICENSE +21 -0
  80. data/ext/ffi_c/libffi/LICENSE-BUILDTOOLS +353 -0
  81. data/ext/ffi_c/libffi/Makefile.am +158 -0
  82. data/ext/ffi_c/libffi/README.md +470 -0
  83. data/ext/ffi_c/libffi/acinclude.m4 +479 -0
  84. data/ext/ffi_c/libffi/autogen.sh +2 -0
  85. data/ext/ffi_c/libffi/config.guess +1466 -0
  86. data/ext/ffi_c/libffi/config.sub +1836 -0
  87. data/ext/ffi_c/libffi/configure.ac +394 -0
  88. data/ext/ffi_c/libffi/configure.host +303 -0
  89. data/ext/ffi_c/libffi/generate-darwin-source-and-headers.py +203 -0
  90. data/ext/ffi_c/libffi/include/Makefile.am +9 -0
  91. data/ext/ffi_c/libffi/include/ffi.h.in +515 -0
  92. data/ext/ffi_c/libffi/include/ffi_cfi.h +55 -0
  93. data/ext/ffi_c/libffi/include/ffi_common.h +153 -0
  94. data/ext/ffi_c/libffi/libffi.map.in +80 -0
  95. data/ext/ffi_c/libffi/libffi.pc.in +11 -0
  96. data/ext/ffi_c/libffi/libffi.xcodeproj/project.pbxproj +1043 -0
  97. data/ext/ffi_c/libffi/libtool-version +29 -0
  98. data/ext/ffi_c/libffi/m4/asmcfi.m4 +13 -0
  99. data/ext/ffi_c/libffi/m4/ax_append_flag.m4 +71 -0
  100. data/ext/ffi_c/libffi/m4/ax_cc_maxopt.m4 +194 -0
  101. data/ext/ffi_c/libffi/m4/ax_cflags_warn_all.m4 +122 -0
  102. data/ext/ffi_c/libffi/m4/ax_check_compile_flag.m4 +74 -0
  103. data/ext/ffi_c/libffi/m4/ax_compiler_vendor.m4 +87 -0
  104. data/ext/ffi_c/libffi/m4/ax_configure_args.m4 +70 -0
  105. data/ext/ffi_c/libffi/m4/ax_enable_builddir.m4 +302 -0
  106. data/ext/ffi_c/libffi/m4/ax_gcc_archflag.m4 +263 -0
  107. data/ext/ffi_c/libffi/m4/ax_gcc_x86_cpuid.m4 +89 -0
  108. data/ext/ffi_c/libffi/m4/ax_require_defined.m4 +37 -0
  109. data/ext/ffi_c/libffi/make_sunver.pl +333 -0
  110. data/ext/ffi_c/libffi/man/Makefile.am +8 -0
  111. data/ext/ffi_c/libffi/man/ffi.3 +41 -0
  112. data/ext/ffi_c/libffi/man/ffi_call.3 +103 -0
  113. data/ext/ffi_c/libffi/man/ffi_prep_cif.3 +68 -0
  114. data/ext/ffi_c/libffi/man/ffi_prep_cif_var.3 +73 -0
  115. data/ext/ffi_c/libffi/msvc_build/aarch64/Ffi_staticLib.sln +33 -0
  116. data/ext/ffi_c/libffi/msvc_build/aarch64/Ffi_staticLib.vcxproj +130 -0
  117. data/ext/ffi_c/libffi/msvc_build/aarch64/Ffi_staticLib.vcxproj.filters +57 -0
  118. data/ext/ffi_c/libffi/msvc_build/aarch64/Ffi_staticLib.vcxproj.user +4 -0
  119. data/ext/ffi_c/libffi/msvc_build/aarch64/aarch64_include/ffi.h +511 -0
  120. data/ext/ffi_c/libffi/msvcc.sh +353 -0
  121. data/ext/ffi_c/libffi/src/aarch64/ffi.c +1009 -0
  122. data/ext/ffi_c/libffi/src/aarch64/ffitarget.h +92 -0
  123. data/ext/ffi_c/libffi/src/aarch64/internal.h +67 -0
  124. data/ext/ffi_c/libffi/src/aarch64/sysv.S +440 -0
  125. data/ext/ffi_c/libffi/src/aarch64/win64_armasm.S +506 -0
  126. data/ext/ffi_c/libffi/src/alpha/ffi.c +521 -0
  127. data/ext/ffi_c/libffi/src/alpha/ffitarget.h +57 -0
  128. data/ext/ffi_c/libffi/src/alpha/internal.h +23 -0
  129. data/ext/ffi_c/libffi/src/alpha/osf.S +282 -0
  130. data/ext/ffi_c/libffi/src/arc/arcompact.S +135 -0
  131. data/ext/ffi_c/libffi/src/arc/ffi.c +266 -0
  132. data/ext/ffi_c/libffi/src/arc/ffitarget.h +53 -0
  133. data/ext/ffi_c/libffi/src/arm/ffi.c +854 -0
  134. data/ext/ffi_c/libffi/src/arm/ffitarget.h +89 -0
  135. data/ext/ffi_c/libffi/src/arm/internal.h +7 -0
  136. data/ext/ffi_c/libffi/src/arm/sysv.S +385 -0
  137. data/ext/ffi_c/libffi/src/arm/sysv_msvc_arm32.S +311 -0
  138. data/ext/ffi_c/libffi/src/avr32/ffi.c +423 -0
  139. data/ext/ffi_c/libffi/src/avr32/ffitarget.h +55 -0
  140. data/ext/ffi_c/libffi/src/avr32/sysv.S +208 -0
  141. data/ext/ffi_c/libffi/src/bfin/ffi.c +196 -0
  142. data/ext/ffi_c/libffi/src/bfin/ffitarget.h +43 -0
  143. data/ext/ffi_c/libffi/src/bfin/sysv.S +179 -0
  144. data/ext/ffi_c/libffi/src/closures.c +990 -0
  145. data/ext/ffi_c/libffi/src/cris/ffi.c +386 -0
  146. data/ext/ffi_c/libffi/src/cris/ffitarget.h +56 -0
  147. data/ext/ffi_c/libffi/src/cris/sysv.S +215 -0
  148. data/ext/ffi_c/libffi/src/debug.c +64 -0
  149. data/ext/ffi_c/libffi/src/dlmalloc.c +5166 -0
  150. data/ext/ffi_c/libffi/src/frv/eabi.S +128 -0
  151. data/ext/ffi_c/libffi/src/frv/ffi.c +292 -0
  152. data/ext/ffi_c/libffi/src/frv/ffitarget.h +62 -0
  153. data/ext/ffi_c/libffi/src/ia64/ffi.c +604 -0
  154. data/ext/ffi_c/libffi/src/ia64/ffitarget.h +56 -0
  155. data/ext/ffi_c/libffi/src/ia64/ia64_flags.h +40 -0
  156. data/ext/ffi_c/libffi/src/ia64/unix.S +567 -0
  157. data/ext/ffi_c/libffi/src/java_raw_api.c +374 -0
  158. data/ext/ffi_c/libffi/src/m32r/ffi.c +232 -0
  159. data/ext/ffi_c/libffi/src/m32r/ffitarget.h +53 -0
  160. data/ext/ffi_c/libffi/src/m32r/sysv.S +121 -0
  161. data/ext/ffi_c/libffi/src/m68k/ffi.c +362 -0
  162. data/ext/ffi_c/libffi/src/m68k/ffitarget.h +54 -0
  163. data/ext/ffi_c/libffi/src/m68k/sysv.S +357 -0
  164. data/ext/ffi_c/libffi/src/m88k/ffi.c +400 -0
  165. data/ext/ffi_c/libffi/src/m88k/ffitarget.h +49 -0
  166. data/ext/ffi_c/libffi/src/m88k/obsd.S +209 -0
  167. data/ext/ffi_c/libffi/src/metag/ffi.c +330 -0
  168. data/ext/ffi_c/libffi/src/metag/ffitarget.h +53 -0
  169. data/ext/ffi_c/libffi/src/metag/sysv.S +311 -0
  170. data/ext/ffi_c/libffi/src/microblaze/ffi.c +321 -0
  171. data/ext/ffi_c/libffi/src/microblaze/ffitarget.h +53 -0
  172. data/ext/ffi_c/libffi/src/microblaze/sysv.S +302 -0
  173. data/ext/ffi_c/libffi/src/mips/ffi.c +1130 -0
  174. data/ext/ffi_c/libffi/src/mips/ffitarget.h +244 -0
  175. data/ext/ffi_c/libffi/src/mips/n32.S +663 -0
  176. data/ext/ffi_c/libffi/src/mips/o32.S +502 -0
  177. data/ext/ffi_c/libffi/src/moxie/eabi.S +101 -0
  178. data/ext/ffi_c/libffi/src/moxie/ffi.c +285 -0
  179. data/ext/ffi_c/libffi/src/moxie/ffitarget.h +52 -0
  180. data/ext/ffi_c/libffi/src/nios2/ffi.c +304 -0
  181. data/ext/ffi_c/libffi/src/nios2/ffitarget.h +52 -0
  182. data/ext/ffi_c/libffi/src/nios2/sysv.S +136 -0
  183. data/ext/ffi_c/libffi/src/or1k/ffi.c +328 -0
  184. data/ext/ffi_c/libffi/src/or1k/ffitarget.h +58 -0
  185. data/ext/ffi_c/libffi/src/or1k/sysv.S +107 -0
  186. data/ext/ffi_c/libffi/src/pa/ffi.c +719 -0
  187. data/ext/ffi_c/libffi/src/pa/ffitarget.h +85 -0
  188. data/ext/ffi_c/libffi/src/pa/hpux32.S +368 -0
  189. data/ext/ffi_c/libffi/src/pa/linux.S +378 -0
  190. data/ext/ffi_c/libffi/src/powerpc/aix.S +566 -0
  191. data/ext/ffi_c/libffi/src/powerpc/aix_closure.S +694 -0
  192. data/ext/ffi_c/libffi/src/powerpc/asm.h +125 -0
  193. data/ext/ffi_c/libffi/src/powerpc/darwin.S +378 -0
  194. data/ext/ffi_c/libffi/src/powerpc/darwin_closure.S +571 -0
  195. data/ext/ffi_c/libffi/src/powerpc/ffi.c +174 -0
  196. data/ext/ffi_c/libffi/src/powerpc/ffi_darwin.c +1440 -0
  197. data/ext/ffi_c/libffi/src/powerpc/ffi_linux64.c +1007 -0
  198. data/ext/ffi_c/libffi/src/powerpc/ffi_powerpc.h +94 -0
  199. data/ext/ffi_c/libffi/src/powerpc/ffi_sysv.c +923 -0
  200. data/ext/ffi_c/libffi/src/powerpc/ffitarget.h +198 -0
  201. data/ext/ffi_c/libffi/src/powerpc/linux64.S +228 -0
  202. data/ext/ffi_c/libffi/src/powerpc/linux64_closure.S +488 -0
  203. data/ext/ffi_c/libffi/src/powerpc/ppc_closure.S +397 -0
  204. data/ext/ffi_c/libffi/src/powerpc/sysv.S +175 -0
  205. data/ext/ffi_c/libffi/src/prep_cif.c +263 -0
  206. data/ext/ffi_c/libffi/src/raw_api.c +267 -0
  207. data/ext/ffi_c/libffi/src/riscv/ffi.c +481 -0
  208. data/ext/ffi_c/libffi/src/riscv/ffitarget.h +69 -0
  209. data/ext/ffi_c/libffi/src/riscv/sysv.S +293 -0
  210. data/ext/ffi_c/libffi/src/s390/ffi.c +756 -0
  211. data/ext/ffi_c/libffi/src/s390/ffitarget.h +70 -0
  212. data/ext/ffi_c/libffi/src/s390/internal.h +11 -0
  213. data/ext/ffi_c/libffi/src/s390/sysv.S +325 -0
  214. data/ext/ffi_c/libffi/src/sh/ffi.c +717 -0
  215. data/ext/ffi_c/libffi/src/sh/ffitarget.h +54 -0
  216. data/ext/ffi_c/libffi/src/sh/sysv.S +850 -0
  217. data/ext/ffi_c/libffi/src/sh64/ffi.c +469 -0
  218. data/ext/ffi_c/libffi/src/sh64/ffitarget.h +58 -0
  219. data/ext/ffi_c/libffi/src/sh64/sysv.S +539 -0
  220. data/ext/ffi_c/libffi/src/sparc/ffi.c +468 -0
  221. data/ext/ffi_c/libffi/src/sparc/ffi64.c +608 -0
  222. data/ext/ffi_c/libffi/src/sparc/ffitarget.h +81 -0
  223. data/ext/ffi_c/libffi/src/sparc/internal.h +26 -0
  224. data/ext/ffi_c/libffi/src/sparc/v8.S +443 -0
  225. data/ext/ffi_c/libffi/src/sparc/v9.S +440 -0
  226. data/ext/ffi_c/libffi/src/tile/ffi.c +355 -0
  227. data/ext/ffi_c/libffi/src/tile/ffitarget.h +65 -0
  228. data/ext/ffi_c/libffi/src/tile/tile.S +360 -0
  229. data/ext/ffi_c/libffi/src/types.c +108 -0
  230. data/ext/ffi_c/libffi/src/vax/elfbsd.S +195 -0
  231. data/ext/ffi_c/libffi/src/vax/ffi.c +276 -0
  232. data/ext/ffi_c/libffi/src/vax/ffitarget.h +49 -0
  233. data/ext/ffi_c/libffi/src/x86/asmnames.h +30 -0
  234. data/ext/ffi_c/libffi/src/x86/ffi.c +761 -0
  235. data/ext/ffi_c/libffi/src/x86/ffi64.c +886 -0
  236. data/ext/ffi_c/libffi/src/x86/ffitarget.h +147 -0
  237. data/ext/ffi_c/libffi/src/x86/ffiw64.c +311 -0
  238. data/ext/ffi_c/libffi/src/x86/internal.h +29 -0
  239. data/ext/ffi_c/libffi/src/x86/internal64.h +22 -0
  240. data/ext/ffi_c/libffi/src/x86/sysv.S +1129 -0
  241. data/ext/ffi_c/libffi/src/x86/sysv_intel.S +995 -0
  242. data/ext/ffi_c/libffi/src/x86/unix64.S +566 -0
  243. data/ext/ffi_c/libffi/src/x86/win64.S +237 -0
  244. data/ext/ffi_c/libffi/src/x86/win64_intel.S +237 -0
  245. data/ext/ffi_c/libffi/src/xtensa/ffi.c +298 -0
  246. data/ext/ffi_c/libffi/src/xtensa/ffitarget.h +53 -0
  247. data/ext/ffi_c/libffi/src/xtensa/sysv.S +258 -0
  248. data/ext/ffi_c/libffi/stamp-h.in +1 -0
  249. data/ext/ffi_c/libffi/testsuite/Makefile.am +119 -0
  250. data/ext/ffi_c/libffi/testsuite/config/default.exp +1 -0
  251. data/ext/ffi_c/libffi/testsuite/lib/libffi.exp +657 -0
  252. data/ext/ffi_c/libffi/testsuite/lib/target-libpath.exp +283 -0
  253. data/ext/ffi_c/libffi/testsuite/lib/wrapper.exp +45 -0
  254. data/ext/ffi_c/libffi/testsuite/libffi.bhaible/Makefile +28 -0
  255. data/ext/ffi_c/libffi/testsuite/libffi.bhaible/README +78 -0
  256. data/ext/ffi_c/libffi/testsuite/libffi.bhaible/alignof.h +50 -0
  257. data/ext/ffi_c/libffi/testsuite/libffi.bhaible/bhaible.exp +58 -0
  258. data/ext/ffi_c/libffi/testsuite/libffi.bhaible/test-call.c +1745 -0
  259. data/ext/ffi_c/libffi/testsuite/libffi.bhaible/test-callback.c +2885 -0
  260. data/ext/ffi_c/libffi/testsuite/libffi.bhaible/testcases.c +743 -0
  261. data/ext/ffi_c/libffi/testsuite/libffi.call/align_mixed.c +46 -0
  262. data/ext/ffi_c/libffi/testsuite/libffi.call/align_stdcall.c +46 -0
  263. data/ext/ffi_c/libffi/testsuite/libffi.call/call.exp +43 -0
  264. data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn0.c +89 -0
  265. data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn1.c +81 -0
  266. data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn2.c +81 -0
  267. data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn3.c +82 -0
  268. data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn4.c +89 -0
  269. data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn5.c +92 -0
  270. data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn6.c +90 -0
  271. data/ext/ffi_c/libffi/testsuite/libffi.call/closure_loc_fn0.c +95 -0
  272. data/ext/ffi_c/libffi/testsuite/libffi.call/closure_simple.c +55 -0
  273. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_12byte.c +94 -0
  274. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_16byte.c +95 -0
  275. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_18byte.c +96 -0
  276. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_19byte.c +102 -0
  277. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_1_1byte.c +89 -0
  278. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_20byte.c +91 -0
  279. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_20byte1.c +93 -0
  280. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_24byte.c +113 -0
  281. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_2byte.c +90 -0
  282. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_3_1byte.c +95 -0
  283. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_3byte1.c +90 -0
  284. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_3byte2.c +90 -0
  285. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_3float.c +95 -0
  286. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_4_1byte.c +98 -0
  287. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_4byte.c +90 -0
  288. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_5_1_byte.c +109 -0
  289. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_5byte.c +98 -0
  290. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_64byte.c +124 -0
  291. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_6_1_byte.c +113 -0
  292. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_6byte.c +99 -0
  293. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_7_1_byte.c +117 -0
  294. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_7byte.c +97 -0
  295. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_8byte.c +88 -0
  296. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_9byte1.c +90 -0
  297. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_9byte2.c +91 -0
  298. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_double.c +93 -0
  299. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_float.c +91 -0
  300. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_longdouble.c +92 -0
  301. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_longdouble_split.c +132 -0
  302. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_longdouble_split2.c +115 -0
  303. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_pointer.c +95 -0
  304. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_sint16.c +91 -0
  305. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_sint32.c +91 -0
  306. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_sint64.c +92 -0
  307. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_uint16.c +91 -0
  308. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_uint32.c +91 -0
  309. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_uint64.c +93 -0
  310. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_dbls_struct.c +66 -0
  311. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_double.c +43 -0
  312. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_double_va.c +61 -0
  313. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_float.c +42 -0
  314. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_longdouble.c +105 -0
  315. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_longdouble_va.c +61 -0
  316. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_many_mixed_args.c +70 -0
  317. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_many_mixed_float_double.c +55 -0
  318. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_schar.c +74 -0
  319. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_sshort.c +74 -0
  320. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_sshortchar.c +86 -0
  321. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_uchar.c +91 -0
  322. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_ushort.c +74 -0
  323. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_ushortchar.c +86 -0
  324. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_pointer.c +74 -0
  325. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_pointer_stack.c +142 -0
  326. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_schar.c +44 -0
  327. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_sint.c +42 -0
  328. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_sshort.c +42 -0
  329. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_struct_va1.c +114 -0
  330. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_uchar.c +42 -0
  331. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_uchar_va.c +44 -0
  332. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_uint.c +43 -0
  333. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_uint_va.c +45 -0
  334. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_ulong_va.c +45 -0
  335. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_ulonglong.c +47 -0
  336. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_ushort.c +43 -0
  337. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_ushort_va.c +44 -0
  338. data/ext/ffi_c/libffi/testsuite/libffi.call/err_bad_abi.c +36 -0
  339. data/ext/ffi_c/libffi/testsuite/libffi.call/err_bad_typedef.c +26 -0
  340. data/ext/ffi_c/libffi/testsuite/libffi.call/ffitest.h +138 -0
  341. data/ext/ffi_c/libffi/testsuite/libffi.call/float.c +59 -0
  342. data/ext/ffi_c/libffi/testsuite/libffi.call/float1.c +60 -0
  343. data/ext/ffi_c/libffi/testsuite/libffi.call/float2.c +61 -0
  344. data/ext/ffi_c/libffi/testsuite/libffi.call/float3.c +74 -0
  345. data/ext/ffi_c/libffi/testsuite/libffi.call/float4.c +62 -0
  346. data/ext/ffi_c/libffi/testsuite/libffi.call/float_va.c +107 -0
  347. data/ext/ffi_c/libffi/testsuite/libffi.call/huge_struct.c +341 -0
  348. data/ext/ffi_c/libffi/testsuite/libffi.call/many.c +59 -0
  349. data/ext/ffi_c/libffi/testsuite/libffi.call/many2.c +57 -0
  350. data/ext/ffi_c/libffi/testsuite/libffi.call/many_double.c +70 -0
  351. data/ext/ffi_c/libffi/testsuite/libffi.call/many_mixed.c +78 -0
  352. data/ext/ffi_c/libffi/testsuite/libffi.call/negint.c +52 -0
  353. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct.c +152 -0
  354. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct1.c +161 -0
  355. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct10.c +134 -0
  356. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct11.c +121 -0
  357. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct2.c +110 -0
  358. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct3.c +111 -0
  359. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct4.c +111 -0
  360. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct5.c +112 -0
  361. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct6.c +131 -0
  362. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct7.c +111 -0
  363. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct8.c +131 -0
  364. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct9.c +131 -0
  365. data/ext/ffi_c/libffi/testsuite/libffi.call/offsets.c +46 -0
  366. data/ext/ffi_c/libffi/testsuite/libffi.call/pr1172638.c +127 -0
  367. data/ext/ffi_c/libffi/testsuite/libffi.call/problem1.c +90 -0
  368. data/ext/ffi_c/libffi/testsuite/libffi.call/promotion.c +59 -0
  369. data/ext/ffi_c/libffi/testsuite/libffi.call/pyobjc-tc.c +114 -0
  370. data/ext/ffi_c/libffi/testsuite/libffi.call/return_dbl.c +36 -0
  371. data/ext/ffi_c/libffi/testsuite/libffi.call/return_dbl1.c +43 -0
  372. data/ext/ffi_c/libffi/testsuite/libffi.call/return_dbl2.c +42 -0
  373. data/ext/ffi_c/libffi/testsuite/libffi.call/return_fl.c +35 -0
  374. data/ext/ffi_c/libffi/testsuite/libffi.call/return_fl1.c +36 -0
  375. data/ext/ffi_c/libffi/testsuite/libffi.call/return_fl2.c +49 -0
  376. data/ext/ffi_c/libffi/testsuite/libffi.call/return_fl3.c +42 -0
  377. data/ext/ffi_c/libffi/testsuite/libffi.call/return_ldl.c +34 -0
  378. data/ext/ffi_c/libffi/testsuite/libffi.call/return_ll.c +41 -0
  379. data/ext/ffi_c/libffi/testsuite/libffi.call/return_ll1.c +43 -0
  380. data/ext/ffi_c/libffi/testsuite/libffi.call/return_sc.c +36 -0
  381. data/ext/ffi_c/libffi/testsuite/libffi.call/return_sl.c +38 -0
  382. data/ext/ffi_c/libffi/testsuite/libffi.call/return_uc.c +38 -0
  383. data/ext/ffi_c/libffi/testsuite/libffi.call/return_ul.c +38 -0
  384. data/ext/ffi_c/libffi/testsuite/libffi.call/stret_large.c +145 -0
  385. data/ext/ffi_c/libffi/testsuite/libffi.call/stret_large2.c +148 -0
  386. data/ext/ffi_c/libffi/testsuite/libffi.call/stret_medium.c +124 -0
  387. data/ext/ffi_c/libffi/testsuite/libffi.call/stret_medium2.c +125 -0
  388. data/ext/ffi_c/libffi/testsuite/libffi.call/strlen.c +44 -0
  389. data/ext/ffi_c/libffi/testsuite/libffi.call/strlen2.c +49 -0
  390. data/ext/ffi_c/libffi/testsuite/libffi.call/strlen3.c +49 -0
  391. data/ext/ffi_c/libffi/testsuite/libffi.call/strlen4.c +55 -0
  392. data/ext/ffi_c/libffi/testsuite/libffi.call/struct1.c +67 -0
  393. data/ext/ffi_c/libffi/testsuite/libffi.call/struct10.c +57 -0
  394. data/ext/ffi_c/libffi/testsuite/libffi.call/struct2.c +67 -0
  395. data/ext/ffi_c/libffi/testsuite/libffi.call/struct3.c +60 -0
  396. data/ext/ffi_c/libffi/testsuite/libffi.call/struct4.c +64 -0
  397. data/ext/ffi_c/libffi/testsuite/libffi.call/struct5.c +66 -0
  398. data/ext/ffi_c/libffi/testsuite/libffi.call/struct6.c +64 -0
  399. data/ext/ffi_c/libffi/testsuite/libffi.call/struct7.c +74 -0
  400. data/ext/ffi_c/libffi/testsuite/libffi.call/struct8.c +81 -0
  401. data/ext/ffi_c/libffi/testsuite/libffi.call/struct9.c +68 -0
  402. data/ext/ffi_c/libffi/testsuite/libffi.call/testclosure.c +70 -0
  403. data/ext/ffi_c/libffi/testsuite/libffi.call/uninitialized.c +61 -0
  404. data/ext/ffi_c/libffi/testsuite/libffi.call/unwindtest.cc +117 -0
  405. data/ext/ffi_c/libffi/testsuite/libffi.call/unwindtest_ffi_call.cc +54 -0
  406. data/ext/ffi_c/libffi/testsuite/libffi.call/va_1.c +196 -0
  407. data/ext/ffi_c/libffi/testsuite/libffi.call/va_struct1.c +121 -0
  408. data/ext/ffi_c/libffi/testsuite/libffi.call/va_struct2.c +123 -0
  409. data/ext/ffi_c/libffi/testsuite/libffi.call/va_struct3.c +125 -0
  410. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_align_complex.inc +91 -0
  411. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_align_complex_double.c +10 -0
  412. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_align_complex_float.c +10 -0
  413. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_align_complex_longdouble.c +10 -0
  414. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex.inc +42 -0
  415. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_double.c +10 -0
  416. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_float.c +10 -0
  417. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_longdouble.c +10 -0
  418. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_struct.inc +71 -0
  419. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_struct_double.c +10 -0
  420. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_struct_float.c +10 -0
  421. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_struct_longdouble.c +10 -0
  422. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_va.inc +80 -0
  423. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_va_double.c +10 -0
  424. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_va_float.c +16 -0
  425. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_va_longdouble.c +10 -0
  426. data/ext/ffi_c/libffi/testsuite/libffi.complex/complex.exp +36 -0
  427. data/ext/ffi_c/libffi/testsuite/libffi.complex/complex.inc +51 -0
  428. data/ext/ffi_c/libffi/testsuite/libffi.complex/complex_defs_double.inc +7 -0
  429. data/ext/ffi_c/libffi/testsuite/libffi.complex/complex_defs_float.inc +7 -0
  430. data/ext/ffi_c/libffi/testsuite/libffi.complex/complex_defs_longdouble.inc +7 -0
  431. data/ext/ffi_c/libffi/testsuite/libffi.complex/complex_double.c +10 -0
  432. data/ext/ffi_c/libffi/testsuite/libffi.complex/complex_float.c +10 -0
  433. data/ext/ffi_c/libffi/testsuite/libffi.complex/complex_int.c +86 -0
  434. data/ext/ffi_c/libffi/testsuite/libffi.complex/complex_longdouble.c +10 -0
  435. data/ext/ffi_c/libffi/testsuite/libffi.complex/ffitest.h +1 -0
  436. data/ext/ffi_c/libffi/testsuite/libffi.complex/many_complex.inc +78 -0
  437. data/ext/ffi_c/libffi/testsuite/libffi.complex/many_complex_double.c +10 -0
  438. data/ext/ffi_c/libffi/testsuite/libffi.complex/many_complex_float.c +10 -0
  439. data/ext/ffi_c/libffi/testsuite/libffi.complex/many_complex_longdouble.c +10 -0
  440. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex.inc +37 -0
  441. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex1.inc +41 -0
  442. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex1_double.c +10 -0
  443. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex1_float.c +10 -0
  444. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex1_longdouble.c +10 -0
  445. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex2.inc +44 -0
  446. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex2_double.c +10 -0
  447. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex2_float.c +10 -0
  448. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex2_longdouble.c +10 -0
  449. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex_double.c +10 -0
  450. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex_float.c +10 -0
  451. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex_longdouble.c +10 -0
  452. data/ext/ffi_c/libffi/testsuite/libffi.go/aa-direct.c +34 -0
  453. data/ext/ffi_c/libffi/testsuite/libffi.go/closure1.c +28 -0
  454. data/ext/ffi_c/libffi/testsuite/libffi.go/ffitest.h +1 -0
  455. data/ext/ffi_c/libffi/testsuite/libffi.go/go.exp +36 -0
  456. data/ext/ffi_c/libffi/testsuite/libffi.go/static-chain.h +19 -0
  457. data/ext/ffi_c/rbffi.h +55 -0
  458. data/ext/ffi_c/rbffi_endian.h +59 -0
  459. data/ext/ffi_c/win32/stdbool.h +8 -0
  460. data/ext/ffi_c/win32/stdint.h +201 -0
  461. data/ffi.gemspec +43 -0
  462. data/lib/ffi.rb +20 -0
  463. data/lib/ffi/autopointer.rb +203 -0
  464. data/lib/ffi/buffer.rb +4 -0
  465. data/lib/ffi/callback.rb +4 -0
  466. data/lib/ffi/data_converter.rb +67 -0
  467. data/lib/ffi/enum.rb +296 -0
  468. data/lib/ffi/errno.rb +43 -0
  469. data/lib/ffi/ffi.rb +45 -0
  470. data/lib/ffi/io.rb +62 -0
  471. data/lib/ffi/library.rb +588 -0
  472. data/lib/ffi/managedstruct.rb +84 -0
  473. data/lib/ffi/memorypointer.rb +1 -0
  474. data/lib/ffi/platform.rb +175 -0
  475. data/lib/ffi/platform/aarch64-freebsd/types.conf +128 -0
  476. data/lib/ffi/platform/aarch64-freebsd12/types.conf +128 -0
  477. data/lib/ffi/platform/aarch64-linux/types.conf +104 -0
  478. data/lib/ffi/platform/arm-freebsd/types.conf +152 -0
  479. data/lib/ffi/platform/arm-freebsd12/types.conf +152 -0
  480. data/lib/ffi/platform/arm-linux/types.conf +104 -0
  481. data/lib/ffi/platform/i386-cygwin/types.conf +3 -0
  482. data/lib/ffi/platform/i386-darwin/types.conf +100 -0
  483. data/lib/ffi/platform/i386-freebsd/types.conf +152 -0
  484. data/lib/ffi/platform/i386-freebsd12/types.conf +152 -0
  485. data/lib/ffi/platform/i386-gnu/types.conf +107 -0
  486. data/lib/ffi/platform/i386-linux/types.conf +103 -0
  487. data/lib/ffi/platform/i386-netbsd/types.conf +126 -0
  488. data/lib/ffi/platform/i386-openbsd/types.conf +128 -0
  489. data/lib/ffi/platform/i386-solaris/types.conf +122 -0
  490. data/lib/ffi/platform/i386-windows/types.conf +105 -0
  491. data/lib/ffi/platform/ia64-linux/types.conf +104 -0
  492. data/lib/ffi/platform/mips-linux/types.conf +102 -0
  493. data/lib/ffi/platform/mips64-linux/types.conf +104 -0
  494. data/lib/ffi/platform/mips64el-linux/types.conf +104 -0
  495. data/lib/ffi/platform/mipsel-linux/types.conf +102 -0
  496. data/lib/ffi/platform/mipsisa32r6-linux/types.conf +102 -0
  497. data/lib/ffi/platform/mipsisa32r6el-linux/types.conf +102 -0
  498. data/lib/ffi/platform/mipsisa64r6-linux/types.conf +104 -0
  499. data/lib/ffi/platform/mipsisa64r6el-linux/types.conf +104 -0
  500. data/lib/ffi/platform/powerpc-aix/types.conf +180 -0
  501. data/lib/ffi/platform/powerpc-darwin/types.conf +100 -0
  502. data/lib/ffi/platform/powerpc-linux/types.conf +100 -0
  503. data/lib/ffi/platform/powerpc64-linux/types.conf +104 -0
  504. data/lib/ffi/platform/s390-linux/types.conf +102 -0
  505. data/lib/ffi/platform/s390x-linux/types.conf +102 -0
  506. data/lib/ffi/platform/sparc-linux/types.conf +102 -0
  507. data/lib/ffi/platform/sparc-solaris/types.conf +128 -0
  508. data/lib/ffi/platform/sparc64-linux/types.conf +102 -0
  509. data/lib/ffi/platform/sparcv9-solaris/types.conf +128 -0
  510. data/lib/ffi/platform/x86_64-cygwin/types.conf +3 -0
  511. data/lib/ffi/platform/x86_64-darwin/types.conf +126 -0
  512. data/lib/ffi/platform/x86_64-dragonflybsd/types.conf +148 -0
  513. data/lib/ffi/platform/x86_64-freebsd/types.conf +128 -0
  514. data/lib/ffi/platform/x86_64-freebsd12/types.conf +158 -0
  515. data/lib/ffi/platform/x86_64-linux/types.conf +111 -0
  516. data/lib/ffi/platform/x86_64-netbsd/types.conf +128 -0
  517. data/lib/ffi/platform/x86_64-openbsd/types.conf +134 -0
  518. data/lib/ffi/platform/x86_64-solaris/types.conf +122 -0
  519. data/lib/ffi/platform/x86_64-windows/types.conf +120 -0
  520. data/lib/ffi/pointer.rb +160 -0
  521. data/lib/ffi/struct.rb +311 -0
  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 +227 -0
  525. data/lib/ffi/tools/const_generator.rb +230 -0
  526. data/lib/ffi/tools/generator.rb +105 -0
  527. data/lib/ffi/tools/generator_task.rb +32 -0
  528. data/lib/ffi/tools/struct_generator.rb +194 -0
  529. data/lib/ffi/tools/types_generator.rb +135 -0
  530. data/lib/ffi/types.rb +194 -0
  531. data/lib/ffi/union.rb +43 -0
  532. data/lib/ffi/variadic.rb +78 -0
  533. data/lib/ffi/version.rb +3 -0
  534. data/samples/getlogin.rb +8 -0
  535. data/samples/getpid.rb +8 -0
  536. data/samples/gettimeofday.rb +18 -0
  537. data/samples/hello.rb +7 -0
  538. data/samples/inotify.rb +60 -0
  539. data/samples/pty.rb +76 -0
  540. data/samples/qsort.rb +21 -0
  541. data/samples/sample_helper.rb +6 -0
  542. metadata +677 -0
@@ -0,0 +1,353 @@
1
+ #!/bin/sh
2
+
3
+ # ***** BEGIN LICENSE BLOCK *****
4
+ # Version: MPL 1.1/GPL 2.0/LGPL 2.1
5
+ #
6
+ # The contents of this file are subject to the Mozilla Public License Version
7
+ # 1.1 (the "License"); you may not use this file except in compliance with
8
+ # the License. You may obtain a copy of the License at
9
+ # http://www.mozilla.org/MPL/
10
+ #
11
+ # Software distributed under the License is distributed on an "AS IS" basis,
12
+ # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13
+ # for the specific language governing rights and limitations under the
14
+ # License.
15
+ #
16
+ # The Original Code is the MSVC wrappificator.
17
+ #
18
+ # The Initial Developer of the Original Code is
19
+ # Timothy Wall <twalljava@dev.java.net>.
20
+ # Portions created by the Initial Developer are Copyright (C) 2009
21
+ # the Initial Developer. All Rights Reserved.
22
+ #
23
+ # Contributor(s):
24
+ # Daniel Witte <dwitte@mozilla.com>
25
+ #
26
+ # Alternatively, the contents of this file may be used under the terms of
27
+ # either the GNU General Public License Version 2 or later (the "GPL"), or
28
+ # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29
+ # in which case the provisions of the GPL or the LGPL are applicable instead
30
+ # of those above. If you wish to allow use of your version of this file only
31
+ # under the terms of either the GPL or the LGPL, and not to allow others to
32
+ # use your version of this file under the terms of the MPL, indicate your
33
+ # decision by deleting the provisions above and replace them with the notice
34
+ # and other provisions required by the GPL or the LGPL. If you do not delete
35
+ # the provisions above, a recipient may use your version of this file under
36
+ # the terms of any one of the MPL, the GPL or the LGPL.
37
+ #
38
+ # ***** END LICENSE BLOCK *****
39
+
40
+ #
41
+ # GCC-compatible wrapper for cl.exe and ml.exe. Arguments are given in GCC
42
+ # format and translated into something sensible for cl or ml.
43
+ #
44
+
45
+ args_orig=$@
46
+ args="-nologo -W3"
47
+ linkargs=
48
+ static_crt=
49
+ debug_crt=
50
+ cl="cl"
51
+ ml="ml"
52
+ safeseh="-safeseh"
53
+ output=
54
+ libpaths=
55
+ libversion=7
56
+ verbose=
57
+
58
+ while [ $# -gt 0 ]
59
+ do
60
+ case $1
61
+ in
62
+ --verbose)
63
+ verbose=1
64
+ shift 1
65
+ ;;
66
+ --version)
67
+ args="-help"
68
+ shift 1
69
+ ;;
70
+ -fexceptions)
71
+ # Don't enable exceptions for now.
72
+ #args="$args -EHac"
73
+ shift 1
74
+ ;;
75
+ -m32)
76
+ shift 1
77
+ ;;
78
+ -m64)
79
+ ml="ml64" # "$MSVC/x86_amd64/ml64"
80
+ safeseh=
81
+ shift 1
82
+ ;;
83
+ -marm)
84
+ ml='armasm'
85
+ safeseh=
86
+ shift 1
87
+ ;;
88
+ -marm64)
89
+ ml='armasm64'
90
+ safeseh=
91
+ shift 1
92
+ ;;
93
+ -clang-cl)
94
+ cl="clang-cl"
95
+ shift 1
96
+ ;;
97
+ -O0)
98
+ args="$args -Od"
99
+ shift 1
100
+ ;;
101
+ -O*)
102
+ # Runtime error checks (enabled by setting -RTC1 in the -DFFI_DEBUG
103
+ # case below) are not compatible with optimization flags and will
104
+ # cause the build to fail. Therefore, drop the optimization flag if
105
+ # -DFFI_DEBUG is also set.
106
+ case $args_orig in
107
+ *-DFFI_DEBUG*)
108
+ args="$args"
109
+ ;;
110
+ *)
111
+ # The ax_cc_maxopt.m4 macro from the upstream autoconf-archive
112
+ # project doesn't support MSVC and therefore ends up trying to
113
+ # use -O3. Use the equivalent "max optimization" flag for MSVC
114
+ # instead of erroring out.
115
+ case $1 in
116
+ -O3)
117
+ args="$args -O2"
118
+ ;;
119
+ *)
120
+ args="$args $1"
121
+ ;;
122
+ esac
123
+ opt="true"
124
+ ;;
125
+ esac
126
+ shift 1
127
+ ;;
128
+ -g)
129
+ # Enable debug symbol generation.
130
+ args="$args -Zi"
131
+ shift 1
132
+ ;;
133
+ -DFFI_DEBUG)
134
+ # Enable runtime error checks.
135
+ args="$args -RTC1"
136
+ defines="$defines $1"
137
+ shift 1
138
+ ;;
139
+ -DUSE_STATIC_RTL)
140
+ # Link against static CRT.
141
+ static_crt=1
142
+ shift 1
143
+ ;;
144
+ -DUSE_DEBUG_RTL)
145
+ # Link against debug CRT.
146
+ debug_crt=1
147
+ shift 1
148
+ ;;
149
+ -c)
150
+ args="$args -c"
151
+ args="$(echo $args | sed 's%/Fe%/Fo%g')"
152
+ single="-c"
153
+ shift 1
154
+ ;;
155
+ -D*=*)
156
+ name="$(echo $1|sed 's/-D\([^=][^=]*\)=.*/\1/g')"
157
+ value="$(echo $1|sed 's/-D[^=][^=]*=//g')"
158
+ args="$args -D${name}='$value'"
159
+ defines="$defines -D${name}='$value'"
160
+ shift 1
161
+ ;;
162
+ -D*)
163
+ args="$args $1"
164
+ defines="$defines $1"
165
+ shift 1
166
+ ;;
167
+ -I)
168
+ p=$(cygpath -m $2)
169
+ args="$args -I$p"
170
+ includes="$includes -I$p"
171
+ shift 2
172
+ ;;
173
+ -I*)
174
+ p=$(cygpath -m ${1#-I})
175
+ args="$args -I$p"
176
+ includes="$includes -I$p"
177
+ shift 1
178
+ ;;
179
+ -L)
180
+ p=$(cygpath -m $2)
181
+ linkargs="$linkargs -LIBPATH:$p"
182
+ shift 2
183
+ ;;
184
+ -L*)
185
+ p=$(cygpath -m ${1#-L})
186
+ linkargs="$linkargs -LIBPATH:$p"
187
+ shift 1
188
+ ;;
189
+ -link)
190
+ # add next argument verbatim to linker args
191
+ linkargs="$linkargs $2"
192
+ shift 2
193
+ ;;
194
+ -l*)
195
+ case $1
196
+ in
197
+ -lffi)
198
+ linkargs="$linkargs lib${1#-l}-${libversion}.lib"
199
+ ;;
200
+ *)
201
+ # ignore other libraries like -lm, hope they are
202
+ # covered by MSVCRT
203
+ # linkargs="$linkargs ${1#-l}.lib"
204
+ ;;
205
+ esac
206
+ shift 1
207
+ ;;
208
+ -W|-Wextra)
209
+ # TODO map extra warnings
210
+ shift 1
211
+ ;;
212
+ -Wall)
213
+ # -Wall on MSVC is overzealous, and we already build with -W3. Nothing
214
+ # to do here.
215
+ shift 1
216
+ ;;
217
+ -pedantic)
218
+ # libffi tests -pedantic with -Wall, so drop it also.
219
+ shift 1
220
+ ;;
221
+ -warn)
222
+ # ignore -warn all from libtool as well.
223
+ if test "$2" = "all"; then
224
+ shift 2
225
+ else
226
+ args="$args -warn"
227
+ shift 1
228
+ fi
229
+ ;;
230
+ -Werror)
231
+ args="$args -WX"
232
+ shift 1
233
+ ;;
234
+ -W*)
235
+ # TODO map specific warnings
236
+ shift 1
237
+ ;;
238
+ -S)
239
+ args="$args -FAs"
240
+ shift 1
241
+ ;;
242
+ -o)
243
+ outdir="$(dirname $2)"
244
+ base="$(basename $2|sed 's/\.[^.]*//g')"
245
+ if [ -n "$single" ]; then
246
+ output="-Fo$2"
247
+ else
248
+ output="-Fe$2"
249
+ fi
250
+ armasm_output="-o $2"
251
+ if [ -n "$assembly" ]; then
252
+ args="$args $output"
253
+ else
254
+ args="$args $output -Fd$outdir/$base -Fp$outdir/$base -Fa$outdir/$base"
255
+ fi
256
+ shift 2
257
+ ;;
258
+ *.S)
259
+ src=$1
260
+ assembly="true"
261
+ shift 1
262
+ ;;
263
+ *.c)
264
+ args="$args $1"
265
+ shift 1
266
+ ;;
267
+ *)
268
+ # Assume it's an MSVC argument, and pass it through.
269
+ args="$args $1"
270
+ shift 1
271
+ ;;
272
+ esac
273
+ done
274
+
275
+ if [ -n "$linkargs" ]; then
276
+
277
+ # If -Zi is specified, certain optimizations are implicitly disabled
278
+ # by MSVC. Add back those optimizations if this is an optimized build.
279
+ # NOTE: These arguments must come after all others.
280
+ if [ -n "$opt" ]; then
281
+ linkargs="$linkargs -OPT:REF -OPT:ICF -INCREMENTAL:NO"
282
+ fi
283
+
284
+ args="$args -link $linkargs"
285
+ fi
286
+
287
+ if [ -n "$static_crt" ]; then
288
+ md=-MT
289
+ else
290
+ md=-MD
291
+ fi
292
+
293
+ if [ -n "$debug_crt" ]; then
294
+ md="${md}d"
295
+ fi
296
+
297
+ if [ -n "$assembly" ]; then
298
+ if [ -z "$outdir" ]; then
299
+ outdir="."
300
+ fi
301
+ ppsrc="$outdir/$(basename $src|sed 's/.S$/.asm/g')"
302
+
303
+ if [ $ml = "armasm" ]; then
304
+ defines="$defines -D_M_ARM"
305
+ fi
306
+
307
+ if [ $ml = "armasm64" ]; then
308
+ defines="$defines -D_M_ARM64"
309
+ fi
310
+
311
+ if test -n "$verbose"; then
312
+ echo "$cl -nologo -EP $includes $defines $src > $ppsrc"
313
+ fi
314
+
315
+ "$cl" -nologo -EP $includes $defines $src > $ppsrc || exit $?
316
+ output="$(echo $output | sed 's%/F[dpa][^ ]*%%g')"
317
+ if [ $ml = "armasm" ]; then
318
+ args="-nologo -g -oldit $armasm_output $ppsrc -errorReport:prompt"
319
+ elif [ $ml = "armasm64" ]; then
320
+ args="-nologo -g $armasm_output $ppsrc -errorReport:prompt"
321
+ else
322
+ args="-nologo $safeseh $single $output $ppsrc"
323
+ fi
324
+
325
+ if test -n "$verbose"; then
326
+ echo "$ml $args"
327
+ fi
328
+
329
+ eval "\"$ml\" $args"
330
+ result=$?
331
+
332
+ # required to fix ml64 broken output?
333
+ #mv *.obj $outdir
334
+ else
335
+ args="$md $args"
336
+
337
+ if test -n "$verbose"; then
338
+ echo "$cl $args"
339
+ fi
340
+ # Return an error code of 1 if an invalid command line parameter is passed
341
+ # instead of just ignoring it. Any output that is not a warning or an
342
+ # error is filtered so this command behaves more like gcc. cl.exe prints
343
+ # the name of the compiled file otherwise, which breaks the dejagnu checks
344
+ # for excess warnings and errors.
345
+ eval "(\"$cl\" $args 2>&1 1>&3 | \
346
+ awk '{print \$0} /D9002/ {error=1} END{exit error}' >&2) 3>&1 | \
347
+ awk '/warning|error/'"
348
+ result=$?
349
+ fi
350
+
351
+ exit $result
352
+
353
+ # vim: noai:ts=4:sw=4
@@ -0,0 +1,1009 @@
1
+ /* Copyright (c) 2009, 2010, 2011, 2012 ARM Ltd.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ ``Software''), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
21
+
22
+ #if defined(__aarch64__) || defined(__arm64__)|| defined (_M_ARM64)
23
+ #include <stdio.h>
24
+ #include <stdlib.h>
25
+ #include <stdint.h>
26
+ #include <fficonfig.h>
27
+ #include <ffi.h>
28
+ #include <ffi_common.h>
29
+ #include "internal.h"
30
+ #ifdef _M_ARM64
31
+ #include <windows.h> /* FlushInstructionCache */
32
+ #endif
33
+
34
+ /* Force FFI_TYPE_LONGDOUBLE to be different than FFI_TYPE_DOUBLE;
35
+ all further uses in this file will refer to the 128-bit type. */
36
+ #if FFI_TYPE_DOUBLE != FFI_TYPE_LONGDOUBLE
37
+ # if FFI_TYPE_LONGDOUBLE != 4
38
+ # error FFI_TYPE_LONGDOUBLE out of date
39
+ # endif
40
+ #else
41
+ # undef FFI_TYPE_LONGDOUBLE
42
+ # define FFI_TYPE_LONGDOUBLE 4
43
+ #endif
44
+
45
+ union _d
46
+ {
47
+ UINT64 d;
48
+ UINT32 s[2];
49
+ };
50
+
51
+ struct _v
52
+ {
53
+ union _d d[2] __attribute__((aligned(16)));
54
+ };
55
+
56
+ struct call_context
57
+ {
58
+ struct _v v[N_V_ARG_REG];
59
+ UINT64 x[N_X_ARG_REG];
60
+ };
61
+
62
+ #if FFI_EXEC_TRAMPOLINE_TABLE
63
+
64
+ #ifdef __MACH__
65
+ #include <mach/vm_param.h>
66
+ #endif
67
+
68
+ #else
69
+
70
+ #if defined (__clang__) && defined (__APPLE__)
71
+ extern void sys_icache_invalidate (void *start, size_t len);
72
+ #endif
73
+
74
+ static inline void
75
+ ffi_clear_cache (void *start, void *end)
76
+ {
77
+ #if defined (__clang__) && defined (__APPLE__)
78
+ sys_icache_invalidate (start, (char *)end - (char *)start);
79
+ #elif defined (__GNUC__)
80
+ __builtin___clear_cache (start, end);
81
+ #elif defined (_M_ARM64)
82
+ FlushInstructionCache(GetCurrentProcess(), start, (char*)end - (char*)start);
83
+ #else
84
+ #error "Missing builtin to flush instruction cache"
85
+ #endif
86
+ }
87
+
88
+ #endif
89
+
90
+ /* A subroutine of is_vfp_type. Given a structure type, return the type code
91
+ of the first non-structure element. Recurse for structure elements.
92
+ Return -1 if the structure is in fact empty, i.e. no nested elements. */
93
+
94
+ static int
95
+ is_hfa0 (const ffi_type *ty)
96
+ {
97
+ ffi_type **elements = ty->elements;
98
+ int i, ret = -1;
99
+
100
+ if (elements != NULL)
101
+ for (i = 0; elements[i]; ++i)
102
+ {
103
+ ret = elements[i]->type;
104
+ if (ret == FFI_TYPE_STRUCT || ret == FFI_TYPE_COMPLEX)
105
+ {
106
+ ret = is_hfa0 (elements[i]);
107
+ if (ret < 0)
108
+ continue;
109
+ }
110
+ break;
111
+ }
112
+
113
+ return ret;
114
+ }
115
+
116
+ /* A subroutine of is_vfp_type. Given a structure type, return true if all
117
+ of the non-structure elements are the same as CANDIDATE. */
118
+
119
+ static int
120
+ is_hfa1 (const ffi_type *ty, int candidate)
121
+ {
122
+ ffi_type **elements = ty->elements;
123
+ int i;
124
+
125
+ if (elements != NULL)
126
+ for (i = 0; elements[i]; ++i)
127
+ {
128
+ int t = elements[i]->type;
129
+ if (t == FFI_TYPE_STRUCT || t == FFI_TYPE_COMPLEX)
130
+ {
131
+ if (!is_hfa1 (elements[i], candidate))
132
+ return 0;
133
+ }
134
+ else if (t != candidate)
135
+ return 0;
136
+ }
137
+
138
+ return 1;
139
+ }
140
+
141
+ /* Determine if TY may be allocated to the FP registers. This is both an
142
+ fp scalar type as well as an homogenous floating point aggregate (HFA).
143
+ That is, a structure consisting of 1 to 4 members of all the same type,
144
+ where that type is an fp scalar.
145
+
146
+ Returns non-zero iff TY is an HFA. The result is the AARCH64_RET_*
147
+ constant for the type. */
148
+
149
+ static int
150
+ is_vfp_type (const ffi_type *ty)
151
+ {
152
+ ffi_type **elements;
153
+ int candidate, i;
154
+ size_t size, ele_count;
155
+
156
+ /* Quickest tests first. */
157
+ candidate = ty->type;
158
+ switch (candidate)
159
+ {
160
+ default:
161
+ return 0;
162
+ case FFI_TYPE_FLOAT:
163
+ case FFI_TYPE_DOUBLE:
164
+ case FFI_TYPE_LONGDOUBLE:
165
+ ele_count = 1;
166
+ goto done;
167
+ case FFI_TYPE_COMPLEX:
168
+ candidate = ty->elements[0]->type;
169
+ switch (candidate)
170
+ {
171
+ case FFI_TYPE_FLOAT:
172
+ case FFI_TYPE_DOUBLE:
173
+ case FFI_TYPE_LONGDOUBLE:
174
+ ele_count = 2;
175
+ goto done;
176
+ }
177
+ return 0;
178
+ case FFI_TYPE_STRUCT:
179
+ break;
180
+ }
181
+
182
+ /* No HFA types are smaller than 4 bytes, or larger than 64 bytes. */
183
+ size = ty->size;
184
+ if (size < 4 || size > 64)
185
+ return 0;
186
+
187
+ /* Find the type of the first non-structure member. */
188
+ elements = ty->elements;
189
+ candidate = elements[0]->type;
190
+ if (candidate == FFI_TYPE_STRUCT || candidate == FFI_TYPE_COMPLEX)
191
+ {
192
+ for (i = 0; ; ++i)
193
+ {
194
+ candidate = is_hfa0 (elements[i]);
195
+ if (candidate >= 0)
196
+ break;
197
+ }
198
+ }
199
+
200
+ /* If the first member is not a floating point type, it's not an HFA.
201
+ Also quickly re-check the size of the structure. */
202
+ switch (candidate)
203
+ {
204
+ case FFI_TYPE_FLOAT:
205
+ ele_count = size / sizeof(float);
206
+ if (size != ele_count * sizeof(float))
207
+ return 0;
208
+ break;
209
+ case FFI_TYPE_DOUBLE:
210
+ ele_count = size / sizeof(double);
211
+ if (size != ele_count * sizeof(double))
212
+ return 0;
213
+ break;
214
+ case FFI_TYPE_LONGDOUBLE:
215
+ ele_count = size / sizeof(long double);
216
+ if (size != ele_count * sizeof(long double))
217
+ return 0;
218
+ break;
219
+ default:
220
+ return 0;
221
+ }
222
+ if (ele_count > 4)
223
+ return 0;
224
+
225
+ /* Finally, make sure that all scalar elements are the same type. */
226
+ for (i = 0; elements[i]; ++i)
227
+ {
228
+ int t = elements[i]->type;
229
+ if (t == FFI_TYPE_STRUCT || t == FFI_TYPE_COMPLEX)
230
+ {
231
+ if (!is_hfa1 (elements[i], candidate))
232
+ return 0;
233
+ }
234
+ else if (t != candidate)
235
+ return 0;
236
+ }
237
+
238
+ /* All tests succeeded. Encode the result. */
239
+ done:
240
+ return candidate * 4 + (4 - (int)ele_count);
241
+ }
242
+
243
+ /* Representation of the procedure call argument marshalling
244
+ state.
245
+
246
+ The terse state variable names match the names used in the AARCH64
247
+ PCS. */
248
+
249
+ struct arg_state
250
+ {
251
+ unsigned ngrn; /* Next general-purpose register number. */
252
+ unsigned nsrn; /* Next vector register number. */
253
+ size_t nsaa; /* Next stack offset. */
254
+
255
+ #if defined (__APPLE__)
256
+ unsigned allocating_variadic;
257
+ #endif
258
+ };
259
+
260
+ /* Initialize a procedure call argument marshalling state. */
261
+ static void
262
+ arg_init (struct arg_state *state)
263
+ {
264
+ state->ngrn = 0;
265
+ state->nsrn = 0;
266
+ state->nsaa = 0;
267
+ #if defined (__APPLE__)
268
+ state->allocating_variadic = 0;
269
+ #endif
270
+ }
271
+
272
+ /* Allocate an aligned slot on the stack and return a pointer to it. */
273
+ static void *
274
+ allocate_to_stack (struct arg_state *state, void *stack,
275
+ size_t alignment, size_t size)
276
+ {
277
+ size_t nsaa = state->nsaa;
278
+
279
+ /* Round up the NSAA to the larger of 8 or the natural
280
+ alignment of the argument's type. */
281
+ #if defined (__APPLE__)
282
+ if (state->allocating_variadic && alignment < 8)
283
+ alignment = 8;
284
+ #else
285
+ if (alignment < 8)
286
+ alignment = 8;
287
+ #endif
288
+
289
+ nsaa = FFI_ALIGN (nsaa, alignment);
290
+ state->nsaa = nsaa + size;
291
+
292
+ return (char *)stack + nsaa;
293
+ }
294
+
295
+ static ffi_arg
296
+ extend_integer_type (void *source, int type)
297
+ {
298
+ switch (type)
299
+ {
300
+ case FFI_TYPE_UINT8:
301
+ return *(UINT8 *) source;
302
+ case FFI_TYPE_SINT8:
303
+ return *(SINT8 *) source;
304
+ case FFI_TYPE_UINT16:
305
+ return *(UINT16 *) source;
306
+ case FFI_TYPE_SINT16:
307
+ return *(SINT16 *) source;
308
+ case FFI_TYPE_UINT32:
309
+ return *(UINT32 *) source;
310
+ case FFI_TYPE_INT:
311
+ case FFI_TYPE_SINT32:
312
+ return *(SINT32 *) source;
313
+ case FFI_TYPE_UINT64:
314
+ case FFI_TYPE_SINT64:
315
+ return *(UINT64 *) source;
316
+ break;
317
+ case FFI_TYPE_POINTER:
318
+ return *(uintptr_t *) source;
319
+ default:
320
+ abort();
321
+ }
322
+ }
323
+
324
+ #if defined(_MSC_VER)
325
+ void extend_hfa_type (void *dest, void *src, int h);
326
+ #else
327
+ static void
328
+ extend_hfa_type (void *dest, void *src, int h)
329
+ {
330
+ ssize_t f = h - AARCH64_RET_S4;
331
+ void *x0;
332
+
333
+ asm volatile (
334
+ "adr %0, 0f\n"
335
+ " add %0, %0, %1\n"
336
+ " br %0\n"
337
+ "0: ldp s16, s17, [%3]\n" /* S4 */
338
+ " ldp s18, s19, [%3, #8]\n"
339
+ " b 4f\n"
340
+ " ldp s16, s17, [%3]\n" /* S3 */
341
+ " ldr s18, [%3, #8]\n"
342
+ " b 3f\n"
343
+ " ldp s16, s17, [%3]\n" /* S2 */
344
+ " b 2f\n"
345
+ " nop\n"
346
+ " ldr s16, [%3]\n" /* S1 */
347
+ " b 1f\n"
348
+ " nop\n"
349
+ " ldp d16, d17, [%3]\n" /* D4 */
350
+ " ldp d18, d19, [%3, #16]\n"
351
+ " b 4f\n"
352
+ " ldp d16, d17, [%3]\n" /* D3 */
353
+ " ldr d18, [%3, #16]\n"
354
+ " b 3f\n"
355
+ " ldp d16, d17, [%3]\n" /* D2 */
356
+ " b 2f\n"
357
+ " nop\n"
358
+ " ldr d16, [%3]\n" /* D1 */
359
+ " b 1f\n"
360
+ " nop\n"
361
+ " ldp q16, q17, [%3]\n" /* Q4 */
362
+ " ldp q18, q19, [%3, #32]\n"
363
+ " b 4f\n"
364
+ " ldp q16, q17, [%3]\n" /* Q3 */
365
+ " ldr q18, [%3, #32]\n"
366
+ " b 3f\n"
367
+ " ldp q16, q17, [%3]\n" /* Q2 */
368
+ " b 2f\n"
369
+ " nop\n"
370
+ " ldr q16, [%3]\n" /* Q1 */
371
+ " b 1f\n"
372
+ "4: str q19, [%2, #48]\n"
373
+ "3: str q18, [%2, #32]\n"
374
+ "2: str q17, [%2, #16]\n"
375
+ "1: str q16, [%2]"
376
+ : "=&r"(x0)
377
+ : "r"(f * 12), "r"(dest), "r"(src)
378
+ : "memory", "v16", "v17", "v18", "v19");
379
+ }
380
+ #endif
381
+
382
+ #if defined(_MSC_VER)
383
+ void* compress_hfa_type (void *dest, void *src, int h);
384
+ #else
385
+ static void *
386
+ compress_hfa_type (void *dest, void *reg, int h)
387
+ {
388
+ switch (h)
389
+ {
390
+ case AARCH64_RET_S1:
391
+ if (dest == reg)
392
+ {
393
+ #ifdef __AARCH64EB__
394
+ dest += 12;
395
+ #endif
396
+ }
397
+ else
398
+ *(float *)dest = *(float *)reg;
399
+ break;
400
+ case AARCH64_RET_S2:
401
+ asm ("ldp q16, q17, [%1]\n\t"
402
+ "st2 { v16.s, v17.s }[0], [%0]"
403
+ : : "r"(dest), "r"(reg) : "memory", "v16", "v17");
404
+ break;
405
+ case AARCH64_RET_S3:
406
+ asm ("ldp q16, q17, [%1]\n\t"
407
+ "ldr q18, [%1, #32]\n\t"
408
+ "st3 { v16.s, v17.s, v18.s }[0], [%0]"
409
+ : : "r"(dest), "r"(reg) : "memory", "v16", "v17", "v18");
410
+ break;
411
+ case AARCH64_RET_S4:
412
+ asm ("ldp q16, q17, [%1]\n\t"
413
+ "ldp q18, q19, [%1, #32]\n\t"
414
+ "st4 { v16.s, v17.s, v18.s, v19.s }[0], [%0]"
415
+ : : "r"(dest), "r"(reg) : "memory", "v16", "v17", "v18", "v19");
416
+ break;
417
+
418
+ case AARCH64_RET_D1:
419
+ if (dest == reg)
420
+ {
421
+ #ifdef __AARCH64EB__
422
+ dest += 8;
423
+ #endif
424
+ }
425
+ else
426
+ *(double *)dest = *(double *)reg;
427
+ break;
428
+ case AARCH64_RET_D2:
429
+ asm ("ldp q16, q17, [%1]\n\t"
430
+ "st2 { v16.d, v17.d }[0], [%0]"
431
+ : : "r"(dest), "r"(reg) : "memory", "v16", "v17");
432
+ break;
433
+ case AARCH64_RET_D3:
434
+ asm ("ldp q16, q17, [%1]\n\t"
435
+ "ldr q18, [%1, #32]\n\t"
436
+ "st3 { v16.d, v17.d, v18.d }[0], [%0]"
437
+ : : "r"(dest), "r"(reg) : "memory", "v16", "v17", "v18");
438
+ break;
439
+ case AARCH64_RET_D4:
440
+ asm ("ldp q16, q17, [%1]\n\t"
441
+ "ldp q18, q19, [%1, #32]\n\t"
442
+ "st4 { v16.d, v17.d, v18.d, v19.d }[0], [%0]"
443
+ : : "r"(dest), "r"(reg) : "memory", "v16", "v17", "v18", "v19");
444
+ break;
445
+
446
+ default:
447
+ if (dest != reg)
448
+ return memcpy (dest, reg, 16 * (4 - (h & 3)));
449
+ break;
450
+ }
451
+ return dest;
452
+ }
453
+ #endif
454
+
455
+ /* Either allocate an appropriate register for the argument type, or if
456
+ none are available, allocate a stack slot and return a pointer
457
+ to the allocated space. */
458
+
459
+ static void *
460
+ allocate_int_to_reg_or_stack (struct call_context *context,
461
+ struct arg_state *state,
462
+ void *stack, size_t size)
463
+ {
464
+ if (state->ngrn < N_X_ARG_REG)
465
+ return &context->x[state->ngrn++];
466
+
467
+ state->ngrn = N_X_ARG_REG;
468
+ return allocate_to_stack (state, stack, size, size);
469
+ }
470
+
471
+ ffi_status FFI_HIDDEN
472
+ ffi_prep_cif_machdep (ffi_cif *cif)
473
+ {
474
+ ffi_type *rtype = cif->rtype;
475
+ size_t bytes = cif->bytes;
476
+ int flags, i, n;
477
+
478
+ switch (rtype->type)
479
+ {
480
+ case FFI_TYPE_VOID:
481
+ flags = AARCH64_RET_VOID;
482
+ break;
483
+ case FFI_TYPE_UINT8:
484
+ flags = AARCH64_RET_UINT8;
485
+ break;
486
+ case FFI_TYPE_UINT16:
487
+ flags = AARCH64_RET_UINT16;
488
+ break;
489
+ case FFI_TYPE_UINT32:
490
+ flags = AARCH64_RET_UINT32;
491
+ break;
492
+ case FFI_TYPE_SINT8:
493
+ flags = AARCH64_RET_SINT8;
494
+ break;
495
+ case FFI_TYPE_SINT16:
496
+ flags = AARCH64_RET_SINT16;
497
+ break;
498
+ case FFI_TYPE_INT:
499
+ case FFI_TYPE_SINT32:
500
+ flags = AARCH64_RET_SINT32;
501
+ break;
502
+ case FFI_TYPE_SINT64:
503
+ case FFI_TYPE_UINT64:
504
+ flags = AARCH64_RET_INT64;
505
+ break;
506
+ case FFI_TYPE_POINTER:
507
+ flags = (sizeof(void *) == 4 ? AARCH64_RET_UINT32 : AARCH64_RET_INT64);
508
+ break;
509
+
510
+ case FFI_TYPE_FLOAT:
511
+ case FFI_TYPE_DOUBLE:
512
+ case FFI_TYPE_LONGDOUBLE:
513
+ case FFI_TYPE_STRUCT:
514
+ case FFI_TYPE_COMPLEX:
515
+ flags = is_vfp_type (rtype);
516
+ if (flags == 0)
517
+ {
518
+ size_t s = rtype->size;
519
+ if (s > 16)
520
+ {
521
+ flags = AARCH64_RET_VOID | AARCH64_RET_IN_MEM;
522
+ bytes += 8;
523
+ }
524
+ else if (s == 16)
525
+ flags = AARCH64_RET_INT128;
526
+ else if (s == 8)
527
+ flags = AARCH64_RET_INT64;
528
+ else
529
+ flags = AARCH64_RET_INT128 | AARCH64_RET_NEED_COPY;
530
+ }
531
+ break;
532
+
533
+ default:
534
+ abort();
535
+ }
536
+
537
+ for (i = 0, n = cif->nargs; i < n; i++)
538
+ if (is_vfp_type (cif->arg_types[i]))
539
+ {
540
+ flags |= AARCH64_FLAG_ARG_V;
541
+ break;
542
+ }
543
+
544
+ /* Round the stack up to a multiple of the stack alignment requirement. */
545
+ cif->bytes = (unsigned) FFI_ALIGN(bytes, 16);
546
+ cif->flags = flags;
547
+ #if defined (__APPLE__)
548
+ cif->aarch64_nfixedargs = 0;
549
+ #endif
550
+
551
+ return FFI_OK;
552
+ }
553
+
554
+ #if defined (__APPLE__)
555
+ /* Perform Apple-specific cif processing for variadic calls */
556
+ ffi_status FFI_HIDDEN
557
+ ffi_prep_cif_machdep_var(ffi_cif *cif, unsigned int nfixedargs,
558
+ unsigned int ntotalargs)
559
+ {
560
+ ffi_status status = ffi_prep_cif_machdep (cif);
561
+ cif->aarch64_nfixedargs = nfixedargs;
562
+ return status;
563
+ }
564
+ #endif /* __APPLE__ */
565
+
566
+ extern void ffi_call_SYSV (struct call_context *context, void *frame,
567
+ void (*fn)(void), void *rvalue, int flags,
568
+ void *closure) FFI_HIDDEN;
569
+
570
+ /* Call a function with the provided arguments and capture the return
571
+ value. */
572
+ static void
573
+ ffi_call_int (ffi_cif *cif, void (*fn)(void), void *orig_rvalue,
574
+ void **avalue, void *closure)
575
+ {
576
+ struct call_context *context;
577
+ void *stack, *frame, *rvalue;
578
+ struct arg_state state;
579
+ size_t stack_bytes, rtype_size, rsize;
580
+ int i, nargs, flags;
581
+ ffi_type *rtype;
582
+
583
+ flags = cif->flags;
584
+ rtype = cif->rtype;
585
+ rtype_size = rtype->size;
586
+ stack_bytes = cif->bytes;
587
+
588
+ /* If the target function returns a structure via hidden pointer,
589
+ then we cannot allow a null rvalue. Otherwise, mash a null
590
+ rvalue to void return type. */
591
+ rsize = 0;
592
+ if (flags & AARCH64_RET_IN_MEM)
593
+ {
594
+ if (orig_rvalue == NULL)
595
+ rsize = rtype_size;
596
+ }
597
+ else if (orig_rvalue == NULL)
598
+ flags &= AARCH64_FLAG_ARG_V;
599
+ else if (flags & AARCH64_RET_NEED_COPY)
600
+ rsize = 16;
601
+
602
+ /* Allocate consectutive stack for everything we'll need. */
603
+ context = alloca (sizeof(struct call_context) + stack_bytes + 32 + rsize);
604
+ stack = context + 1;
605
+ frame = (void*)((uintptr_t)stack + (uintptr_t)stack_bytes);
606
+ rvalue = (rsize ? (void*)((uintptr_t)frame + 32) : orig_rvalue);
607
+
608
+ arg_init (&state);
609
+ for (i = 0, nargs = cif->nargs; i < nargs; i++)
610
+ {
611
+ ffi_type *ty = cif->arg_types[i];
612
+ size_t s = ty->size;
613
+ void *a = avalue[i];
614
+ int h, t;
615
+
616
+ t = ty->type;
617
+ switch (t)
618
+ {
619
+ case FFI_TYPE_VOID:
620
+ FFI_ASSERT (0);
621
+ break;
622
+
623
+ /* If the argument is a basic type the argument is allocated to an
624
+ appropriate register, or if none are available, to the stack. */
625
+ case FFI_TYPE_INT:
626
+ case FFI_TYPE_UINT8:
627
+ case FFI_TYPE_SINT8:
628
+ case FFI_TYPE_UINT16:
629
+ case FFI_TYPE_SINT16:
630
+ case FFI_TYPE_UINT32:
631
+ case FFI_TYPE_SINT32:
632
+ case FFI_TYPE_UINT64:
633
+ case FFI_TYPE_SINT64:
634
+ case FFI_TYPE_POINTER:
635
+ do_pointer:
636
+ {
637
+ ffi_arg ext = extend_integer_type (a, t);
638
+ if (state.ngrn < N_X_ARG_REG)
639
+ context->x[state.ngrn++] = ext;
640
+ else
641
+ {
642
+ void *d = allocate_to_stack (&state, stack, ty->alignment, s);
643
+ state.ngrn = N_X_ARG_REG;
644
+ /* Note that the default abi extends each argument
645
+ to a full 64-bit slot, while the iOS abi allocates
646
+ only enough space. */
647
+ #ifdef __APPLE__
648
+ memcpy(d, a, s);
649
+ #else
650
+ *(ffi_arg *)d = ext;
651
+ #endif
652
+ }
653
+ }
654
+ break;
655
+
656
+ case FFI_TYPE_FLOAT:
657
+ case FFI_TYPE_DOUBLE:
658
+ case FFI_TYPE_LONGDOUBLE:
659
+ case FFI_TYPE_STRUCT:
660
+ case FFI_TYPE_COMPLEX:
661
+ {
662
+ void *dest;
663
+
664
+ h = is_vfp_type (ty);
665
+ if (h)
666
+ {
667
+ int elems = 4 - (h & 3);
668
+ #ifdef _M_ARM64 /* for handling armasm calling convention */
669
+ if (cif->is_variadic)
670
+ {
671
+ if (state.ngrn + elems <= N_X_ARG_REG)
672
+ {
673
+ dest = &context->x[state.ngrn];
674
+ state.ngrn += elems;
675
+ extend_hfa_type(dest, a, h);
676
+ break;
677
+ }
678
+ state.nsrn = N_X_ARG_REG;
679
+ dest = allocate_to_stack(&state, stack, ty->alignment, s);
680
+ }
681
+ else
682
+ {
683
+ #endif /* for handling armasm calling convention */
684
+ if (state.nsrn + elems <= N_V_ARG_REG)
685
+ {
686
+ dest = &context->v[state.nsrn];
687
+ state.nsrn += elems;
688
+ extend_hfa_type (dest, a, h);
689
+ break;
690
+ }
691
+ state.nsrn = N_V_ARG_REG;
692
+ dest = allocate_to_stack (&state, stack, ty->alignment, s);
693
+ #ifdef _M_ARM64 /* for handling armasm calling convention */
694
+ }
695
+ #endif /* for handling armasm calling convention */
696
+ }
697
+ else if (s > 16)
698
+ {
699
+ /* If the argument is a composite type that is larger than 16
700
+ bytes, then the argument has been copied to memory, and
701
+ the argument is replaced by a pointer to the copy. */
702
+ a = &avalue[i];
703
+ t = FFI_TYPE_POINTER;
704
+ s = sizeof (void *);
705
+ goto do_pointer;
706
+ }
707
+ else
708
+ {
709
+ size_t n = (s + 7) / 8;
710
+ if (state.ngrn + n <= N_X_ARG_REG)
711
+ {
712
+ /* If the argument is a composite type and the size in
713
+ double-words is not more than the number of available
714
+ X registers, then the argument is copied into
715
+ consecutive X registers. */
716
+ dest = &context->x[state.ngrn];
717
+ state.ngrn += (unsigned int)n;
718
+ }
719
+ else
720
+ {
721
+ /* Otherwise, there are insufficient X registers. Further
722
+ X register allocations are prevented, the NSAA is
723
+ adjusted and the argument is copied to memory at the
724
+ adjusted NSAA. */
725
+ state.ngrn = N_X_ARG_REG;
726
+ dest = allocate_to_stack (&state, stack, ty->alignment, s);
727
+ }
728
+ }
729
+ memcpy (dest, a, s);
730
+ }
731
+ break;
732
+
733
+ default:
734
+ abort();
735
+ }
736
+
737
+ #if defined (__APPLE__)
738
+ if (i + 1 == cif->aarch64_nfixedargs)
739
+ {
740
+ state.ngrn = N_X_ARG_REG;
741
+ state.nsrn = N_V_ARG_REG;
742
+ state.allocating_variadic = 1;
743
+ }
744
+ #endif
745
+ }
746
+
747
+ ffi_call_SYSV (context, frame, fn, rvalue, flags, closure);
748
+
749
+ if (flags & AARCH64_RET_NEED_COPY)
750
+ memcpy (orig_rvalue, rvalue, rtype_size);
751
+ }
752
+
753
+ void
754
+ ffi_call (ffi_cif *cif, void (*fn) (void), void *rvalue, void **avalue)
755
+ {
756
+ ffi_call_int (cif, fn, rvalue, avalue, NULL);
757
+ }
758
+
759
+ #ifdef FFI_GO_CLOSURES
760
+ void
761
+ ffi_call_go (ffi_cif *cif, void (*fn) (void), void *rvalue,
762
+ void **avalue, void *closure)
763
+ {
764
+ ffi_call_int (cif, fn, rvalue, avalue, closure);
765
+ }
766
+ #endif /* FFI_GO_CLOSURES */
767
+
768
+ /* Build a trampoline. */
769
+
770
+ extern void ffi_closure_SYSV (void) FFI_HIDDEN;
771
+ extern void ffi_closure_SYSV_V (void) FFI_HIDDEN;
772
+
773
+ ffi_status
774
+ ffi_prep_closure_loc (ffi_closure *closure,
775
+ ffi_cif* cif,
776
+ void (*fun)(ffi_cif*,void*,void**,void*),
777
+ void *user_data,
778
+ void *codeloc)
779
+ {
780
+ if (cif->abi != FFI_SYSV)
781
+ return FFI_BAD_ABI;
782
+
783
+ void (*start)(void);
784
+
785
+ if (cif->flags & AARCH64_FLAG_ARG_V)
786
+ start = ffi_closure_SYSV_V;
787
+ else
788
+ start = ffi_closure_SYSV;
789
+
790
+ #if FFI_EXEC_TRAMPOLINE_TABLE
791
+ #ifdef __MACH__
792
+ void **config = (void **)((uint8_t *)codeloc - PAGE_MAX_SIZE);
793
+ config[0] = closure;
794
+ config[1] = start;
795
+ #endif
796
+ #else
797
+ static const unsigned char trampoline[16] = {
798
+ 0x90, 0x00, 0x00, 0x58, /* ldr x16, tramp+16 */
799
+ 0xf1, 0xff, 0xff, 0x10, /* adr x17, tramp+0 */
800
+ 0x00, 0x02, 0x1f, 0xd6 /* br x16 */
801
+ };
802
+ char *tramp = closure->tramp;
803
+
804
+ memcpy (tramp, trampoline, sizeof(trampoline));
805
+
806
+ *(UINT64 *)(tramp + 16) = (uintptr_t)start;
807
+
808
+ ffi_clear_cache(tramp, tramp + FFI_TRAMPOLINE_SIZE);
809
+
810
+ /* Also flush the cache for code mapping. */
811
+ #ifdef _M_ARM64
812
+ // Not using dlmalloc.c for Windows ARM64 builds
813
+ // so calling ffi_data_to_code_pointer() isn't necessary
814
+ unsigned char *tramp_code = tramp;
815
+ #else
816
+ unsigned char *tramp_code = ffi_data_to_code_pointer (tramp);
817
+ #endif
818
+ ffi_clear_cache (tramp_code, tramp_code + FFI_TRAMPOLINE_SIZE);
819
+ #endif
820
+
821
+ closure->cif = cif;
822
+ closure->fun = fun;
823
+ closure->user_data = user_data;
824
+
825
+ return FFI_OK;
826
+ }
827
+
828
+ #ifdef FFI_GO_CLOSURES
829
+ extern void ffi_go_closure_SYSV (void) FFI_HIDDEN;
830
+ extern void ffi_go_closure_SYSV_V (void) FFI_HIDDEN;
831
+
832
+ ffi_status
833
+ ffi_prep_go_closure (ffi_go_closure *closure, ffi_cif* cif,
834
+ void (*fun)(ffi_cif*,void*,void**,void*))
835
+ {
836
+ void (*start)(void);
837
+
838
+ if (cif->abi != FFI_SYSV)
839
+ return FFI_BAD_ABI;
840
+
841
+ if (cif->flags & AARCH64_FLAG_ARG_V)
842
+ start = ffi_go_closure_SYSV_V;
843
+ else
844
+ start = ffi_go_closure_SYSV;
845
+
846
+ closure->tramp = start;
847
+ closure->cif = cif;
848
+ closure->fun = fun;
849
+
850
+ return FFI_OK;
851
+ }
852
+ #endif /* FFI_GO_CLOSURES */
853
+
854
+ /* Primary handler to setup and invoke a function within a closure.
855
+
856
+ A closure when invoked enters via the assembler wrapper
857
+ ffi_closure_SYSV(). The wrapper allocates a call context on the
858
+ stack, saves the interesting registers (from the perspective of
859
+ the calling convention) into the context then passes control to
860
+ ffi_closure_SYSV_inner() passing the saved context and a pointer to
861
+ the stack at the point ffi_closure_SYSV() was invoked.
862
+
863
+ On the return path the assembler wrapper will reload call context
864
+ registers.
865
+
866
+ ffi_closure_SYSV_inner() marshalls the call context into ffi value
867
+ descriptors, invokes the wrapped function, then marshalls the return
868
+ value back into the call context. */
869
+
870
+ int FFI_HIDDEN
871
+ ffi_closure_SYSV_inner (ffi_cif *cif,
872
+ void (*fun)(ffi_cif*,void*,void**,void*),
873
+ void *user_data,
874
+ struct call_context *context,
875
+ void *stack, void *rvalue, void *struct_rvalue)
876
+ {
877
+ void **avalue = (void**) alloca (cif->nargs * sizeof (void*));
878
+ int i, h, nargs, flags;
879
+ struct arg_state state;
880
+
881
+ arg_init (&state);
882
+
883
+ for (i = 0, nargs = cif->nargs; i < nargs; i++)
884
+ {
885
+ ffi_type *ty = cif->arg_types[i];
886
+ int t = ty->type;
887
+ size_t n, s = ty->size;
888
+
889
+ switch (t)
890
+ {
891
+ case FFI_TYPE_VOID:
892
+ FFI_ASSERT (0);
893
+ break;
894
+
895
+ case FFI_TYPE_INT:
896
+ case FFI_TYPE_UINT8:
897
+ case FFI_TYPE_SINT8:
898
+ case FFI_TYPE_UINT16:
899
+ case FFI_TYPE_SINT16:
900
+ case FFI_TYPE_UINT32:
901
+ case FFI_TYPE_SINT32:
902
+ case FFI_TYPE_UINT64:
903
+ case FFI_TYPE_SINT64:
904
+ case FFI_TYPE_POINTER:
905
+ avalue[i] = allocate_int_to_reg_or_stack (context, &state, stack, s);
906
+ break;
907
+
908
+ case FFI_TYPE_FLOAT:
909
+ case FFI_TYPE_DOUBLE:
910
+ case FFI_TYPE_LONGDOUBLE:
911
+ case FFI_TYPE_STRUCT:
912
+ case FFI_TYPE_COMPLEX:
913
+ h = is_vfp_type (ty);
914
+ if (h)
915
+ {
916
+ n = 4 - (h & 3);
917
+ #ifdef _M_ARM64 /* for handling armasm calling convention */
918
+ if (cif->is_variadic)
919
+ {
920
+ if (state.ngrn + n <= N_X_ARG_REG)
921
+ {
922
+ void *reg = &context->x[state.ngrn];
923
+ state.ngrn += (unsigned int)n;
924
+
925
+ /* Eeek! We need a pointer to the structure, however the
926
+ homogeneous float elements are being passed in individual
927
+ registers, therefore for float and double the structure
928
+ is not represented as a contiguous sequence of bytes in
929
+ our saved register context. We don't need the original
930
+ contents of the register storage, so we reformat the
931
+ structure into the same memory. */
932
+ avalue[i] = compress_hfa_type(reg, reg, h);
933
+ }
934
+ else
935
+ {
936
+ state.ngrn = N_X_ARG_REG;
937
+ state.nsrn = N_V_ARG_REG;
938
+ avalue[i] = allocate_to_stack(&state, stack,
939
+ ty->alignment, s);
940
+ }
941
+ }
942
+ else
943
+ {
944
+ #endif /* for handling armasm calling convention */
945
+ if (state.nsrn + n <= N_V_ARG_REG)
946
+ {
947
+ void *reg = &context->v[state.nsrn];
948
+ state.nsrn += (unsigned int)n;
949
+ avalue[i] = compress_hfa_type(reg, reg, h);
950
+ }
951
+ else
952
+ {
953
+ state.nsrn = N_V_ARG_REG;
954
+ avalue[i] = allocate_to_stack(&state, stack,
955
+ ty->alignment, s);
956
+ }
957
+ #ifdef _M_ARM64 /* for handling armasm calling convention */
958
+ }
959
+ #endif /* for handling armasm calling convention */
960
+ }
961
+ else if (s > 16)
962
+ {
963
+ /* Replace Composite type of size greater than 16 with a
964
+ pointer. */
965
+ avalue[i] = *(void **)
966
+ allocate_int_to_reg_or_stack (context, &state, stack,
967
+ sizeof (void *));
968
+ }
969
+ else
970
+ {
971
+ n = (s + 7) / 8;
972
+ if (state.ngrn + n <= N_X_ARG_REG)
973
+ {
974
+ avalue[i] = &context->x[state.ngrn];
975
+ state.ngrn += (unsigned int)n;
976
+ }
977
+ else
978
+ {
979
+ state.ngrn = N_X_ARG_REG;
980
+ avalue[i] = allocate_to_stack(&state, stack,
981
+ ty->alignment, s);
982
+ }
983
+ }
984
+ break;
985
+
986
+ default:
987
+ abort();
988
+ }
989
+
990
+ #if defined (__APPLE__)
991
+ if (i + 1 == cif->aarch64_nfixedargs)
992
+ {
993
+ state.ngrn = N_X_ARG_REG;
994
+ state.nsrn = N_V_ARG_REG;
995
+ state.allocating_variadic = 1;
996
+ }
997
+ #endif
998
+ }
999
+
1000
+ flags = cif->flags;
1001
+ if (flags & AARCH64_RET_IN_MEM)
1002
+ rvalue = struct_rvalue;
1003
+
1004
+ fun (cif, rvalue, avalue, user_data);
1005
+
1006
+ return flags;
1007
+ }
1008
+
1009
+ #endif /* (__aarch64__) || defined(__arm64__)|| defined (_M_ARM64)*/