immunio 0.15.4 → 0.16.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (454) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +0 -27
  3. data/ext/immunio/Rakefile +9 -0
  4. data/lib/immunio/plugins/active_record.rb +1 -1
  5. data/lib/immunio/plugins/active_record_relation.rb +1 -1
  6. data/lib/immunio/plugins/environment_reporter.rb +20 -0
  7. data/lib/immunio/rufus_lua_ext/ref.rb +1 -3
  8. data/lib/immunio/version.rb +1 -1
  9. data/lib/immunio/vm.rb +1 -2
  10. data/lua-hooks/Makefile +97 -0
  11. data/lua-hooks/ext/all.c +41 -52
  12. data/lua-hooks/ext/all.o +0 -0
  13. data/lua-hooks/ext/libinjection/libinjection_html5.o +0 -0
  14. data/lua-hooks/ext/libinjection/libinjection_sqli.o +0 -0
  15. data/lua-hooks/ext/libinjection/libinjection_xss.o +0 -0
  16. data/lua-hooks/ext/libinjection/lualib.c +2 -2
  17. data/lua-hooks/ext/lpeg/lpcap.c +2 -2
  18. data/lua-hooks/ext/lpeg/lpcap.o +0 -0
  19. data/lua-hooks/ext/lpeg/lpcode.c +2 -2
  20. data/lua-hooks/ext/lpeg/lpcode.h +1 -1
  21. data/lua-hooks/ext/lpeg/lpcode.o +0 -0
  22. data/lua-hooks/ext/lpeg/lpprint.o +0 -0
  23. data/lua-hooks/ext/lpeg/lptree.c +2 -2
  24. data/lua-hooks/ext/lpeg/lptypes.h +1 -1
  25. data/lua-hooks/ext/lpeg/lpvm.c +2 -2
  26. data/lua-hooks/ext/lpeg/lpvm.o +0 -0
  27. data/lua-hooks/ext/lua-cmsgpack/lua_cmsgpack.c +16 -3
  28. data/lua-hooks/ext/lua-snapshot/snapshot.c +14 -7
  29. data/lua-hooks/ext/luajit/COPYRIGHT +56 -0
  30. data/lua-hooks/ext/luajit/Makefile +159 -0
  31. data/lua-hooks/ext/luajit/README +16 -0
  32. data/lua-hooks/ext/luajit/doc/bluequad-print.css +166 -0
  33. data/lua-hooks/ext/luajit/doc/bluequad.css +325 -0
  34. data/lua-hooks/ext/luajit/doc/changes.html +804 -0
  35. data/lua-hooks/ext/luajit/doc/contact.html +104 -0
  36. data/lua-hooks/ext/luajit/doc/ext_c_api.html +189 -0
  37. data/lua-hooks/ext/luajit/doc/ext_ffi.html +332 -0
  38. data/lua-hooks/ext/luajit/doc/ext_ffi_api.html +570 -0
  39. data/lua-hooks/ext/luajit/doc/ext_ffi_semantics.html +1261 -0
  40. data/lua-hooks/ext/luajit/doc/ext_ffi_tutorial.html +603 -0
  41. data/lua-hooks/ext/luajit/doc/ext_jit.html +201 -0
  42. data/lua-hooks/ext/luajit/doc/ext_profiler.html +365 -0
  43. data/lua-hooks/ext/luajit/doc/extensions.html +448 -0
  44. data/lua-hooks/ext/luajit/doc/faq.html +186 -0
  45. data/lua-hooks/ext/luajit/doc/img/contact.png +0 -0
  46. data/lua-hooks/ext/luajit/doc/install.html +659 -0
  47. data/lua-hooks/ext/luajit/doc/luajit.html +236 -0
  48. data/lua-hooks/ext/luajit/doc/running.html +309 -0
  49. data/lua-hooks/ext/luajit/doc/status.html +118 -0
  50. data/lua-hooks/ext/luajit/dynasm/dasm_arm.h +456 -0
  51. data/lua-hooks/ext/luajit/dynasm/dasm_arm.lua +1125 -0
  52. data/lua-hooks/ext/luajit/dynasm/dasm_arm64.h +518 -0
  53. data/lua-hooks/ext/luajit/dynasm/dasm_arm64.lua +1166 -0
  54. data/lua-hooks/ext/luajit/dynasm/dasm_mips.h +416 -0
  55. data/lua-hooks/ext/luajit/dynasm/dasm_mips.lua +953 -0
  56. data/lua-hooks/ext/luajit/dynasm/dasm_ppc.h +419 -0
  57. data/lua-hooks/ext/luajit/dynasm/dasm_ppc.lua +1919 -0
  58. data/lua-hooks/ext/luajit/dynasm/dasm_proto.h +83 -0
  59. data/lua-hooks/ext/luajit/dynasm/dasm_x64.lua +12 -0
  60. data/lua-hooks/ext/luajit/dynasm/dasm_x86.h +471 -0
  61. data/lua-hooks/ext/luajit/dynasm/dasm_x86.lua +1945 -0
  62. data/lua-hooks/ext/luajit/dynasm/dynasm.lua +1094 -0
  63. data/lua-hooks/ext/luajit/etc/luajit.1 +88 -0
  64. data/lua-hooks/ext/luajit/etc/luajit.pc +25 -0
  65. data/lua-hooks/ext/luajit/src/Makefile +697 -0
  66. data/lua-hooks/ext/luajit/src/Makefile.dep +244 -0
  67. data/lua-hooks/ext/luajit/src/host/README +4 -0
  68. data/lua-hooks/ext/luajit/src/host/buildvm +0 -0
  69. data/lua-hooks/ext/luajit/src/host/buildvm.c +518 -0
  70. data/lua-hooks/ext/luajit/src/host/buildvm.h +105 -0
  71. data/lua-hooks/ext/luajit/src/host/buildvm.o +0 -0
  72. data/lua-hooks/ext/luajit/src/host/buildvm_arch.h +7449 -0
  73. data/lua-hooks/ext/luajit/src/host/buildvm_asm.c +345 -0
  74. data/lua-hooks/ext/luajit/src/host/buildvm_asm.o +0 -0
  75. data/lua-hooks/ext/luajit/src/host/buildvm_fold.c +229 -0
  76. data/lua-hooks/ext/luajit/src/host/buildvm_fold.o +0 -0
  77. data/lua-hooks/ext/luajit/src/host/buildvm_lib.c +457 -0
  78. data/lua-hooks/ext/luajit/src/host/buildvm_lib.o +0 -0
  79. data/lua-hooks/ext/luajit/src/host/buildvm_libbc.h +45 -0
  80. data/lua-hooks/ext/luajit/src/host/buildvm_peobj.c +368 -0
  81. data/lua-hooks/ext/luajit/src/host/buildvm_peobj.o +0 -0
  82. data/lua-hooks/ext/luajit/src/host/genlibbc.lua +197 -0
  83. data/lua-hooks/ext/luajit/src/host/genminilua.lua +428 -0
  84. data/lua-hooks/ext/luajit/src/host/minilua +0 -0
  85. data/lua-hooks/ext/luajit/src/host/minilua.c +7770 -0
  86. data/lua-hooks/ext/luajit/src/host/minilua.o +0 -0
  87. data/lua-hooks/ext/luajit/src/jit/bc.lua +190 -0
  88. data/lua-hooks/ext/luajit/src/jit/bcsave.lua +661 -0
  89. data/lua-hooks/ext/luajit/src/jit/dis_arm.lua +689 -0
  90. data/lua-hooks/ext/luajit/src/jit/dis_mips.lua +428 -0
  91. data/lua-hooks/ext/luajit/src/jit/dis_mipsel.lua +17 -0
  92. data/lua-hooks/ext/luajit/src/jit/dis_ppc.lua +591 -0
  93. data/lua-hooks/ext/luajit/src/jit/dis_x64.lua +17 -0
  94. data/lua-hooks/ext/luajit/src/jit/dis_x86.lua +838 -0
  95. data/lua-hooks/ext/luajit/src/jit/dump.lua +706 -0
  96. data/lua-hooks/ext/luajit/src/jit/p.lua +310 -0
  97. data/lua-hooks/ext/luajit/src/jit/v.lua +170 -0
  98. data/lua-hooks/ext/luajit/src/jit/vmdef.lua +362 -0
  99. data/lua-hooks/ext/luajit/src/jit/zone.lua +45 -0
  100. data/lua-hooks/ext/{lua → luajit/src}/lauxlib.h +10 -17
  101. data/lua-hooks/ext/luajit/src/lib_aux.c +356 -0
  102. data/lua-hooks/ext/luajit/src/lib_aux.o +0 -0
  103. data/lua-hooks/ext/luajit/src/lib_aux_dyn.o +0 -0
  104. data/lua-hooks/ext/luajit/src/lib_base.c +664 -0
  105. data/lua-hooks/ext/luajit/src/lib_base.o +0 -0
  106. data/lua-hooks/ext/luajit/src/lib_base_dyn.o +0 -0
  107. data/lua-hooks/ext/luajit/src/lib_bit.c +180 -0
  108. data/lua-hooks/ext/luajit/src/lib_bit.o +0 -0
  109. data/lua-hooks/ext/luajit/src/lib_bit_dyn.o +0 -0
  110. data/lua-hooks/ext/luajit/src/lib_debug.c +405 -0
  111. data/lua-hooks/ext/luajit/src/lib_debug.o +0 -0
  112. data/lua-hooks/ext/luajit/src/lib_debug_dyn.o +0 -0
  113. data/lua-hooks/ext/luajit/src/lib_ffi.c +872 -0
  114. data/lua-hooks/ext/luajit/src/lib_ffi.o +0 -0
  115. data/lua-hooks/ext/luajit/src/lib_ffi_dyn.o +0 -0
  116. data/lua-hooks/ext/luajit/src/lib_init.c +55 -0
  117. data/lua-hooks/ext/luajit/src/lib_init.o +0 -0
  118. data/lua-hooks/ext/luajit/src/lib_init_dyn.o +0 -0
  119. data/lua-hooks/ext/luajit/src/lib_io.c +541 -0
  120. data/lua-hooks/ext/luajit/src/lib_io.o +0 -0
  121. data/lua-hooks/ext/luajit/src/lib_io_dyn.o +0 -0
  122. data/lua-hooks/ext/luajit/src/lib_jit.c +767 -0
  123. data/lua-hooks/ext/luajit/src/lib_jit.o +0 -0
  124. data/lua-hooks/ext/luajit/src/lib_jit_dyn.o +0 -0
  125. data/lua-hooks/ext/luajit/src/lib_math.c +230 -0
  126. data/lua-hooks/ext/luajit/src/lib_math.o +0 -0
  127. data/lua-hooks/ext/luajit/src/lib_math_dyn.o +0 -0
  128. data/lua-hooks/ext/luajit/src/lib_os.c +292 -0
  129. data/lua-hooks/ext/luajit/src/lib_os.o +0 -0
  130. data/lua-hooks/ext/luajit/src/lib_os_dyn.o +0 -0
  131. data/lua-hooks/ext/luajit/src/lib_package.c +610 -0
  132. data/lua-hooks/ext/luajit/src/lib_package.o +0 -0
  133. data/lua-hooks/ext/luajit/src/lib_package_dyn.o +0 -0
  134. data/lua-hooks/ext/luajit/src/lib_string.c +752 -0
  135. data/lua-hooks/ext/luajit/src/lib_string.o +0 -0
  136. data/lua-hooks/ext/luajit/src/lib_string_dyn.o +0 -0
  137. data/lua-hooks/ext/luajit/src/lib_table.c +307 -0
  138. data/lua-hooks/ext/luajit/src/lib_table.o +0 -0
  139. data/lua-hooks/ext/luajit/src/lib_table_dyn.o +0 -0
  140. data/lua-hooks/ext/luajit/src/libluajit.a +0 -0
  141. data/lua-hooks/ext/luajit/src/libluajit.so +0 -0
  142. data/lua-hooks/ext/luajit/src/lj.supp +26 -0
  143. data/lua-hooks/ext/luajit/src/lj_alloc.c +1398 -0
  144. data/lua-hooks/ext/luajit/src/lj_alloc.h +17 -0
  145. data/lua-hooks/ext/luajit/src/lj_alloc.o +0 -0
  146. data/lua-hooks/ext/luajit/src/lj_alloc_dyn.o +0 -0
  147. data/lua-hooks/ext/luajit/src/lj_api.c +1210 -0
  148. data/lua-hooks/ext/luajit/src/lj_api.o +0 -0
  149. data/lua-hooks/ext/luajit/src/lj_api_dyn.o +0 -0
  150. data/lua-hooks/ext/luajit/src/lj_arch.h +509 -0
  151. data/lua-hooks/ext/luajit/src/lj_asm.c +2278 -0
  152. data/lua-hooks/ext/luajit/src/lj_asm.h +17 -0
  153. data/lua-hooks/ext/luajit/src/lj_asm.o +0 -0
  154. data/lua-hooks/ext/luajit/src/lj_asm_arm.h +2217 -0
  155. data/lua-hooks/ext/luajit/src/lj_asm_dyn.o +0 -0
  156. data/lua-hooks/ext/luajit/src/lj_asm_mips.h +1833 -0
  157. data/lua-hooks/ext/luajit/src/lj_asm_ppc.h +2015 -0
  158. data/lua-hooks/ext/luajit/src/lj_asm_x86.h +2634 -0
  159. data/lua-hooks/ext/luajit/src/lj_bc.c +14 -0
  160. data/lua-hooks/ext/luajit/src/lj_bc.h +265 -0
  161. data/lua-hooks/ext/luajit/src/lj_bc.o +0 -0
  162. data/lua-hooks/ext/luajit/src/lj_bc_dyn.o +0 -0
  163. data/lua-hooks/ext/luajit/src/lj_bcdef.h +220 -0
  164. data/lua-hooks/ext/luajit/src/lj_bcdump.h +68 -0
  165. data/lua-hooks/ext/luajit/src/lj_bcread.c +457 -0
  166. data/lua-hooks/ext/luajit/src/lj_bcread.o +0 -0
  167. data/lua-hooks/ext/luajit/src/lj_bcread_dyn.o +0 -0
  168. data/lua-hooks/ext/luajit/src/lj_bcwrite.c +361 -0
  169. data/lua-hooks/ext/luajit/src/lj_bcwrite.o +0 -0
  170. data/lua-hooks/ext/luajit/src/lj_bcwrite_dyn.o +0 -0
  171. data/lua-hooks/ext/luajit/src/lj_buf.c +234 -0
  172. data/lua-hooks/ext/luajit/src/lj_buf.h +105 -0
  173. data/lua-hooks/ext/luajit/src/lj_buf.o +0 -0
  174. data/lua-hooks/ext/luajit/src/lj_buf_dyn.o +0 -0
  175. data/lua-hooks/ext/luajit/src/lj_carith.c +429 -0
  176. data/lua-hooks/ext/luajit/src/lj_carith.h +37 -0
  177. data/lua-hooks/ext/luajit/src/lj_carith.o +0 -0
  178. data/lua-hooks/ext/luajit/src/lj_carith_dyn.o +0 -0
  179. data/lua-hooks/ext/luajit/src/lj_ccall.c +984 -0
  180. data/lua-hooks/ext/luajit/src/lj_ccall.h +178 -0
  181. data/lua-hooks/ext/luajit/src/lj_ccall.o +0 -0
  182. data/lua-hooks/ext/luajit/src/lj_ccall_dyn.o +0 -0
  183. data/lua-hooks/ext/luajit/src/lj_ccallback.c +712 -0
  184. data/lua-hooks/ext/luajit/src/lj_ccallback.h +25 -0
  185. data/lua-hooks/ext/luajit/src/lj_ccallback.o +0 -0
  186. data/lua-hooks/ext/luajit/src/lj_ccallback_dyn.o +0 -0
  187. data/lua-hooks/ext/luajit/src/lj_cconv.c +752 -0
  188. data/lua-hooks/ext/luajit/src/lj_cconv.h +70 -0
  189. data/lua-hooks/ext/luajit/src/lj_cconv.o +0 -0
  190. data/lua-hooks/ext/luajit/src/lj_cconv_dyn.o +0 -0
  191. data/lua-hooks/ext/luajit/src/lj_cdata.c +288 -0
  192. data/lua-hooks/ext/luajit/src/lj_cdata.h +76 -0
  193. data/lua-hooks/ext/luajit/src/lj_cdata.o +0 -0
  194. data/lua-hooks/ext/luajit/src/lj_cdata_dyn.o +0 -0
  195. data/lua-hooks/ext/luajit/src/lj_char.c +43 -0
  196. data/lua-hooks/ext/luajit/src/lj_char.h +42 -0
  197. data/lua-hooks/ext/luajit/src/lj_char.o +0 -0
  198. data/lua-hooks/ext/luajit/src/lj_char_dyn.o +0 -0
  199. data/lua-hooks/ext/luajit/src/lj_clib.c +418 -0
  200. data/lua-hooks/ext/luajit/src/lj_clib.h +29 -0
  201. data/lua-hooks/ext/luajit/src/lj_clib.o +0 -0
  202. data/lua-hooks/ext/luajit/src/lj_clib_dyn.o +0 -0
  203. data/lua-hooks/ext/luajit/src/lj_cparse.c +1862 -0
  204. data/lua-hooks/ext/luajit/src/lj_cparse.h +65 -0
  205. data/lua-hooks/ext/luajit/src/lj_cparse.o +0 -0
  206. data/lua-hooks/ext/luajit/src/lj_cparse_dyn.o +0 -0
  207. data/lua-hooks/ext/luajit/src/lj_crecord.c +1834 -0
  208. data/lua-hooks/ext/luajit/src/lj_crecord.h +38 -0
  209. data/lua-hooks/ext/luajit/src/lj_crecord.o +0 -0
  210. data/lua-hooks/ext/luajit/src/lj_crecord_dyn.o +0 -0
  211. data/lua-hooks/ext/luajit/src/lj_ctype.c +635 -0
  212. data/lua-hooks/ext/luajit/src/lj_ctype.h +461 -0
  213. data/lua-hooks/ext/luajit/src/lj_ctype.o +0 -0
  214. data/lua-hooks/ext/luajit/src/lj_ctype_dyn.o +0 -0
  215. data/lua-hooks/ext/luajit/src/lj_debug.c +699 -0
  216. data/lua-hooks/ext/luajit/src/lj_debug.h +65 -0
  217. data/lua-hooks/ext/luajit/src/lj_debug.o +0 -0
  218. data/lua-hooks/ext/luajit/src/lj_debug_dyn.o +0 -0
  219. data/lua-hooks/ext/luajit/src/lj_def.h +365 -0
  220. data/lua-hooks/ext/luajit/src/lj_dispatch.c +557 -0
  221. data/lua-hooks/ext/luajit/src/lj_dispatch.h +138 -0
  222. data/lua-hooks/ext/luajit/src/lj_dispatch.o +0 -0
  223. data/lua-hooks/ext/luajit/src/lj_dispatch_dyn.o +0 -0
  224. data/lua-hooks/ext/luajit/src/lj_emit_arm.h +356 -0
  225. data/lua-hooks/ext/luajit/src/lj_emit_mips.h +211 -0
  226. data/lua-hooks/ext/luajit/src/lj_emit_ppc.h +238 -0
  227. data/lua-hooks/ext/luajit/src/lj_emit_x86.h +462 -0
  228. data/lua-hooks/ext/luajit/src/lj_err.c +794 -0
  229. data/lua-hooks/ext/luajit/src/lj_err.h +41 -0
  230. data/lua-hooks/ext/luajit/src/lj_err.o +0 -0
  231. data/lua-hooks/ext/luajit/src/lj_err_dyn.o +0 -0
  232. data/lua-hooks/ext/luajit/src/lj_errmsg.h +190 -0
  233. data/lua-hooks/ext/luajit/src/lj_ff.h +18 -0
  234. data/lua-hooks/ext/luajit/src/lj_ffdef.h +209 -0
  235. data/lua-hooks/ext/luajit/src/lj_ffrecord.c +1247 -0
  236. data/lua-hooks/ext/luajit/src/lj_ffrecord.h +24 -0
  237. data/lua-hooks/ext/luajit/src/lj_ffrecord.o +0 -0
  238. data/lua-hooks/ext/luajit/src/lj_ffrecord_dyn.o +0 -0
  239. data/lua-hooks/ext/luajit/src/lj_folddef.h +1138 -0
  240. data/lua-hooks/ext/luajit/src/lj_frame.h +259 -0
  241. data/lua-hooks/ext/luajit/src/lj_func.c +185 -0
  242. data/lua-hooks/ext/luajit/src/lj_func.h +24 -0
  243. data/lua-hooks/ext/luajit/src/lj_func.o +0 -0
  244. data/lua-hooks/ext/luajit/src/lj_func_dyn.o +0 -0
  245. data/lua-hooks/ext/luajit/src/lj_gc.c +845 -0
  246. data/lua-hooks/ext/luajit/src/lj_gc.h +134 -0
  247. data/lua-hooks/ext/luajit/src/lj_gc.o +0 -0
  248. data/lua-hooks/ext/luajit/src/lj_gc_dyn.o +0 -0
  249. data/lua-hooks/ext/luajit/src/lj_gdbjit.c +787 -0
  250. data/lua-hooks/ext/luajit/src/lj_gdbjit.h +22 -0
  251. data/lua-hooks/ext/luajit/src/lj_gdbjit.o +0 -0
  252. data/lua-hooks/ext/luajit/src/lj_gdbjit_dyn.o +0 -0
  253. data/lua-hooks/ext/luajit/src/lj_ir.c +505 -0
  254. data/lua-hooks/ext/luajit/src/lj_ir.h +577 -0
  255. data/lua-hooks/ext/luajit/src/lj_ir.o +0 -0
  256. data/lua-hooks/ext/luajit/src/lj_ir_dyn.o +0 -0
  257. data/lua-hooks/ext/luajit/src/lj_ircall.h +321 -0
  258. data/lua-hooks/ext/luajit/src/lj_iropt.h +161 -0
  259. data/lua-hooks/ext/luajit/src/lj_jit.h +440 -0
  260. data/lua-hooks/ext/luajit/src/lj_lex.c +482 -0
  261. data/lua-hooks/ext/luajit/src/lj_lex.h +86 -0
  262. data/lua-hooks/ext/luajit/src/lj_lex.o +0 -0
  263. data/lua-hooks/ext/luajit/src/lj_lex_dyn.o +0 -0
  264. data/lua-hooks/ext/luajit/src/lj_lib.c +303 -0
  265. data/lua-hooks/ext/luajit/src/lj_lib.h +115 -0
  266. data/lua-hooks/ext/luajit/src/lj_lib.o +0 -0
  267. data/lua-hooks/ext/luajit/src/lj_lib_dyn.o +0 -0
  268. data/lua-hooks/ext/luajit/src/lj_libdef.h +414 -0
  269. data/lua-hooks/ext/luajit/src/lj_load.c +168 -0
  270. data/lua-hooks/ext/luajit/src/lj_load.o +0 -0
  271. data/lua-hooks/ext/luajit/src/lj_load_dyn.o +0 -0
  272. data/lua-hooks/ext/luajit/src/lj_mcode.c +386 -0
  273. data/lua-hooks/ext/luajit/src/lj_mcode.h +30 -0
  274. data/lua-hooks/ext/luajit/src/lj_mcode.o +0 -0
  275. data/lua-hooks/ext/luajit/src/lj_mcode_dyn.o +0 -0
  276. data/lua-hooks/ext/luajit/src/lj_meta.c +477 -0
  277. data/lua-hooks/ext/luajit/src/lj_meta.h +38 -0
  278. data/lua-hooks/ext/luajit/src/lj_meta.o +0 -0
  279. data/lua-hooks/ext/luajit/src/lj_meta_dyn.o +0 -0
  280. data/lua-hooks/ext/luajit/src/lj_obj.c +50 -0
  281. data/lua-hooks/ext/luajit/src/lj_obj.h +976 -0
  282. data/lua-hooks/ext/luajit/src/lj_obj.o +0 -0
  283. data/lua-hooks/ext/luajit/src/lj_obj_dyn.o +0 -0
  284. data/lua-hooks/ext/luajit/src/lj_opt_dce.c +78 -0
  285. data/lua-hooks/ext/luajit/src/lj_opt_dce.o +0 -0
  286. data/lua-hooks/ext/luajit/src/lj_opt_dce_dyn.o +0 -0
  287. data/lua-hooks/ext/luajit/src/lj_opt_fold.c +2488 -0
  288. data/lua-hooks/ext/luajit/src/lj_opt_fold.o +0 -0
  289. data/lua-hooks/ext/luajit/src/lj_opt_fold_dyn.o +0 -0
  290. data/lua-hooks/ext/luajit/src/lj_opt_loop.c +449 -0
  291. data/lua-hooks/ext/luajit/src/lj_opt_loop.o +0 -0
  292. data/lua-hooks/ext/luajit/src/lj_opt_loop_dyn.o +0 -0
  293. data/lua-hooks/ext/luajit/src/lj_opt_mem.c +935 -0
  294. data/lua-hooks/ext/luajit/src/lj_opt_mem.o +0 -0
  295. data/lua-hooks/ext/luajit/src/lj_opt_mem_dyn.o +0 -0
  296. data/lua-hooks/ext/luajit/src/lj_opt_narrow.c +652 -0
  297. data/lua-hooks/ext/luajit/src/lj_opt_narrow.o +0 -0
  298. data/lua-hooks/ext/luajit/src/lj_opt_narrow_dyn.o +0 -0
  299. data/lua-hooks/ext/luajit/src/lj_opt_sink.c +245 -0
  300. data/lua-hooks/ext/luajit/src/lj_opt_sink.o +0 -0
  301. data/lua-hooks/ext/luajit/src/lj_opt_sink_dyn.o +0 -0
  302. data/lua-hooks/ext/luajit/src/lj_opt_split.c +856 -0
  303. data/lua-hooks/ext/luajit/src/lj_opt_split.o +0 -0
  304. data/lua-hooks/ext/luajit/src/lj_opt_split_dyn.o +0 -0
  305. data/lua-hooks/ext/luajit/src/lj_parse.c +2725 -0
  306. data/lua-hooks/ext/luajit/src/lj_parse.h +18 -0
  307. data/lua-hooks/ext/luajit/src/lj_parse.o +0 -0
  308. data/lua-hooks/ext/luajit/src/lj_parse_dyn.o +0 -0
  309. data/lua-hooks/ext/luajit/src/lj_profile.c +368 -0
  310. data/lua-hooks/ext/luajit/src/lj_profile.h +21 -0
  311. data/lua-hooks/ext/luajit/src/lj_profile.o +0 -0
  312. data/lua-hooks/ext/luajit/src/lj_profile_dyn.o +0 -0
  313. data/lua-hooks/ext/luajit/src/lj_recdef.h +270 -0
  314. data/lua-hooks/ext/luajit/src/lj_record.c +2554 -0
  315. data/lua-hooks/ext/luajit/src/lj_record.h +45 -0
  316. data/lua-hooks/ext/luajit/src/lj_record.o +0 -0
  317. data/lua-hooks/ext/luajit/src/lj_record_dyn.o +0 -0
  318. data/lua-hooks/ext/luajit/src/lj_snap.c +870 -0
  319. data/lua-hooks/ext/luajit/src/lj_snap.h +34 -0
  320. data/lua-hooks/ext/luajit/src/lj_snap.o +0 -0
  321. data/lua-hooks/ext/luajit/src/lj_snap_dyn.o +0 -0
  322. data/lua-hooks/ext/luajit/src/lj_state.c +300 -0
  323. data/lua-hooks/ext/luajit/src/lj_state.h +35 -0
  324. data/lua-hooks/ext/luajit/src/lj_state.o +0 -0
  325. data/lua-hooks/ext/luajit/src/lj_state_dyn.o +0 -0
  326. data/lua-hooks/ext/luajit/src/lj_str.c +197 -0
  327. data/lua-hooks/ext/luajit/src/lj_str.h +27 -0
  328. data/lua-hooks/ext/luajit/src/lj_str.o +0 -0
  329. data/lua-hooks/ext/luajit/src/lj_str_dyn.o +0 -0
  330. data/lua-hooks/ext/luajit/src/lj_strfmt.c +554 -0
  331. data/lua-hooks/ext/luajit/src/lj_strfmt.h +125 -0
  332. data/lua-hooks/ext/luajit/src/lj_strfmt.o +0 -0
  333. data/lua-hooks/ext/luajit/src/lj_strfmt_dyn.o +0 -0
  334. data/lua-hooks/ext/luajit/src/lj_strscan.c +547 -0
  335. data/lua-hooks/ext/luajit/src/lj_strscan.h +39 -0
  336. data/lua-hooks/ext/luajit/src/lj_strscan.o +0 -0
  337. data/lua-hooks/ext/luajit/src/lj_strscan_dyn.o +0 -0
  338. data/lua-hooks/ext/luajit/src/lj_tab.c +666 -0
  339. data/lua-hooks/ext/luajit/src/lj_tab.h +73 -0
  340. data/lua-hooks/ext/luajit/src/lj_tab.o +0 -0
  341. data/lua-hooks/ext/luajit/src/lj_tab_dyn.o +0 -0
  342. data/lua-hooks/ext/luajit/src/lj_target.h +164 -0
  343. data/lua-hooks/ext/luajit/src/lj_target_arm.h +270 -0
  344. data/lua-hooks/ext/luajit/src/lj_target_arm64.h +97 -0
  345. data/lua-hooks/ext/luajit/src/lj_target_mips.h +260 -0
  346. data/lua-hooks/ext/luajit/src/lj_target_ppc.h +280 -0
  347. data/lua-hooks/ext/luajit/src/lj_target_x86.h +345 -0
  348. data/lua-hooks/ext/luajit/src/lj_trace.c +859 -0
  349. data/lua-hooks/ext/luajit/src/lj_trace.h +54 -0
  350. data/lua-hooks/ext/luajit/src/lj_trace.o +0 -0
  351. data/lua-hooks/ext/luajit/src/lj_trace_dyn.o +0 -0
  352. data/lua-hooks/ext/luajit/src/lj_traceerr.h +63 -0
  353. data/lua-hooks/ext/luajit/src/lj_udata.c +34 -0
  354. data/lua-hooks/ext/luajit/src/lj_udata.h +14 -0
  355. data/lua-hooks/ext/luajit/src/lj_udata.o +0 -0
  356. data/lua-hooks/ext/luajit/src/lj_udata_dyn.o +0 -0
  357. data/lua-hooks/ext/luajit/src/lj_vm.S +2730 -0
  358. data/lua-hooks/ext/luajit/src/lj_vm.h +114 -0
  359. data/lua-hooks/ext/luajit/src/lj_vm.o +0 -0
  360. data/lua-hooks/ext/luajit/src/lj_vm_dyn.o +0 -0
  361. data/lua-hooks/ext/luajit/src/lj_vmevent.c +58 -0
  362. data/lua-hooks/ext/luajit/src/lj_vmevent.h +59 -0
  363. data/lua-hooks/ext/luajit/src/lj_vmevent.o +0 -0
  364. data/lua-hooks/ext/luajit/src/lj_vmevent_dyn.o +0 -0
  365. data/lua-hooks/ext/luajit/src/lj_vmmath.c +152 -0
  366. data/lua-hooks/ext/luajit/src/lj_vmmath.o +0 -0
  367. data/lua-hooks/ext/luajit/src/lj_vmmath_dyn.o +0 -0
  368. data/lua-hooks/ext/luajit/src/ljamalg.c +96 -0
  369. data/lua-hooks/ext/{lua → luajit/src}/lua.h +12 -7
  370. data/lua-hooks/ext/luajit/src/lua.hpp +9 -0
  371. data/lua-hooks/ext/luajit/src/luaconf.h +156 -0
  372. data/lua-hooks/ext/luajit/src/luajit +0 -0
  373. data/lua-hooks/ext/luajit/src/luajit.c +570 -0
  374. data/lua-hooks/ext/luajit/src/luajit.h +79 -0
  375. data/lua-hooks/ext/luajit/src/luajit.o +0 -0
  376. data/lua-hooks/ext/luajit/src/lualib.h +43 -0
  377. data/lua-hooks/ext/luajit/src/msvcbuild.bat +114 -0
  378. data/lua-hooks/ext/luajit/src/ps4build.bat +103 -0
  379. data/lua-hooks/ext/luajit/src/psvitabuild.bat +93 -0
  380. data/lua-hooks/ext/luajit/src/vm_arm.dasc +4585 -0
  381. data/lua-hooks/ext/luajit/src/vm_arm64.dasc +3764 -0
  382. data/lua-hooks/ext/luajit/src/vm_mips.dasc +4355 -0
  383. data/lua-hooks/ext/luajit/src/vm_ppc.dasc +5252 -0
  384. data/lua-hooks/ext/luajit/src/vm_x64.dasc +4902 -0
  385. data/lua-hooks/ext/luajit/src/vm_x86.dasc +5710 -0
  386. data/lua-hooks/ext/luajit/src/xb1build.bat +101 -0
  387. data/lua-hooks/ext/luajit/src/xedkbuild.bat +92 -0
  388. data/lua-hooks/ext/luautf8/lutf8lib.c +3 -3
  389. data/lua-hooks/lib/boot.lua +37 -2
  390. metadata +372 -69
  391. data/lua-hooks/ext/bitop/README +0 -22
  392. data/lua-hooks/ext/bitop/bit.c +0 -189
  393. data/lua-hooks/ext/extconf.rb +0 -38
  394. data/lua-hooks/ext/lua/COPYRIGHT +0 -34
  395. data/lua-hooks/ext/lua/lapi.c +0 -1087
  396. data/lua-hooks/ext/lua/lapi.h +0 -16
  397. data/lua-hooks/ext/lua/lauxlib.c +0 -652
  398. data/lua-hooks/ext/lua/lbaselib.c +0 -659
  399. data/lua-hooks/ext/lua/lcode.c +0 -831
  400. data/lua-hooks/ext/lua/lcode.h +0 -76
  401. data/lua-hooks/ext/lua/ldblib.c +0 -398
  402. data/lua-hooks/ext/lua/ldebug.c +0 -638
  403. data/lua-hooks/ext/lua/ldebug.h +0 -33
  404. data/lua-hooks/ext/lua/ldo.c +0 -519
  405. data/lua-hooks/ext/lua/ldo.h +0 -57
  406. data/lua-hooks/ext/lua/ldump.c +0 -164
  407. data/lua-hooks/ext/lua/lfunc.c +0 -174
  408. data/lua-hooks/ext/lua/lfunc.h +0 -34
  409. data/lua-hooks/ext/lua/lgc.c +0 -710
  410. data/lua-hooks/ext/lua/lgc.h +0 -110
  411. data/lua-hooks/ext/lua/linit.c +0 -38
  412. data/lua-hooks/ext/lua/liolib.c +0 -556
  413. data/lua-hooks/ext/lua/llex.c +0 -463
  414. data/lua-hooks/ext/lua/llex.h +0 -81
  415. data/lua-hooks/ext/lua/llimits.h +0 -128
  416. data/lua-hooks/ext/lua/lmathlib.c +0 -263
  417. data/lua-hooks/ext/lua/lmem.c +0 -86
  418. data/lua-hooks/ext/lua/lmem.h +0 -49
  419. data/lua-hooks/ext/lua/loadlib.c +0 -705
  420. data/lua-hooks/ext/lua/loadlib_rel.c +0 -760
  421. data/lua-hooks/ext/lua/lobject.c +0 -214
  422. data/lua-hooks/ext/lua/lobject.h +0 -381
  423. data/lua-hooks/ext/lua/lopcodes.c +0 -102
  424. data/lua-hooks/ext/lua/lopcodes.h +0 -268
  425. data/lua-hooks/ext/lua/loslib.c +0 -243
  426. data/lua-hooks/ext/lua/lparser.c +0 -1339
  427. data/lua-hooks/ext/lua/lparser.h +0 -82
  428. data/lua-hooks/ext/lua/lstate.c +0 -214
  429. data/lua-hooks/ext/lua/lstate.h +0 -169
  430. data/lua-hooks/ext/lua/lstring.c +0 -111
  431. data/lua-hooks/ext/lua/lstring.h +0 -31
  432. data/lua-hooks/ext/lua/lstrlib.c +0 -871
  433. data/lua-hooks/ext/lua/ltable.c +0 -588
  434. data/lua-hooks/ext/lua/ltable.h +0 -40
  435. data/lua-hooks/ext/lua/ltablib.c +0 -287
  436. data/lua-hooks/ext/lua/ltm.c +0 -75
  437. data/lua-hooks/ext/lua/ltm.h +0 -54
  438. data/lua-hooks/ext/lua/lua.c +0 -392
  439. data/lua-hooks/ext/lua/lua.def +0 -131
  440. data/lua-hooks/ext/lua/lua.rc +0 -28
  441. data/lua-hooks/ext/lua/lua_dll.rc +0 -26
  442. data/lua-hooks/ext/lua/luac.c +0 -200
  443. data/lua-hooks/ext/lua/luac.rc +0 -1
  444. data/lua-hooks/ext/lua/luaconf.h +0 -763
  445. data/lua-hooks/ext/lua/luaconf.h.in +0 -724
  446. data/lua-hooks/ext/lua/luaconf.h.orig +0 -763
  447. data/lua-hooks/ext/lua/lualib.h +0 -53
  448. data/lua-hooks/ext/lua/lundump.c +0 -227
  449. data/lua-hooks/ext/lua/lundump.h +0 -36
  450. data/lua-hooks/ext/lua/lvm.c +0 -767
  451. data/lua-hooks/ext/lua/lvm.h +0 -36
  452. data/lua-hooks/ext/lua/lzio.c +0 -82
  453. data/lua-hooks/ext/lua/lzio.h +0 -67
  454. data/lua-hooks/ext/lua/print.c +0 -227
@@ -0,0 +1,37 @@
1
+ /*
2
+ ** C data arithmetic.
3
+ ** Copyright (C) 2005-2015 Mike Pall. See Copyright Notice in luajit.h
4
+ */
5
+
6
+ #ifndef _LJ_CARITH_H
7
+ #define _LJ_CARITH_H
8
+
9
+ #include "lj_obj.h"
10
+
11
+ #if LJ_HASFFI
12
+
13
+ LJ_FUNC int lj_carith_op(lua_State *L, MMS mm);
14
+
15
+ #if LJ_32
16
+ LJ_FUNC uint64_t lj_carith_shl64(uint64_t x, int32_t sh);
17
+ LJ_FUNC uint64_t lj_carith_shr64(uint64_t x, int32_t sh);
18
+ LJ_FUNC uint64_t lj_carith_sar64(uint64_t x, int32_t sh);
19
+ LJ_FUNC uint64_t lj_carith_rol64(uint64_t x, int32_t sh);
20
+ LJ_FUNC uint64_t lj_carith_ror64(uint64_t x, int32_t sh);
21
+ #endif
22
+ LJ_FUNC uint64_t lj_carith_shift64(uint64_t x, int32_t sh, int op);
23
+ LJ_FUNC uint64_t lj_carith_check64(lua_State *L, int narg, CTypeID *id);
24
+
25
+ #if LJ_32 && LJ_HASJIT
26
+ LJ_FUNC int64_t lj_carith_mul64(int64_t x, int64_t k);
27
+ #endif
28
+ LJ_FUNC uint64_t lj_carith_divu64(uint64_t a, uint64_t b);
29
+ LJ_FUNC int64_t lj_carith_divi64(int64_t a, int64_t b);
30
+ LJ_FUNC uint64_t lj_carith_modu64(uint64_t a, uint64_t b);
31
+ LJ_FUNC int64_t lj_carith_modi64(int64_t a, int64_t b);
32
+ LJ_FUNC uint64_t lj_carith_powu64(uint64_t x, uint64_t k);
33
+ LJ_FUNC int64_t lj_carith_powi64(int64_t x, int64_t k);
34
+
35
+ #endif
36
+
37
+ #endif
@@ -0,0 +1,984 @@
1
+ /*
2
+ ** FFI C call handling.
3
+ ** Copyright (C) 2005-2015 Mike Pall. See Copyright Notice in luajit.h
4
+ */
5
+
6
+ #include "lj_obj.h"
7
+
8
+ #if LJ_HASFFI
9
+
10
+ #include "lj_gc.h"
11
+ #include "lj_err.h"
12
+ #include "lj_tab.h"
13
+ #include "lj_ctype.h"
14
+ #include "lj_cconv.h"
15
+ #include "lj_cdata.h"
16
+ #include "lj_ccall.h"
17
+ #include "lj_trace.h"
18
+
19
+ /* Target-specific handling of register arguments. */
20
+ #if LJ_TARGET_X86
21
+ /* -- x86 calling conventions --------------------------------------------- */
22
+
23
+ #if LJ_ABI_WIN
24
+
25
+ #define CCALL_HANDLE_STRUCTRET \
26
+ /* Return structs bigger than 8 by reference (on stack only). */ \
27
+ cc->retref = (sz > 8); \
28
+ if (cc->retref) cc->stack[nsp++] = (GPRArg)dp;
29
+
30
+ #define CCALL_HANDLE_COMPLEXRET CCALL_HANDLE_STRUCTRET
31
+
32
+ #else
33
+
34
+ #if LJ_TARGET_OSX
35
+
36
+ #define CCALL_HANDLE_STRUCTRET \
37
+ /* Return structs of size 1, 2, 4 or 8 in registers. */ \
38
+ cc->retref = !(sz == 1 || sz == 2 || sz == 4 || sz == 8); \
39
+ if (cc->retref) { \
40
+ if (ngpr < maxgpr) \
41
+ cc->gpr[ngpr++] = (GPRArg)dp; \
42
+ else \
43
+ cc->stack[nsp++] = (GPRArg)dp; \
44
+ } else { /* Struct with single FP field ends up in FPR. */ \
45
+ cc->resx87 = ccall_classify_struct(cts, ctr); \
46
+ }
47
+
48
+ #define CCALL_HANDLE_STRUCTRET2 \
49
+ if (cc->resx87) sp = (uint8_t *)&cc->fpr[0]; \
50
+ memcpy(dp, sp, ctr->size);
51
+
52
+ #else
53
+
54
+ #define CCALL_HANDLE_STRUCTRET \
55
+ cc->retref = 1; /* Return all structs by reference (in reg or on stack). */ \
56
+ if (ngpr < maxgpr) \
57
+ cc->gpr[ngpr++] = (GPRArg)dp; \
58
+ else \
59
+ cc->stack[nsp++] = (GPRArg)dp;
60
+
61
+ #endif
62
+
63
+ #define CCALL_HANDLE_COMPLEXRET \
64
+ /* Return complex float in GPRs and complex double by reference. */ \
65
+ cc->retref = (sz > 8); \
66
+ if (cc->retref) { \
67
+ if (ngpr < maxgpr) \
68
+ cc->gpr[ngpr++] = (GPRArg)dp; \
69
+ else \
70
+ cc->stack[nsp++] = (GPRArg)dp; \
71
+ }
72
+
73
+ #endif
74
+
75
+ #define CCALL_HANDLE_COMPLEXRET2 \
76
+ if (!cc->retref) \
77
+ *(int64_t *)dp = *(int64_t *)sp; /* Copy complex float from GPRs. */
78
+
79
+ #define CCALL_HANDLE_STRUCTARG \
80
+ ngpr = maxgpr; /* Pass all structs by value on the stack. */
81
+
82
+ #define CCALL_HANDLE_COMPLEXARG \
83
+ isfp = 1; /* Pass complex by value on stack. */
84
+
85
+ #define CCALL_HANDLE_REGARG \
86
+ if (!isfp) { /* Only non-FP values may be passed in registers. */ \
87
+ if (n > 1) { /* Anything > 32 bit is passed on the stack. */ \
88
+ if (!LJ_ABI_WIN) ngpr = maxgpr; /* Prevent reordering. */ \
89
+ } else if (ngpr + 1 <= maxgpr) { \
90
+ dp = &cc->gpr[ngpr]; \
91
+ ngpr += n; \
92
+ goto done; \
93
+ } \
94
+ }
95
+
96
+ #elif LJ_TARGET_X64 && LJ_ABI_WIN
97
+ /* -- Windows/x64 calling conventions ------------------------------------- */
98
+
99
+ #define CCALL_HANDLE_STRUCTRET \
100
+ /* Return structs of size 1, 2, 4 or 8 in a GPR. */ \
101
+ cc->retref = !(sz == 1 || sz == 2 || sz == 4 || sz == 8); \
102
+ if (cc->retref) cc->gpr[ngpr++] = (GPRArg)dp;
103
+
104
+ #define CCALL_HANDLE_COMPLEXRET CCALL_HANDLE_STRUCTRET
105
+
106
+ #define CCALL_HANDLE_COMPLEXRET2 \
107
+ if (!cc->retref) \
108
+ *(int64_t *)dp = *(int64_t *)sp; /* Copy complex float from GPRs. */
109
+
110
+ #define CCALL_HANDLE_STRUCTARG \
111
+ /* Pass structs of size 1, 2, 4 or 8 in a GPR by value. */ \
112
+ if (!(sz == 1 || sz == 2 || sz == 4 || sz == 8)) { \
113
+ rp = cdataptr(lj_cdata_new(cts, did, sz)); \
114
+ sz = CTSIZE_PTR; /* Pass all other structs by reference. */ \
115
+ }
116
+
117
+ #define CCALL_HANDLE_COMPLEXARG \
118
+ /* Pass complex float in a GPR and complex double by reference. */ \
119
+ if (sz != 2*sizeof(float)) { \
120
+ rp = cdataptr(lj_cdata_new(cts, did, sz)); \
121
+ sz = CTSIZE_PTR; \
122
+ }
123
+
124
+ /* Windows/x64 argument registers are strictly positional (use ngpr). */
125
+ #define CCALL_HANDLE_REGARG \
126
+ if (isfp) { \
127
+ if (ngpr < maxgpr) { dp = &cc->fpr[ngpr++]; nfpr = ngpr; goto done; } \
128
+ } else { \
129
+ if (ngpr < maxgpr) { dp = &cc->gpr[ngpr++]; goto done; } \
130
+ }
131
+
132
+ #elif LJ_TARGET_X64
133
+ /* -- POSIX/x64 calling conventions --------------------------------------- */
134
+
135
+ #define CCALL_HANDLE_STRUCTRET \
136
+ int rcl[2]; rcl[0] = rcl[1] = 0; \
137
+ if (ccall_classify_struct(cts, ctr, rcl, 0)) { \
138
+ cc->retref = 1; /* Return struct by reference. */ \
139
+ cc->gpr[ngpr++] = (GPRArg)dp; \
140
+ } else { \
141
+ cc->retref = 0; /* Return small structs in registers. */ \
142
+ }
143
+
144
+ #define CCALL_HANDLE_STRUCTRET2 \
145
+ int rcl[2]; rcl[0] = rcl[1] = 0; \
146
+ ccall_classify_struct(cts, ctr, rcl, 0); \
147
+ ccall_struct_ret(cc, rcl, dp, ctr->size);
148
+
149
+ #define CCALL_HANDLE_COMPLEXRET \
150
+ /* Complex values are returned in one or two FPRs. */ \
151
+ cc->retref = 0;
152
+
153
+ #define CCALL_HANDLE_COMPLEXRET2 \
154
+ if (ctr->size == 2*sizeof(float)) { /* Copy complex float from FPR. */ \
155
+ *(int64_t *)dp = cc->fpr[0].l[0]; \
156
+ } else { /* Copy non-contiguous complex double from FPRs. */ \
157
+ ((int64_t *)dp)[0] = cc->fpr[0].l[0]; \
158
+ ((int64_t *)dp)[1] = cc->fpr[1].l[0]; \
159
+ }
160
+
161
+ #define CCALL_HANDLE_STRUCTARG \
162
+ int rcl[2]; rcl[0] = rcl[1] = 0; \
163
+ if (!ccall_classify_struct(cts, d, rcl, 0)) { \
164
+ cc->nsp = nsp; cc->ngpr = ngpr; cc->nfpr = nfpr; \
165
+ if (ccall_struct_arg(cc, cts, d, rcl, o, narg)) goto err_nyi; \
166
+ nsp = cc->nsp; ngpr = cc->ngpr; nfpr = cc->nfpr; \
167
+ continue; \
168
+ } /* Pass all other structs by value on stack. */
169
+
170
+ #define CCALL_HANDLE_COMPLEXARG \
171
+ isfp = 2; /* Pass complex in FPRs or on stack. Needs postprocessing. */
172
+
173
+ #define CCALL_HANDLE_REGARG \
174
+ if (isfp) { /* Try to pass argument in FPRs. */ \
175
+ int n2 = ctype_isvector(d->info) ? 1 : n; \
176
+ if (nfpr + n2 <= CCALL_NARG_FPR) { \
177
+ dp = &cc->fpr[nfpr]; \
178
+ nfpr += n2; \
179
+ goto done; \
180
+ } \
181
+ } else { /* Try to pass argument in GPRs. */ \
182
+ /* Note that reordering is explicitly allowed in the x64 ABI. */ \
183
+ if (n <= 2 && ngpr + n <= maxgpr) { \
184
+ dp = &cc->gpr[ngpr]; \
185
+ ngpr += n; \
186
+ goto done; \
187
+ } \
188
+ }
189
+
190
+ #elif LJ_TARGET_ARM
191
+ /* -- ARM calling conventions --------------------------------------------- */
192
+
193
+ #if LJ_ABI_SOFTFP
194
+
195
+ #define CCALL_HANDLE_STRUCTRET \
196
+ /* Return structs of size <= 4 in a GPR. */ \
197
+ cc->retref = !(sz <= 4); \
198
+ if (cc->retref) cc->gpr[ngpr++] = (GPRArg)dp;
199
+
200
+ #define CCALL_HANDLE_COMPLEXRET \
201
+ cc->retref = 1; /* Return all complex values by reference. */ \
202
+ cc->gpr[ngpr++] = (GPRArg)dp;
203
+
204
+ #define CCALL_HANDLE_COMPLEXRET2 \
205
+ UNUSED(dp); /* Nothing to do. */
206
+
207
+ #define CCALL_HANDLE_STRUCTARG \
208
+ /* Pass all structs by value in registers and/or on the stack. */
209
+
210
+ #define CCALL_HANDLE_COMPLEXARG \
211
+ /* Pass complex by value in 2 or 4 GPRs. */
212
+
213
+ #define CCALL_HANDLE_REGARG_FP1
214
+ #define CCALL_HANDLE_REGARG_FP2
215
+
216
+ #else
217
+
218
+ #define CCALL_HANDLE_STRUCTRET \
219
+ cc->retref = !ccall_classify_struct(cts, ctr, ct); \
220
+ if (cc->retref) cc->gpr[ngpr++] = (GPRArg)dp;
221
+
222
+ #define CCALL_HANDLE_STRUCTRET2 \
223
+ if (ccall_classify_struct(cts, ctr, ct) > 1) sp = (uint8_t *)&cc->fpr[0]; \
224
+ memcpy(dp, sp, ctr->size);
225
+
226
+ #define CCALL_HANDLE_COMPLEXRET \
227
+ if (!(ct->info & CTF_VARARG)) cc->retref = 0; /* Return complex in FPRs. */
228
+
229
+ #define CCALL_HANDLE_COMPLEXRET2 \
230
+ if (!(ct->info & CTF_VARARG)) memcpy(dp, &cc->fpr[0], ctr->size);
231
+
232
+ #define CCALL_HANDLE_STRUCTARG \
233
+ isfp = (ccall_classify_struct(cts, d, ct) > 1);
234
+ /* Pass all structs by value in registers and/or on the stack. */
235
+
236
+ #define CCALL_HANDLE_COMPLEXARG \
237
+ isfp = 1; /* Pass complex by value in FPRs or on stack. */
238
+
239
+ #define CCALL_HANDLE_REGARG_FP1 \
240
+ if (isfp && !(ct->info & CTF_VARARG)) { \
241
+ if ((d->info & CTF_ALIGN) > CTALIGN_PTR) { \
242
+ if (nfpr + (n >> 1) <= CCALL_NARG_FPR) { \
243
+ dp = &cc->fpr[nfpr]; \
244
+ nfpr += (n >> 1); \
245
+ goto done; \
246
+ } \
247
+ } else { \
248
+ if (sz > 1 && fprodd != nfpr) fprodd = 0; \
249
+ if (fprodd) { \
250
+ if (2*nfpr+n <= 2*CCALL_NARG_FPR+1) { \
251
+ dp = (void *)&cc->fpr[fprodd-1].f[1]; \
252
+ nfpr += (n >> 1); \
253
+ if ((n & 1)) fprodd = 0; else fprodd = nfpr-1; \
254
+ goto done; \
255
+ } \
256
+ } else { \
257
+ if (2*nfpr+n <= 2*CCALL_NARG_FPR) { \
258
+ dp = (void *)&cc->fpr[nfpr]; \
259
+ nfpr += (n >> 1); \
260
+ if ((n & 1)) fprodd = ++nfpr; else fprodd = 0; \
261
+ goto done; \
262
+ } \
263
+ } \
264
+ } \
265
+ fprodd = 0; /* No reordering after the first FP value is on stack. */ \
266
+ } else {
267
+
268
+ #define CCALL_HANDLE_REGARG_FP2 }
269
+
270
+ #endif
271
+
272
+ #define CCALL_HANDLE_REGARG \
273
+ CCALL_HANDLE_REGARG_FP1 \
274
+ if ((d->info & CTF_ALIGN) > CTALIGN_PTR) { \
275
+ if (ngpr < maxgpr) \
276
+ ngpr = (ngpr + 1u) & ~1u; /* Align to regpair. */ \
277
+ } \
278
+ if (ngpr < maxgpr) { \
279
+ dp = &cc->gpr[ngpr]; \
280
+ if (ngpr + n > maxgpr) { \
281
+ nsp += ngpr + n - maxgpr; /* Assumes contiguous gpr/stack fields. */ \
282
+ if (nsp > CCALL_MAXSTACK) goto err_nyi; /* Too many arguments. */ \
283
+ ngpr = maxgpr; \
284
+ } else { \
285
+ ngpr += n; \
286
+ } \
287
+ goto done; \
288
+ } CCALL_HANDLE_REGARG_FP2
289
+
290
+ #define CCALL_HANDLE_RET \
291
+ if ((ct->info & CTF_VARARG)) sp = (uint8_t *)&cc->gpr[0];
292
+
293
+ #elif LJ_TARGET_ARM64
294
+ /* -- ARM64 calling conventions ------------------------------------------- */
295
+
296
+ #define CCALL_HANDLE_STRUCTRET \
297
+ cc->retref = !ccall_classify_struct(cts, ctr); \
298
+ if (cc->retref) cc->retp = dp;
299
+
300
+ #define CCALL_HANDLE_STRUCTRET2 \
301
+ unsigned int cl = ccall_classify_struct(cts, ctr); \
302
+ if ((cl & 4)) { /* Combine float HFA from separate registers. */ \
303
+ CTSize i = (cl >> 8) - 1; \
304
+ do { ((uint32_t *)dp)[i] = cc->fpr[i].u32; } while (i--); \
305
+ } else { \
306
+ if (cl > 1) sp = (uint8_t *)&cc->fpr[0]; \
307
+ memcpy(dp, sp, ctr->size); \
308
+ }
309
+
310
+ #define CCALL_HANDLE_COMPLEXRET \
311
+ /* Complex values are returned in one or two FPRs. */ \
312
+ cc->retref = 0;
313
+
314
+ #define CCALL_HANDLE_COMPLEXRET2 \
315
+ if (ctr->size == 2*sizeof(float)) { /* Copy complex float from FPRs. */ \
316
+ ((float *)dp)[0] = cc->fpr[0].f; \
317
+ ((float *)dp)[1] = cc->fpr[1].f; \
318
+ } else { /* Copy complex double from FPRs. */ \
319
+ ((double *)dp)[0] = cc->fpr[0].d; \
320
+ ((double *)dp)[1] = cc->fpr[1].d; \
321
+ }
322
+
323
+ #define CCALL_HANDLE_STRUCTARG \
324
+ unsigned int cl = ccall_classify_struct(cts, d); \
325
+ if (cl == 0) { /* Pass struct by reference. */ \
326
+ rp = cdataptr(lj_cdata_new(cts, did, sz)); \
327
+ sz = CTSIZE_PTR; \
328
+ } else if (cl > 1) { /* Pass struct in FPRs or on stack. */ \
329
+ isfp = (cl & 4) ? 2 : 1; \
330
+ } /* else: Pass struct in GPRs or on stack. */
331
+
332
+ #define CCALL_HANDLE_COMPLEXARG \
333
+ /* Pass complex by value in separate (!) FPRs or on stack. */ \
334
+ isfp = ctr->size == 2*sizeof(float) ? 2 : 1;
335
+
336
+ #define CCALL_HANDLE_REGARG \
337
+ if (LJ_TARGET_IOS && isva) { \
338
+ /* IOS: All variadic arguments are on the stack. */ \
339
+ } else if (isfp) { /* Try to pass argument in FPRs. */ \
340
+ int n2 = ctype_isvector(d->info) ? 1 : n*isfp; \
341
+ if (nfpr + n2 <= CCALL_NARG_FPR) { \
342
+ dp = &cc->fpr[nfpr]; \
343
+ nfpr += n2; \
344
+ goto done; \
345
+ } else { \
346
+ nfpr = CCALL_NARG_FPR; /* Prevent reordering. */ \
347
+ if (LJ_TARGET_IOS && d->size < 8) goto err_nyi; \
348
+ } \
349
+ } else { /* Try to pass argument in GPRs. */ \
350
+ if (!LJ_TARGET_IOS && (d->info & CTF_ALIGN) > CTALIGN_PTR) \
351
+ ngpr = (ngpr + 1u) & ~1u; /* Align to regpair. */ \
352
+ if (ngpr + n <= maxgpr) { \
353
+ dp = &cc->gpr[ngpr]; \
354
+ ngpr += n; \
355
+ goto done; \
356
+ } else { \
357
+ ngpr = maxgpr; /* Prevent reordering. */ \
358
+ if (LJ_TARGET_IOS && d->size < 8) goto err_nyi; \
359
+ } \
360
+ }
361
+
362
+ #elif LJ_TARGET_PPC
363
+ /* -- PPC calling conventions --------------------------------------------- */
364
+
365
+ #define CCALL_HANDLE_STRUCTRET \
366
+ cc->retref = 1; /* Return all structs by reference. */ \
367
+ cc->gpr[ngpr++] = (GPRArg)dp;
368
+
369
+ #define CCALL_HANDLE_COMPLEXRET \
370
+ /* Complex values are returned in 2 or 4 GPRs. */ \
371
+ cc->retref = 0;
372
+
373
+ #define CCALL_HANDLE_COMPLEXRET2 \
374
+ memcpy(dp, sp, ctr->size); /* Copy complex from GPRs. */
375
+
376
+ #define CCALL_HANDLE_STRUCTARG \
377
+ rp = cdataptr(lj_cdata_new(cts, did, sz)); \
378
+ sz = CTSIZE_PTR; /* Pass all structs by reference. */
379
+
380
+ #define CCALL_HANDLE_COMPLEXARG \
381
+ /* Pass complex by value in 2 or 4 GPRs. */
382
+
383
+ #define CCALL_HANDLE_REGARG \
384
+ if (isfp) { /* Try to pass argument in FPRs. */ \
385
+ if (nfpr + 1 <= CCALL_NARG_FPR) { \
386
+ dp = &cc->fpr[nfpr]; \
387
+ nfpr += 1; \
388
+ d = ctype_get(cts, CTID_DOUBLE); /* FPRs always hold doubles. */ \
389
+ goto done; \
390
+ } \
391
+ } else { /* Try to pass argument in GPRs. */ \
392
+ if (n > 1) { \
393
+ lua_assert(n == 2 || n == 4); /* int64_t or complex (float). */ \
394
+ if (ctype_isinteger(d->info)) \
395
+ ngpr = (ngpr + 1u) & ~1u; /* Align int64_t to regpair. */ \
396
+ else if (ngpr + n > maxgpr) \
397
+ ngpr = maxgpr; /* Prevent reordering. */ \
398
+ } \
399
+ if (ngpr + n <= maxgpr) { \
400
+ dp = &cc->gpr[ngpr]; \
401
+ ngpr += n; \
402
+ goto done; \
403
+ } \
404
+ }
405
+
406
+ #define CCALL_HANDLE_RET \
407
+ if (ctype_isfp(ctr->info) && ctr->size == sizeof(float)) \
408
+ ctr = ctype_get(cts, CTID_DOUBLE); /* FPRs always hold doubles. */
409
+
410
+ #elif LJ_TARGET_MIPS
411
+ /* -- MIPS calling conventions -------------------------------------------- */
412
+
413
+ #define CCALL_HANDLE_STRUCTRET \
414
+ cc->retref = 1; /* Return all structs by reference. */ \
415
+ cc->gpr[ngpr++] = (GPRArg)dp;
416
+
417
+ #define CCALL_HANDLE_COMPLEXRET \
418
+ /* Complex values are returned in 1 or 2 FPRs. */ \
419
+ cc->retref = 0;
420
+
421
+ #define CCALL_HANDLE_COMPLEXRET2 \
422
+ if (ctr->size == 2*sizeof(float)) { /* Copy complex float from FPRs. */ \
423
+ ((float *)dp)[0] = cc->fpr[0].f; \
424
+ ((float *)dp)[1] = cc->fpr[1].f; \
425
+ } else { /* Copy complex double from FPRs. */ \
426
+ ((double *)dp)[0] = cc->fpr[0].d; \
427
+ ((double *)dp)[1] = cc->fpr[1].d; \
428
+ }
429
+
430
+ #define CCALL_HANDLE_STRUCTARG \
431
+ /* Pass all structs by value in registers and/or on the stack. */
432
+
433
+ #define CCALL_HANDLE_COMPLEXARG \
434
+ /* Pass complex by value in 2 or 4 GPRs. */
435
+
436
+ #define CCALL_HANDLE_REGARG \
437
+ if (isfp && nfpr < CCALL_NARG_FPR && !(ct->info & CTF_VARARG)) { \
438
+ /* Try to pass argument in FPRs. */ \
439
+ dp = n == 1 ? (void *)&cc->fpr[nfpr].f : (void *)&cc->fpr[nfpr].d; \
440
+ nfpr++; ngpr += n; \
441
+ goto done; \
442
+ } else { /* Try to pass argument in GPRs. */ \
443
+ nfpr = CCALL_NARG_FPR; \
444
+ if ((d->info & CTF_ALIGN) > CTALIGN_PTR) \
445
+ ngpr = (ngpr + 1u) & ~1u; /* Align to regpair. */ \
446
+ if (ngpr < maxgpr) { \
447
+ dp = &cc->gpr[ngpr]; \
448
+ if (ngpr + n > maxgpr) { \
449
+ nsp += ngpr + n - maxgpr; /* Assumes contiguous gpr/stack fields. */ \
450
+ if (nsp > CCALL_MAXSTACK) goto err_nyi; /* Too many arguments. */ \
451
+ ngpr = maxgpr; \
452
+ } else { \
453
+ ngpr += n; \
454
+ } \
455
+ goto done; \
456
+ } \
457
+ }
458
+
459
+ #define CCALL_HANDLE_RET \
460
+ if (ctype_isfp(ctr->info) && ctr->size == sizeof(float)) \
461
+ sp = (uint8_t *)&cc->fpr[0].f;
462
+
463
+ #else
464
+ #error "Missing calling convention definitions for this architecture"
465
+ #endif
466
+
467
+ #ifndef CCALL_HANDLE_STRUCTRET2
468
+ #define CCALL_HANDLE_STRUCTRET2 \
469
+ memcpy(dp, sp, ctr->size); /* Copy struct return value from GPRs. */
470
+ #endif
471
+
472
+ /* -- x86 OSX ABI struct classification ----------------------------------- */
473
+
474
+ #if LJ_TARGET_X86 && LJ_TARGET_OSX
475
+
476
+ /* Check for struct with single FP field. */
477
+ static int ccall_classify_struct(CTState *cts, CType *ct)
478
+ {
479
+ CTSize sz = ct->size;
480
+ if (!(sz == sizeof(float) || sz == sizeof(double))) return 0;
481
+ if ((ct->info & CTF_UNION)) return 0;
482
+ while (ct->sib) {
483
+ ct = ctype_get(cts, ct->sib);
484
+ if (ctype_isfield(ct->info)) {
485
+ CType *sct = ctype_rawchild(cts, ct);
486
+ if (ctype_isfp(sct->info)) {
487
+ if (sct->size == sz)
488
+ return (sz >> 2); /* Return 1 for float or 2 for double. */
489
+ } else if (ctype_isstruct(sct->info)) {
490
+ if (sct->size)
491
+ return ccall_classify_struct(cts, sct);
492
+ } else {
493
+ break;
494
+ }
495
+ } else if (ctype_isbitfield(ct->info)) {
496
+ break;
497
+ } else if (ctype_isxattrib(ct->info, CTA_SUBTYPE)) {
498
+ CType *sct = ctype_rawchild(cts, ct);
499
+ if (sct->size)
500
+ return ccall_classify_struct(cts, sct);
501
+ }
502
+ }
503
+ return 0;
504
+ }
505
+
506
+ #endif
507
+
508
+ /* -- x64 struct classification ------------------------------------------- */
509
+
510
+ #if LJ_TARGET_X64 && !LJ_ABI_WIN
511
+
512
+ /* Register classes for x64 struct classification. */
513
+ #define CCALL_RCL_INT 1
514
+ #define CCALL_RCL_SSE 2
515
+ #define CCALL_RCL_MEM 4
516
+ /* NYI: classify vectors. */
517
+
518
+ static int ccall_classify_struct(CTState *cts, CType *ct, int *rcl, CTSize ofs);
519
+
520
+ /* Classify a C type. */
521
+ static void ccall_classify_ct(CTState *cts, CType *ct, int *rcl, CTSize ofs)
522
+ {
523
+ if (ctype_isarray(ct->info)) {
524
+ CType *cct = ctype_rawchild(cts, ct);
525
+ CTSize eofs, esz = cct->size, asz = ct->size;
526
+ for (eofs = 0; eofs < asz; eofs += esz)
527
+ ccall_classify_ct(cts, cct, rcl, ofs+eofs);
528
+ } else if (ctype_isstruct(ct->info)) {
529
+ ccall_classify_struct(cts, ct, rcl, ofs);
530
+ } else {
531
+ int cl = ctype_isfp(ct->info) ? CCALL_RCL_SSE : CCALL_RCL_INT;
532
+ lua_assert(ctype_hassize(ct->info));
533
+ if ((ofs & (ct->size-1))) cl = CCALL_RCL_MEM; /* Unaligned. */
534
+ rcl[(ofs >= 8)] |= cl;
535
+ }
536
+ }
537
+
538
+ /* Recursively classify a struct based on its fields. */
539
+ static int ccall_classify_struct(CTState *cts, CType *ct, int *rcl, CTSize ofs)
540
+ {
541
+ if (ct->size > 16) return CCALL_RCL_MEM; /* Too big, gets memory class. */
542
+ while (ct->sib) {
543
+ CTSize fofs;
544
+ ct = ctype_get(cts, ct->sib);
545
+ fofs = ofs+ct->size;
546
+ if (ctype_isfield(ct->info))
547
+ ccall_classify_ct(cts, ctype_rawchild(cts, ct), rcl, fofs);
548
+ else if (ctype_isbitfield(ct->info))
549
+ rcl[(fofs >= 8)] |= CCALL_RCL_INT; /* NYI: unaligned bitfields? */
550
+ else if (ctype_isxattrib(ct->info, CTA_SUBTYPE))
551
+ ccall_classify_struct(cts, ctype_rawchild(cts, ct), rcl, fofs);
552
+ }
553
+ return ((rcl[0]|rcl[1]) & CCALL_RCL_MEM); /* Memory class? */
554
+ }
555
+
556
+ /* Try to split up a small struct into registers. */
557
+ static int ccall_struct_reg(CCallState *cc, GPRArg *dp, int *rcl)
558
+ {
559
+ MSize ngpr = cc->ngpr, nfpr = cc->nfpr;
560
+ uint32_t i;
561
+ for (i = 0; i < 2; i++) {
562
+ lua_assert(!(rcl[i] & CCALL_RCL_MEM));
563
+ if ((rcl[i] & CCALL_RCL_INT)) { /* Integer class takes precedence. */
564
+ if (ngpr >= CCALL_NARG_GPR) return 1; /* Register overflow. */
565
+ cc->gpr[ngpr++] = dp[i];
566
+ } else if ((rcl[i] & CCALL_RCL_SSE)) {
567
+ if (nfpr >= CCALL_NARG_FPR) return 1; /* Register overflow. */
568
+ cc->fpr[nfpr++].l[0] = dp[i];
569
+ }
570
+ }
571
+ cc->ngpr = ngpr; cc->nfpr = nfpr;
572
+ return 0; /* Ok. */
573
+ }
574
+
575
+ /* Pass a small struct argument. */
576
+ static int ccall_struct_arg(CCallState *cc, CTState *cts, CType *d, int *rcl,
577
+ TValue *o, int narg)
578
+ {
579
+ GPRArg dp[2];
580
+ dp[0] = dp[1] = 0;
581
+ /* Convert to temp. struct. */
582
+ lj_cconv_ct_tv(cts, d, (uint8_t *)dp, o, CCF_ARG(narg));
583
+ if (ccall_struct_reg(cc, dp, rcl)) { /* Register overflow? Pass on stack. */
584
+ MSize nsp = cc->nsp, n = rcl[1] ? 2 : 1;
585
+ if (nsp + n > CCALL_MAXSTACK) return 1; /* Too many arguments. */
586
+ cc->nsp = nsp + n;
587
+ memcpy(&cc->stack[nsp], dp, n*CTSIZE_PTR);
588
+ }
589
+ return 0; /* Ok. */
590
+ }
591
+
592
+ /* Combine returned small struct. */
593
+ static void ccall_struct_ret(CCallState *cc, int *rcl, uint8_t *dp, CTSize sz)
594
+ {
595
+ GPRArg sp[2];
596
+ MSize ngpr = 0, nfpr = 0;
597
+ uint32_t i;
598
+ for (i = 0; i < 2; i++) {
599
+ if ((rcl[i] & CCALL_RCL_INT)) { /* Integer class takes precedence. */
600
+ sp[i] = cc->gpr[ngpr++];
601
+ } else if ((rcl[i] & CCALL_RCL_SSE)) {
602
+ sp[i] = cc->fpr[nfpr++].l[0];
603
+ }
604
+ }
605
+ memcpy(dp, sp, sz);
606
+ }
607
+ #endif
608
+
609
+ /* -- ARM hard-float ABI struct classification ---------------------------- */
610
+
611
+ #if LJ_TARGET_ARM && !LJ_ABI_SOFTFP
612
+
613
+ /* Classify a struct based on its fields. */
614
+ static unsigned int ccall_classify_struct(CTState *cts, CType *ct, CType *ctf)
615
+ {
616
+ CTSize sz = ct->size;
617
+ unsigned int r = 0, n = 0, isu = (ct->info & CTF_UNION);
618
+ if ((ctf->info & CTF_VARARG)) goto noth;
619
+ while (ct->sib) {
620
+ CType *sct;
621
+ ct = ctype_get(cts, ct->sib);
622
+ if (ctype_isfield(ct->info)) {
623
+ sct = ctype_rawchild(cts, ct);
624
+ if (ctype_isfp(sct->info)) {
625
+ r |= sct->size;
626
+ if (!isu) n++; else if (n == 0) n = 1;
627
+ } else if (ctype_iscomplex(sct->info)) {
628
+ r |= (sct->size >> 1);
629
+ if (!isu) n += 2; else if (n < 2) n = 2;
630
+ } else if (ctype_isstruct(sct->info)) {
631
+ goto substruct;
632
+ } else {
633
+ goto noth;
634
+ }
635
+ } else if (ctype_isbitfield(ct->info)) {
636
+ goto noth;
637
+ } else if (ctype_isxattrib(ct->info, CTA_SUBTYPE)) {
638
+ sct = ctype_rawchild(cts, ct);
639
+ substruct:
640
+ if (sct->size > 0) {
641
+ unsigned int s = ccall_classify_struct(cts, sct, ctf);
642
+ if (s <= 1) goto noth;
643
+ r |= (s & 255);
644
+ if (!isu) n += (s >> 8); else if (n < (s >>8)) n = (s >> 8);
645
+ }
646
+ }
647
+ }
648
+ if ((r == 4 || r == 8) && n <= 4)
649
+ return r + (n << 8);
650
+ noth: /* Not a homogeneous float/double aggregate. */
651
+ return (sz <= 4); /* Return structs of size <= 4 in a GPR. */
652
+ }
653
+
654
+ #endif
655
+
656
+ /* -- ARM64 ABI struct classification ------------------------------------- */
657
+
658
+ #if LJ_TARGET_ARM64
659
+
660
+ /* Classify a struct based on its fields. */
661
+ static unsigned int ccall_classify_struct(CTState *cts, CType *ct)
662
+ {
663
+ CTSize sz = ct->size;
664
+ unsigned int r = 0, n = 0, isu = (ct->info & CTF_UNION);
665
+ while (ct->sib) {
666
+ CType *sct;
667
+ ct = ctype_get(cts, ct->sib);
668
+ if (ctype_isfield(ct->info)) {
669
+ sct = ctype_rawchild(cts, ct);
670
+ if (ctype_isfp(sct->info)) {
671
+ r |= sct->size;
672
+ if (!isu) n++; else if (n == 0) n = 1;
673
+ } else if (ctype_iscomplex(sct->info)) {
674
+ r |= (sct->size >> 1);
675
+ if (!isu) n += 2; else if (n < 2) n = 2;
676
+ } else if (ctype_isstruct(sct->info)) {
677
+ goto substruct;
678
+ } else {
679
+ goto noth;
680
+ }
681
+ } else if (ctype_isbitfield(ct->info)) {
682
+ goto noth;
683
+ } else if (ctype_isxattrib(ct->info, CTA_SUBTYPE)) {
684
+ sct = ctype_rawchild(cts, ct);
685
+ substruct:
686
+ if (sct->size > 0) {
687
+ unsigned int s = ccall_classify_struct(cts, sct);
688
+ if (s <= 1) goto noth;
689
+ r |= (s & 255);
690
+ if (!isu) n += (s >> 8); else if (n < (s >>8)) n = (s >> 8);
691
+ }
692
+ }
693
+ }
694
+ if ((r == 4 || r == 8) && n <= 4)
695
+ return r + (n << 8);
696
+ noth: /* Not a homogeneous float/double aggregate. */
697
+ return (sz <= 16); /* Return structs of size <= 16 in GPRs. */
698
+ }
699
+
700
+ #endif
701
+
702
+ /* -- Common C call handling ---------------------------------------------- */
703
+
704
+ /* Infer the destination CTypeID for a vararg argument. */
705
+ CTypeID lj_ccall_ctid_vararg(CTState *cts, cTValue *o)
706
+ {
707
+ if (tvisnumber(o)) {
708
+ return CTID_DOUBLE;
709
+ } else if (tviscdata(o)) {
710
+ CTypeID id = cdataV(o)->ctypeid;
711
+ CType *s = ctype_get(cts, id);
712
+ if (ctype_isrefarray(s->info)) {
713
+ return lj_ctype_intern(cts,
714
+ CTINFO(CT_PTR, CTALIGN_PTR|ctype_cid(s->info)), CTSIZE_PTR);
715
+ } else if (ctype_isstruct(s->info) || ctype_isfunc(s->info)) {
716
+ /* NYI: how to pass a struct by value in a vararg argument? */
717
+ return lj_ctype_intern(cts, CTINFO(CT_PTR, CTALIGN_PTR|id), CTSIZE_PTR);
718
+ } else if (ctype_isfp(s->info) && s->size == sizeof(float)) {
719
+ return CTID_DOUBLE;
720
+ } else {
721
+ return id;
722
+ }
723
+ } else if (tvisstr(o)) {
724
+ return CTID_P_CCHAR;
725
+ } else if (tvisbool(o)) {
726
+ return CTID_BOOL;
727
+ } else {
728
+ return CTID_P_VOID;
729
+ }
730
+ }
731
+
732
+ /* Setup arguments for C call. */
733
+ static int ccall_set_args(lua_State *L, CTState *cts, CType *ct,
734
+ CCallState *cc)
735
+ {
736
+ int gcsteps = 0;
737
+ TValue *o, *top = L->top;
738
+ CTypeID fid;
739
+ CType *ctr;
740
+ MSize maxgpr, ngpr = 0, nsp = 0, narg;
741
+ #if CCALL_NARG_FPR
742
+ MSize nfpr = 0;
743
+ #if LJ_TARGET_ARM
744
+ MSize fprodd = 0;
745
+ #endif
746
+ #endif
747
+
748
+ /* Clear unused regs to get some determinism in case of misdeclaration. */
749
+ memset(cc->gpr, 0, sizeof(cc->gpr));
750
+ #if CCALL_NUM_FPR
751
+ memset(cc->fpr, 0, sizeof(cc->fpr));
752
+ #endif
753
+
754
+ #if LJ_TARGET_X86
755
+ /* x86 has several different calling conventions. */
756
+ cc->resx87 = 0;
757
+ switch (ctype_cconv(ct->info)) {
758
+ case CTCC_FASTCALL: maxgpr = 2; break;
759
+ case CTCC_THISCALL: maxgpr = 1; break;
760
+ default: maxgpr = 0; break;
761
+ }
762
+ #else
763
+ maxgpr = CCALL_NARG_GPR;
764
+ #endif
765
+
766
+ /* Perform required setup for some result types. */
767
+ ctr = ctype_rawchild(cts, ct);
768
+ if (ctype_isvector(ctr->info)) {
769
+ if (!(CCALL_VECTOR_REG && (ctr->size == 8 || ctr->size == 16)))
770
+ goto err_nyi;
771
+ } else if (ctype_iscomplex(ctr->info) || ctype_isstruct(ctr->info)) {
772
+ /* Preallocate cdata object and anchor it after arguments. */
773
+ CTSize sz = ctr->size;
774
+ GCcdata *cd = lj_cdata_new(cts, ctype_cid(ct->info), sz);
775
+ void *dp = cdataptr(cd);
776
+ setcdataV(L, L->top++, cd);
777
+ if (ctype_isstruct(ctr->info)) {
778
+ CCALL_HANDLE_STRUCTRET
779
+ } else {
780
+ CCALL_HANDLE_COMPLEXRET
781
+ }
782
+ #if LJ_TARGET_X86
783
+ } else if (ctype_isfp(ctr->info)) {
784
+ cc->resx87 = ctr->size == sizeof(float) ? 1 : 2;
785
+ #endif
786
+ }
787
+
788
+ /* Skip initial attributes. */
789
+ fid = ct->sib;
790
+ while (fid) {
791
+ CType *ctf = ctype_get(cts, fid);
792
+ if (!ctype_isattrib(ctf->info)) break;
793
+ fid = ctf->sib;
794
+ }
795
+
796
+ /* Walk through all passed arguments. */
797
+ for (o = L->base+1, narg = 1; o < top; o++, narg++) {
798
+ CTypeID did;
799
+ CType *d;
800
+ CTSize sz;
801
+ MSize n, isfp = 0, isva = 0;
802
+ void *dp, *rp = NULL;
803
+
804
+ if (fid) { /* Get argument type from field. */
805
+ CType *ctf = ctype_get(cts, fid);
806
+ fid = ctf->sib;
807
+ lua_assert(ctype_isfield(ctf->info));
808
+ did = ctype_cid(ctf->info);
809
+ } else {
810
+ if (!(ct->info & CTF_VARARG))
811
+ lj_err_caller(L, LJ_ERR_FFI_NUMARG); /* Too many arguments. */
812
+ did = lj_ccall_ctid_vararg(cts, o); /* Infer vararg type. */
813
+ isva = 1;
814
+ }
815
+ d = ctype_raw(cts, did);
816
+ sz = d->size;
817
+
818
+ /* Find out how (by value/ref) and where (GPR/FPR) to pass an argument. */
819
+ if (ctype_isnum(d->info)) {
820
+ if (sz > 8) goto err_nyi;
821
+ if ((d->info & CTF_FP))
822
+ isfp = 1;
823
+ } else if (ctype_isvector(d->info)) {
824
+ if (CCALL_VECTOR_REG && (sz == 8 || sz == 16))
825
+ isfp = 1;
826
+ else
827
+ goto err_nyi;
828
+ } else if (ctype_isstruct(d->info)) {
829
+ CCALL_HANDLE_STRUCTARG
830
+ } else if (ctype_iscomplex(d->info)) {
831
+ CCALL_HANDLE_COMPLEXARG
832
+ } else {
833
+ sz = CTSIZE_PTR;
834
+ }
835
+ sz = (sz + CTSIZE_PTR-1) & ~(CTSIZE_PTR-1);
836
+ n = sz / CTSIZE_PTR; /* Number of GPRs or stack slots needed. */
837
+
838
+ CCALL_HANDLE_REGARG /* Handle register arguments. */
839
+
840
+ /* Otherwise pass argument on stack. */
841
+ if (CCALL_ALIGN_STACKARG && !rp && (d->info & CTF_ALIGN) > CTALIGN_PTR) {
842
+ MSize align = (1u << ctype_align(d->info-CTALIGN_PTR)) -1;
843
+ nsp = (nsp + align) & ~align; /* Align argument on stack. */
844
+ }
845
+ if (nsp + n > CCALL_MAXSTACK) { /* Too many arguments. */
846
+ err_nyi:
847
+ lj_err_caller(L, LJ_ERR_FFI_NYICALL);
848
+ }
849
+ dp = &cc->stack[nsp];
850
+ nsp += n;
851
+ isva = 0;
852
+
853
+ done:
854
+ if (rp) { /* Pass by reference. */
855
+ gcsteps++;
856
+ *(void **)dp = rp;
857
+ dp = rp;
858
+ }
859
+ lj_cconv_ct_tv(cts, d, (uint8_t *)dp, o, CCF_ARG(narg));
860
+ /* Extend passed integers to 32 bits at least. */
861
+ if (ctype_isinteger_or_bool(d->info) && d->size < 4) {
862
+ if (d->info & CTF_UNSIGNED)
863
+ *(uint32_t *)dp = d->size == 1 ? (uint32_t)*(uint8_t *)dp :
864
+ (uint32_t)*(uint16_t *)dp;
865
+ else
866
+ *(int32_t *)dp = d->size == 1 ? (int32_t)*(int8_t *)dp :
867
+ (int32_t)*(int16_t *)dp;
868
+ }
869
+ #if LJ_TARGET_X64 && LJ_ABI_WIN
870
+ if (isva) { /* Windows/x64 mirrors varargs in both register sets. */
871
+ if (nfpr == ngpr)
872
+ cc->gpr[ngpr-1] = cc->fpr[ngpr-1].l[0];
873
+ else
874
+ cc->fpr[ngpr-1].l[0] = cc->gpr[ngpr-1];
875
+ }
876
+ #else
877
+ UNUSED(isva);
878
+ #endif
879
+ #if LJ_TARGET_X64 && !LJ_ABI_WIN
880
+ if (isfp == 2 && n == 2 && (uint8_t *)dp == (uint8_t *)&cc->fpr[nfpr-2]) {
881
+ cc->fpr[nfpr-1].d[0] = cc->fpr[nfpr-2].d[1]; /* Split complex double. */
882
+ cc->fpr[nfpr-2].d[1] = 0;
883
+ }
884
+ #elif LJ_TARGET_ARM64
885
+ if (isfp == 2 && (uint8_t *)dp < (uint8_t *)cc->stack) {
886
+ /* Split float HFA or complex float into separate registers. */
887
+ CTSize i = (sz >> 2) - 1;
888
+ do { ((uint64_t *)dp)[i] = ((uint32_t *)dp)[i]; } while (i--);
889
+ }
890
+ #else
891
+ UNUSED(isfp);
892
+ #endif
893
+ }
894
+ if (fid) lj_err_caller(L, LJ_ERR_FFI_NUMARG); /* Too few arguments. */
895
+
896
+ #if LJ_TARGET_X64 || LJ_TARGET_PPC
897
+ cc->nfpr = nfpr; /* Required for vararg functions. */
898
+ #endif
899
+ cc->nsp = nsp;
900
+ cc->spadj = (CCALL_SPS_FREE + CCALL_SPS_EXTRA)*CTSIZE_PTR;
901
+ if (nsp > CCALL_SPS_FREE)
902
+ cc->spadj += (((nsp-CCALL_SPS_FREE)*CTSIZE_PTR + 15u) & ~15u);
903
+ return gcsteps;
904
+ }
905
+
906
+ /* Get results from C call. */
907
+ static int ccall_get_results(lua_State *L, CTState *cts, CType *ct,
908
+ CCallState *cc, int *ret)
909
+ {
910
+ CType *ctr = ctype_rawchild(cts, ct);
911
+ uint8_t *sp = (uint8_t *)&cc->gpr[0];
912
+ if (ctype_isvoid(ctr->info)) {
913
+ *ret = 0; /* Zero results. */
914
+ return 0; /* No additional GC step. */
915
+ }
916
+ *ret = 1; /* One result. */
917
+ if (ctype_isstruct(ctr->info)) {
918
+ /* Return cdata object which is already on top of stack. */
919
+ if (!cc->retref) {
920
+ void *dp = cdataptr(cdataV(L->top-1)); /* Use preallocated object. */
921
+ CCALL_HANDLE_STRUCTRET2
922
+ }
923
+ return 1; /* One GC step. */
924
+ }
925
+ if (ctype_iscomplex(ctr->info)) {
926
+ /* Return cdata object which is already on top of stack. */
927
+ void *dp = cdataptr(cdataV(L->top-1)); /* Use preallocated object. */
928
+ CCALL_HANDLE_COMPLEXRET2
929
+ return 1; /* One GC step. */
930
+ }
931
+ if (LJ_BE && ctype_isinteger_or_bool(ctr->info) && ctr->size < CTSIZE_PTR)
932
+ sp += (CTSIZE_PTR - ctr->size);
933
+ #if CCALL_NUM_FPR
934
+ if (ctype_isfp(ctr->info) || ctype_isvector(ctr->info))
935
+ sp = (uint8_t *)&cc->fpr[0];
936
+ #endif
937
+ #ifdef CCALL_HANDLE_RET
938
+ CCALL_HANDLE_RET
939
+ #endif
940
+ /* No reference types end up here, so there's no need for the CTypeID. */
941
+ lua_assert(!(ctype_isrefarray(ctr->info) || ctype_isstruct(ctr->info)));
942
+ return lj_cconv_tv_ct(cts, ctr, 0, L->top-1, sp);
943
+ }
944
+
945
+ /* Call C function. */
946
+ int lj_ccall_func(lua_State *L, GCcdata *cd)
947
+ {
948
+ CTState *cts = ctype_cts(L);
949
+ CType *ct = ctype_raw(cts, cd->ctypeid);
950
+ CTSize sz = CTSIZE_PTR;
951
+ if (ctype_isptr(ct->info)) {
952
+ sz = ct->size;
953
+ ct = ctype_rawchild(cts, ct);
954
+ }
955
+ if (ctype_isfunc(ct->info)) {
956
+ CCallState cc;
957
+ int gcsteps, ret;
958
+ cc.func = (void (*)(void))cdata_getptr(cdataptr(cd), sz);
959
+ gcsteps = ccall_set_args(L, cts, ct, &cc);
960
+ ct = (CType *)((intptr_t)ct-(intptr_t)cts->tab);
961
+ cts->cb.slot = ~0u;
962
+ lj_vm_ffi_call(&cc);
963
+ if (cts->cb.slot != ~0u) { /* Blacklist function that called a callback. */
964
+ TValue tv;
965
+ setlightudV(&tv, (void *)cc.func);
966
+ setboolV(lj_tab_set(L, cts->miscmap, &tv), 1);
967
+ }
968
+ ct = (CType *)((intptr_t)ct+(intptr_t)cts->tab); /* May be reallocated. */
969
+ gcsteps += ccall_get_results(L, cts, ct, &cc, &ret);
970
+ #if LJ_TARGET_X86 && LJ_ABI_WIN
971
+ /* Automatically detect __stdcall and fix up C function declaration. */
972
+ if (cc.spadj && ctype_cconv(ct->info) == CTCC_CDECL) {
973
+ CTF_INSERT(ct->info, CCONV, CTCC_STDCALL);
974
+ lj_trace_abort(G(L));
975
+ }
976
+ #endif
977
+ while (gcsteps-- > 0)
978
+ lj_gc_check(L);
979
+ return ret;
980
+ }
981
+ return -1; /* Not a function. */
982
+ }
983
+
984
+ #endif