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,45 @@
1
+ /*
2
+ ** Trace recorder (bytecode -> SSA IR).
3
+ ** Copyright (C) 2005-2015 Mike Pall. See Copyright Notice in luajit.h
4
+ */
5
+
6
+ #ifndef _LJ_RECORD_H
7
+ #define _LJ_RECORD_H
8
+
9
+ #include "lj_obj.h"
10
+ #include "lj_jit.h"
11
+
12
+ #if LJ_HASJIT
13
+ /* Context for recording an indexed load/store. */
14
+ typedef struct RecordIndex {
15
+ TValue tabv; /* Runtime value of table (or indexed object). */
16
+ TValue keyv; /* Runtime value of key. */
17
+ TValue valv; /* Runtime value of stored value. */
18
+ TValue mobjv; /* Runtime value of metamethod object. */
19
+ GCtab *mtv; /* Runtime value of metatable object. */
20
+ cTValue *oldv; /* Runtime value of previously stored value. */
21
+ TRef tab; /* Table (or indexed object) reference. */
22
+ TRef key; /* Key reference. */
23
+ TRef val; /* Value reference for a store or 0 for a load. */
24
+ TRef mt; /* Metatable reference. */
25
+ TRef mobj; /* Metamethod object reference. */
26
+ int idxchain; /* Index indirections left or 0 for raw lookup. */
27
+ } RecordIndex;
28
+
29
+ LJ_FUNC int lj_record_objcmp(jit_State *J, TRef a, TRef b,
30
+ cTValue *av, cTValue *bv);
31
+ LJ_FUNC void lj_record_stop(jit_State *J, TraceLink linktype, TraceNo lnk);
32
+ LJ_FUNC TRef lj_record_constify(jit_State *J, cTValue *o);
33
+
34
+ LJ_FUNC void lj_record_call(jit_State *J, BCReg func, ptrdiff_t nargs);
35
+ LJ_FUNC void lj_record_tailcall(jit_State *J, BCReg func, ptrdiff_t nargs);
36
+ LJ_FUNC void lj_record_ret(jit_State *J, BCReg rbase, ptrdiff_t gotresults);
37
+
38
+ LJ_FUNC int lj_record_mm_lookup(jit_State *J, RecordIndex *ix, MMS mm);
39
+ LJ_FUNC TRef lj_record_idx(jit_State *J, RecordIndex *ix);
40
+
41
+ LJ_FUNC void lj_record_ins(jit_State *J);
42
+ LJ_FUNC void lj_record_setup(jit_State *J);
43
+ #endif
44
+
45
+ #endif
@@ -0,0 +1,870 @@
1
+ /*
2
+ ** Snapshot handling.
3
+ ** Copyright (C) 2005-2015 Mike Pall. See Copyright Notice in luajit.h
4
+ */
5
+
6
+ #define lj_snap_c
7
+ #define LUA_CORE
8
+
9
+ #include "lj_obj.h"
10
+
11
+ #if LJ_HASJIT
12
+
13
+ #include "lj_gc.h"
14
+ #include "lj_tab.h"
15
+ #include "lj_state.h"
16
+ #include "lj_frame.h"
17
+ #include "lj_bc.h"
18
+ #include "lj_ir.h"
19
+ #include "lj_jit.h"
20
+ #include "lj_iropt.h"
21
+ #include "lj_trace.h"
22
+ #include "lj_snap.h"
23
+ #include "lj_target.h"
24
+ #if LJ_HASFFI
25
+ #include "lj_ctype.h"
26
+ #include "lj_cdata.h"
27
+ #endif
28
+
29
+ /* Some local macros to save typing. Undef'd at the end. */
30
+ #define IR(ref) (&J->cur.ir[(ref)])
31
+
32
+ /* Pass IR on to next optimization in chain (FOLD). */
33
+ #define emitir(ot, a, b) (lj_ir_set(J, (ot), (a), (b)), lj_opt_fold(J))
34
+
35
+ /* Emit raw IR without passing through optimizations. */
36
+ #define emitir_raw(ot, a, b) (lj_ir_set(J, (ot), (a), (b)), lj_ir_emit(J))
37
+
38
+ /* -- Snapshot buffer allocation ------------------------------------------ */
39
+
40
+ /* Grow snapshot buffer. */
41
+ void lj_snap_grow_buf_(jit_State *J, MSize need)
42
+ {
43
+ MSize maxsnap = (MSize)J->param[JIT_P_maxsnap];
44
+ if (need > maxsnap)
45
+ lj_trace_err(J, LJ_TRERR_SNAPOV);
46
+ lj_mem_growvec(J->L, J->snapbuf, J->sizesnap, maxsnap, SnapShot);
47
+ J->cur.snap = J->snapbuf;
48
+ }
49
+
50
+ /* Grow snapshot map buffer. */
51
+ void lj_snap_grow_map_(jit_State *J, MSize need)
52
+ {
53
+ if (need < 2*J->sizesnapmap)
54
+ need = 2*J->sizesnapmap;
55
+ else if (need < 64)
56
+ need = 64;
57
+ J->snapmapbuf = (SnapEntry *)lj_mem_realloc(J->L, J->snapmapbuf,
58
+ J->sizesnapmap*sizeof(SnapEntry), need*sizeof(SnapEntry));
59
+ J->cur.snapmap = J->snapmapbuf;
60
+ J->sizesnapmap = need;
61
+ }
62
+
63
+ /* -- Snapshot generation ------------------------------------------------- */
64
+
65
+ /* Add all modified slots to the snapshot. */
66
+ static MSize snapshot_slots(jit_State *J, SnapEntry *map, BCReg nslots)
67
+ {
68
+ IRRef retf = J->chain[IR_RETF]; /* Limits SLOAD restore elimination. */
69
+ BCReg s;
70
+ MSize n = 0;
71
+ for (s = 0; s < nslots; s++) {
72
+ TRef tr = J->slot[s];
73
+ IRRef ref = tref_ref(tr);
74
+ if (ref) {
75
+ SnapEntry sn = SNAP_TR(s, tr);
76
+ IRIns *ir = IR(ref);
77
+ if (!(sn & (SNAP_CONT|SNAP_FRAME)) &&
78
+ ir->o == IR_SLOAD && ir->op1 == s && ref > retf) {
79
+ /* No need to snapshot unmodified non-inherited slots. */
80
+ if (!(ir->op2 & IRSLOAD_INHERIT))
81
+ continue;
82
+ /* No need to restore readonly slots and unmodified non-parent slots. */
83
+ if (!(LJ_DUALNUM && (ir->op2 & IRSLOAD_CONVERT)) &&
84
+ (ir->op2 & (IRSLOAD_READONLY|IRSLOAD_PARENT)) != IRSLOAD_PARENT)
85
+ sn |= SNAP_NORESTORE;
86
+ }
87
+ if (LJ_SOFTFP && irt_isnum(ir->t))
88
+ sn |= SNAP_SOFTFPNUM;
89
+ map[n++] = sn;
90
+ }
91
+ }
92
+ return n;
93
+ }
94
+
95
+ /* Add frame links at the end of the snapshot. */
96
+ static BCReg snapshot_framelinks(jit_State *J, SnapEntry *map)
97
+ {
98
+ cTValue *frame = J->L->base - 1;
99
+ cTValue *lim = J->L->base - J->baseslot;
100
+ GCfunc *fn = frame_func(frame);
101
+ cTValue *ftop = isluafunc(fn) ? (frame+funcproto(fn)->framesize) : J->L->top;
102
+ MSize f = 0;
103
+ lua_assert(!LJ_FR2); /* TODO_FR2: store 64 bit PCs. */
104
+ map[f++] = SNAP_MKPC(J->pc); /* The current PC is always the first entry. */
105
+ while (frame > lim) { /* Backwards traversal of all frames above base. */
106
+ if (frame_islua(frame)) {
107
+ map[f++] = SNAP_MKPC(frame_pc(frame));
108
+ frame = frame_prevl(frame);
109
+ } else if (frame_iscont(frame)) {
110
+ map[f++] = SNAP_MKFTSZ(frame_ftsz(frame));
111
+ map[f++] = SNAP_MKPC(frame_contpc(frame));
112
+ frame = frame_prevd(frame);
113
+ } else {
114
+ lua_assert(!frame_isc(frame));
115
+ map[f++] = SNAP_MKFTSZ(frame_ftsz(frame));
116
+ frame = frame_prevd(frame);
117
+ continue;
118
+ }
119
+ if (frame + funcproto(frame_func(frame))->framesize > ftop)
120
+ ftop = frame + funcproto(frame_func(frame))->framesize;
121
+ }
122
+ lua_assert(f == (MSize)(1 + J->framedepth));
123
+ return (BCReg)(ftop - lim);
124
+ }
125
+
126
+ /* Take a snapshot of the current stack. */
127
+ static void snapshot_stack(jit_State *J, SnapShot *snap, MSize nsnapmap)
128
+ {
129
+ BCReg nslots = J->baseslot + J->maxslot;
130
+ MSize nent;
131
+ SnapEntry *p;
132
+ /* Conservative estimate. */
133
+ lj_snap_grow_map(J, nsnapmap + nslots + (MSize)J->framedepth+1);
134
+ p = &J->cur.snapmap[nsnapmap];
135
+ nent = snapshot_slots(J, p, nslots);
136
+ snap->topslot = (uint8_t)snapshot_framelinks(J, p + nent);
137
+ snap->mapofs = (uint16_t)nsnapmap;
138
+ snap->ref = (IRRef1)J->cur.nins;
139
+ snap->nent = (uint8_t)nent;
140
+ snap->nslots = (uint8_t)nslots;
141
+ snap->count = 0;
142
+ J->cur.nsnapmap = (uint16_t)(nsnapmap + nent + 1 + J->framedepth);
143
+ }
144
+
145
+ /* Add or merge a snapshot. */
146
+ void lj_snap_add(jit_State *J)
147
+ {
148
+ MSize nsnap = J->cur.nsnap;
149
+ MSize nsnapmap = J->cur.nsnapmap;
150
+ /* Merge if no ins. inbetween or if requested and no guard inbetween. */
151
+ if (J->mergesnap ? !irt_isguard(J->guardemit) :
152
+ (nsnap > 0 && J->cur.snap[nsnap-1].ref == J->cur.nins)) {
153
+ if (nsnap == 1) { /* But preserve snap #0 PC. */
154
+ emitir_raw(IRT(IR_NOP, IRT_NIL), 0, 0);
155
+ goto nomerge;
156
+ }
157
+ nsnapmap = J->cur.snap[--nsnap].mapofs;
158
+ } else {
159
+ nomerge:
160
+ lj_snap_grow_buf(J, nsnap+1);
161
+ J->cur.nsnap = (uint16_t)(nsnap+1);
162
+ }
163
+ J->mergesnap = 0;
164
+ J->guardemit.irt = 0;
165
+ snapshot_stack(J, &J->cur.snap[nsnap], nsnapmap);
166
+ }
167
+
168
+ /* -- Snapshot modification ----------------------------------------------- */
169
+
170
+ #define SNAP_USEDEF_SLOTS (LJ_MAX_JSLOTS+LJ_STACK_EXTRA)
171
+
172
+ /* Find unused slots with reaching-definitions bytecode data-flow analysis. */
173
+ static BCReg snap_usedef(jit_State *J, uint8_t *udf,
174
+ const BCIns *pc, BCReg maxslot)
175
+ {
176
+ BCReg s;
177
+ GCobj *o;
178
+
179
+ if (maxslot == 0) return 0;
180
+ #ifdef LUAJIT_USE_VALGRIND
181
+ /* Avoid errors for harmless reads beyond maxslot. */
182
+ memset(udf, 1, SNAP_USEDEF_SLOTS);
183
+ #else
184
+ memset(udf, 1, maxslot);
185
+ #endif
186
+
187
+ /* Treat open upvalues as used. */
188
+ o = gcref(J->L->openupval);
189
+ while (o) {
190
+ if (uvval(gco2uv(o)) < J->L->base) break;
191
+ udf[uvval(gco2uv(o)) - J->L->base] = 0;
192
+ o = gcref(o->gch.nextgc);
193
+ }
194
+
195
+ #define USE_SLOT(s) udf[(s)] &= ~1
196
+ #define DEF_SLOT(s) udf[(s)] *= 3
197
+
198
+ /* Scan through following bytecode and check for uses/defs. */
199
+ lua_assert(pc >= proto_bc(J->pt) && pc < proto_bc(J->pt) + J->pt->sizebc);
200
+ for (;;) {
201
+ BCIns ins = *pc++;
202
+ BCOp op = bc_op(ins);
203
+ switch (bcmode_b(op)) {
204
+ case BCMvar: USE_SLOT(bc_b(ins)); break;
205
+ default: break;
206
+ }
207
+ switch (bcmode_c(op)) {
208
+ case BCMvar: USE_SLOT(bc_c(ins)); break;
209
+ case BCMrbase:
210
+ lua_assert(op == BC_CAT);
211
+ for (s = bc_b(ins); s <= bc_c(ins); s++) USE_SLOT(s);
212
+ for (; s < maxslot; s++) DEF_SLOT(s);
213
+ break;
214
+ case BCMjump:
215
+ handle_jump: {
216
+ BCReg minslot = bc_a(ins);
217
+ if (op >= BC_FORI && op <= BC_JFORL) minslot += FORL_EXT;
218
+ else if (op >= BC_ITERL && op <= BC_JITERL) minslot += bc_b(pc[-2])-1;
219
+ else if (op == BC_UCLO) { pc += bc_j(ins); break; }
220
+ for (s = minslot; s < maxslot; s++) DEF_SLOT(s);
221
+ return minslot < maxslot ? minslot : maxslot;
222
+ }
223
+ case BCMlit:
224
+ if (op == BC_JFORL || op == BC_JITERL || op == BC_JLOOP) {
225
+ goto handle_jump;
226
+ } else if (bc_isret(op)) {
227
+ BCReg top = op == BC_RETM ? maxslot : (bc_a(ins) + bc_d(ins)-1);
228
+ for (s = 0; s < bc_a(ins); s++) DEF_SLOT(s);
229
+ for (; s < top; s++) USE_SLOT(s);
230
+ for (; s < maxslot; s++) DEF_SLOT(s);
231
+ return 0;
232
+ }
233
+ break;
234
+ case BCMfunc: return maxslot; /* NYI: will abort, anyway. */
235
+ default: break;
236
+ }
237
+ switch (bcmode_a(op)) {
238
+ case BCMvar: USE_SLOT(bc_a(ins)); break;
239
+ case BCMdst:
240
+ if (!(op == BC_ISTC || op == BC_ISFC)) DEF_SLOT(bc_a(ins));
241
+ break;
242
+ case BCMbase:
243
+ if (op >= BC_CALLM && op <= BC_VARG) {
244
+ BCReg top = (op == BC_CALLM || op == BC_CALLMT || bc_c(ins) == 0) ?
245
+ maxslot : (bc_a(ins) + bc_c(ins)+LJ_FR2);
246
+ if (LJ_FR2) DEF_SLOT(bc_a(ins)+1);
247
+ s = bc_a(ins) - ((op == BC_ITERC || op == BC_ITERN) ? 3 : 0);
248
+ for (; s < top; s++) USE_SLOT(s);
249
+ for (; s < maxslot; s++) DEF_SLOT(s);
250
+ if (op == BC_CALLT || op == BC_CALLMT) {
251
+ for (s = 0; s < bc_a(ins); s++) DEF_SLOT(s);
252
+ return 0;
253
+ }
254
+ } else if (op == BC_KNIL) {
255
+ for (s = bc_a(ins); s <= bc_d(ins); s++) DEF_SLOT(s);
256
+ } else if (op == BC_TSETM) {
257
+ for (s = bc_a(ins)-1; s < maxslot; s++) USE_SLOT(s);
258
+ }
259
+ break;
260
+ default: break;
261
+ }
262
+ lua_assert(pc >= proto_bc(J->pt) && pc < proto_bc(J->pt) + J->pt->sizebc);
263
+ }
264
+
265
+ #undef USE_SLOT
266
+ #undef DEF_SLOT
267
+
268
+ return 0; /* unreachable */
269
+ }
270
+
271
+ /* Purge dead slots before the next snapshot. */
272
+ void lj_snap_purge(jit_State *J)
273
+ {
274
+ uint8_t udf[SNAP_USEDEF_SLOTS];
275
+ BCReg maxslot = J->maxslot;
276
+ BCReg s = snap_usedef(J, udf, J->pc, maxslot);
277
+ for (; s < maxslot; s++)
278
+ if (udf[s] != 0)
279
+ J->base[s] = 0; /* Purge dead slots. */
280
+ }
281
+
282
+ /* Shrink last snapshot. */
283
+ void lj_snap_shrink(jit_State *J)
284
+ {
285
+ SnapShot *snap = &J->cur.snap[J->cur.nsnap-1];
286
+ SnapEntry *map = &J->cur.snapmap[snap->mapofs];
287
+ MSize n, m, nlim, nent = snap->nent;
288
+ uint8_t udf[SNAP_USEDEF_SLOTS];
289
+ BCReg maxslot = J->maxslot;
290
+ BCReg minslot = snap_usedef(J, udf, snap_pc(map[nent]), maxslot);
291
+ BCReg baseslot = J->baseslot;
292
+ maxslot += baseslot;
293
+ minslot += baseslot;
294
+ snap->nslots = (uint8_t)maxslot;
295
+ for (n = m = 0; n < nent; n++) { /* Remove unused slots from snapshot. */
296
+ BCReg s = snap_slot(map[n]);
297
+ if (s < minslot || (s < maxslot && udf[s-baseslot] == 0))
298
+ map[m++] = map[n]; /* Only copy used slots. */
299
+ }
300
+ snap->nent = (uint8_t)m;
301
+ nlim = J->cur.nsnapmap - snap->mapofs - 1;
302
+ while (n <= nlim) map[m++] = map[n++]; /* Move PC + frame links down. */
303
+ J->cur.nsnapmap = (uint16_t)(snap->mapofs + m); /* Free up space in map. */
304
+ }
305
+
306
+ /* -- Snapshot access ----------------------------------------------------- */
307
+
308
+ /* Initialize a Bloom Filter with all renamed refs.
309
+ ** There are very few renames (often none), so the filter has
310
+ ** very few bits set. This makes it suitable for negative filtering.
311
+ */
312
+ static BloomFilter snap_renamefilter(GCtrace *T, SnapNo lim)
313
+ {
314
+ BloomFilter rfilt = 0;
315
+ IRIns *ir;
316
+ for (ir = &T->ir[T->nins-1]; ir->o == IR_RENAME; ir--)
317
+ if (ir->op2 <= lim)
318
+ bloomset(rfilt, ir->op1);
319
+ return rfilt;
320
+ }
321
+
322
+ /* Process matching renames to find the original RegSP. */
323
+ static RegSP snap_renameref(GCtrace *T, SnapNo lim, IRRef ref, RegSP rs)
324
+ {
325
+ IRIns *ir;
326
+ for (ir = &T->ir[T->nins-1]; ir->o == IR_RENAME; ir--)
327
+ if (ir->op1 == ref && ir->op2 <= lim)
328
+ rs = ir->prev;
329
+ return rs;
330
+ }
331
+
332
+ /* Copy RegSP from parent snapshot to the parent links of the IR. */
333
+ IRIns *lj_snap_regspmap(GCtrace *T, SnapNo snapno, IRIns *ir)
334
+ {
335
+ SnapShot *snap = &T->snap[snapno];
336
+ SnapEntry *map = &T->snapmap[snap->mapofs];
337
+ BloomFilter rfilt = snap_renamefilter(T, snapno);
338
+ MSize n = 0;
339
+ IRRef ref = 0;
340
+ for ( ; ; ir++) {
341
+ uint32_t rs;
342
+ if (ir->o == IR_SLOAD) {
343
+ if (!(ir->op2 & IRSLOAD_PARENT)) break;
344
+ for ( ; ; n++) {
345
+ lua_assert(n < snap->nent);
346
+ if (snap_slot(map[n]) == ir->op1) {
347
+ ref = snap_ref(map[n++]);
348
+ break;
349
+ }
350
+ }
351
+ } else if (LJ_SOFTFP && ir->o == IR_HIOP) {
352
+ ref++;
353
+ } else if (ir->o == IR_PVAL) {
354
+ ref = ir->op1 + REF_BIAS;
355
+ } else {
356
+ break;
357
+ }
358
+ rs = T->ir[ref].prev;
359
+ if (bloomtest(rfilt, ref))
360
+ rs = snap_renameref(T, snapno, ref, rs);
361
+ ir->prev = (uint16_t)rs;
362
+ lua_assert(regsp_used(rs));
363
+ }
364
+ return ir;
365
+ }
366
+
367
+ /* -- Snapshot replay ----------------------------------------------------- */
368
+
369
+ /* Replay constant from parent trace. */
370
+ static TRef snap_replay_const(jit_State *J, IRIns *ir)
371
+ {
372
+ /* Only have to deal with constants that can occur in stack slots. */
373
+ switch ((IROp)ir->o) {
374
+ case IR_KPRI: return TREF_PRI(irt_type(ir->t));
375
+ case IR_KINT: return lj_ir_kint(J, ir->i);
376
+ case IR_KGC: return lj_ir_kgc(J, ir_kgc(ir), irt_t(ir->t));
377
+ case IR_KNUM: return lj_ir_k64(J, IR_KNUM, ir_knum(ir));
378
+ case IR_KINT64: return lj_ir_k64(J, IR_KINT64, ir_kint64(ir));
379
+ case IR_KPTR: return lj_ir_kptr(J, ir_kptr(ir)); /* Continuation. */
380
+ default: lua_assert(0); return TREF_NIL; break;
381
+ }
382
+ }
383
+
384
+ /* De-duplicate parent reference. */
385
+ static TRef snap_dedup(jit_State *J, SnapEntry *map, MSize nmax, IRRef ref)
386
+ {
387
+ MSize j;
388
+ for (j = 0; j < nmax; j++)
389
+ if (snap_ref(map[j]) == ref)
390
+ return J->slot[snap_slot(map[j])] & ~(SNAP_CONT|SNAP_FRAME);
391
+ return 0;
392
+ }
393
+
394
+ /* Emit parent reference with de-duplication. */
395
+ static TRef snap_pref(jit_State *J, GCtrace *T, SnapEntry *map, MSize nmax,
396
+ BloomFilter seen, IRRef ref)
397
+ {
398
+ IRIns *ir = &T->ir[ref];
399
+ TRef tr;
400
+ if (irref_isk(ref))
401
+ tr = snap_replay_const(J, ir);
402
+ else if (!regsp_used(ir->prev))
403
+ tr = 0;
404
+ else if (!bloomtest(seen, ref) || (tr = snap_dedup(J, map, nmax, ref)) == 0)
405
+ tr = emitir(IRT(IR_PVAL, irt_type(ir->t)), ref - REF_BIAS, 0);
406
+ return tr;
407
+ }
408
+
409
+ /* Check whether a sunk store corresponds to an allocation. Slow path. */
410
+ static int snap_sunk_store2(jit_State *J, IRIns *ira, IRIns *irs)
411
+ {
412
+ if (irs->o == IR_ASTORE || irs->o == IR_HSTORE ||
413
+ irs->o == IR_FSTORE || irs->o == IR_XSTORE) {
414
+ IRIns *irk = IR(irs->op1);
415
+ if (irk->o == IR_AREF || irk->o == IR_HREFK)
416
+ irk = IR(irk->op1);
417
+ return (IR(irk->op1) == ira);
418
+ }
419
+ return 0;
420
+ }
421
+
422
+ /* Check whether a sunk store corresponds to an allocation. Fast path. */
423
+ static LJ_AINLINE int snap_sunk_store(jit_State *J, IRIns *ira, IRIns *irs)
424
+ {
425
+ if (irs->s != 255)
426
+ return (ira + irs->s == irs); /* Fast check. */
427
+ return snap_sunk_store2(J, ira, irs);
428
+ }
429
+
430
+ /* Replay snapshot state to setup side trace. */
431
+ void lj_snap_replay(jit_State *J, GCtrace *T)
432
+ {
433
+ SnapShot *snap = &T->snap[J->exitno];
434
+ SnapEntry *map = &T->snapmap[snap->mapofs];
435
+ MSize n, nent = snap->nent;
436
+ BloomFilter seen = 0;
437
+ int pass23 = 0;
438
+ J->framedepth = 0;
439
+ /* Emit IR for slots inherited from parent snapshot. */
440
+ for (n = 0; n < nent; n++) {
441
+ SnapEntry sn = map[n];
442
+ BCReg s = snap_slot(sn);
443
+ IRRef ref = snap_ref(sn);
444
+ IRIns *ir = &T->ir[ref];
445
+ TRef tr;
446
+ /* The bloom filter avoids O(nent^2) overhead for de-duping slots. */
447
+ if (bloomtest(seen, ref) && (tr = snap_dedup(J, map, n, ref)) != 0)
448
+ goto setslot;
449
+ bloomset(seen, ref);
450
+ if (irref_isk(ref)) {
451
+ tr = snap_replay_const(J, ir);
452
+ } else if (!regsp_used(ir->prev)) {
453
+ pass23 = 1;
454
+ lua_assert(s != 0);
455
+ tr = s;
456
+ } else {
457
+ IRType t = irt_type(ir->t);
458
+ uint32_t mode = IRSLOAD_INHERIT|IRSLOAD_PARENT;
459
+ if (LJ_SOFTFP && (sn & SNAP_SOFTFPNUM)) t = IRT_NUM;
460
+ if (ir->o == IR_SLOAD) mode |= (ir->op2 & IRSLOAD_READONLY);
461
+ tr = emitir_raw(IRT(IR_SLOAD, t), s, mode);
462
+ }
463
+ setslot:
464
+ J->slot[s] = tr | (sn&(SNAP_CONT|SNAP_FRAME)); /* Same as TREF_* flags. */
465
+ J->framedepth += ((sn & (SNAP_CONT|SNAP_FRAME)) && s);
466
+ if ((sn & SNAP_FRAME))
467
+ J->baseslot = s+1;
468
+ }
469
+ if (pass23) {
470
+ IRIns *irlast = &T->ir[snap->ref];
471
+ pass23 = 0;
472
+ /* Emit dependent PVALs. */
473
+ for (n = 0; n < nent; n++) {
474
+ SnapEntry sn = map[n];
475
+ IRRef refp = snap_ref(sn);
476
+ IRIns *ir = &T->ir[refp];
477
+ if (regsp_reg(ir->r) == RID_SUNK) {
478
+ if (J->slot[snap_slot(sn)] != snap_slot(sn)) continue;
479
+ pass23 = 1;
480
+ lua_assert(ir->o == IR_TNEW || ir->o == IR_TDUP ||
481
+ ir->o == IR_CNEW || ir->o == IR_CNEWI);
482
+ if (ir->op1 >= T->nk) snap_pref(J, T, map, nent, seen, ir->op1);
483
+ if (ir->op2 >= T->nk) snap_pref(J, T, map, nent, seen, ir->op2);
484
+ if (LJ_HASFFI && ir->o == IR_CNEWI) {
485
+ if (LJ_32 && refp+1 < T->nins && (ir+1)->o == IR_HIOP)
486
+ snap_pref(J, T, map, nent, seen, (ir+1)->op2);
487
+ } else {
488
+ IRIns *irs;
489
+ for (irs = ir+1; irs < irlast; irs++)
490
+ if (irs->r == RID_SINK && snap_sunk_store(J, ir, irs)) {
491
+ if (snap_pref(J, T, map, nent, seen, irs->op2) == 0)
492
+ snap_pref(J, T, map, nent, seen, T->ir[irs->op2].op1);
493
+ else if ((LJ_SOFTFP || (LJ_32 && LJ_HASFFI)) &&
494
+ irs+1 < irlast && (irs+1)->o == IR_HIOP)
495
+ snap_pref(J, T, map, nent, seen, (irs+1)->op2);
496
+ }
497
+ }
498
+ } else if (!irref_isk(refp) && !regsp_used(ir->prev)) {
499
+ lua_assert(ir->o == IR_CONV && ir->op2 == IRCONV_NUM_INT);
500
+ J->slot[snap_slot(sn)] = snap_pref(J, T, map, nent, seen, ir->op1);
501
+ }
502
+ }
503
+ /* Replay sunk instructions. */
504
+ for (n = 0; pass23 && n < nent; n++) {
505
+ SnapEntry sn = map[n];
506
+ IRRef refp = snap_ref(sn);
507
+ IRIns *ir = &T->ir[refp];
508
+ if (regsp_reg(ir->r) == RID_SUNK) {
509
+ TRef op1, op2;
510
+ if (J->slot[snap_slot(sn)] != snap_slot(sn)) { /* De-dup allocs. */
511
+ J->slot[snap_slot(sn)] = J->slot[J->slot[snap_slot(sn)]];
512
+ continue;
513
+ }
514
+ op1 = ir->op1;
515
+ if (op1 >= T->nk) op1 = snap_pref(J, T, map, nent, seen, op1);
516
+ op2 = ir->op2;
517
+ if (op2 >= T->nk) op2 = snap_pref(J, T, map, nent, seen, op2);
518
+ if (LJ_HASFFI && ir->o == IR_CNEWI) {
519
+ if (LJ_32 && refp+1 < T->nins && (ir+1)->o == IR_HIOP) {
520
+ lj_needsplit(J); /* Emit joining HIOP. */
521
+ op2 = emitir_raw(IRT(IR_HIOP, IRT_I64), op2,
522
+ snap_pref(J, T, map, nent, seen, (ir+1)->op2));
523
+ }
524
+ J->slot[snap_slot(sn)] = emitir(ir->ot, op1, op2);
525
+ } else {
526
+ IRIns *irs;
527
+ TRef tr = emitir(ir->ot, op1, op2);
528
+ J->slot[snap_slot(sn)] = tr;
529
+ for (irs = ir+1; irs < irlast; irs++)
530
+ if (irs->r == RID_SINK && snap_sunk_store(J, ir, irs)) {
531
+ IRIns *irr = &T->ir[irs->op1];
532
+ TRef val, key = irr->op2, tmp = tr;
533
+ if (irr->o != IR_FREF) {
534
+ IRIns *irk = &T->ir[key];
535
+ if (irr->o == IR_HREFK)
536
+ key = lj_ir_kslot(J, snap_replay_const(J, &T->ir[irk->op1]),
537
+ irk->op2);
538
+ else
539
+ key = snap_replay_const(J, irk);
540
+ if (irr->o == IR_HREFK || irr->o == IR_AREF) {
541
+ IRIns *irf = &T->ir[irr->op1];
542
+ tmp = emitir(irf->ot, tmp, irf->op2);
543
+ }
544
+ }
545
+ tmp = emitir(irr->ot, tmp, key);
546
+ val = snap_pref(J, T, map, nent, seen, irs->op2);
547
+ if (val == 0) {
548
+ IRIns *irc = &T->ir[irs->op2];
549
+ lua_assert(irc->o == IR_CONV && irc->op2 == IRCONV_NUM_INT);
550
+ val = snap_pref(J, T, map, nent, seen, irc->op1);
551
+ val = emitir(IRTN(IR_CONV), val, IRCONV_NUM_INT);
552
+ } else if ((LJ_SOFTFP || (LJ_32 && LJ_HASFFI)) &&
553
+ irs+1 < irlast && (irs+1)->o == IR_HIOP) {
554
+ IRType t = IRT_I64;
555
+ if (LJ_SOFTFP && irt_type((irs+1)->t) == IRT_SOFTFP)
556
+ t = IRT_NUM;
557
+ lj_needsplit(J);
558
+ if (irref_isk(irs->op2) && irref_isk((irs+1)->op2)) {
559
+ uint64_t k = (uint32_t)T->ir[irs->op2].i +
560
+ ((uint64_t)T->ir[(irs+1)->op2].i << 32);
561
+ val = lj_ir_k64(J, t == IRT_I64 ? IR_KINT64 : IR_KNUM,
562
+ lj_ir_k64_find(J, k));
563
+ } else {
564
+ val = emitir_raw(IRT(IR_HIOP, t), val,
565
+ snap_pref(J, T, map, nent, seen, (irs+1)->op2));
566
+ }
567
+ tmp = emitir(IRT(irs->o, t), tmp, val);
568
+ continue;
569
+ }
570
+ tmp = emitir(irs->ot, tmp, val);
571
+ } else if (LJ_HASFFI && irs->o == IR_XBAR && ir->o == IR_CNEW) {
572
+ emitir(IRT(IR_XBAR, IRT_NIL), 0, 0);
573
+ }
574
+ }
575
+ }
576
+ }
577
+ }
578
+ J->base = J->slot + J->baseslot;
579
+ J->maxslot = snap->nslots - J->baseslot;
580
+ lj_snap_add(J);
581
+ if (pass23) /* Need explicit GC step _after_ initial snapshot. */
582
+ emitir_raw(IRTG(IR_GCSTEP, IRT_NIL), 0, 0);
583
+ }
584
+
585
+ /* -- Snapshot restore ---------------------------------------------------- */
586
+
587
+ static void snap_unsink(jit_State *J, GCtrace *T, ExitState *ex,
588
+ SnapNo snapno, BloomFilter rfilt,
589
+ IRIns *ir, TValue *o);
590
+
591
+ /* Restore a value from the trace exit state. */
592
+ static void snap_restoreval(jit_State *J, GCtrace *T, ExitState *ex,
593
+ SnapNo snapno, BloomFilter rfilt,
594
+ IRRef ref, TValue *o)
595
+ {
596
+ IRIns *ir = &T->ir[ref];
597
+ IRType1 t = ir->t;
598
+ RegSP rs = ir->prev;
599
+ if (irref_isk(ref)) { /* Restore constant slot. */
600
+ lj_ir_kvalue(J->L, o, ir);
601
+ return;
602
+ }
603
+ if (LJ_UNLIKELY(bloomtest(rfilt, ref)))
604
+ rs = snap_renameref(T, snapno, ref, rs);
605
+ lua_assert(!LJ_GC64); /* TODO_GC64: handle 64 bit references. */
606
+ if (ra_hasspill(regsp_spill(rs))) { /* Restore from spill slot. */
607
+ int32_t *sps = &ex->spill[regsp_spill(rs)];
608
+ if (irt_isinteger(t)) {
609
+ setintV(o, *sps);
610
+ #if !LJ_SOFTFP
611
+ } else if (irt_isnum(t)) {
612
+ o->u64 = *(uint64_t *)sps;
613
+ #endif
614
+ } else if (LJ_64 && irt_islightud(t)) {
615
+ /* 64 bit lightuserdata which may escape already has the tag bits. */
616
+ o->u64 = *(uint64_t *)sps;
617
+ } else {
618
+ lua_assert(!irt_ispri(t)); /* PRI refs never have a spill slot. */
619
+ setgcV(J->L, o, (GCobj *)(uintptr_t)*(GCSize *)sps, irt_toitype(t));
620
+ }
621
+ } else { /* Restore from register. */
622
+ Reg r = regsp_reg(rs);
623
+ if (ra_noreg(r)) {
624
+ lua_assert(ir->o == IR_CONV && ir->op2 == IRCONV_NUM_INT);
625
+ snap_restoreval(J, T, ex, snapno, rfilt, ir->op1, o);
626
+ if (LJ_DUALNUM) setnumV(o, (lua_Number)intV(o));
627
+ return;
628
+ } else if (irt_isinteger(t)) {
629
+ setintV(o, (int32_t)ex->gpr[r-RID_MIN_GPR]);
630
+ #if !LJ_SOFTFP
631
+ } else if (irt_isnum(t)) {
632
+ setnumV(o, ex->fpr[r-RID_MIN_FPR]);
633
+ #endif
634
+ } else if (LJ_64 && irt_islightud(t)) {
635
+ /* 64 bit lightuserdata which may escape already has the tag bits. */
636
+ o->u64 = ex->gpr[r-RID_MIN_GPR];
637
+ } else if (irt_ispri(t)) {
638
+ setpriV(o, irt_toitype(t));
639
+ } else {
640
+ setgcV(J->L, o, (GCobj *)ex->gpr[r-RID_MIN_GPR], irt_toitype(t));
641
+ }
642
+ }
643
+ }
644
+
645
+ #if LJ_HASFFI
646
+ /* Restore raw data from the trace exit state. */
647
+ static void snap_restoredata(GCtrace *T, ExitState *ex,
648
+ SnapNo snapno, BloomFilter rfilt,
649
+ IRRef ref, void *dst, CTSize sz)
650
+ {
651
+ IRIns *ir = &T->ir[ref];
652
+ RegSP rs = ir->prev;
653
+ int32_t *src;
654
+ uint64_t tmp;
655
+ if (irref_isk(ref)) {
656
+ if (ir->o == IR_KNUM || ir->o == IR_KINT64) {
657
+ src = mref(ir->ptr, int32_t);
658
+ } else if (sz == 8) {
659
+ tmp = (uint64_t)(uint32_t)ir->i;
660
+ src = (int32_t *)&tmp;
661
+ } else {
662
+ src = &ir->i;
663
+ }
664
+ } else {
665
+ if (LJ_UNLIKELY(bloomtest(rfilt, ref)))
666
+ rs = snap_renameref(T, snapno, ref, rs);
667
+ if (ra_hasspill(regsp_spill(rs))) {
668
+ src = &ex->spill[regsp_spill(rs)];
669
+ if (sz == 8 && !irt_is64(ir->t)) {
670
+ tmp = (uint64_t)(uint32_t)*src;
671
+ src = (int32_t *)&tmp;
672
+ }
673
+ } else {
674
+ Reg r = regsp_reg(rs);
675
+ if (ra_noreg(r)) {
676
+ /* Note: this assumes CNEWI is never used for SOFTFP split numbers. */
677
+ lua_assert(sz == 8 && ir->o == IR_CONV && ir->op2 == IRCONV_NUM_INT);
678
+ snap_restoredata(T, ex, snapno, rfilt, ir->op1, dst, 4);
679
+ *(lua_Number *)dst = (lua_Number)*(int32_t *)dst;
680
+ return;
681
+ }
682
+ src = (int32_t *)&ex->gpr[r-RID_MIN_GPR];
683
+ #if !LJ_SOFTFP
684
+ if (r >= RID_MAX_GPR) {
685
+ src = (int32_t *)&ex->fpr[r-RID_MIN_FPR];
686
+ #if LJ_TARGET_PPC
687
+ if (sz == 4) { /* PPC FPRs are always doubles. */
688
+ *(float *)dst = (float)*(double *)src;
689
+ return;
690
+ }
691
+ #else
692
+ if (LJ_BE && sz == 4) src++;
693
+ #endif
694
+ }
695
+ #endif
696
+ }
697
+ }
698
+ lua_assert(sz == 1 || sz == 2 || sz == 4 || sz == 8);
699
+ if (sz == 4) *(int32_t *)dst = *src;
700
+ else if (sz == 8) *(int64_t *)dst = *(int64_t *)src;
701
+ else if (sz == 1) *(int8_t *)dst = (int8_t)*src;
702
+ else *(int16_t *)dst = (int16_t)*src;
703
+ }
704
+ #endif
705
+
706
+ /* Unsink allocation from the trace exit state. Unsink sunk stores. */
707
+ static void snap_unsink(jit_State *J, GCtrace *T, ExitState *ex,
708
+ SnapNo snapno, BloomFilter rfilt,
709
+ IRIns *ir, TValue *o)
710
+ {
711
+ lua_assert(ir->o == IR_TNEW || ir->o == IR_TDUP ||
712
+ ir->o == IR_CNEW || ir->o == IR_CNEWI);
713
+ #if LJ_HASFFI
714
+ if (ir->o == IR_CNEW || ir->o == IR_CNEWI) {
715
+ CTState *cts = ctype_cts(J->L);
716
+ CTypeID id = (CTypeID)T->ir[ir->op1].i;
717
+ CTSize sz = lj_ctype_size(cts, id);
718
+ GCcdata *cd = lj_cdata_new(cts, id, sz);
719
+ setcdataV(J->L, o, cd);
720
+ if (ir->o == IR_CNEWI) {
721
+ uint8_t *p = (uint8_t *)cdataptr(cd);
722
+ lua_assert(sz == 4 || sz == 8);
723
+ if (LJ_32 && sz == 8 && ir+1 < T->ir + T->nins && (ir+1)->o == IR_HIOP) {
724
+ snap_restoredata(T, ex, snapno, rfilt, (ir+1)->op2, LJ_LE?p+4:p, 4);
725
+ if (LJ_BE) p += 4;
726
+ sz = 4;
727
+ }
728
+ snap_restoredata(T, ex, snapno, rfilt, ir->op2, p, sz);
729
+ } else {
730
+ IRIns *irs, *irlast = &T->ir[T->snap[snapno].ref];
731
+ for (irs = ir+1; irs < irlast; irs++)
732
+ if (irs->r == RID_SINK && snap_sunk_store(J, ir, irs)) {
733
+ IRIns *iro = &T->ir[T->ir[irs->op1].op2];
734
+ uint8_t *p = (uint8_t *)cd;
735
+ CTSize szs;
736
+ lua_assert(irs->o == IR_XSTORE && T->ir[irs->op1].o == IR_ADD);
737
+ lua_assert(iro->o == IR_KINT || iro->o == IR_KINT64);
738
+ if (irt_is64(irs->t)) szs = 8;
739
+ else if (irt_isi8(irs->t) || irt_isu8(irs->t)) szs = 1;
740
+ else if (irt_isi16(irs->t) || irt_isu16(irs->t)) szs = 2;
741
+ else szs = 4;
742
+ if (LJ_64 && iro->o == IR_KINT64)
743
+ p += (int64_t)ir_k64(iro)->u64;
744
+ else
745
+ p += iro->i;
746
+ lua_assert(p >= (uint8_t *)cdataptr(cd) &&
747
+ p + szs <= (uint8_t *)cdataptr(cd) + sz);
748
+ if (LJ_32 && irs+1 < T->ir + T->nins && (irs+1)->o == IR_HIOP) {
749
+ lua_assert(szs == 4);
750
+ snap_restoredata(T, ex, snapno, rfilt, (irs+1)->op2, LJ_LE?p+4:p,4);
751
+ if (LJ_BE) p += 4;
752
+ }
753
+ snap_restoredata(T, ex, snapno, rfilt, irs->op2, p, szs);
754
+ }
755
+ }
756
+ } else
757
+ #endif
758
+ {
759
+ IRIns *irs, *irlast;
760
+ GCtab *t = ir->o == IR_TNEW ? lj_tab_new(J->L, ir->op1, ir->op2) :
761
+ lj_tab_dup(J->L, ir_ktab(&T->ir[ir->op1]));
762
+ settabV(J->L, o, t);
763
+ irlast = &T->ir[T->snap[snapno].ref];
764
+ for (irs = ir+1; irs < irlast; irs++)
765
+ if (irs->r == RID_SINK && snap_sunk_store(J, ir, irs)) {
766
+ IRIns *irk = &T->ir[irs->op1];
767
+ TValue tmp, *val;
768
+ lua_assert(irs->o == IR_ASTORE || irs->o == IR_HSTORE ||
769
+ irs->o == IR_FSTORE);
770
+ if (irk->o == IR_FREF) {
771
+ lua_assert(irk->op2 == IRFL_TAB_META);
772
+ snap_restoreval(J, T, ex, snapno, rfilt, irs->op2, &tmp);
773
+ /* NOBARRIER: The table is new (marked white). */
774
+ setgcref(t->metatable, obj2gco(tabV(&tmp)));
775
+ } else {
776
+ irk = &T->ir[irk->op2];
777
+ if (irk->o == IR_KSLOT) irk = &T->ir[irk->op1];
778
+ lj_ir_kvalue(J->L, &tmp, irk);
779
+ val = lj_tab_set(J->L, t, &tmp);
780
+ /* NOBARRIER: The table is new (marked white). */
781
+ snap_restoreval(J, T, ex, snapno, rfilt, irs->op2, val);
782
+ if (LJ_SOFTFP && irs+1 < T->ir + T->nins && (irs+1)->o == IR_HIOP) {
783
+ snap_restoreval(J, T, ex, snapno, rfilt, (irs+1)->op2, &tmp);
784
+ val->u32.hi = tmp.u32.lo;
785
+ }
786
+ }
787
+ }
788
+ }
789
+ }
790
+
791
+ /* Restore interpreter state from exit state with the help of a snapshot. */
792
+ const BCIns *lj_snap_restore(jit_State *J, void *exptr)
793
+ {
794
+ ExitState *ex = (ExitState *)exptr;
795
+ SnapNo snapno = J->exitno; /* For now, snapno == exitno. */
796
+ GCtrace *T = traceref(J, J->parent);
797
+ SnapShot *snap = &T->snap[snapno];
798
+ MSize n, nent = snap->nent;
799
+ SnapEntry *map = &T->snapmap[snap->mapofs];
800
+ SnapEntry *flinks = &T->snapmap[snap_nextofs(T, snap)-1];
801
+ ptrdiff_t ftsz0;
802
+ TValue *frame;
803
+ BloomFilter rfilt = snap_renamefilter(T, snapno);
804
+ const BCIns *pc = snap_pc(map[nent]);
805
+ lua_State *L = J->L;
806
+
807
+ /* Set interpreter PC to the next PC to get correct error messages. */
808
+ setcframe_pc(cframe_raw(L->cframe), pc+1);
809
+
810
+ /* Make sure the stack is big enough for the slots from the snapshot. */
811
+ if (LJ_UNLIKELY(L->base + snap->topslot >= tvref(L->maxstack))) {
812
+ L->top = curr_topL(L);
813
+ lj_state_growstack(L, snap->topslot - curr_proto(L)->framesize);
814
+ }
815
+
816
+ /* Fill stack slots with data from the registers and spill slots. */
817
+ frame = L->base-1;
818
+ ftsz0 = frame_ftsz(frame); /* Preserve link to previous frame in slot #0. */
819
+ for (n = 0; n < nent; n++) {
820
+ SnapEntry sn = map[n];
821
+ if (!(sn & SNAP_NORESTORE)) {
822
+ TValue *o = &frame[snap_slot(sn)];
823
+ IRRef ref = snap_ref(sn);
824
+ IRIns *ir = &T->ir[ref];
825
+ if (ir->r == RID_SUNK) {
826
+ MSize j;
827
+ for (j = 0; j < n; j++)
828
+ if (snap_ref(map[j]) == ref) { /* De-duplicate sunk allocations. */
829
+ copyTV(L, o, &frame[snap_slot(map[j])]);
830
+ goto dupslot;
831
+ }
832
+ snap_unsink(J, T, ex, snapno, rfilt, ir, o);
833
+ dupslot:
834
+ continue;
835
+ }
836
+ snap_restoreval(J, T, ex, snapno, rfilt, ref, o);
837
+ if (LJ_SOFTFP && (sn & SNAP_SOFTFPNUM) && tvisint(o)) {
838
+ TValue tmp;
839
+ snap_restoreval(J, T, ex, snapno, rfilt, ref+1, &tmp);
840
+ o->u32.hi = tmp.u32.lo;
841
+ } else if ((sn & (SNAP_CONT|SNAP_FRAME))) {
842
+ lua_assert(!LJ_FR2); /* TODO_FR2: store 64 bit PCs. */
843
+ /* Overwrite tag with frame link. */
844
+ setframe_ftsz(o, snap_slot(sn) != 0 ? (int32_t)*flinks-- : ftsz0);
845
+ L->base = o+1;
846
+ }
847
+ }
848
+ }
849
+ lua_assert(map + nent == flinks);
850
+
851
+ /* Compute current stack top. */
852
+ switch (bc_op(*pc)) {
853
+ default:
854
+ if (bc_op(*pc) < BC_FUNCF) {
855
+ L->top = curr_topL(L);
856
+ break;
857
+ }
858
+ /* fallthrough */
859
+ case BC_CALLM: case BC_CALLMT: case BC_RETM: case BC_TSETM:
860
+ L->top = frame + snap->nslots;
861
+ break;
862
+ }
863
+ return pc;
864
+ }
865
+
866
+ #undef IR
867
+ #undef emitir_raw
868
+ #undef emitir
869
+
870
+ #endif