ffi 1.9.18-x64-mingw32 → 1.9.21-x64-mingw32

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of ffi might be problematic. Click here for more details.

Files changed (384) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +3 -2
  3. data/Rakefile +14 -4
  4. data/ext/ffi_c/AbstractMemory.c +6 -1
  5. data/ext/ffi_c/Platform.c +10 -2
  6. data/ext/ffi_c/extconf.rb +7 -2
  7. data/ext/ffi_c/libffi.bsd.mk +9 -3
  8. data/ext/ffi_c/libffi.darwin.mk +14 -4
  9. data/ext/ffi_c/libffi.gnu.mk +2 -1
  10. data/ext/ffi_c/libffi.mk +9 -4
  11. data/ext/ffi_c/libffi/ChangeLog.libffi +2 -2
  12. data/ext/ffi_c/libffi/{ChangeLog → ChangeLog.libffi-3.1} +1402 -2
  13. data/ext/ffi_c/libffi/ChangeLog.v1 +1 -1
  14. data/ext/ffi_c/libffi/LICENSE +1 -1
  15. data/ext/ffi_c/libffi/Makefile.am +166 -157
  16. data/ext/ffi_c/libffi/Makefile.in +923 -938
  17. data/ext/ffi_c/libffi/README +164 -52
  18. data/ext/ffi_c/libffi/acinclude.m4 +381 -0
  19. data/ext/ffi_c/libffi/aclocal.m4 +645 -384
  20. data/ext/ffi_c/libffi/autogen.sh +2 -0
  21. data/ext/ffi_c/libffi/autom4te.cache/output.0 +21972 -0
  22. data/ext/ffi_c/libffi/autom4te.cache/output.1 +21972 -0
  23. data/ext/ffi_c/libffi/autom4te.cache/output.2 +21972 -0
  24. data/ext/ffi_c/libffi/autom4te.cache/output.3 +21972 -0
  25. data/ext/ffi_c/libffi/autom4te.cache/requests +331 -0
  26. data/ext/ffi_c/libffi/autom4te.cache/traces.0 +4010 -0
  27. data/ext/ffi_c/libffi/autom4te.cache/traces.1 +1005 -0
  28. data/ext/ffi_c/libffi/autom4te.cache/traces.2 +4010 -0
  29. data/ext/ffi_c/libffi/autom4te.cache/traces.3 +4010 -0
  30. data/ext/ffi_c/libffi/compile +218 -14
  31. data/ext/ffi_c/libffi/config.guess +329 -368
  32. data/ext/ffi_c/libffi/config.sub +232 -112
  33. data/ext/ffi_c/libffi/configure +6970 -2189
  34. data/ext/ffi_c/libffi/configure.ac +148 -256
  35. data/ext/ffi_c/libffi/configure.host +265 -4
  36. data/ext/ffi_c/libffi/depcomp +346 -185
  37. data/ext/ffi_c/libffi/doc/Makefile.am +3 -0
  38. data/ext/ffi_c/libffi/doc/Makefile.in +811 -0
  39. data/ext/ffi_c/libffi/doc/libffi.texi +430 -45
  40. data/ext/ffi_c/libffi/{mdate-sh → doc/mdate-sh} +40 -13
  41. data/ext/ffi_c/libffi/{texinfo.tex → doc/texinfo.tex} +3990 -1121
  42. data/ext/ffi_c/libffi/doc/version.texi +4 -4
  43. data/ext/ffi_c/libffi/fficonfig.h.in +24 -13
  44. data/ext/ffi_c/libffi/fficonfig.h.in~ +210 -0
  45. data/ext/ffi_c/libffi/generate-darwin-source-and-headers.py +207 -0
  46. data/ext/ffi_c/libffi/include/Makefile.am +3 -3
  47. data/ext/ffi_c/libffi/include/Makefile.in +188 -71
  48. data/ext/ffi_c/libffi/include/ffi.h.in +107 -50
  49. data/ext/ffi_c/libffi/include/ffi_cfi.h +55 -0
  50. data/ext/ffi_c/libffi/include/ffi_common.h +32 -11
  51. data/ext/ffi_c/libffi/install-sh +190 -202
  52. data/ext/ffi_c/libffi/libffi.map.in +80 -0
  53. data/ext/ffi_c/libffi/libffi.pc.in +3 -2
  54. data/ext/ffi_c/libffi/libffi.xcodeproj/project.pbxproj +637 -0
  55. data/ext/ffi_c/libffi/libtool-ldflags +106 -0
  56. data/ext/ffi_c/libffi/libtool-version +1 -1
  57. data/ext/ffi_c/libffi/ltmain.sh +3553 -2033
  58. data/ext/ffi_c/libffi/m4/asmcfi.m4 +13 -0
  59. data/ext/ffi_c/libffi/m4/ax_append_flag.m4 +69 -0
  60. data/ext/ffi_c/libffi/m4/ax_cc_maxopt.m4 +13 -8
  61. data/ext/ffi_c/libffi/m4/ax_cflags_warn_all.m4 +31 -104
  62. data/ext/ffi_c/libffi/m4/{ax_check_compiler_flags.m4 → ax_check_compile_flag.m4} +30 -34
  63. data/ext/ffi_c/libffi/m4/ax_compiler_vendor.m4 +32 -11
  64. data/ext/ffi_c/libffi/m4/ax_enable_builddir.m4 +6 -5
  65. data/ext/ffi_c/libffi/m4/ax_gcc_archflag.m4 +31 -21
  66. data/ext/ffi_c/libffi/m4/libtool.m4 +1691 -1135
  67. data/ext/ffi_c/libffi/m4/ltoptions.m4 +104 -36
  68. data/ext/ffi_c/libffi/m4/ltsugar.m4 +4 -3
  69. data/ext/ffi_c/libffi/m4/ltversion.m4 +6 -6
  70. data/ext/ffi_c/libffi/m4/lt~obsolete.m4 +4 -3
  71. data/ext/ffi_c/libffi/man/Makefile.am +2 -2
  72. data/ext/ffi_c/libffi/man/Makefile.in +141 -49
  73. data/ext/ffi_c/libffi/man/ffi.3 +10 -0
  74. data/ext/ffi_c/libffi/man/ffi_prep_cif.3 +6 -4
  75. data/ext/ffi_c/libffi/man/ffi_prep_cif_var.3 +73 -0
  76. data/ext/ffi_c/libffi/missing +150 -311
  77. data/ext/ffi_c/libffi/msvcc.sh +72 -9
  78. data/ext/ffi_c/libffi/src/aarch64/ffi.c +941 -0
  79. data/ext/ffi_c/libffi/src/aarch64/ffitarget.h +81 -0
  80. data/ext/ffi_c/libffi/src/aarch64/internal.h +67 -0
  81. data/ext/ffi_c/libffi/src/aarch64/sysv.S +438 -0
  82. data/ext/ffi_c/libffi/src/alpha/ffi.c +335 -98
  83. data/ext/ffi_c/libffi/src/alpha/ffitarget.h +10 -1
  84. data/ext/ffi_c/libffi/src/alpha/internal.h +23 -0
  85. data/ext/ffi_c/libffi/src/alpha/osf.S +161 -266
  86. data/ext/ffi_c/libffi/src/arc/arcompact.S +135 -0
  87. data/ext/ffi_c/libffi/src/arc/ffi.c +266 -0
  88. data/ext/ffi_c/libffi/src/arc/ffitarget.h +53 -0
  89. data/ext/ffi_c/libffi/src/arm/ffi.c +597 -517
  90. data/ext/ffi_c/libffi/src/arm/ffitarget.h +24 -7
  91. data/ext/ffi_c/libffi/src/arm/internal.h +7 -0
  92. data/ext/ffi_c/libffi/src/arm/sysv.S +303 -417
  93. data/ext/ffi_c/libffi/src/avr32/ffitarget.h +6 -1
  94. data/ext/ffi_c/libffi/src/bfin/ffi.c +196 -0
  95. data/ext/ffi_c/libffi/src/bfin/ffitarget.h +43 -0
  96. data/ext/ffi_c/libffi/src/bfin/sysv.S +179 -0
  97. data/ext/ffi_c/libffi/src/closures.c +319 -44
  98. data/ext/ffi_c/libffi/src/cris/ffi.c +10 -7
  99. data/ext/ffi_c/libffi/src/cris/ffitarget.h +6 -1
  100. data/ext/ffi_c/libffi/src/debug.c +6 -1
  101. data/ext/ffi_c/libffi/src/dlmalloc.c +16 -11
  102. data/ext/ffi_c/libffi/src/frv/ffi.c +1 -1
  103. data/ext/ffi_c/libffi/src/frv/ffitarget.h +6 -1
  104. data/ext/ffi_c/libffi/src/ia64/ffi.c +11 -7
  105. data/ext/ffi_c/libffi/src/ia64/ffitarget.h +6 -1
  106. data/ext/ffi_c/libffi/src/java_raw_api.c +23 -5
  107. data/ext/ffi_c/libffi/src/m32r/ffi.c +1 -1
  108. data/ext/ffi_c/libffi/src/m32r/ffitarget.h +6 -1
  109. data/ext/ffi_c/libffi/src/m68k/ffi.c +87 -13
  110. data/ext/ffi_c/libffi/src/m68k/ffitarget.h +6 -1
  111. data/ext/ffi_c/libffi/src/m68k/sysv.S +119 -32
  112. data/ext/ffi_c/libffi/src/m88k/ffi.c +400 -0
  113. data/ext/ffi_c/libffi/src/m88k/ffitarget.h +49 -0
  114. data/ext/ffi_c/libffi/src/m88k/obsd.S +209 -0
  115. data/ext/ffi_c/libffi/src/metag/ffi.c +330 -0
  116. data/ext/ffi_c/libffi/{fficonfig.hw → src/metag/ffitarget.h} +22 -26
  117. data/ext/ffi_c/libffi/src/metag/sysv.S +311 -0
  118. data/ext/ffi_c/libffi/src/microblaze/ffi.c +321 -0
  119. data/ext/ffi_c/libffi/src/microblaze/ffitarget.h +53 -0
  120. data/ext/ffi_c/libffi/src/microblaze/sysv.S +302 -0
  121. data/ext/ffi_c/libffi/src/mips/ffi.c +95 -28
  122. data/ext/ffi_c/libffi/src/mips/ffitarget.h +9 -2
  123. data/ext/ffi_c/libffi/src/mips/n32.S +126 -56
  124. data/ext/ffi_c/libffi/src/mips/o32.S +148 -27
  125. data/ext/ffi_c/libffi/src/moxie/eabi.S +55 -82
  126. data/ext/ffi_c/libffi/src/moxie/ffi.c +40 -44
  127. data/ext/ffi_c/libffi/src/moxie/ffitarget.h +52 -0
  128. data/ext/ffi_c/libffi/src/nios2/ffi.c +304 -0
  129. data/ext/ffi_c/libffi/src/nios2/ffitarget.h +52 -0
  130. data/ext/ffi_c/libffi/src/nios2/sysv.S +136 -0
  131. data/ext/ffi_c/libffi/src/or1k/ffi.c +328 -0
  132. data/ext/ffi_c/libffi/src/or1k/ffitarget.h +58 -0
  133. data/ext/ffi_c/libffi/src/or1k/sysv.S +107 -0
  134. data/ext/ffi_c/libffi/src/pa/ffitarget.h +8 -1
  135. data/ext/ffi_c/libffi/src/powerpc/aix.S +6 -6
  136. data/ext/ffi_c/libffi/src/powerpc/aix_closure.S +3 -1
  137. data/ext/ffi_c/libffi/src/powerpc/asm.h +2 -2
  138. data/ext/ffi_c/libffi/src/powerpc/darwin.S +2 -7
  139. data/ext/ffi_c/libffi/src/powerpc/darwin_closure.S +22 -26
  140. data/ext/ffi_c/libffi/src/powerpc/ffi.c +103 -1378
  141. data/ext/ffi_c/libffi/src/powerpc/ffi_darwin.c +25 -25
  142. data/ext/ffi_c/libffi/src/powerpc/ffi_linux64.c +945 -0
  143. data/ext/ffi_c/libffi/src/powerpc/ffi_powerpc.h +94 -0
  144. data/ext/ffi_c/libffi/src/powerpc/ffi_sysv.c +923 -0
  145. data/ext/ffi_c/libffi/src/powerpc/ffitarget.h +100 -44
  146. data/ext/ffi_c/libffi/src/powerpc/linux64.S +100 -59
  147. data/ext/ffi_c/libffi/src/powerpc/linux64_closure.S +360 -108
  148. data/ext/ffi_c/libffi/src/powerpc/ppc_closure.S +138 -68
  149. data/ext/ffi_c/libffi/src/powerpc/sysv.S +68 -112
  150. data/ext/ffi_c/libffi/src/prep_cif.c +108 -24
  151. data/ext/ffi_c/libffi/src/raw_api.c +18 -5
  152. data/ext/ffi_c/libffi/src/s390/ffi.c +294 -318
  153. data/ext/ffi_c/libffi/src/s390/ffitarget.h +9 -1
  154. data/ext/ffi_c/libffi/src/s390/internal.h +11 -0
  155. data/ext/ffi_c/libffi/src/s390/sysv.S +257 -366
  156. data/ext/ffi_c/libffi/src/sh/ffi.c +4 -3
  157. data/ext/ffi_c/libffi/src/sh/ffitarget.h +6 -1
  158. data/ext/ffi_c/libffi/src/sh64/ffi.c +3 -2
  159. data/ext/ffi_c/libffi/src/sh64/ffitarget.h +6 -1
  160. data/ext/ffi_c/libffi/src/sparc/ffi.c +326 -527
  161. data/ext/ffi_c/libffi/src/sparc/ffi64.c +608 -0
  162. data/ext/ffi_c/libffi/src/sparc/ffitarget.h +20 -7
  163. data/ext/ffi_c/libffi/src/sparc/internal.h +26 -0
  164. data/ext/ffi_c/libffi/src/sparc/v8.S +364 -234
  165. data/ext/ffi_c/libffi/src/sparc/v9.S +340 -207
  166. data/ext/ffi_c/libffi/src/tile/ffi.c +355 -0
  167. data/ext/ffi_c/libffi/src/tile/ffitarget.h +65 -0
  168. data/ext/ffi_c/libffi/src/tile/tile.S +360 -0
  169. data/ext/ffi_c/libffi/src/types.c +43 -14
  170. data/ext/ffi_c/libffi/src/vax/elfbsd.S +195 -0
  171. data/ext/ffi_c/libffi/src/vax/ffi.c +276 -0
  172. data/ext/ffi_c/libffi/src/vax/ffitarget.h +49 -0
  173. data/ext/ffi_c/libffi/src/x86/asmnames.h +30 -0
  174. data/ext/ffi_c/libffi/src/x86/ffi.c +589 -500
  175. data/ext/ffi_c/libffi/src/x86/ffi64.c +338 -116
  176. data/ext/ffi_c/libffi/src/x86/ffitarget.h +55 -35
  177. data/ext/ffi_c/libffi/src/x86/ffiw64.c +287 -0
  178. data/ext/ffi_c/libffi/src/x86/internal.h +29 -0
  179. data/ext/ffi_c/libffi/src/x86/internal64.h +22 -0
  180. data/ext/ffi_c/libffi/src/x86/sysv.S +975 -400
  181. data/ext/ffi_c/libffi/src/x86/unix64.S +398 -299
  182. data/ext/ffi_c/libffi/src/x86/win64.S +222 -458
  183. data/ext/ffi_c/libffi/src/x86/win64_intel.S +237 -0
  184. data/ext/ffi_c/libffi/src/xtensa/ffi.c +298 -0
  185. data/ext/ffi_c/libffi/src/xtensa/ffitarget.h +53 -0
  186. data/ext/ffi_c/libffi/src/xtensa/sysv.S +253 -0
  187. data/ext/ffi_c/libffi/stamp-h.in +1 -0
  188. data/ext/ffi_c/libffi/testsuite/Makefile.am +78 -73
  189. data/ext/ffi_c/libffi/testsuite/Makefile.in +218 -111
  190. data/ext/ffi_c/libffi/testsuite/lib/libffi.exp +120 -25
  191. data/ext/ffi_c/libffi/testsuite/lib/target-libpath.exp +21 -1
  192. data/ext/ffi_c/libffi/testsuite/libffi.call/align_mixed.c +46 -0
  193. data/ext/ffi_c/libffi/testsuite/libffi.call/call.exp +4 -6
  194. data/ext/ffi_c/libffi/testsuite/libffi.call/{closure_stdcall.c → closure_simple.c} +7 -16
  195. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_12byte.c +4 -4
  196. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_16byte.c +4 -4
  197. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_18byte.c +4 -4
  198. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_19byte.c +4 -4
  199. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_1_1byte.c +4 -4
  200. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_20byte.c +4 -4
  201. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_20byte1.c +4 -4
  202. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_24byte.c +5 -5
  203. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_2byte.c +4 -4
  204. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_3_1byte.c +4 -4
  205. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_3byte1.c +4 -4
  206. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_3byte2.c +4 -4
  207. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_4_1byte.c +4 -4
  208. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_4byte.c +4 -4
  209. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_5_1_byte.c +4 -4
  210. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_5byte.c +4 -4
  211. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_64byte.c +5 -5
  212. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_6_1_byte.c +4 -4
  213. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_6byte.c +4 -4
  214. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_7_1_byte.c +4 -4
  215. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_7byte.c +4 -4
  216. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_8byte.c +4 -4
  217. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_9byte1.c +4 -4
  218. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_9byte2.c +4 -4
  219. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_double.c +4 -4
  220. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_float.c +4 -4
  221. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_longdouble.c +4 -4
  222. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_longdouble_split.c +4 -6
  223. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_longdouble_split2.c +4 -6
  224. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_pointer.c +4 -4
  225. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_sint16.c +4 -4
  226. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_sint32.c +4 -4
  227. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_sint64.c +4 -4
  228. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_uint16.c +4 -4
  229. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_uint32.c +4 -4
  230. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_uint64.c +4 -4
  231. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_dbls_struct.c +4 -4
  232. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_double_va.c +10 -9
  233. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_longdouble.c +3 -3
  234. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_longdouble_va.c +10 -9
  235. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_many_mixed_args.c +70 -0
  236. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_many_mixed_float_double.c +55 -0
  237. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_pointer.c +1 -1
  238. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_pointer_stack.c +11 -9
  239. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_struct_va1.c +114 -0
  240. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_uchar_va.c +44 -0
  241. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_uint_va.c +45 -0
  242. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_ulong_va.c +45 -0
  243. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_ulonglong.c +5 -5
  244. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_ushort_va.c +44 -0
  245. data/ext/ffi_c/libffi/testsuite/libffi.call/err_bad_typedef.c +2 -2
  246. data/ext/ffi_c/libffi/testsuite/libffi.call/ffitest.h +23 -40
  247. data/ext/ffi_c/libffi/testsuite/libffi.call/float1.c +3 -1
  248. data/ext/ffi_c/libffi/testsuite/libffi.call/float2.c +6 -4
  249. data/ext/ffi_c/libffi/testsuite/libffi.call/float3.c +4 -2
  250. data/ext/ffi_c/libffi/testsuite/libffi.call/float_va.c +107 -0
  251. data/ext/ffi_c/libffi/testsuite/libffi.call/huge_struct.c +18 -19
  252. data/ext/ffi_c/libffi/testsuite/libffi.call/many.c +6 -16
  253. data/ext/ffi_c/libffi/testsuite/libffi.call/many2.c +57 -0
  254. data/ext/ffi_c/libffi/testsuite/libffi.call/many_double.c +70 -0
  255. data/ext/ffi_c/libffi/testsuite/libffi.call/many_mixed.c +78 -0
  256. data/ext/ffi_c/libffi/testsuite/libffi.call/negint.c +0 -1
  257. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct.c +6 -6
  258. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct1.c +8 -8
  259. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct10.c +6 -6
  260. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct11.c +121 -0
  261. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct2.c +5 -5
  262. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct3.c +5 -5
  263. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct4.c +5 -5
  264. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct5.c +5 -5
  265. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct6.c +6 -6
  266. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct7.c +5 -5
  267. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct8.c +6 -6
  268. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct9.c +6 -6
  269. data/ext/ffi_c/libffi/testsuite/libffi.call/offsets.c +46 -0
  270. data/ext/ffi_c/libffi/testsuite/libffi.call/pr1172638.c +127 -0
  271. data/ext/ffi_c/libffi/testsuite/libffi.call/return_dbl.c +1 -0
  272. data/ext/ffi_c/libffi/testsuite/libffi.call/return_ldl.c +1 -1
  273. data/ext/ffi_c/libffi/testsuite/libffi.call/return_sc.c +1 -1
  274. data/ext/ffi_c/libffi/testsuite/libffi.call/return_uc.c +1 -1
  275. data/ext/ffi_c/libffi/testsuite/libffi.call/stret_large.c +7 -7
  276. data/ext/ffi_c/libffi/testsuite/libffi.call/stret_large2.c +7 -7
  277. data/ext/ffi_c/libffi/testsuite/libffi.call/stret_medium.c +5 -5
  278. data/ext/ffi_c/libffi/testsuite/libffi.call/stret_medium2.c +5 -5
  279. data/ext/ffi_c/libffi/testsuite/libffi.call/strlen.c +2 -2
  280. data/ext/ffi_c/libffi/testsuite/libffi.call/strlen2.c +49 -0
  281. data/ext/ffi_c/libffi/testsuite/libffi.call/strlen3.c +49 -0
  282. data/ext/ffi_c/libffi/testsuite/libffi.call/strlen4.c +55 -0
  283. data/ext/ffi_c/libffi/testsuite/libffi.call/struct1.c +9 -7
  284. data/ext/ffi_c/libffi/testsuite/libffi.call/struct2.c +7 -7
  285. data/ext/ffi_c/libffi/testsuite/libffi.call/struct3.c +7 -6
  286. data/ext/ffi_c/libffi/testsuite/libffi.call/struct4.c +9 -8
  287. data/ext/ffi_c/libffi/testsuite/libffi.call/struct5.c +9 -8
  288. data/ext/ffi_c/libffi/testsuite/libffi.call/struct6.c +9 -9
  289. data/ext/ffi_c/libffi/testsuite/libffi.call/struct7.c +9 -9
  290. data/ext/ffi_c/libffi/testsuite/libffi.call/struct8.c +9 -8
  291. data/ext/ffi_c/libffi/testsuite/libffi.call/struct9.c +9 -8
  292. data/ext/ffi_c/libffi/testsuite/libffi.call/testclosure.c +2 -2
  293. data/ext/ffi_c/libffi/testsuite/libffi.call/uninitialized.c +61 -0
  294. data/ext/ffi_c/libffi/testsuite/{libffi.special → libffi.call}/unwindtest.cc +3 -10
  295. data/ext/ffi_c/libffi/testsuite/{libffi.special → libffi.call}/unwindtest_ffi_call.cc +2 -1
  296. data/ext/ffi_c/libffi/testsuite/libffi.call/va_1.c +196 -0
  297. data/ext/ffi_c/libffi/testsuite/libffi.call/va_struct1.c +121 -0
  298. data/ext/ffi_c/libffi/testsuite/libffi.call/va_struct2.c +123 -0
  299. data/ext/ffi_c/libffi/testsuite/libffi.call/va_struct3.c +125 -0
  300. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_align_complex.inc +91 -0
  301. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_align_complex_double.c +10 -0
  302. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_align_complex_float.c +10 -0
  303. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_align_complex_longdouble.c +10 -0
  304. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex.inc +42 -0
  305. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_double.c +10 -0
  306. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_float.c +10 -0
  307. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_longdouble.c +10 -0
  308. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_struct.inc +71 -0
  309. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_struct_double.c +10 -0
  310. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_struct_float.c +10 -0
  311. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_struct_longdouble.c +10 -0
  312. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_va.inc +80 -0
  313. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_va_double.c +10 -0
  314. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_va_float.c +16 -0
  315. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_va_longdouble.c +10 -0
  316. data/ext/ffi_c/libffi/testsuite/{libffi.special/special.exp → libffi.complex/complex.exp} +9 -8
  317. data/ext/ffi_c/libffi/testsuite/libffi.complex/complex.inc +51 -0
  318. data/ext/ffi_c/libffi/testsuite/libffi.complex/complex_defs_double.inc +7 -0
  319. data/ext/ffi_c/libffi/testsuite/libffi.complex/complex_defs_float.inc +7 -0
  320. data/ext/ffi_c/libffi/testsuite/libffi.complex/complex_defs_longdouble.inc +7 -0
  321. data/ext/ffi_c/libffi/testsuite/libffi.complex/complex_double.c +10 -0
  322. data/ext/ffi_c/libffi/testsuite/libffi.complex/complex_float.c +10 -0
  323. data/ext/ffi_c/libffi/testsuite/libffi.complex/complex_int.c +86 -0
  324. data/ext/ffi_c/libffi/testsuite/libffi.complex/complex_longdouble.c +10 -0
  325. data/ext/ffi_c/libffi/testsuite/libffi.complex/ffitest.h +1 -0
  326. data/ext/ffi_c/libffi/testsuite/libffi.complex/many_complex.inc +78 -0
  327. data/ext/ffi_c/libffi/testsuite/libffi.complex/many_complex_double.c +10 -0
  328. data/ext/ffi_c/libffi/testsuite/libffi.complex/many_complex_float.c +10 -0
  329. data/ext/ffi_c/libffi/testsuite/libffi.complex/many_complex_longdouble.c +10 -0
  330. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex.inc +37 -0
  331. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex1.inc +41 -0
  332. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex1_double.c +10 -0
  333. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex1_float.c +10 -0
  334. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex1_longdouble.c +10 -0
  335. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex2.inc +44 -0
  336. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex2_double.c +10 -0
  337. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex2_float.c +10 -0
  338. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex2_longdouble.c +10 -0
  339. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex_double.c +10 -0
  340. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex_float.c +10 -0
  341. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex_longdouble.c +10 -0
  342. data/ext/ffi_c/libffi/testsuite/libffi.go/aa-direct.c +34 -0
  343. data/ext/ffi_c/libffi/testsuite/libffi.go/closure1.c +28 -0
  344. data/ext/ffi_c/libffi/testsuite/libffi.go/ffitest.h +1 -0
  345. data/ext/ffi_c/libffi/testsuite/libffi.go/go.exp +36 -0
  346. data/ext/ffi_c/libffi/testsuite/libffi.go/static-chain.h +19 -0
  347. data/ffi.gemspec +2 -2
  348. data/lib/2.0/ffi_c.so +0 -0
  349. data/lib/2.1/ffi_c.so +0 -0
  350. data/lib/2.2/ffi_c.so +0 -0
  351. data/lib/2.3/ffi_c.so +0 -0
  352. data/lib/2.4/ffi_c.so +0 -0
  353. data/lib/2.5/ffi_c.so +0 -0
  354. data/lib/ffi/enum.rb +124 -0
  355. data/lib/ffi/library.rb +65 -13
  356. data/lib/ffi/platform.rb +7 -2
  357. data/lib/ffi/platform/sparc64-linux/types.conf +102 -0
  358. data/lib/ffi/platform/x86_64-windows/types.conf +113 -20
  359. data/lib/ffi/pointer.rb +1 -0
  360. data/lib/ffi/struct.rb +0 -2
  361. data/lib/ffi/version.rb +1 -1
  362. data/spec/ffi/bitmask_spec.rb +575 -0
  363. data/spec/ffi/embed-test/ext/Makefile +242 -0
  364. data/spec/ffi/fixtures/BitmaskTest.c +51 -0
  365. data/spec/ffi/rbx/memory_pointer_spec.rb +4 -0
  366. data/spec/ffi/struct_spec.rb +0 -4
  367. metadata +158 -32
  368. data/ext/ffi_c/libffi/Makefile.vc +0 -141
  369. data/ext/ffi_c/libffi/Makefile.vc64 +0 -141
  370. data/ext/ffi_c/libffi/build-ios.sh +0 -67
  371. data/ext/ffi_c/libffi/doc/libffi.info +0 -593
  372. data/ext/ffi_c/libffi/doc/stamp-vti +0 -4
  373. data/ext/ffi_c/libffi/include/ffi.h.vc +0 -427
  374. data/ext/ffi_c/libffi/include/ffi.h.vc64 +0 -427
  375. data/ext/ffi_c/libffi/src/arm/gentramp.sh +0 -118
  376. data/ext/ffi_c/libffi/src/arm/trampoline.S +0 -4450
  377. data/ext/ffi_c/libffi/src/x86/darwin.S +0 -444
  378. data/ext/ffi_c/libffi/src/x86/darwin64.S +0 -416
  379. data/ext/ffi_c/libffi/src/x86/freebsd.S +0 -458
  380. data/ext/ffi_c/libffi/src/x86/win32.S +0 -1065
  381. data/ext/ffi_c/libffi/testsuite/lib/libffi-dg.exp +0 -300
  382. data/ext/ffi_c/libffi/testsuite/libffi.call/many_win32.c +0 -63
  383. data/ext/ffi_c/libffi/testsuite/libffi.call/strlen_win32.c +0 -44
  384. data/ext/ffi_c/libffi/testsuite/libffi.special/ffitestcxx.h +0 -96
@@ -255,7 +255,7 @@ ffi_prep_args (extended_cif *ecif, unsigned long *const stack)
255
255
  case FFI_TYPE_STRUCT:
256
256
  size_al = (*ptr)->size;
257
257
  #if defined(POWERPC_DARWIN64)
258
- next_arg = (unsigned long *)ALIGN((char *)next_arg, (*ptr)->alignment);
258
+ next_arg = (unsigned long *)FFI_ALIGN((char *)next_arg, (*ptr)->alignment);
259
259
  darwin64_pass_struct_by_value (*ptr, (char *) *p_argv,
260
260
  (unsigned) size_al,
261
261
  (unsigned int *) &fparg_count,
@@ -266,7 +266,7 @@ ffi_prep_args (extended_cif *ecif, unsigned long *const stack)
266
266
  /* If the first member of the struct is a double, then include enough
267
267
  padding in the struct size to align it to double-word. */
268
268
  if ((*ptr)->elements[0]->type == FFI_TYPE_DOUBLE)
269
- size_al = ALIGN((*ptr)->size, 8);
269
+ size_al = FFI_ALIGN((*ptr)->size, 8);
270
270
 
271
271
  # if defined(POWERPC64)
272
272
  FFI_ASSERT (abi != FFI_DARWIN);
@@ -302,10 +302,10 @@ ffi_prep_args (extended_cif *ecif, unsigned long *const stack)
302
302
  }
303
303
 
304
304
  /* Check that we didn't overrun the stack... */
305
- //FFI_ASSERT(gpr_base <= stacktop - ASM_NEEDS_REGISTERS);
306
- //FFI_ASSERT((unsigned *)fpr_base
307
- // <= stacktop - ASM_NEEDS_REGISTERS - NUM_GPR_ARG_REGISTERS);
308
- //FFI_ASSERT(flags & FLAG_4_GPR_ARGUMENTS || intarg_count <= 4);
305
+ /* FFI_ASSERT(gpr_base <= stacktop - ASM_NEEDS_REGISTERS);
306
+ FFI_ASSERT((unsigned *)fpr_base
307
+ <= stacktop - ASM_NEEDS_REGISTERS - NUM_GPR_ARG_REGISTERS);
308
+ FFI_ASSERT(flags & FLAG_4_GPR_ARGUMENTS || intarg_count <= 4); */
309
309
  }
310
310
 
311
311
  #if defined(POWERPC_DARWIN64)
@@ -352,7 +352,7 @@ darwin64_struct_size_exceeds_gprs_p (ffi_type *s, char *src, unsigned *nfpr)
352
352
  ffi_type *p = s->elements[i];
353
353
  /* Find the start of this item (0 for the first one). */
354
354
  if (i > 0)
355
- struct_offset = ALIGN(struct_offset, p->alignment);
355
+ struct_offset = FFI_ALIGN(struct_offset, p->alignment);
356
356
 
357
357
  item_base = src + struct_offset;
358
358
 
@@ -436,7 +436,7 @@ darwin64_pass_struct_floats (ffi_type *s, char *src,
436
436
  ffi_type *p = s->elements[i];
437
437
  /* Find the start of this item (0 for the first one). */
438
438
  if (i > 0)
439
- struct_offset = ALIGN(struct_offset, p->alignment);
439
+ struct_offset = FFI_ALIGN(struct_offset, p->alignment);
440
440
  item_base = src + struct_offset;
441
441
 
442
442
  switch (p->type)
@@ -527,7 +527,7 @@ darwin64_struct_floats_to_mem (ffi_type *s, char *dest, double *fprs, unsigned *
527
527
  ffi_type *p = s->elements[i];
528
528
  /* Find the start of this item (0 for the first one). */
529
529
  if (i > 0)
530
- struct_offset = ALIGN(struct_offset, p->alignment);
530
+ struct_offset = FFI_ALIGN(struct_offset, p->alignment);
531
531
  item_base = dest + struct_offset;
532
532
 
533
533
  switch (p->type)
@@ -593,7 +593,7 @@ darwin_adjust_aggregate_sizes (ffi_type *s)
593
593
  /* Natural alignment for all items. */
594
594
  align = p->alignment;
595
595
  #else
596
- /* Natrual alignment for the first item... */
596
+ /* Natural alignment for the first item... */
597
597
  if (i == 0)
598
598
  align = p->alignment;
599
599
  else if (p->alignment == 16 || p->alignment < 4)
@@ -604,10 +604,10 @@ darwin_adjust_aggregate_sizes (ffi_type *s)
604
604
  align = 4;
605
605
  #endif
606
606
  /* Pad, if necessary, before adding the current item. */
607
- s->size = ALIGN(s->size, align) + p->size;
607
+ s->size = FFI_ALIGN(s->size, align) + p->size;
608
608
  }
609
609
 
610
- s->size = ALIGN(s->size, s->alignment);
610
+ s->size = FFI_ALIGN(s->size, s->alignment);
611
611
 
612
612
  /* This should not be necessary on m64, but harmless. */
613
613
  if (s->elements[0]->type == FFI_TYPE_UINT64
@@ -640,10 +640,10 @@ aix_adjust_aggregate_sizes (ffi_type *s)
640
640
  align = p->alignment;
641
641
  if (i != 0 && p->type == FFI_TYPE_DOUBLE)
642
642
  align = 4;
643
- s->size = ALIGN(s->size, align) + p->size;
643
+ s->size = FFI_ALIGN(s->size, align) + p->size;
644
644
  }
645
645
 
646
- s->size = ALIGN(s->size, s->alignment);
646
+ s->size = FFI_ALIGN(s->size, s->alignment);
647
647
 
648
648
  if (s->elements[0]->type == FFI_TYPE_UINT64
649
649
  || s->elements[0]->type == FFI_TYPE_SINT64
@@ -809,9 +809,9 @@ ffi_prep_cif_machdep (ffi_cif *cif)
809
809
  16-byte-aligned. */
810
810
  if (fparg_count >= NUM_FPR_ARG_REGISTERS)
811
811
  #if defined (POWERPC64)
812
- intarg_count = ALIGN(intarg_count, 2);
812
+ intarg_count = FFI_ALIGN(intarg_count, 2);
813
813
  #else
814
- intarg_count = ALIGN(intarg_count, 4);
814
+ intarg_count = FFI_ALIGN(intarg_count, 4);
815
815
  #endif
816
816
  break;
817
817
  #endif
@@ -838,7 +838,7 @@ ffi_prep_cif_machdep (ffi_cif *cif)
838
838
  #if defined(POWERPC_DARWIN64)
839
839
  align_words = (*ptr)->alignment >> 3;
840
840
  if (align_words)
841
- intarg_count = ALIGN(intarg_count, align_words);
841
+ intarg_count = FFI_ALIGN(intarg_count, align_words);
842
842
  /* Base size of the struct. */
843
843
  intarg_count += (size_al + 7) / 8;
844
844
  /* If 16 bytes then don't worry about floats. */
@@ -848,11 +848,11 @@ ffi_prep_cif_machdep (ffi_cif *cif)
848
848
  #else
849
849
  align_words = (*ptr)->alignment >> 2;
850
850
  if (align_words)
851
- intarg_count = ALIGN(intarg_count, align_words);
851
+ intarg_count = FFI_ALIGN(intarg_count, align_words);
852
852
  /* If the first member of the struct is a double, then align
853
853
  the struct to double-word.
854
854
  if ((*ptr)->elements[0]->type == FFI_TYPE_DOUBLE)
855
- size_al = ALIGN((*ptr)->size, 8); */
855
+ size_al = FFI_ALIGN((*ptr)->size, 8); */
856
856
  # ifdef POWERPC64
857
857
  intarg_count += (size_al + 7) / 8;
858
858
  # else
@@ -897,7 +897,7 @@ ffi_prep_cif_machdep (ffi_cif *cif)
897
897
  bytes += NUM_GPR_ARG_REGISTERS * sizeof(long);
898
898
 
899
899
  /* The stack space allocated needs to be a multiple of 16 bytes. */
900
- bytes = ALIGN(bytes, 16) ;
900
+ bytes = FFI_ALIGN(bytes, 16) ;
901
901
 
902
902
  cif->flags = flags;
903
903
  cif->bytes = bytes;
@@ -1065,10 +1065,10 @@ ffi_prep_closure_loc (ffi_closure* closure,
1065
1065
  closure->cif = cif;
1066
1066
  closure->fun = fun;
1067
1067
  closure->user_data = user_data;
1068
+ break;
1068
1069
 
1069
1070
  default:
1070
-
1071
- FFI_ASSERT(0);
1071
+ return FFI_BAD_ABI;
1072
1072
  break;
1073
1073
  }
1074
1074
  return FFI_OK;
@@ -1208,7 +1208,7 @@ ffi_closure_helper_DARWIN (ffi_closure *closure, void *rvalue,
1208
1208
  case FFI_TYPE_STRUCT:
1209
1209
  size_al = arg_types[i]->size;
1210
1210
  #if defined(POWERPC_DARWIN64)
1211
- pgr = (unsigned long *)ALIGN((char *)pgr, arg_types[i]->alignment);
1211
+ pgr = (unsigned long *)FFI_ALIGN((char *)pgr, arg_types[i]->alignment);
1212
1212
  if (size_al < 3 || size_al == 4)
1213
1213
  {
1214
1214
  avalue[i] = ((char *)pgr)+8-size_al;
@@ -1233,9 +1233,9 @@ ffi_closure_helper_DARWIN (ffi_closure *closure, void *rvalue,
1233
1233
  /* If the first member of the struct is a double, then align
1234
1234
  the struct to double-word. */
1235
1235
  if (arg_types[i]->elements[0]->type == FFI_TYPE_DOUBLE)
1236
- size_al = ALIGN(arg_types[i]->size, 8);
1236
+ size_al = FFI_ALIGN(arg_types[i]->size, 8);
1237
1237
  # if defined(POWERPC64)
1238
- FFI_ASSERT (cif->abi != FFI_DARWIN)
1238
+ FFI_ASSERT (cif->abi != FFI_DARWIN);
1239
1239
  avalue[i] = pgr;
1240
1240
  pgr += (size_al + 7) / 8;
1241
1241
  # else
@@ -0,0 +1,945 @@
1
+ /* -----------------------------------------------------------------------
2
+ ffi_linux64.c - Copyright (C) 2013 IBM
3
+ Copyright (C) 2011 Anthony Green
4
+ Copyright (C) 2011 Kyle Moffett
5
+ Copyright (C) 2008 Red Hat, Inc
6
+ Copyright (C) 2007, 2008 Free Software Foundation, Inc
7
+ Copyright (c) 1998 Geoffrey Keating
8
+
9
+ PowerPC Foreign Function Interface
10
+
11
+ Permission is hereby granted, free of charge, to any person obtaining
12
+ a copy of this software and associated documentation files (the
13
+ ``Software''), to deal in the Software without restriction, including
14
+ without limitation the rights to use, copy, modify, merge, publish,
15
+ distribute, sublicense, and/or sell copies of the Software, and to
16
+ permit persons to whom the Software is furnished to do so, subject to
17
+ the following conditions:
18
+
19
+ The above copyright notice and this permission notice shall be included
20
+ in all copies or substantial portions of the Software.
21
+
22
+ THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
23
+ OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
25
+ IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR
26
+ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
27
+ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
28
+ OTHER DEALINGS IN THE SOFTWARE.
29
+ ----------------------------------------------------------------------- */
30
+
31
+ #include "ffi.h"
32
+
33
+ #ifdef POWERPC64
34
+ #include "ffi_common.h"
35
+ #include "ffi_powerpc.h"
36
+
37
+
38
+ /* About the LINUX64 ABI. */
39
+ enum {
40
+ NUM_GPR_ARG_REGISTERS64 = 8,
41
+ NUM_FPR_ARG_REGISTERS64 = 13
42
+ };
43
+ enum { ASM_NEEDS_REGISTERS64 = 4 };
44
+
45
+
46
+ #if HAVE_LONG_DOUBLE_VARIANT && FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
47
+ /* Adjust size of ffi_type_longdouble. */
48
+ void FFI_HIDDEN
49
+ ffi_prep_types_linux64 (ffi_abi abi)
50
+ {
51
+ if ((abi & (FFI_LINUX | FFI_LINUX_LONG_DOUBLE_128)) == FFI_LINUX)
52
+ {
53
+ ffi_type_longdouble.size = 8;
54
+ ffi_type_longdouble.alignment = 8;
55
+ }
56
+ else
57
+ {
58
+ ffi_type_longdouble.size = 16;
59
+ ffi_type_longdouble.alignment = 16;
60
+ }
61
+ }
62
+ #endif
63
+
64
+
65
+ #if _CALL_ELF == 2
66
+ static unsigned int
67
+ discover_homogeneous_aggregate (const ffi_type *t, unsigned int *elnum)
68
+ {
69
+ switch (t->type)
70
+ {
71
+ case FFI_TYPE_FLOAT:
72
+ case FFI_TYPE_DOUBLE:
73
+ *elnum = 1;
74
+ return (int) t->type;
75
+
76
+ case FFI_TYPE_STRUCT:;
77
+ {
78
+ unsigned int base_elt = 0, total_elnum = 0;
79
+ ffi_type **el = t->elements;
80
+ while (*el)
81
+ {
82
+ unsigned int el_elt, el_elnum = 0;
83
+ el_elt = discover_homogeneous_aggregate (*el, &el_elnum);
84
+ if (el_elt == 0
85
+ || (base_elt && base_elt != el_elt))
86
+ return 0;
87
+ base_elt = el_elt;
88
+ total_elnum += el_elnum;
89
+ if (total_elnum > 8)
90
+ return 0;
91
+ el++;
92
+ }
93
+ *elnum = total_elnum;
94
+ return base_elt;
95
+ }
96
+
97
+ default:
98
+ return 0;
99
+ }
100
+ }
101
+ #endif
102
+
103
+
104
+ /* Perform machine dependent cif processing */
105
+ static ffi_status
106
+ ffi_prep_cif_linux64_core (ffi_cif *cif)
107
+ {
108
+ ffi_type **ptr;
109
+ unsigned bytes;
110
+ unsigned i, fparg_count = 0, intarg_count = 0;
111
+ unsigned flags = cif->flags;
112
+ #if _CALL_ELF == 2
113
+ unsigned int elt, elnum;
114
+ #endif
115
+
116
+ #if FFI_TYPE_LONGDOUBLE == FFI_TYPE_DOUBLE
117
+ /* If compiled without long double support.. */
118
+ if ((cif->abi & FFI_LINUX_LONG_DOUBLE_128) != 0)
119
+ return FFI_BAD_ABI;
120
+ #endif
121
+
122
+ /* The machine-independent calculation of cif->bytes doesn't work
123
+ for us. Redo the calculation. */
124
+ #if _CALL_ELF == 2
125
+ /* Space for backchain, CR, LR, TOC and the asm's temp regs. */
126
+ bytes = (4 + ASM_NEEDS_REGISTERS64) * sizeof (long);
127
+
128
+ /* Space for the general registers. */
129
+ bytes += NUM_GPR_ARG_REGISTERS64 * sizeof (long);
130
+ #else
131
+ /* Space for backchain, CR, LR, cc/ld doubleword, TOC and the asm's temp
132
+ regs. */
133
+ bytes = (6 + ASM_NEEDS_REGISTERS64) * sizeof (long);
134
+
135
+ /* Space for the mandatory parm save area and general registers. */
136
+ bytes += 2 * NUM_GPR_ARG_REGISTERS64 * sizeof (long);
137
+ #endif
138
+
139
+ /* Return value handling. */
140
+ switch (cif->rtype->type)
141
+ {
142
+ #if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
143
+ case FFI_TYPE_LONGDOUBLE:
144
+ if ((cif->abi & FFI_LINUX_LONG_DOUBLE_128) != 0)
145
+ flags |= FLAG_RETURNS_128BITS;
146
+ /* Fall through. */
147
+ #endif
148
+ case FFI_TYPE_DOUBLE:
149
+ flags |= FLAG_RETURNS_64BITS;
150
+ /* Fall through. */
151
+ case FFI_TYPE_FLOAT:
152
+ flags |= FLAG_RETURNS_FP;
153
+ break;
154
+
155
+ case FFI_TYPE_UINT128:
156
+ flags |= FLAG_RETURNS_128BITS;
157
+ /* Fall through. */
158
+ case FFI_TYPE_UINT64:
159
+ case FFI_TYPE_SINT64:
160
+ flags |= FLAG_RETURNS_64BITS;
161
+ break;
162
+
163
+ case FFI_TYPE_STRUCT:
164
+ #if _CALL_ELF == 2
165
+ elt = discover_homogeneous_aggregate (cif->rtype, &elnum);
166
+ if (elt)
167
+ {
168
+ if (elt == FFI_TYPE_DOUBLE)
169
+ flags |= FLAG_RETURNS_64BITS;
170
+ flags |= FLAG_RETURNS_FP | FLAG_RETURNS_SMST;
171
+ break;
172
+ }
173
+ if (cif->rtype->size <= 16)
174
+ {
175
+ flags |= FLAG_RETURNS_SMST;
176
+ break;
177
+ }
178
+ #endif
179
+ intarg_count++;
180
+ flags |= FLAG_RETVAL_REFERENCE;
181
+ /* Fall through. */
182
+ case FFI_TYPE_VOID:
183
+ flags |= FLAG_RETURNS_NOTHING;
184
+ break;
185
+
186
+ default:
187
+ /* Returns 32-bit integer, or similar. Nothing to do here. */
188
+ break;
189
+ }
190
+
191
+ for (ptr = cif->arg_types, i = cif->nargs; i > 0; i--, ptr++)
192
+ {
193
+ unsigned int align;
194
+
195
+ switch ((*ptr)->type)
196
+ {
197
+ #if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
198
+ case FFI_TYPE_LONGDOUBLE:
199
+ if ((cif->abi & FFI_LINUX_LONG_DOUBLE_128) != 0)
200
+ {
201
+ fparg_count++;
202
+ intarg_count++;
203
+ }
204
+ /* Fall through. */
205
+ #endif
206
+ case FFI_TYPE_DOUBLE:
207
+ case FFI_TYPE_FLOAT:
208
+ fparg_count++;
209
+ intarg_count++;
210
+ if (fparg_count > NUM_FPR_ARG_REGISTERS64)
211
+ flags |= FLAG_ARG_NEEDS_PSAVE;
212
+ break;
213
+
214
+ case FFI_TYPE_STRUCT:
215
+ if ((cif->abi & FFI_LINUX_STRUCT_ALIGN) != 0)
216
+ {
217
+ align = (*ptr)->alignment;
218
+ if (align > 16)
219
+ align = 16;
220
+ align = align / 8;
221
+ if (align > 1)
222
+ intarg_count = FFI_ALIGN (intarg_count, align);
223
+ }
224
+ intarg_count += ((*ptr)->size + 7) / 8;
225
+ #if _CALL_ELF == 2
226
+ elt = discover_homogeneous_aggregate (*ptr, &elnum);
227
+ if (elt)
228
+ {
229
+ fparg_count += elnum;
230
+ if (fparg_count > NUM_FPR_ARG_REGISTERS64)
231
+ flags |= FLAG_ARG_NEEDS_PSAVE;
232
+ }
233
+ else
234
+ #endif
235
+ {
236
+ if (intarg_count > NUM_GPR_ARG_REGISTERS64)
237
+ flags |= FLAG_ARG_NEEDS_PSAVE;
238
+ }
239
+ break;
240
+
241
+ case FFI_TYPE_POINTER:
242
+ case FFI_TYPE_UINT64:
243
+ case FFI_TYPE_SINT64:
244
+ case FFI_TYPE_INT:
245
+ case FFI_TYPE_UINT32:
246
+ case FFI_TYPE_SINT32:
247
+ case FFI_TYPE_UINT16:
248
+ case FFI_TYPE_SINT16:
249
+ case FFI_TYPE_UINT8:
250
+ case FFI_TYPE_SINT8:
251
+ /* Everything else is passed as a 8-byte word in a GPR, either
252
+ the object itself or a pointer to it. */
253
+ intarg_count++;
254
+ if (intarg_count > NUM_GPR_ARG_REGISTERS64)
255
+ flags |= FLAG_ARG_NEEDS_PSAVE;
256
+ break;
257
+ default:
258
+ FFI_ASSERT (0);
259
+ }
260
+ }
261
+
262
+ if (fparg_count != 0)
263
+ flags |= FLAG_FP_ARGUMENTS;
264
+ if (intarg_count > 4)
265
+ flags |= FLAG_4_GPR_ARGUMENTS;
266
+
267
+ /* Space for the FPR registers, if needed. */
268
+ if (fparg_count != 0)
269
+ bytes += NUM_FPR_ARG_REGISTERS64 * sizeof (double);
270
+
271
+ /* Stack space. */
272
+ #if _CALL_ELF == 2
273
+ if ((flags & FLAG_ARG_NEEDS_PSAVE) != 0)
274
+ bytes += intarg_count * sizeof (long);
275
+ #else
276
+ if (intarg_count > NUM_GPR_ARG_REGISTERS64)
277
+ bytes += (intarg_count - NUM_GPR_ARG_REGISTERS64) * sizeof (long);
278
+ #endif
279
+
280
+ /* The stack space allocated needs to be a multiple of 16 bytes. */
281
+ bytes = (bytes + 15) & ~0xF;
282
+
283
+ cif->flags = flags;
284
+ cif->bytes = bytes;
285
+
286
+ return FFI_OK;
287
+ }
288
+
289
+ ffi_status FFI_HIDDEN
290
+ ffi_prep_cif_linux64 (ffi_cif *cif)
291
+ {
292
+ if ((cif->abi & FFI_LINUX) != 0)
293
+ cif->nfixedargs = cif->nargs;
294
+ #if _CALL_ELF != 2
295
+ else if (cif->abi == FFI_COMPAT_LINUX64)
296
+ {
297
+ /* This call is from old code. Don't touch cif->nfixedargs
298
+ since old code will be using a smaller cif. */
299
+ cif->flags |= FLAG_COMPAT;
300
+ /* Translate to new abi value. */
301
+ cif->abi = FFI_LINUX | FFI_LINUX_LONG_DOUBLE_128;
302
+ }
303
+ #endif
304
+ else
305
+ return FFI_BAD_ABI;
306
+ return ffi_prep_cif_linux64_core (cif);
307
+ }
308
+
309
+ ffi_status FFI_HIDDEN
310
+ ffi_prep_cif_linux64_var (ffi_cif *cif,
311
+ unsigned int nfixedargs,
312
+ unsigned int ntotalargs MAYBE_UNUSED)
313
+ {
314
+ if ((cif->abi & FFI_LINUX) != 0)
315
+ cif->nfixedargs = nfixedargs;
316
+ #if _CALL_ELF != 2
317
+ else if (cif->abi == FFI_COMPAT_LINUX64)
318
+ {
319
+ /* This call is from old code. Don't touch cif->nfixedargs
320
+ since old code will be using a smaller cif. */
321
+ cif->flags |= FLAG_COMPAT;
322
+ /* Translate to new abi value. */
323
+ cif->abi = FFI_LINUX | FFI_LINUX_LONG_DOUBLE_128;
324
+ }
325
+ #endif
326
+ else
327
+ return FFI_BAD_ABI;
328
+ #if _CALL_ELF == 2
329
+ cif->flags |= FLAG_ARG_NEEDS_PSAVE;
330
+ #endif
331
+ return ffi_prep_cif_linux64_core (cif);
332
+ }
333
+
334
+
335
+ /* ffi_prep_args64 is called by the assembly routine once stack space
336
+ has been allocated for the function's arguments.
337
+
338
+ The stack layout we want looks like this:
339
+
340
+ | Ret addr from ffi_call_LINUX64 8bytes | higher addresses
341
+ |--------------------------------------------|
342
+ | CR save area 8bytes |
343
+ |--------------------------------------------|
344
+ | Previous backchain pointer 8 | stack pointer here
345
+ |--------------------------------------------|<+ <<< on entry to
346
+ | Saved r28-r31 4*8 | | ffi_call_LINUX64
347
+ |--------------------------------------------| |
348
+ | GPR registers r3-r10 8*8 | |
349
+ |--------------------------------------------| |
350
+ | FPR registers f1-f13 (optional) 13*8 | |
351
+ |--------------------------------------------| |
352
+ | Parameter save area | |
353
+ |--------------------------------------------| |
354
+ | TOC save area 8 | |
355
+ |--------------------------------------------| | stack |
356
+ | Linker doubleword 8 | | grows |
357
+ |--------------------------------------------| | down V
358
+ | Compiler doubleword 8 | |
359
+ |--------------------------------------------| | lower addresses
360
+ | Space for callee's LR 8 | |
361
+ |--------------------------------------------| |
362
+ | CR save area 8 | |
363
+ |--------------------------------------------| | stack pointer here
364
+ | Current backchain pointer 8 |-/ during
365
+ |--------------------------------------------| <<< ffi_call_LINUX64
366
+
367
+ */
368
+
369
+ void FFI_HIDDEN
370
+ ffi_prep_args64 (extended_cif *ecif, unsigned long *const stack)
371
+ {
372
+ const unsigned long bytes = ecif->cif->bytes;
373
+ const unsigned long flags = ecif->cif->flags;
374
+
375
+ typedef union
376
+ {
377
+ char *c;
378
+ unsigned long *ul;
379
+ float *f;
380
+ double *d;
381
+ size_t p;
382
+ } valp;
383
+
384
+ /* 'stacktop' points at the previous backchain pointer. */
385
+ valp stacktop;
386
+
387
+ /* 'next_arg' points at the space for gpr3, and grows upwards as
388
+ we use GPR registers, then continues at rest. */
389
+ valp gpr_base;
390
+ valp gpr_end;
391
+ valp rest;
392
+ valp next_arg;
393
+
394
+ /* 'fpr_base' points at the space for fpr3, and grows upwards as
395
+ we use FPR registers. */
396
+ valp fpr_base;
397
+ unsigned int fparg_count;
398
+
399
+ unsigned int i, words, nargs, nfixedargs;
400
+ ffi_type **ptr;
401
+ double double_tmp;
402
+ union
403
+ {
404
+ void **v;
405
+ char **c;
406
+ signed char **sc;
407
+ unsigned char **uc;
408
+ signed short **ss;
409
+ unsigned short **us;
410
+ signed int **si;
411
+ unsigned int **ui;
412
+ unsigned long **ul;
413
+ float **f;
414
+ double **d;
415
+ } p_argv;
416
+ unsigned long gprvalue;
417
+ unsigned long align;
418
+
419
+ stacktop.c = (char *) stack + bytes;
420
+ gpr_base.ul = stacktop.ul - ASM_NEEDS_REGISTERS64 - NUM_GPR_ARG_REGISTERS64;
421
+ gpr_end.ul = gpr_base.ul + NUM_GPR_ARG_REGISTERS64;
422
+ #if _CALL_ELF == 2
423
+ rest.ul = stack + 4 + NUM_GPR_ARG_REGISTERS64;
424
+ #else
425
+ rest.ul = stack + 6 + NUM_GPR_ARG_REGISTERS64;
426
+ #endif
427
+ fpr_base.d = gpr_base.d - NUM_FPR_ARG_REGISTERS64;
428
+ fparg_count = 0;
429
+ next_arg.ul = gpr_base.ul;
430
+
431
+ /* Check that everything starts aligned properly. */
432
+ FFI_ASSERT (((unsigned long) (char *) stack & 0xF) == 0);
433
+ FFI_ASSERT (((unsigned long) stacktop.c & 0xF) == 0);
434
+ FFI_ASSERT ((bytes & 0xF) == 0);
435
+
436
+ /* Deal with return values that are actually pass-by-reference. */
437
+ if (flags & FLAG_RETVAL_REFERENCE)
438
+ *next_arg.ul++ = (unsigned long) (char *) ecif->rvalue;
439
+
440
+ /* Now for the arguments. */
441
+ p_argv.v = ecif->avalue;
442
+ nargs = ecif->cif->nargs;
443
+ #if _CALL_ELF != 2
444
+ nfixedargs = (unsigned) -1;
445
+ if ((flags & FLAG_COMPAT) == 0)
446
+ #endif
447
+ nfixedargs = ecif->cif->nfixedargs;
448
+ for (ptr = ecif->cif->arg_types, i = 0;
449
+ i < nargs;
450
+ i++, ptr++, p_argv.v++)
451
+ {
452
+ #if _CALL_ELF == 2
453
+ unsigned int elt, elnum;
454
+ #endif
455
+
456
+ switch ((*ptr)->type)
457
+ {
458
+ #if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
459
+ case FFI_TYPE_LONGDOUBLE:
460
+ if ((ecif->cif->abi & FFI_LINUX_LONG_DOUBLE_128) != 0)
461
+ {
462
+ double_tmp = (*p_argv.d)[0];
463
+ if (fparg_count < NUM_FPR_ARG_REGISTERS64 && i < nfixedargs)
464
+ {
465
+ *fpr_base.d++ = double_tmp;
466
+ # if _CALL_ELF != 2
467
+ if ((flags & FLAG_COMPAT) != 0)
468
+ *next_arg.d = double_tmp;
469
+ # endif
470
+ }
471
+ else
472
+ *next_arg.d = double_tmp;
473
+ if (++next_arg.ul == gpr_end.ul)
474
+ next_arg.ul = rest.ul;
475
+ fparg_count++;
476
+ double_tmp = (*p_argv.d)[1];
477
+ if (fparg_count < NUM_FPR_ARG_REGISTERS64 && i < nfixedargs)
478
+ {
479
+ *fpr_base.d++ = double_tmp;
480
+ # if _CALL_ELF != 2
481
+ if ((flags & FLAG_COMPAT) != 0)
482
+ *next_arg.d = double_tmp;
483
+ # endif
484
+ }
485
+ else
486
+ *next_arg.d = double_tmp;
487
+ if (++next_arg.ul == gpr_end.ul)
488
+ next_arg.ul = rest.ul;
489
+ fparg_count++;
490
+ FFI_ASSERT (__LDBL_MANT_DIG__ == 106);
491
+ FFI_ASSERT (flags & FLAG_FP_ARGUMENTS);
492
+ break;
493
+ }
494
+ /* Fall through. */
495
+ #endif
496
+ case FFI_TYPE_DOUBLE:
497
+ double_tmp = **p_argv.d;
498
+ if (fparg_count < NUM_FPR_ARG_REGISTERS64 && i < nfixedargs)
499
+ {
500
+ *fpr_base.d++ = double_tmp;
501
+ #if _CALL_ELF != 2
502
+ if ((flags & FLAG_COMPAT) != 0)
503
+ *next_arg.d = double_tmp;
504
+ #endif
505
+ }
506
+ else
507
+ *next_arg.d = double_tmp;
508
+ if (++next_arg.ul == gpr_end.ul)
509
+ next_arg.ul = rest.ul;
510
+ fparg_count++;
511
+ FFI_ASSERT (flags & FLAG_FP_ARGUMENTS);
512
+ break;
513
+
514
+ case FFI_TYPE_FLOAT:
515
+ double_tmp = **p_argv.f;
516
+ if (fparg_count < NUM_FPR_ARG_REGISTERS64 && i < nfixedargs)
517
+ {
518
+ *fpr_base.d++ = double_tmp;
519
+ #if _CALL_ELF != 2
520
+ if ((flags & FLAG_COMPAT) != 0)
521
+ *next_arg.f = (float) double_tmp;
522
+ #endif
523
+ }
524
+ else
525
+ *next_arg.f = (float) double_tmp;
526
+ if (++next_arg.ul == gpr_end.ul)
527
+ next_arg.ul = rest.ul;
528
+ fparg_count++;
529
+ FFI_ASSERT (flags & FLAG_FP_ARGUMENTS);
530
+ break;
531
+
532
+ case FFI_TYPE_STRUCT:
533
+ if ((ecif->cif->abi & FFI_LINUX_STRUCT_ALIGN) != 0)
534
+ {
535
+ align = (*ptr)->alignment;
536
+ if (align > 16)
537
+ align = 16;
538
+ if (align > 1)
539
+ next_arg.p = FFI_ALIGN (next_arg.p, align);
540
+ }
541
+ #if _CALL_ELF == 2
542
+ elt = discover_homogeneous_aggregate (*ptr, &elnum);
543
+ if (elt)
544
+ {
545
+ union {
546
+ void *v;
547
+ float *f;
548
+ double *d;
549
+ } arg;
550
+
551
+ arg.v = *p_argv.v;
552
+ if (elt == FFI_TYPE_FLOAT)
553
+ {
554
+ do
555
+ {
556
+ double_tmp = *arg.f++;
557
+ if (fparg_count < NUM_FPR_ARG_REGISTERS64
558
+ && i < nfixedargs)
559
+ *fpr_base.d++ = double_tmp;
560
+ else
561
+ *next_arg.f = (float) double_tmp;
562
+ if (++next_arg.f == gpr_end.f)
563
+ next_arg.f = rest.f;
564
+ fparg_count++;
565
+ }
566
+ while (--elnum != 0);
567
+ if ((next_arg.p & 3) != 0)
568
+ {
569
+ if (++next_arg.f == gpr_end.f)
570
+ next_arg.f = rest.f;
571
+ }
572
+ }
573
+ else
574
+ do
575
+ {
576
+ double_tmp = *arg.d++;
577
+ if (fparg_count < NUM_FPR_ARG_REGISTERS64 && i < nfixedargs)
578
+ *fpr_base.d++ = double_tmp;
579
+ else
580
+ *next_arg.d = double_tmp;
581
+ if (++next_arg.d == gpr_end.d)
582
+ next_arg.d = rest.d;
583
+ fparg_count++;
584
+ }
585
+ while (--elnum != 0);
586
+ }
587
+ else
588
+ #endif
589
+ {
590
+ words = ((*ptr)->size + 7) / 8;
591
+ if (next_arg.ul >= gpr_base.ul && next_arg.ul + words > gpr_end.ul)
592
+ {
593
+ size_t first = gpr_end.c - next_arg.c;
594
+ memcpy (next_arg.c, *p_argv.c, first);
595
+ memcpy (rest.c, *p_argv.c + first, (*ptr)->size - first);
596
+ next_arg.c = rest.c + words * 8 - first;
597
+ }
598
+ else
599
+ {
600
+ char *where = next_arg.c;
601
+
602
+ #ifndef __LITTLE_ENDIAN__
603
+ /* Structures with size less than eight bytes are passed
604
+ left-padded. */
605
+ if ((*ptr)->size < 8)
606
+ where += 8 - (*ptr)->size;
607
+ #endif
608
+ memcpy (where, *p_argv.c, (*ptr)->size);
609
+ next_arg.ul += words;
610
+ if (next_arg.ul == gpr_end.ul)
611
+ next_arg.ul = rest.ul;
612
+ }
613
+ }
614
+ break;
615
+
616
+ case FFI_TYPE_UINT8:
617
+ gprvalue = **p_argv.uc;
618
+ goto putgpr;
619
+ case FFI_TYPE_SINT8:
620
+ gprvalue = **p_argv.sc;
621
+ goto putgpr;
622
+ case FFI_TYPE_UINT16:
623
+ gprvalue = **p_argv.us;
624
+ goto putgpr;
625
+ case FFI_TYPE_SINT16:
626
+ gprvalue = **p_argv.ss;
627
+ goto putgpr;
628
+ case FFI_TYPE_UINT32:
629
+ gprvalue = **p_argv.ui;
630
+ goto putgpr;
631
+ case FFI_TYPE_INT:
632
+ case FFI_TYPE_SINT32:
633
+ gprvalue = **p_argv.si;
634
+ goto putgpr;
635
+
636
+ case FFI_TYPE_UINT64:
637
+ case FFI_TYPE_SINT64:
638
+ case FFI_TYPE_POINTER:
639
+ gprvalue = **p_argv.ul;
640
+ putgpr:
641
+ *next_arg.ul++ = gprvalue;
642
+ if (next_arg.ul == gpr_end.ul)
643
+ next_arg.ul = rest.ul;
644
+ break;
645
+ }
646
+ }
647
+
648
+ FFI_ASSERT (flags & FLAG_4_GPR_ARGUMENTS
649
+ || (next_arg.ul >= gpr_base.ul
650
+ && next_arg.ul <= gpr_base.ul + 4));
651
+ }
652
+
653
+
654
+ #if _CALL_ELF == 2
655
+ #define MIN_CACHE_LINE_SIZE 8
656
+
657
+ static void
658
+ flush_icache (char *wraddr, char *xaddr, int size)
659
+ {
660
+ int i;
661
+ for (i = 0; i < size; i += MIN_CACHE_LINE_SIZE)
662
+ __asm__ volatile ("icbi 0,%0;" "dcbf 0,%1;"
663
+ : : "r" (xaddr + i), "r" (wraddr + i) : "memory");
664
+ __asm__ volatile ("icbi 0,%0;" "dcbf 0,%1;" "sync;" "isync;"
665
+ : : "r"(xaddr + size - 1), "r"(wraddr + size - 1)
666
+ : "memory");
667
+ }
668
+ #endif
669
+
670
+
671
+ ffi_status FFI_HIDDEN
672
+ ffi_prep_closure_loc_linux64 (ffi_closure *closure,
673
+ ffi_cif *cif,
674
+ void (*fun) (ffi_cif *, void *, void **, void *),
675
+ void *user_data,
676
+ void *codeloc)
677
+ {
678
+ #if _CALL_ELF == 2
679
+ unsigned int *tramp = (unsigned int *) &closure->tramp[0];
680
+
681
+ if (cif->abi < FFI_LINUX || cif->abi >= FFI_LAST_ABI)
682
+ return FFI_BAD_ABI;
683
+
684
+ tramp[0] = 0xe96c0018; /* 0: ld 11,2f-0b(12) */
685
+ tramp[1] = 0xe98c0010; /* ld 12,1f-0b(12) */
686
+ tramp[2] = 0x7d8903a6; /* mtctr 12 */
687
+ tramp[3] = 0x4e800420; /* bctr */
688
+ /* 1: .quad function_addr */
689
+ /* 2: .quad context */
690
+ *(void **) &tramp[4] = (void *) ffi_closure_LINUX64;
691
+ *(void **) &tramp[6] = codeloc;
692
+ flush_icache ((char *) tramp, (char *) codeloc, 4 * 4);
693
+ #else
694
+ void **tramp = (void **) &closure->tramp[0];
695
+
696
+ if (cif->abi < FFI_LINUX || cif->abi >= FFI_LAST_ABI)
697
+ return FFI_BAD_ABI;
698
+
699
+ /* Copy function address and TOC from ffi_closure_LINUX64 OPD. */
700
+ memcpy (&tramp[0], (void **) ffi_closure_LINUX64, sizeof (void *));
701
+ tramp[1] = codeloc;
702
+ memcpy (&tramp[2], (void **) ffi_closure_LINUX64 + 1, sizeof (void *));
703
+ #endif
704
+
705
+ closure->cif = cif;
706
+ closure->fun = fun;
707
+ closure->user_data = user_data;
708
+
709
+ return FFI_OK;
710
+ }
711
+
712
+
713
+ int FFI_HIDDEN
714
+ ffi_closure_helper_LINUX64 (ffi_cif *cif,
715
+ void (*fun) (ffi_cif *, void *, void **, void *),
716
+ void *user_data,
717
+ void *rvalue,
718
+ unsigned long *pst,
719
+ ffi_dblfl *pfr)
720
+ {
721
+ /* rvalue is the pointer to space for return value in closure assembly */
722
+ /* pst is the pointer to parameter save area
723
+ (r3-r10 are stored into its first 8 slots by ffi_closure_LINUX64) */
724
+ /* pfr is the pointer to where f1-f13 are stored in ffi_closure_LINUX64 */
725
+
726
+ void **avalue;
727
+ ffi_type **arg_types;
728
+ unsigned long i, avn, nfixedargs;
729
+ ffi_dblfl *end_pfr = pfr + NUM_FPR_ARG_REGISTERS64;
730
+ unsigned long align;
731
+
732
+ avalue = alloca (cif->nargs * sizeof (void *));
733
+
734
+ /* Copy the caller's structure return value address so that the
735
+ closure returns the data directly to the caller. */
736
+ if (cif->rtype->type == FFI_TYPE_STRUCT
737
+ && (cif->flags & FLAG_RETURNS_SMST) == 0)
738
+ {
739
+ rvalue = (void *) *pst;
740
+ pst++;
741
+ }
742
+
743
+ i = 0;
744
+ avn = cif->nargs;
745
+ #if _CALL_ELF != 2
746
+ nfixedargs = (unsigned) -1;
747
+ if ((cif->flags & FLAG_COMPAT) == 0)
748
+ #endif
749
+ nfixedargs = cif->nfixedargs;
750
+ arg_types = cif->arg_types;
751
+
752
+ /* Grab the addresses of the arguments from the stack frame. */
753
+ while (i < avn)
754
+ {
755
+ unsigned int elt, elnum;
756
+
757
+ switch (arg_types[i]->type)
758
+ {
759
+ case FFI_TYPE_SINT8:
760
+ case FFI_TYPE_UINT8:
761
+ #ifndef __LITTLE_ENDIAN__
762
+ avalue[i] = (char *) pst + 7;
763
+ pst++;
764
+ break;
765
+ #endif
766
+
767
+ case FFI_TYPE_SINT16:
768
+ case FFI_TYPE_UINT16:
769
+ #ifndef __LITTLE_ENDIAN__
770
+ avalue[i] = (char *) pst + 6;
771
+ pst++;
772
+ break;
773
+ #endif
774
+
775
+ case FFI_TYPE_SINT32:
776
+ case FFI_TYPE_UINT32:
777
+ #ifndef __LITTLE_ENDIAN__
778
+ avalue[i] = (char *) pst + 4;
779
+ pst++;
780
+ break;
781
+ #endif
782
+
783
+ case FFI_TYPE_SINT64:
784
+ case FFI_TYPE_UINT64:
785
+ case FFI_TYPE_POINTER:
786
+ avalue[i] = pst;
787
+ pst++;
788
+ break;
789
+
790
+ case FFI_TYPE_STRUCT:
791
+ if ((cif->abi & FFI_LINUX_STRUCT_ALIGN) != 0)
792
+ {
793
+ align = arg_types[i]->alignment;
794
+ if (align > 16)
795
+ align = 16;
796
+ if (align > 1)
797
+ pst = (unsigned long *) FFI_ALIGN ((size_t) pst, align);
798
+ }
799
+ elt = 0;
800
+ #if _CALL_ELF == 2
801
+ elt = discover_homogeneous_aggregate (arg_types[i], &elnum);
802
+ #endif
803
+ if (elt)
804
+ {
805
+ union {
806
+ void *v;
807
+ unsigned long *ul;
808
+ float *f;
809
+ double *d;
810
+ size_t p;
811
+ } to, from;
812
+
813
+ /* Repackage the aggregate from its parts. The
814
+ aggregate size is not greater than the space taken by
815
+ the registers so store back to the register/parameter
816
+ save arrays. */
817
+ if (pfr + elnum <= end_pfr)
818
+ to.v = pfr;
819
+ else
820
+ to.v = pst;
821
+
822
+ avalue[i] = to.v;
823
+ from.ul = pst;
824
+ if (elt == FFI_TYPE_FLOAT)
825
+ {
826
+ do
827
+ {
828
+ if (pfr < end_pfr && i < nfixedargs)
829
+ {
830
+ *to.f = (float) pfr->d;
831
+ pfr++;
832
+ }
833
+ else
834
+ *to.f = *from.f;
835
+ to.f++;
836
+ from.f++;
837
+ }
838
+ while (--elnum != 0);
839
+ }
840
+ else
841
+ {
842
+ do
843
+ {
844
+ if (pfr < end_pfr && i < nfixedargs)
845
+ {
846
+ *to.d = pfr->d;
847
+ pfr++;
848
+ }
849
+ else
850
+ *to.d = *from.d;
851
+ to.d++;
852
+ from.d++;
853
+ }
854
+ while (--elnum != 0);
855
+ }
856
+ }
857
+ else
858
+ {
859
+ #ifndef __LITTLE_ENDIAN__
860
+ /* Structures with size less than eight bytes are passed
861
+ left-padded. */
862
+ if (arg_types[i]->size < 8)
863
+ avalue[i] = (char *) pst + 8 - arg_types[i]->size;
864
+ else
865
+ #endif
866
+ avalue[i] = pst;
867
+ }
868
+ pst += (arg_types[i]->size + 7) / 8;
869
+ break;
870
+
871
+ #if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
872
+ case FFI_TYPE_LONGDOUBLE:
873
+ if ((cif->abi & FFI_LINUX_LONG_DOUBLE_128) != 0)
874
+ {
875
+ if (pfr + 1 < end_pfr && i + 1 < nfixedargs)
876
+ {
877
+ avalue[i] = pfr;
878
+ pfr += 2;
879
+ }
880
+ else
881
+ {
882
+ if (pfr < end_pfr && i < nfixedargs)
883
+ {
884
+ /* Passed partly in f13 and partly on the stack.
885
+ Move it all to the stack. */
886
+ *pst = *(unsigned long *) pfr;
887
+ pfr++;
888
+ }
889
+ avalue[i] = pst;
890
+ }
891
+ pst += 2;
892
+ break;
893
+ }
894
+ /* Fall through. */
895
+ #endif
896
+ case FFI_TYPE_DOUBLE:
897
+ /* On the outgoing stack all values are aligned to 8 */
898
+ /* there are 13 64bit floating point registers */
899
+
900
+ if (pfr < end_pfr && i < nfixedargs)
901
+ {
902
+ avalue[i] = pfr;
903
+ pfr++;
904
+ }
905
+ else
906
+ avalue[i] = pst;
907
+ pst++;
908
+ break;
909
+
910
+ case FFI_TYPE_FLOAT:
911
+ if (pfr < end_pfr && i < nfixedargs)
912
+ {
913
+ /* Float values are stored as doubles in the
914
+ ffi_closure_LINUX64 code. Fix them here. */
915
+ pfr->f = (float) pfr->d;
916
+ avalue[i] = pfr;
917
+ pfr++;
918
+ }
919
+ else
920
+ avalue[i] = pst;
921
+ pst++;
922
+ break;
923
+
924
+ default:
925
+ FFI_ASSERT (0);
926
+ }
927
+
928
+ i++;
929
+ }
930
+
931
+ (*fun) (cif, rvalue, avalue, user_data);
932
+
933
+ /* Tell ffi_closure_LINUX64 how to perform return type promotions. */
934
+ if ((cif->flags & FLAG_RETURNS_SMST) != 0)
935
+ {
936
+ if ((cif->flags & FLAG_RETURNS_FP) == 0)
937
+ return FFI_V2_TYPE_SMALL_STRUCT + cif->rtype->size - 1;
938
+ else if ((cif->flags & FLAG_RETURNS_64BITS) != 0)
939
+ return FFI_V2_TYPE_DOUBLE_HOMOG;
940
+ else
941
+ return FFI_V2_TYPE_FLOAT_HOMOG;
942
+ }
943
+ return cif->rtype->type;
944
+ }
945
+ #endif