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