ffi 1.9.18 → 1.9.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (468) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +22 -0
  3. data/.gitmodules +3 -0
  4. data/.travis.yml +52 -0
  5. data/.yardopts +5 -0
  6. data/Gemfile +15 -0
  7. data/{spec/ffi/LICENSE.SPECS → LICENSE.SPECS} +1 -1
  8. data/README.md +3 -4
  9. data/Rakefile +41 -5
  10. data/appveyor.yml +22 -0
  11. data/ext/ffi_c/AbstractMemory.c +6 -1
  12. data/ext/ffi_c/Call.c +1 -22
  13. data/ext/ffi_c/Call.h +0 -9
  14. data/ext/ffi_c/Closure.c +54 -0
  15. data/ext/ffi_c/{ClosurePool.h → Closure.h} +13 -23
  16. data/ext/ffi_c/Function.c +16 -25
  17. data/ext/ffi_c/Function.h +1 -2
  18. data/ext/ffi_c/FunctionInfo.c +0 -4
  19. data/ext/ffi_c/MethodHandle.c +33 -268
  20. data/ext/ffi_c/Platform.c +10 -2
  21. data/ext/ffi_c/extconf.rb +10 -5
  22. data/ext/ffi_c/ffi.c +2 -2
  23. data/ext/ffi_c/libffi/.appveyor.yml +48 -0
  24. data/ext/ffi_c/libffi/.gitignore +36 -0
  25. data/ext/ffi_c/libffi/.travis/install.sh +14 -0
  26. data/ext/ffi_c/libffi/.travis.yml +30 -0
  27. data/ext/ffi_c/libffi/ChangeLog.libffi +2 -2
  28. data/ext/ffi_c/libffi/{ChangeLog → ChangeLog.libffi-3.1} +1402 -2
  29. data/ext/ffi_c/libffi/ChangeLog.v1 +1 -1
  30. data/ext/ffi_c/libffi/LICENSE +1 -1
  31. data/ext/ffi_c/libffi/Makefile.am +169 -158
  32. data/ext/ffi_c/libffi/Makefile.in +927 -938
  33. data/ext/ffi_c/libffi/README +164 -52
  34. data/ext/ffi_c/libffi/acinclude.m4 +387 -0
  35. data/ext/ffi_c/libffi/autogen.sh +2 -0
  36. data/ext/ffi_c/libffi/config.guess +336 -371
  37. data/ext/ffi_c/libffi/config.sub +246 -115
  38. data/ext/ffi_c/libffi/configure +6976 -2189
  39. data/ext/ffi_c/libffi/configure.ac +148 -256
  40. data/ext/ffi_c/libffi/configure.host +277 -4
  41. data/ext/ffi_c/libffi/doc/Makefile.am +3 -0
  42. data/ext/ffi_c/libffi/doc/Makefile.in +811 -0
  43. data/ext/ffi_c/libffi/doc/libffi.texi +430 -45
  44. data/ext/ffi_c/libffi/doc/version.texi +4 -4
  45. data/ext/ffi_c/libffi/fficonfig.h.in +24 -13
  46. data/ext/ffi_c/libffi/generate-darwin-source-and-headers.py +203 -0
  47. data/ext/ffi_c/libffi/include/Makefile.am +3 -3
  48. data/ext/ffi_c/libffi/include/Makefile.in +188 -71
  49. data/ext/ffi_c/libffi/include/ffi.h.in +112 -50
  50. data/ext/ffi_c/libffi/include/ffi_cfi.h +55 -0
  51. data/ext/ffi_c/libffi/include/ffi_common.h +32 -11
  52. data/ext/ffi_c/libffi/install-sh +190 -202
  53. data/ext/ffi_c/libffi/libffi.map.in +80 -0
  54. data/ext/ffi_c/libffi/libffi.pc.in +3 -2
  55. data/ext/ffi_c/libffi/libffi.xcodeproj/project.pbxproj +1043 -0
  56. data/ext/ffi_c/libffi/libtool-ldflags +106 -0
  57. data/ext/ffi_c/libffi/libtool-version +1 -1
  58. data/ext/ffi_c/libffi/ltmain.sh +3553 -2033
  59. data/ext/ffi_c/libffi/m4/asmcfi.m4 +13 -0
  60. data/ext/ffi_c/libffi/m4/ax_append_flag.m4 +69 -0
  61. data/ext/ffi_c/libffi/m4/ax_cc_maxopt.m4 +13 -8
  62. data/ext/ffi_c/libffi/m4/ax_cflags_warn_all.m4 +31 -104
  63. data/ext/ffi_c/libffi/m4/{ax_check_compiler_flags.m4 → ax_check_compile_flag.m4} +30 -34
  64. data/ext/ffi_c/libffi/m4/ax_compiler_vendor.m4 +32 -11
  65. data/ext/ffi_c/libffi/m4/ax_enable_builddir.m4 +6 -5
  66. data/ext/ffi_c/libffi/m4/ax_gcc_archflag.m4 +31 -21
  67. data/ext/ffi_c/libffi/man/Makefile.am +2 -2
  68. data/ext/ffi_c/libffi/man/Makefile.in +141 -49
  69. data/ext/ffi_c/libffi/man/ffi.3 +10 -0
  70. data/ext/ffi_c/libffi/man/ffi_prep_cif.3 +6 -4
  71. data/ext/ffi_c/libffi/man/ffi_prep_cif_var.3 +73 -0
  72. data/ext/ffi_c/libffi/missing +150 -311
  73. data/ext/ffi_c/libffi/msvcc.sh +72 -9
  74. data/ext/ffi_c/libffi/src/aarch64/ffi.c +964 -0
  75. data/ext/ffi_c/libffi/src/aarch64/ffitarget.h +81 -0
  76. data/ext/ffi_c/libffi/src/aarch64/internal.h +67 -0
  77. data/ext/ffi_c/libffi/src/aarch64/sysv.S +438 -0
  78. data/ext/ffi_c/libffi/src/alpha/ffi.c +335 -98
  79. data/ext/ffi_c/libffi/src/alpha/ffitarget.h +10 -1
  80. data/ext/ffi_c/libffi/src/alpha/internal.h +23 -0
  81. data/ext/ffi_c/libffi/src/alpha/osf.S +161 -266
  82. data/ext/ffi_c/libffi/src/arc/arcompact.S +135 -0
  83. data/ext/ffi_c/libffi/src/arc/ffi.c +266 -0
  84. data/ext/ffi_c/libffi/src/arc/ffitarget.h +53 -0
  85. data/ext/ffi_c/libffi/src/arm/ffi.c +608 -517
  86. data/ext/ffi_c/libffi/src/arm/ffitarget.h +24 -7
  87. data/ext/ffi_c/libffi/src/arm/internal.h +7 -0
  88. data/ext/ffi_c/libffi/src/arm/sysv.S +303 -417
  89. data/ext/ffi_c/libffi/src/avr32/ffitarget.h +6 -1
  90. data/ext/ffi_c/libffi/src/bfin/ffi.c +196 -0
  91. data/ext/ffi_c/libffi/src/bfin/ffitarget.h +43 -0
  92. data/ext/ffi_c/libffi/src/bfin/sysv.S +179 -0
  93. data/ext/ffi_c/libffi/src/closures.c +366 -45
  94. data/ext/ffi_c/libffi/src/cris/ffi.c +10 -7
  95. data/ext/ffi_c/libffi/src/cris/ffitarget.h +6 -1
  96. data/ext/ffi_c/libffi/src/debug.c +6 -1
  97. data/ext/ffi_c/libffi/src/dlmalloc.c +16 -11
  98. data/ext/ffi_c/libffi/src/frv/ffi.c +1 -1
  99. data/ext/ffi_c/libffi/src/frv/ffitarget.h +6 -1
  100. data/ext/ffi_c/libffi/src/ia64/ffi.c +11 -7
  101. data/ext/ffi_c/libffi/src/ia64/ffitarget.h +6 -1
  102. data/ext/ffi_c/libffi/src/ia64/unix.S +2 -0
  103. data/ext/ffi_c/libffi/src/java_raw_api.c +23 -5
  104. data/ext/ffi_c/libffi/src/m32r/ffi.c +1 -1
  105. data/ext/ffi_c/libffi/src/m32r/ffitarget.h +6 -1
  106. data/ext/ffi_c/libffi/src/m68k/ffi.c +87 -13
  107. data/ext/ffi_c/libffi/src/m68k/ffitarget.h +6 -1
  108. data/ext/ffi_c/libffi/src/m68k/sysv.S +119 -32
  109. data/ext/ffi_c/libffi/src/m88k/ffi.c +400 -0
  110. data/ext/ffi_c/libffi/src/m88k/ffitarget.h +49 -0
  111. data/ext/ffi_c/libffi/src/m88k/obsd.S +209 -0
  112. data/ext/ffi_c/libffi/src/metag/ffi.c +330 -0
  113. data/ext/ffi_c/libffi/{fficonfig.hw → src/metag/ffitarget.h} +22 -26
  114. data/ext/ffi_c/libffi/src/metag/sysv.S +311 -0
  115. data/ext/ffi_c/libffi/src/microblaze/ffi.c +321 -0
  116. data/ext/ffi_c/libffi/src/microblaze/ffitarget.h +53 -0
  117. data/ext/ffi_c/libffi/src/microblaze/sysv.S +302 -0
  118. data/ext/ffi_c/libffi/src/mips/ffi.c +103 -28
  119. data/ext/ffi_c/libffi/src/mips/ffitarget.h +10 -3
  120. data/ext/ffi_c/libffi/src/mips/n32.S +128 -56
  121. data/ext/ffi_c/libffi/src/mips/o32.S +148 -27
  122. data/ext/ffi_c/libffi/src/moxie/eabi.S +55 -82
  123. data/ext/ffi_c/libffi/src/moxie/ffi.c +40 -44
  124. data/ext/ffi_c/libffi/src/moxie/ffitarget.h +52 -0
  125. data/ext/ffi_c/libffi/src/nios2/ffi.c +304 -0
  126. data/ext/ffi_c/libffi/src/nios2/ffitarget.h +52 -0
  127. data/ext/ffi_c/libffi/src/nios2/sysv.S +136 -0
  128. data/ext/ffi_c/libffi/src/or1k/ffi.c +328 -0
  129. data/ext/ffi_c/libffi/src/or1k/ffitarget.h +58 -0
  130. data/ext/ffi_c/libffi/src/or1k/sysv.S +107 -0
  131. data/ext/ffi_c/libffi/src/pa/ffitarget.h +8 -1
  132. data/ext/ffi_c/libffi/src/powerpc/aix.S +245 -7
  133. data/ext/ffi_c/libffi/src/powerpc/aix_closure.S +253 -4
  134. data/ext/ffi_c/libffi/src/powerpc/asm.h +2 -2
  135. data/ext/ffi_c/libffi/src/powerpc/darwin.S +2 -7
  136. data/ext/ffi_c/libffi/src/powerpc/darwin_closure.S +22 -26
  137. data/ext/ffi_c/libffi/src/powerpc/ffi.c +103 -1378
  138. data/ext/ffi_c/libffi/src/powerpc/ffi_darwin.c +111 -30
  139. data/ext/ffi_c/libffi/src/powerpc/ffi_linux64.c +945 -0
  140. data/ext/ffi_c/libffi/src/powerpc/ffi_powerpc.h +94 -0
  141. data/ext/ffi_c/libffi/src/powerpc/ffi_sysv.c +923 -0
  142. data/ext/ffi_c/libffi/src/powerpc/ffitarget.h +103 -44
  143. data/ext/ffi_c/libffi/src/powerpc/linux64.S +100 -59
  144. data/ext/ffi_c/libffi/src/powerpc/linux64_closure.S +360 -108
  145. data/ext/ffi_c/libffi/src/powerpc/ppc_closure.S +138 -68
  146. data/ext/ffi_c/libffi/src/powerpc/sysv.S +68 -112
  147. data/ext/ffi_c/libffi/src/prep_cif.c +108 -24
  148. data/ext/ffi_c/libffi/src/raw_api.c +18 -5
  149. data/ext/ffi_c/libffi/src/s390/ffi.c +294 -318
  150. data/ext/ffi_c/libffi/src/s390/ffitarget.h +9 -1
  151. data/ext/ffi_c/libffi/src/s390/internal.h +11 -0
  152. data/ext/ffi_c/libffi/src/s390/sysv.S +257 -366
  153. data/ext/ffi_c/libffi/src/sh/ffi.c +4 -3
  154. data/ext/ffi_c/libffi/src/sh/ffitarget.h +6 -1
  155. data/ext/ffi_c/libffi/src/sh64/ffi.c +3 -2
  156. data/ext/ffi_c/libffi/src/sh64/ffitarget.h +6 -1
  157. data/ext/ffi_c/libffi/src/sparc/ffi.c +326 -527
  158. data/ext/ffi_c/libffi/src/sparc/ffi64.c +608 -0
  159. data/ext/ffi_c/libffi/src/sparc/ffitarget.h +20 -7
  160. data/ext/ffi_c/libffi/src/sparc/internal.h +26 -0
  161. data/ext/ffi_c/libffi/src/sparc/v8.S +364 -234
  162. data/ext/ffi_c/libffi/src/sparc/v9.S +340 -207
  163. data/ext/ffi_c/libffi/src/tile/ffi.c +355 -0
  164. data/ext/ffi_c/libffi/src/tile/ffitarget.h +65 -0
  165. data/ext/ffi_c/libffi/src/tile/tile.S +360 -0
  166. data/ext/ffi_c/libffi/src/types.c +43 -14
  167. data/ext/ffi_c/libffi/src/vax/elfbsd.S +195 -0
  168. data/ext/ffi_c/libffi/src/vax/ffi.c +276 -0
  169. data/ext/ffi_c/libffi/src/vax/ffitarget.h +49 -0
  170. data/ext/ffi_c/libffi/src/x86/asmnames.h +30 -0
  171. data/ext/ffi_c/libffi/src/x86/ffi.c +591 -500
  172. data/ext/ffi_c/libffi/src/x86/ffi64.c +359 -116
  173. data/ext/ffi_c/libffi/src/x86/ffitarget.h +55 -35
  174. data/ext/ffi_c/libffi/src/x86/ffiw64.c +287 -0
  175. data/ext/ffi_c/libffi/src/x86/internal.h +29 -0
  176. data/ext/ffi_c/libffi/src/x86/internal64.h +22 -0
  177. data/ext/ffi_c/libffi/src/x86/sysv.S +975 -400
  178. data/ext/ffi_c/libffi/src/x86/unix64.S +398 -299
  179. data/ext/ffi_c/libffi/src/x86/win64.S +222 -458
  180. data/ext/ffi_c/libffi/src/x86/win64_intel.S +237 -0
  181. data/ext/ffi_c/libffi/src/xtensa/ffi.c +298 -0
  182. data/ext/ffi_c/libffi/src/xtensa/ffitarget.h +53 -0
  183. data/ext/ffi_c/libffi/src/xtensa/sysv.S +253 -0
  184. data/ext/ffi_c/libffi/stamp-h.in +1 -0
  185. data/ext/ffi_c/libffi/testsuite/Makefile.am +79 -73
  186. data/ext/ffi_c/libffi/testsuite/Makefile.in +219 -111
  187. data/ext/ffi_c/libffi/testsuite/lib/libffi.exp +121 -25
  188. data/ext/ffi_c/libffi/testsuite/lib/target-libpath.exp +21 -1
  189. data/ext/ffi_c/libffi/testsuite/libffi.call/align_mixed.c +46 -0
  190. data/ext/ffi_c/libffi/testsuite/libffi.call/call.exp +4 -6
  191. data/ext/ffi_c/libffi/testsuite/libffi.call/{closure_stdcall.c → closure_simple.c} +7 -16
  192. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_12byte.c +4 -4
  193. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_16byte.c +4 -4
  194. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_18byte.c +4 -4
  195. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_19byte.c +4 -4
  196. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_1_1byte.c +4 -4
  197. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_20byte.c +4 -4
  198. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_20byte1.c +4 -4
  199. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_24byte.c +5 -5
  200. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_2byte.c +4 -4
  201. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_3_1byte.c +4 -4
  202. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_3byte1.c +4 -4
  203. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_3byte2.c +4 -4
  204. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_3float.c +95 -0
  205. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_4_1byte.c +4 -4
  206. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_4byte.c +4 -4
  207. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_5_1_byte.c +4 -4
  208. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_5byte.c +4 -4
  209. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_64byte.c +5 -5
  210. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_6_1_byte.c +4 -4
  211. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_6byte.c +4 -4
  212. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_7_1_byte.c +4 -4
  213. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_7byte.c +4 -4
  214. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_8byte.c +4 -4
  215. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_9byte1.c +4 -4
  216. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_9byte2.c +4 -4
  217. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_double.c +4 -4
  218. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_float.c +4 -4
  219. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_longdouble.c +4 -4
  220. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_longdouble_split.c +4 -6
  221. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_longdouble_split2.c +4 -6
  222. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_pointer.c +4 -4
  223. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_sint16.c +4 -4
  224. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_sint32.c +4 -4
  225. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_sint64.c +4 -4
  226. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_uint16.c +4 -4
  227. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_uint32.c +4 -4
  228. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_uint64.c +4 -4
  229. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_dbls_struct.c +4 -4
  230. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_double_va.c +10 -9
  231. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_longdouble.c +3 -3
  232. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_longdouble_va.c +10 -9
  233. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_many_mixed_args.c +70 -0
  234. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_many_mixed_float_double.c +55 -0
  235. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_pointer.c +1 -1
  236. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_pointer_stack.c +11 -9
  237. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_struct_va1.c +114 -0
  238. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_uchar_va.c +44 -0
  239. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_uint_va.c +45 -0
  240. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_ulong_va.c +45 -0
  241. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_ulonglong.c +5 -5
  242. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_ushort_va.c +44 -0
  243. data/ext/ffi_c/libffi/testsuite/libffi.call/err_bad_typedef.c +2 -2
  244. data/ext/ffi_c/libffi/testsuite/libffi.call/ffitest.h +23 -40
  245. data/ext/ffi_c/libffi/testsuite/libffi.call/float1.c +3 -1
  246. data/ext/ffi_c/libffi/testsuite/libffi.call/float2.c +6 -4
  247. data/ext/ffi_c/libffi/testsuite/libffi.call/float3.c +4 -2
  248. data/ext/ffi_c/libffi/testsuite/libffi.call/float_va.c +107 -0
  249. data/ext/ffi_c/libffi/testsuite/libffi.call/huge_struct.c +18 -19
  250. data/ext/ffi_c/libffi/testsuite/libffi.call/many.c +6 -16
  251. data/ext/ffi_c/libffi/testsuite/libffi.call/many2.c +57 -0
  252. data/ext/ffi_c/libffi/testsuite/libffi.call/many_double.c +70 -0
  253. data/ext/ffi_c/libffi/testsuite/libffi.call/many_mixed.c +78 -0
  254. data/ext/ffi_c/libffi/testsuite/libffi.call/negint.c +0 -1
  255. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct.c +6 -6
  256. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct1.c +8 -8
  257. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct10.c +6 -6
  258. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct11.c +121 -0
  259. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct2.c +5 -5
  260. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct3.c +5 -5
  261. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct4.c +5 -5
  262. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct5.c +5 -5
  263. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct6.c +6 -6
  264. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct7.c +5 -5
  265. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct8.c +6 -6
  266. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct9.c +6 -6
  267. data/ext/ffi_c/libffi/testsuite/libffi.call/offsets.c +46 -0
  268. data/ext/ffi_c/libffi/testsuite/libffi.call/pr1172638.c +127 -0
  269. data/ext/ffi_c/libffi/testsuite/libffi.call/return_dbl.c +1 -0
  270. data/ext/ffi_c/libffi/testsuite/libffi.call/return_ldl.c +1 -1
  271. data/ext/ffi_c/libffi/testsuite/libffi.call/return_sc.c +1 -1
  272. data/ext/ffi_c/libffi/testsuite/libffi.call/return_uc.c +1 -1
  273. data/ext/ffi_c/libffi/testsuite/libffi.call/stret_large.c +7 -7
  274. data/ext/ffi_c/libffi/testsuite/libffi.call/stret_large2.c +7 -7
  275. data/ext/ffi_c/libffi/testsuite/libffi.call/stret_medium.c +5 -5
  276. data/ext/ffi_c/libffi/testsuite/libffi.call/stret_medium2.c +5 -5
  277. data/ext/ffi_c/libffi/testsuite/libffi.call/strlen.c +2 -2
  278. data/ext/ffi_c/libffi/testsuite/libffi.call/strlen2.c +49 -0
  279. data/ext/ffi_c/libffi/testsuite/libffi.call/strlen3.c +49 -0
  280. data/ext/ffi_c/libffi/testsuite/libffi.call/strlen4.c +55 -0
  281. data/ext/ffi_c/libffi/testsuite/libffi.call/struct1.c +9 -7
  282. data/ext/ffi_c/libffi/testsuite/libffi.call/struct2.c +7 -7
  283. data/ext/ffi_c/libffi/testsuite/libffi.call/struct3.c +7 -6
  284. data/ext/ffi_c/libffi/testsuite/libffi.call/struct4.c +9 -8
  285. data/ext/ffi_c/libffi/testsuite/libffi.call/struct5.c +9 -8
  286. data/ext/ffi_c/libffi/testsuite/libffi.call/struct6.c +9 -9
  287. data/ext/ffi_c/libffi/testsuite/libffi.call/struct7.c +9 -9
  288. data/ext/ffi_c/libffi/testsuite/libffi.call/struct8.c +9 -8
  289. data/ext/ffi_c/libffi/testsuite/libffi.call/struct9.c +9 -8
  290. data/ext/ffi_c/libffi/testsuite/libffi.call/testclosure.c +2 -2
  291. data/ext/ffi_c/libffi/testsuite/libffi.call/uninitialized.c +61 -0
  292. data/ext/ffi_c/libffi/testsuite/{libffi.special → libffi.call}/unwindtest.cc +3 -10
  293. data/ext/ffi_c/libffi/testsuite/{libffi.special → libffi.call}/unwindtest_ffi_call.cc +2 -1
  294. data/ext/ffi_c/libffi/testsuite/libffi.call/va_1.c +196 -0
  295. data/ext/ffi_c/libffi/testsuite/libffi.call/va_struct1.c +121 -0
  296. data/ext/ffi_c/libffi/testsuite/libffi.call/va_struct2.c +123 -0
  297. data/ext/ffi_c/libffi/testsuite/libffi.call/va_struct3.c +125 -0
  298. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_align_complex.inc +91 -0
  299. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_align_complex_double.c +10 -0
  300. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_align_complex_float.c +10 -0
  301. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_align_complex_longdouble.c +10 -0
  302. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex.inc +42 -0
  303. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_double.c +10 -0
  304. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_float.c +10 -0
  305. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_longdouble.c +10 -0
  306. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_struct.inc +71 -0
  307. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_struct_double.c +10 -0
  308. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_struct_float.c +10 -0
  309. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_struct_longdouble.c +10 -0
  310. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_va.inc +80 -0
  311. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_va_double.c +10 -0
  312. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_va_float.c +16 -0
  313. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_va_longdouble.c +10 -0
  314. data/ext/ffi_c/libffi/testsuite/{libffi.special/special.exp → libffi.complex/complex.exp} +9 -8
  315. data/ext/ffi_c/libffi/testsuite/libffi.complex/complex.inc +51 -0
  316. data/ext/ffi_c/libffi/testsuite/libffi.complex/complex_defs_double.inc +7 -0
  317. data/ext/ffi_c/libffi/testsuite/libffi.complex/complex_defs_float.inc +7 -0
  318. data/ext/ffi_c/libffi/testsuite/libffi.complex/complex_defs_longdouble.inc +7 -0
  319. data/ext/ffi_c/libffi/testsuite/libffi.complex/complex_double.c +10 -0
  320. data/ext/ffi_c/libffi/testsuite/libffi.complex/complex_float.c +10 -0
  321. data/ext/ffi_c/libffi/testsuite/libffi.complex/complex_int.c +86 -0
  322. data/ext/ffi_c/libffi/testsuite/libffi.complex/complex_longdouble.c +10 -0
  323. data/ext/ffi_c/libffi/testsuite/libffi.complex/ffitest.h +1 -0
  324. data/ext/ffi_c/libffi/testsuite/libffi.complex/many_complex.inc +78 -0
  325. data/ext/ffi_c/libffi/testsuite/libffi.complex/many_complex_double.c +10 -0
  326. data/ext/ffi_c/libffi/testsuite/libffi.complex/many_complex_float.c +10 -0
  327. data/ext/ffi_c/libffi/testsuite/libffi.complex/many_complex_longdouble.c +10 -0
  328. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex.inc +37 -0
  329. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex1.inc +41 -0
  330. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex1_double.c +10 -0
  331. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex1_float.c +10 -0
  332. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex1_longdouble.c +10 -0
  333. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex2.inc +44 -0
  334. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex2_double.c +10 -0
  335. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex2_float.c +10 -0
  336. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex2_longdouble.c +10 -0
  337. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex_double.c +10 -0
  338. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex_float.c +10 -0
  339. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex_longdouble.c +10 -0
  340. data/ext/ffi_c/libffi/testsuite/libffi.go/aa-direct.c +34 -0
  341. data/ext/ffi_c/libffi/testsuite/libffi.go/closure1.c +28 -0
  342. data/ext/ffi_c/libffi/testsuite/libffi.go/ffitest.h +1 -0
  343. data/ext/ffi_c/libffi/testsuite/libffi.go/go.exp +36 -0
  344. data/ext/ffi_c/libffi/testsuite/libffi.go/static-chain.h +19 -0
  345. data/ext/ffi_c/libffi.bsd.mk +11 -5
  346. data/ext/ffi_c/libffi.darwin.mk +14 -4
  347. data/ext/ffi_c/libffi.gnu.mk +3 -2
  348. data/ext/ffi_c/libffi.mk +10 -5
  349. data/ext/ffi_c/libffi.vc.mk +1 -1
  350. data/ext/ffi_c/libffi.vc64.mk +1 -1
  351. data/ffi.gemspec +16 -3
  352. data/lib/ffi/enum.rb +124 -0
  353. data/lib/ffi/library.rb +66 -14
  354. data/lib/ffi/platform/sparc64-linux/types.conf +102 -0
  355. data/lib/ffi/platform/x86_64-windows/types.conf +113 -20
  356. data/lib/ffi/platform.rb +7 -2
  357. data/lib/ffi/pointer.rb +1 -0
  358. data/lib/ffi/struct.rb +0 -2
  359. data/lib/ffi/version.rb +1 -2
  360. data/samples/getlogin.rb +8 -0
  361. data/samples/getpid.rb +8 -0
  362. data/samples/gettimeofday.rb +18 -0
  363. data/samples/hello.rb +7 -0
  364. data/samples/inotify.rb +60 -0
  365. data/samples/pty.rb +76 -0
  366. data/samples/qsort.rb +21 -0
  367. data/samples/sample_helper.rb +6 -0
  368. metadata +164 -115
  369. data/ext/ffi_c/ClosurePool.c +0 -283
  370. data/ext/ffi_c/libffi/Makefile.vc +0 -141
  371. data/ext/ffi_c/libffi/Makefile.vc64 +0 -141
  372. data/ext/ffi_c/libffi/aclocal.m4 +0 -1873
  373. data/ext/ffi_c/libffi/build-ios.sh +0 -67
  374. data/ext/ffi_c/libffi/compile +0 -143
  375. data/ext/ffi_c/libffi/depcomp +0 -630
  376. data/ext/ffi_c/libffi/doc/libffi.info +0 -593
  377. data/ext/ffi_c/libffi/doc/stamp-vti +0 -4
  378. data/ext/ffi_c/libffi/include/ffi.h.vc +0 -427
  379. data/ext/ffi_c/libffi/include/ffi.h.vc64 +0 -427
  380. data/ext/ffi_c/libffi/m4/libtool.m4 +0 -7831
  381. data/ext/ffi_c/libffi/m4/ltoptions.m4 +0 -369
  382. data/ext/ffi_c/libffi/m4/ltsugar.m4 +0 -123
  383. data/ext/ffi_c/libffi/m4/ltversion.m4 +0 -23
  384. data/ext/ffi_c/libffi/m4/lt~obsolete.m4 +0 -98
  385. data/ext/ffi_c/libffi/mdate-sh +0 -201
  386. data/ext/ffi_c/libffi/src/arm/gentramp.sh +0 -118
  387. data/ext/ffi_c/libffi/src/arm/trampoline.S +0 -4450
  388. data/ext/ffi_c/libffi/src/x86/darwin.S +0 -444
  389. data/ext/ffi_c/libffi/src/x86/darwin64.S +0 -416
  390. data/ext/ffi_c/libffi/src/x86/freebsd.S +0 -458
  391. data/ext/ffi_c/libffi/src/x86/win32.S +0 -1065
  392. data/ext/ffi_c/libffi/testsuite/lib/libffi-dg.exp +0 -300
  393. data/ext/ffi_c/libffi/testsuite/libffi.call/many_win32.c +0 -63
  394. data/ext/ffi_c/libffi/testsuite/libffi.call/strlen_win32.c +0 -44
  395. data/ext/ffi_c/libffi/testsuite/libffi.special/ffitestcxx.h +0 -96
  396. data/ext/ffi_c/libffi/texinfo.tex +0 -7210
  397. data/gen/Rakefile +0 -30
  398. data/libtest/Benchmark.c +0 -52
  399. data/libtest/BoolTest.c +0 -34
  400. data/libtest/BufferTest.c +0 -31
  401. data/libtest/ClosureTest.c +0 -205
  402. data/libtest/EnumTest.c +0 -51
  403. data/libtest/FunctionTest.c +0 -70
  404. data/libtest/GNUmakefile +0 -149
  405. data/libtest/GlobalVariable.c +0 -62
  406. data/libtest/LastErrorTest.c +0 -21
  407. data/libtest/NumberTest.c +0 -132
  408. data/libtest/PointerTest.c +0 -63
  409. data/libtest/ReferenceTest.c +0 -23
  410. data/libtest/StringTest.c +0 -34
  411. data/libtest/StructTest.c +0 -243
  412. data/libtest/UnionTest.c +0 -43
  413. data/libtest/VariadicTest.c +0 -99
  414. data/spec/ffi/async_callback_spec.rb +0 -35
  415. data/spec/ffi/bool_spec.rb +0 -32
  416. data/spec/ffi/buffer_spec.rb +0 -279
  417. data/spec/ffi/callback_spec.rb +0 -773
  418. data/spec/ffi/custom_param_type.rb +0 -37
  419. data/spec/ffi/custom_type_spec.rb +0 -74
  420. data/spec/ffi/dup_spec.rb +0 -52
  421. data/spec/ffi/enum_spec.rb +0 -423
  422. data/spec/ffi/errno_spec.rb +0 -20
  423. data/spec/ffi/ffi_spec.rb +0 -28
  424. data/spec/ffi/fixtures/Benchmark.c +0 -52
  425. data/spec/ffi/fixtures/BoolTest.c +0 -34
  426. data/spec/ffi/fixtures/BufferTest.c +0 -31
  427. data/spec/ffi/fixtures/ClosureTest.c +0 -205
  428. data/spec/ffi/fixtures/EnumTest.c +0 -51
  429. data/spec/ffi/fixtures/FunctionTest.c +0 -142
  430. data/spec/ffi/fixtures/GNUmakefile +0 -149
  431. data/spec/ffi/fixtures/GlobalVariable.c +0 -62
  432. data/spec/ffi/fixtures/LastErrorTest.c +0 -21
  433. data/spec/ffi/fixtures/NumberTest.c +0 -132
  434. data/spec/ffi/fixtures/PipeHelper.h +0 -21
  435. data/spec/ffi/fixtures/PipeHelperPosix.c +0 -41
  436. data/spec/ffi/fixtures/PipeHelperWindows.c +0 -72
  437. data/spec/ffi/fixtures/PointerTest.c +0 -63
  438. data/spec/ffi/fixtures/ReferenceTest.c +0 -23
  439. data/spec/ffi/fixtures/StringTest.c +0 -34
  440. data/spec/ffi/fixtures/StructTest.c +0 -243
  441. data/spec/ffi/fixtures/UnionTest.c +0 -43
  442. data/spec/ffi/fixtures/VariadicTest.c +0 -99
  443. data/spec/ffi/fixtures/classes.rb +0 -438
  444. data/spec/ffi/function_spec.rb +0 -97
  445. data/spec/ffi/io_spec.rb +0 -16
  446. data/spec/ffi/library_spec.rb +0 -286
  447. data/spec/ffi/long_double.rb +0 -30
  448. data/spec/ffi/managed_struct_spec.rb +0 -68
  449. data/spec/ffi/memorypointer_spec.rb +0 -78
  450. data/spec/ffi/number_spec.rb +0 -247
  451. data/spec/ffi/platform_spec.rb +0 -114
  452. data/spec/ffi/pointer_spec.rb +0 -285
  453. data/spec/ffi/rbx/attach_function_spec.rb +0 -34
  454. data/spec/ffi/rbx/memory_pointer_spec.rb +0 -194
  455. data/spec/ffi/rbx/spec_helper.rb +0 -6
  456. data/spec/ffi/rbx/struct_spec.rb +0 -18
  457. data/spec/ffi/spec_helper.rb +0 -93
  458. data/spec/ffi/string_spec.rb +0 -118
  459. data/spec/ffi/strptr_spec.rb +0 -50
  460. data/spec/ffi/struct_by_ref_spec.rb +0 -43
  461. data/spec/ffi/struct_callback_spec.rb +0 -69
  462. data/spec/ffi/struct_initialize_spec.rb +0 -35
  463. data/spec/ffi/struct_packed_spec.rb +0 -50
  464. data/spec/ffi/struct_spec.rb +0 -886
  465. data/spec/ffi/typedef_spec.rb +0 -91
  466. data/spec/ffi/union_spec.rb +0 -67
  467. data/spec/ffi/variadic_spec.rb +0 -132
  468. data/spec/spec.opts +0 -4
@@ -0,0 +1,964 @@
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
+ #include <stdio.h>
23
+ #include <stdlib.h>
24
+ #include <stdint.h>
25
+ #include <fficonfig.h>
26
+ #include <ffi.h>
27
+ #include <ffi_common.h>
28
+ #include "internal.h"
29
+
30
+ /* Force FFI_TYPE_LONGDOUBLE to be different than FFI_TYPE_DOUBLE;
31
+ all further uses in this file will refer to the 128-bit type. */
32
+ #if FFI_TYPE_DOUBLE != FFI_TYPE_LONGDOUBLE
33
+ # if FFI_TYPE_LONGDOUBLE != 4
34
+ # error FFI_TYPE_LONGDOUBLE out of date
35
+ # endif
36
+ #else
37
+ # undef FFI_TYPE_LONGDOUBLE
38
+ # define FFI_TYPE_LONGDOUBLE 4
39
+ #endif
40
+
41
+ union _d
42
+ {
43
+ UINT64 d;
44
+ UINT32 s[2];
45
+ };
46
+
47
+ struct _v
48
+ {
49
+ union _d d[2] __attribute__((aligned(16)));
50
+ };
51
+
52
+ struct call_context
53
+ {
54
+ struct _v v[N_V_ARG_REG];
55
+ UINT64 x[N_X_ARG_REG];
56
+ };
57
+
58
+ #if FFI_EXEC_TRAMPOLINE_TABLE
59
+
60
+ #ifdef __MACH__
61
+ #include <mach/vm_param.h>
62
+ #endif
63
+
64
+ #else
65
+
66
+ #if defined (__clang__) && defined (__APPLE__)
67
+ extern void sys_icache_invalidate (void *start, size_t len);
68
+ #endif
69
+
70
+ static inline void
71
+ ffi_clear_cache (void *start, void *end)
72
+ {
73
+ #if defined (__clang__) && defined (__APPLE__)
74
+ sys_icache_invalidate (start, (char *)end - (char *)start);
75
+ #elif defined (__GNUC__)
76
+ __builtin___clear_cache (start, end);
77
+ #else
78
+ #error "Missing builtin to flush instruction cache"
79
+ #endif
80
+ }
81
+
82
+ #endif
83
+
84
+ /* A subroutine of is_vfp_type. Given a structure type, return the type code
85
+ of the first non-structure element. Recurse for structure elements.
86
+ Return -1 if the structure is in fact empty, i.e. no nested elements. */
87
+
88
+ static int
89
+ is_hfa0 (const ffi_type *ty)
90
+ {
91
+ ffi_type **elements = ty->elements;
92
+ int i, ret = -1;
93
+
94
+ if (elements != NULL)
95
+ for (i = 0; elements[i]; ++i)
96
+ {
97
+ ret = elements[i]->type;
98
+ if (ret == FFI_TYPE_STRUCT || ret == FFI_TYPE_COMPLEX)
99
+ {
100
+ ret = is_hfa0 (elements[i]);
101
+ if (ret < 0)
102
+ continue;
103
+ }
104
+ break;
105
+ }
106
+
107
+ return ret;
108
+ }
109
+
110
+ /* A subroutine of is_vfp_type. Given a structure type, return true if all
111
+ of the non-structure elements are the same as CANDIDATE. */
112
+
113
+ static int
114
+ is_hfa1 (const ffi_type *ty, int candidate)
115
+ {
116
+ ffi_type **elements = ty->elements;
117
+ int i;
118
+
119
+ if (elements != NULL)
120
+ for (i = 0; elements[i]; ++i)
121
+ {
122
+ int t = elements[i]->type;
123
+ if (t == FFI_TYPE_STRUCT || t == FFI_TYPE_COMPLEX)
124
+ {
125
+ if (!is_hfa1 (elements[i], candidate))
126
+ return 0;
127
+ }
128
+ else if (t != candidate)
129
+ return 0;
130
+ }
131
+
132
+ return 1;
133
+ }
134
+
135
+ /* Determine if TY may be allocated to the FP registers. This is both an
136
+ fp scalar type as well as an homogenous floating point aggregate (HFA).
137
+ That is, a structure consisting of 1 to 4 members of all the same type,
138
+ where that type is an fp scalar.
139
+
140
+ Returns non-zero iff TY is an HFA. The result is the AARCH64_RET_*
141
+ constant for the type. */
142
+
143
+ static int
144
+ is_vfp_type (const ffi_type *ty)
145
+ {
146
+ ffi_type **elements;
147
+ int candidate, i;
148
+ size_t size, ele_count;
149
+
150
+ /* Quickest tests first. */
151
+ candidate = ty->type;
152
+ switch (candidate)
153
+ {
154
+ default:
155
+ return 0;
156
+ case FFI_TYPE_FLOAT:
157
+ case FFI_TYPE_DOUBLE:
158
+ case FFI_TYPE_LONGDOUBLE:
159
+ ele_count = 1;
160
+ goto done;
161
+ case FFI_TYPE_COMPLEX:
162
+ candidate = ty->elements[0]->type;
163
+ switch (candidate)
164
+ {
165
+ case FFI_TYPE_FLOAT:
166
+ case FFI_TYPE_DOUBLE:
167
+ case FFI_TYPE_LONGDOUBLE:
168
+ ele_count = 2;
169
+ goto done;
170
+ }
171
+ return 0;
172
+ case FFI_TYPE_STRUCT:
173
+ break;
174
+ }
175
+
176
+ /* No HFA types are smaller than 4 bytes, or larger than 64 bytes. */
177
+ size = ty->size;
178
+ if (size < 4 || size > 64)
179
+ return 0;
180
+
181
+ /* Find the type of the first non-structure member. */
182
+ elements = ty->elements;
183
+ candidate = elements[0]->type;
184
+ if (candidate == FFI_TYPE_STRUCT || candidate == FFI_TYPE_COMPLEX)
185
+ {
186
+ for (i = 0; ; ++i)
187
+ {
188
+ candidate = is_hfa0 (elements[i]);
189
+ if (candidate >= 0)
190
+ break;
191
+ }
192
+ }
193
+
194
+ /* If the first member is not a floating point type, it's not an HFA.
195
+ Also quickly re-check the size of the structure. */
196
+ switch (candidate)
197
+ {
198
+ case FFI_TYPE_FLOAT:
199
+ ele_count = size / sizeof(float);
200
+ if (size != ele_count * sizeof(float))
201
+ return 0;
202
+ break;
203
+ case FFI_TYPE_DOUBLE:
204
+ ele_count = size / sizeof(double);
205
+ if (size != ele_count * sizeof(double))
206
+ return 0;
207
+ break;
208
+ case FFI_TYPE_LONGDOUBLE:
209
+ ele_count = size / sizeof(long double);
210
+ if (size != ele_count * sizeof(long double))
211
+ return 0;
212
+ break;
213
+ default:
214
+ return 0;
215
+ }
216
+ if (ele_count > 4)
217
+ return 0;
218
+
219
+ /* Finally, make sure that all scalar elements are the same type. */
220
+ for (i = 0; elements[i]; ++i)
221
+ {
222
+ int t = elements[i]->type;
223
+ if (t == FFI_TYPE_STRUCT || t == FFI_TYPE_COMPLEX)
224
+ {
225
+ if (!is_hfa1 (elements[i], candidate))
226
+ return 0;
227
+ }
228
+ else if (t != candidate)
229
+ return 0;
230
+ }
231
+
232
+ /* All tests succeeded. Encode the result. */
233
+ done:
234
+ return candidate * 4 + (4 - (int)ele_count);
235
+ }
236
+
237
+ /* Representation of the procedure call argument marshalling
238
+ state.
239
+
240
+ The terse state variable names match the names used in the AARCH64
241
+ PCS.
242
+
243
+ The struct area is allocated downwards from the top of the argument
244
+ area. It is used to hold copies of structures passed by value that are
245
+ bigger than 16 bytes. */
246
+
247
+ struct arg_state
248
+ {
249
+ unsigned ngrn; /* Next general-purpose register number. */
250
+ unsigned nsrn; /* Next vector register number. */
251
+ size_t nsaa; /* Next stack offset. */
252
+ size_t next_struct_area; /* Place to allocate big structs. */
253
+
254
+ #if defined (__APPLE__)
255
+ unsigned allocating_variadic;
256
+ #endif
257
+ };
258
+
259
+ /* Initialize a procedure call argument marshalling state. */
260
+ static void
261
+ arg_init (struct arg_state *state, size_t size)
262
+ {
263
+ state->ngrn = 0;
264
+ state->nsrn = 0;
265
+ state->nsaa = 0;
266
+ state->next_struct_area = size;
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
+ /* Allocate and copy a structure that is passed by value on the stack and
296
+ return a pointer to it. */
297
+ static void *
298
+ allocate_and_copy_struct_to_stack (struct arg_state *state, void *stack,
299
+ size_t alignment, size_t size, void *value)
300
+ {
301
+ size_t dest = state->next_struct_area - size;
302
+
303
+ /* Round down to the natural alignment of the value. */
304
+ dest = ALIGN_DOWN (dest, alignment);
305
+ state->next_struct_area = dest;
306
+
307
+ return memcpy ((char *) stack + dest, value, size);
308
+ }
309
+
310
+ static ffi_arg
311
+ extend_integer_type (void *source, int type)
312
+ {
313
+ switch (type)
314
+ {
315
+ case FFI_TYPE_UINT8:
316
+ return *(UINT8 *) source;
317
+ case FFI_TYPE_SINT8:
318
+ return *(SINT8 *) source;
319
+ case FFI_TYPE_UINT16:
320
+ return *(UINT16 *) source;
321
+ case FFI_TYPE_SINT16:
322
+ return *(SINT16 *) source;
323
+ case FFI_TYPE_UINT32:
324
+ return *(UINT32 *) source;
325
+ case FFI_TYPE_INT:
326
+ case FFI_TYPE_SINT32:
327
+ return *(SINT32 *) source;
328
+ case FFI_TYPE_UINT64:
329
+ case FFI_TYPE_SINT64:
330
+ return *(UINT64 *) source;
331
+ break;
332
+ case FFI_TYPE_POINTER:
333
+ return *(uintptr_t *) source;
334
+ default:
335
+ abort();
336
+ }
337
+ }
338
+
339
+ static void
340
+ extend_hfa_type (void *dest, void *src, int h)
341
+ {
342
+ ssize_t f = h - AARCH64_RET_S4;
343
+ void *x0;
344
+
345
+ asm volatile (
346
+ "adr %0, 0f\n"
347
+ " add %0, %0, %1\n"
348
+ " br %0\n"
349
+ "0: ldp s16, s17, [%3]\n" /* S4 */
350
+ " ldp s18, s19, [%3, #8]\n"
351
+ " b 4f\n"
352
+ " ldp s16, s17, [%3]\n" /* S3 */
353
+ " ldr s18, [%3, #8]\n"
354
+ " b 3f\n"
355
+ " ldp s16, s17, [%3]\n" /* S2 */
356
+ " b 2f\n"
357
+ " nop\n"
358
+ " ldr s16, [%3]\n" /* S1 */
359
+ " b 1f\n"
360
+ " nop\n"
361
+ " ldp d16, d17, [%3]\n" /* D4 */
362
+ " ldp d18, d19, [%3, #16]\n"
363
+ " b 4f\n"
364
+ " ldp d16, d17, [%3]\n" /* D3 */
365
+ " ldr d18, [%3, #16]\n"
366
+ " b 3f\n"
367
+ " ldp d16, d17, [%3]\n" /* D2 */
368
+ " b 2f\n"
369
+ " nop\n"
370
+ " ldr d16, [%3]\n" /* D1 */
371
+ " b 1f\n"
372
+ " nop\n"
373
+ " ldp q16, q17, [%3]\n" /* Q4 */
374
+ " ldp q18, q19, [%3, #16]\n"
375
+ " b 4f\n"
376
+ " ldp q16, q17, [%3]\n" /* Q3 */
377
+ " ldr q18, [%3, #16]\n"
378
+ " b 3f\n"
379
+ " ldp q16, q17, [%3]\n" /* Q2 */
380
+ " b 2f\n"
381
+ " nop\n"
382
+ " ldr q16, [%3]\n" /* Q1 */
383
+ " b 1f\n"
384
+ "4: str q19, [%2, #48]\n"
385
+ "3: str q18, [%2, #32]\n"
386
+ "2: str q17, [%2, #16]\n"
387
+ "1: str q16, [%2]"
388
+ : "=&r"(x0)
389
+ : "r"(f * 12), "r"(dest), "r"(src)
390
+ : "memory", "v16", "v17", "v18", "v19");
391
+ }
392
+
393
+ static void *
394
+ compress_hfa_type (void *dest, void *reg, int h)
395
+ {
396
+ switch (h)
397
+ {
398
+ case AARCH64_RET_S1:
399
+ if (dest == reg)
400
+ {
401
+ #ifdef __AARCH64EB__
402
+ dest += 12;
403
+ #endif
404
+ }
405
+ else
406
+ *(float *)dest = *(float *)reg;
407
+ break;
408
+ case AARCH64_RET_S2:
409
+ asm ("ldp q16, q17, [%1]\n\t"
410
+ "st2 { v16.s, v17.s }[0], [%0]"
411
+ : : "r"(dest), "r"(reg) : "memory", "v16", "v17");
412
+ break;
413
+ case AARCH64_RET_S3:
414
+ asm ("ldp q16, q17, [%1]\n\t"
415
+ "ldr q18, [%1, #32]\n\t"
416
+ "st3 { v16.s, v17.s, v18.s }[0], [%0]"
417
+ : : "r"(dest), "r"(reg) : "memory", "v16", "v17", "v18");
418
+ break;
419
+ case AARCH64_RET_S4:
420
+ asm ("ldp q16, q17, [%1]\n\t"
421
+ "ldp q18, q19, [%1, #32]\n\t"
422
+ "st4 { v16.s, v17.s, v18.s, v19.s }[0], [%0]"
423
+ : : "r"(dest), "r"(reg) : "memory", "v16", "v17", "v18", "v19");
424
+ break;
425
+
426
+ case AARCH64_RET_D1:
427
+ if (dest == reg)
428
+ {
429
+ #ifdef __AARCH64EB__
430
+ dest += 8;
431
+ #endif
432
+ }
433
+ else
434
+ *(double *)dest = *(double *)reg;
435
+ break;
436
+ case AARCH64_RET_D2:
437
+ asm ("ldp q16, q17, [%1]\n\t"
438
+ "st2 { v16.d, v17.d }[0], [%0]"
439
+ : : "r"(dest), "r"(reg) : "memory", "v16", "v17");
440
+ break;
441
+ case AARCH64_RET_D3:
442
+ asm ("ldp q16, q17, [%1]\n\t"
443
+ "ldr q18, [%1, #32]\n\t"
444
+ "st3 { v16.d, v17.d, v18.d }[0], [%0]"
445
+ : : "r"(dest), "r"(reg) : "memory", "v16", "v17", "v18");
446
+ break;
447
+ case AARCH64_RET_D4:
448
+ asm ("ldp q16, q17, [%1]\n\t"
449
+ "ldp q18, q19, [%1, #32]\n\t"
450
+ "st4 { v16.d, v17.d, v18.d, v19.d }[0], [%0]"
451
+ : : "r"(dest), "r"(reg) : "memory", "v16", "v17", "v18", "v19");
452
+ break;
453
+
454
+ default:
455
+ if (dest != reg)
456
+ return memcpy (dest, reg, 16 * (4 - (h & 3)));
457
+ break;
458
+ }
459
+ return dest;
460
+ }
461
+
462
+ /* Either allocate an appropriate register for the argument type, or if
463
+ none are available, allocate a stack slot and return a pointer
464
+ to the allocated space. */
465
+
466
+ static void *
467
+ allocate_int_to_reg_or_stack (struct call_context *context,
468
+ struct arg_state *state,
469
+ void *stack, size_t size)
470
+ {
471
+ if (state->ngrn < N_X_ARG_REG)
472
+ return &context->x[state->ngrn++];
473
+
474
+ state->ngrn = N_X_ARG_REG;
475
+ return allocate_to_stack (state, stack, size, size);
476
+ }
477
+
478
+ ffi_status
479
+ ffi_prep_cif_machdep (ffi_cif *cif)
480
+ {
481
+ ffi_type *rtype = cif->rtype;
482
+ size_t bytes = cif->bytes;
483
+ int flags, i, n;
484
+
485
+ switch (rtype->type)
486
+ {
487
+ case FFI_TYPE_VOID:
488
+ flags = AARCH64_RET_VOID;
489
+ break;
490
+ case FFI_TYPE_UINT8:
491
+ flags = AARCH64_RET_UINT8;
492
+ break;
493
+ case FFI_TYPE_UINT16:
494
+ flags = AARCH64_RET_UINT16;
495
+ break;
496
+ case FFI_TYPE_UINT32:
497
+ flags = AARCH64_RET_UINT32;
498
+ break;
499
+ case FFI_TYPE_SINT8:
500
+ flags = AARCH64_RET_SINT8;
501
+ break;
502
+ case FFI_TYPE_SINT16:
503
+ flags = AARCH64_RET_SINT16;
504
+ break;
505
+ case FFI_TYPE_INT:
506
+ case FFI_TYPE_SINT32:
507
+ flags = AARCH64_RET_SINT32;
508
+ break;
509
+ case FFI_TYPE_SINT64:
510
+ case FFI_TYPE_UINT64:
511
+ flags = AARCH64_RET_INT64;
512
+ break;
513
+ case FFI_TYPE_POINTER:
514
+ flags = (sizeof(void *) == 4 ? AARCH64_RET_UINT32 : AARCH64_RET_INT64);
515
+ break;
516
+
517
+ case FFI_TYPE_FLOAT:
518
+ case FFI_TYPE_DOUBLE:
519
+ case FFI_TYPE_LONGDOUBLE:
520
+ case FFI_TYPE_STRUCT:
521
+ case FFI_TYPE_COMPLEX:
522
+ flags = is_vfp_type (rtype);
523
+ if (flags == 0)
524
+ {
525
+ size_t s = rtype->size;
526
+ if (s > 16)
527
+ {
528
+ flags = AARCH64_RET_VOID | AARCH64_RET_IN_MEM;
529
+ bytes += 8;
530
+ }
531
+ else if (s == 16)
532
+ flags = AARCH64_RET_INT128;
533
+ else if (s == 8)
534
+ flags = AARCH64_RET_INT64;
535
+ else
536
+ flags = AARCH64_RET_INT128 | AARCH64_RET_NEED_COPY;
537
+ }
538
+ break;
539
+
540
+ default:
541
+ abort();
542
+ }
543
+
544
+ for (i = 0, n = cif->nargs; i < n; i++)
545
+ if (is_vfp_type (cif->arg_types[i]))
546
+ {
547
+ flags |= AARCH64_FLAG_ARG_V;
548
+ break;
549
+ }
550
+
551
+ /* Round the stack up to a multiple of the stack alignment requirement. */
552
+ cif->bytes = (unsigned) FFI_ALIGN(bytes, 16);
553
+ cif->flags = flags;
554
+ #if defined (__APPLE__)
555
+ cif->aarch64_nfixedargs = 0;
556
+ #endif
557
+
558
+ return FFI_OK;
559
+ }
560
+
561
+ #if defined (__APPLE__)
562
+ /* Perform Apple-specific cif processing for variadic calls */
563
+ ffi_status ffi_prep_cif_machdep_var(ffi_cif *cif,
564
+ unsigned int nfixedargs,
565
+ unsigned int ntotalargs)
566
+ {
567
+ ffi_status status = ffi_prep_cif_machdep (cif);
568
+ cif->aarch64_nfixedargs = nfixedargs;
569
+ return status;
570
+ }
571
+ #endif /* __APPLE__ */
572
+
573
+ extern void ffi_call_SYSV (struct call_context *context, void *frame,
574
+ void (*fn)(void), void *rvalue, int flags,
575
+ void *closure) FFI_HIDDEN;
576
+
577
+ /* Call a function with the provided arguments and capture the return
578
+ value. */
579
+ static void
580
+ ffi_call_int (ffi_cif *cif, void (*fn)(void), void *orig_rvalue,
581
+ void **avalue, void *closure)
582
+ {
583
+ struct call_context *context;
584
+ void *stack, *frame, *rvalue;
585
+ struct arg_state state;
586
+ size_t stack_bytes, rtype_size, rsize;
587
+ int i, nargs, flags;
588
+ ffi_type *rtype;
589
+
590
+ flags = cif->flags;
591
+ rtype = cif->rtype;
592
+ rtype_size = rtype->size;
593
+ stack_bytes = cif->bytes;
594
+
595
+ /* If the target function returns a structure via hidden pointer,
596
+ then we cannot allow a null rvalue. Otherwise, mash a null
597
+ rvalue to void return type. */
598
+ rsize = 0;
599
+ if (flags & AARCH64_RET_IN_MEM)
600
+ {
601
+ if (orig_rvalue == NULL)
602
+ rsize = rtype_size;
603
+ }
604
+ else if (orig_rvalue == NULL)
605
+ flags &= AARCH64_FLAG_ARG_V;
606
+ else if (flags & AARCH64_RET_NEED_COPY)
607
+ rsize = 16;
608
+
609
+ /* Allocate consectutive stack for everything we'll need. */
610
+ context = alloca (sizeof(struct call_context) + stack_bytes + 32 + rsize);
611
+ stack = context + 1;
612
+ frame = stack + stack_bytes;
613
+ rvalue = (rsize ? frame + 32 : orig_rvalue);
614
+
615
+ arg_init (&state, stack_bytes);
616
+ for (i = 0, nargs = cif->nargs; i < nargs; i++)
617
+ {
618
+ ffi_type *ty = cif->arg_types[i];
619
+ size_t s = ty->size;
620
+ void *a = avalue[i];
621
+ int h, t;
622
+ void *dest;
623
+
624
+ t = ty->type;
625
+ switch (t)
626
+ {
627
+ case FFI_TYPE_VOID:
628
+ FFI_ASSERT (0);
629
+ break;
630
+
631
+ /* If the argument is a basic type the argument is allocated to an
632
+ appropriate register, or if none are available, to the stack. */
633
+ case FFI_TYPE_INT:
634
+ case FFI_TYPE_UINT8:
635
+ case FFI_TYPE_SINT8:
636
+ case FFI_TYPE_UINT16:
637
+ case FFI_TYPE_SINT16:
638
+ case FFI_TYPE_UINT32:
639
+ case FFI_TYPE_SINT32:
640
+ case FFI_TYPE_UINT64:
641
+ case FFI_TYPE_SINT64:
642
+ case FFI_TYPE_POINTER:
643
+ do_pointer:
644
+ {
645
+ ffi_arg ext = extend_integer_type (a, t);
646
+ if (state.ngrn < N_X_ARG_REG)
647
+ context->x[state.ngrn++] = ext;
648
+ else
649
+ {
650
+ void *d = allocate_to_stack (&state, stack, ty->alignment, s);
651
+ state.ngrn = N_X_ARG_REG;
652
+ /* Note that the default abi extends each argument
653
+ to a full 64-bit slot, while the iOS abi allocates
654
+ only enough space. */
655
+ #ifdef __APPLE__
656
+ memcpy(d, a, s);
657
+ #else
658
+ *(ffi_arg *)d = ext;
659
+ #endif
660
+ }
661
+ }
662
+ break;
663
+
664
+ case FFI_TYPE_FLOAT:
665
+ case FFI_TYPE_DOUBLE:
666
+ case FFI_TYPE_LONGDOUBLE:
667
+ case FFI_TYPE_STRUCT:
668
+ case FFI_TYPE_COMPLEX:
669
+ {
670
+ h = is_vfp_type (ty);
671
+ if (h)
672
+ {
673
+ int elems = 4 - (h & 3);
674
+ if (state.nsrn + elems <= N_V_ARG_REG)
675
+ {
676
+ dest = &context->v[state.nsrn];
677
+ state.nsrn += elems;
678
+ extend_hfa_type (dest, a, h);
679
+ break;
680
+ }
681
+ state.nsrn = N_V_ARG_REG;
682
+ dest = allocate_to_stack (&state, stack, ty->alignment, s);
683
+ }
684
+ else if (s > 16)
685
+ {
686
+ /* If the argument is a composite type that is larger than 16
687
+ bytes, then the argument is copied to memory, and
688
+ the argument is replaced by a pointer to the copy. */
689
+ dest = allocate_and_copy_struct_to_stack (&state, stack,
690
+ ty->alignment, s,
691
+ avalue[i]);
692
+ a = &dest;
693
+ t = FFI_TYPE_POINTER;
694
+ s = sizeof (void *);
695
+ goto do_pointer;
696
+ }
697
+ else
698
+ {
699
+ size_t n = (s + 7) / 8;
700
+ if (state.ngrn + n <= N_X_ARG_REG)
701
+ {
702
+ /* If the argument is a composite type and the size in
703
+ double-words is not more than the number of available
704
+ X registers, then the argument is copied into
705
+ consecutive X registers. */
706
+ dest = &context->x[state.ngrn];
707
+ state.ngrn += n;
708
+ }
709
+ else
710
+ {
711
+ /* Otherwise, there are insufficient X registers. Further
712
+ X register allocations are prevented, the NSAA is
713
+ adjusted and the argument is copied to memory at the
714
+ adjusted NSAA. */
715
+ state.ngrn = N_X_ARG_REG;
716
+ dest = allocate_to_stack (&state, stack, ty->alignment, s);
717
+ }
718
+ }
719
+ memcpy (dest, a, s);
720
+ }
721
+ break;
722
+
723
+ default:
724
+ abort();
725
+ }
726
+
727
+ #if defined (__APPLE__)
728
+ if (i + 1 == cif->aarch64_nfixedargs)
729
+ {
730
+ state.ngrn = N_X_ARG_REG;
731
+ state.nsrn = N_V_ARG_REG;
732
+ state.allocating_variadic = 1;
733
+ }
734
+ #endif
735
+ }
736
+
737
+ ffi_call_SYSV (context, frame, fn, rvalue, flags, closure);
738
+
739
+ if (flags & AARCH64_RET_NEED_COPY)
740
+ memcpy (orig_rvalue, rvalue, rtype_size);
741
+ }
742
+
743
+ void
744
+ ffi_call (ffi_cif *cif, void (*fn) (void), void *rvalue, void **avalue)
745
+ {
746
+ ffi_call_int (cif, fn, rvalue, avalue, NULL);
747
+ }
748
+
749
+ #ifdef FFI_GO_CLOSURES
750
+ void
751
+ ffi_call_go (ffi_cif *cif, void (*fn) (void), void *rvalue,
752
+ void **avalue, void *closure)
753
+ {
754
+ ffi_call_int (cif, fn, rvalue, avalue, closure);
755
+ }
756
+ #endif /* FFI_GO_CLOSURES */
757
+
758
+ /* Build a trampoline. */
759
+
760
+ extern void ffi_closure_SYSV (void) FFI_HIDDEN;
761
+ extern void ffi_closure_SYSV_V (void) FFI_HIDDEN;
762
+
763
+ ffi_status
764
+ ffi_prep_closure_loc (ffi_closure *closure,
765
+ ffi_cif* cif,
766
+ void (*fun)(ffi_cif*,void*,void**,void*),
767
+ void *user_data,
768
+ void *codeloc)
769
+ {
770
+ if (cif->abi != FFI_SYSV)
771
+ return FFI_BAD_ABI;
772
+
773
+ void (*start)(void);
774
+
775
+ if (cif->flags & AARCH64_FLAG_ARG_V)
776
+ start = ffi_closure_SYSV_V;
777
+ else
778
+ start = ffi_closure_SYSV;
779
+
780
+ #if FFI_EXEC_TRAMPOLINE_TABLE
781
+ #ifdef __MACH__
782
+ void **config = (void **)((uint8_t *)codeloc - PAGE_MAX_SIZE);
783
+ config[0] = closure;
784
+ config[1] = start;
785
+ #endif
786
+ #else
787
+ static const unsigned char trampoline[16] = {
788
+ 0x90, 0x00, 0x00, 0x58, /* ldr x16, tramp+16 */
789
+ 0xf1, 0xff, 0xff, 0x10, /* adr x17, tramp+0 */
790
+ 0x00, 0x02, 0x1f, 0xd6 /* br x16 */
791
+ };
792
+ char *tramp = closure->tramp;
793
+
794
+ memcpy (tramp, trampoline, sizeof(trampoline));
795
+
796
+ *(UINT64 *)(tramp + 16) = (uintptr_t)start;
797
+
798
+ ffi_clear_cache(tramp, tramp + FFI_TRAMPOLINE_SIZE);
799
+ #endif
800
+
801
+ closure->cif = cif;
802
+ closure->fun = fun;
803
+ closure->user_data = user_data;
804
+
805
+ return FFI_OK;
806
+ }
807
+
808
+ #ifdef FFI_GO_CLOSURES
809
+ extern void ffi_go_closure_SYSV (void) FFI_HIDDEN;
810
+ extern void ffi_go_closure_SYSV_V (void) FFI_HIDDEN;
811
+
812
+ ffi_status
813
+ ffi_prep_go_closure (ffi_go_closure *closure, ffi_cif* cif,
814
+ void (*fun)(ffi_cif*,void*,void**,void*))
815
+ {
816
+ void (*start)(void);
817
+
818
+ if (cif->abi != FFI_SYSV)
819
+ return FFI_BAD_ABI;
820
+
821
+ if (cif->flags & AARCH64_FLAG_ARG_V)
822
+ start = ffi_go_closure_SYSV_V;
823
+ else
824
+ start = ffi_go_closure_SYSV;
825
+
826
+ closure->tramp = start;
827
+ closure->cif = cif;
828
+ closure->fun = fun;
829
+
830
+ return FFI_OK;
831
+ }
832
+ #endif /* FFI_GO_CLOSURES */
833
+
834
+ /* Primary handler to setup and invoke a function within a closure.
835
+
836
+ A closure when invoked enters via the assembler wrapper
837
+ ffi_closure_SYSV(). The wrapper allocates a call context on the
838
+ stack, saves the interesting registers (from the perspective of
839
+ the calling convention) into the context then passes control to
840
+ ffi_closure_SYSV_inner() passing the saved context and a pointer to
841
+ the stack at the point ffi_closure_SYSV() was invoked.
842
+
843
+ On the return path the assembler wrapper will reload call context
844
+ registers.
845
+
846
+ ffi_closure_SYSV_inner() marshalls the call context into ffi value
847
+ descriptors, invokes the wrapped function, then marshalls the return
848
+ value back into the call context. */
849
+
850
+ int FFI_HIDDEN
851
+ ffi_closure_SYSV_inner (ffi_cif *cif,
852
+ void (*fun)(ffi_cif*,void*,void**,void*),
853
+ void *user_data,
854
+ struct call_context *context,
855
+ void *stack, void *rvalue, void *struct_rvalue)
856
+ {
857
+ void **avalue = (void**) alloca (cif->nargs * sizeof (void*));
858
+ int i, h, nargs, flags;
859
+ struct arg_state state;
860
+
861
+ arg_init (&state, cif->bytes);
862
+
863
+ for (i = 0, nargs = cif->nargs; i < nargs; i++)
864
+ {
865
+ ffi_type *ty = cif->arg_types[i];
866
+ int t = ty->type;
867
+ size_t n, s = ty->size;
868
+
869
+ switch (t)
870
+ {
871
+ case FFI_TYPE_VOID:
872
+ FFI_ASSERT (0);
873
+ break;
874
+
875
+ case FFI_TYPE_INT:
876
+ case FFI_TYPE_UINT8:
877
+ case FFI_TYPE_SINT8:
878
+ case FFI_TYPE_UINT16:
879
+ case FFI_TYPE_SINT16:
880
+ case FFI_TYPE_UINT32:
881
+ case FFI_TYPE_SINT32:
882
+ case FFI_TYPE_UINT64:
883
+ case FFI_TYPE_SINT64:
884
+ case FFI_TYPE_POINTER:
885
+ avalue[i] = allocate_int_to_reg_or_stack (context, &state, stack, s);
886
+ break;
887
+
888
+ case FFI_TYPE_FLOAT:
889
+ case FFI_TYPE_DOUBLE:
890
+ case FFI_TYPE_LONGDOUBLE:
891
+ case FFI_TYPE_STRUCT:
892
+ case FFI_TYPE_COMPLEX:
893
+ h = is_vfp_type (ty);
894
+ if (h)
895
+ {
896
+ n = 4 - (h & 3);
897
+ if (state.nsrn + n <= N_V_ARG_REG)
898
+ {
899
+ void *reg = &context->v[state.nsrn];
900
+ state.nsrn += n;
901
+
902
+ /* Eeek! We need a pointer to the structure, however the
903
+ homogeneous float elements are being passed in individual
904
+ registers, therefore for float and double the structure
905
+ is not represented as a contiguous sequence of bytes in
906
+ our saved register context. We don't need the original
907
+ contents of the register storage, so we reformat the
908
+ structure into the same memory. */
909
+ avalue[i] = compress_hfa_type (reg, reg, h);
910
+ }
911
+ else
912
+ {
913
+ state.nsrn = N_V_ARG_REG;
914
+ avalue[i] = allocate_to_stack (&state, stack,
915
+ ty->alignment, s);
916
+ }
917
+ }
918
+ else if (s > 16)
919
+ {
920
+ /* Replace Composite type of size greater than 16 with a
921
+ pointer. */
922
+ avalue[i] = *(void **)
923
+ allocate_int_to_reg_or_stack (context, &state, stack,
924
+ sizeof (void *));
925
+ }
926
+ else
927
+ {
928
+ n = (s + 7) / 8;
929
+ if (state.ngrn + n <= N_X_ARG_REG)
930
+ {
931
+ avalue[i] = &context->x[state.ngrn];
932
+ state.ngrn += n;
933
+ }
934
+ else
935
+ {
936
+ state.ngrn = N_X_ARG_REG;
937
+ avalue[i] = allocate_to_stack (&state, stack,
938
+ ty->alignment, s);
939
+ }
940
+ }
941
+ break;
942
+
943
+ default:
944
+ abort();
945
+ }
946
+
947
+ #if defined (__APPLE__)
948
+ if (i + 1 == cif->aarch64_nfixedargs)
949
+ {
950
+ state.ngrn = N_X_ARG_REG;
951
+ state.nsrn = N_V_ARG_REG;
952
+ state.allocating_variadic = 1;
953
+ }
954
+ #endif
955
+ }
956
+
957
+ flags = cif->flags;
958
+ if (flags & AARCH64_RET_IN_MEM)
959
+ rvalue = struct_rvalue;
960
+
961
+ fun (cif, rvalue, avalue, user_data);
962
+
963
+ return flags;
964
+ }