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,65 @@
1
+ /*
2
+ ** Debugging and introspection.
3
+ ** Copyright (C) 2005-2015 Mike Pall. See Copyright Notice in luajit.h
4
+ */
5
+
6
+ #ifndef _LJ_DEBUG_H
7
+ #define _LJ_DEBUG_H
8
+
9
+ #include "lj_obj.h"
10
+
11
+ typedef struct lj_Debug {
12
+ /* Common fields. Must be in the same order as in lua.h. */
13
+ int event;
14
+ const char *name;
15
+ const char *namewhat;
16
+ const char *what;
17
+ const char *source;
18
+ int currentline;
19
+ int nups;
20
+ int linedefined;
21
+ int lastlinedefined;
22
+ char short_src[LUA_IDSIZE];
23
+ int i_ci;
24
+ /* Extended fields. Only valid if lj_debug_getinfo() is called with ext = 1.*/
25
+ int nparams;
26
+ int isvararg;
27
+ } lj_Debug;
28
+
29
+ LJ_FUNC cTValue *lj_debug_frame(lua_State *L, int level, int *size);
30
+ LJ_FUNC BCLine LJ_FASTCALL lj_debug_line(GCproto *pt, BCPos pc);
31
+ LJ_FUNC const char *lj_debug_uvname(GCproto *pt, uint32_t idx);
32
+ LJ_FUNC const char *lj_debug_uvnamev(cTValue *o, uint32_t idx, TValue **tvp);
33
+ LJ_FUNC const char *lj_debug_slotname(GCproto *pt, const BCIns *pc,
34
+ BCReg slot, const char **name);
35
+ LJ_FUNC const char *lj_debug_funcname(lua_State *L, cTValue *frame,
36
+ const char **name);
37
+ LJ_FUNC void lj_debug_shortname(char *out, GCstr *str, BCLine line);
38
+ LJ_FUNC void lj_debug_addloc(lua_State *L, const char *msg,
39
+ cTValue *frame, cTValue *nextframe);
40
+ LJ_FUNC void lj_debug_pushloc(lua_State *L, GCproto *pt, BCPos pc);
41
+ LJ_FUNC int lj_debug_getinfo(lua_State *L, const char *what, lj_Debug *ar,
42
+ int ext);
43
+ #if LJ_HASPROFILE
44
+ LJ_FUNC void lj_debug_dumpstack(lua_State *L, SBuf *sb, const char *fmt,
45
+ int depth);
46
+ #endif
47
+
48
+ /* Fixed internal variable names. */
49
+ #define VARNAMEDEF(_) \
50
+ _(FOR_IDX, "(for index)") \
51
+ _(FOR_STOP, "(for limit)") \
52
+ _(FOR_STEP, "(for step)") \
53
+ _(FOR_GEN, "(for generator)") \
54
+ _(FOR_STATE, "(for state)") \
55
+ _(FOR_CTL, "(for control)")
56
+
57
+ enum {
58
+ VARNAME_END,
59
+ #define VARNAMEENUM(name, str) VARNAME_##name,
60
+ VARNAMEDEF(VARNAMEENUM)
61
+ #undef VARNAMEENUM
62
+ VARNAME__MAX
63
+ };
64
+
65
+ #endif
@@ -0,0 +1,365 @@
1
+ /*
2
+ ** LuaJIT common internal definitions.
3
+ ** Copyright (C) 2005-2015 Mike Pall. See Copyright Notice in luajit.h
4
+ */
5
+
6
+ #ifndef _LJ_DEF_H
7
+ #define _LJ_DEF_H
8
+
9
+ #include "lua.h"
10
+
11
+ #if defined(_MSC_VER)
12
+ /* MSVC is stuck in the last century and doesn't have C99's stdint.h. */
13
+ typedef __int8 int8_t;
14
+ typedef __int16 int16_t;
15
+ typedef __int32 int32_t;
16
+ typedef __int64 int64_t;
17
+ typedef unsigned __int8 uint8_t;
18
+ typedef unsigned __int16 uint16_t;
19
+ typedef unsigned __int32 uint32_t;
20
+ typedef unsigned __int64 uint64_t;
21
+ #ifdef _WIN64
22
+ typedef __int64 intptr_t;
23
+ typedef unsigned __int64 uintptr_t;
24
+ #else
25
+ typedef __int32 intptr_t;
26
+ typedef unsigned __int32 uintptr_t;
27
+ #endif
28
+ #elif defined(__symbian__)
29
+ /* Cough. */
30
+ typedef signed char int8_t;
31
+ typedef short int int16_t;
32
+ typedef int int32_t;
33
+ typedef long long int64_t;
34
+ typedef unsigned char uint8_t;
35
+ typedef unsigned short int uint16_t;
36
+ typedef unsigned int uint32_t;
37
+ typedef unsigned long long uint64_t;
38
+ typedef int intptr_t;
39
+ typedef unsigned int uintptr_t;
40
+ #else
41
+ #include <stdint.h>
42
+ #endif
43
+
44
+ /* Needed everywhere. */
45
+ #include <string.h>
46
+ #include <stdlib.h>
47
+
48
+ /* Various VM limits. */
49
+ #define LJ_MAX_MEM32 0x7fffff00 /* Max. 32 bit memory allocation. */
50
+ #define LJ_MAX_MEM64 ((uint64_t)1<<47) /* Max. 64 bit memory allocation. */
51
+ /* Max. total memory allocation. */
52
+ #define LJ_MAX_MEM (LJ_GC64 ? LJ_MAX_MEM64 : LJ_MAX_MEM32)
53
+ #define LJ_MAX_ALLOC LJ_MAX_MEM /* Max. individual allocation length. */
54
+ #define LJ_MAX_STR LJ_MAX_MEM32 /* Max. string length. */
55
+ #define LJ_MAX_BUF LJ_MAX_MEM32 /* Max. buffer length. */
56
+ #define LJ_MAX_UDATA LJ_MAX_MEM32 /* Max. userdata length. */
57
+
58
+ #define LJ_MAX_STRTAB (1<<26) /* Max. string table size. */
59
+ #define LJ_MAX_HBITS 26 /* Max. hash bits. */
60
+ #define LJ_MAX_ABITS 28 /* Max. bits of array key. */
61
+ #define LJ_MAX_ASIZE ((1<<(LJ_MAX_ABITS-1))+1) /* Max. array part size. */
62
+ #define LJ_MAX_COLOSIZE 16 /* Max. elems for colocated array. */
63
+
64
+ #define LJ_MAX_LINE LJ_MAX_MEM32 /* Max. source code line number. */
65
+ #define LJ_MAX_XLEVEL 200 /* Max. syntactic nesting level. */
66
+ #define LJ_MAX_BCINS (1<<26) /* Max. # of bytecode instructions. */
67
+ #define LJ_MAX_SLOTS 250 /* Max. # of slots in a Lua func. */
68
+ #define LJ_MAX_LOCVAR 200 /* Max. # of local variables. */
69
+ #define LJ_MAX_UPVAL 60 /* Max. # of upvalues. */
70
+
71
+ #define LJ_MAX_IDXCHAIN 100 /* __index/__newindex chain limit. */
72
+ #define LJ_STACK_EXTRA (5+2*LJ_FR2) /* Extra stack space (metamethods). */
73
+
74
+ #define LJ_NUM_CBPAGE 1 /* Number of FFI callback pages. */
75
+
76
+ /* Minimum table/buffer sizes. */
77
+ #define LJ_MIN_GLOBAL 6 /* Min. global table size (hbits). */
78
+ #define LJ_MIN_REGISTRY 2 /* Min. registry size (hbits). */
79
+ #define LJ_MIN_STRTAB 256 /* Min. string table size (pow2). */
80
+ #define LJ_MIN_SBUF 32 /* Min. string buffer length. */
81
+ #define LJ_MIN_VECSZ 8 /* Min. size for growable vectors. */
82
+ #define LJ_MIN_IRSZ 32 /* Min. size for growable IR. */
83
+ #define LJ_MIN_K64SZ 16 /* Min. size for chained K64Array. */
84
+
85
+ /* JIT compiler limits. */
86
+ #define LJ_MAX_JSLOTS 250 /* Max. # of stack slots for a trace. */
87
+ #define LJ_MAX_PHI 64 /* Max. # of PHIs for a loop. */
88
+ #define LJ_MAX_EXITSTUBGR 16 /* Max. # of exit stub groups. */
89
+
90
+ /* Various macros. */
91
+ #ifndef UNUSED
92
+ #define UNUSED(x) ((void)(x)) /* to avoid warnings */
93
+ #endif
94
+
95
+ #define U64x(hi, lo) (((uint64_t)0x##hi << 32) + (uint64_t)0x##lo)
96
+ #define i32ptr(p) ((int32_t)(intptr_t)(void *)(p))
97
+ #define u32ptr(p) ((uint32_t)(intptr_t)(void *)(p))
98
+
99
+ #define checki8(x) ((x) == (int32_t)(int8_t)(x))
100
+ #define checku8(x) ((x) == (int32_t)(uint8_t)(x))
101
+ #define checki16(x) ((x) == (int32_t)(int16_t)(x))
102
+ #define checku16(x) ((x) == (int32_t)(uint16_t)(x))
103
+ #define checki32(x) ((x) == (int32_t)(x))
104
+ #define checku32(x) ((x) == (uint32_t)(x))
105
+ #define checkptr32(x) ((uintptr_t)(x) == (uint32_t)(uintptr_t)(x))
106
+ #define checkptr47(x) (((uint64_t)(x) >> 47) == 0)
107
+ #if LJ_GC64
108
+ #define checkptrGC(x) (checkptr47((x)))
109
+ #elif LJ_64
110
+ #define checkptrGC(x) (checkptr32((x)))
111
+ #else
112
+ #define checkptrGC(x) 1
113
+ #endif
114
+
115
+ /* Every half-decent C compiler transforms this into a rotate instruction. */
116
+ #define lj_rol(x, n) (((x)<<(n)) | ((x)>>(-(int)(n)&(8*sizeof(x)-1))))
117
+ #define lj_ror(x, n) (((x)<<(-(int)(n)&(8*sizeof(x)-1))) | ((x)>>(n)))
118
+
119
+ /* A really naive Bloom filter. But sufficient for our needs. */
120
+ typedef uintptr_t BloomFilter;
121
+ #define BLOOM_MASK (8*sizeof(BloomFilter) - 1)
122
+ #define bloombit(x) ((uintptr_t)1 << ((x) & BLOOM_MASK))
123
+ #define bloomset(b, x) ((b) |= bloombit((x)))
124
+ #define bloomtest(b, x) ((b) & bloombit((x)))
125
+
126
+ #if defined(__GNUC__) || defined(__psp2__)
127
+
128
+ #define LJ_NORET __attribute__((noreturn))
129
+ #define LJ_ALIGN(n) __attribute__((aligned(n)))
130
+ #define LJ_INLINE inline
131
+ #define LJ_AINLINE inline __attribute__((always_inline))
132
+ #define LJ_NOINLINE __attribute__((noinline))
133
+
134
+ #if defined(__ELF__) || defined(__MACH__) || defined(__psp2__)
135
+ #if !((defined(__sun__) && defined(__svr4__)) || defined(__CELLOS_LV2__))
136
+ #define LJ_NOAPI extern __attribute__((visibility("hidden")))
137
+ #endif
138
+ #endif
139
+
140
+ /* Note: it's only beneficial to use fastcall on x86 and then only for up to
141
+ ** two non-FP args. The amalgamated compile covers all LJ_FUNC cases. Only
142
+ ** indirect calls and related tail-called C functions are marked as fastcall.
143
+ */
144
+ #if defined(__i386__)
145
+ #define LJ_FASTCALL __attribute__((fastcall))
146
+ #endif
147
+
148
+ #define LJ_LIKELY(x) __builtin_expect(!!(x), 1)
149
+ #define LJ_UNLIKELY(x) __builtin_expect(!!(x), 0)
150
+
151
+ #define lj_ffs(x) ((uint32_t)__builtin_ctz(x))
152
+ /* Don't ask ... */
153
+ #if defined(__INTEL_COMPILER) && (defined(__i386__) || defined(__x86_64__))
154
+ static LJ_AINLINE uint32_t lj_fls(uint32_t x)
155
+ {
156
+ uint32_t r; __asm__("bsrl %1, %0" : "=r" (r) : "rm" (x) : "cc"); return r;
157
+ }
158
+ #else
159
+ #define lj_fls(x) ((uint32_t)(__builtin_clz(x)^31))
160
+ #endif
161
+
162
+ #if defined(__arm__)
163
+ static LJ_AINLINE uint32_t lj_bswap(uint32_t x)
164
+ {
165
+ #if defined(__psp2__)
166
+ return __builtin_rev(x);
167
+ #else
168
+ uint32_t r;
169
+ #if __ARM_ARCH_6__ || __ARM_ARCH_6J__ || __ARM_ARCH_6T2__ || __ARM_ARCH_6Z__ ||\
170
+ __ARM_ARCH_6ZK__ || __ARM_ARCH_7__ || __ARM_ARCH_7A__ || __ARM_ARCH_7R__
171
+ __asm__("rev %0, %1" : "=r" (r) : "r" (x));
172
+ return r;
173
+ #else
174
+ #ifdef __thumb__
175
+ r = x ^ lj_ror(x, 16);
176
+ #else
177
+ __asm__("eor %0, %1, %1, ror #16" : "=r" (r) : "r" (x));
178
+ #endif
179
+ return ((r & 0xff00ffffu) >> 8) ^ lj_ror(x, 8);
180
+ #endif
181
+ #endif
182
+ }
183
+
184
+ static LJ_AINLINE uint64_t lj_bswap64(uint64_t x)
185
+ {
186
+ return ((uint64_t)lj_bswap((uint32_t)x)<<32) | lj_bswap((uint32_t)(x>>32));
187
+ }
188
+ #elif (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
189
+ static LJ_AINLINE uint32_t lj_bswap(uint32_t x)
190
+ {
191
+ return (uint32_t)__builtin_bswap32((int32_t)x);
192
+ }
193
+
194
+ static LJ_AINLINE uint64_t lj_bswap64(uint64_t x)
195
+ {
196
+ return (uint64_t)__builtin_bswap64((int64_t)x);
197
+ }
198
+ #elif defined(__i386__) || defined(__x86_64__)
199
+ static LJ_AINLINE uint32_t lj_bswap(uint32_t x)
200
+ {
201
+ uint32_t r; __asm__("bswap %0" : "=r" (r) : "0" (x)); return r;
202
+ }
203
+
204
+ #if defined(__i386__)
205
+ static LJ_AINLINE uint64_t lj_bswap64(uint64_t x)
206
+ {
207
+ return ((uint64_t)lj_bswap((uint32_t)x)<<32) | lj_bswap((uint32_t)(x>>32));
208
+ }
209
+ #else
210
+ static LJ_AINLINE uint64_t lj_bswap64(uint64_t x)
211
+ {
212
+ uint64_t r; __asm__("bswap %0" : "=r" (r) : "0" (x)); return r;
213
+ }
214
+ #endif
215
+ #else
216
+ static LJ_AINLINE uint32_t lj_bswap(uint32_t x)
217
+ {
218
+ return (x << 24) | ((x & 0xff00) << 8) | ((x >> 8) & 0xff00) | (x >> 24);
219
+ }
220
+
221
+ static LJ_AINLINE uint64_t lj_bswap64(uint64_t x)
222
+ {
223
+ return (uint64_t)lj_bswap((uint32_t)(x >> 32)) |
224
+ ((uint64_t)lj_bswap((uint32_t)x) << 32);
225
+ }
226
+ #endif
227
+
228
+ typedef union __attribute__((packed)) Unaligned16 {
229
+ uint16_t u;
230
+ uint8_t b[2];
231
+ } Unaligned16;
232
+
233
+ typedef union __attribute__((packed)) Unaligned32 {
234
+ uint32_t u;
235
+ uint8_t b[4];
236
+ } Unaligned32;
237
+
238
+ /* Unaligned load of uint16_t. */
239
+ static LJ_AINLINE uint16_t lj_getu16(const void *p)
240
+ {
241
+ return ((const Unaligned16 *)p)->u;
242
+ }
243
+
244
+ /* Unaligned load of uint32_t. */
245
+ static LJ_AINLINE uint32_t lj_getu32(const void *p)
246
+ {
247
+ return ((const Unaligned32 *)p)->u;
248
+ }
249
+
250
+ #elif defined(_MSC_VER)
251
+
252
+ #define LJ_NORET __declspec(noreturn)
253
+ #define LJ_ALIGN(n) __declspec(align(n))
254
+ #define LJ_INLINE __inline
255
+ #define LJ_AINLINE __forceinline
256
+ #define LJ_NOINLINE __declspec(noinline)
257
+ #if defined(_M_IX86)
258
+ #define LJ_FASTCALL __fastcall
259
+ #endif
260
+
261
+ #ifdef _M_PPC
262
+ unsigned int _CountLeadingZeros(long);
263
+ #pragma intrinsic(_CountLeadingZeros)
264
+ static LJ_AINLINE uint32_t lj_fls(uint32_t x)
265
+ {
266
+ return _CountLeadingZeros(x) ^ 31;
267
+ }
268
+ #else
269
+ unsigned char _BitScanForward(uint32_t *, unsigned long);
270
+ unsigned char _BitScanReverse(uint32_t *, unsigned long);
271
+ #pragma intrinsic(_BitScanForward)
272
+ #pragma intrinsic(_BitScanReverse)
273
+
274
+ static LJ_AINLINE uint32_t lj_ffs(uint32_t x)
275
+ {
276
+ uint32_t r; _BitScanForward(&r, x); return r;
277
+ }
278
+
279
+ static LJ_AINLINE uint32_t lj_fls(uint32_t x)
280
+ {
281
+ uint32_t r; _BitScanReverse(&r, x); return r;
282
+ }
283
+ #endif
284
+
285
+ unsigned long _byteswap_ulong(unsigned long);
286
+ uint64_t _byteswap_uint64(uint64_t);
287
+ #define lj_bswap(x) (_byteswap_ulong((x)))
288
+ #define lj_bswap64(x) (_byteswap_uint64((x)))
289
+
290
+ #if defined(_M_PPC) && defined(LUAJIT_NO_UNALIGNED)
291
+ /*
292
+ ** Replacement for unaligned loads on Xbox 360. Disabled by default since it's
293
+ ** usually more costly than the occasional stall when crossing a cache-line.
294
+ */
295
+ static LJ_AINLINE uint16_t lj_getu16(const void *v)
296
+ {
297
+ const uint8_t *p = (const uint8_t *)v;
298
+ return (uint16_t)((p[0]<<8) | p[1]);
299
+ }
300
+ static LJ_AINLINE uint32_t lj_getu32(const void *v)
301
+ {
302
+ const uint8_t *p = (const uint8_t *)v;
303
+ return (uint32_t)((p[0]<<24) | (p[1]<<16) | (p[2]<<8) | p[3]);
304
+ }
305
+ #else
306
+ /* Unaligned loads are generally ok on x86/x64. */
307
+ #define lj_getu16(p) (*(uint16_t *)(p))
308
+ #define lj_getu32(p) (*(uint32_t *)(p))
309
+ #endif
310
+
311
+ #else
312
+ #error "missing defines for your compiler"
313
+ #endif
314
+
315
+ /* Optional defines. */
316
+ #ifndef LJ_FASTCALL
317
+ #define LJ_FASTCALL
318
+ #endif
319
+ #ifndef LJ_NORET
320
+ #define LJ_NORET
321
+ #endif
322
+ #ifndef LJ_NOAPI
323
+ #define LJ_NOAPI extern
324
+ #endif
325
+ #ifndef LJ_LIKELY
326
+ #define LJ_LIKELY(x) (x)
327
+ #define LJ_UNLIKELY(x) (x)
328
+ #endif
329
+
330
+ /* Attributes for internal functions. */
331
+ #define LJ_DATA LJ_NOAPI
332
+ #define LJ_DATADEF
333
+ #define LJ_ASMF LJ_NOAPI
334
+ #define LJ_FUNCA LJ_NOAPI
335
+ #if defined(ljamalg_c)
336
+ #define LJ_FUNC static
337
+ #else
338
+ #define LJ_FUNC LJ_NOAPI
339
+ #endif
340
+ #define LJ_FUNC_NORET LJ_FUNC LJ_NORET
341
+ #define LJ_FUNCA_NORET LJ_FUNCA LJ_NORET
342
+ #define LJ_ASMF_NORET LJ_ASMF LJ_NORET
343
+
344
+ /* Runtime assertions. */
345
+ #ifdef lua_assert
346
+ #define check_exp(c, e) (lua_assert(c), (e))
347
+ #define api_check(l, e) lua_assert(e)
348
+ #else
349
+ #define lua_assert(c) ((void)0)
350
+ #define check_exp(c, e) (e)
351
+ #define api_check luai_apicheck
352
+ #endif
353
+
354
+ /* Static assertions. */
355
+ #define LJ_ASSERT_NAME2(name, line) name ## line
356
+ #define LJ_ASSERT_NAME(line) LJ_ASSERT_NAME2(lj_assert_, line)
357
+ #ifdef __COUNTER__
358
+ #define LJ_STATIC_ASSERT(cond) \
359
+ extern void LJ_ASSERT_NAME(__COUNTER__)(int STATIC_ASSERTION_FAILED[(cond)?1:-1])
360
+ #else
361
+ #define LJ_STATIC_ASSERT(cond) \
362
+ extern void LJ_ASSERT_NAME(__LINE__)(int STATIC_ASSERTION_FAILED[(cond)?1:-1])
363
+ #endif
364
+
365
+ #endif
@@ -0,0 +1,557 @@
1
+ /*
2
+ ** Instruction dispatch handling.
3
+ ** Copyright (C) 2005-2015 Mike Pall. See Copyright Notice in luajit.h
4
+ */
5
+
6
+ #define lj_dispatch_c
7
+ #define LUA_CORE
8
+
9
+ #include "lj_obj.h"
10
+ #include "lj_err.h"
11
+ #include "lj_buf.h"
12
+ #include "lj_func.h"
13
+ #include "lj_str.h"
14
+ #include "lj_tab.h"
15
+ #include "lj_meta.h"
16
+ #include "lj_debug.h"
17
+ #include "lj_state.h"
18
+ #include "lj_frame.h"
19
+ #include "lj_bc.h"
20
+ #include "lj_ff.h"
21
+ #include "lj_strfmt.h"
22
+ #if LJ_HASJIT
23
+ #include "lj_jit.h"
24
+ #endif
25
+ #if LJ_HASFFI
26
+ #include "lj_ccallback.h"
27
+ #endif
28
+ #include "lj_trace.h"
29
+ #include "lj_dispatch.h"
30
+ #if LJ_HASPROFILE
31
+ #include "lj_profile.h"
32
+ #endif
33
+ #include "lj_vm.h"
34
+ #include "luajit.h"
35
+
36
+ /* Bump GG_NUM_ASMFF in lj_dispatch.h as needed. Ugly. */
37
+ LJ_STATIC_ASSERT(GG_NUM_ASMFF == FF_NUM_ASMFUNC);
38
+
39
+ /* -- Dispatch table management ------------------------------------------- */
40
+
41
+ #if LJ_TARGET_MIPS
42
+ #include <math.h>
43
+ LJ_FUNCA_NORET void LJ_FASTCALL lj_ffh_coroutine_wrap_err(lua_State *L,
44
+ lua_State *co);
45
+ #if !LJ_HASJIT
46
+ #define lj_dispatch_stitch lj_dispatch_ins
47
+ #endif
48
+ #if !LJ_HASPROFILE
49
+ #define lj_dispatch_profile lj_dispatch_ins
50
+ #endif
51
+
52
+ #define GOTFUNC(name) (ASMFunction)name,
53
+ static const ASMFunction dispatch_got[] = {
54
+ GOTDEF(GOTFUNC)
55
+ };
56
+ #undef GOTFUNC
57
+ #endif
58
+
59
+ /* Initialize instruction dispatch table and hot counters. */
60
+ void lj_dispatch_init(GG_State *GG)
61
+ {
62
+ uint32_t i;
63
+ ASMFunction *disp = GG->dispatch;
64
+ for (i = 0; i < GG_LEN_SDISP; i++)
65
+ disp[GG_LEN_DDISP+i] = disp[i] = makeasmfunc(lj_bc_ofs[i]);
66
+ for (i = GG_LEN_SDISP; i < GG_LEN_DDISP; i++)
67
+ disp[i] = makeasmfunc(lj_bc_ofs[i]);
68
+ /* The JIT engine is off by default. luaopen_jit() turns it on. */
69
+ disp[BC_FORL] = disp[BC_IFORL];
70
+ disp[BC_ITERL] = disp[BC_IITERL];
71
+ disp[BC_LOOP] = disp[BC_ILOOP];
72
+ disp[BC_FUNCF] = disp[BC_IFUNCF];
73
+ disp[BC_FUNCV] = disp[BC_IFUNCV];
74
+ GG->g.bc_cfunc_ext = GG->g.bc_cfunc_int = BCINS_AD(BC_FUNCC, LUA_MINSTACK, 0);
75
+ for (i = 0; i < GG_NUM_ASMFF; i++)
76
+ GG->bcff[i] = BCINS_AD(BC__MAX+i, 0, 0);
77
+ #if LJ_TARGET_MIPS
78
+ memcpy(GG->got, dispatch_got, LJ_GOT__MAX*4);
79
+ #endif
80
+ }
81
+
82
+ #if LJ_HASJIT
83
+ /* Initialize hotcount table. */
84
+ void lj_dispatch_init_hotcount(global_State *g)
85
+ {
86
+ int32_t hotloop = G2J(g)->param[JIT_P_hotloop];
87
+ HotCount start = (HotCount)(hotloop*HOTCOUNT_LOOP - 1);
88
+ HotCount *hotcount = G2GG(g)->hotcount;
89
+ uint32_t i;
90
+ for (i = 0; i < HOTCOUNT_SIZE; i++)
91
+ hotcount[i] = start;
92
+ }
93
+ #endif
94
+
95
+ /* Internal dispatch mode bits. */
96
+ #define DISPMODE_CALL 0x01 /* Override call dispatch. */
97
+ #define DISPMODE_RET 0x02 /* Override return dispatch. */
98
+ #define DISPMODE_INS 0x04 /* Override instruction dispatch. */
99
+ #define DISPMODE_JIT 0x10 /* JIT compiler on. */
100
+ #define DISPMODE_REC 0x20 /* Recording active. */
101
+ #define DISPMODE_PROF 0x40 /* Profiling active. */
102
+
103
+ /* Update dispatch table depending on various flags. */
104
+ void lj_dispatch_update(global_State *g)
105
+ {
106
+ uint8_t oldmode = g->dispatchmode;
107
+ uint8_t mode = 0;
108
+ #if LJ_HASJIT
109
+ mode |= (G2J(g)->flags & JIT_F_ON) ? DISPMODE_JIT : 0;
110
+ mode |= G2J(g)->state != LJ_TRACE_IDLE ?
111
+ (DISPMODE_REC|DISPMODE_INS|DISPMODE_CALL) : 0;
112
+ #endif
113
+ #if LJ_HASPROFILE
114
+ mode |= (g->hookmask & HOOK_PROFILE) ? (DISPMODE_PROF|DISPMODE_INS) : 0;
115
+ #endif
116
+ mode |= (g->hookmask & (LUA_MASKLINE|LUA_MASKCOUNT)) ? DISPMODE_INS : 0;
117
+ mode |= (g->hookmask & LUA_MASKCALL) ? DISPMODE_CALL : 0;
118
+ mode |= (g->hookmask & LUA_MASKRET) ? DISPMODE_RET : 0;
119
+ if (oldmode != mode) { /* Mode changed? */
120
+ ASMFunction *disp = G2GG(g)->dispatch;
121
+ ASMFunction f_forl, f_iterl, f_loop, f_funcf, f_funcv;
122
+ g->dispatchmode = mode;
123
+
124
+ /* Hotcount if JIT is on, but not while recording. */
125
+ if ((mode & (DISPMODE_JIT|DISPMODE_REC)) == DISPMODE_JIT) {
126
+ f_forl = makeasmfunc(lj_bc_ofs[BC_FORL]);
127
+ f_iterl = makeasmfunc(lj_bc_ofs[BC_ITERL]);
128
+ f_loop = makeasmfunc(lj_bc_ofs[BC_LOOP]);
129
+ f_funcf = makeasmfunc(lj_bc_ofs[BC_FUNCF]);
130
+ f_funcv = makeasmfunc(lj_bc_ofs[BC_FUNCV]);
131
+ } else { /* Otherwise use the non-hotcounting instructions. */
132
+ f_forl = disp[GG_LEN_DDISP+BC_IFORL];
133
+ f_iterl = disp[GG_LEN_DDISP+BC_IITERL];
134
+ f_loop = disp[GG_LEN_DDISP+BC_ILOOP];
135
+ f_funcf = makeasmfunc(lj_bc_ofs[BC_IFUNCF]);
136
+ f_funcv = makeasmfunc(lj_bc_ofs[BC_IFUNCV]);
137
+ }
138
+ /* Init static counting instruction dispatch first (may be copied below). */
139
+ disp[GG_LEN_DDISP+BC_FORL] = f_forl;
140
+ disp[GG_LEN_DDISP+BC_ITERL] = f_iterl;
141
+ disp[GG_LEN_DDISP+BC_LOOP] = f_loop;
142
+
143
+ /* Set dynamic instruction dispatch. */
144
+ if ((oldmode ^ mode) & (DISPMODE_PROF|DISPMODE_REC|DISPMODE_INS)) {
145
+ /* Need to update the whole table. */
146
+ if (!(mode & DISPMODE_INS)) { /* No ins dispatch? */
147
+ /* Copy static dispatch table to dynamic dispatch table. */
148
+ memcpy(&disp[0], &disp[GG_LEN_DDISP], GG_LEN_SDISP*sizeof(ASMFunction));
149
+ /* Overwrite with dynamic return dispatch. */
150
+ if ((mode & DISPMODE_RET)) {
151
+ disp[BC_RETM] = lj_vm_rethook;
152
+ disp[BC_RET] = lj_vm_rethook;
153
+ disp[BC_RET0] = lj_vm_rethook;
154
+ disp[BC_RET1] = lj_vm_rethook;
155
+ }
156
+ } else {
157
+ /* The recording dispatch also checks for hooks. */
158
+ ASMFunction f = (mode & DISPMODE_PROF) ? lj_vm_profhook :
159
+ (mode & DISPMODE_REC) ? lj_vm_record : lj_vm_inshook;
160
+ uint32_t i;
161
+ for (i = 0; i < GG_LEN_SDISP; i++)
162
+ disp[i] = f;
163
+ }
164
+ } else if (!(mode & DISPMODE_INS)) {
165
+ /* Otherwise set dynamic counting ins. */
166
+ disp[BC_FORL] = f_forl;
167
+ disp[BC_ITERL] = f_iterl;
168
+ disp[BC_LOOP] = f_loop;
169
+ /* Set dynamic return dispatch. */
170
+ if ((mode & DISPMODE_RET)) {
171
+ disp[BC_RETM] = lj_vm_rethook;
172
+ disp[BC_RET] = lj_vm_rethook;
173
+ disp[BC_RET0] = lj_vm_rethook;
174
+ disp[BC_RET1] = lj_vm_rethook;
175
+ } else {
176
+ disp[BC_RETM] = disp[GG_LEN_DDISP+BC_RETM];
177
+ disp[BC_RET] = disp[GG_LEN_DDISP+BC_RET];
178
+ disp[BC_RET0] = disp[GG_LEN_DDISP+BC_RET0];
179
+ disp[BC_RET1] = disp[GG_LEN_DDISP+BC_RET1];
180
+ }
181
+ }
182
+
183
+ /* Set dynamic call dispatch. */
184
+ if ((oldmode ^ mode) & DISPMODE_CALL) { /* Update the whole table? */
185
+ uint32_t i;
186
+ if ((mode & DISPMODE_CALL) == 0) { /* No call hooks? */
187
+ for (i = GG_LEN_SDISP; i < GG_LEN_DDISP; i++)
188
+ disp[i] = makeasmfunc(lj_bc_ofs[i]);
189
+ } else {
190
+ for (i = GG_LEN_SDISP; i < GG_LEN_DDISP; i++)
191
+ disp[i] = lj_vm_callhook;
192
+ }
193
+ }
194
+ if (!(mode & DISPMODE_CALL)) { /* Overwrite dynamic counting ins. */
195
+ disp[BC_FUNCF] = f_funcf;
196
+ disp[BC_FUNCV] = f_funcv;
197
+ }
198
+
199
+ #if LJ_HASJIT
200
+ /* Reset hotcounts for JIT off to on transition. */
201
+ if ((mode & DISPMODE_JIT) && !(oldmode & DISPMODE_JIT))
202
+ lj_dispatch_init_hotcount(g);
203
+ #endif
204
+ }
205
+ }
206
+
207
+ /* -- JIT mode setting ---------------------------------------------------- */
208
+
209
+ #if LJ_HASJIT
210
+ /* Set JIT mode for a single prototype. */
211
+ static void setptmode(global_State *g, GCproto *pt, int mode)
212
+ {
213
+ if ((mode & LUAJIT_MODE_ON)) { /* (Re-)enable JIT compilation. */
214
+ pt->flags &= ~PROTO_NOJIT;
215
+ lj_trace_reenableproto(pt); /* Unpatch all ILOOP etc. bytecodes. */
216
+ } else { /* Flush and/or disable JIT compilation. */
217
+ if (!(mode & LUAJIT_MODE_FLUSH))
218
+ pt->flags |= PROTO_NOJIT;
219
+ lj_trace_flushproto(g, pt); /* Flush all traces of prototype. */
220
+ }
221
+ }
222
+
223
+ /* Recursively set the JIT mode for all children of a prototype. */
224
+ static void setptmode_all(global_State *g, GCproto *pt, int mode)
225
+ {
226
+ ptrdiff_t i;
227
+ if (!(pt->flags & PROTO_CHILD)) return;
228
+ for (i = -(ptrdiff_t)pt->sizekgc; i < 0; i++) {
229
+ GCobj *o = proto_kgc(pt, i);
230
+ if (o->gch.gct == ~LJ_TPROTO) {
231
+ setptmode(g, gco2pt(o), mode);
232
+ setptmode_all(g, gco2pt(o), mode);
233
+ }
234
+ }
235
+ }
236
+ #endif
237
+
238
+ /* Public API function: control the JIT engine. */
239
+ int luaJIT_setmode(lua_State *L, int idx, int mode)
240
+ {
241
+ global_State *g = G(L);
242
+ int mm = mode & LUAJIT_MODE_MASK;
243
+ lj_trace_abort(g); /* Abort recording on any state change. */
244
+ /* Avoid pulling the rug from under our own feet. */
245
+ if ((g->hookmask & HOOK_GC))
246
+ lj_err_caller(L, LJ_ERR_NOGCMM);
247
+ switch (mm) {
248
+ #if LJ_HASJIT
249
+ case LUAJIT_MODE_ENGINE:
250
+ if ((mode & LUAJIT_MODE_FLUSH)) {
251
+ lj_trace_flushall(L);
252
+ } else {
253
+ if (!(mode & LUAJIT_MODE_ON))
254
+ G2J(g)->flags &= ~(uint32_t)JIT_F_ON;
255
+ #if LJ_TARGET_X86ORX64
256
+ else if ((G2J(g)->flags & JIT_F_SSE2))
257
+ G2J(g)->flags |= (uint32_t)JIT_F_ON;
258
+ else
259
+ return 0; /* Don't turn on JIT compiler without SSE2 support. */
260
+ #else
261
+ else
262
+ G2J(g)->flags |= (uint32_t)JIT_F_ON;
263
+ #endif
264
+ lj_dispatch_update(g);
265
+ }
266
+ break;
267
+ case LUAJIT_MODE_FUNC:
268
+ case LUAJIT_MODE_ALLFUNC:
269
+ case LUAJIT_MODE_ALLSUBFUNC: {
270
+ cTValue *tv = idx == 0 ? frame_prev(L->base-1) :
271
+ idx > 0 ? L->base + (idx-1) : L->top + idx;
272
+ GCproto *pt;
273
+ if ((idx == 0 || tvisfunc(tv)) && isluafunc(&gcval(tv)->fn))
274
+ pt = funcproto(&gcval(tv)->fn); /* Cannot use funcV() for frame slot. */
275
+ else if (tvisproto(tv))
276
+ pt = protoV(tv);
277
+ else
278
+ return 0; /* Failed. */
279
+ if (mm != LUAJIT_MODE_ALLSUBFUNC)
280
+ setptmode(g, pt, mode);
281
+ if (mm != LUAJIT_MODE_FUNC)
282
+ setptmode_all(g, pt, mode);
283
+ break;
284
+ }
285
+ case LUAJIT_MODE_TRACE:
286
+ if (!(mode & LUAJIT_MODE_FLUSH))
287
+ return 0; /* Failed. */
288
+ lj_trace_flush(G2J(g), idx);
289
+ break;
290
+ #else
291
+ case LUAJIT_MODE_ENGINE:
292
+ case LUAJIT_MODE_FUNC:
293
+ case LUAJIT_MODE_ALLFUNC:
294
+ case LUAJIT_MODE_ALLSUBFUNC:
295
+ UNUSED(idx);
296
+ if ((mode & LUAJIT_MODE_ON))
297
+ return 0; /* Failed. */
298
+ break;
299
+ #endif
300
+ case LUAJIT_MODE_WRAPCFUNC:
301
+ if ((mode & LUAJIT_MODE_ON)) {
302
+ if (idx != 0) {
303
+ cTValue *tv = idx > 0 ? L->base + (idx-1) : L->top + idx;
304
+ if (tvislightud(tv))
305
+ g->wrapf = (lua_CFunction)lightudV(tv);
306
+ else
307
+ return 0; /* Failed. */
308
+ } else {
309
+ return 0; /* Failed. */
310
+ }
311
+ g->bc_cfunc_ext = BCINS_AD(BC_FUNCCW, 0, 0);
312
+ } else {
313
+ g->bc_cfunc_ext = BCINS_AD(BC_FUNCC, 0, 0);
314
+ }
315
+ break;
316
+ default:
317
+ return 0; /* Failed. */
318
+ }
319
+ return 1; /* OK. */
320
+ }
321
+
322
+ /* Enforce (dynamic) linker error for version mismatches. See luajit.c. */
323
+ LUA_API void LUAJIT_VERSION_SYM(void)
324
+ {
325
+ }
326
+
327
+ /* -- Hooks --------------------------------------------------------------- */
328
+
329
+ /* This function can be called asynchronously (e.g. during a signal). */
330
+ LUA_API int lua_sethook(lua_State *L, lua_Hook func, int mask, int count)
331
+ {
332
+ global_State *g = G(L);
333
+ mask &= HOOK_EVENTMASK;
334
+ if (func == NULL || mask == 0) { mask = 0; func = NULL; } /* Consistency. */
335
+ g->hookf = func;
336
+ g->hookcount = g->hookcstart = (int32_t)count;
337
+ g->hookmask = (uint8_t)((g->hookmask & ~HOOK_EVENTMASK) | mask);
338
+ lj_trace_abort(g); /* Abort recording on any hook change. */
339
+ lj_dispatch_update(g);
340
+ return 1;
341
+ }
342
+
343
+ LUA_API lua_Hook lua_gethook(lua_State *L)
344
+ {
345
+ return G(L)->hookf;
346
+ }
347
+
348
+ LUA_API int lua_gethookmask(lua_State *L)
349
+ {
350
+ return G(L)->hookmask & HOOK_EVENTMASK;
351
+ }
352
+
353
+ LUA_API int lua_gethookcount(lua_State *L)
354
+ {
355
+ return (int)G(L)->hookcstart;
356
+ }
357
+
358
+ /* Call a hook. */
359
+ static void callhook(lua_State *L, int event, BCLine line)
360
+ {
361
+ global_State *g = G(L);
362
+ lua_Hook hookf = g->hookf;
363
+ if (hookf && !hook_active(g)) {
364
+ lua_Debug ar;
365
+ lj_trace_abort(g); /* Abort recording on any hook call. */
366
+ ar.event = event;
367
+ ar.currentline = line;
368
+ /* Top frame, nextframe = NULL. */
369
+ ar.i_ci = (int)((L->base-1) - tvref(L->stack));
370
+ lj_state_checkstack(L, 1+LUA_MINSTACK);
371
+ #if LJ_HASPROFILE && !LJ_PROFILE_SIGPROF
372
+ lj_profile_hook_enter(g);
373
+ #else
374
+ hook_enter(g);
375
+ #endif
376
+ hookf(L, &ar);
377
+ lua_assert(hook_active(g));
378
+ setgcref(g->cur_L, obj2gco(L));
379
+ #if LJ_HASPROFILE && !LJ_PROFILE_SIGPROF
380
+ lj_profile_hook_leave(g);
381
+ #else
382
+ hook_leave(g);
383
+ #endif
384
+ }
385
+ }
386
+
387
+ /* -- Dispatch callbacks -------------------------------------------------- */
388
+
389
+ /* Calculate number of used stack slots in the current frame. */
390
+ static BCReg cur_topslot(GCproto *pt, const BCIns *pc, uint32_t nres)
391
+ {
392
+ BCIns ins = pc[-1];
393
+ if (bc_op(ins) == BC_UCLO)
394
+ ins = pc[bc_j(ins)];
395
+ switch (bc_op(ins)) {
396
+ case BC_CALLM: case BC_CALLMT: return bc_a(ins) + bc_c(ins) + nres-1+1+LJ_FR2;
397
+ case BC_RETM: return bc_a(ins) + bc_d(ins) + nres-1;
398
+ case BC_TSETM: return bc_a(ins) + nres-1;
399
+ default: return pt->framesize;
400
+ }
401
+ }
402
+
403
+ /* Instruction dispatch. Used by instr/line/return hooks or when recording. */
404
+ void LJ_FASTCALL lj_dispatch_ins(lua_State *L, const BCIns *pc)
405
+ {
406
+ ERRNO_SAVE
407
+ GCfunc *fn = curr_func(L);
408
+ GCproto *pt = funcproto(fn);
409
+ void *cf = cframe_raw(L->cframe);
410
+ const BCIns *oldpc = cframe_pc(cf);
411
+ global_State *g = G(L);
412
+ BCReg slots;
413
+ setcframe_pc(cf, pc);
414
+ slots = cur_topslot(pt, pc, cframe_multres_n(cf));
415
+ L->top = L->base + slots; /* Fix top. */
416
+ #if LJ_HASJIT
417
+ {
418
+ jit_State *J = G2J(g);
419
+ if (J->state != LJ_TRACE_IDLE) {
420
+ #ifdef LUA_USE_ASSERT
421
+ ptrdiff_t delta = L->top - L->base;
422
+ #endif
423
+ J->L = L;
424
+ lj_trace_ins(J, pc-1); /* The interpreter bytecode PC is offset by 1. */
425
+ lua_assert(L->top - L->base == delta);
426
+ }
427
+ }
428
+ #endif
429
+ if ((g->hookmask & LUA_MASKCOUNT) && g->hookcount == 0) {
430
+ g->hookcount = g->hookcstart;
431
+ callhook(L, LUA_HOOKCOUNT, -1);
432
+ L->top = L->base + slots; /* Fix top again. */
433
+ }
434
+ if ((g->hookmask & LUA_MASKLINE)) {
435
+ BCPos npc = proto_bcpos(pt, pc) - 1;
436
+ BCPos opc = proto_bcpos(pt, oldpc) - 1;
437
+ BCLine line = lj_debug_line(pt, npc);
438
+ if (pc <= oldpc || opc >= pt->sizebc || line != lj_debug_line(pt, opc)) {
439
+ callhook(L, LUA_HOOKLINE, line);
440
+ L->top = L->base + slots; /* Fix top again. */
441
+ }
442
+ }
443
+ if ((g->hookmask & LUA_MASKRET) && bc_isret(bc_op(pc[-1])))
444
+ callhook(L, LUA_HOOKRET, -1);
445
+ ERRNO_RESTORE
446
+ }
447
+
448
+ /* Initialize call. Ensure stack space and return # of missing parameters. */
449
+ static int call_init(lua_State *L, GCfunc *fn)
450
+ {
451
+ if (isluafunc(fn)) {
452
+ GCproto *pt = funcproto(fn);
453
+ int numparams = pt->numparams;
454
+ int gotparams = (int)(L->top - L->base);
455
+ int need = pt->framesize;
456
+ if ((pt->flags & PROTO_VARARG)) need += 1+gotparams;
457
+ lj_state_checkstack(L, (MSize)need);
458
+ numparams -= gotparams;
459
+ return numparams >= 0 ? numparams : 0;
460
+ } else {
461
+ lj_state_checkstack(L, LUA_MINSTACK);
462
+ return 0;
463
+ }
464
+ }
465
+
466
+ /* Call dispatch. Used by call hooks, hot calls or when recording. */
467
+ ASMFunction LJ_FASTCALL lj_dispatch_call(lua_State *L, const BCIns *pc)
468
+ {
469
+ ERRNO_SAVE
470
+ GCfunc *fn = curr_func(L);
471
+ BCOp op;
472
+ global_State *g = G(L);
473
+ #if LJ_HASJIT
474
+ jit_State *J = G2J(g);
475
+ #endif
476
+ int missing = call_init(L, fn);
477
+ #if LJ_HASJIT
478
+ J->L = L;
479
+ if ((uintptr_t)pc & 1) { /* Marker for hot call. */
480
+ #ifdef LUA_USE_ASSERT
481
+ ptrdiff_t delta = L->top - L->base;
482
+ #endif
483
+ pc = (const BCIns *)((uintptr_t)pc & ~(uintptr_t)1);
484
+ lj_trace_hot(J, pc);
485
+ lua_assert(L->top - L->base == delta);
486
+ goto out;
487
+ } else if (J->state != LJ_TRACE_IDLE &&
488
+ !(g->hookmask & (HOOK_GC|HOOK_VMEVENT))) {
489
+ #ifdef LUA_USE_ASSERT
490
+ ptrdiff_t delta = L->top - L->base;
491
+ #endif
492
+ /* Record the FUNC* bytecodes, too. */
493
+ lj_trace_ins(J, pc-1); /* The interpreter bytecode PC is offset by 1. */
494
+ lua_assert(L->top - L->base == delta);
495
+ }
496
+ #endif
497
+ if ((g->hookmask & LUA_MASKCALL)) {
498
+ int i;
499
+ for (i = 0; i < missing; i++) /* Add missing parameters. */
500
+ setnilV(L->top++);
501
+ callhook(L, LUA_HOOKCALL, -1);
502
+ /* Preserve modifications of missing parameters by lua_setlocal(). */
503
+ while (missing-- > 0 && tvisnil(L->top - 1))
504
+ L->top--;
505
+ }
506
+ #if LJ_HASJIT
507
+ out:
508
+ #endif
509
+ op = bc_op(pc[-1]); /* Get FUNC* op. */
510
+ #if LJ_HASJIT
511
+ /* Use the non-hotcounting variants if JIT is off or while recording. */
512
+ if ((!(J->flags & JIT_F_ON) || J->state != LJ_TRACE_IDLE) &&
513
+ (op == BC_FUNCF || op == BC_FUNCV))
514
+ op = (BCOp)((int)op+(int)BC_IFUNCF-(int)BC_FUNCF);
515
+ #endif
516
+ ERRNO_RESTORE
517
+ return makeasmfunc(lj_bc_ofs[op]); /* Return static dispatch target. */
518
+ }
519
+
520
+ #if LJ_HASJIT
521
+ /* Stitch a new trace. */
522
+ void LJ_FASTCALL lj_dispatch_stitch(jit_State *J, const BCIns *pc)
523
+ {
524
+ ERRNO_SAVE
525
+ lua_State *L = J->L;
526
+ void *cf = cframe_raw(L->cframe);
527
+ const BCIns *oldpc = cframe_pc(cf);
528
+ setcframe_pc(cf, pc);
529
+ /* Before dispatch, have to bias PC by 1. */
530
+ L->top = L->base + cur_topslot(curr_proto(L), pc+1, cframe_multres_n(cf));
531
+ lj_trace_stitch(J, pc-1); /* Point to the CALL instruction. */
532
+ setcframe_pc(cf, oldpc);
533
+ ERRNO_RESTORE
534
+ }
535
+ #endif
536
+
537
+ #if LJ_HASPROFILE
538
+ /* Profile dispatch. */
539
+ void LJ_FASTCALL lj_dispatch_profile(lua_State *L, const BCIns *pc)
540
+ {
541
+ ERRNO_SAVE
542
+ GCfunc *fn = curr_func(L);
543
+ GCproto *pt = funcproto(fn);
544
+ void *cf = cframe_raw(L->cframe);
545
+ const BCIns *oldpc = cframe_pc(cf);
546
+ global_State *g;
547
+ setcframe_pc(cf, pc);
548
+ L->top = L->base + cur_topslot(pt, pc, cframe_multres_n(cf));
549
+ lj_profile_interpreter(L);
550
+ setcframe_pc(cf, oldpc);
551
+ g = G(L);
552
+ setgcref(g->cur_L, obj2gco(L));
553
+ setvmstate(g, INTERP);
554
+ ERRNO_RESTORE
555
+ }
556
+ #endif
557
+