ffi 1.9.3-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 (436) hide show
  1. data/COPYING +49 -0
  2. data/LICENSE +24 -0
  3. data/README.md +109 -0
  4. data/Rakefile +220 -0
  5. data/ext/ffi_c/AbstractMemory.c +1032 -0
  6. data/ext/ffi_c/AbstractMemory.h +175 -0
  7. data/ext/ffi_c/ArrayType.c +162 -0
  8. data/ext/ffi_c/ArrayType.h +59 -0
  9. data/ext/ffi_c/Buffer.c +365 -0
  10. data/ext/ffi_c/Call.c +465 -0
  11. data/ext/ffi_c/Call.h +93 -0
  12. data/ext/ffi_c/ClosurePool.c +283 -0
  13. data/ext/ffi_c/ClosurePool.h +57 -0
  14. data/ext/ffi_c/DataConverter.c +91 -0
  15. data/ext/ffi_c/DynamicLibrary.c +333 -0
  16. data/ext/ffi_c/DynamicLibrary.h +49 -0
  17. data/ext/ffi_c/Function.c +999 -0
  18. data/ext/ffi_c/Function.h +87 -0
  19. data/ext/ffi_c/FunctionInfo.c +271 -0
  20. data/ext/ffi_c/LastError.c +184 -0
  21. data/ext/ffi_c/LastError.h +47 -0
  22. data/ext/ffi_c/LongDouble.c +63 -0
  23. data/ext/ffi_c/LongDouble.h +51 -0
  24. data/ext/ffi_c/MappedType.c +168 -0
  25. data/ext/ffi_c/MappedType.h +59 -0
  26. data/ext/ffi_c/MemoryPointer.c +197 -0
  27. data/ext/ffi_c/MemoryPointer.h +53 -0
  28. data/ext/ffi_c/MethodHandle.c +360 -0
  29. data/ext/ffi_c/MethodHandle.h +55 -0
  30. data/ext/ffi_c/Platform.c +121 -0
  31. data/ext/ffi_c/Platform.h +45 -0
  32. data/ext/ffi_c/Pointer.c +508 -0
  33. data/ext/ffi_c/Pointer.h +63 -0
  34. data/ext/ffi_c/Struct.c +828 -0
  35. data/ext/ffi_c/Struct.h +106 -0
  36. data/ext/ffi_c/StructByReference.c +190 -0
  37. data/ext/ffi_c/StructByReference.h +50 -0
  38. data/ext/ffi_c/StructByValue.c +150 -0
  39. data/ext/ffi_c/StructByValue.h +55 -0
  40. data/ext/ffi_c/StructLayout.c +698 -0
  41. data/ext/ffi_c/Thread.c +352 -0
  42. data/ext/ffi_c/Thread.h +95 -0
  43. data/ext/ffi_c/Type.c +397 -0
  44. data/ext/ffi_c/Type.h +62 -0
  45. data/ext/ffi_c/Types.c +139 -0
  46. data/ext/ffi_c/Types.h +89 -0
  47. data/ext/ffi_c/Variadic.c +276 -0
  48. data/ext/ffi_c/compat.h +83 -0
  49. data/ext/ffi_c/extconf.rb +64 -0
  50. data/ext/ffi_c/ffi.c +98 -0
  51. data/ext/ffi_c/libffi.bsd.mk +34 -0
  52. data/ext/ffi_c/libffi.darwin.mk +95 -0
  53. data/ext/ffi_c/libffi.gnu.mk +31 -0
  54. data/ext/ffi_c/libffi.mk +13 -0
  55. data/ext/ffi_c/libffi.vc.mk +26 -0
  56. data/ext/ffi_c/libffi.vc64.mk +26 -0
  57. data/ext/ffi_c/libffi/ChangeLog +4600 -0
  58. data/ext/ffi_c/libffi/ChangeLog.libffi +584 -0
  59. data/ext/ffi_c/libffi/ChangeLog.libgcj +40 -0
  60. data/ext/ffi_c/libffi/ChangeLog.v1 +764 -0
  61. data/ext/ffi_c/libffi/LICENSE +21 -0
  62. data/ext/ffi_c/libffi/Makefile.am +196 -0
  63. data/ext/ffi_c/libffi/Makefile.in +1820 -0
  64. data/ext/ffi_c/libffi/Makefile.vc +141 -0
  65. data/ext/ffi_c/libffi/Makefile.vc64 +141 -0
  66. data/ext/ffi_c/libffi/README +342 -0
  67. data/ext/ffi_c/libffi/acinclude.m4 +92 -0
  68. data/ext/ffi_c/libffi/aclocal.m4 +1873 -0
  69. data/ext/ffi_c/libffi/build-ios.sh +67 -0
  70. data/ext/ffi_c/libffi/compile +143 -0
  71. data/ext/ffi_c/libffi/config.guess +1501 -0
  72. data/ext/ffi_c/libffi/config.sub +1705 -0
  73. data/ext/ffi_c/libffi/configure +17191 -0
  74. data/ext/ffi_c/libffi/configure.ac +496 -0
  75. data/ext/ffi_c/libffi/configure.host +11 -0
  76. data/ext/ffi_c/libffi/depcomp +630 -0
  77. data/ext/ffi_c/libffi/doc/libffi.info +593 -0
  78. data/ext/ffi_c/libffi/doc/libffi.texi +600 -0
  79. data/ext/ffi_c/libffi/doc/stamp-vti +4 -0
  80. data/ext/ffi_c/libffi/doc/version.texi +4 -0
  81. data/ext/ffi_c/libffi/fficonfig.h.in +199 -0
  82. data/ext/ffi_c/libffi/fficonfig.hw +57 -0
  83. data/ext/ffi_c/libffi/include/Makefile.am +9 -0
  84. data/ext/ffi_c/libffi/include/Makefile.in +487 -0
  85. data/ext/ffi_c/libffi/include/ffi.h.in +427 -0
  86. data/ext/ffi_c/libffi/include/ffi.h.vc +427 -0
  87. data/ext/ffi_c/libffi/include/ffi.h.vc64 +427 -0
  88. data/ext/ffi_c/libffi/include/ffi_common.h +126 -0
  89. data/ext/ffi_c/libffi/install-sh +520 -0
  90. data/ext/ffi_c/libffi/libffi.pc.in +10 -0
  91. data/ext/ffi_c/libffi/libtool-version +29 -0
  92. data/ext/ffi_c/libffi/ltmain.sh +9636 -0
  93. data/ext/ffi_c/libffi/m4/ax_cc_maxopt.m4 +176 -0
  94. data/ext/ffi_c/libffi/m4/ax_cflags_warn_all.m4 +195 -0
  95. data/ext/ffi_c/libffi/m4/ax_check_compiler_flags.m4 +76 -0
  96. data/ext/ffi_c/libffi/m4/ax_compiler_vendor.m4 +63 -0
  97. data/ext/ffi_c/libffi/m4/ax_configure_args.m4 +70 -0
  98. data/ext/ffi_c/libffi/m4/ax_enable_builddir.m4 +300 -0
  99. data/ext/ffi_c/libffi/m4/ax_gcc_archflag.m4 +215 -0
  100. data/ext/ffi_c/libffi/m4/ax_gcc_x86_cpuid.m4 +79 -0
  101. data/ext/ffi_c/libffi/m4/libtool.m4 +7831 -0
  102. data/ext/ffi_c/libffi/m4/ltoptions.m4 +369 -0
  103. data/ext/ffi_c/libffi/m4/ltsugar.m4 +123 -0
  104. data/ext/ffi_c/libffi/m4/ltversion.m4 +23 -0
  105. data/ext/ffi_c/libffi/m4/lt~obsolete.m4 +98 -0
  106. data/ext/ffi_c/libffi/man/Makefile.am +8 -0
  107. data/ext/ffi_c/libffi/man/Makefile.in +466 -0
  108. data/ext/ffi_c/libffi/man/ffi.3 +31 -0
  109. data/ext/ffi_c/libffi/man/ffi_call.3 +103 -0
  110. data/ext/ffi_c/libffi/man/ffi_prep_cif.3 +66 -0
  111. data/ext/ffi_c/libffi/mdate-sh +201 -0
  112. data/ext/ffi_c/libffi/missing +376 -0
  113. data/ext/ffi_c/libffi/msvcc.sh +197 -0
  114. data/ext/ffi_c/libffi/src/alpha/ffi.c +284 -0
  115. data/ext/ffi_c/libffi/src/alpha/ffitarget.h +48 -0
  116. data/ext/ffi_c/libffi/src/alpha/osf.S +387 -0
  117. data/ext/ffi_c/libffi/src/arm/ffi.c +728 -0
  118. data/ext/ffi_c/libffi/src/arm/ffitarget.h +65 -0
  119. data/ext/ffi_c/libffi/src/arm/gentramp.sh +118 -0
  120. data/ext/ffi_c/libffi/src/arm/sysv.S +497 -0
  121. data/ext/ffi_c/libffi/src/arm/trampoline.S +4450 -0
  122. data/ext/ffi_c/libffi/src/avr32/ffi.c +423 -0
  123. data/ext/ffi_c/libffi/src/avr32/ffitarget.h +50 -0
  124. data/ext/ffi_c/libffi/src/avr32/sysv.S +208 -0
  125. data/ext/ffi_c/libffi/src/closures.c +615 -0
  126. data/ext/ffi_c/libffi/src/cris/ffi.c +383 -0
  127. data/ext/ffi_c/libffi/src/cris/ffitarget.h +51 -0
  128. data/ext/ffi_c/libffi/src/cris/sysv.S +215 -0
  129. data/ext/ffi_c/libffi/src/debug.c +59 -0
  130. data/ext/ffi_c/libffi/src/dlmalloc.c +5161 -0
  131. data/ext/ffi_c/libffi/src/frv/eabi.S +128 -0
  132. data/ext/ffi_c/libffi/src/frv/ffi.c +292 -0
  133. data/ext/ffi_c/libffi/src/frv/ffitarget.h +57 -0
  134. data/ext/ffi_c/libffi/src/ia64/ffi.c +582 -0
  135. data/ext/ffi_c/libffi/src/ia64/ffitarget.h +50 -0
  136. data/ext/ffi_c/libffi/src/ia64/ia64_flags.h +40 -0
  137. data/ext/ffi_c/libffi/src/ia64/unix.S +560 -0
  138. data/ext/ffi_c/libffi/src/java_raw_api.c +356 -0
  139. data/ext/ffi_c/libffi/src/m32r/ffi.c +232 -0
  140. data/ext/ffi_c/libffi/src/m32r/ffitarget.h +48 -0
  141. data/ext/ffi_c/libffi/src/m32r/sysv.S +121 -0
  142. data/ext/ffi_c/libffi/src/m68k/ffi.c +288 -0
  143. data/ext/ffi_c/libffi/src/m68k/ffitarget.h +49 -0
  144. data/ext/ffi_c/libffi/src/m68k/sysv.S +270 -0
  145. data/ext/ffi_c/libffi/src/mips/ffi.c +1036 -0
  146. data/ext/ffi_c/libffi/src/mips/ffitarget.h +242 -0
  147. data/ext/ffi_c/libffi/src/mips/n32.S +591 -0
  148. data/ext/ffi_c/libffi/src/mips/o32.S +381 -0
  149. data/ext/ffi_c/libffi/src/moxie/eabi.S +128 -0
  150. data/ext/ffi_c/libffi/src/moxie/ffi.c +276 -0
  151. data/ext/ffi_c/libffi/src/pa/ffi.c +719 -0
  152. data/ext/ffi_c/libffi/src/pa/ffitarget.h +78 -0
  153. data/ext/ffi_c/libffi/src/pa/hpux32.S +368 -0
  154. data/ext/ffi_c/libffi/src/pa/linux.S +357 -0
  155. data/ext/ffi_c/libffi/src/powerpc/aix.S +328 -0
  156. data/ext/ffi_c/libffi/src/powerpc/aix_closure.S +445 -0
  157. data/ext/ffi_c/libffi/src/powerpc/asm.h +125 -0
  158. data/ext/ffi_c/libffi/src/powerpc/darwin.S +383 -0
  159. data/ext/ffi_c/libffi/src/powerpc/darwin_closure.S +575 -0
  160. data/ext/ffi_c/libffi/src/powerpc/ffi.c +1448 -0
  161. data/ext/ffi_c/libffi/src/powerpc/ffi_darwin.c +1359 -0
  162. data/ext/ffi_c/libffi/src/powerpc/ffitarget.h +139 -0
  163. data/ext/ffi_c/libffi/src/powerpc/linux64.S +187 -0
  164. data/ext/ffi_c/libffi/src/powerpc/linux64_closure.S +236 -0
  165. data/ext/ffi_c/libffi/src/powerpc/ppc_closure.S +327 -0
  166. data/ext/ffi_c/libffi/src/powerpc/sysv.S +219 -0
  167. data/ext/ffi_c/libffi/src/prep_cif.c +177 -0
  168. data/ext/ffi_c/libffi/src/raw_api.c +254 -0
  169. data/ext/ffi_c/libffi/src/s390/ffi.c +780 -0
  170. data/ext/ffi_c/libffi/src/s390/ffitarget.h +62 -0
  171. data/ext/ffi_c/libffi/src/s390/sysv.S +434 -0
  172. data/ext/ffi_c/libffi/src/sh/ffi.c +716 -0
  173. data/ext/ffi_c/libffi/src/sh/ffitarget.h +49 -0
  174. data/ext/ffi_c/libffi/src/sh/sysv.S +850 -0
  175. data/ext/ffi_c/libffi/src/sh64/ffi.c +468 -0
  176. data/ext/ffi_c/libffi/src/sh64/ffitarget.h +53 -0
  177. data/ext/ffi_c/libffi/src/sh64/sysv.S +539 -0
  178. data/ext/ffi_c/libffi/src/sparc/ffi.c +669 -0
  179. data/ext/ffi_c/libffi/src/sparc/ffitarget.h +68 -0
  180. data/ext/ffi_c/libffi/src/sparc/v8.S +313 -0
  181. data/ext/ffi_c/libffi/src/sparc/v9.S +307 -0
  182. data/ext/ffi_c/libffi/src/types.c +77 -0
  183. data/ext/ffi_c/libffi/src/x86/darwin.S +444 -0
  184. data/ext/ffi_c/libffi/src/x86/darwin64.S +416 -0
  185. data/ext/ffi_c/libffi/src/x86/ffi.c +644 -0
  186. data/ext/ffi_c/libffi/src/x86/ffi64.c +635 -0
  187. data/ext/ffi_c/libffi/src/x86/ffitarget.h +121 -0
  188. data/ext/ffi_c/libffi/src/x86/freebsd.S +458 -0
  189. data/ext/ffi_c/libffi/src/x86/sysv.S +468 -0
  190. data/ext/ffi_c/libffi/src/x86/unix64.S +426 -0
  191. data/ext/ffi_c/libffi/src/x86/win32.S +1065 -0
  192. data/ext/ffi_c/libffi/src/x86/win64.S +468 -0
  193. data/ext/ffi_c/libffi/testsuite/Makefile.am +80 -0
  194. data/ext/ffi_c/libffi/testsuite/Makefile.in +500 -0
  195. data/ext/ffi_c/libffi/testsuite/config/default.exp +1 -0
  196. data/ext/ffi_c/libffi/testsuite/lib/libffi-dg.exp +300 -0
  197. data/ext/ffi_c/libffi/testsuite/lib/libffi.exp +350 -0
  198. data/ext/ffi_c/libffi/testsuite/lib/target-libpath.exp +263 -0
  199. data/ext/ffi_c/libffi/testsuite/lib/wrapper.exp +45 -0
  200. data/ext/ffi_c/libffi/testsuite/libffi.call/call.exp +32 -0
  201. data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn0.c +89 -0
  202. data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn1.c +81 -0
  203. data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn2.c +81 -0
  204. data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn3.c +82 -0
  205. data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn4.c +89 -0
  206. data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn5.c +92 -0
  207. data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn6.c +90 -0
  208. data/ext/ffi_c/libffi/testsuite/libffi.call/closure_loc_fn0.c +95 -0
  209. data/ext/ffi_c/libffi/testsuite/libffi.call/closure_stdcall.c +64 -0
  210. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_12byte.c +94 -0
  211. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_16byte.c +95 -0
  212. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_18byte.c +96 -0
  213. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_19byte.c +102 -0
  214. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_1_1byte.c +89 -0
  215. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_20byte.c +91 -0
  216. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_20byte1.c +93 -0
  217. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_24byte.c +113 -0
  218. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_2byte.c +90 -0
  219. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_3_1byte.c +95 -0
  220. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_3byte1.c +90 -0
  221. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_3byte2.c +90 -0
  222. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_4_1byte.c +98 -0
  223. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_4byte.c +90 -0
  224. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_5_1_byte.c +109 -0
  225. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_5byte.c +98 -0
  226. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_64byte.c +124 -0
  227. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_6_1_byte.c +113 -0
  228. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_6byte.c +99 -0
  229. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_7_1_byte.c +117 -0
  230. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_7byte.c +97 -0
  231. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_8byte.c +88 -0
  232. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_9byte1.c +90 -0
  233. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_9byte2.c +91 -0
  234. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_double.c +93 -0
  235. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_float.c +91 -0
  236. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_longdouble.c +92 -0
  237. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_longdouble_split.c +134 -0
  238. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_longdouble_split2.c +117 -0
  239. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_pointer.c +95 -0
  240. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_sint16.c +91 -0
  241. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_sint32.c +91 -0
  242. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_sint64.c +92 -0
  243. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_uint16.c +91 -0
  244. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_uint32.c +91 -0
  245. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_uint64.c +93 -0
  246. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_dbls_struct.c +66 -0
  247. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_double.c +43 -0
  248. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_double_va.c +60 -0
  249. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_float.c +42 -0
  250. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_longdouble.c +105 -0
  251. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_longdouble_va.c +60 -0
  252. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_schar.c +74 -0
  253. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_sshort.c +74 -0
  254. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_sshortchar.c +86 -0
  255. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_uchar.c +91 -0
  256. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_ushort.c +74 -0
  257. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_ushortchar.c +86 -0
  258. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_pointer.c +74 -0
  259. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_pointer_stack.c +140 -0
  260. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_schar.c +44 -0
  261. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_sint.c +42 -0
  262. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_sshort.c +42 -0
  263. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_uchar.c +42 -0
  264. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_uint.c +43 -0
  265. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_ulonglong.c +47 -0
  266. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_ushort.c +43 -0
  267. data/ext/ffi_c/libffi/testsuite/libffi.call/err_bad_abi.c +36 -0
  268. data/ext/ffi_c/libffi/testsuite/libffi.call/err_bad_typedef.c +26 -0
  269. data/ext/ffi_c/libffi/testsuite/libffi.call/ffitest.h +153 -0
  270. data/ext/ffi_c/libffi/testsuite/libffi.call/float.c +59 -0
  271. data/ext/ffi_c/libffi/testsuite/libffi.call/float1.c +58 -0
  272. data/ext/ffi_c/libffi/testsuite/libffi.call/float2.c +58 -0
  273. data/ext/ffi_c/libffi/testsuite/libffi.call/float3.c +72 -0
  274. data/ext/ffi_c/libffi/testsuite/libffi.call/float4.c +62 -0
  275. data/ext/ffi_c/libffi/testsuite/libffi.call/huge_struct.c +342 -0
  276. data/ext/ffi_c/libffi/testsuite/libffi.call/many.c +69 -0
  277. data/ext/ffi_c/libffi/testsuite/libffi.call/many_win32.c +63 -0
  278. data/ext/ffi_c/libffi/testsuite/libffi.call/negint.c +53 -0
  279. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct.c +152 -0
  280. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct1.c +161 -0
  281. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct10.c +133 -0
  282. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct2.c +110 -0
  283. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct3.c +111 -0
  284. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct4.c +111 -0
  285. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct5.c +112 -0
  286. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct6.c +131 -0
  287. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct7.c +111 -0
  288. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct8.c +131 -0
  289. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct9.c +131 -0
  290. data/ext/ffi_c/libffi/testsuite/libffi.call/problem1.c +90 -0
  291. data/ext/ffi_c/libffi/testsuite/libffi.call/promotion.c +59 -0
  292. data/ext/ffi_c/libffi/testsuite/libffi.call/pyobjc-tc.c +114 -0
  293. data/ext/ffi_c/libffi/testsuite/libffi.call/return_dbl.c +35 -0
  294. data/ext/ffi_c/libffi/testsuite/libffi.call/return_dbl1.c +43 -0
  295. data/ext/ffi_c/libffi/testsuite/libffi.call/return_dbl2.c +42 -0
  296. data/ext/ffi_c/libffi/testsuite/libffi.call/return_fl.c +35 -0
  297. data/ext/ffi_c/libffi/testsuite/libffi.call/return_fl1.c +36 -0
  298. data/ext/ffi_c/libffi/testsuite/libffi.call/return_fl2.c +49 -0
  299. data/ext/ffi_c/libffi/testsuite/libffi.call/return_fl3.c +42 -0
  300. data/ext/ffi_c/libffi/testsuite/libffi.call/return_ldl.c +34 -0
  301. data/ext/ffi_c/libffi/testsuite/libffi.call/return_ll.c +41 -0
  302. data/ext/ffi_c/libffi/testsuite/libffi.call/return_ll1.c +43 -0
  303. data/ext/ffi_c/libffi/testsuite/libffi.call/return_sc.c +36 -0
  304. data/ext/ffi_c/libffi/testsuite/libffi.call/return_sl.c +38 -0
  305. data/ext/ffi_c/libffi/testsuite/libffi.call/return_uc.c +38 -0
  306. data/ext/ffi_c/libffi/testsuite/libffi.call/return_ul.c +38 -0
  307. data/ext/ffi_c/libffi/testsuite/libffi.call/stret_large.c +145 -0
  308. data/ext/ffi_c/libffi/testsuite/libffi.call/stret_large2.c +148 -0
  309. data/ext/ffi_c/libffi/testsuite/libffi.call/stret_medium.c +124 -0
  310. data/ext/ffi_c/libffi/testsuite/libffi.call/stret_medium2.c +125 -0
  311. data/ext/ffi_c/libffi/testsuite/libffi.call/strlen.c +44 -0
  312. data/ext/ffi_c/libffi/testsuite/libffi.call/strlen_win32.c +44 -0
  313. data/ext/ffi_c/libffi/testsuite/libffi.call/struct1.c +65 -0
  314. data/ext/ffi_c/libffi/testsuite/libffi.call/struct2.c +67 -0
  315. data/ext/ffi_c/libffi/testsuite/libffi.call/struct3.c +59 -0
  316. data/ext/ffi_c/libffi/testsuite/libffi.call/struct4.c +63 -0
  317. data/ext/ffi_c/libffi/testsuite/libffi.call/struct5.c +65 -0
  318. data/ext/ffi_c/libffi/testsuite/libffi.call/struct6.c +64 -0
  319. data/ext/ffi_c/libffi/testsuite/libffi.call/struct7.c +74 -0
  320. data/ext/ffi_c/libffi/testsuite/libffi.call/struct8.c +80 -0
  321. data/ext/ffi_c/libffi/testsuite/libffi.call/struct9.c +67 -0
  322. data/ext/ffi_c/libffi/testsuite/libffi.call/testclosure.c +70 -0
  323. data/ext/ffi_c/libffi/testsuite/libffi.special/ffitestcxx.h +96 -0
  324. data/ext/ffi_c/libffi/testsuite/libffi.special/special.exp +35 -0
  325. data/ext/ffi_c/libffi/testsuite/libffi.special/unwindtest.cc +124 -0
  326. data/ext/ffi_c/libffi/testsuite/libffi.special/unwindtest_ffi_call.cc +53 -0
  327. data/ext/ffi_c/libffi/texinfo.tex +7210 -0
  328. data/ext/ffi_c/rbffi.h +57 -0
  329. data/ext/ffi_c/rbffi_endian.h +59 -0
  330. data/ext/ffi_c/win32/stdbool.h +8 -0
  331. data/ext/ffi_c/win32/stdint.h +201 -0
  332. data/ffi.gemspec +22 -0
  333. data/gen/Rakefile +30 -0
  334. data/lib/ffi.rb +28 -0
  335. data/lib/ffi/autopointer.rb +194 -0
  336. data/lib/ffi/buffer.rb +4 -0
  337. data/lib/ffi/callback.rb +4 -0
  338. data/lib/ffi/enum.rb +173 -0
  339. data/lib/ffi/errno.rb +43 -0
  340. data/lib/ffi/ffi.rb +44 -0
  341. data/lib/ffi/io.rb +62 -0
  342. data/lib/ffi/library.rb +499 -0
  343. data/lib/ffi/managedstruct.rb +84 -0
  344. data/lib/ffi/memorypointer.rb +1 -0
  345. data/lib/ffi/platform.rb +148 -0
  346. data/lib/ffi/platform/arm-linux/types.conf +104 -0
  347. data/lib/ffi/platform/i386-cygwin/types.conf +3 -0
  348. data/lib/ffi/platform/i386-darwin/types.conf +100 -0
  349. data/lib/ffi/platform/i386-freebsd/types.conf +152 -0
  350. data/lib/ffi/platform/i386-gnu/types.conf +107 -0
  351. data/lib/ffi/platform/i386-linux/types.conf +103 -0
  352. data/lib/ffi/platform/i386-netbsd/types.conf +126 -0
  353. data/lib/ffi/platform/i386-openbsd/types.conf +128 -0
  354. data/lib/ffi/platform/i386-solaris/types.conf +122 -0
  355. data/lib/ffi/platform/i386-windows/types.conf +105 -0
  356. data/lib/ffi/platform/ia64-linux/types.conf +104 -0
  357. data/lib/ffi/platform/mips-linux/types.conf +102 -0
  358. data/lib/ffi/platform/mipsel-linux/types.conf +102 -0
  359. data/lib/ffi/platform/powerpc-aix/types.conf +180 -0
  360. data/lib/ffi/platform/powerpc-darwin/types.conf +100 -0
  361. data/lib/ffi/platform/powerpc-linux/types.conf +100 -0
  362. data/lib/ffi/platform/s390-linux/types.conf +102 -0
  363. data/lib/ffi/platform/s390x-linux/types.conf +102 -0
  364. data/lib/ffi/platform/sparc-linux/types.conf +102 -0
  365. data/lib/ffi/platform/sparc-solaris/types.conf +128 -0
  366. data/lib/ffi/platform/sparcv9-solaris/types.conf +128 -0
  367. data/lib/ffi/platform/x86_64-cygwin/types.conf +3 -0
  368. data/lib/ffi/platform/x86_64-darwin/types.conf +100 -0
  369. data/lib/ffi/platform/x86_64-freebsd/types.conf +128 -0
  370. data/lib/ffi/platform/x86_64-linux/types.conf +102 -0
  371. data/lib/ffi/platform/x86_64-netbsd/types.conf +126 -0
  372. data/lib/ffi/platform/x86_64-openbsd/types.conf +128 -0
  373. data/lib/ffi/platform/x86_64-solaris/types.conf +122 -0
  374. data/lib/ffi/platform/x86_64-windows/types.conf +27 -0
  375. data/lib/ffi/pointer.rb +134 -0
  376. data/lib/ffi/struct.rb +367 -0
  377. data/lib/ffi/struct_layout_builder.rb +222 -0
  378. data/lib/ffi/tools/const_generator.rb +229 -0
  379. data/lib/ffi/tools/generator.rb +60 -0
  380. data/lib/ffi/tools/generator_task.rb +36 -0
  381. data/lib/ffi/tools/struct_generator.rb +194 -0
  382. data/lib/ffi/tools/types_generator.rb +135 -0
  383. data/lib/ffi/types.rb +190 -0
  384. data/lib/ffi/union.rb +43 -0
  385. data/lib/ffi/variadic.rb +78 -0
  386. data/lib/ffi/version.rb +4 -0
  387. data/lib/ffi_c.so +0 -0
  388. data/libtest/Benchmark.c +52 -0
  389. data/libtest/BoolTest.c +34 -0
  390. data/libtest/BufferTest.c +31 -0
  391. data/libtest/ClosureTest.c +190 -0
  392. data/libtest/EnumTest.c +34 -0
  393. data/libtest/FunctionTest.c +58 -0
  394. data/libtest/GNUmakefile +149 -0
  395. data/libtest/GlobalVariable.c +62 -0
  396. data/libtest/LastErrorTest.c +21 -0
  397. data/libtest/NumberTest.c +132 -0
  398. data/libtest/PointerTest.c +63 -0
  399. data/libtest/ReferenceTest.c +23 -0
  400. data/libtest/StringTest.c +34 -0
  401. data/libtest/StructTest.c +243 -0
  402. data/libtest/UnionTest.c +43 -0
  403. data/libtest/VariadicTest.c +62 -0
  404. data/spec/ffi/async_callback_spec.rb +35 -0
  405. data/spec/ffi/bool_spec.rb +29 -0
  406. data/spec/ffi/buffer_spec.rb +251 -0
  407. data/spec/ffi/callback_spec.rb +667 -0
  408. data/spec/ffi/custom_param_type.rb +36 -0
  409. data/spec/ffi/custom_type_spec.rb +74 -0
  410. data/spec/ffi/dup_spec.rb +54 -0
  411. data/spec/ffi/enum_spec.rb +220 -0
  412. data/spec/ffi/errno_spec.rb +18 -0
  413. data/spec/ffi/ffi_spec.rb +29 -0
  414. data/spec/ffi/function_spec.rb +76 -0
  415. data/spec/ffi/library_spec.rb +216 -0
  416. data/spec/ffi/long_double.rb +30 -0
  417. data/spec/ffi/managed_struct_spec.rb +57 -0
  418. data/spec/ffi/number_spec.rb +236 -0
  419. data/spec/ffi/pointer_spec.rb +265 -0
  420. data/spec/ffi/rbx/attach_function_spec.rb +28 -0
  421. data/spec/ffi/rbx/memory_pointer_spec.rb +123 -0
  422. data/spec/ffi/rbx/spec_helper.rb +1 -0
  423. data/spec/ffi/rbx/struct_spec.rb +13 -0
  424. data/spec/ffi/spec_helper.rb +33 -0
  425. data/spec/ffi/string_spec.rb +108 -0
  426. data/spec/ffi/strptr_spec.rb +50 -0
  427. data/spec/ffi/struct_by_ref_spec.rb +43 -0
  428. data/spec/ffi/struct_callback_spec.rb +69 -0
  429. data/spec/ffi/struct_initialize_spec.rb +35 -0
  430. data/spec/ffi/struct_packed_spec.rb +51 -0
  431. data/spec/ffi/struct_spec.rb +748 -0
  432. data/spec/ffi/typedef_spec.rb +78 -0
  433. data/spec/ffi/union_spec.rb +65 -0
  434. data/spec/ffi/variadic_spec.rb +92 -0
  435. data/spec/spec.opts +4 -0
  436. metadata +562 -0
@@ -0,0 +1,49 @@
1
+ /* -----------------------------------------------------------------*-C-*-
2
+ ffitarget.h - Copyright (c) 1996-2003 Red Hat, Inc.
3
+ Target configuration macros for Motorola 68K.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ ``Software''), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included
14
+ in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23
+ DEALINGS IN THE SOFTWARE.
24
+
25
+ ----------------------------------------------------------------------- */
26
+
27
+ #ifndef LIBFFI_TARGET_H
28
+ #define LIBFFI_TARGET_H
29
+
30
+ #ifndef LIBFFI_ASM
31
+ typedef unsigned long ffi_arg;
32
+ typedef signed long ffi_sarg;
33
+
34
+ typedef enum ffi_abi {
35
+ FFI_FIRST_ABI = 0,
36
+ FFI_SYSV,
37
+ FFI_LAST_ABI,
38
+ FFI_DEFAULT_ABI = FFI_SYSV
39
+ } ffi_abi;
40
+ #endif
41
+
42
+ /* ---- Definitions for closures ----------------------------------------- */
43
+
44
+ #define FFI_CLOSURES 1
45
+ #define FFI_TRAMPOLINE_SIZE 16
46
+ #define FFI_NATIVE_RAW_API 0
47
+
48
+ #endif
49
+
@@ -0,0 +1,270 @@
1
+ /* -----------------------------------------------------------------------
2
+
3
+ sysv.S - Copyright (c) 1998 Andreas Schwab
4
+ Copyright (c) 2008 Red Hat, Inc.
5
+
6
+ m68k Foreign Function Interface
7
+
8
+ Permission is hereby granted, free of charge, to any person obtaining
9
+ a copy of this software and associated documentation files (the
10
+ ``Software''), to deal in the Software without restriction, including
11
+ without limitation the rights to use, copy, modify, merge, publish,
12
+ distribute, sublicense, and/or sell copies of the Software, and to
13
+ permit persons to whom the Software is furnished to do so, subject to
14
+ the following conditions:
15
+
16
+ The above copyright notice and this permission notice shall be included
17
+ in all copies or substantial portions of the Software.
18
+
19
+ THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
20
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
23
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
24
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26
+ DEALINGS IN THE SOFTWARE.
27
+ ----------------------------------------------------------------------- */
28
+
29
+ #define LIBFFI_ASM
30
+ #include <fficonfig.h>
31
+ #include <ffi.h>
32
+
33
+ #ifdef HAVE_AS_CFI_PSEUDO_OP
34
+ #define CFI_STARTPROC() .cfi_startproc
35
+ #define CFI_OFFSET(reg,off) .cfi_offset reg,off
36
+ #define CFI_DEF_CFA(reg,off) .cfi_def_cfa reg,off
37
+ #define CFI_ENDPROC() .cfi_endproc
38
+ #else
39
+ #define CFI_STARTPROC()
40
+ #define CFI_OFFSET(reg,off)
41
+ #define CFI_DEF_CFA(reg,off)
42
+ #define CFI_ENDPROC()
43
+ #endif
44
+
45
+ .text
46
+
47
+ .globl ffi_call_SYSV
48
+ .type ffi_call_SYSV,@function
49
+ .align 4
50
+
51
+ ffi_call_SYSV:
52
+ CFI_STARTPROC()
53
+ link %fp,#0
54
+ CFI_OFFSET(14,-8)
55
+ CFI_DEF_CFA(14,8)
56
+ move.l %d2,-(%sp)
57
+ CFI_OFFSET(2,-12)
58
+
59
+ | Make room for all of the new args.
60
+ sub.l 12(%fp),%sp
61
+
62
+ | Call ffi_prep_args
63
+ move.l 8(%fp),-(%sp)
64
+ pea 4(%sp)
65
+ #if !defined __PIC__
66
+ jsr ffi_prep_args
67
+ #else
68
+ bsr.l ffi_prep_args@PLTPC
69
+ #endif
70
+ addq.l #8,%sp
71
+
72
+ | Pass pointer to struct value, if any
73
+ move.l %a0,%a1
74
+
75
+ | Call the function
76
+ move.l 24(%fp),%a0
77
+ jsr (%a0)
78
+
79
+ | Remove the space we pushed for the args
80
+ add.l 12(%fp),%sp
81
+
82
+ | Load the pointer to storage for the return value
83
+ move.l 20(%fp),%a1
84
+
85
+ | Load the return type code
86
+ move.l 16(%fp),%d2
87
+
88
+ | If the return value pointer is NULL, assume no return value.
89
+ | NOTE: On the mc68000, tst on an address register is not supported.
90
+ #if defined(__mc68000__) && !defined(__mcoldfire__)
91
+ cmp.w #0, %a1
92
+ #else
93
+ tst.l %a1
94
+ #endif
95
+ jbeq noretval
96
+
97
+ btst #0,%d2
98
+ jbeq retlongint
99
+ move.l %d0,(%a1)
100
+ jbra epilogue
101
+
102
+ retlongint:
103
+ btst #1,%d2
104
+ jbeq retfloat
105
+ move.l %d0,(%a1)
106
+ move.l %d1,4(%a1)
107
+ jbra epilogue
108
+
109
+ retfloat:
110
+ btst #2,%d2
111
+ jbeq retdouble
112
+ #if defined(__MC68881__)
113
+ fmove.s %fp0,(%a1)
114
+ #else
115
+ move.l %d0,(%a1)
116
+ #endif
117
+ jbra epilogue
118
+
119
+ retdouble:
120
+ btst #3,%d2
121
+ jbeq retlongdouble
122
+ #if defined(__MC68881__)
123
+ fmove.d %fp0,(%a1)
124
+ #else
125
+ move.l %d0,(%a1)+
126
+ move.l %d1,(%a1)
127
+ #endif
128
+ jbra epilogue
129
+
130
+ retlongdouble:
131
+ btst #4,%d2
132
+ jbeq retpointer
133
+ #if defined(__MC68881__)
134
+ fmove.x %fp0,(%a1)
135
+ #else
136
+ move.l %d0,(%a1)+
137
+ move.l %d1,(%a1)+
138
+ move.l %d2,(%a1)
139
+ #endif
140
+ jbra epilogue
141
+
142
+ retpointer:
143
+ btst #5,%d2
144
+ jbeq retstruct1
145
+ move.l %a0,(%a1)
146
+ jbra epilogue
147
+
148
+ retstruct1:
149
+ btst #6,%d2
150
+ jbeq retstruct2
151
+ move.b %d0,(%a1)
152
+ jbra epilogue
153
+
154
+ retstruct2:
155
+ btst #7,%d2
156
+ jbeq noretval
157
+ move.w %d0,(%a1)
158
+
159
+ noretval:
160
+ epilogue:
161
+ move.l (%sp)+,%d2
162
+ unlk %fp
163
+ rts
164
+ CFI_ENDPROC()
165
+ .size ffi_call_SYSV,.-ffi_call_SYSV
166
+
167
+ .globl ffi_closure_SYSV
168
+ .type ffi_closure_SYSV, @function
169
+ .align 4
170
+
171
+ ffi_closure_SYSV:
172
+ CFI_STARTPROC()
173
+ link %fp,#-12
174
+ CFI_OFFSET(14,-8)
175
+ CFI_DEF_CFA(14,8)
176
+ move.l %sp,-12(%fp)
177
+ pea 8(%fp)
178
+ pea -12(%fp)
179
+ move.l %a0,-(%sp)
180
+ #if !defined __PIC__
181
+ jsr ffi_closure_SYSV_inner
182
+ #else
183
+ bsr.l ffi_closure_SYSV_inner@PLTPC
184
+ #endif
185
+
186
+ lsr.l #1,%d0
187
+ jne 1f
188
+ jcc .Lcls_epilogue
189
+ move.l -12(%fp),%d0
190
+ .Lcls_epilogue:
191
+ unlk %fp
192
+ rts
193
+ 1:
194
+ lea -12(%fp),%a0
195
+ lsr.l #2,%d0
196
+ jne 1f
197
+ jcs .Lcls_ret_float
198
+ move.l (%a0)+,%d0
199
+ move.l (%a0),%d1
200
+ jra .Lcls_epilogue
201
+ .Lcls_ret_float:
202
+ #if defined(__MC68881__)
203
+ fmove.s (%a0),%fp0
204
+ #else
205
+ move.l (%a0),%d0
206
+ #endif
207
+ jra .Lcls_epilogue
208
+ 1:
209
+ lsr.l #2,%d0
210
+ jne 1f
211
+ jcs .Lcls_ret_ldouble
212
+ #if defined(__MC68881__)
213
+ fmove.d (%a0),%fp0
214
+ #else
215
+ move.l (%a0)+,%d0
216
+ move.l (%a0),%d1
217
+ #endif
218
+ jra .Lcls_epilogue
219
+ .Lcls_ret_ldouble:
220
+ #if defined(__MC68881__)
221
+ fmove.x (%a0),%fp0
222
+ #else
223
+ move.l (%a0)+,%d0
224
+ move.l (%a0)+,%d1
225
+ move.l (%a0),%d2
226
+ #endif
227
+ jra .Lcls_epilogue
228
+ 1:
229
+ lsr.l #2,%d0
230
+ jne .Lcls_ret_struct2
231
+ jcs .Lcls_ret_struct1
232
+ move.l (%a0),%a0
233
+ move.l %a0,%d0
234
+ jra .Lcls_epilogue
235
+ .Lcls_ret_struct1:
236
+ move.b (%a0),%d0
237
+ jra .Lcls_epilogue
238
+ .Lcls_ret_struct2:
239
+ move.w (%a0),%d0
240
+ jra .Lcls_epilogue
241
+ CFI_ENDPROC()
242
+
243
+ .size ffi_closure_SYSV,.-ffi_closure_SYSV
244
+
245
+ .globl ffi_closure_struct_SYSV
246
+ .type ffi_closure_struct_SYSV, @function
247
+ .align 4
248
+
249
+ ffi_closure_struct_SYSV:
250
+ CFI_STARTPROC()
251
+ link %fp,#0
252
+ CFI_OFFSET(14,-8)
253
+ CFI_DEF_CFA(14,8)
254
+ move.l %sp,-12(%fp)
255
+ pea 8(%fp)
256
+ move.l %a1,-(%sp)
257
+ move.l %a0,-(%sp)
258
+ #if !defined __PIC__
259
+ jsr ffi_closure_SYSV_inner
260
+ #else
261
+ bsr.l ffi_closure_SYSV_inner@PLTPC
262
+ #endif
263
+ unlk %fp
264
+ rts
265
+ CFI_ENDPROC()
266
+ .size ffi_closure_struct_SYSV,.-ffi_closure_struct_SYSV
267
+
268
+ #if defined __ELF__ && defined __linux__
269
+ .section .note.GNU-stack,"",@progbits
270
+ #endif
@@ -0,0 +1,1036 @@
1
+ /* -----------------------------------------------------------------------
2
+ ffi.c - Copyright (c) 2011 Anthony Green
3
+ Copyright (c) 2008 David Daney
4
+ Copyright (c) 1996, 2007, 2008, 2011 Red Hat, Inc.
5
+
6
+ MIPS Foreign Function Interface
7
+
8
+ Permission is hereby granted, free of charge, to any person obtaining
9
+ a copy of this software and associated documentation files (the
10
+ ``Software''), to deal in the Software without restriction, including
11
+ without limitation the rights to use, copy, modify, merge, publish,
12
+ distribute, sublicense, and/or sell copies of the Software, and to
13
+ permit persons to whom the Software is furnished to do so, subject to
14
+ the following conditions:
15
+
16
+ The above copyright notice and this permission notice shall be included
17
+ in all copies or substantial portions of the Software.
18
+
19
+ THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
20
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
23
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
24
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26
+ DEALINGS IN THE SOFTWARE.
27
+ ----------------------------------------------------------------------- */
28
+
29
+ #include <ffi.h>
30
+ #include <ffi_common.h>
31
+
32
+ #include <stdlib.h>
33
+
34
+ #ifdef __GNUC__
35
+ # if (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 3))
36
+ # define USE__BUILTIN___CLEAR_CACHE 1
37
+ # endif
38
+ #endif
39
+
40
+ #ifndef USE__BUILTIN___CLEAR_CACHE
41
+ # if defined(__OpenBSD__)
42
+ # include <mips64/sysarch.h>
43
+ # else
44
+ # include <sys/cachectl.h>
45
+ # endif
46
+ #endif
47
+
48
+ #ifdef FFI_DEBUG
49
+ # define FFI_MIPS_STOP_HERE() ffi_stop_here()
50
+ #else
51
+ # define FFI_MIPS_STOP_HERE() do {} while(0)
52
+ #endif
53
+
54
+ #ifdef FFI_MIPS_N32
55
+ #define FIX_ARGP \
56
+ FFI_ASSERT(argp <= &stack[bytes]); \
57
+ if (argp == &stack[bytes]) \
58
+ { \
59
+ argp = stack; \
60
+ FFI_MIPS_STOP_HERE(); \
61
+ }
62
+ #else
63
+ #define FIX_ARGP
64
+ #endif
65
+
66
+
67
+ /* ffi_prep_args is called by the assembly routine once stack space
68
+ has been allocated for the function's arguments */
69
+
70
+ static void ffi_prep_args(char *stack,
71
+ extended_cif *ecif,
72
+ int bytes,
73
+ int flags)
74
+ {
75
+ int i;
76
+ void **p_argv;
77
+ char *argp;
78
+ ffi_type **p_arg;
79
+
80
+ #ifdef FFI_MIPS_N32
81
+ /* If more than 8 double words are used, the remainder go
82
+ on the stack. We reorder stuff on the stack here to
83
+ support this easily. */
84
+ if (bytes > 8 * sizeof(ffi_arg))
85
+ argp = &stack[bytes - (8 * sizeof(ffi_arg))];
86
+ else
87
+ argp = stack;
88
+ #else
89
+ argp = stack;
90
+ #endif
91
+
92
+ memset(stack, 0, bytes);
93
+
94
+ #ifdef FFI_MIPS_N32
95
+ if ( ecif->cif->rstruct_flag != 0 )
96
+ #else
97
+ if ( ecif->cif->rtype->type == FFI_TYPE_STRUCT )
98
+ #endif
99
+ {
100
+ *(ffi_arg *) argp = (ffi_arg) ecif->rvalue;
101
+ argp += sizeof(ffi_arg);
102
+ FIX_ARGP;
103
+ }
104
+
105
+ p_argv = ecif->avalue;
106
+
107
+ for (i = 0, p_arg = ecif->cif->arg_types; i < ecif->cif->nargs; i++, p_arg++)
108
+ {
109
+ size_t z;
110
+ unsigned int a;
111
+
112
+ /* Align if necessary. */
113
+ a = (*p_arg)->alignment;
114
+ if (a < sizeof(ffi_arg))
115
+ a = sizeof(ffi_arg);
116
+
117
+ if ((a - 1) & (unsigned long) argp)
118
+ {
119
+ argp = (char *) ALIGN(argp, a);
120
+ FIX_ARGP;
121
+ }
122
+
123
+ z = (*p_arg)->size;
124
+ if (z <= sizeof(ffi_arg))
125
+ {
126
+ int type = (*p_arg)->type;
127
+ z = sizeof(ffi_arg);
128
+
129
+ /* The size of a pointer depends on the ABI */
130
+ if (type == FFI_TYPE_POINTER)
131
+ type = (ecif->cif->abi == FFI_N64
132
+ || ecif->cif->abi == FFI_N64_SOFT_FLOAT)
133
+ ? FFI_TYPE_SINT64 : FFI_TYPE_SINT32;
134
+
135
+ if (i < 8 && (ecif->cif->abi == FFI_N32_SOFT_FLOAT
136
+ || ecif->cif->abi == FFI_N64_SOFT_FLOAT))
137
+ {
138
+ switch (type)
139
+ {
140
+ case FFI_TYPE_FLOAT:
141
+ type = FFI_TYPE_UINT32;
142
+ break;
143
+ case FFI_TYPE_DOUBLE:
144
+ type = FFI_TYPE_UINT64;
145
+ break;
146
+ default:
147
+ break;
148
+ }
149
+ }
150
+ switch (type)
151
+ {
152
+ case FFI_TYPE_SINT8:
153
+ *(ffi_arg *)argp = *(SINT8 *)(* p_argv);
154
+ break;
155
+
156
+ case FFI_TYPE_UINT8:
157
+ *(ffi_arg *)argp = *(UINT8 *)(* p_argv);
158
+ break;
159
+
160
+ case FFI_TYPE_SINT16:
161
+ *(ffi_arg *)argp = *(SINT16 *)(* p_argv);
162
+ break;
163
+
164
+ case FFI_TYPE_UINT16:
165
+ *(ffi_arg *)argp = *(UINT16 *)(* p_argv);
166
+ break;
167
+
168
+ case FFI_TYPE_SINT32:
169
+ *(ffi_arg *)argp = *(SINT32 *)(* p_argv);
170
+ break;
171
+
172
+ case FFI_TYPE_UINT32:
173
+ *(ffi_arg *)argp = *(UINT32 *)(* p_argv);
174
+ break;
175
+
176
+ /* This can only happen with 64bit slots. */
177
+ case FFI_TYPE_FLOAT:
178
+ *(float *) argp = *(float *)(* p_argv);
179
+ break;
180
+
181
+ /* Handle structures. */
182
+ default:
183
+ memcpy(argp, *p_argv, (*p_arg)->size);
184
+ break;
185
+ }
186
+ }
187
+ else
188
+ {
189
+ #ifdef FFI_MIPS_O32
190
+ memcpy(argp, *p_argv, z);
191
+ #else
192
+ {
193
+ unsigned long end = (unsigned long) argp + z;
194
+ unsigned long cap = (unsigned long) stack + bytes;
195
+
196
+ /* Check if the data will fit within the register space.
197
+ Handle it if it doesn't. */
198
+
199
+ if (end <= cap)
200
+ memcpy(argp, *p_argv, z);
201
+ else
202
+ {
203
+ unsigned long portion = cap - (unsigned long)argp;
204
+
205
+ memcpy(argp, *p_argv, portion);
206
+ argp = stack;
207
+ z -= portion;
208
+ memcpy(argp, (void*)((unsigned long)(*p_argv) + portion),
209
+ z);
210
+ }
211
+ }
212
+ #endif
213
+ }
214
+ p_argv++;
215
+ argp += z;
216
+ FIX_ARGP;
217
+ }
218
+ }
219
+
220
+ #ifdef FFI_MIPS_N32
221
+
222
+ /* The n32 spec says that if "a chunk consists solely of a double
223
+ float field (but not a double, which is part of a union), it
224
+ is passed in a floating point register. Any other chunk is
225
+ passed in an integer register". This code traverses structure
226
+ definitions and generates the appropriate flags. */
227
+
228
+ static unsigned
229
+ calc_n32_struct_flags(int soft_float, ffi_type *arg,
230
+ unsigned *loc, unsigned *arg_reg)
231
+ {
232
+ unsigned flags = 0;
233
+ unsigned index = 0;
234
+
235
+ ffi_type *e;
236
+
237
+ if (soft_float)
238
+ return 0;
239
+
240
+ while ((e = arg->elements[index]))
241
+ {
242
+ /* Align this object. */
243
+ *loc = ALIGN(*loc, e->alignment);
244
+ if (e->type == FFI_TYPE_DOUBLE)
245
+ {
246
+ /* Already aligned to FFI_SIZEOF_ARG. */
247
+ *arg_reg = *loc / FFI_SIZEOF_ARG;
248
+ if (*arg_reg > 7)
249
+ break;
250
+ flags += (FFI_TYPE_DOUBLE << (*arg_reg * FFI_FLAG_BITS));
251
+ *loc += e->size;
252
+ }
253
+ else
254
+ *loc += e->size;
255
+ index++;
256
+ }
257
+ /* Next Argument register at alignment of FFI_SIZEOF_ARG. */
258
+ *arg_reg = ALIGN(*loc, FFI_SIZEOF_ARG) / FFI_SIZEOF_ARG;
259
+
260
+ return flags;
261
+ }
262
+
263
+ static unsigned
264
+ calc_n32_return_struct_flags(int soft_float, ffi_type *arg)
265
+ {
266
+ unsigned flags = 0;
267
+ unsigned small = FFI_TYPE_SMALLSTRUCT;
268
+ ffi_type *e;
269
+
270
+ /* Returning structures under n32 is a tricky thing.
271
+ A struct with only one or two floating point fields
272
+ is returned in $f0 (and $f2 if necessary). Any other
273
+ struct results at most 128 bits are returned in $2
274
+ (the first 64 bits) and $3 (remainder, if necessary).
275
+ Larger structs are handled normally. */
276
+
277
+ if (arg->size > 16)
278
+ return 0;
279
+
280
+ if (arg->size > 8)
281
+ small = FFI_TYPE_SMALLSTRUCT2;
282
+
283
+ e = arg->elements[0];
284
+
285
+ if (e->type == FFI_TYPE_DOUBLE)
286
+ flags = FFI_TYPE_DOUBLE;
287
+ else if (e->type == FFI_TYPE_FLOAT)
288
+ flags = FFI_TYPE_FLOAT;
289
+
290
+ if (flags && (e = arg->elements[1]))
291
+ {
292
+ if (e->type == FFI_TYPE_DOUBLE)
293
+ flags += FFI_TYPE_DOUBLE << FFI_FLAG_BITS;
294
+ else if (e->type == FFI_TYPE_FLOAT)
295
+ flags += FFI_TYPE_FLOAT << FFI_FLAG_BITS;
296
+ else
297
+ return small;
298
+
299
+ if (flags && (arg->elements[2]))
300
+ {
301
+ /* There are three arguments and the first two are
302
+ floats! This must be passed the old way. */
303
+ return small;
304
+ }
305
+ if (soft_float)
306
+ flags += FFI_TYPE_STRUCT_SOFT;
307
+ }
308
+ else
309
+ if (!flags)
310
+ return small;
311
+
312
+ return flags;
313
+ }
314
+
315
+ #endif
316
+
317
+ /* Perform machine dependent cif processing */
318
+ ffi_status ffi_prep_cif_machdep(ffi_cif *cif)
319
+ {
320
+ cif->flags = 0;
321
+
322
+ #ifdef FFI_MIPS_O32
323
+ /* Set the flags necessary for O32 processing. FFI_O32_SOFT_FLOAT
324
+ * does not have special handling for floating point args.
325
+ */
326
+
327
+ if (cif->rtype->type != FFI_TYPE_STRUCT && cif->abi == FFI_O32)
328
+ {
329
+ if (cif->nargs > 0)
330
+ {
331
+ switch ((cif->arg_types)[0]->type)
332
+ {
333
+ case FFI_TYPE_FLOAT:
334
+ case FFI_TYPE_DOUBLE:
335
+ cif->flags += (cif->arg_types)[0]->type;
336
+ break;
337
+
338
+ default:
339
+ break;
340
+ }
341
+
342
+ if (cif->nargs > 1)
343
+ {
344
+ /* Only handle the second argument if the first
345
+ is a float or double. */
346
+ if (cif->flags)
347
+ {
348
+ switch ((cif->arg_types)[1]->type)
349
+ {
350
+ case FFI_TYPE_FLOAT:
351
+ case FFI_TYPE_DOUBLE:
352
+ cif->flags += (cif->arg_types)[1]->type << FFI_FLAG_BITS;
353
+ break;
354
+
355
+ default:
356
+ break;
357
+ }
358
+ }
359
+ }
360
+ }
361
+ }
362
+
363
+ /* Set the return type flag */
364
+
365
+ if (cif->abi == FFI_O32_SOFT_FLOAT)
366
+ {
367
+ switch (cif->rtype->type)
368
+ {
369
+ case FFI_TYPE_VOID:
370
+ case FFI_TYPE_STRUCT:
371
+ cif->flags += cif->rtype->type << (FFI_FLAG_BITS * 2);
372
+ break;
373
+
374
+ case FFI_TYPE_SINT64:
375
+ case FFI_TYPE_UINT64:
376
+ case FFI_TYPE_DOUBLE:
377
+ cif->flags += FFI_TYPE_UINT64 << (FFI_FLAG_BITS * 2);
378
+ break;
379
+
380
+ case FFI_TYPE_FLOAT:
381
+ default:
382
+ cif->flags += FFI_TYPE_INT << (FFI_FLAG_BITS * 2);
383
+ break;
384
+ }
385
+ }
386
+ else
387
+ {
388
+ /* FFI_O32 */
389
+ switch (cif->rtype->type)
390
+ {
391
+ case FFI_TYPE_VOID:
392
+ case FFI_TYPE_STRUCT:
393
+ case FFI_TYPE_FLOAT:
394
+ case FFI_TYPE_DOUBLE:
395
+ cif->flags += cif->rtype->type << (FFI_FLAG_BITS * 2);
396
+ break;
397
+
398
+ case FFI_TYPE_SINT64:
399
+ case FFI_TYPE_UINT64:
400
+ cif->flags += FFI_TYPE_UINT64 << (FFI_FLAG_BITS * 2);
401
+ break;
402
+
403
+ default:
404
+ cif->flags += FFI_TYPE_INT << (FFI_FLAG_BITS * 2);
405
+ break;
406
+ }
407
+ }
408
+ #endif
409
+
410
+ #ifdef FFI_MIPS_N32
411
+ /* Set the flags necessary for N32 processing */
412
+ {
413
+ int type;
414
+ unsigned arg_reg = 0;
415
+ unsigned loc = 0;
416
+ unsigned count = (cif->nargs < 8) ? cif->nargs : 8;
417
+ unsigned index = 0;
418
+
419
+ unsigned struct_flags = 0;
420
+ int soft_float = (cif->abi == FFI_N32_SOFT_FLOAT
421
+ || cif->abi == FFI_N64_SOFT_FLOAT);
422
+
423
+ if (cif->rtype->type == FFI_TYPE_STRUCT)
424
+ {
425
+ struct_flags = calc_n32_return_struct_flags(soft_float, cif->rtype);
426
+
427
+ if (struct_flags == 0)
428
+ {
429
+ /* This means that the structure is being passed as
430
+ a hidden argument */
431
+
432
+ arg_reg = 1;
433
+ count = (cif->nargs < 7) ? cif->nargs : 7;
434
+
435
+ cif->rstruct_flag = !0;
436
+ }
437
+ else
438
+ cif->rstruct_flag = 0;
439
+ }
440
+ else
441
+ cif->rstruct_flag = 0;
442
+
443
+ while (count-- > 0 && arg_reg < 8)
444
+ {
445
+ type = (cif->arg_types)[index]->type;
446
+ if (soft_float)
447
+ {
448
+ switch (type)
449
+ {
450
+ case FFI_TYPE_FLOAT:
451
+ type = FFI_TYPE_UINT32;
452
+ break;
453
+ case FFI_TYPE_DOUBLE:
454
+ type = FFI_TYPE_UINT64;
455
+ break;
456
+ default:
457
+ break;
458
+ }
459
+ }
460
+ switch (type)
461
+ {
462
+ case FFI_TYPE_FLOAT:
463
+ case FFI_TYPE_DOUBLE:
464
+ cif->flags +=
465
+ ((cif->arg_types)[index]->type << (arg_reg * FFI_FLAG_BITS));
466
+ arg_reg++;
467
+ break;
468
+ case FFI_TYPE_LONGDOUBLE:
469
+ /* Align it. */
470
+ arg_reg = ALIGN(arg_reg, 2);
471
+ /* Treat it as two adjacent doubles. */
472
+ if (soft_float)
473
+ {
474
+ arg_reg += 2;
475
+ }
476
+ else
477
+ {
478
+ cif->flags +=
479
+ (FFI_TYPE_DOUBLE << (arg_reg * FFI_FLAG_BITS));
480
+ arg_reg++;
481
+ cif->flags +=
482
+ (FFI_TYPE_DOUBLE << (arg_reg * FFI_FLAG_BITS));
483
+ arg_reg++;
484
+ }
485
+ break;
486
+
487
+ case FFI_TYPE_STRUCT:
488
+ loc = arg_reg * FFI_SIZEOF_ARG;
489
+ cif->flags += calc_n32_struct_flags(soft_float,
490
+ (cif->arg_types)[index],
491
+ &loc, &arg_reg);
492
+ break;
493
+
494
+ default:
495
+ arg_reg++;
496
+ break;
497
+ }
498
+
499
+ index++;
500
+ }
501
+
502
+ /* Set the return type flag */
503
+ switch (cif->rtype->type)
504
+ {
505
+ case FFI_TYPE_STRUCT:
506
+ {
507
+ if (struct_flags == 0)
508
+ {
509
+ /* The structure is returned through a hidden
510
+ first argument. Do nothing, 'cause FFI_TYPE_VOID
511
+ is 0 */
512
+ }
513
+ else
514
+ {
515
+ /* The structure is returned via some tricky
516
+ mechanism */
517
+ cif->flags += FFI_TYPE_STRUCT << (FFI_FLAG_BITS * 8);
518
+ cif->flags += struct_flags << (4 + (FFI_FLAG_BITS * 8));
519
+ }
520
+ break;
521
+ }
522
+
523
+ case FFI_TYPE_VOID:
524
+ /* Do nothing, 'cause FFI_TYPE_VOID is 0 */
525
+ break;
526
+
527
+ case FFI_TYPE_POINTER:
528
+ if (cif->abi == FFI_N32_SOFT_FLOAT || cif->abi == FFI_N32)
529
+ cif->flags += FFI_TYPE_SINT32 << (FFI_FLAG_BITS * 8);
530
+ else
531
+ cif->flags += FFI_TYPE_INT << (FFI_FLAG_BITS * 8);
532
+ break;
533
+
534
+ case FFI_TYPE_FLOAT:
535
+ if (soft_float)
536
+ {
537
+ cif->flags += FFI_TYPE_SINT32 << (FFI_FLAG_BITS * 8);
538
+ break;
539
+ }
540
+ /* else fall through */
541
+ case FFI_TYPE_DOUBLE:
542
+ if (soft_float)
543
+ cif->flags += FFI_TYPE_INT << (FFI_FLAG_BITS * 8);
544
+ else
545
+ cif->flags += cif->rtype->type << (FFI_FLAG_BITS * 8);
546
+ break;
547
+
548
+ case FFI_TYPE_LONGDOUBLE:
549
+ /* Long double is returned as if it were a struct containing
550
+ two doubles. */
551
+ if (soft_float)
552
+ {
553
+ cif->flags += FFI_TYPE_STRUCT << (FFI_FLAG_BITS * 8);
554
+ cif->flags += FFI_TYPE_SMALLSTRUCT2 << (4 + (FFI_FLAG_BITS * 8));
555
+ }
556
+ else
557
+ {
558
+ cif->flags += FFI_TYPE_STRUCT << (FFI_FLAG_BITS * 8);
559
+ cif->flags += (FFI_TYPE_DOUBLE
560
+ + (FFI_TYPE_DOUBLE << FFI_FLAG_BITS))
561
+ << (4 + (FFI_FLAG_BITS * 8));
562
+ }
563
+ break;
564
+ default:
565
+ cif->flags += FFI_TYPE_INT << (FFI_FLAG_BITS * 8);
566
+ break;
567
+ }
568
+ }
569
+ #endif
570
+
571
+ return FFI_OK;
572
+ }
573
+
574
+ /* Low level routine for calling O32 functions */
575
+ extern int ffi_call_O32(void (*)(char *, extended_cif *, int, int),
576
+ extended_cif *, unsigned,
577
+ unsigned, unsigned *, void (*)(void));
578
+
579
+ /* Low level routine for calling N32 functions */
580
+ extern int ffi_call_N32(void (*)(char *, extended_cif *, int, int),
581
+ extended_cif *, unsigned,
582
+ unsigned, void *, void (*)(void));
583
+
584
+ void ffi_call(ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue)
585
+ {
586
+ extended_cif ecif;
587
+
588
+ ecif.cif = cif;
589
+ ecif.avalue = avalue;
590
+
591
+ /* If the return value is a struct and we don't have a return */
592
+ /* value address then we need to make one */
593
+
594
+ if ((rvalue == NULL) &&
595
+ (cif->rtype->type == FFI_TYPE_STRUCT))
596
+ ecif.rvalue = alloca(cif->rtype->size);
597
+ else
598
+ ecif.rvalue = rvalue;
599
+
600
+ switch (cif->abi)
601
+ {
602
+ #ifdef FFI_MIPS_O32
603
+ case FFI_O32:
604
+ case FFI_O32_SOFT_FLOAT:
605
+ ffi_call_O32(ffi_prep_args, &ecif, cif->bytes,
606
+ cif->flags, ecif.rvalue, fn);
607
+ break;
608
+ #endif
609
+
610
+ #ifdef FFI_MIPS_N32
611
+ case FFI_N32:
612
+ case FFI_N32_SOFT_FLOAT:
613
+ case FFI_N64:
614
+ case FFI_N64_SOFT_FLOAT:
615
+ {
616
+ int copy_rvalue = 0;
617
+ int copy_offset = 0;
618
+ char *rvalue_copy = ecif.rvalue;
619
+ if (cif->rtype->type == FFI_TYPE_STRUCT && cif->rtype->size < 16)
620
+ {
621
+ /* For structures smaller than 16 bytes we clobber memory
622
+ in 8 byte increments. Make a copy so we don't clobber
623
+ the callers memory outside of the struct bounds. */
624
+ rvalue_copy = alloca(16);
625
+ copy_rvalue = 1;
626
+ }
627
+ else if (cif->rtype->type == FFI_TYPE_FLOAT
628
+ && (cif->abi == FFI_N64_SOFT_FLOAT
629
+ || cif->abi == FFI_N32_SOFT_FLOAT))
630
+ {
631
+ rvalue_copy = alloca (8);
632
+ copy_rvalue = 1;
633
+ #if defined(__MIPSEB__) || defined(_MIPSEB)
634
+ copy_offset = 4;
635
+ #endif
636
+ }
637
+ ffi_call_N32(ffi_prep_args, &ecif, cif->bytes,
638
+ cif->flags, rvalue_copy, fn);
639
+ if (copy_rvalue)
640
+ memcpy(ecif.rvalue, rvalue_copy + copy_offset, cif->rtype->size);
641
+ }
642
+ break;
643
+ #endif
644
+
645
+ default:
646
+ FFI_ASSERT(0);
647
+ break;
648
+ }
649
+ }
650
+
651
+ #if FFI_CLOSURES
652
+ #if defined(FFI_MIPS_O32)
653
+ extern void ffi_closure_O32(void);
654
+ #else
655
+ extern void ffi_closure_N32(void);
656
+ #endif /* FFI_MIPS_O32 */
657
+
658
+ ffi_status
659
+ ffi_prep_closure_loc (ffi_closure *closure,
660
+ ffi_cif *cif,
661
+ void (*fun)(ffi_cif*,void*,void**,void*),
662
+ void *user_data,
663
+ void *codeloc)
664
+ {
665
+ unsigned int *tramp = (unsigned int *) &closure->tramp[0];
666
+ void * fn;
667
+ char *clear_location = (char *) codeloc;
668
+
669
+ #if defined(FFI_MIPS_O32)
670
+ if (cif->abi != FFI_O32 && cif->abi != FFI_O32_SOFT_FLOAT)
671
+ return FFI_BAD_ABI;
672
+ fn = ffi_closure_O32;
673
+ #else /* FFI_MIPS_N32 */
674
+ if (cif->abi != FFI_N32 && cif->abi != FFI_N64)
675
+ return FFI_BAD_ABI;
676
+ fn = ffi_closure_N32;
677
+ #endif /* FFI_MIPS_O32 */
678
+
679
+ #if defined(FFI_MIPS_O32) || (_MIPS_SIM ==_ABIN32)
680
+ /* lui $25,high(fn) */
681
+ tramp[0] = 0x3c190000 | ((unsigned)fn >> 16);
682
+ /* ori $25,low(fn) */
683
+ tramp[1] = 0x37390000 | ((unsigned)fn & 0xffff);
684
+ /* lui $12,high(codeloc) */
685
+ tramp[2] = 0x3c0c0000 | ((unsigned)codeloc >> 16);
686
+ /* jr $25 */
687
+ tramp[3] = 0x03200008;
688
+ /* ori $12,low(codeloc) */
689
+ tramp[4] = 0x358c0000 | ((unsigned)codeloc & 0xffff);
690
+ #else
691
+ /* N64 has a somewhat larger trampoline. */
692
+ /* lui $25,high(fn) */
693
+ tramp[0] = 0x3c190000 | ((unsigned long)fn >> 48);
694
+ /* lui $12,high(codeloc) */
695
+ tramp[1] = 0x3c0c0000 | ((unsigned long)codeloc >> 48);
696
+ /* ori $25,mid-high(fn) */
697
+ tramp[2] = 0x37390000 | (((unsigned long)fn >> 32 ) & 0xffff);
698
+ /* ori $12,mid-high(codeloc) */
699
+ tramp[3] = 0x358c0000 | (((unsigned long)codeloc >> 32) & 0xffff);
700
+ /* dsll $25,$25,16 */
701
+ tramp[4] = 0x0019cc38;
702
+ /* dsll $12,$12,16 */
703
+ tramp[5] = 0x000c6438;
704
+ /* ori $25,mid-low(fn) */
705
+ tramp[6] = 0x37390000 | (((unsigned long)fn >> 16 ) & 0xffff);
706
+ /* ori $12,mid-low(codeloc) */
707
+ tramp[7] = 0x358c0000 | (((unsigned long)codeloc >> 16) & 0xffff);
708
+ /* dsll $25,$25,16 */
709
+ tramp[8] = 0x0019cc38;
710
+ /* dsll $12,$12,16 */
711
+ tramp[9] = 0x000c6438;
712
+ /* ori $25,low(fn) */
713
+ tramp[10] = 0x37390000 | ((unsigned long)fn & 0xffff);
714
+ /* jr $25 */
715
+ tramp[11] = 0x03200008;
716
+ /* ori $12,low(codeloc) */
717
+ tramp[12] = 0x358c0000 | ((unsigned long)codeloc & 0xffff);
718
+
719
+ #endif
720
+
721
+ closure->cif = cif;
722
+ closure->fun = fun;
723
+ closure->user_data = user_data;
724
+
725
+ #ifdef USE__BUILTIN___CLEAR_CACHE
726
+ __builtin___clear_cache(clear_location, clear_location + FFI_TRAMPOLINE_SIZE);
727
+ #else
728
+ cacheflush (clear_location, FFI_TRAMPOLINE_SIZE, ICACHE);
729
+ #endif
730
+ return FFI_OK;
731
+ }
732
+
733
+ /*
734
+ * Decodes the arguments to a function, which will be stored on the
735
+ * stack. AR is the pointer to the beginning of the integer arguments
736
+ * (and, depending upon the arguments, some floating-point arguments
737
+ * as well). FPR is a pointer to the area where floating point
738
+ * registers have been saved, if any.
739
+ *
740
+ * RVALUE is the location where the function return value will be
741
+ * stored. CLOSURE is the prepared closure to invoke.
742
+ *
743
+ * This function should only be called from assembly, which is in
744
+ * turn called from a trampoline.
745
+ *
746
+ * Returns the function return type.
747
+ *
748
+ * Based on the similar routine for sparc.
749
+ */
750
+ int
751
+ ffi_closure_mips_inner_O32 (ffi_closure *closure,
752
+ void *rvalue, ffi_arg *ar,
753
+ double *fpr)
754
+ {
755
+ ffi_cif *cif;
756
+ void **avaluep;
757
+ ffi_arg *avalue;
758
+ ffi_type **arg_types;
759
+ int i, avn, argn, seen_int;
760
+
761
+ cif = closure->cif;
762
+ avalue = alloca (cif->nargs * sizeof (ffi_arg));
763
+ avaluep = alloca (cif->nargs * sizeof (ffi_arg));
764
+
765
+ seen_int = (cif->abi == FFI_O32_SOFT_FLOAT);
766
+ argn = 0;
767
+
768
+ if ((cif->flags >> (FFI_FLAG_BITS * 2)) == FFI_TYPE_STRUCT)
769
+ {
770
+ rvalue = (void *)(UINT32)ar[0];
771
+ argn = 1;
772
+ }
773
+
774
+ i = 0;
775
+ avn = cif->nargs;
776
+ arg_types = cif->arg_types;
777
+
778
+ while (i < avn)
779
+ {
780
+ if (i < 2 && !seen_int &&
781
+ (arg_types[i]->type == FFI_TYPE_FLOAT ||
782
+ arg_types[i]->type == FFI_TYPE_DOUBLE ||
783
+ arg_types[i]->type == FFI_TYPE_LONGDOUBLE))
784
+ {
785
+ #if defined(__MIPSEB__) || defined(_MIPSEB)
786
+ if (arg_types[i]->type == FFI_TYPE_FLOAT)
787
+ avaluep[i] = ((char *) &fpr[i]) + sizeof (float);
788
+ else
789
+ #endif
790
+ avaluep[i] = (char *) &fpr[i];
791
+ }
792
+ else
793
+ {
794
+ if (arg_types[i]->alignment == 8 && (argn & 0x1))
795
+ argn++;
796
+ switch (arg_types[i]->type)
797
+ {
798
+ case FFI_TYPE_SINT8:
799
+ avaluep[i] = &avalue[i];
800
+ *(SINT8 *) &avalue[i] = (SINT8) ar[argn];
801
+ break;
802
+
803
+ case FFI_TYPE_UINT8:
804
+ avaluep[i] = &avalue[i];
805
+ *(UINT8 *) &avalue[i] = (UINT8) ar[argn];
806
+ break;
807
+
808
+ case FFI_TYPE_SINT16:
809
+ avaluep[i] = &avalue[i];
810
+ *(SINT16 *) &avalue[i] = (SINT16) ar[argn];
811
+ break;
812
+
813
+ case FFI_TYPE_UINT16:
814
+ avaluep[i] = &avalue[i];
815
+ *(UINT16 *) &avalue[i] = (UINT16) ar[argn];
816
+ break;
817
+
818
+ default:
819
+ avaluep[i] = (char *) &ar[argn];
820
+ break;
821
+ }
822
+ seen_int = 1;
823
+ }
824
+ argn += ALIGN(arg_types[i]->size, FFI_SIZEOF_ARG) / FFI_SIZEOF_ARG;
825
+ i++;
826
+ }
827
+
828
+ /* Invoke the closure. */
829
+ (closure->fun) (cif, rvalue, avaluep, closure->user_data);
830
+
831
+ if (cif->abi == FFI_O32_SOFT_FLOAT)
832
+ {
833
+ switch (cif->rtype->type)
834
+ {
835
+ case FFI_TYPE_FLOAT:
836
+ return FFI_TYPE_INT;
837
+ case FFI_TYPE_DOUBLE:
838
+ return FFI_TYPE_UINT64;
839
+ default:
840
+ return cif->rtype->type;
841
+ }
842
+ }
843
+ else
844
+ {
845
+ return cif->rtype->type;
846
+ }
847
+ }
848
+
849
+ #if defined(FFI_MIPS_N32)
850
+
851
+ static void
852
+ copy_struct_N32(char *target, unsigned offset, ffi_abi abi, ffi_type *type,
853
+ int argn, unsigned arg_offset, ffi_arg *ar,
854
+ ffi_arg *fpr, int soft_float)
855
+ {
856
+ ffi_type **elt_typep = type->elements;
857
+ while(*elt_typep)
858
+ {
859
+ ffi_type *elt_type = *elt_typep;
860
+ unsigned o;
861
+ char *tp;
862
+ char *argp;
863
+ char *fpp;
864
+
865
+ o = ALIGN(offset, elt_type->alignment);
866
+ arg_offset += o - offset;
867
+ offset = o;
868
+ argn += arg_offset / sizeof(ffi_arg);
869
+ arg_offset = arg_offset % sizeof(ffi_arg);
870
+
871
+ argp = (char *)(ar + argn);
872
+ fpp = (char *)(argn >= 8 ? ar + argn : fpr + argn);
873
+
874
+ tp = target + offset;
875
+
876
+ if (elt_type->type == FFI_TYPE_DOUBLE && !soft_float)
877
+ *(double *)tp = *(double *)fpp;
878
+ else
879
+ memcpy(tp, argp + arg_offset, elt_type->size);
880
+
881
+ offset += elt_type->size;
882
+ arg_offset += elt_type->size;
883
+ elt_typep++;
884
+ argn += arg_offset / sizeof(ffi_arg);
885
+ arg_offset = arg_offset % sizeof(ffi_arg);
886
+ }
887
+ }
888
+
889
+ /*
890
+ * Decodes the arguments to a function, which will be stored on the
891
+ * stack. AR is the pointer to the beginning of the integer
892
+ * arguments. FPR is a pointer to the area where floating point
893
+ * registers have been saved.
894
+ *
895
+ * RVALUE is the location where the function return value will be
896
+ * stored. CLOSURE is the prepared closure to invoke.
897
+ *
898
+ * This function should only be called from assembly, which is in
899
+ * turn called from a trampoline.
900
+ *
901
+ * Returns the function return flags.
902
+ *
903
+ */
904
+ int
905
+ ffi_closure_mips_inner_N32 (ffi_closure *closure,
906
+ void *rvalue, ffi_arg *ar,
907
+ ffi_arg *fpr)
908
+ {
909
+ ffi_cif *cif;
910
+ void **avaluep;
911
+ ffi_arg *avalue;
912
+ ffi_type **arg_types;
913
+ int i, avn, argn;
914
+ int soft_float;
915
+ ffi_arg *argp;
916
+
917
+ cif = closure->cif;
918
+ soft_float = cif->abi == FFI_N64_SOFT_FLOAT
919
+ || cif->abi == FFI_N32_SOFT_FLOAT;
920
+ avalue = alloca (cif->nargs * sizeof (ffi_arg));
921
+ avaluep = alloca (cif->nargs * sizeof (ffi_arg));
922
+
923
+ argn = 0;
924
+
925
+ if (cif->rstruct_flag)
926
+ {
927
+ #if _MIPS_SIM==_ABIN32
928
+ rvalue = (void *)(UINT32)ar[0];
929
+ #else /* N64 */
930
+ rvalue = (void *)ar[0];
931
+ #endif
932
+ argn = 1;
933
+ }
934
+
935
+ i = 0;
936
+ avn = cif->nargs;
937
+ arg_types = cif->arg_types;
938
+
939
+ while (i < avn)
940
+ {
941
+ if (arg_types[i]->type == FFI_TYPE_FLOAT
942
+ || arg_types[i]->type == FFI_TYPE_DOUBLE
943
+ || arg_types[i]->type == FFI_TYPE_LONGDOUBLE)
944
+ {
945
+ argp = (argn >= 8 || soft_float) ? ar + argn : fpr + argn;
946
+ if ((arg_types[i]->type == FFI_TYPE_LONGDOUBLE) && ((unsigned)argp & (arg_types[i]->alignment-1)))
947
+ {
948
+ argp=(ffi_arg*)ALIGN(argp,arg_types[i]->alignment);
949
+ argn++;
950
+ }
951
+ #if defined(__MIPSEB__) || defined(_MIPSEB)
952
+ if (arg_types[i]->type == FFI_TYPE_FLOAT && argn < 8)
953
+ avaluep[i] = ((char *) argp) + sizeof (float);
954
+ else
955
+ #endif
956
+ avaluep[i] = (char *) argp;
957
+ }
958
+ else
959
+ {
960
+ unsigned type = arg_types[i]->type;
961
+
962
+ if (arg_types[i]->alignment > sizeof(ffi_arg))
963
+ argn = ALIGN(argn, arg_types[i]->alignment / sizeof(ffi_arg));
964
+
965
+ argp = ar + argn;
966
+
967
+ /* The size of a pointer depends on the ABI */
968
+ if (type == FFI_TYPE_POINTER)
969
+ type = (cif->abi == FFI_N64 || cif->abi == FFI_N64_SOFT_FLOAT)
970
+ ? FFI_TYPE_SINT64 : FFI_TYPE_SINT32;
971
+
972
+ if (soft_float && type == FFI_TYPE_FLOAT)
973
+ type = FFI_TYPE_UINT32;
974
+
975
+ switch (type)
976
+ {
977
+ case FFI_TYPE_SINT8:
978
+ avaluep[i] = &avalue[i];
979
+ *(SINT8 *) &avalue[i] = (SINT8) *argp;
980
+ break;
981
+
982
+ case FFI_TYPE_UINT8:
983
+ avaluep[i] = &avalue[i];
984
+ *(UINT8 *) &avalue[i] = (UINT8) *argp;
985
+ break;
986
+
987
+ case FFI_TYPE_SINT16:
988
+ avaluep[i] = &avalue[i];
989
+ *(SINT16 *) &avalue[i] = (SINT16) *argp;
990
+ break;
991
+
992
+ case FFI_TYPE_UINT16:
993
+ avaluep[i] = &avalue[i];
994
+ *(UINT16 *) &avalue[i] = (UINT16) *argp;
995
+ break;
996
+
997
+ case FFI_TYPE_SINT32:
998
+ avaluep[i] = &avalue[i];
999
+ *(SINT32 *) &avalue[i] = (SINT32) *argp;
1000
+ break;
1001
+
1002
+ case FFI_TYPE_UINT32:
1003
+ avaluep[i] = &avalue[i];
1004
+ *(UINT32 *) &avalue[i] = (UINT32) *argp;
1005
+ break;
1006
+
1007
+ case FFI_TYPE_STRUCT:
1008
+ if (argn < 8)
1009
+ {
1010
+ /* Allocate space for the struct as at least part of
1011
+ it was passed in registers. */
1012
+ avaluep[i] = alloca(arg_types[i]->size);
1013
+ copy_struct_N32(avaluep[i], 0, cif->abi, arg_types[i],
1014
+ argn, 0, ar, fpr, soft_float);
1015
+
1016
+ break;
1017
+ }
1018
+ /* Else fall through. */
1019
+ default:
1020
+ avaluep[i] = (char *) argp;
1021
+ break;
1022
+ }
1023
+ }
1024
+ argn += ALIGN(arg_types[i]->size, sizeof(ffi_arg)) / sizeof(ffi_arg);
1025
+ i++;
1026
+ }
1027
+
1028
+ /* Invoke the closure. */
1029
+ (closure->fun) (cif, rvalue, avaluep, closure->user_data);
1030
+
1031
+ return cif->flags >> (FFI_FLAG_BITS * 8);
1032
+ }
1033
+
1034
+ #endif /* FFI_MIPS_N32 */
1035
+
1036
+ #endif /* FFI_CLOSURES */