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
@@ -1,9 +1,10 @@
1
1
  /* -----------------------------------------------------------------------
2
- ffi64.c - Copyright (c) 20011 Anthony Green
2
+ ffi64.c - Copyright (c) 2013 The Written Word, Inc.
3
+ Copyright (c) 2011 Anthony Green
3
4
  Copyright (c) 2008, 2010 Red Hat, Inc.
4
5
  Copyright (c) 2002, 2007 Bo Thorsen <bo@suse.de>
5
-
6
- x86-64 Foreign Function Interface
6
+
7
+ x86-64 Foreign Function Interface
7
8
 
8
9
  Permission is hereby granted, free of charge, to any person obtaining
9
10
  a copy of this software and associated documentation files (the
@@ -31,21 +32,44 @@
31
32
 
32
33
  #include <stdlib.h>
33
34
  #include <stdarg.h>
35
+ #include <stdint.h>
36
+ #include "internal64.h"
34
37
 
35
38
  #ifdef __x86_64__
36
39
 
37
40
  #define MAX_GPR_REGS 6
38
41
  #define MAX_SSE_REGS 8
39
42
 
43
+ #if defined(__INTEL_COMPILER)
44
+ #include "xmmintrin.h"
45
+ #define UINT128 __m128
46
+ #else
47
+ #if defined(__SUNPRO_C)
48
+ #include <sunmedia_types.h>
49
+ #define UINT128 __m128i
50
+ #else
51
+ #define UINT128 __int128_t
52
+ #endif
53
+ #endif
54
+
55
+ union big_int_union
56
+ {
57
+ UINT32 i32;
58
+ UINT64 i64;
59
+ UINT128 i128;
60
+ };
61
+
40
62
  struct register_args
41
63
  {
42
64
  /* Registers for argument passing. */
43
65
  UINT64 gpr[MAX_GPR_REGS];
44
- __int128_t sse[MAX_SSE_REGS];
66
+ union big_int_union sse[MAX_SSE_REGS];
67
+ UINT64 rax; /* ssecount */
68
+ UINT64 r10; /* static chain */
45
69
  };
46
70
 
47
71
  extern void ffi_call_unix64 (void *args, unsigned long bytes, unsigned flags,
48
- void *raddr, void (*fnaddr)(void), unsigned ssecount);
72
+ void *raddr, void (*fnaddr)(void)) FFI_HIDDEN;
49
73
 
50
74
  /* All reference to register classes here is identical to the code in
51
75
  gcc/config/i386/i386.c. Do *not* change one without the other. */
@@ -132,7 +156,7 @@ merge_classes (enum x86_64_reg_class class1, enum x86_64_reg_class class2)
132
156
 
133
157
  See the x86-64 PS ABI for details.
134
158
  */
135
- static int
159
+ static size_t
136
160
  classify_argument (ffi_type *type, enum x86_64_reg_class classes[],
137
161
  size_t byte_offset)
138
162
  {
@@ -147,8 +171,9 @@ classify_argument (ffi_type *type, enum x86_64_reg_class classes[],
147
171
  case FFI_TYPE_UINT64:
148
172
  case FFI_TYPE_SINT64:
149
173
  case FFI_TYPE_POINTER:
174
+ do_integer:
150
175
  {
151
- int size = byte_offset + type->size;
176
+ size_t size = byte_offset + type->size;
152
177
 
153
178
  if (size <= 4)
154
179
  {
@@ -168,7 +193,7 @@ classify_argument (ffi_type *type, enum x86_64_reg_class classes[],
168
193
  }
169
194
  else if (size <= 16)
170
195
  {
171
- classes[0] = classes[1] = X86_64_INTEGERSI_CLASS;
196
+ classes[0] = classes[1] = X86_64_INTEGER_CLASS;
172
197
  return 2;
173
198
  }
174
199
  else
@@ -183,16 +208,18 @@ classify_argument (ffi_type *type, enum x86_64_reg_class classes[],
183
208
  case FFI_TYPE_DOUBLE:
184
209
  classes[0] = X86_64_SSEDF_CLASS;
185
210
  return 1;
211
+ #if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
186
212
  case FFI_TYPE_LONGDOUBLE:
187
213
  classes[0] = X86_64_X87_CLASS;
188
214
  classes[1] = X86_64_X87UP_CLASS;
189
215
  return 2;
216
+ #endif
190
217
  case FFI_TYPE_STRUCT:
191
218
  {
192
- const int UNITS_PER_WORD = 8;
193
- int words = (type->size + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
194
- ffi_type **ptr;
195
- int i;
219
+ const size_t UNITS_PER_WORD = 8;
220
+ size_t words = (type->size + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
221
+ ffi_type **ptr;
222
+ unsigned int i;
196
223
  enum x86_64_reg_class subclasses[MAX_CLASSES];
197
224
 
198
225
  /* If the struct is larger than 32 bytes, pass it on the stack. */
@@ -206,6 +233,7 @@ classify_argument (ffi_type *type, enum x86_64_reg_class classes[],
206
233
  signalize memory class, so handle it as special case. */
207
234
  if (!words)
208
235
  {
236
+ case FFI_TYPE_VOID:
209
237
  classes[0] = X86_64_NO_CLASS;
210
238
  return 1;
211
239
  }
@@ -213,16 +241,16 @@ classify_argument (ffi_type *type, enum x86_64_reg_class classes[],
213
241
  /* Merge the fields of structure. */
214
242
  for (ptr = type->elements; *ptr != NULL; ptr++)
215
243
  {
216
- int num;
244
+ size_t num;
217
245
 
218
- byte_offset = ALIGN (byte_offset, (*ptr)->alignment);
246
+ byte_offset = FFI_ALIGN (byte_offset, (*ptr)->alignment);
219
247
 
220
248
  num = classify_argument (*ptr, subclasses, byte_offset % 8);
221
249
  if (num == 0)
222
250
  return 0;
223
251
  for (i = 0; i < num; i++)
224
252
  {
225
- int pos = byte_offset / 8;
253
+ size_t pos = byte_offset / 8;
226
254
  classes[i + pos] =
227
255
  merge_classes (subclasses[i], classes[i + pos]);
228
256
  }
@@ -275,22 +303,55 @@ classify_argument (ffi_type *type, enum x86_64_reg_class classes[],
275
303
  }
276
304
  return words;
277
305
  }
278
-
279
- default:
280
- FFI_ASSERT(0);
306
+ case FFI_TYPE_COMPLEX:
307
+ {
308
+ ffi_type *inner = type->elements[0];
309
+ switch (inner->type)
310
+ {
311
+ case FFI_TYPE_INT:
312
+ case FFI_TYPE_UINT8:
313
+ case FFI_TYPE_SINT8:
314
+ case FFI_TYPE_UINT16:
315
+ case FFI_TYPE_SINT16:
316
+ case FFI_TYPE_UINT32:
317
+ case FFI_TYPE_SINT32:
318
+ case FFI_TYPE_UINT64:
319
+ case FFI_TYPE_SINT64:
320
+ goto do_integer;
321
+
322
+ case FFI_TYPE_FLOAT:
323
+ classes[0] = X86_64_SSE_CLASS;
324
+ if (byte_offset % 8)
325
+ {
326
+ classes[1] = X86_64_SSESF_CLASS;
327
+ return 2;
328
+ }
329
+ return 1;
330
+ case FFI_TYPE_DOUBLE:
331
+ classes[0] = classes[1] = X86_64_SSEDF_CLASS;
332
+ return 2;
333
+ #if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
334
+ case FFI_TYPE_LONGDOUBLE:
335
+ classes[0] = X86_64_COMPLEX_X87_CLASS;
336
+ return 1;
337
+ #endif
338
+ }
339
+ }
281
340
  }
282
- return 0; /* Never reached. */
341
+ abort();
283
342
  }
284
343
 
285
344
  /* Examine the argument and return set number of register required in each
286
345
  class. Return zero iff parameter should be passed in memory, otherwise
287
346
  the number of registers. */
288
347
 
289
- static int
348
+ static size_t
290
349
  examine_argument (ffi_type *type, enum x86_64_reg_class classes[MAX_CLASSES],
291
350
  _Bool in_return, int *pngpr, int *pnsse)
292
351
  {
293
- int i, n, ngpr, nsse;
352
+ size_t n;
353
+ unsigned int i;
354
+ int ngpr, nsse;
294
355
 
295
356
  n = classify_argument (type, classes, 0);
296
357
  if (n == 0)
@@ -328,18 +389,72 @@ examine_argument (ffi_type *type, enum x86_64_reg_class classes[MAX_CLASSES],
328
389
 
329
390
  /* Perform machine dependent cif processing. */
330
391
 
392
+ #ifndef __ILP32__
393
+ extern ffi_status
394
+ ffi_prep_cif_machdep_efi64(ffi_cif *cif);
395
+ #endif
396
+
331
397
  ffi_status
332
398
  ffi_prep_cif_machdep (ffi_cif *cif)
333
399
  {
334
- int gprcount, ssecount, i, avn, n, ngpr, nsse, flags;
400
+ int gprcount, ssecount, i, avn, ngpr, nsse;
401
+ unsigned flags;
335
402
  enum x86_64_reg_class classes[MAX_CLASSES];
336
- size_t bytes;
403
+ size_t bytes, n, rtype_size;
404
+ ffi_type *rtype;
405
+
406
+ #ifndef __ILP32__
407
+ if (cif->abi == FFI_EFI64)
408
+ return ffi_prep_cif_machdep_efi64(cif);
409
+ #endif
410
+ if (cif->abi != FFI_UNIX64)
411
+ return FFI_BAD_ABI;
337
412
 
338
413
  gprcount = ssecount = 0;
339
414
 
340
- flags = cif->rtype->type;
341
- if (flags != FFI_TYPE_VOID)
415
+ rtype = cif->rtype;
416
+ rtype_size = rtype->size;
417
+ switch (rtype->type)
342
418
  {
419
+ case FFI_TYPE_VOID:
420
+ flags = UNIX64_RET_VOID;
421
+ break;
422
+ case FFI_TYPE_UINT8:
423
+ flags = UNIX64_RET_UINT8;
424
+ break;
425
+ case FFI_TYPE_SINT8:
426
+ flags = UNIX64_RET_SINT8;
427
+ break;
428
+ case FFI_TYPE_UINT16:
429
+ flags = UNIX64_RET_UINT16;
430
+ break;
431
+ case FFI_TYPE_SINT16:
432
+ flags = UNIX64_RET_SINT16;
433
+ break;
434
+ case FFI_TYPE_UINT32:
435
+ flags = UNIX64_RET_UINT32;
436
+ break;
437
+ case FFI_TYPE_INT:
438
+ case FFI_TYPE_SINT32:
439
+ flags = UNIX64_RET_SINT32;
440
+ break;
441
+ case FFI_TYPE_UINT64:
442
+ case FFI_TYPE_SINT64:
443
+ flags = UNIX64_RET_INT64;
444
+ break;
445
+ case FFI_TYPE_POINTER:
446
+ flags = (sizeof(void *) == 4 ? UNIX64_RET_UINT32 : UNIX64_RET_INT64);
447
+ break;
448
+ case FFI_TYPE_FLOAT:
449
+ flags = UNIX64_RET_XMM32;
450
+ break;
451
+ case FFI_TYPE_DOUBLE:
452
+ flags = UNIX64_RET_XMM64;
453
+ break;
454
+ case FFI_TYPE_LONGDOUBLE:
455
+ flags = UNIX64_RET_X87;
456
+ break;
457
+ case FFI_TYPE_STRUCT:
343
458
  n = examine_argument (cif->rtype, classes, 1, &ngpr, &nsse);
344
459
  if (n == 0)
345
460
  {
@@ -347,22 +462,62 @@ ffi_prep_cif_machdep (ffi_cif *cif)
347
462
  memory is the first argument. Allocate a register for it. */
348
463
  gprcount++;
349
464
  /* We don't have to do anything in asm for the return. */
350
- flags = FFI_TYPE_VOID;
465
+ flags = UNIX64_RET_VOID | UNIX64_FLAG_RET_IN_MEM;
351
466
  }
352
- else if (flags == FFI_TYPE_STRUCT)
467
+ else
353
468
  {
354
- /* Mark which registers the result appears in. */
355
469
  _Bool sse0 = SSE_CLASS_P (classes[0]);
356
- _Bool sse1 = n == 2 && SSE_CLASS_P (classes[1]);
357
- if (sse0 && !sse1)
358
- flags |= 1 << 8;
359
- else if (!sse0 && sse1)
360
- flags |= 1 << 9;
361
- else if (sse0 && sse1)
362
- flags |= 1 << 10;
363
- /* Mark the true size of the structure. */
364
- flags |= cif->rtype->size << 12;
470
+
471
+ if (rtype_size == 4 && sse0)
472
+ flags = UNIX64_RET_XMM32;
473
+ else if (rtype_size == 8)
474
+ flags = sse0 ? UNIX64_RET_XMM64 : UNIX64_RET_INT64;
475
+ else
476
+ {
477
+ _Bool sse1 = n == 2 && SSE_CLASS_P (classes[1]);
478
+ if (sse0 && sse1)
479
+ flags = UNIX64_RET_ST_XMM0_XMM1;
480
+ else if (sse0)
481
+ flags = UNIX64_RET_ST_XMM0_RAX;
482
+ else if (sse1)
483
+ flags = UNIX64_RET_ST_RAX_XMM0;
484
+ else
485
+ flags = UNIX64_RET_ST_RAX_RDX;
486
+ flags |= rtype_size << UNIX64_SIZE_SHIFT;
487
+ }
488
+ }
489
+ break;
490
+ case FFI_TYPE_COMPLEX:
491
+ switch (rtype->elements[0]->type)
492
+ {
493
+ case FFI_TYPE_UINT8:
494
+ case FFI_TYPE_SINT8:
495
+ case FFI_TYPE_UINT16:
496
+ case FFI_TYPE_SINT16:
497
+ case FFI_TYPE_INT:
498
+ case FFI_TYPE_UINT32:
499
+ case FFI_TYPE_SINT32:
500
+ case FFI_TYPE_UINT64:
501
+ case FFI_TYPE_SINT64:
502
+ flags = UNIX64_RET_ST_RAX_RDX | ((unsigned) rtype_size << UNIX64_SIZE_SHIFT);
503
+ break;
504
+ case FFI_TYPE_FLOAT:
505
+ flags = UNIX64_RET_XMM64;
506
+ break;
507
+ case FFI_TYPE_DOUBLE:
508
+ flags = UNIX64_RET_ST_XMM0_XMM1 | (16 << UNIX64_SIZE_SHIFT);
509
+ break;
510
+ #if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
511
+ case FFI_TYPE_LONGDOUBLE:
512
+ flags = UNIX64_RET_X87_2;
513
+ break;
514
+ #endif
515
+ default:
516
+ return FFI_BAD_TYPEDEF;
365
517
  }
518
+ break;
519
+ default:
520
+ return FFI_BAD_TYPEDEF;
366
521
  }
367
522
 
368
523
  /* Go over all arguments and determine the way they should be passed.
@@ -379,7 +534,7 @@ ffi_prep_cif_machdep (ffi_cif *cif)
379
534
  if (align < 8)
380
535
  align = 8;
381
536
 
382
- bytes = ALIGN (bytes, align);
537
+ bytes = FFI_ALIGN (bytes, align);
383
538
  bytes += cif->arg_types[i]->size;
384
539
  }
385
540
  else
@@ -389,53 +544,58 @@ ffi_prep_cif_machdep (ffi_cif *cif)
389
544
  }
390
545
  }
391
546
  if (ssecount)
392
- flags |= 1 << 11;
547
+ flags |= UNIX64_FLAG_XMM_ARGS;
548
+
393
549
  cif->flags = flags;
394
- cif->bytes = ALIGN (bytes, 8);
550
+ cif->bytes = (unsigned) FFI_ALIGN (bytes, 8);
395
551
 
396
552
  return FFI_OK;
397
553
  }
398
554
 
399
- void
400
- ffi_call (ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue)
555
+ static void
556
+ ffi_call_int (ffi_cif *cif, void (*fn)(void), void *rvalue,
557
+ void **avalue, void *closure)
401
558
  {
402
559
  enum x86_64_reg_class classes[MAX_CLASSES];
403
560
  char *stack, *argp;
404
561
  ffi_type **arg_types;
405
- int gprcount, ssecount, ngpr, nsse, i, avn;
406
- _Bool ret_in_memory;
562
+ int gprcount, ssecount, ngpr, nsse, i, avn, flags;
407
563
  struct register_args *reg_args;
408
564
 
409
565
  /* Can't call 32-bit mode from 64-bit mode. */
410
566
  FFI_ASSERT (cif->abi == FFI_UNIX64);
411
567
 
412
568
  /* If the return value is a struct and we don't have a return value
413
- address then we need to make one. Note the setting of flags to
414
- VOID above in ffi_prep_cif_machdep. */
415
- ret_in_memory = (cif->rtype->type == FFI_TYPE_STRUCT
416
- && (cif->flags & 0xff) == FFI_TYPE_VOID);
417
- if (rvalue == NULL && ret_in_memory)
418
- rvalue = alloca (cif->rtype->size);
569
+ address then we need to make one. Otherwise we can ignore it. */
570
+ flags = cif->flags;
571
+ if (rvalue == NULL)
572
+ {
573
+ if (flags & UNIX64_FLAG_RET_IN_MEM)
574
+ rvalue = alloca (cif->rtype->size);
575
+ else
576
+ flags = UNIX64_RET_VOID;
577
+ }
419
578
 
420
579
  /* Allocate the space for the arguments, plus 4 words of temp space. */
421
580
  stack = alloca (sizeof (struct register_args) + cif->bytes + 4*8);
422
581
  reg_args = (struct register_args *) stack;
423
582
  argp = stack + sizeof (struct register_args);
424
583
 
584
+ reg_args->r10 = (uintptr_t) closure;
585
+
425
586
  gprcount = ssecount = 0;
426
587
 
427
588
  /* If the return value is passed in memory, add the pointer as the
428
589
  first integer argument. */
429
- if (ret_in_memory)
430
- reg_args->gpr[gprcount++] = (long) rvalue;
590
+ if (flags & UNIX64_FLAG_RET_IN_MEM)
591
+ reg_args->gpr[gprcount++] = (unsigned long) rvalue;
431
592
 
432
593
  avn = cif->nargs;
433
594
  arg_types = cif->arg_types;
434
595
 
435
596
  for (i = 0; i < avn; ++i)
436
597
  {
437
- size_t size = arg_types[i]->size;
438
- int n;
598
+ size_t n, size = arg_types[i]->size;
439
599
 
440
600
  n = examine_argument (arg_types[i], classes, 0, &ngpr, &nsse);
441
601
  if (n == 0
@@ -449,7 +609,7 @@ ffi_call (ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue)
449
609
  align = 8;
450
610
 
451
611
  /* Pass this argument in memory. */
452
- argp = (void *) ALIGN (argp, align);
612
+ argp = (void *) FFI_ALIGN (argp, align);
453
613
  memcpy (argp, avalue[i], size);
454
614
  argp += size;
455
615
  }
@@ -457,24 +617,44 @@ ffi_call (ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue)
457
617
  {
458
618
  /* The argument is passed entirely in registers. */
459
619
  char *a = (char *) avalue[i];
460
- int j;
620
+ unsigned int j;
461
621
 
462
622
  for (j = 0; j < n; j++, a += 8, size -= 8)
463
623
  {
464
624
  switch (classes[j])
465
625
  {
626
+ case X86_64_NO_CLASS:
627
+ case X86_64_SSEUP_CLASS:
628
+ break;
466
629
  case X86_64_INTEGER_CLASS:
467
630
  case X86_64_INTEGERSI_CLASS:
468
- reg_args->gpr[gprcount] = 0;
469
- memcpy (&reg_args->gpr[gprcount], a, size < 8 ? size : 8);
631
+ /* Sign-extend integer arguments passed in general
632
+ purpose registers, to cope with the fact that
633
+ LLVM incorrectly assumes that this will be done
634
+ (the x86-64 PS ABI does not specify this). */
635
+ switch (arg_types[i]->type)
636
+ {
637
+ case FFI_TYPE_SINT8:
638
+ reg_args->gpr[gprcount] = (SINT64) *((SINT8 *) a);
639
+ break;
640
+ case FFI_TYPE_SINT16:
641
+ reg_args->gpr[gprcount] = (SINT64) *((SINT16 *) a);
642
+ break;
643
+ case FFI_TYPE_SINT32:
644
+ reg_args->gpr[gprcount] = (SINT64) *((SINT32 *) a);
645
+ break;
646
+ default:
647
+ reg_args->gpr[gprcount] = 0;
648
+ memcpy (&reg_args->gpr[gprcount], a, size);
649
+ }
470
650
  gprcount++;
471
651
  break;
472
652
  case X86_64_SSE_CLASS:
473
653
  case X86_64_SSEDF_CLASS:
474
- reg_args->sse[ssecount++] = *(UINT64 *) a;
654
+ memcpy (&reg_args->sse[ssecount++].i64, a, sizeof(UINT64));
475
655
  break;
476
656
  case X86_64_SSESF_CLASS:
477
- reg_args->sse[ssecount++] = *(UINT32 *) a;
657
+ memcpy (&reg_args->sse[ssecount++].i32, a, sizeof(UINT32));
478
658
  break;
479
659
  default:
480
660
  abort();
@@ -482,13 +662,56 @@ ffi_call (ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue)
482
662
  }
483
663
  }
484
664
  }
665
+ reg_args->rax = ssecount;
485
666
 
486
667
  ffi_call_unix64 (stack, cif->bytes + sizeof (struct register_args),
487
- cif->flags, rvalue, fn, ssecount);
668
+ flags, rvalue, fn);
488
669
  }
489
670
 
671
+ #ifndef __ILP32__
672
+ extern void
673
+ ffi_call_efi64(ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue);
674
+ #endif
490
675
 
491
- extern void ffi_closure_unix64(void);
676
+ void
677
+ ffi_call (ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue)
678
+ {
679
+ #ifndef __ILP32__
680
+ if (cif->abi == FFI_EFI64)
681
+ return ffi_call_efi64(cif, fn, rvalue, avalue);
682
+ #endif
683
+ ffi_call_int (cif, fn, rvalue, avalue, NULL);
684
+ }
685
+
686
+ #ifndef __ILP32__
687
+ extern void
688
+ ffi_call_go_efi64(ffi_cif *cif, void (*fn)(void), void *rvalue,
689
+ void **avalue, void *closure);
690
+ #endif
691
+
692
+ void
693
+ ffi_call_go (ffi_cif *cif, void (*fn)(void), void *rvalue,
694
+ void **avalue, void *closure)
695
+ {
696
+ #ifndef __ILP32__
697
+ if (cif->abi == FFI_EFI64)
698
+ ffi_call_go_efi64(cif, fn, rvalue, avalue, closure);
699
+ #endif
700
+ ffi_call_int (cif, fn, rvalue, avalue, closure);
701
+ }
702
+
703
+
704
+ extern void ffi_closure_unix64(void) FFI_HIDDEN;
705
+ extern void ffi_closure_unix64_sse(void) FFI_HIDDEN;
706
+
707
+ #ifndef __ILP32__
708
+ extern ffi_status
709
+ ffi_prep_closure_loc_efi64(ffi_closure* closure,
710
+ ffi_cif* cif,
711
+ void (*fun)(ffi_cif*, void*, void**, void*),
712
+ void *user_data,
713
+ void *codeloc);
714
+ #endif
492
715
 
493
716
  ffi_status
494
717
  ffi_prep_closure_loc (ffi_closure* closure,
@@ -497,27 +720,31 @@ ffi_prep_closure_loc (ffi_closure* closure,
497
720
  void *user_data,
498
721
  void *codeloc)
499
722
  {
500
- volatile unsigned short *tramp;
501
-
502
- /* Sanity check on the cif ABI. */
503
- {
504
- int abi = cif->abi;
505
- if (UNLIKELY (! (abi > FFI_FIRST_ABI && abi < FFI_LAST_ABI)))
506
- return FFI_BAD_ABI;
507
- }
508
-
509
- tramp = (volatile unsigned short *) &closure->tramp[0];
723
+ static const unsigned char trampoline[16] = {
724
+ /* leaq -0x7(%rip),%r10 # 0x0 */
725
+ 0x4c, 0x8d, 0x15, 0xf9, 0xff, 0xff, 0xff,
726
+ /* jmpq *0x3(%rip) # 0x10 */
727
+ 0xff, 0x25, 0x03, 0x00, 0x00, 0x00,
728
+ /* nopl (%rax) */
729
+ 0x0f, 0x1f, 0x00
730
+ };
731
+ void (*dest)(void);
732
+ char *tramp = closure->tramp;
510
733
 
511
- tramp[0] = 0xbb49; /* mov <code>, %r11 */
512
- *(void * volatile *) &tramp[1] = ffi_closure_unix64;
513
- tramp[5] = 0xba49; /* mov <data>, %r10 */
514
- *(void * volatile *) &tramp[6] = codeloc;
734
+ #ifndef __ILP32__
735
+ if (cif->abi == FFI_EFI64)
736
+ return ffi_prep_closure_loc_efi64(closure, cif, fun, user_data, codeloc);
737
+ #endif
738
+ if (cif->abi != FFI_UNIX64)
739
+ return FFI_BAD_ABI;
515
740
 
516
- /* Set the carry bit iff the function uses any sse registers.
517
- This is clc or stc, together with the first byte of the jmp. */
518
- tramp[10] = cif->flags & (1 << 11) ? 0x49f9 : 0x49f8;
741
+ if (cif->flags & UNIX64_FLAG_XMM_ARGS)
742
+ dest = ffi_closure_unix64_sse;
743
+ else
744
+ dest = ffi_closure_unix64;
519
745
 
520
- tramp[11] = 0xe3ff; /* jmp *%r11 */
746
+ memcpy (tramp, trampoline, sizeof(trampoline));
747
+ *(UINT64 *)(tramp + 16) = (uintptr_t)dest;
521
748
 
522
749
  closure->cif = cif;
523
750
  closure->fun = fun;
@@ -526,53 +753,40 @@ ffi_prep_closure_loc (ffi_closure* closure,
526
753
  return FFI_OK;
527
754
  }
528
755
 
529
- int
530
- ffi_closure_unix64_inner(ffi_closure *closure, void *rvalue,
531
- struct register_args *reg_args, char *argp)
756
+ int FFI_HIDDEN
757
+ ffi_closure_unix64_inner(ffi_cif *cif,
758
+ void (*fun)(ffi_cif*, void*, void**, void*),
759
+ void *user_data,
760
+ void *rvalue,
761
+ struct register_args *reg_args,
762
+ char *argp)
532
763
  {
533
- ffi_cif *cif;
534
764
  void **avalue;
535
765
  ffi_type **arg_types;
536
766
  long i, avn;
537
767
  int gprcount, ssecount, ngpr, nsse;
538
- int ret;
768
+ int flags;
539
769
 
540
- cif = closure->cif;
541
- avalue = alloca(cif->nargs * sizeof(void *));
770
+ avn = cif->nargs;
771
+ flags = cif->flags;
772
+ avalue = alloca(avn * sizeof(void *));
542
773
  gprcount = ssecount = 0;
543
774
 
544
- ret = cif->rtype->type;
545
- if (ret != FFI_TYPE_VOID)
775
+ if (flags & UNIX64_FLAG_RET_IN_MEM)
546
776
  {
547
- enum x86_64_reg_class classes[MAX_CLASSES];
548
- int n = examine_argument (cif->rtype, classes, 1, &ngpr, &nsse);
549
- if (n == 0)
550
- {
551
- /* The return value goes in memory. Arrange for the closure
552
- return value to go directly back to the original caller. */
553
- rvalue = (void *) reg_args->gpr[gprcount++];
554
- /* We don't have to do anything in asm for the return. */
555
- ret = FFI_TYPE_VOID;
556
- }
557
- else if (ret == FFI_TYPE_STRUCT && n == 2)
558
- {
559
- /* Mark which register the second word of the structure goes in. */
560
- _Bool sse0 = SSE_CLASS_P (classes[0]);
561
- _Bool sse1 = SSE_CLASS_P (classes[1]);
562
- if (!sse0 && sse1)
563
- ret |= 1 << 8;
564
- else if (sse0 && !sse1)
565
- ret |= 1 << 9;
566
- }
777
+ /* On return, %rax will contain the address that was passed
778
+ by the caller in %rdi. */
779
+ void *r = (void *)(uintptr_t)reg_args->gpr[gprcount++];
780
+ *(void **)rvalue = r;
781
+ rvalue = r;
782
+ flags = (sizeof(void *) == 4 ? UNIX64_RET_UINT32 : UNIX64_RET_INT64);
567
783
  }
568
784
 
569
- avn = cif->nargs;
570
785
  arg_types = cif->arg_types;
571
-
572
786
  for (i = 0; i < avn; ++i)
573
787
  {
574
788
  enum x86_64_reg_class classes[MAX_CLASSES];
575
- int n;
789
+ size_t n;
576
790
 
577
791
  n = examine_argument (arg_types[i], classes, 0, &ngpr, &nsse);
578
792
  if (n == 0
@@ -586,7 +800,7 @@ ffi_closure_unix64_inner(ffi_closure *closure, void *rvalue,
586
800
  align = 8;
587
801
 
588
802
  /* Pass this argument in memory. */
589
- argp = (void *) ALIGN (argp, align);
803
+ argp = (void *) FFI_ALIGN (argp, align);
590
804
  avalue[i] = argp;
591
805
  argp += arg_types[i]->size;
592
806
  }
@@ -612,7 +826,7 @@ ffi_closure_unix64_inner(ffi_closure *closure, void *rvalue,
612
826
  else
613
827
  {
614
828
  char *a = alloca (16);
615
- int j;
829
+ unsigned int j;
616
830
 
617
831
  avalue[i] = a;
618
832
  for (j = 0; j < n; j++, a += 8)
@@ -626,10 +840,39 @@ ffi_closure_unix64_inner(ffi_closure *closure, void *rvalue,
626
840
  }
627
841
 
628
842
  /* Invoke the closure. */
629
- closure->fun (cif, rvalue, avalue, closure->user_data);
843
+ fun (cif, rvalue, avalue, user_data);
630
844
 
631
845
  /* Tell assembly how to perform return type promotions. */
632
- return ret;
846
+ return flags;
847
+ }
848
+
849
+ extern void ffi_go_closure_unix64(void) FFI_HIDDEN;
850
+ extern void ffi_go_closure_unix64_sse(void) FFI_HIDDEN;
851
+
852
+ #ifndef __ILP32__
853
+ extern ffi_status
854
+ ffi_prep_go_closure_efi64(ffi_go_closure* closure, ffi_cif* cif,
855
+ void (*fun)(ffi_cif*, void*, void**, void*));
856
+ #endif
857
+
858
+ ffi_status
859
+ ffi_prep_go_closure (ffi_go_closure* closure, ffi_cif* cif,
860
+ void (*fun)(ffi_cif*, void*, void**, void*))
861
+ {
862
+ #ifndef __ILP32__
863
+ if (cif->abi == FFI_EFI64)
864
+ return ffi_prep_go_closure_efi64(closure, cif, fun);
865
+ #endif
866
+ if (cif->abi != FFI_UNIX64)
867
+ return FFI_BAD_ABI;
868
+
869
+ closure->tramp = (cif->flags & UNIX64_FLAG_XMM_ARGS
870
+ ? ffi_go_closure_unix64_sse
871
+ : ffi_go_closure_unix64);
872
+ closure->cif = cif;
873
+ closure->fun = fun;
874
+
875
+ return FFI_OK;
633
876
  }
634
877
 
635
878
  #endif /* __x86_64__ */