ffi 1.11.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (530) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +25 -0
  3. data/.gitmodules +4 -0
  4. data/.travis.yml +42 -0
  5. data/.yardopts +5 -0
  6. data/CHANGELOG.md +131 -0
  7. data/COPYING +49 -0
  8. data/Gemfile +15 -0
  9. data/LICENSE +24 -0
  10. data/LICENSE.SPECS +22 -0
  11. data/README.md +115 -0
  12. data/Rakefile +195 -0
  13. data/appveyor.yml +27 -0
  14. data/ext/ffi_c/AbstractMemory.c +1109 -0
  15. data/ext/ffi_c/AbstractMemory.h +175 -0
  16. data/ext/ffi_c/ArrayType.c +162 -0
  17. data/ext/ffi_c/ArrayType.h +59 -0
  18. data/ext/ffi_c/Buffer.c +365 -0
  19. data/ext/ffi_c/Call.c +503 -0
  20. data/ext/ffi_c/Call.h +107 -0
  21. data/ext/ffi_c/ClosurePool.c +283 -0
  22. data/ext/ffi_c/ClosurePool.h +57 -0
  23. data/ext/ffi_c/DynamicLibrary.c +339 -0
  24. data/ext/ffi_c/DynamicLibrary.h +98 -0
  25. data/ext/ffi_c/Function.c +917 -0
  26. data/ext/ffi_c/Function.h +87 -0
  27. data/ext/ffi_c/FunctionInfo.c +271 -0
  28. data/ext/ffi_c/LastError.c +229 -0
  29. data/ext/ffi_c/LastError.h +47 -0
  30. data/ext/ffi_c/LongDouble.c +63 -0
  31. data/ext/ffi_c/LongDouble.h +51 -0
  32. data/ext/ffi_c/MappedType.c +168 -0
  33. data/ext/ffi_c/MappedType.h +59 -0
  34. data/ext/ffi_c/MemoryPointer.c +197 -0
  35. data/ext/ffi_c/MemoryPointer.h +53 -0
  36. data/ext/ffi_c/MethodHandle.c +358 -0
  37. data/ext/ffi_c/MethodHandle.h +55 -0
  38. data/ext/ffi_c/Platform.c +82 -0
  39. data/ext/ffi_c/Platform.h +45 -0
  40. data/ext/ffi_c/Pointer.c +508 -0
  41. data/ext/ffi_c/Pointer.h +63 -0
  42. data/ext/ffi_c/Struct.c +829 -0
  43. data/ext/ffi_c/Struct.h +106 -0
  44. data/ext/ffi_c/StructByValue.c +150 -0
  45. data/ext/ffi_c/StructByValue.h +55 -0
  46. data/ext/ffi_c/StructLayout.c +698 -0
  47. data/ext/ffi_c/Thread.c +137 -0
  48. data/ext/ffi_c/Thread.h +84 -0
  49. data/ext/ffi_c/Type.c +379 -0
  50. data/ext/ffi_c/Type.h +61 -0
  51. data/ext/ffi_c/Types.c +139 -0
  52. data/ext/ffi_c/Types.h +89 -0
  53. data/ext/ffi_c/Variadic.c +298 -0
  54. data/ext/ffi_c/compat.h +78 -0
  55. data/ext/ffi_c/extconf.rb +86 -0
  56. data/ext/ffi_c/ffi.c +93 -0
  57. data/ext/ffi_c/libffi.bsd.mk +40 -0
  58. data/ext/ffi_c/libffi.darwin.mk +105 -0
  59. data/ext/ffi_c/libffi.gnu.mk +32 -0
  60. data/ext/ffi_c/libffi.mk +18 -0
  61. data/ext/ffi_c/libffi.vc.mk +26 -0
  62. data/ext/ffi_c/libffi.vc64.mk +26 -0
  63. data/ext/ffi_c/libffi/.appveyor.yml +50 -0
  64. data/ext/ffi_c/libffi/.github/issue_template.md +10 -0
  65. data/ext/ffi_c/libffi/.gitignore +38 -0
  66. data/ext/ffi_c/libffi/.travis.yml +34 -0
  67. data/ext/ffi_c/libffi/.travis/ar-lib +270 -0
  68. data/ext/ffi_c/libffi/.travis/build.sh +34 -0
  69. data/ext/ffi_c/libffi/.travis/compile +351 -0
  70. data/ext/ffi_c/libffi/.travis/install.sh +22 -0
  71. data/ext/ffi_c/libffi/.travis/moxie-sim.exp +60 -0
  72. data/ext/ffi_c/libffi/.travis/site.exp +18 -0
  73. data/ext/ffi_c/libffi/ChangeLog.libffi +584 -0
  74. data/ext/ffi_c/libffi/ChangeLog.libffi-3.1 +6000 -0
  75. data/ext/ffi_c/libffi/ChangeLog.libgcj +40 -0
  76. data/ext/ffi_c/libffi/ChangeLog.v1 +764 -0
  77. data/ext/ffi_c/libffi/LICENSE +21 -0
  78. data/ext/ffi_c/libffi/LICENSE-BUILDTOOLS +352 -0
  79. data/ext/ffi_c/libffi/Makefile.am +166 -0
  80. data/ext/ffi_c/libffi/README.md +461 -0
  81. data/ext/ffi_c/libffi/acinclude.m4 +479 -0
  82. data/ext/ffi_c/libffi/autogen.sh +2 -0
  83. data/ext/ffi_c/libffi/config.guess +1466 -0
  84. data/ext/ffi_c/libffi/config.sub +1836 -0
  85. data/ext/ffi_c/libffi/configure.ac +394 -0
  86. data/ext/ffi_c/libffi/configure.host +289 -0
  87. data/ext/ffi_c/libffi/generate-darwin-source-and-headers.py +203 -0
  88. data/ext/ffi_c/libffi/include/Makefile.am +9 -0
  89. data/ext/ffi_c/libffi/include/ffi.h.in +511 -0
  90. data/ext/ffi_c/libffi/include/ffi_cfi.h +55 -0
  91. data/ext/ffi_c/libffi/include/ffi_common.h +149 -0
  92. data/ext/ffi_c/libffi/libffi.map.in +80 -0
  93. data/ext/ffi_c/libffi/libffi.pc.in +11 -0
  94. data/ext/ffi_c/libffi/libffi.xcodeproj/project.pbxproj +1043 -0
  95. data/ext/ffi_c/libffi/libtool-version +29 -0
  96. data/ext/ffi_c/libffi/m4/asmcfi.m4 +13 -0
  97. data/ext/ffi_c/libffi/m4/ax_append_flag.m4 +71 -0
  98. data/ext/ffi_c/libffi/m4/ax_cc_maxopt.m4 +194 -0
  99. data/ext/ffi_c/libffi/m4/ax_cflags_warn_all.m4 +122 -0
  100. data/ext/ffi_c/libffi/m4/ax_check_compile_flag.m4 +74 -0
  101. data/ext/ffi_c/libffi/m4/ax_compiler_vendor.m4 +87 -0
  102. data/ext/ffi_c/libffi/m4/ax_configure_args.m4 +70 -0
  103. data/ext/ffi_c/libffi/m4/ax_enable_builddir.m4 +302 -0
  104. data/ext/ffi_c/libffi/m4/ax_gcc_archflag.m4 +263 -0
  105. data/ext/ffi_c/libffi/m4/ax_gcc_x86_cpuid.m4 +89 -0
  106. data/ext/ffi_c/libffi/m4/ax_require_defined.m4 +37 -0
  107. data/ext/ffi_c/libffi/man/Makefile.am +8 -0
  108. data/ext/ffi_c/libffi/man/ffi.3 +41 -0
  109. data/ext/ffi_c/libffi/man/ffi_call.3 +103 -0
  110. data/ext/ffi_c/libffi/man/ffi_prep_cif.3 +68 -0
  111. data/ext/ffi_c/libffi/man/ffi_prep_cif_var.3 +73 -0
  112. data/ext/ffi_c/libffi/msvcc.sh +328 -0
  113. data/ext/ffi_c/libffi/src/aarch64/ffi.c +941 -0
  114. data/ext/ffi_c/libffi/src/aarch64/ffitarget.h +81 -0
  115. data/ext/ffi_c/libffi/src/aarch64/internal.h +67 -0
  116. data/ext/ffi_c/libffi/src/aarch64/sysv.S +438 -0
  117. data/ext/ffi_c/libffi/src/alpha/ffi.c +521 -0
  118. data/ext/ffi_c/libffi/src/alpha/ffitarget.h +57 -0
  119. data/ext/ffi_c/libffi/src/alpha/internal.h +23 -0
  120. data/ext/ffi_c/libffi/src/alpha/osf.S +282 -0
  121. data/ext/ffi_c/libffi/src/arc/arcompact.S +135 -0
  122. data/ext/ffi_c/libffi/src/arc/ffi.c +266 -0
  123. data/ext/ffi_c/libffi/src/arc/ffitarget.h +53 -0
  124. data/ext/ffi_c/libffi/src/arm/ffi.c +819 -0
  125. data/ext/ffi_c/libffi/src/arm/ffitarget.h +82 -0
  126. data/ext/ffi_c/libffi/src/arm/internal.h +7 -0
  127. data/ext/ffi_c/libffi/src/arm/sysv.S +383 -0
  128. data/ext/ffi_c/libffi/src/avr32/ffi.c +423 -0
  129. data/ext/ffi_c/libffi/src/avr32/ffitarget.h +55 -0
  130. data/ext/ffi_c/libffi/src/avr32/sysv.S +208 -0
  131. data/ext/ffi_c/libffi/src/bfin/ffi.c +196 -0
  132. data/ext/ffi_c/libffi/src/bfin/ffitarget.h +43 -0
  133. data/ext/ffi_c/libffi/src/bfin/sysv.S +179 -0
  134. data/ext/ffi_c/libffi/src/closures.c +966 -0
  135. data/ext/ffi_c/libffi/src/cris/ffi.c +386 -0
  136. data/ext/ffi_c/libffi/src/cris/ffitarget.h +56 -0
  137. data/ext/ffi_c/libffi/src/cris/sysv.S +215 -0
  138. data/ext/ffi_c/libffi/src/debug.c +64 -0
  139. data/ext/ffi_c/libffi/src/dlmalloc.c +5166 -0
  140. data/ext/ffi_c/libffi/src/frv/eabi.S +128 -0
  141. data/ext/ffi_c/libffi/src/frv/ffi.c +292 -0
  142. data/ext/ffi_c/libffi/src/frv/ffitarget.h +62 -0
  143. data/ext/ffi_c/libffi/src/ia64/ffi.c +604 -0
  144. data/ext/ffi_c/libffi/src/ia64/ffitarget.h +56 -0
  145. data/ext/ffi_c/libffi/src/ia64/ia64_flags.h +40 -0
  146. data/ext/ffi_c/libffi/src/ia64/unix.S +567 -0
  147. data/ext/ffi_c/libffi/src/java_raw_api.c +374 -0
  148. data/ext/ffi_c/libffi/src/m32r/ffi.c +232 -0
  149. data/ext/ffi_c/libffi/src/m32r/ffitarget.h +53 -0
  150. data/ext/ffi_c/libffi/src/m32r/sysv.S +121 -0
  151. data/ext/ffi_c/libffi/src/m68k/ffi.c +362 -0
  152. data/ext/ffi_c/libffi/src/m68k/ffitarget.h +54 -0
  153. data/ext/ffi_c/libffi/src/m68k/sysv.S +357 -0
  154. data/ext/ffi_c/libffi/src/m88k/ffi.c +400 -0
  155. data/ext/ffi_c/libffi/src/m88k/ffitarget.h +49 -0
  156. data/ext/ffi_c/libffi/src/m88k/obsd.S +209 -0
  157. data/ext/ffi_c/libffi/src/metag/ffi.c +330 -0
  158. data/ext/ffi_c/libffi/src/metag/ffitarget.h +53 -0
  159. data/ext/ffi_c/libffi/src/metag/sysv.S +311 -0
  160. data/ext/ffi_c/libffi/src/microblaze/ffi.c +321 -0
  161. data/ext/ffi_c/libffi/src/microblaze/ffitarget.h +53 -0
  162. data/ext/ffi_c/libffi/src/microblaze/sysv.S +302 -0
  163. data/ext/ffi_c/libffi/src/mips/ffi.c +1130 -0
  164. data/ext/ffi_c/libffi/src/mips/ffitarget.h +244 -0
  165. data/ext/ffi_c/libffi/src/mips/n32.S +663 -0
  166. data/ext/ffi_c/libffi/src/mips/o32.S +502 -0
  167. data/ext/ffi_c/libffi/src/moxie/eabi.S +101 -0
  168. data/ext/ffi_c/libffi/src/moxie/ffi.c +285 -0
  169. data/ext/ffi_c/libffi/src/moxie/ffitarget.h +52 -0
  170. data/ext/ffi_c/libffi/src/nios2/ffi.c +304 -0
  171. data/ext/ffi_c/libffi/src/nios2/ffitarget.h +52 -0
  172. data/ext/ffi_c/libffi/src/nios2/sysv.S +136 -0
  173. data/ext/ffi_c/libffi/src/or1k/ffi.c +328 -0
  174. data/ext/ffi_c/libffi/src/or1k/ffitarget.h +58 -0
  175. data/ext/ffi_c/libffi/src/or1k/sysv.S +107 -0
  176. data/ext/ffi_c/libffi/src/pa/ffi.c +719 -0
  177. data/ext/ffi_c/libffi/src/pa/ffitarget.h +85 -0
  178. data/ext/ffi_c/libffi/src/pa/hpux32.S +368 -0
  179. data/ext/ffi_c/libffi/src/pa/linux.S +357 -0
  180. data/ext/ffi_c/libffi/src/powerpc/aix.S +566 -0
  181. data/ext/ffi_c/libffi/src/powerpc/aix_closure.S +694 -0
  182. data/ext/ffi_c/libffi/src/powerpc/asm.h +125 -0
  183. data/ext/ffi_c/libffi/src/powerpc/darwin.S +378 -0
  184. data/ext/ffi_c/libffi/src/powerpc/darwin_closure.S +571 -0
  185. data/ext/ffi_c/libffi/src/powerpc/ffi.c +173 -0
  186. data/ext/ffi_c/libffi/src/powerpc/ffi_darwin.c +1440 -0
  187. data/ext/ffi_c/libffi/src/powerpc/ffi_linux64.c +974 -0
  188. data/ext/ffi_c/libffi/src/powerpc/ffi_powerpc.h +94 -0
  189. data/ext/ffi_c/libffi/src/powerpc/ffi_sysv.c +923 -0
  190. data/ext/ffi_c/libffi/src/powerpc/ffitarget.h +198 -0
  191. data/ext/ffi_c/libffi/src/powerpc/linux64.S +228 -0
  192. data/ext/ffi_c/libffi/src/powerpc/linux64_closure.S +488 -0
  193. data/ext/ffi_c/libffi/src/powerpc/ppc_closure.S +397 -0
  194. data/ext/ffi_c/libffi/src/powerpc/sysv.S +175 -0
  195. data/ext/ffi_c/libffi/src/prep_cif.c +261 -0
  196. data/ext/ffi_c/libffi/src/raw_api.c +267 -0
  197. data/ext/ffi_c/libffi/src/riscv/ffi.c +481 -0
  198. data/ext/ffi_c/libffi/src/riscv/ffitarget.h +69 -0
  199. data/ext/ffi_c/libffi/src/riscv/sysv.S +293 -0
  200. data/ext/ffi_c/libffi/src/s390/ffi.c +756 -0
  201. data/ext/ffi_c/libffi/src/s390/ffitarget.h +70 -0
  202. data/ext/ffi_c/libffi/src/s390/internal.h +11 -0
  203. data/ext/ffi_c/libffi/src/s390/sysv.S +325 -0
  204. data/ext/ffi_c/libffi/src/sh/ffi.c +717 -0
  205. data/ext/ffi_c/libffi/src/sh/ffitarget.h +54 -0
  206. data/ext/ffi_c/libffi/src/sh/sysv.S +850 -0
  207. data/ext/ffi_c/libffi/src/sh64/ffi.c +469 -0
  208. data/ext/ffi_c/libffi/src/sh64/ffitarget.h +58 -0
  209. data/ext/ffi_c/libffi/src/sh64/sysv.S +539 -0
  210. data/ext/ffi_c/libffi/src/sparc/ffi.c +468 -0
  211. data/ext/ffi_c/libffi/src/sparc/ffi64.c +608 -0
  212. data/ext/ffi_c/libffi/src/sparc/ffitarget.h +81 -0
  213. data/ext/ffi_c/libffi/src/sparc/internal.h +26 -0
  214. data/ext/ffi_c/libffi/src/sparc/v8.S +443 -0
  215. data/ext/ffi_c/libffi/src/sparc/v9.S +440 -0
  216. data/ext/ffi_c/libffi/src/tile/ffi.c +355 -0
  217. data/ext/ffi_c/libffi/src/tile/ffitarget.h +65 -0
  218. data/ext/ffi_c/libffi/src/tile/tile.S +360 -0
  219. data/ext/ffi_c/libffi/src/types.c +108 -0
  220. data/ext/ffi_c/libffi/src/vax/elfbsd.S +195 -0
  221. data/ext/ffi_c/libffi/src/vax/ffi.c +276 -0
  222. data/ext/ffi_c/libffi/src/vax/ffitarget.h +49 -0
  223. data/ext/ffi_c/libffi/src/x86/asmnames.h +30 -0
  224. data/ext/ffi_c/libffi/src/x86/ffi.c +754 -0
  225. data/ext/ffi_c/libffi/src/x86/ffi64.c +884 -0
  226. data/ext/ffi_c/libffi/src/x86/ffitarget.h +147 -0
  227. data/ext/ffi_c/libffi/src/x86/ffiw64.c +308 -0
  228. data/ext/ffi_c/libffi/src/x86/internal.h +29 -0
  229. data/ext/ffi_c/libffi/src/x86/internal64.h +22 -0
  230. data/ext/ffi_c/libffi/src/x86/sysv.S +1129 -0
  231. data/ext/ffi_c/libffi/src/x86/unix64.S +566 -0
  232. data/ext/ffi_c/libffi/src/x86/win64.S +232 -0
  233. data/ext/ffi_c/libffi/src/x86/win64_intel.S +237 -0
  234. data/ext/ffi_c/libffi/src/xtensa/ffi.c +298 -0
  235. data/ext/ffi_c/libffi/src/xtensa/ffitarget.h +53 -0
  236. data/ext/ffi_c/libffi/src/xtensa/sysv.S +258 -0
  237. data/ext/ffi_c/libffi/stamp-h.in +1 -0
  238. data/ext/ffi_c/libffi/testsuite/Makefile.am +117 -0
  239. data/ext/ffi_c/libffi/testsuite/config/default.exp +1 -0
  240. data/ext/ffi_c/libffi/testsuite/lib/libffi.exp +636 -0
  241. data/ext/ffi_c/libffi/testsuite/lib/target-libpath.exp +283 -0
  242. data/ext/ffi_c/libffi/testsuite/lib/wrapper.exp +45 -0
  243. data/ext/ffi_c/libffi/testsuite/libffi.bhaible/Makefile +28 -0
  244. data/ext/ffi_c/libffi/testsuite/libffi.bhaible/README +78 -0
  245. data/ext/ffi_c/libffi/testsuite/libffi.bhaible/alignof.h +50 -0
  246. data/ext/ffi_c/libffi/testsuite/libffi.bhaible/bhaible.exp +58 -0
  247. data/ext/ffi_c/libffi/testsuite/libffi.bhaible/test-call.c +1745 -0
  248. data/ext/ffi_c/libffi/testsuite/libffi.bhaible/test-callback.c +2885 -0
  249. data/ext/ffi_c/libffi/testsuite/libffi.bhaible/testcases.c +743 -0
  250. data/ext/ffi_c/libffi/testsuite/libffi.call/align_mixed.c +46 -0
  251. data/ext/ffi_c/libffi/testsuite/libffi.call/align_stdcall.c +46 -0
  252. data/ext/ffi_c/libffi/testsuite/libffi.call/call.exp +43 -0
  253. data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn0.c +89 -0
  254. data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn1.c +81 -0
  255. data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn2.c +81 -0
  256. data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn3.c +82 -0
  257. data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn4.c +89 -0
  258. data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn5.c +92 -0
  259. data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn6.c +90 -0
  260. data/ext/ffi_c/libffi/testsuite/libffi.call/closure_loc_fn0.c +95 -0
  261. data/ext/ffi_c/libffi/testsuite/libffi.call/closure_simple.c +55 -0
  262. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_12byte.c +94 -0
  263. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_16byte.c +95 -0
  264. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_18byte.c +96 -0
  265. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_19byte.c +102 -0
  266. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_1_1byte.c +89 -0
  267. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_20byte.c +91 -0
  268. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_20byte1.c +93 -0
  269. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_24byte.c +113 -0
  270. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_2byte.c +90 -0
  271. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_3_1byte.c +95 -0
  272. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_3byte1.c +90 -0
  273. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_3byte2.c +90 -0
  274. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_3float.c +95 -0
  275. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_4_1byte.c +98 -0
  276. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_4byte.c +90 -0
  277. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_5_1_byte.c +109 -0
  278. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_5byte.c +98 -0
  279. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_64byte.c +124 -0
  280. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_6_1_byte.c +113 -0
  281. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_6byte.c +99 -0
  282. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_7_1_byte.c +117 -0
  283. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_7byte.c +97 -0
  284. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_8byte.c +88 -0
  285. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_9byte1.c +90 -0
  286. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_9byte2.c +91 -0
  287. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_double.c +93 -0
  288. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_float.c +91 -0
  289. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_longdouble.c +92 -0
  290. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_longdouble_split.c +132 -0
  291. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_longdouble_split2.c +115 -0
  292. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_pointer.c +95 -0
  293. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_sint16.c +91 -0
  294. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_sint32.c +91 -0
  295. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_sint64.c +92 -0
  296. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_uint16.c +91 -0
  297. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_uint32.c +91 -0
  298. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_uint64.c +93 -0
  299. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_dbls_struct.c +66 -0
  300. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_double.c +43 -0
  301. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_double_va.c +61 -0
  302. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_float.c +42 -0
  303. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_longdouble.c +105 -0
  304. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_longdouble_va.c +61 -0
  305. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_many_mixed_args.c +70 -0
  306. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_many_mixed_float_double.c +55 -0
  307. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_schar.c +74 -0
  308. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_sshort.c +74 -0
  309. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_sshortchar.c +86 -0
  310. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_uchar.c +91 -0
  311. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_ushort.c +74 -0
  312. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_ushortchar.c +86 -0
  313. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_pointer.c +74 -0
  314. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_pointer_stack.c +142 -0
  315. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_schar.c +44 -0
  316. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_sint.c +42 -0
  317. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_sshort.c +42 -0
  318. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_struct_va1.c +114 -0
  319. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_uchar.c +42 -0
  320. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_uchar_va.c +44 -0
  321. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_uint.c +43 -0
  322. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_uint_va.c +45 -0
  323. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_ulong_va.c +45 -0
  324. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_ulonglong.c +47 -0
  325. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_ushort.c +43 -0
  326. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_ushort_va.c +44 -0
  327. data/ext/ffi_c/libffi/testsuite/libffi.call/err_bad_abi.c +36 -0
  328. data/ext/ffi_c/libffi/testsuite/libffi.call/err_bad_typedef.c +26 -0
  329. data/ext/ffi_c/libffi/testsuite/libffi.call/ffitest.h +138 -0
  330. data/ext/ffi_c/libffi/testsuite/libffi.call/float.c +59 -0
  331. data/ext/ffi_c/libffi/testsuite/libffi.call/float1.c +60 -0
  332. data/ext/ffi_c/libffi/testsuite/libffi.call/float2.c +60 -0
  333. data/ext/ffi_c/libffi/testsuite/libffi.call/float3.c +74 -0
  334. data/ext/ffi_c/libffi/testsuite/libffi.call/float4.c +62 -0
  335. data/ext/ffi_c/libffi/testsuite/libffi.call/float_va.c +107 -0
  336. data/ext/ffi_c/libffi/testsuite/libffi.call/huge_struct.c +341 -0
  337. data/ext/ffi_c/libffi/testsuite/libffi.call/many.c +59 -0
  338. data/ext/ffi_c/libffi/testsuite/libffi.call/many2.c +57 -0
  339. data/ext/ffi_c/libffi/testsuite/libffi.call/many_double.c +70 -0
  340. data/ext/ffi_c/libffi/testsuite/libffi.call/many_mixed.c +78 -0
  341. data/ext/ffi_c/libffi/testsuite/libffi.call/negint.c +52 -0
  342. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct.c +152 -0
  343. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct1.c +161 -0
  344. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct10.c +134 -0
  345. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct11.c +121 -0
  346. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct2.c +110 -0
  347. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct3.c +111 -0
  348. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct4.c +111 -0
  349. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct5.c +112 -0
  350. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct6.c +131 -0
  351. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct7.c +111 -0
  352. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct8.c +131 -0
  353. data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct9.c +131 -0
  354. data/ext/ffi_c/libffi/testsuite/libffi.call/offsets.c +46 -0
  355. data/ext/ffi_c/libffi/testsuite/libffi.call/pr1172638.c +127 -0
  356. data/ext/ffi_c/libffi/testsuite/libffi.call/problem1.c +90 -0
  357. data/ext/ffi_c/libffi/testsuite/libffi.call/promotion.c +59 -0
  358. data/ext/ffi_c/libffi/testsuite/libffi.call/pyobjc-tc.c +114 -0
  359. data/ext/ffi_c/libffi/testsuite/libffi.call/return_dbl.c +36 -0
  360. data/ext/ffi_c/libffi/testsuite/libffi.call/return_dbl1.c +43 -0
  361. data/ext/ffi_c/libffi/testsuite/libffi.call/return_dbl2.c +42 -0
  362. data/ext/ffi_c/libffi/testsuite/libffi.call/return_fl.c +35 -0
  363. data/ext/ffi_c/libffi/testsuite/libffi.call/return_fl1.c +36 -0
  364. data/ext/ffi_c/libffi/testsuite/libffi.call/return_fl2.c +49 -0
  365. data/ext/ffi_c/libffi/testsuite/libffi.call/return_fl3.c +42 -0
  366. data/ext/ffi_c/libffi/testsuite/libffi.call/return_ldl.c +34 -0
  367. data/ext/ffi_c/libffi/testsuite/libffi.call/return_ll.c +41 -0
  368. data/ext/ffi_c/libffi/testsuite/libffi.call/return_ll1.c +43 -0
  369. data/ext/ffi_c/libffi/testsuite/libffi.call/return_sc.c +36 -0
  370. data/ext/ffi_c/libffi/testsuite/libffi.call/return_sl.c +38 -0
  371. data/ext/ffi_c/libffi/testsuite/libffi.call/return_uc.c +38 -0
  372. data/ext/ffi_c/libffi/testsuite/libffi.call/return_ul.c +38 -0
  373. data/ext/ffi_c/libffi/testsuite/libffi.call/stret_large.c +145 -0
  374. data/ext/ffi_c/libffi/testsuite/libffi.call/stret_large2.c +148 -0
  375. data/ext/ffi_c/libffi/testsuite/libffi.call/stret_medium.c +124 -0
  376. data/ext/ffi_c/libffi/testsuite/libffi.call/stret_medium2.c +125 -0
  377. data/ext/ffi_c/libffi/testsuite/libffi.call/strlen.c +44 -0
  378. data/ext/ffi_c/libffi/testsuite/libffi.call/strlen2.c +49 -0
  379. data/ext/ffi_c/libffi/testsuite/libffi.call/strlen3.c +49 -0
  380. data/ext/ffi_c/libffi/testsuite/libffi.call/strlen4.c +55 -0
  381. data/ext/ffi_c/libffi/testsuite/libffi.call/struct1.c +67 -0
  382. data/ext/ffi_c/libffi/testsuite/libffi.call/struct10.c +57 -0
  383. data/ext/ffi_c/libffi/testsuite/libffi.call/struct2.c +67 -0
  384. data/ext/ffi_c/libffi/testsuite/libffi.call/struct3.c +60 -0
  385. data/ext/ffi_c/libffi/testsuite/libffi.call/struct4.c +64 -0
  386. data/ext/ffi_c/libffi/testsuite/libffi.call/struct5.c +66 -0
  387. data/ext/ffi_c/libffi/testsuite/libffi.call/struct6.c +64 -0
  388. data/ext/ffi_c/libffi/testsuite/libffi.call/struct7.c +74 -0
  389. data/ext/ffi_c/libffi/testsuite/libffi.call/struct8.c +81 -0
  390. data/ext/ffi_c/libffi/testsuite/libffi.call/struct9.c +68 -0
  391. data/ext/ffi_c/libffi/testsuite/libffi.call/testclosure.c +70 -0
  392. data/ext/ffi_c/libffi/testsuite/libffi.call/uninitialized.c +61 -0
  393. data/ext/ffi_c/libffi/testsuite/libffi.call/unwindtest.cc +117 -0
  394. data/ext/ffi_c/libffi/testsuite/libffi.call/unwindtest_ffi_call.cc +54 -0
  395. data/ext/ffi_c/libffi/testsuite/libffi.call/va_1.c +196 -0
  396. data/ext/ffi_c/libffi/testsuite/libffi.call/va_struct1.c +121 -0
  397. data/ext/ffi_c/libffi/testsuite/libffi.call/va_struct2.c +123 -0
  398. data/ext/ffi_c/libffi/testsuite/libffi.call/va_struct3.c +125 -0
  399. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_align_complex.inc +91 -0
  400. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_align_complex_double.c +10 -0
  401. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_align_complex_float.c +10 -0
  402. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_align_complex_longdouble.c +10 -0
  403. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex.inc +42 -0
  404. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_double.c +10 -0
  405. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_float.c +10 -0
  406. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_longdouble.c +10 -0
  407. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_struct.inc +71 -0
  408. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_struct_double.c +10 -0
  409. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_struct_float.c +10 -0
  410. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_struct_longdouble.c +10 -0
  411. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_va.inc +80 -0
  412. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_va_double.c +10 -0
  413. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_va_float.c +16 -0
  414. data/ext/ffi_c/libffi/testsuite/libffi.complex/cls_complex_va_longdouble.c +10 -0
  415. data/ext/ffi_c/libffi/testsuite/libffi.complex/complex.exp +36 -0
  416. data/ext/ffi_c/libffi/testsuite/libffi.complex/complex.inc +51 -0
  417. data/ext/ffi_c/libffi/testsuite/libffi.complex/complex_defs_double.inc +7 -0
  418. data/ext/ffi_c/libffi/testsuite/libffi.complex/complex_defs_float.inc +7 -0
  419. data/ext/ffi_c/libffi/testsuite/libffi.complex/complex_defs_longdouble.inc +7 -0
  420. data/ext/ffi_c/libffi/testsuite/libffi.complex/complex_double.c +10 -0
  421. data/ext/ffi_c/libffi/testsuite/libffi.complex/complex_float.c +10 -0
  422. data/ext/ffi_c/libffi/testsuite/libffi.complex/complex_int.c +86 -0
  423. data/ext/ffi_c/libffi/testsuite/libffi.complex/complex_longdouble.c +10 -0
  424. data/ext/ffi_c/libffi/testsuite/libffi.complex/ffitest.h +1 -0
  425. data/ext/ffi_c/libffi/testsuite/libffi.complex/many_complex.inc +78 -0
  426. data/ext/ffi_c/libffi/testsuite/libffi.complex/many_complex_double.c +10 -0
  427. data/ext/ffi_c/libffi/testsuite/libffi.complex/many_complex_float.c +10 -0
  428. data/ext/ffi_c/libffi/testsuite/libffi.complex/many_complex_longdouble.c +10 -0
  429. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex.inc +37 -0
  430. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex1.inc +41 -0
  431. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex1_double.c +10 -0
  432. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex1_float.c +10 -0
  433. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex1_longdouble.c +10 -0
  434. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex2.inc +44 -0
  435. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex2_double.c +10 -0
  436. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex2_float.c +10 -0
  437. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex2_longdouble.c +10 -0
  438. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex_double.c +10 -0
  439. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex_float.c +10 -0
  440. data/ext/ffi_c/libffi/testsuite/libffi.complex/return_complex_longdouble.c +10 -0
  441. data/ext/ffi_c/libffi/testsuite/libffi.go/aa-direct.c +34 -0
  442. data/ext/ffi_c/libffi/testsuite/libffi.go/closure1.c +28 -0
  443. data/ext/ffi_c/libffi/testsuite/libffi.go/ffitest.h +1 -0
  444. data/ext/ffi_c/libffi/testsuite/libffi.go/go.exp +36 -0
  445. data/ext/ffi_c/libffi/testsuite/libffi.go/static-chain.h +19 -0
  446. data/ext/ffi_c/rbffi.h +55 -0
  447. data/ext/ffi_c/rbffi_endian.h +59 -0
  448. data/ext/ffi_c/win32/stdbool.h +8 -0
  449. data/ext/ffi_c/win32/stdint.h +201 -0
  450. data/ffi.gemspec +43 -0
  451. data/lib/ffi.rb +20 -0
  452. data/lib/ffi/autopointer.rb +203 -0
  453. data/lib/ffi/buffer.rb +4 -0
  454. data/lib/ffi/callback.rb +4 -0
  455. data/lib/ffi/data_converter.rb +67 -0
  456. data/lib/ffi/enum.rb +296 -0
  457. data/lib/ffi/errno.rb +43 -0
  458. data/lib/ffi/ffi.rb +45 -0
  459. data/lib/ffi/io.rb +62 -0
  460. data/lib/ffi/library.rb +588 -0
  461. data/lib/ffi/managedstruct.rb +84 -0
  462. data/lib/ffi/memorypointer.rb +1 -0
  463. data/lib/ffi/platform.rb +172 -0
  464. data/lib/ffi/platform/aarch64-freebsd/types.conf +128 -0
  465. data/lib/ffi/platform/aarch64-freebsd12/types.conf +128 -0
  466. data/lib/ffi/platform/aarch64-linux/types.conf +104 -0
  467. data/lib/ffi/platform/arm-freebsd/types.conf +152 -0
  468. data/lib/ffi/platform/arm-freebsd12/types.conf +152 -0
  469. data/lib/ffi/platform/arm-linux/types.conf +104 -0
  470. data/lib/ffi/platform/i386-cygwin/types.conf +3 -0
  471. data/lib/ffi/platform/i386-darwin/types.conf +100 -0
  472. data/lib/ffi/platform/i386-freebsd/types.conf +152 -0
  473. data/lib/ffi/platform/i386-freebsd12/types.conf +152 -0
  474. data/lib/ffi/platform/i386-gnu/types.conf +107 -0
  475. data/lib/ffi/platform/i386-linux/types.conf +103 -0
  476. data/lib/ffi/platform/i386-netbsd/types.conf +126 -0
  477. data/lib/ffi/platform/i386-openbsd/types.conf +128 -0
  478. data/lib/ffi/platform/i386-solaris/types.conf +122 -0
  479. data/lib/ffi/platform/i386-windows/types.conf +105 -0
  480. data/lib/ffi/platform/ia64-linux/types.conf +104 -0
  481. data/lib/ffi/platform/mips-linux/types.conf +102 -0
  482. data/lib/ffi/platform/mips64-linux/types.conf +104 -0
  483. data/lib/ffi/platform/mips64el-linux/types.conf +104 -0
  484. data/lib/ffi/platform/mipsel-linux/types.conf +102 -0
  485. data/lib/ffi/platform/mipsisa32r6-linux/types.conf +102 -0
  486. data/lib/ffi/platform/mipsisa32r6el-linux/types.conf +102 -0
  487. data/lib/ffi/platform/mipsisa64r6-linux/types.conf +104 -0
  488. data/lib/ffi/platform/mipsisa64r6el-linux/types.conf +104 -0
  489. data/lib/ffi/platform/powerpc-aix/types.conf +180 -0
  490. data/lib/ffi/platform/powerpc-darwin/types.conf +100 -0
  491. data/lib/ffi/platform/powerpc-linux/types.conf +100 -0
  492. data/lib/ffi/platform/powerpc64-linux/types.conf +104 -0
  493. data/lib/ffi/platform/s390-linux/types.conf +102 -0
  494. data/lib/ffi/platform/s390x-linux/types.conf +102 -0
  495. data/lib/ffi/platform/sparc-linux/types.conf +102 -0
  496. data/lib/ffi/platform/sparc-solaris/types.conf +128 -0
  497. data/lib/ffi/platform/sparc64-linux/types.conf +102 -0
  498. data/lib/ffi/platform/sparcv9-solaris/types.conf +128 -0
  499. data/lib/ffi/platform/x86_64-cygwin/types.conf +3 -0
  500. data/lib/ffi/platform/x86_64-darwin/types.conf +126 -0
  501. data/lib/ffi/platform/x86_64-freebsd/types.conf +128 -0
  502. data/lib/ffi/platform/x86_64-freebsd12/types.conf +128 -0
  503. data/lib/ffi/platform/x86_64-linux/types.conf +102 -0
  504. data/lib/ffi/platform/x86_64-netbsd/types.conf +128 -0
  505. data/lib/ffi/platform/x86_64-openbsd/types.conf +134 -0
  506. data/lib/ffi/platform/x86_64-solaris/types.conf +122 -0
  507. data/lib/ffi/platform/x86_64-windows/types.conf +120 -0
  508. data/lib/ffi/pointer.rb +160 -0
  509. data/lib/ffi/struct.rb +311 -0
  510. data/lib/ffi/struct_by_reference.rb +72 -0
  511. data/lib/ffi/struct_layout.rb +96 -0
  512. data/lib/ffi/struct_layout_builder.rb +227 -0
  513. data/lib/ffi/tools/const_generator.rb +230 -0
  514. data/lib/ffi/tools/generator.rb +105 -0
  515. data/lib/ffi/tools/generator_task.rb +32 -0
  516. data/lib/ffi/tools/struct_generator.rb +194 -0
  517. data/lib/ffi/tools/types_generator.rb +134 -0
  518. data/lib/ffi/types.rb +194 -0
  519. data/lib/ffi/union.rb +43 -0
  520. data/lib/ffi/variadic.rb +78 -0
  521. data/lib/ffi/version.rb +3 -0
  522. data/samples/getlogin.rb +8 -0
  523. data/samples/getpid.rb +8 -0
  524. data/samples/gettimeofday.rb +18 -0
  525. data/samples/hello.rb +7 -0
  526. data/samples/inotify.rb +60 -0
  527. data/samples/pty.rb +76 -0
  528. data/samples/qsort.rb +21 -0
  529. data/samples/sample_helper.rb +6 -0
  530. metadata +663 -0
@@ -0,0 +1,53 @@
1
+ /* -----------------------------------------------------------------------
2
+ ffitarget.h - Copyright (c) 2012, 2013 Xilinx, Inc
3
+
4
+ Target configuration macros for MicroBlaze.
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining
7
+ a copy of this software and associated documentation files (the
8
+ ``Software''), to deal in the Software without restriction, including
9
+ without limitation the rights to use, copy, modify, merge, publish,
10
+ distribute, sublicense, and/or sell copies of the Software, and to
11
+ permit persons to whom the Software is furnished to do so, subject to
12
+ the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be included
15
+ in all copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
18
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24
+ DEALINGS IN THE SOFTWARE.
25
+ ----------------------------------------------------------------------- */
26
+
27
+ #ifndef LIBFFI_TARGET_H
28
+ #define LIBFFI_TARGET_H
29
+
30
+ #ifndef LIBFFI_H
31
+ #error "Please do not include ffitarget.h directly into your source. Use ffi.h instead."
32
+ #endif
33
+
34
+ #ifndef LIBFFI_ASM
35
+ typedef unsigned long ffi_arg;
36
+ typedef signed long ffi_sarg;
37
+
38
+ typedef enum ffi_abi {
39
+ FFI_FIRST_ABI = 0,
40
+ FFI_SYSV,
41
+ FFI_LAST_ABI,
42
+ FFI_DEFAULT_ABI = FFI_SYSV
43
+ } ffi_abi;
44
+ #endif
45
+
46
+ /* Definitions for closures */
47
+
48
+ #define FFI_CLOSURES 1
49
+ #define FFI_NATIVE_RAW_API 0
50
+
51
+ #define FFI_TRAMPOLINE_SIZE (4*8)
52
+
53
+ #endif
@@ -0,0 +1,302 @@
1
+ /* -----------------------------------------------------------------------
2
+ sysv.S - Copyright (c) 2012, 2013 Xilinx, Inc
3
+
4
+ MicroBlaze Foreign Function Interface
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining
7
+ a copy of this software and associated documentation files (the
8
+ ``Software''), to deal in the Software without restriction, including
9
+ without limitation the rights to use, copy, modify, merge, publish,
10
+ distribute, sublicense, and/or sell copies of the Software, and to
11
+ permit persons to whom the Software is furnished to do so, subject to
12
+ the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be included
15
+ in all copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
18
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24
+ DEALINGS IN THE SOFTWARE.
25
+ ----------------------------------------------------------------------- */
26
+
27
+ #define LIBFFI_ASM
28
+ #include <fficonfig.h>
29
+ #include <ffi.h>
30
+
31
+ /*
32
+ * arg[0] (r5) = ffi_prep_args,
33
+ * arg[1] (r6) = &ecif,
34
+ * arg[2] (r7) = cif->bytes,
35
+ * arg[3] (r8) = cif->flags,
36
+ * arg[4] (r9) = ecif.rvalue,
37
+ * arg[5] (r10) = fn
38
+ * arg[6] (sp[0]) = cif->rtype->type
39
+ * arg[7] (sp[4]) = cif->rtype->size
40
+ */
41
+ .text
42
+ .globl ffi_call_SYSV
43
+ .type ffi_call_SYSV, @function
44
+ ffi_call_SYSV:
45
+ /* push callee saves */
46
+ addik r1, r1, -20
47
+ swi r19, r1, 0 /* Frame Pointer */
48
+ swi r20, r1, 4 /* PIC register */
49
+ swi r21, r1, 8 /* PIC register */
50
+ swi r22, r1, 12 /* save for locals */
51
+ swi r23, r1, 16 /* save for locals */
52
+
53
+ /* save the r5-r10 registers in the stack */
54
+ addik r1, r1, -24 /* increment sp to store 6x 32-bit words */
55
+ swi r5, r1, 0
56
+ swi r6, r1, 4
57
+ swi r7, r1, 8
58
+ swi r8, r1, 12
59
+ swi r9, r1, 16
60
+ swi r10, r1, 20
61
+
62
+ /* save function pointer */
63
+ addik r3, r5, 0 /* copy ffi_prep_args into r3 */
64
+ addik r22, r1, 0 /* save sp for unallocated args into r22 (callee-saved) */
65
+ addik r23, r10, 0 /* save function address into r23 (callee-saved) */
66
+
67
+ /* prepare stack with allocation for n (bytes = r7) args */
68
+ rsub r1, r7, r1 /* subtract bytes from sp */
69
+
70
+ /* prep args for ffi_prep_args call */
71
+ addik r5, r1, 0 /* store stack pointer into arg[0] */
72
+ /* r6 still holds ecif for arg[1] */
73
+
74
+ /* Call ffi_prep_args(stack, &ecif). */
75
+ addik r1, r1, -4
76
+ swi r15, r1, 0 /* store the link register in the frame */
77
+ brald r15, r3
78
+ nop /* branch has delay slot */
79
+ lwi r15, r1, 0
80
+ addik r1, r1, 4 /* restore the link register from the frame */
81
+ /* returns calling stack pointer location */
82
+
83
+ /* prepare args for fn call, prep_args populates them onto the stack */
84
+ lwi r5, r1, 0 /* arg[0] */
85
+ lwi r6, r1, 4 /* arg[1] */
86
+ lwi r7, r1, 8 /* arg[2] */
87
+ lwi r8, r1, 12 /* arg[3] */
88
+ lwi r9, r1, 16 /* arg[4] */
89
+ lwi r10, r1, 20 /* arg[5] */
90
+
91
+ /* call (fn) (...). */
92
+ addik r1, r1, -4
93
+ swi r15, r1, 0 /* store the link register in the frame */
94
+ brald r15, r23
95
+ nop /* branch has delay slot */
96
+ lwi r15, r1, 0
97
+ addik r1, r1, 4 /* restore the link register from the frame */
98
+
99
+ /* Remove the space we pushed for the args. */
100
+ addik r1, r22, 0 /* restore old SP */
101
+
102
+ /* restore this functions parameters */
103
+ lwi r5, r1, 0 /* arg[0] */
104
+ lwi r6, r1, 4 /* arg[1] */
105
+ lwi r7, r1, 8 /* arg[2] */
106
+ lwi r8, r1, 12 /* arg[3] */
107
+ lwi r9, r1, 16 /* arg[4] */
108
+ lwi r10, r1, 20 /* arg[5] */
109
+ addik r1, r1, 24 /* decrement sp to de-allocate 6x 32-bit words */
110
+
111
+ /* If the return value pointer is NULL, assume no return value. */
112
+ beqi r9, ffi_call_SYSV_end
113
+
114
+ lwi r22, r1, 48 /* get return type (20 for locals + 28 for arg[6]) */
115
+ lwi r23, r1, 52 /* get return size (20 for locals + 32 for arg[7]) */
116
+
117
+ /* Check if return type is actually a struct, do nothing */
118
+ rsubi r11, r22, FFI_TYPE_STRUCT
119
+ beqi r11, ffi_call_SYSV_end
120
+
121
+ /* Return 8bit */
122
+ rsubi r11, r23, 1
123
+ beqi r11, ffi_call_SYSV_store8
124
+
125
+ /* Return 16bit */
126
+ rsubi r11, r23, 2
127
+ beqi r11, ffi_call_SYSV_store16
128
+
129
+ /* Return 32bit */
130
+ rsubi r11, r23, 4
131
+ beqi r11, ffi_call_SYSV_store32
132
+
133
+ /* Return 64bit */
134
+ rsubi r11, r23, 8
135
+ beqi r11, ffi_call_SYSV_store64
136
+
137
+ /* Didn't match anything */
138
+ bri ffi_call_SYSV_end
139
+
140
+ ffi_call_SYSV_store64:
141
+ swi r3, r9, 0 /* store word r3 into return value */
142
+ swi r4, r9, 4 /* store word r4 into return value */
143
+ bri ffi_call_SYSV_end
144
+
145
+ ffi_call_SYSV_store32:
146
+ swi r3, r9, 0 /* store word r3 into return value */
147
+ bri ffi_call_SYSV_end
148
+
149
+ ffi_call_SYSV_store16:
150
+ #ifdef __BIG_ENDIAN__
151
+ shi r3, r9, 2 /* store half-word r3 into return value */
152
+ #else
153
+ shi r3, r9, 0 /* store half-word r3 into return value */
154
+ #endif
155
+ bri ffi_call_SYSV_end
156
+
157
+ ffi_call_SYSV_store8:
158
+ #ifdef __BIG_ENDIAN__
159
+ sbi r3, r9, 3 /* store byte r3 into return value */
160
+ #else
161
+ sbi r3, r9, 0 /* store byte r3 into return value */
162
+ #endif
163
+ bri ffi_call_SYSV_end
164
+
165
+ ffi_call_SYSV_end:
166
+ /* callee restores */
167
+ lwi r19, r1, 0 /* frame pointer */
168
+ lwi r20, r1, 4 /* PIC register */
169
+ lwi r21, r1, 8 /* PIC register */
170
+ lwi r22, r1, 12
171
+ lwi r23, r1, 16
172
+ addik r1, r1, 20
173
+
174
+ /* return from sub-routine (with delay slot) */
175
+ rtsd r15, 8
176
+ nop
177
+
178
+ .size ffi_call_SYSV, . - ffi_call_SYSV
179
+
180
+ /* ------------------------------------------------------------------------- */
181
+
182
+ /*
183
+ * args passed into this function, are passed down to the callee.
184
+ * this function is the target of the closure trampoline, as such r12 is
185
+ * a pointer to the closure object.
186
+ */
187
+ .text
188
+ .globl ffi_closure_SYSV
189
+ .type ffi_closure_SYSV, @function
190
+ ffi_closure_SYSV:
191
+ /* push callee saves */
192
+ addik r11, r1, 28 /* save stack args start location (excluding regs/link) */
193
+ addik r1, r1, -12
194
+ swi r19, r1, 0 /* Frame Pointer */
195
+ swi r20, r1, 4 /* PIC register */
196
+ swi r21, r1, 8 /* PIC register */
197
+
198
+ /* store register args on stack */
199
+ addik r1, r1, -24
200
+ swi r5, r1, 0
201
+ swi r6, r1, 4
202
+ swi r7, r1, 8
203
+ swi r8, r1, 12
204
+ swi r9, r1, 16
205
+ swi r10, r1, 20
206
+
207
+ /* setup args */
208
+ addik r5, r1, 0 /* register_args */
209
+ addik r6, r11, 0 /* stack_args */
210
+ addik r7, r12, 0 /* closure object */
211
+ addik r1, r1, -8 /* allocate return value */
212
+ addik r8, r1, 0 /* void* rvalue */
213
+ addik r1, r1, -8 /* allocate for return type/size values */
214
+ addik r9, r1, 0 /* void* rtype */
215
+ addik r10, r1, 4 /* void* rsize */
216
+
217
+ /* call the wrap_call function */
218
+ addik r1, r1, -28 /* allocate args + link reg */
219
+ swi r15, r1, 0 /* store the link register in the frame */
220
+ brald r15, r3
221
+ nop /* branch has delay slot */
222
+ lwi r15, r1, 0
223
+ addik r1, r1, 28 /* restore the link register from the frame */
224
+
225
+ ffi_closure_SYSV_prepare_return:
226
+ lwi r9, r1, 0 /* rtype */
227
+ lwi r10, r1, 4 /* rsize */
228
+ addik r1, r1, 8 /* de-allocate return info values */
229
+
230
+ /* Check if return type is actually a struct, store 4 bytes */
231
+ rsubi r11, r9, FFI_TYPE_STRUCT
232
+ beqi r11, ffi_closure_SYSV_store32
233
+
234
+ /* Return 8bit */
235
+ rsubi r11, r10, 1
236
+ beqi r11, ffi_closure_SYSV_store8
237
+
238
+ /* Return 16bit */
239
+ rsubi r11, r10, 2
240
+ beqi r11, ffi_closure_SYSV_store16
241
+
242
+ /* Return 32bit */
243
+ rsubi r11, r10, 4
244
+ beqi r11, ffi_closure_SYSV_store32
245
+
246
+ /* Return 64bit */
247
+ rsubi r11, r10, 8
248
+ beqi r11, ffi_closure_SYSV_store64
249
+
250
+ /* Didn't match anything */
251
+ bri ffi_closure_SYSV_end
252
+
253
+ ffi_closure_SYSV_store64:
254
+ lwi r3, r1, 0 /* store word r3 into return value */
255
+ lwi r4, r1, 4 /* store word r4 into return value */
256
+ /* 64 bits == 2 words, no sign extend occurs */
257
+ bri ffi_closure_SYSV_end
258
+
259
+ ffi_closure_SYSV_store32:
260
+ lwi r3, r1, 0 /* store word r3 into return value */
261
+ /* 32 bits == 1 word, no sign extend occurs */
262
+ bri ffi_closure_SYSV_end
263
+
264
+ ffi_closure_SYSV_store16:
265
+ #ifdef __BIG_ENDIAN__
266
+ lhui r3, r1, 2 /* store half-word r3 into return value */
267
+ #else
268
+ lhui r3, r1, 0 /* store half-word r3 into return value */
269
+ #endif
270
+ rsubi r11, r9, FFI_TYPE_SINT16
271
+ bnei r11, ffi_closure_SYSV_end
272
+ sext16 r3, r3 /* fix sign extend of sint8 */
273
+ bri ffi_closure_SYSV_end
274
+
275
+ ffi_closure_SYSV_store8:
276
+ #ifdef __BIG_ENDIAN__
277
+ lbui r3, r1, 3 /* store byte r3 into return value */
278
+ #else
279
+ lbui r3, r1, 0 /* store byte r3 into return value */
280
+ #endif
281
+ rsubi r11, r9, FFI_TYPE_SINT8
282
+ bnei r11, ffi_closure_SYSV_end
283
+ sext8 r3, r3 /* fix sign extend of sint8 */
284
+ bri ffi_closure_SYSV_end
285
+
286
+ ffi_closure_SYSV_end:
287
+ addik r1, r1, 8 /* de-allocate return value */
288
+
289
+ /* de-allocate stored args */
290
+ addik r1, r1, 24
291
+
292
+ /* callee restores */
293
+ lwi r19, r1, 0 /* frame pointer */
294
+ lwi r20, r1, 4 /* PIC register */
295
+ lwi r21, r1, 8 /* PIC register */
296
+ addik r1, r1, 12
297
+
298
+ /* return from sub-routine (with delay slot) */
299
+ rtsd r15, 8
300
+ nop
301
+
302
+ .size ffi_closure_SYSV, . - ffi_closure_SYSV
@@ -0,0 +1,1130 @@
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 <stdint.h>
33
+ #include <stdlib.h>
34
+
35
+ #ifdef __GNUC__
36
+ # if (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 3))
37
+ # define USE__BUILTIN___CLEAR_CACHE 1
38
+ # endif
39
+ #endif
40
+
41
+ #ifndef USE__BUILTIN___CLEAR_CACHE
42
+ # if defined(__OpenBSD__)
43
+ # include <mips64/sysarch.h>
44
+ # else
45
+ # include <sys/cachectl.h>
46
+ # endif
47
+ #endif
48
+
49
+ #ifdef FFI_DEBUG
50
+ # define FFI_MIPS_STOP_HERE() ffi_stop_here()
51
+ #else
52
+ # define FFI_MIPS_STOP_HERE() do {} while(0)
53
+ #endif
54
+
55
+ #ifdef FFI_MIPS_N32
56
+ #define FIX_ARGP \
57
+ FFI_ASSERT(argp <= &stack[bytes]); \
58
+ if (argp == &stack[bytes]) \
59
+ { \
60
+ argp = stack; \
61
+ FFI_MIPS_STOP_HERE(); \
62
+ }
63
+ #else
64
+ #define FIX_ARGP
65
+ #endif
66
+
67
+
68
+ /* ffi_prep_args is called by the assembly routine once stack space
69
+ has been allocated for the function's arguments */
70
+
71
+ static void ffi_prep_args(char *stack,
72
+ extended_cif *ecif,
73
+ int bytes,
74
+ int flags)
75
+ {
76
+ int i;
77
+ void **p_argv;
78
+ char *argp;
79
+ ffi_type **p_arg;
80
+
81
+ #ifdef FFI_MIPS_N32
82
+ /* If more than 8 double words are used, the remainder go
83
+ on the stack. We reorder stuff on the stack here to
84
+ support this easily. */
85
+ if (bytes > 8 * sizeof(ffi_arg))
86
+ argp = &stack[bytes - (8 * sizeof(ffi_arg))];
87
+ else
88
+ argp = stack;
89
+ #else
90
+ argp = stack;
91
+ #endif
92
+
93
+ memset(stack, 0, bytes);
94
+
95
+ #ifdef FFI_MIPS_N32
96
+ if ( ecif->cif->rstruct_flag != 0 )
97
+ #else
98
+ if ( ecif->cif->rtype->type == FFI_TYPE_STRUCT )
99
+ #endif
100
+ {
101
+ *(ffi_arg *) argp = (ffi_arg) ecif->rvalue;
102
+ argp += sizeof(ffi_arg);
103
+ FIX_ARGP;
104
+ }
105
+
106
+ p_argv = ecif->avalue;
107
+
108
+ for (i = 0, p_arg = ecif->cif->arg_types; i < ecif->cif->nargs; i++, p_arg++)
109
+ {
110
+ size_t z;
111
+ unsigned int a;
112
+
113
+ /* Align if necessary. */
114
+ a = (*p_arg)->alignment;
115
+ if (a < sizeof(ffi_arg))
116
+ a = sizeof(ffi_arg);
117
+
118
+ if ((a - 1) & (unsigned long) argp)
119
+ {
120
+ argp = (char *) FFI_ALIGN(argp, a);
121
+ FIX_ARGP;
122
+ }
123
+
124
+ z = (*p_arg)->size;
125
+ if (z <= sizeof(ffi_arg))
126
+ {
127
+ int type = (*p_arg)->type;
128
+ z = sizeof(ffi_arg);
129
+
130
+ /* The size of a pointer depends on the ABI */
131
+ if (type == FFI_TYPE_POINTER)
132
+ type = (ecif->cif->abi == FFI_N64
133
+ || ecif->cif->abi == FFI_N64_SOFT_FLOAT)
134
+ ? FFI_TYPE_SINT64 : FFI_TYPE_SINT32;
135
+
136
+ if (i < 8 && (ecif->cif->abi == FFI_N32_SOFT_FLOAT
137
+ || ecif->cif->abi == FFI_N64_SOFT_FLOAT))
138
+ {
139
+ switch (type)
140
+ {
141
+ case FFI_TYPE_FLOAT:
142
+ type = FFI_TYPE_UINT32;
143
+ break;
144
+ case FFI_TYPE_DOUBLE:
145
+ type = FFI_TYPE_UINT64;
146
+ break;
147
+ default:
148
+ break;
149
+ }
150
+ }
151
+ switch (type)
152
+ {
153
+ case FFI_TYPE_SINT8:
154
+ *(ffi_arg *)argp = *(SINT8 *)(* p_argv);
155
+ break;
156
+
157
+ case FFI_TYPE_UINT8:
158
+ *(ffi_arg *)argp = *(UINT8 *)(* p_argv);
159
+ break;
160
+
161
+ case FFI_TYPE_SINT16:
162
+ *(ffi_arg *)argp = *(SINT16 *)(* p_argv);
163
+ break;
164
+
165
+ case FFI_TYPE_UINT16:
166
+ *(ffi_arg *)argp = *(UINT16 *)(* p_argv);
167
+ break;
168
+
169
+ case FFI_TYPE_SINT32:
170
+ *(ffi_arg *)argp = *(SINT32 *)(* p_argv);
171
+ break;
172
+
173
+ case FFI_TYPE_UINT32:
174
+ #ifdef FFI_MIPS_N32
175
+ /* The N32 ABI requires that 32-bit integers
176
+ be sign-extended to 64-bits, regardless of
177
+ whether they are signed or unsigned. */
178
+ *(ffi_arg *)argp = *(SINT32 *)(* p_argv);
179
+ #else
180
+ *(ffi_arg *)argp = *(UINT32 *)(* p_argv);
181
+ #endif
182
+ break;
183
+
184
+ /* This can only happen with 64bit slots. */
185
+ case FFI_TYPE_FLOAT:
186
+ *(float *) argp = *(float *)(* p_argv);
187
+ break;
188
+
189
+ /* Handle structures. */
190
+ default:
191
+ memcpy(argp, *p_argv, (*p_arg)->size);
192
+ break;
193
+ }
194
+ }
195
+ else
196
+ {
197
+ #ifdef FFI_MIPS_O32
198
+ memcpy(argp, *p_argv, z);
199
+ #else
200
+ {
201
+ unsigned long end = (unsigned long) argp + z;
202
+ unsigned long cap = (unsigned long) stack + bytes;
203
+
204
+ /* Check if the data will fit within the register space.
205
+ Handle it if it doesn't. */
206
+
207
+ if (end <= cap)
208
+ memcpy(argp, *p_argv, z);
209
+ else
210
+ {
211
+ unsigned long portion = cap - (unsigned long)argp;
212
+
213
+ memcpy(argp, *p_argv, portion);
214
+ argp = stack;
215
+ z -= portion;
216
+ memcpy(argp, (void*)((unsigned long)(*p_argv) + portion),
217
+ z);
218
+ }
219
+ }
220
+ #endif
221
+ }
222
+ p_argv++;
223
+ argp += z;
224
+ FIX_ARGP;
225
+ }
226
+ }
227
+
228
+ #ifdef FFI_MIPS_N32
229
+
230
+ /* The n32 spec says that if "a chunk consists solely of a double
231
+ float field (but not a double, which is part of a union), it
232
+ is passed in a floating point register. Any other chunk is
233
+ passed in an integer register". This code traverses structure
234
+ definitions and generates the appropriate flags. */
235
+
236
+ static unsigned
237
+ calc_n32_struct_flags(int soft_float, ffi_type *arg,
238
+ unsigned *loc, unsigned *arg_reg)
239
+ {
240
+ unsigned flags = 0;
241
+ unsigned index = 0;
242
+
243
+ ffi_type *e;
244
+
245
+ if (soft_float)
246
+ return 0;
247
+
248
+ while ((e = arg->elements[index]))
249
+ {
250
+ /* Align this object. */
251
+ *loc = FFI_ALIGN(*loc, e->alignment);
252
+ if (e->type == FFI_TYPE_DOUBLE)
253
+ {
254
+ /* Already aligned to FFI_SIZEOF_ARG. */
255
+ *arg_reg = *loc / FFI_SIZEOF_ARG;
256
+ if (*arg_reg > 7)
257
+ break;
258
+ flags += (FFI_TYPE_DOUBLE << (*arg_reg * FFI_FLAG_BITS));
259
+ *loc += e->size;
260
+ }
261
+ else
262
+ *loc += e->size;
263
+ index++;
264
+ }
265
+ /* Next Argument register at alignment of FFI_SIZEOF_ARG. */
266
+ *arg_reg = FFI_ALIGN(*loc, FFI_SIZEOF_ARG) / FFI_SIZEOF_ARG;
267
+
268
+ return flags;
269
+ }
270
+
271
+ static unsigned
272
+ calc_n32_return_struct_flags(int soft_float, ffi_type *arg)
273
+ {
274
+ unsigned flags = 0;
275
+ unsigned small = FFI_TYPE_SMALLSTRUCT;
276
+ ffi_type *e;
277
+
278
+ /* Returning structures under n32 is a tricky thing.
279
+ A struct with only one or two floating point fields
280
+ is returned in $f0 (and $f2 if necessary). Any other
281
+ struct results at most 128 bits are returned in $2
282
+ (the first 64 bits) and $3 (remainder, if necessary).
283
+ Larger structs are handled normally. */
284
+
285
+ if (arg->size > 16)
286
+ return 0;
287
+
288
+ if (arg->size > 8)
289
+ small = FFI_TYPE_SMALLSTRUCT2;
290
+
291
+ e = arg->elements[0];
292
+
293
+ if (e->type == FFI_TYPE_DOUBLE)
294
+ flags = FFI_TYPE_DOUBLE;
295
+ else if (e->type == FFI_TYPE_FLOAT)
296
+ flags = FFI_TYPE_FLOAT;
297
+
298
+ if (flags && (e = arg->elements[1]))
299
+ {
300
+ if (e->type == FFI_TYPE_DOUBLE)
301
+ flags += FFI_TYPE_DOUBLE << FFI_FLAG_BITS;
302
+ else if (e->type == FFI_TYPE_FLOAT)
303
+ flags += FFI_TYPE_FLOAT << FFI_FLAG_BITS;
304
+ else
305
+ return small;
306
+
307
+ if (flags && (arg->elements[2]))
308
+ {
309
+ /* There are three arguments and the first two are
310
+ floats! This must be passed the old way. */
311
+ return small;
312
+ }
313
+ if (soft_float)
314
+ flags += FFI_TYPE_STRUCT_SOFT;
315
+ }
316
+ else
317
+ if (!flags)
318
+ return small;
319
+
320
+ return flags;
321
+ }
322
+
323
+ #endif
324
+
325
+ /* Perform machine dependent cif processing */
326
+ static ffi_status ffi_prep_cif_machdep_int(ffi_cif *cif, unsigned nfixedargs)
327
+ {
328
+ cif->flags = 0;
329
+ cif->mips_nfixedargs = nfixedargs;
330
+
331
+ #ifdef FFI_MIPS_O32
332
+ /* Set the flags necessary for O32 processing. FFI_O32_SOFT_FLOAT
333
+ * does not have special handling for floating point args.
334
+ */
335
+
336
+ if (cif->rtype->type != FFI_TYPE_STRUCT && cif->abi == FFI_O32)
337
+ {
338
+ if (cif->nargs > 0 && cif->nargs == nfixedargs)
339
+ {
340
+ switch ((cif->arg_types)[0]->type)
341
+ {
342
+ case FFI_TYPE_FLOAT:
343
+ case FFI_TYPE_DOUBLE:
344
+ cif->flags += (cif->arg_types)[0]->type;
345
+ break;
346
+
347
+ default:
348
+ break;
349
+ }
350
+
351
+ if (cif->nargs > 1)
352
+ {
353
+ /* Only handle the second argument if the first
354
+ is a float or double. */
355
+ if (cif->flags)
356
+ {
357
+ switch ((cif->arg_types)[1]->type)
358
+ {
359
+ case FFI_TYPE_FLOAT:
360
+ case FFI_TYPE_DOUBLE:
361
+ cif->flags += (cif->arg_types)[1]->type << FFI_FLAG_BITS;
362
+ break;
363
+
364
+ default:
365
+ break;
366
+ }
367
+ }
368
+ }
369
+ }
370
+ }
371
+
372
+ /* Set the return type flag */
373
+
374
+ if (cif->abi == FFI_O32_SOFT_FLOAT)
375
+ {
376
+ switch (cif->rtype->type)
377
+ {
378
+ case FFI_TYPE_VOID:
379
+ case FFI_TYPE_STRUCT:
380
+ cif->flags += cif->rtype->type << (FFI_FLAG_BITS * 2);
381
+ break;
382
+
383
+ case FFI_TYPE_SINT64:
384
+ case FFI_TYPE_UINT64:
385
+ case FFI_TYPE_DOUBLE:
386
+ cif->flags += FFI_TYPE_UINT64 << (FFI_FLAG_BITS * 2);
387
+ break;
388
+
389
+ case FFI_TYPE_FLOAT:
390
+ default:
391
+ cif->flags += FFI_TYPE_INT << (FFI_FLAG_BITS * 2);
392
+ break;
393
+ }
394
+ }
395
+ else
396
+ {
397
+ /* FFI_O32 */
398
+ switch (cif->rtype->type)
399
+ {
400
+ case FFI_TYPE_VOID:
401
+ case FFI_TYPE_STRUCT:
402
+ case FFI_TYPE_FLOAT:
403
+ case FFI_TYPE_DOUBLE:
404
+ cif->flags += cif->rtype->type << (FFI_FLAG_BITS * 2);
405
+ break;
406
+
407
+ case FFI_TYPE_SINT64:
408
+ case FFI_TYPE_UINT64:
409
+ cif->flags += FFI_TYPE_UINT64 << (FFI_FLAG_BITS * 2);
410
+ break;
411
+
412
+ default:
413
+ cif->flags += FFI_TYPE_INT << (FFI_FLAG_BITS * 2);
414
+ break;
415
+ }
416
+ }
417
+ #endif
418
+
419
+ #ifdef FFI_MIPS_N32
420
+ /* Set the flags necessary for N32 processing */
421
+ {
422
+ int type;
423
+ unsigned arg_reg = 0;
424
+ unsigned loc = 0;
425
+ unsigned count = (cif->nargs < 8) ? cif->nargs : 8;
426
+ unsigned index = 0;
427
+
428
+ unsigned struct_flags = 0;
429
+ int soft_float = (cif->abi == FFI_N32_SOFT_FLOAT
430
+ || cif->abi == FFI_N64_SOFT_FLOAT);
431
+
432
+ if (cif->rtype->type == FFI_TYPE_STRUCT)
433
+ {
434
+ struct_flags = calc_n32_return_struct_flags(soft_float, cif->rtype);
435
+
436
+ if (struct_flags == 0)
437
+ {
438
+ /* This means that the structure is being passed as
439
+ a hidden argument */
440
+
441
+ arg_reg = 1;
442
+ count = (cif->nargs < 7) ? cif->nargs : 7;
443
+
444
+ cif->rstruct_flag = !0;
445
+ }
446
+ else
447
+ cif->rstruct_flag = 0;
448
+ }
449
+ else
450
+ cif->rstruct_flag = 0;
451
+
452
+ while (count-- > 0 && arg_reg < 8)
453
+ {
454
+ type = (cif->arg_types)[index]->type;
455
+
456
+ // Pass variadic arguments in integer registers even if they're floats
457
+ if (soft_float || index >= nfixedargs)
458
+ {
459
+ switch (type)
460
+ {
461
+ case FFI_TYPE_FLOAT:
462
+ type = FFI_TYPE_UINT32;
463
+ break;
464
+ case FFI_TYPE_DOUBLE:
465
+ type = FFI_TYPE_UINT64;
466
+ break;
467
+ default:
468
+ break;
469
+ }
470
+ }
471
+ switch (type)
472
+ {
473
+ case FFI_TYPE_FLOAT:
474
+ case FFI_TYPE_DOUBLE:
475
+ cif->flags +=
476
+ ((cif->arg_types)[index]->type << (arg_reg * FFI_FLAG_BITS));
477
+ arg_reg++;
478
+ break;
479
+ case FFI_TYPE_LONGDOUBLE:
480
+ /* Align it. */
481
+ arg_reg = FFI_ALIGN(arg_reg, 2);
482
+ /* Treat it as two adjacent doubles. */
483
+ if (soft_float || index >= nfixedargs)
484
+ {
485
+ arg_reg += 2;
486
+ }
487
+ else
488
+ {
489
+ cif->flags +=
490
+ (FFI_TYPE_DOUBLE << (arg_reg * FFI_FLAG_BITS));
491
+ arg_reg++;
492
+ cif->flags +=
493
+ (FFI_TYPE_DOUBLE << (arg_reg * FFI_FLAG_BITS));
494
+ arg_reg++;
495
+ }
496
+ break;
497
+
498
+ case FFI_TYPE_STRUCT:
499
+ loc = arg_reg * FFI_SIZEOF_ARG;
500
+ cif->flags += calc_n32_struct_flags(soft_float || index >= nfixedargs,
501
+ (cif->arg_types)[index],
502
+ &loc, &arg_reg);
503
+ break;
504
+
505
+ default:
506
+ arg_reg++;
507
+ break;
508
+ }
509
+
510
+ index++;
511
+ }
512
+
513
+ /* Set the return type flag */
514
+ switch (cif->rtype->type)
515
+ {
516
+ case FFI_TYPE_STRUCT:
517
+ {
518
+ if (struct_flags == 0)
519
+ {
520
+ /* The structure is returned through a hidden
521
+ first argument. Do nothing, 'cause FFI_TYPE_VOID
522
+ is 0 */
523
+ }
524
+ else
525
+ {
526
+ /* The structure is returned via some tricky
527
+ mechanism */
528
+ cif->flags += FFI_TYPE_STRUCT << (FFI_FLAG_BITS * 8);
529
+ cif->flags += struct_flags << (4 + (FFI_FLAG_BITS * 8));
530
+ }
531
+ break;
532
+ }
533
+
534
+ case FFI_TYPE_VOID:
535
+ /* Do nothing, 'cause FFI_TYPE_VOID is 0 */
536
+ break;
537
+
538
+ case FFI_TYPE_POINTER:
539
+ if (cif->abi == FFI_N32_SOFT_FLOAT || cif->abi == FFI_N32)
540
+ cif->flags += FFI_TYPE_SINT32 << (FFI_FLAG_BITS * 8);
541
+ else
542
+ cif->flags += FFI_TYPE_INT << (FFI_FLAG_BITS * 8);
543
+ break;
544
+
545
+ case FFI_TYPE_FLOAT:
546
+ if (soft_float)
547
+ {
548
+ cif->flags += FFI_TYPE_SINT32 << (FFI_FLAG_BITS * 8);
549
+ break;
550
+ }
551
+ /* else fall through */
552
+ case FFI_TYPE_DOUBLE:
553
+ if (soft_float)
554
+ cif->flags += FFI_TYPE_INT << (FFI_FLAG_BITS * 8);
555
+ else
556
+ cif->flags += cif->rtype->type << (FFI_FLAG_BITS * 8);
557
+ break;
558
+
559
+ case FFI_TYPE_LONGDOUBLE:
560
+ /* Long double is returned as if it were a struct containing
561
+ two doubles. */
562
+ if (soft_float)
563
+ {
564
+ cif->flags += FFI_TYPE_STRUCT << (FFI_FLAG_BITS * 8);
565
+ cif->flags += FFI_TYPE_SMALLSTRUCT2 << (4 + (FFI_FLAG_BITS * 8));
566
+ }
567
+ else
568
+ {
569
+ cif->flags += FFI_TYPE_STRUCT << (FFI_FLAG_BITS * 8);
570
+ cif->flags += (FFI_TYPE_DOUBLE
571
+ + (FFI_TYPE_DOUBLE << FFI_FLAG_BITS))
572
+ << (4 + (FFI_FLAG_BITS * 8));
573
+ }
574
+ break;
575
+ default:
576
+ cif->flags += FFI_TYPE_INT << (FFI_FLAG_BITS * 8);
577
+ break;
578
+ }
579
+ }
580
+ #endif
581
+
582
+ return FFI_OK;
583
+ }
584
+
585
+ ffi_status ffi_prep_cif_machdep(ffi_cif *cif)
586
+ {
587
+ return ffi_prep_cif_machdep_int(cif, cif->nargs);
588
+ }
589
+
590
+ ffi_status ffi_prep_cif_machdep_var(ffi_cif *cif,
591
+ unsigned nfixedargs,
592
+ unsigned ntotalargs MAYBE_UNUSED)
593
+ {
594
+ return ffi_prep_cif_machdep_int(cif, nfixedargs);
595
+ }
596
+
597
+ /* Low level routine for calling O32 functions */
598
+ extern int ffi_call_O32(void (*)(char *, extended_cif *, int, int),
599
+ extended_cif *, unsigned,
600
+ unsigned, unsigned *, void (*)(void), void *closure);
601
+
602
+ /* Low level routine for calling N32 functions */
603
+ extern int ffi_call_N32(void (*)(char *, extended_cif *, int, int),
604
+ extended_cif *, unsigned,
605
+ unsigned, void *, void (*)(void), void *closure);
606
+
607
+ void ffi_call_int(ffi_cif *cif, void (*fn)(void), void *rvalue,
608
+ void **avalue, void *closure)
609
+ {
610
+ extended_cif ecif;
611
+
612
+ ecif.cif = cif;
613
+ ecif.avalue = avalue;
614
+
615
+ /* If the return value is a struct and we don't have a return */
616
+ /* value address then we need to make one */
617
+
618
+ if ((rvalue == NULL) &&
619
+ (cif->rtype->type == FFI_TYPE_STRUCT))
620
+ ecif.rvalue = alloca(cif->rtype->size);
621
+ else
622
+ ecif.rvalue = rvalue;
623
+
624
+ switch (cif->abi)
625
+ {
626
+ #ifdef FFI_MIPS_O32
627
+ case FFI_O32:
628
+ case FFI_O32_SOFT_FLOAT:
629
+ ffi_call_O32(ffi_prep_args, &ecif, cif->bytes,
630
+ cif->flags, ecif.rvalue, fn, closure);
631
+ break;
632
+ #endif
633
+
634
+ #ifdef FFI_MIPS_N32
635
+ case FFI_N32:
636
+ case FFI_N32_SOFT_FLOAT:
637
+ case FFI_N64:
638
+ case FFI_N64_SOFT_FLOAT:
639
+ {
640
+ int copy_rvalue = 0;
641
+ int copy_offset = 0;
642
+ char *rvalue_copy = ecif.rvalue;
643
+ if (cif->rtype->type == FFI_TYPE_STRUCT && cif->rtype->size < 16)
644
+ {
645
+ /* For structures smaller than 16 bytes we clobber memory
646
+ in 8 byte increments. Make a copy so we don't clobber
647
+ the callers memory outside of the struct bounds. */
648
+ rvalue_copy = alloca(16);
649
+ copy_rvalue = 1;
650
+ }
651
+ else if (cif->rtype->type == FFI_TYPE_FLOAT
652
+ && (cif->abi == FFI_N64_SOFT_FLOAT
653
+ || cif->abi == FFI_N32_SOFT_FLOAT))
654
+ {
655
+ rvalue_copy = alloca (8);
656
+ copy_rvalue = 1;
657
+ #if defined(__MIPSEB__) || defined(_MIPSEB)
658
+ copy_offset = 4;
659
+ #endif
660
+ }
661
+ ffi_call_N32(ffi_prep_args, &ecif, cif->bytes,
662
+ cif->flags, rvalue_copy, fn, closure);
663
+ if (copy_rvalue)
664
+ memcpy(ecif.rvalue, rvalue_copy + copy_offset, cif->rtype->size);
665
+ }
666
+ break;
667
+ #endif
668
+
669
+ default:
670
+ FFI_ASSERT(0);
671
+ break;
672
+ }
673
+ }
674
+
675
+ void
676
+ ffi_call(ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue)
677
+ {
678
+ ffi_call_int (cif, fn, rvalue, avalue, NULL);
679
+ }
680
+
681
+ void
682
+ ffi_call_go (ffi_cif *cif, void (*fn)(void), void *rvalue,
683
+ void **avalue, void *closure)
684
+ {
685
+ ffi_call_int (cif, fn, rvalue, avalue, closure);
686
+ }
687
+
688
+
689
+ #if FFI_CLOSURES
690
+ #if defined(FFI_MIPS_O32)
691
+ extern void ffi_closure_O32(void);
692
+ extern void ffi_go_closure_O32(void);
693
+ #else
694
+ extern void ffi_closure_N32(void);
695
+ extern void ffi_go_closure_N32(void);
696
+ #endif /* FFI_MIPS_O32 */
697
+
698
+ ffi_status
699
+ ffi_prep_closure_loc (ffi_closure *closure,
700
+ ffi_cif *cif,
701
+ void (*fun)(ffi_cif*,void*,void**,void*),
702
+ void *user_data,
703
+ void *codeloc)
704
+ {
705
+ unsigned int *tramp = (unsigned int *) &closure->tramp[0];
706
+ void * fn;
707
+ char *clear_location = (char *) codeloc;
708
+
709
+ #if defined(FFI_MIPS_O32)
710
+ if (cif->abi != FFI_O32 && cif->abi != FFI_O32_SOFT_FLOAT)
711
+ return FFI_BAD_ABI;
712
+ fn = ffi_closure_O32;
713
+ #else
714
+ #if _MIPS_SIM ==_ABIN32
715
+ if (cif->abi != FFI_N32
716
+ && cif->abi != FFI_N32_SOFT_FLOAT)
717
+ return FFI_BAD_ABI;
718
+ #else
719
+ if (cif->abi != FFI_N64
720
+ && cif->abi != FFI_N64_SOFT_FLOAT)
721
+ return FFI_BAD_ABI;
722
+ #endif
723
+ fn = ffi_closure_N32;
724
+ #endif /* FFI_MIPS_O32 */
725
+
726
+ #if defined(FFI_MIPS_O32) || (_MIPS_SIM ==_ABIN32)
727
+ /* lui $25,high(fn) */
728
+ tramp[0] = 0x3c190000 | ((unsigned)fn >> 16);
729
+ /* ori $25,low(fn) */
730
+ tramp[1] = 0x37390000 | ((unsigned)fn & 0xffff);
731
+ /* lui $12,high(codeloc) */
732
+ tramp[2] = 0x3c0c0000 | ((unsigned)codeloc >> 16);
733
+ /* jr $25 */
734
+ #if !defined(__mips_isa_rev) || (__mips_isa_rev<6)
735
+ tramp[3] = 0x03200008;
736
+ #else
737
+ tramp[3] = 0x03200009;
738
+ #endif
739
+ /* ori $12,low(codeloc) */
740
+ tramp[4] = 0x358c0000 | ((unsigned)codeloc & 0xffff);
741
+ #else
742
+ /* N64 has a somewhat larger trampoline. */
743
+ /* lui $25,high(fn) */
744
+ tramp[0] = 0x3c190000 | ((unsigned long)fn >> 48);
745
+ /* lui $12,high(codeloc) */
746
+ tramp[1] = 0x3c0c0000 | ((unsigned long)codeloc >> 48);
747
+ /* ori $25,mid-high(fn) */
748
+ tramp[2] = 0x37390000 | (((unsigned long)fn >> 32 ) & 0xffff);
749
+ /* ori $12,mid-high(codeloc) */
750
+ tramp[3] = 0x358c0000 | (((unsigned long)codeloc >> 32) & 0xffff);
751
+ /* dsll $25,$25,16 */
752
+ tramp[4] = 0x0019cc38;
753
+ /* dsll $12,$12,16 */
754
+ tramp[5] = 0x000c6438;
755
+ /* ori $25,mid-low(fn) */
756
+ tramp[6] = 0x37390000 | (((unsigned long)fn >> 16 ) & 0xffff);
757
+ /* ori $12,mid-low(codeloc) */
758
+ tramp[7] = 0x358c0000 | (((unsigned long)codeloc >> 16) & 0xffff);
759
+ /* dsll $25,$25,16 */
760
+ tramp[8] = 0x0019cc38;
761
+ /* dsll $12,$12,16 */
762
+ tramp[9] = 0x000c6438;
763
+ /* ori $25,low(fn) */
764
+ tramp[10] = 0x37390000 | ((unsigned long)fn & 0xffff);
765
+ /* jr $25 */
766
+ #if !defined(__mips_isa_rev) || (__mips_isa_rev<6)
767
+ tramp[11] = 0x03200008;
768
+ #else
769
+ tramp[11] = 0x03200009;
770
+ #endif
771
+ /* ori $12,low(codeloc) */
772
+ tramp[12] = 0x358c0000 | ((unsigned long)codeloc & 0xffff);
773
+
774
+ #endif
775
+
776
+ closure->cif = cif;
777
+ closure->fun = fun;
778
+ closure->user_data = user_data;
779
+
780
+ #ifdef USE__BUILTIN___CLEAR_CACHE
781
+ __builtin___clear_cache(clear_location, clear_location + FFI_TRAMPOLINE_SIZE);
782
+ #else
783
+ cacheflush (clear_location, FFI_TRAMPOLINE_SIZE, ICACHE);
784
+ #endif
785
+ return FFI_OK;
786
+ }
787
+
788
+ /*
789
+ * Decodes the arguments to a function, which will be stored on the
790
+ * stack. AR is the pointer to the beginning of the integer arguments
791
+ * (and, depending upon the arguments, some floating-point arguments
792
+ * as well). FPR is a pointer to the area where floating point
793
+ * registers have been saved, if any.
794
+ *
795
+ * RVALUE is the location where the function return value will be
796
+ * stored. CLOSURE is the prepared closure to invoke.
797
+ *
798
+ * This function should only be called from assembly, which is in
799
+ * turn called from a trampoline.
800
+ *
801
+ * Returns the function return type.
802
+ *
803
+ * Based on the similar routine for sparc.
804
+ */
805
+ int
806
+ ffi_closure_mips_inner_O32 (ffi_cif *cif,
807
+ void (*fun)(ffi_cif*, void*, void**, void*),
808
+ void *user_data,
809
+ void *rvalue, ffi_arg *ar,
810
+ double *fpr)
811
+ {
812
+ void **avaluep;
813
+ ffi_arg *avalue;
814
+ ffi_type **arg_types;
815
+ int i, avn, argn, seen_int;
816
+
817
+ avalue = alloca (cif->nargs * sizeof (ffi_arg));
818
+ avaluep = alloca (cif->nargs * sizeof (ffi_arg));
819
+
820
+ seen_int = (cif->abi == FFI_O32_SOFT_FLOAT) || (cif->mips_nfixedargs != cif->nargs);
821
+ argn = 0;
822
+
823
+ if ((cif->flags >> (FFI_FLAG_BITS * 2)) == FFI_TYPE_STRUCT)
824
+ {
825
+ rvalue = (void *)(uintptr_t)ar[0];
826
+ argn = 1;
827
+ seen_int = 1;
828
+ }
829
+
830
+ i = 0;
831
+ avn = cif->nargs;
832
+ arg_types = cif->arg_types;
833
+
834
+ while (i < avn)
835
+ {
836
+ if (arg_types[i]->alignment == 8 && (argn & 0x1))
837
+ argn++;
838
+ if (i < 2 && !seen_int &&
839
+ (arg_types[i]->type == FFI_TYPE_FLOAT ||
840
+ arg_types[i]->type == FFI_TYPE_DOUBLE ||
841
+ arg_types[i]->type == FFI_TYPE_LONGDOUBLE))
842
+ {
843
+ #if defined(__MIPSEB__) || defined(_MIPSEB)
844
+ if (arg_types[i]->type == FFI_TYPE_FLOAT)
845
+ avaluep[i] = ((char *) &fpr[i]) + sizeof (float);
846
+ else
847
+ #endif
848
+ avaluep[i] = (char *) &fpr[i];
849
+ }
850
+ else
851
+ {
852
+ switch (arg_types[i]->type)
853
+ {
854
+ case FFI_TYPE_SINT8:
855
+ avaluep[i] = &avalue[i];
856
+ *(SINT8 *) &avalue[i] = (SINT8) ar[argn];
857
+ break;
858
+
859
+ case FFI_TYPE_UINT8:
860
+ avaluep[i] = &avalue[i];
861
+ *(UINT8 *) &avalue[i] = (UINT8) ar[argn];
862
+ break;
863
+
864
+ case FFI_TYPE_SINT16:
865
+ avaluep[i] = &avalue[i];
866
+ *(SINT16 *) &avalue[i] = (SINT16) ar[argn];
867
+ break;
868
+
869
+ case FFI_TYPE_UINT16:
870
+ avaluep[i] = &avalue[i];
871
+ *(UINT16 *) &avalue[i] = (UINT16) ar[argn];
872
+ break;
873
+
874
+ default:
875
+ avaluep[i] = (char *) &ar[argn];
876
+ break;
877
+ }
878
+ seen_int = 1;
879
+ }
880
+ argn += FFI_ALIGN(arg_types[i]->size, FFI_SIZEOF_ARG) / FFI_SIZEOF_ARG;
881
+ i++;
882
+ }
883
+
884
+ /* Invoke the closure. */
885
+ fun(cif, rvalue, avaluep, user_data);
886
+
887
+ if (cif->abi == FFI_O32_SOFT_FLOAT)
888
+ {
889
+ switch (cif->rtype->type)
890
+ {
891
+ case FFI_TYPE_FLOAT:
892
+ return FFI_TYPE_INT;
893
+ case FFI_TYPE_DOUBLE:
894
+ return FFI_TYPE_UINT64;
895
+ default:
896
+ return cif->rtype->type;
897
+ }
898
+ }
899
+ else
900
+ {
901
+ return cif->rtype->type;
902
+ }
903
+ }
904
+
905
+ #if defined(FFI_MIPS_N32)
906
+
907
+ static void
908
+ copy_struct_N32(char *target, unsigned offset, ffi_abi abi, ffi_type *type,
909
+ int argn, unsigned arg_offset, ffi_arg *ar,
910
+ ffi_arg *fpr, int soft_float)
911
+ {
912
+ ffi_type **elt_typep = type->elements;
913
+ while(*elt_typep)
914
+ {
915
+ ffi_type *elt_type = *elt_typep;
916
+ unsigned o;
917
+ char *tp;
918
+ char *argp;
919
+ char *fpp;
920
+
921
+ o = FFI_ALIGN(offset, elt_type->alignment);
922
+ arg_offset += o - offset;
923
+ offset = o;
924
+ argn += arg_offset / sizeof(ffi_arg);
925
+ arg_offset = arg_offset % sizeof(ffi_arg);
926
+
927
+ argp = (char *)(ar + argn);
928
+ fpp = (char *)(argn >= 8 ? ar + argn : fpr + argn);
929
+
930
+ tp = target + offset;
931
+
932
+ if (elt_type->type == FFI_TYPE_DOUBLE && !soft_float)
933
+ *(double *)tp = *(double *)fpp;
934
+ else
935
+ memcpy(tp, argp + arg_offset, elt_type->size);
936
+
937
+ offset += elt_type->size;
938
+ arg_offset += elt_type->size;
939
+ elt_typep++;
940
+ argn += arg_offset / sizeof(ffi_arg);
941
+ arg_offset = arg_offset % sizeof(ffi_arg);
942
+ }
943
+ }
944
+
945
+ /*
946
+ * Decodes the arguments to a function, which will be stored on the
947
+ * stack. AR is the pointer to the beginning of the integer
948
+ * arguments. FPR is a pointer to the area where floating point
949
+ * registers have been saved.
950
+ *
951
+ * RVALUE is the location where the function return value will be
952
+ * stored. CLOSURE is the prepared closure to invoke.
953
+ *
954
+ * This function should only be called from assembly, which is in
955
+ * turn called from a trampoline.
956
+ *
957
+ * Returns the function return flags.
958
+ *
959
+ */
960
+ int
961
+ ffi_closure_mips_inner_N32 (ffi_cif *cif,
962
+ void (*fun)(ffi_cif*, void*, void**, void*),
963
+ void *user_data,
964
+ void *rvalue, ffi_arg *ar,
965
+ ffi_arg *fpr)
966
+ {
967
+ void **avaluep;
968
+ ffi_arg *avalue;
969
+ ffi_type **arg_types;
970
+ int i, avn, argn;
971
+ int soft_float;
972
+ ffi_arg *argp;
973
+
974
+ soft_float = cif->abi == FFI_N64_SOFT_FLOAT
975
+ || cif->abi == FFI_N32_SOFT_FLOAT;
976
+ avalue = alloca (cif->nargs * sizeof (ffi_arg));
977
+ avaluep = alloca (cif->nargs * sizeof (ffi_arg));
978
+
979
+ argn = 0;
980
+
981
+ if (cif->rstruct_flag)
982
+ {
983
+ #if _MIPS_SIM==_ABIN32
984
+ rvalue = (void *)(UINT32)ar[0];
985
+ #else /* N64 */
986
+ rvalue = (void *)ar[0];
987
+ #endif
988
+ argn = 1;
989
+ }
990
+
991
+ i = 0;
992
+ avn = cif->nargs;
993
+ arg_types = cif->arg_types;
994
+
995
+ while (i < avn)
996
+ {
997
+ if (arg_types[i]->type == FFI_TYPE_FLOAT
998
+ || arg_types[i]->type == FFI_TYPE_DOUBLE
999
+ || arg_types[i]->type == FFI_TYPE_LONGDOUBLE)
1000
+ {
1001
+ argp = (argn >= 8 || i >= cif->mips_nfixedargs || soft_float) ? ar + argn : fpr + argn;
1002
+ if ((arg_types[i]->type == FFI_TYPE_LONGDOUBLE) && ((uintptr_t)argp & (arg_types[i]->alignment-1)))
1003
+ {
1004
+ argp=(ffi_arg*)FFI_ALIGN(argp,arg_types[i]->alignment);
1005
+ argn++;
1006
+ }
1007
+ #if defined(__MIPSEB__) || defined(_MIPSEB)
1008
+ if (arg_types[i]->type == FFI_TYPE_FLOAT && argn < 8)
1009
+ avaluep[i] = ((char *) argp) + sizeof (float);
1010
+ else
1011
+ #endif
1012
+ avaluep[i] = (char *) argp;
1013
+ }
1014
+ else
1015
+ {
1016
+ unsigned type = arg_types[i]->type;
1017
+
1018
+ if (arg_types[i]->alignment > sizeof(ffi_arg))
1019
+ argn = FFI_ALIGN(argn, arg_types[i]->alignment / sizeof(ffi_arg));
1020
+
1021
+ argp = ar + argn;
1022
+
1023
+ /* The size of a pointer depends on the ABI */
1024
+ if (type == FFI_TYPE_POINTER)
1025
+ type = (cif->abi == FFI_N64 || cif->abi == FFI_N64_SOFT_FLOAT)
1026
+ ? FFI_TYPE_SINT64 : FFI_TYPE_SINT32;
1027
+
1028
+ if (soft_float && type == FFI_TYPE_FLOAT)
1029
+ type = FFI_TYPE_UINT32;
1030
+
1031
+ switch (type)
1032
+ {
1033
+ case FFI_TYPE_SINT8:
1034
+ avaluep[i] = &avalue[i];
1035
+ *(SINT8 *) &avalue[i] = (SINT8) *argp;
1036
+ break;
1037
+
1038
+ case FFI_TYPE_UINT8:
1039
+ avaluep[i] = &avalue[i];
1040
+ *(UINT8 *) &avalue[i] = (UINT8) *argp;
1041
+ break;
1042
+
1043
+ case FFI_TYPE_SINT16:
1044
+ avaluep[i] = &avalue[i];
1045
+ *(SINT16 *) &avalue[i] = (SINT16) *argp;
1046
+ break;
1047
+
1048
+ case FFI_TYPE_UINT16:
1049
+ avaluep[i] = &avalue[i];
1050
+ *(UINT16 *) &avalue[i] = (UINT16) *argp;
1051
+ break;
1052
+
1053
+ case FFI_TYPE_SINT32:
1054
+ avaluep[i] = &avalue[i];
1055
+ *(SINT32 *) &avalue[i] = (SINT32) *argp;
1056
+ break;
1057
+
1058
+ case FFI_TYPE_UINT32:
1059
+ avaluep[i] = &avalue[i];
1060
+ *(UINT32 *) &avalue[i] = (UINT32) *argp;
1061
+ break;
1062
+
1063
+ case FFI_TYPE_STRUCT:
1064
+ if (argn < 8)
1065
+ {
1066
+ /* Allocate space for the struct as at least part of
1067
+ it was passed in registers. */
1068
+ avaluep[i] = alloca(arg_types[i]->size);
1069
+ copy_struct_N32(avaluep[i], 0, cif->abi, arg_types[i],
1070
+ argn, 0, ar, fpr, i >= cif->mips_nfixedargs || soft_float);
1071
+
1072
+ break;
1073
+ }
1074
+ /* Else fall through. */
1075
+ default:
1076
+ avaluep[i] = (char *) argp;
1077
+ break;
1078
+ }
1079
+ }
1080
+ argn += FFI_ALIGN(arg_types[i]->size, sizeof(ffi_arg)) / sizeof(ffi_arg);
1081
+ i++;
1082
+ }
1083
+
1084
+ /* Invoke the closure. */
1085
+ fun (cif, rvalue, avaluep, user_data);
1086
+
1087
+ return cif->flags >> (FFI_FLAG_BITS * 8);
1088
+ }
1089
+
1090
+ #endif /* FFI_MIPS_N32 */
1091
+
1092
+ #if defined(FFI_MIPS_O32)
1093
+ extern void ffi_closure_O32(void);
1094
+ extern void ffi_go_closure_O32(void);
1095
+ #else
1096
+ extern void ffi_closure_N32(void);
1097
+ extern void ffi_go_closure_N32(void);
1098
+ #endif /* FFI_MIPS_O32 */
1099
+
1100
+ ffi_status
1101
+ ffi_prep_go_closure (ffi_go_closure* closure, ffi_cif* cif,
1102
+ void (*fun)(ffi_cif*,void*,void**,void*))
1103
+ {
1104
+ void * fn;
1105
+
1106
+ #if defined(FFI_MIPS_O32)
1107
+ if (cif->abi != FFI_O32 && cif->abi != FFI_O32_SOFT_FLOAT)
1108
+ return FFI_BAD_ABI;
1109
+ fn = ffi_go_closure_O32;
1110
+ #else
1111
+ #if _MIPS_SIM ==_ABIN32
1112
+ if (cif->abi != FFI_N32
1113
+ && cif->abi != FFI_N32_SOFT_FLOAT)
1114
+ return FFI_BAD_ABI;
1115
+ #else
1116
+ if (cif->abi != FFI_N64
1117
+ && cif->abi != FFI_N64_SOFT_FLOAT)
1118
+ return FFI_BAD_ABI;
1119
+ #endif
1120
+ fn = ffi_go_closure_N32;
1121
+ #endif /* FFI_MIPS_O32 */
1122
+
1123
+ closure->tramp = (void *)fn;
1124
+ closure->cif = cif;
1125
+ closure->fun = fun;
1126
+
1127
+ return FFI_OK;
1128
+ }
1129
+
1130
+ #endif /* FFI_CLOSURES */