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,25 @@
1
+ /*
2
+ ** FFI C callback handling.
3
+ ** Copyright (C) 2005-2015 Mike Pall. See Copyright Notice in luajit.h
4
+ */
5
+
6
+ #ifndef _LJ_CCALLBACK_H
7
+ #define _LJ_CCALLBACK_H
8
+
9
+ #include "lj_obj.h"
10
+ #include "lj_ctype.h"
11
+
12
+ #if LJ_HASFFI
13
+
14
+ /* Really belongs to lj_vm.h. */
15
+ LJ_ASMF void lj_vm_ffi_callback(void);
16
+
17
+ LJ_FUNC MSize lj_ccallback_ptr2slot(CTState *cts, void *p);
18
+ LJ_FUNCA lua_State * LJ_FASTCALL lj_ccallback_enter(CTState *cts, void *cf);
19
+ LJ_FUNCA void LJ_FASTCALL lj_ccallback_leave(CTState *cts, TValue *o);
20
+ LJ_FUNC void *lj_ccallback_new(CTState *cts, CType *ct, GCfunc *fn);
21
+ LJ_FUNC void lj_ccallback_mcode_free(CTState *cts);
22
+
23
+ #endif
24
+
25
+ #endif
@@ -0,0 +1,752 @@
1
+ /*
2
+ ** C type conversions.
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_err.h"
11
+ #include "lj_tab.h"
12
+ #include "lj_ctype.h"
13
+ #include "lj_cdata.h"
14
+ #include "lj_cconv.h"
15
+ #include "lj_ccallback.h"
16
+
17
+ /* -- Conversion errors --------------------------------------------------- */
18
+
19
+ /* Bad conversion. */
20
+ LJ_NORET static void cconv_err_conv(CTState *cts, CType *d, CType *s,
21
+ CTInfo flags)
22
+ {
23
+ const char *dst = strdata(lj_ctype_repr(cts->L, ctype_typeid(cts, d), NULL));
24
+ const char *src;
25
+ if ((flags & CCF_FROMTV))
26
+ src = lj_obj_typename[1+(ctype_isnum(s->info) ? LUA_TNUMBER :
27
+ ctype_isarray(s->info) ? LUA_TSTRING : LUA_TNIL)];
28
+ else
29
+ src = strdata(lj_ctype_repr(cts->L, ctype_typeid(cts, s), NULL));
30
+ if (CCF_GETARG(flags))
31
+ lj_err_argv(cts->L, CCF_GETARG(flags), LJ_ERR_FFI_BADCONV, src, dst);
32
+ else
33
+ lj_err_callerv(cts->L, LJ_ERR_FFI_BADCONV, src, dst);
34
+ }
35
+
36
+ /* Bad conversion from TValue. */
37
+ LJ_NORET static void cconv_err_convtv(CTState *cts, CType *d, TValue *o,
38
+ CTInfo flags)
39
+ {
40
+ const char *dst = strdata(lj_ctype_repr(cts->L, ctype_typeid(cts, d), NULL));
41
+ const char *src = lj_typename(o);
42
+ if (CCF_GETARG(flags))
43
+ lj_err_argv(cts->L, CCF_GETARG(flags), LJ_ERR_FFI_BADCONV, src, dst);
44
+ else
45
+ lj_err_callerv(cts->L, LJ_ERR_FFI_BADCONV, src, dst);
46
+ }
47
+
48
+ /* Initializer overflow. */
49
+ LJ_NORET static void cconv_err_initov(CTState *cts, CType *d)
50
+ {
51
+ const char *dst = strdata(lj_ctype_repr(cts->L, ctype_typeid(cts, d), NULL));
52
+ lj_err_callerv(cts->L, LJ_ERR_FFI_INITOV, dst);
53
+ }
54
+
55
+ /* -- C type compatibility checks ----------------------------------------- */
56
+
57
+ /* Get raw type and qualifiers for a child type. Resolves enums, too. */
58
+ static CType *cconv_childqual(CTState *cts, CType *ct, CTInfo *qual)
59
+ {
60
+ ct = ctype_child(cts, ct);
61
+ for (;;) {
62
+ if (ctype_isattrib(ct->info)) {
63
+ if (ctype_attrib(ct->info) == CTA_QUAL) *qual |= ct->size;
64
+ } else if (!ctype_isenum(ct->info)) {
65
+ break;
66
+ }
67
+ ct = ctype_child(cts, ct);
68
+ }
69
+ *qual |= (ct->info & CTF_QUAL);
70
+ return ct;
71
+ }
72
+
73
+ /* Check for compatible types when converting to a pointer.
74
+ ** Note: these checks are more relaxed than what C99 mandates.
75
+ */
76
+ int lj_cconv_compatptr(CTState *cts, CType *d, CType *s, CTInfo flags)
77
+ {
78
+ if (!((flags & CCF_CAST) || d == s)) {
79
+ CTInfo dqual = 0, squal = 0;
80
+ d = cconv_childqual(cts, d, &dqual);
81
+ if (!ctype_isstruct(s->info))
82
+ s = cconv_childqual(cts, s, &squal);
83
+ if ((flags & CCF_SAME)) {
84
+ if (dqual != squal)
85
+ return 0; /* Different qualifiers. */
86
+ } else if (!(flags & CCF_IGNQUAL)) {
87
+ if ((dqual & squal) != squal)
88
+ return 0; /* Discarded qualifiers. */
89
+ if (ctype_isvoid(d->info) || ctype_isvoid(s->info))
90
+ return 1; /* Converting to/from void * is always ok. */
91
+ }
92
+ if (ctype_type(d->info) != ctype_type(s->info) ||
93
+ d->size != s->size)
94
+ return 0; /* Different type or different size. */
95
+ if (ctype_isnum(d->info)) {
96
+ if (((d->info ^ s->info) & (CTF_BOOL|CTF_FP)))
97
+ return 0; /* Different numeric types. */
98
+ } else if (ctype_ispointer(d->info)) {
99
+ /* Check child types for compatibility. */
100
+ return lj_cconv_compatptr(cts, d, s, flags|CCF_SAME);
101
+ } else if (ctype_isstruct(d->info)) {
102
+ if (d != s)
103
+ return 0; /* Must be exact same type for struct/union. */
104
+ } else if (ctype_isfunc(d->info)) {
105
+ /* NYI: structural equality of functions. */
106
+ }
107
+ }
108
+ return 1; /* Types are compatible. */
109
+ }
110
+
111
+ /* -- C type to C type conversion ----------------------------------------- */
112
+
113
+ /* Convert C type to C type. Caveat: expects to get the raw CType!
114
+ **
115
+ ** Note: This is only used by the interpreter and not optimized at all.
116
+ ** The JIT compiler will do a much better job specializing for each case.
117
+ */
118
+ void lj_cconv_ct_ct(CTState *cts, CType *d, CType *s,
119
+ uint8_t *dp, uint8_t *sp, CTInfo flags)
120
+ {
121
+ CTSize dsize = d->size, ssize = s->size;
122
+ CTInfo dinfo = d->info, sinfo = s->info;
123
+ void *tmpptr;
124
+
125
+ lua_assert(!ctype_isenum(dinfo) && !ctype_isenum(sinfo));
126
+ lua_assert(!ctype_isattrib(dinfo) && !ctype_isattrib(sinfo));
127
+
128
+ if (ctype_type(dinfo) > CT_MAYCONVERT || ctype_type(sinfo) > CT_MAYCONVERT)
129
+ goto err_conv;
130
+
131
+ /* Some basic sanity checks. */
132
+ lua_assert(!ctype_isnum(dinfo) || dsize > 0);
133
+ lua_assert(!ctype_isnum(sinfo) || ssize > 0);
134
+ lua_assert(!ctype_isbool(dinfo) || dsize == 1 || dsize == 4);
135
+ lua_assert(!ctype_isbool(sinfo) || ssize == 1 || ssize == 4);
136
+ lua_assert(!ctype_isinteger(dinfo) || (1u<<lj_fls(dsize)) == dsize);
137
+ lua_assert(!ctype_isinteger(sinfo) || (1u<<lj_fls(ssize)) == ssize);
138
+
139
+ switch (cconv_idx2(dinfo, sinfo)) {
140
+ /* Destination is a bool. */
141
+ case CCX(B, B):
142
+ /* Source operand is already normalized. */
143
+ if (dsize == 1) *dp = *sp; else *(int *)dp = *sp;
144
+ break;
145
+ case CCX(B, I): {
146
+ MSize i;
147
+ uint8_t b = 0;
148
+ for (i = 0; i < ssize; i++) b |= sp[i];
149
+ b = (b != 0);
150
+ if (dsize == 1) *dp = b; else *(int *)dp = b;
151
+ break;
152
+ }
153
+ case CCX(B, F): {
154
+ uint8_t b;
155
+ if (ssize == sizeof(double)) b = (*(double *)sp != 0);
156
+ else if (ssize == sizeof(float)) b = (*(float *)sp != 0);
157
+ else goto err_conv; /* NYI: long double. */
158
+ if (dsize == 1) *dp = b; else *(int *)dp = b;
159
+ break;
160
+ }
161
+
162
+ /* Destination is an integer. */
163
+ case CCX(I, B):
164
+ case CCX(I, I):
165
+ conv_I_I:
166
+ if (dsize > ssize) { /* Zero-extend or sign-extend LSB. */
167
+ #if LJ_LE
168
+ uint8_t fill = (!(sinfo & CTF_UNSIGNED) && (sp[ssize-1]&0x80)) ? 0xff : 0;
169
+ memcpy(dp, sp, ssize);
170
+ memset(dp + ssize, fill, dsize-ssize);
171
+ #else
172
+ uint8_t fill = (!(sinfo & CTF_UNSIGNED) && (sp[0]&0x80)) ? 0xff : 0;
173
+ memset(dp, fill, dsize-ssize);
174
+ memcpy(dp + (dsize-ssize), sp, ssize);
175
+ #endif
176
+ } else { /* Copy LSB. */
177
+ #if LJ_LE
178
+ memcpy(dp, sp, dsize);
179
+ #else
180
+ memcpy(dp, sp + (ssize-dsize), dsize);
181
+ #endif
182
+ }
183
+ break;
184
+ case CCX(I, F): {
185
+ double n; /* Always convert via double. */
186
+ conv_I_F:
187
+ /* Convert source to double. */
188
+ if (ssize == sizeof(double)) n = *(double *)sp;
189
+ else if (ssize == sizeof(float)) n = (double)*(float *)sp;
190
+ else goto err_conv; /* NYI: long double. */
191
+ /* Then convert double to integer. */
192
+ /* The conversion must exactly match the semantics of JIT-compiled code! */
193
+ if (dsize < 4 || (dsize == 4 && !(dinfo & CTF_UNSIGNED))) {
194
+ int32_t i = (int32_t)n;
195
+ if (dsize == 4) *(int32_t *)dp = i;
196
+ else if (dsize == 2) *(int16_t *)dp = (int16_t)i;
197
+ else *(int8_t *)dp = (int8_t)i;
198
+ } else if (dsize == 4) {
199
+ *(uint32_t *)dp = (uint32_t)n;
200
+ } else if (dsize == 8) {
201
+ if (!(dinfo & CTF_UNSIGNED))
202
+ *(int64_t *)dp = (int64_t)n;
203
+ else
204
+ *(uint64_t *)dp = lj_num2u64(n);
205
+ } else {
206
+ goto err_conv; /* NYI: conversion to >64 bit integers. */
207
+ }
208
+ break;
209
+ }
210
+ case CCX(I, C):
211
+ s = ctype_child(cts, s);
212
+ sinfo = s->info;
213
+ ssize = s->size;
214
+ goto conv_I_F; /* Just convert re. */
215
+ case CCX(I, P):
216
+ if (!(flags & CCF_CAST)) goto err_conv;
217
+ sinfo = CTINFO(CT_NUM, CTF_UNSIGNED);
218
+ goto conv_I_I;
219
+ case CCX(I, A):
220
+ if (!(flags & CCF_CAST)) goto err_conv;
221
+ sinfo = CTINFO(CT_NUM, CTF_UNSIGNED);
222
+ ssize = CTSIZE_PTR;
223
+ tmpptr = sp;
224
+ sp = (uint8_t *)&tmpptr;
225
+ goto conv_I_I;
226
+
227
+ /* Destination is a floating-point number. */
228
+ case CCX(F, B):
229
+ case CCX(F, I): {
230
+ double n; /* Always convert via double. */
231
+ conv_F_I:
232
+ /* First convert source to double. */
233
+ /* The conversion must exactly match the semantics of JIT-compiled code! */
234
+ if (ssize < 4 || (ssize == 4 && !(sinfo & CTF_UNSIGNED))) {
235
+ int32_t i;
236
+ if (ssize == 4) {
237
+ i = *(int32_t *)sp;
238
+ } else if (!(sinfo & CTF_UNSIGNED)) {
239
+ if (ssize == 2) i = *(int16_t *)sp;
240
+ else i = *(int8_t *)sp;
241
+ } else {
242
+ if (ssize == 2) i = *(uint16_t *)sp;
243
+ else i = *(uint8_t *)sp;
244
+ }
245
+ n = (double)i;
246
+ } else if (ssize == 4) {
247
+ n = (double)*(uint32_t *)sp;
248
+ } else if (ssize == 8) {
249
+ if (!(sinfo & CTF_UNSIGNED)) n = (double)*(int64_t *)sp;
250
+ else n = (double)*(uint64_t *)sp;
251
+ } else {
252
+ goto err_conv; /* NYI: conversion from >64 bit integers. */
253
+ }
254
+ /* Convert double to destination. */
255
+ if (dsize == sizeof(double)) *(double *)dp = n;
256
+ else if (dsize == sizeof(float)) *(float *)dp = (float)n;
257
+ else goto err_conv; /* NYI: long double. */
258
+ break;
259
+ }
260
+ case CCX(F, F): {
261
+ double n; /* Always convert via double. */
262
+ conv_F_F:
263
+ if (ssize == dsize) goto copyval;
264
+ /* Convert source to double. */
265
+ if (ssize == sizeof(double)) n = *(double *)sp;
266
+ else if (ssize == sizeof(float)) n = (double)*(float *)sp;
267
+ else goto err_conv; /* NYI: long double. */
268
+ /* Convert double to destination. */
269
+ if (dsize == sizeof(double)) *(double *)dp = n;
270
+ else if (dsize == sizeof(float)) *(float *)dp = (float)n;
271
+ else goto err_conv; /* NYI: long double. */
272
+ break;
273
+ }
274
+ case CCX(F, C):
275
+ s = ctype_child(cts, s);
276
+ sinfo = s->info;
277
+ ssize = s->size;
278
+ goto conv_F_F; /* Ignore im, and convert from re. */
279
+
280
+ /* Destination is a complex number. */
281
+ case CCX(C, I):
282
+ d = ctype_child(cts, d);
283
+ dinfo = d->info;
284
+ dsize = d->size;
285
+ memset(dp + dsize, 0, dsize); /* Clear im. */
286
+ goto conv_F_I; /* Convert to re. */
287
+ case CCX(C, F):
288
+ d = ctype_child(cts, d);
289
+ dinfo = d->info;
290
+ dsize = d->size;
291
+ memset(dp + dsize, 0, dsize); /* Clear im. */
292
+ goto conv_F_F; /* Convert to re. */
293
+
294
+ case CCX(C, C):
295
+ if (dsize != ssize) { /* Different types: convert re/im separately. */
296
+ CType *dc = ctype_child(cts, d);
297
+ CType *sc = ctype_child(cts, s);
298
+ lj_cconv_ct_ct(cts, dc, sc, dp, sp, flags);
299
+ lj_cconv_ct_ct(cts, dc, sc, dp + dc->size, sp + sc->size, flags);
300
+ return;
301
+ }
302
+ goto copyval; /* Otherwise this is easy. */
303
+
304
+ /* Destination is a vector. */
305
+ case CCX(V, I):
306
+ case CCX(V, F):
307
+ case CCX(V, C): {
308
+ CType *dc = ctype_child(cts, d);
309
+ CTSize esize;
310
+ /* First convert the scalar to the first element. */
311
+ lj_cconv_ct_ct(cts, dc, s, dp, sp, flags);
312
+ /* Then replicate it to the other elements (splat). */
313
+ for (sp = dp, esize = dc->size; dsize > esize; dsize -= esize) {
314
+ dp += esize;
315
+ memcpy(dp, sp, esize);
316
+ }
317
+ break;
318
+ }
319
+
320
+ case CCX(V, V):
321
+ /* Copy same-sized vectors, even for different lengths/element-types. */
322
+ if (dsize != ssize) goto err_conv;
323
+ goto copyval;
324
+
325
+ /* Destination is a pointer. */
326
+ case CCX(P, I):
327
+ if (!(flags & CCF_CAST)) goto err_conv;
328
+ dinfo = CTINFO(CT_NUM, CTF_UNSIGNED);
329
+ goto conv_I_I;
330
+
331
+ case CCX(P, F):
332
+ if (!(flags & CCF_CAST) || !(flags & CCF_FROMTV)) goto err_conv;
333
+ /* The signed conversion is cheaper. x64 really has 47 bit pointers. */
334
+ dinfo = CTINFO(CT_NUM, (LJ_64 && dsize == 8) ? 0 : CTF_UNSIGNED);
335
+ goto conv_I_F;
336
+
337
+ case CCX(P, P):
338
+ if (!lj_cconv_compatptr(cts, d, s, flags)) goto err_conv;
339
+ cdata_setptr(dp, dsize, cdata_getptr(sp, ssize));
340
+ break;
341
+
342
+ case CCX(P, A):
343
+ case CCX(P, S):
344
+ if (!lj_cconv_compatptr(cts, d, s, flags)) goto err_conv;
345
+ cdata_setptr(dp, dsize, sp);
346
+ break;
347
+
348
+ /* Destination is an array. */
349
+ case CCX(A, A):
350
+ if ((flags & CCF_CAST) || (d->info & CTF_VLA) || dsize != ssize ||
351
+ d->size == CTSIZE_INVALID || !lj_cconv_compatptr(cts, d, s, flags))
352
+ goto err_conv;
353
+ goto copyval;
354
+
355
+ /* Destination is a struct/union. */
356
+ case CCX(S, S):
357
+ if ((flags & CCF_CAST) || (d->info & CTF_VLA) || d != s)
358
+ goto err_conv; /* Must be exact same type. */
359
+ copyval: /* Copy value. */
360
+ lua_assert(dsize == ssize);
361
+ memcpy(dp, sp, dsize);
362
+ break;
363
+
364
+ default:
365
+ err_conv:
366
+ cconv_err_conv(cts, d, s, flags);
367
+ }
368
+ }
369
+
370
+ /* -- C type to TValue conversion ----------------------------------------- */
371
+
372
+ /* Convert C type to TValue. Caveat: expects to get the raw CType! */
373
+ int lj_cconv_tv_ct(CTState *cts, CType *s, CTypeID sid,
374
+ TValue *o, uint8_t *sp)
375
+ {
376
+ CTInfo sinfo = s->info;
377
+ if (ctype_isnum(sinfo)) {
378
+ if (!ctype_isbool(sinfo)) {
379
+ if (ctype_isinteger(sinfo) && s->size > 4) goto copyval;
380
+ if (LJ_DUALNUM && ctype_isinteger(sinfo)) {
381
+ int32_t i;
382
+ lj_cconv_ct_ct(cts, ctype_get(cts, CTID_INT32), s,
383
+ (uint8_t *)&i, sp, 0);
384
+ if ((sinfo & CTF_UNSIGNED) && i < 0)
385
+ setnumV(o, (lua_Number)(uint32_t)i);
386
+ else
387
+ setintV(o, i);
388
+ } else {
389
+ lj_cconv_ct_ct(cts, ctype_get(cts, CTID_DOUBLE), s,
390
+ (uint8_t *)&o->n, sp, 0);
391
+ /* Numbers are NOT canonicalized here! Beware of uninitialized data. */
392
+ lua_assert(tvisnum(o));
393
+ }
394
+ } else {
395
+ uint32_t b = s->size == 1 ? (*sp != 0) : (*(int *)sp != 0);
396
+ setboolV(o, b);
397
+ setboolV(&cts->g->tmptv2, b); /* Remember for trace recorder. */
398
+ }
399
+ return 0;
400
+ } else if (ctype_isrefarray(sinfo) || ctype_isstruct(sinfo)) {
401
+ /* Create reference. */
402
+ setcdataV(cts->L, o, lj_cdata_newref(cts, sp, sid));
403
+ return 1; /* Need GC step. */
404
+ } else {
405
+ GCcdata *cd;
406
+ CTSize sz;
407
+ copyval: /* Copy value. */
408
+ sz = s->size;
409
+ lua_assert(sz != CTSIZE_INVALID);
410
+ /* Attributes are stripped, qualifiers are kept (but mostly ignored). */
411
+ cd = lj_cdata_new(cts, ctype_typeid(cts, s), sz);
412
+ setcdataV(cts->L, o, cd);
413
+ memcpy(cdataptr(cd), sp, sz);
414
+ return 1; /* Need GC step. */
415
+ }
416
+ }
417
+
418
+ /* Convert bitfield to TValue. */
419
+ int lj_cconv_tv_bf(CTState *cts, CType *s, TValue *o, uint8_t *sp)
420
+ {
421
+ CTInfo info = s->info;
422
+ CTSize pos, bsz;
423
+ uint32_t val;
424
+ lua_assert(ctype_isbitfield(info));
425
+ /* NYI: packed bitfields may cause misaligned reads. */
426
+ switch (ctype_bitcsz(info)) {
427
+ case 4: val = *(uint32_t *)sp; break;
428
+ case 2: val = *(uint16_t *)sp; break;
429
+ case 1: val = *(uint8_t *)sp; break;
430
+ default: lua_assert(0); val = 0; break;
431
+ }
432
+ /* Check if a packed bitfield crosses a container boundary. */
433
+ pos = ctype_bitpos(info);
434
+ bsz = ctype_bitbsz(info);
435
+ lua_assert(pos < 8*ctype_bitcsz(info));
436
+ lua_assert(bsz > 0 && bsz <= 8*ctype_bitcsz(info));
437
+ if (pos + bsz > 8*ctype_bitcsz(info))
438
+ lj_err_caller(cts->L, LJ_ERR_FFI_NYIPACKBIT);
439
+ if (!(info & CTF_BOOL)) {
440
+ CTSize shift = 32 - bsz;
441
+ if (!(info & CTF_UNSIGNED)) {
442
+ setintV(o, (int32_t)(val << (shift-pos)) >> shift);
443
+ } else {
444
+ val = (val << (shift-pos)) >> shift;
445
+ if (!LJ_DUALNUM || (int32_t)val < 0)
446
+ setnumV(o, (lua_Number)(uint32_t)val);
447
+ else
448
+ setintV(o, (int32_t)val);
449
+ }
450
+ } else {
451
+ lua_assert(bsz == 1);
452
+ setboolV(o, (val >> pos) & 1);
453
+ }
454
+ return 0; /* No GC step needed. */
455
+ }
456
+
457
+ /* -- TValue to C type conversion ----------------------------------------- */
458
+
459
+ /* Convert table to array. */
460
+ static void cconv_array_tab(CTState *cts, CType *d,
461
+ uint8_t *dp, GCtab *t, CTInfo flags)
462
+ {
463
+ int32_t i;
464
+ CType *dc = ctype_rawchild(cts, d); /* Array element type. */
465
+ CTSize size = d->size, esize = dc->size, ofs = 0;
466
+ for (i = 0; ; i++) {
467
+ TValue *tv = (TValue *)lj_tab_getint(t, i);
468
+ if (!tv || tvisnil(tv)) {
469
+ if (i == 0) continue; /* Try again for 1-based tables. */
470
+ break; /* Stop at first nil. */
471
+ }
472
+ if (ofs >= size)
473
+ cconv_err_initov(cts, d);
474
+ lj_cconv_ct_tv(cts, dc, dp + ofs, tv, flags);
475
+ ofs += esize;
476
+ }
477
+ if (size != CTSIZE_INVALID) { /* Only fill up arrays with known size. */
478
+ if (ofs == esize) { /* Replicate a single element. */
479
+ for (; ofs < size; ofs += esize) memcpy(dp + ofs, dp, esize);
480
+ } else { /* Otherwise fill the remainder with zero. */
481
+ memset(dp + ofs, 0, size - ofs);
482
+ }
483
+ }
484
+ }
485
+
486
+ /* Convert table to sub-struct/union. */
487
+ static void cconv_substruct_tab(CTState *cts, CType *d, uint8_t *dp,
488
+ GCtab *t, int32_t *ip, CTInfo flags)
489
+ {
490
+ CTypeID id = d->sib;
491
+ while (id) {
492
+ CType *df = ctype_get(cts, id);
493
+ id = df->sib;
494
+ if (ctype_isfield(df->info) || ctype_isbitfield(df->info)) {
495
+ TValue *tv;
496
+ int32_t i = *ip, iz = i;
497
+ if (!gcref(df->name)) continue; /* Ignore unnamed fields. */
498
+ if (i >= 0) {
499
+ retry:
500
+ tv = (TValue *)lj_tab_getint(t, i);
501
+ if (!tv || tvisnil(tv)) {
502
+ if (i == 0) { i = 1; goto retry; } /* 1-based tables. */
503
+ if (iz == 0) { *ip = i = -1; goto tryname; } /* Init named fields. */
504
+ break; /* Stop at first nil. */
505
+ }
506
+ *ip = i + 1;
507
+ } else {
508
+ tryname:
509
+ tv = (TValue *)lj_tab_getstr(t, gco2str(gcref(df->name)));
510
+ if (!tv || tvisnil(tv)) continue;
511
+ }
512
+ if (ctype_isfield(df->info))
513
+ lj_cconv_ct_tv(cts, ctype_rawchild(cts, df), dp+df->size, tv, flags);
514
+ else
515
+ lj_cconv_bf_tv(cts, df, dp+df->size, tv);
516
+ if ((d->info & CTF_UNION)) break;
517
+ } else if (ctype_isxattrib(df->info, CTA_SUBTYPE)) {
518
+ cconv_substruct_tab(cts, ctype_rawchild(cts, df),
519
+ dp+df->size, t, ip, flags);
520
+ } /* Ignore all other entries in the chain. */
521
+ }
522
+ }
523
+
524
+ /* Convert table to struct/union. */
525
+ static void cconv_struct_tab(CTState *cts, CType *d,
526
+ uint8_t *dp, GCtab *t, CTInfo flags)
527
+ {
528
+ int32_t i = 0;
529
+ memset(dp, 0, d->size); /* Much simpler to clear the struct first. */
530
+ cconv_substruct_tab(cts, d, dp, t, &i, flags);
531
+ }
532
+
533
+ /* Convert TValue to C type. Caveat: expects to get the raw CType! */
534
+ void lj_cconv_ct_tv(CTState *cts, CType *d,
535
+ uint8_t *dp, TValue *o, CTInfo flags)
536
+ {
537
+ CTypeID sid = CTID_P_VOID;
538
+ CType *s;
539
+ void *tmpptr;
540
+ uint8_t tmpbool, *sp = (uint8_t *)&tmpptr;
541
+ if (LJ_LIKELY(tvisint(o))) {
542
+ sp = (uint8_t *)&o->i;
543
+ sid = CTID_INT32;
544
+ flags |= CCF_FROMTV;
545
+ } else if (LJ_LIKELY(tvisnum(o))) {
546
+ sp = (uint8_t *)&o->n;
547
+ sid = CTID_DOUBLE;
548
+ flags |= CCF_FROMTV;
549
+ } else if (tviscdata(o)) {
550
+ sp = cdataptr(cdataV(o));
551
+ sid = cdataV(o)->ctypeid;
552
+ s = ctype_get(cts, sid);
553
+ if (ctype_isref(s->info)) { /* Resolve reference for value. */
554
+ lua_assert(s->size == CTSIZE_PTR);
555
+ sp = *(void **)sp;
556
+ sid = ctype_cid(s->info);
557
+ }
558
+ s = ctype_raw(cts, sid);
559
+ if (ctype_isfunc(s->info)) {
560
+ sid = lj_ctype_intern(cts, CTINFO(CT_PTR, CTALIGN_PTR|sid), CTSIZE_PTR);
561
+ } else {
562
+ if (ctype_isenum(s->info)) s = ctype_child(cts, s);
563
+ goto doconv;
564
+ }
565
+ } else if (tvisstr(o)) {
566
+ GCstr *str = strV(o);
567
+ if (ctype_isenum(d->info)) { /* Match string against enum constant. */
568
+ CTSize ofs;
569
+ CType *cct = lj_ctype_getfield(cts, d, str, &ofs);
570
+ if (!cct || !ctype_isconstval(cct->info))
571
+ goto err_conv;
572
+ lua_assert(d->size == 4);
573
+ sp = (uint8_t *)&cct->size;
574
+ sid = ctype_cid(cct->info);
575
+ } else if (ctype_isrefarray(d->info)) { /* Copy string to array. */
576
+ CType *dc = ctype_rawchild(cts, d);
577
+ CTSize sz = str->len+1;
578
+ if (!ctype_isinteger(dc->info) || dc->size != 1)
579
+ goto err_conv;
580
+ if (d->size != 0 && d->size < sz)
581
+ sz = d->size;
582
+ memcpy(dp, strdata(str), sz);
583
+ return;
584
+ } else { /* Otherwise pass it as a const char[]. */
585
+ sp = (uint8_t *)strdata(str);
586
+ sid = CTID_A_CCHAR;
587
+ flags |= CCF_FROMTV;
588
+ }
589
+ } else if (tvistab(o)) {
590
+ if (ctype_isarray(d->info)) {
591
+ cconv_array_tab(cts, d, dp, tabV(o), flags);
592
+ return;
593
+ } else if (ctype_isstruct(d->info)) {
594
+ cconv_struct_tab(cts, d, dp, tabV(o), flags);
595
+ return;
596
+ } else {
597
+ goto err_conv;
598
+ }
599
+ } else if (tvisbool(o)) {
600
+ tmpbool = boolV(o);
601
+ sp = &tmpbool;
602
+ sid = CTID_BOOL;
603
+ } else if (tvisnil(o)) {
604
+ tmpptr = (void *)0;
605
+ flags |= CCF_FROMTV;
606
+ } else if (tvisudata(o)) {
607
+ GCudata *ud = udataV(o);
608
+ tmpptr = uddata(ud);
609
+ if (ud->udtype == UDTYPE_IO_FILE)
610
+ tmpptr = *(void **)tmpptr;
611
+ } else if (tvislightud(o)) {
612
+ tmpptr = lightudV(o);
613
+ } else if (tvisfunc(o)) {
614
+ void *p = lj_ccallback_new(cts, d, funcV(o));
615
+ if (p) {
616
+ *(void **)dp = p;
617
+ return;
618
+ }
619
+ goto err_conv;
620
+ } else {
621
+ err_conv:
622
+ cconv_err_convtv(cts, d, o, flags);
623
+ }
624
+ s = ctype_get(cts, sid);
625
+ doconv:
626
+ if (ctype_isenum(d->info)) d = ctype_child(cts, d);
627
+ lj_cconv_ct_ct(cts, d, s, dp, sp, flags);
628
+ }
629
+
630
+ /* Convert TValue to bitfield. */
631
+ void lj_cconv_bf_tv(CTState *cts, CType *d, uint8_t *dp, TValue *o)
632
+ {
633
+ CTInfo info = d->info;
634
+ CTSize pos, bsz;
635
+ uint32_t val, mask;
636
+ lua_assert(ctype_isbitfield(info));
637
+ if ((info & CTF_BOOL)) {
638
+ uint8_t tmpbool;
639
+ lua_assert(ctype_bitbsz(info) == 1);
640
+ lj_cconv_ct_tv(cts, ctype_get(cts, CTID_BOOL), &tmpbool, o, 0);
641
+ val = tmpbool;
642
+ } else {
643
+ CTypeID did = (info & CTF_UNSIGNED) ? CTID_UINT32 : CTID_INT32;
644
+ lj_cconv_ct_tv(cts, ctype_get(cts, did), (uint8_t *)&val, o, 0);
645
+ }
646
+ pos = ctype_bitpos(info);
647
+ bsz = ctype_bitbsz(info);
648
+ lua_assert(pos < 8*ctype_bitcsz(info));
649
+ lua_assert(bsz > 0 && bsz <= 8*ctype_bitcsz(info));
650
+ /* Check if a packed bitfield crosses a container boundary. */
651
+ if (pos + bsz > 8*ctype_bitcsz(info))
652
+ lj_err_caller(cts->L, LJ_ERR_FFI_NYIPACKBIT);
653
+ mask = ((1u << bsz) - 1u) << pos;
654
+ val = (val << pos) & mask;
655
+ /* NYI: packed bitfields may cause misaligned reads/writes. */
656
+ switch (ctype_bitcsz(info)) {
657
+ case 4: *(uint32_t *)dp = (*(uint32_t *)dp & ~mask) | (uint32_t)val; break;
658
+ case 2: *(uint16_t *)dp = (*(uint16_t *)dp & ~mask) | (uint16_t)val; break;
659
+ case 1: *(uint8_t *)dp = (*(uint8_t *)dp & ~mask) | (uint8_t)val; break;
660
+ default: lua_assert(0); break;
661
+ }
662
+ }
663
+
664
+ /* -- Initialize C type with TValues -------------------------------------- */
665
+
666
+ /* Initialize an array with TValues. */
667
+ static void cconv_array_init(CTState *cts, CType *d, CTSize sz, uint8_t *dp,
668
+ TValue *o, MSize len)
669
+ {
670
+ CType *dc = ctype_rawchild(cts, d); /* Array element type. */
671
+ CTSize ofs, esize = dc->size;
672
+ MSize i;
673
+ if (len*esize > sz)
674
+ cconv_err_initov(cts, d);
675
+ for (i = 0, ofs = 0; i < len; i++, ofs += esize)
676
+ lj_cconv_ct_tv(cts, dc, dp + ofs, o + i, 0);
677
+ if (ofs == esize) { /* Replicate a single element. */
678
+ for (; ofs < sz; ofs += esize) memcpy(dp + ofs, dp, esize);
679
+ } else { /* Otherwise fill the remainder with zero. */
680
+ memset(dp + ofs, 0, sz - ofs);
681
+ }
682
+ }
683
+
684
+ /* Initialize a sub-struct/union with TValues. */
685
+ static void cconv_substruct_init(CTState *cts, CType *d, uint8_t *dp,
686
+ TValue *o, MSize len, MSize *ip)
687
+ {
688
+ CTypeID id = d->sib;
689
+ while (id) {
690
+ CType *df = ctype_get(cts, id);
691
+ id = df->sib;
692
+ if (ctype_isfield(df->info) || ctype_isbitfield(df->info)) {
693
+ MSize i = *ip;
694
+ if (!gcref(df->name)) continue; /* Ignore unnamed fields. */
695
+ if (i >= len) break;
696
+ *ip = i + 1;
697
+ if (ctype_isfield(df->info))
698
+ lj_cconv_ct_tv(cts, ctype_rawchild(cts, df), dp+df->size, o + i, 0);
699
+ else
700
+ lj_cconv_bf_tv(cts, df, dp+df->size, o + i);
701
+ if ((d->info & CTF_UNION)) break;
702
+ } else if (ctype_isxattrib(df->info, CTA_SUBTYPE)) {
703
+ cconv_substruct_init(cts, ctype_rawchild(cts, df),
704
+ dp+df->size, o, len, ip);
705
+ if ((d->info & CTF_UNION)) break;
706
+ } /* Ignore all other entries in the chain. */
707
+ }
708
+ }
709
+
710
+ /* Initialize a struct/union with TValues. */
711
+ static void cconv_struct_init(CTState *cts, CType *d, CTSize sz, uint8_t *dp,
712
+ TValue *o, MSize len)
713
+ {
714
+ MSize i = 0;
715
+ memset(dp, 0, sz); /* Much simpler to clear the struct first. */
716
+ cconv_substruct_init(cts, d, dp, o, len, &i);
717
+ if (i < len)
718
+ cconv_err_initov(cts, d);
719
+ }
720
+
721
+ /* Check whether to use a multi-value initializer.
722
+ ** This is true if an aggregate is to be initialized with a value.
723
+ ** Valarrays are treated as values here so ct_tv handles (V|C, I|F).
724
+ */
725
+ int lj_cconv_multi_init(CTState *cts, CType *d, TValue *o)
726
+ {
727
+ if (!(ctype_isrefarray(d->info) || ctype_isstruct(d->info)))
728
+ return 0; /* Destination is not an aggregate. */
729
+ if (tvistab(o) || (tvisstr(o) && !ctype_isstruct(d->info)))
730
+ return 0; /* Initializer is not a value. */
731
+ if (tviscdata(o) && lj_ctype_rawref(cts, cdataV(o)->ctypeid) == d)
732
+ return 0; /* Source and destination are identical aggregates. */
733
+ return 1; /* Otherwise the initializer is a value. */
734
+ }
735
+
736
+ /* Initialize C type with TValues. Caveat: expects to get the raw CType! */
737
+ void lj_cconv_ct_init(CTState *cts, CType *d, CTSize sz,
738
+ uint8_t *dp, TValue *o, MSize len)
739
+ {
740
+ if (len == 0)
741
+ memset(dp, 0, sz);
742
+ else if (len == 1 && !lj_cconv_multi_init(cts, d, o))
743
+ lj_cconv_ct_tv(cts, d, dp, o, 0);
744
+ else if (ctype_isarray(d->info)) /* Also handles valarray init with len>1. */
745
+ cconv_array_init(cts, d, sz, dp, o, len);
746
+ else if (ctype_isstruct(d->info))
747
+ cconv_struct_init(cts, d, sz, dp, o, len);
748
+ else
749
+ cconv_err_initov(cts, d);
750
+ }
751
+
752
+ #endif