immunio 1.2.1 → 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (291) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +13 -5
  3. data/ext/immunio/Rakefile +14 -6
  4. data/lib/immunio/context.rb +2 -0
  5. data/lib/immunio/plugins/action_view.rb +7 -668
  6. data/lib/immunio/plugins/action_view/action_view.rb +22 -0
  7. data/lib/immunio/plugins/action_view/active_support_hash.rb +29 -0
  8. data/lib/immunio/plugins/action_view/cache_store.rb +24 -0
  9. data/lib/immunio/plugins/action_view/erubi.rb +38 -0
  10. data/lib/immunio/plugins/action_view/erubis.rb +39 -0
  11. data/lib/immunio/plugins/action_view/fragment_caching.rb +29 -0
  12. data/lib/immunio/plugins/action_view/haml.rb +46 -0
  13. data/lib/immunio/plugins/action_view/slim.rb +42 -0
  14. data/lib/immunio/plugins/action_view/template.rb +431 -0
  15. data/lib/immunio/plugins/action_view/template_rendering.rb +45 -0
  16. data/lib/immunio/plugins/http_tracker.rb +2 -0
  17. data/lib/immunio/plugins/io.rb +34 -0
  18. data/lib/immunio/version.rb +1 -1
  19. data/lua-hooks/Makefile +36 -9
  20. data/lua-hooks/ext/luajit/COPYRIGHT +1 -1
  21. data/lua-hooks/ext/luajit/Makefile +22 -15
  22. data/lua-hooks/ext/luajit/README +2 -2
  23. data/lua-hooks/ext/luajit/doc/bluequad-print.css +1 -1
  24. data/lua-hooks/ext/luajit/doc/bluequad.css +1 -1
  25. data/lua-hooks/ext/luajit/doc/changes.html +69 -3
  26. data/lua-hooks/ext/luajit/doc/contact.html +10 -3
  27. data/lua-hooks/ext/luajit/doc/ext_c_api.html +2 -2
  28. data/lua-hooks/ext/luajit/doc/ext_ffi.html +2 -2
  29. data/lua-hooks/ext/luajit/doc/ext_ffi_api.html +2 -2
  30. data/lua-hooks/ext/luajit/doc/ext_ffi_semantics.html +3 -4
  31. data/lua-hooks/ext/luajit/doc/ext_ffi_tutorial.html +2 -2
  32. data/lua-hooks/ext/luajit/doc/ext_jit.html +3 -3
  33. data/lua-hooks/ext/luajit/doc/ext_profiler.html +2 -2
  34. data/lua-hooks/ext/luajit/doc/extensions.html +47 -20
  35. data/lua-hooks/ext/luajit/doc/faq.html +2 -2
  36. data/lua-hooks/ext/luajit/doc/install.html +74 -45
  37. data/lua-hooks/ext/luajit/doc/luajit.html +5 -5
  38. data/lua-hooks/ext/luajit/doc/running.html +3 -3
  39. data/lua-hooks/ext/luajit/doc/status.html +13 -8
  40. data/lua-hooks/ext/luajit/dynasm/dasm_arm.h +1 -1
  41. data/lua-hooks/ext/luajit/dynasm/dasm_arm.lua +1 -1
  42. data/lua-hooks/ext/luajit/dynasm/dasm_arm64.h +1 -1
  43. data/lua-hooks/ext/luajit/dynasm/dasm_arm64.lua +1 -1
  44. data/lua-hooks/ext/luajit/dynasm/dasm_mips.h +8 -5
  45. data/lua-hooks/ext/luajit/dynasm/dasm_mips.lua +66 -11
  46. data/lua-hooks/ext/luajit/dynasm/dasm_mips64.lua +12 -0
  47. data/lua-hooks/ext/luajit/dynasm/dasm_ppc.h +1 -1
  48. data/lua-hooks/ext/luajit/dynasm/dasm_ppc.lua +1 -1
  49. data/lua-hooks/ext/luajit/dynasm/dasm_proto.h +1 -1
  50. data/lua-hooks/ext/luajit/dynasm/dasm_x64.lua +1 -1
  51. data/lua-hooks/ext/luajit/dynasm/dasm_x86.h +1 -1
  52. data/lua-hooks/ext/luajit/dynasm/dasm_x86.lua +5 -1
  53. data/lua-hooks/ext/luajit/dynasm/dynasm.lua +2 -2
  54. data/lua-hooks/ext/luajit/etc/luajit.1 +1 -1
  55. data/lua-hooks/ext/luajit/etc/luajit.pc +1 -1
  56. data/lua-hooks/ext/luajit/src/Makefile +15 -11
  57. data/lua-hooks/ext/luajit/src/Makefile.dep +16 -16
  58. data/lua-hooks/ext/luajit/src/host/buildvm.c +2 -2
  59. data/lua-hooks/ext/luajit/src/host/buildvm.h +1 -1
  60. data/lua-hooks/ext/luajit/src/host/buildvm_asm.c +9 -4
  61. data/lua-hooks/ext/luajit/src/host/buildvm_fold.c +2 -2
  62. data/lua-hooks/ext/luajit/src/host/buildvm_lib.c +1 -1
  63. data/lua-hooks/ext/luajit/src/host/buildvm_libbc.h +14 -3
  64. data/lua-hooks/ext/luajit/src/host/buildvm_peobj.c +27 -3
  65. data/lua-hooks/ext/luajit/src/host/genlibbc.lua +1 -1
  66. data/lua-hooks/ext/luajit/src/host/genminilua.lua +6 -5
  67. data/lua-hooks/ext/luajit/src/host/minilua.c +1 -1
  68. data/lua-hooks/ext/luajit/src/jit/bc.lua +1 -1
  69. data/lua-hooks/ext/luajit/src/jit/bcsave.lua +8 -8
  70. data/lua-hooks/ext/luajit/src/jit/dis_arm.lua +2 -2
  71. data/lua-hooks/ext/luajit/src/jit/dis_arm64.lua +1216 -0
  72. data/lua-hooks/ext/luajit/src/jit/dis_arm64be.lua +12 -0
  73. data/lua-hooks/ext/luajit/src/jit/dis_mips.lua +35 -20
  74. data/lua-hooks/ext/luajit/src/jit/dis_mips64.lua +17 -0
  75. data/lua-hooks/ext/luajit/src/jit/dis_mips64el.lua +17 -0
  76. data/lua-hooks/ext/luajit/src/jit/dis_mipsel.lua +1 -1
  77. data/lua-hooks/ext/luajit/src/jit/dis_ppc.lua +2 -2
  78. data/lua-hooks/ext/luajit/src/jit/dis_x64.lua +1 -1
  79. data/lua-hooks/ext/luajit/src/jit/dis_x86.lua +7 -4
  80. data/lua-hooks/ext/luajit/src/jit/dump.lua +17 -12
  81. data/lua-hooks/ext/luajit/src/jit/p.lua +3 -2
  82. data/lua-hooks/ext/luajit/src/jit/v.lua +2 -2
  83. data/lua-hooks/ext/luajit/src/jit/zone.lua +1 -1
  84. data/lua-hooks/ext/luajit/src/lauxlib.h +14 -20
  85. data/lua-hooks/ext/luajit/src/lib_aux.c +38 -27
  86. data/lua-hooks/ext/luajit/src/lib_base.c +12 -5
  87. data/lua-hooks/ext/luajit/src/lib_bit.c +1 -1
  88. data/lua-hooks/ext/luajit/src/lib_debug.c +5 -5
  89. data/lua-hooks/ext/luajit/src/lib_ffi.c +2 -2
  90. data/lua-hooks/ext/luajit/src/lib_init.c +16 -16
  91. data/lua-hooks/ext/luajit/src/lib_io.c +6 -7
  92. data/lua-hooks/ext/luajit/src/lib_jit.c +14 -4
  93. data/lua-hooks/ext/luajit/src/lib_math.c +1 -5
  94. data/lua-hooks/ext/luajit/src/lib_os.c +1 -1
  95. data/lua-hooks/ext/luajit/src/lib_package.c +14 -23
  96. data/lua-hooks/ext/luajit/src/lib_string.c +1 -5
  97. data/lua-hooks/ext/luajit/src/lib_table.c +21 -1
  98. data/lua-hooks/ext/luajit/src/lj.supp +3 -3
  99. data/lua-hooks/ext/luajit/src/lj_alloc.c +174 -83
  100. data/lua-hooks/ext/luajit/src/lj_api.c +97 -18
  101. data/lua-hooks/ext/luajit/src/lj_arch.h +54 -22
  102. data/lua-hooks/ext/luajit/src/lj_asm.c +172 -53
  103. data/lua-hooks/ext/luajit/src/lj_asm.h +1 -1
  104. data/lua-hooks/ext/luajit/src/lj_asm_arm.h +19 -16
  105. data/lua-hooks/ext/luajit/src/lj_asm_arm64.h +2022 -0
  106. data/lua-hooks/ext/luajit/src/lj_asm_mips.h +564 -158
  107. data/lua-hooks/ext/luajit/src/lj_asm_ppc.h +19 -18
  108. data/lua-hooks/ext/luajit/src/lj_asm_x86.h +578 -92
  109. data/lua-hooks/ext/luajit/src/lj_bc.c +1 -1
  110. data/lua-hooks/ext/luajit/src/lj_bc.h +1 -1
  111. data/lua-hooks/ext/luajit/src/lj_bcdump.h +1 -1
  112. data/lua-hooks/ext/luajit/src/lj_bcread.c +1 -1
  113. data/lua-hooks/ext/luajit/src/lj_bcwrite.c +1 -1
  114. data/lua-hooks/ext/luajit/src/lj_buf.c +1 -1
  115. data/lua-hooks/ext/luajit/src/lj_buf.h +1 -1
  116. data/lua-hooks/ext/luajit/src/lj_carith.c +1 -1
  117. data/lua-hooks/ext/luajit/src/lj_carith.h +1 -1
  118. data/lua-hooks/ext/luajit/src/lj_ccall.c +172 -7
  119. data/lua-hooks/ext/luajit/src/lj_ccall.h +21 -5
  120. data/lua-hooks/ext/luajit/src/lj_ccallback.c +71 -17
  121. data/lua-hooks/ext/luajit/src/lj_ccallback.h +1 -1
  122. data/lua-hooks/ext/luajit/src/lj_cconv.c +4 -2
  123. data/lua-hooks/ext/luajit/src/lj_cconv.h +1 -1
  124. data/lua-hooks/ext/luajit/src/lj_cdata.c +7 -5
  125. data/lua-hooks/ext/luajit/src/lj_cdata.h +1 -1
  126. data/lua-hooks/ext/luajit/src/lj_clib.c +5 -5
  127. data/lua-hooks/ext/luajit/src/lj_clib.h +1 -1
  128. data/lua-hooks/ext/luajit/src/lj_cparse.c +11 -6
  129. data/lua-hooks/ext/luajit/src/lj_cparse.h +1 -1
  130. data/lua-hooks/ext/luajit/src/lj_crecord.c +70 -14
  131. data/lua-hooks/ext/luajit/src/lj_crecord.h +1 -1
  132. data/lua-hooks/ext/luajit/src/lj_ctype.c +1 -1
  133. data/lua-hooks/ext/luajit/src/lj_ctype.h +8 -8
  134. data/lua-hooks/ext/luajit/src/lj_debug.c +1 -1
  135. data/lua-hooks/ext/luajit/src/lj_debug.h +1 -1
  136. data/lua-hooks/ext/luajit/src/lj_def.h +6 -9
  137. data/lua-hooks/ext/luajit/src/lj_dispatch.c +3 -3
  138. data/lua-hooks/ext/luajit/src/lj_dispatch.h +2 -1
  139. data/lua-hooks/ext/luajit/src/lj_emit_arm.h +5 -4
  140. data/lua-hooks/ext/luajit/src/lj_emit_arm64.h +419 -0
  141. data/lua-hooks/ext/luajit/src/lj_emit_mips.h +100 -20
  142. data/lua-hooks/ext/luajit/src/lj_emit_ppc.h +4 -4
  143. data/lua-hooks/ext/luajit/src/lj_emit_x86.h +116 -25
  144. data/lua-hooks/ext/luajit/src/lj_err.c +34 -13
  145. data/lua-hooks/ext/luajit/src/lj_err.h +1 -1
  146. data/lua-hooks/ext/luajit/src/lj_errmsg.h +1 -1
  147. data/lua-hooks/ext/luajit/src/lj_ff.h +1 -1
  148. data/lua-hooks/ext/luajit/src/lj_ffrecord.c +58 -49
  149. data/lua-hooks/ext/luajit/src/lj_ffrecord.h +1 -1
  150. data/lua-hooks/ext/luajit/src/lj_frame.h +33 -6
  151. data/lua-hooks/ext/luajit/src/lj_func.c +4 -2
  152. data/lua-hooks/ext/luajit/src/lj_func.h +1 -1
  153. data/lua-hooks/ext/luajit/src/lj_gc.c +16 -7
  154. data/lua-hooks/ext/luajit/src/lj_gc.h +1 -1
  155. data/lua-hooks/ext/luajit/src/lj_gdbjit.c +31 -1
  156. data/lua-hooks/ext/luajit/src/lj_gdbjit.h +1 -1
  157. data/lua-hooks/ext/luajit/src/lj_ir.c +69 -96
  158. data/lua-hooks/ext/luajit/src/lj_ir.h +29 -18
  159. data/lua-hooks/ext/luajit/src/lj_ircall.h +24 -30
  160. data/lua-hooks/ext/luajit/src/lj_iropt.h +9 -9
  161. data/lua-hooks/ext/luajit/src/lj_jit.h +67 -9
  162. data/lua-hooks/ext/luajit/src/lj_lex.c +1 -1
  163. data/lua-hooks/ext/luajit/src/lj_lex.h +1 -1
  164. data/lua-hooks/ext/luajit/src/lj_lib.c +1 -1
  165. data/lua-hooks/ext/luajit/src/lj_lib.h +1 -1
  166. data/lua-hooks/ext/luajit/src/lj_load.c +1 -1
  167. data/lua-hooks/ext/luajit/src/lj_mcode.c +11 -10
  168. data/lua-hooks/ext/luajit/src/lj_mcode.h +1 -1
  169. data/lua-hooks/ext/luajit/src/lj_meta.c +1 -1
  170. data/lua-hooks/ext/luajit/src/lj_meta.h +1 -1
  171. data/lua-hooks/ext/luajit/src/lj_obj.c +1 -1
  172. data/lua-hooks/ext/luajit/src/lj_obj.h +7 -3
  173. data/lua-hooks/ext/luajit/src/lj_opt_dce.c +1 -1
  174. data/lua-hooks/ext/luajit/src/lj_opt_fold.c +84 -17
  175. data/lua-hooks/ext/luajit/src/lj_opt_loop.c +1 -1
  176. data/lua-hooks/ext/luajit/src/lj_opt_mem.c +3 -3
  177. data/lua-hooks/ext/luajit/src/lj_opt_narrow.c +24 -22
  178. data/lua-hooks/ext/luajit/src/lj_opt_sink.c +11 -6
  179. data/lua-hooks/ext/luajit/src/lj_opt_split.c +11 -2
  180. data/lua-hooks/ext/luajit/src/lj_parse.c +9 -7
  181. data/lua-hooks/ext/luajit/src/lj_parse.h +1 -1
  182. data/lua-hooks/ext/luajit/src/lj_profile.c +1 -1
  183. data/lua-hooks/ext/luajit/src/lj_profile.h +1 -1
  184. data/lua-hooks/ext/luajit/src/lj_record.c +201 -117
  185. data/lua-hooks/ext/luajit/src/lj_record.h +1 -1
  186. data/lua-hooks/ext/luajit/src/lj_snap.c +72 -26
  187. data/lua-hooks/ext/luajit/src/lj_snap.h +1 -1
  188. data/lua-hooks/ext/luajit/src/lj_state.c +6 -6
  189. data/lua-hooks/ext/luajit/src/lj_state.h +2 -2
  190. data/lua-hooks/ext/luajit/src/lj_str.c +1 -1
  191. data/lua-hooks/ext/luajit/src/lj_str.h +1 -1
  192. data/lua-hooks/ext/luajit/src/lj_strfmt.c +7 -3
  193. data/lua-hooks/ext/luajit/src/lj_strfmt.h +1 -1
  194. data/lua-hooks/ext/luajit/src/lj_strfmt_num.c +4 -3
  195. data/lua-hooks/ext/luajit/src/lj_strscan.c +1 -1
  196. data/lua-hooks/ext/luajit/src/lj_strscan.h +1 -1
  197. data/lua-hooks/ext/luajit/src/lj_tab.c +1 -2
  198. data/lua-hooks/ext/luajit/src/lj_tab.h +1 -1
  199. data/lua-hooks/ext/luajit/src/lj_target.h +3 -3
  200. data/lua-hooks/ext/luajit/src/lj_target_arm.h +1 -1
  201. data/lua-hooks/ext/luajit/src/lj_target_arm64.h +239 -7
  202. data/lua-hooks/ext/luajit/src/lj_target_mips.h +111 -22
  203. data/lua-hooks/ext/luajit/src/lj_target_ppc.h +1 -1
  204. data/lua-hooks/ext/luajit/src/lj_target_x86.h +21 -4
  205. data/lua-hooks/ext/luajit/src/lj_trace.c +63 -18
  206. data/lua-hooks/ext/luajit/src/lj_trace.h +2 -1
  207. data/lua-hooks/ext/luajit/src/lj_traceerr.h +1 -1
  208. data/lua-hooks/ext/luajit/src/lj_udata.c +1 -1
  209. data/lua-hooks/ext/luajit/src/lj_udata.h +1 -1
  210. data/lua-hooks/ext/luajit/src/lj_vm.h +5 -1
  211. data/lua-hooks/ext/luajit/src/lj_vmevent.c +1 -1
  212. data/lua-hooks/ext/luajit/src/lj_vmevent.h +1 -1
  213. data/lua-hooks/ext/luajit/src/lj_vmmath.c +1 -1
  214. data/lua-hooks/ext/luajit/src/ljamalg.c +1 -1
  215. data/lua-hooks/ext/luajit/src/lua.h +9 -1
  216. data/lua-hooks/ext/luajit/src/luaconf.h +3 -7
  217. data/lua-hooks/ext/luajit/src/luajit.c +69 -54
  218. data/lua-hooks/ext/luajit/src/luajit.h +4 -4
  219. data/lua-hooks/ext/luajit/src/lualib.h +1 -1
  220. data/lua-hooks/ext/luajit/src/msvcbuild.bat +12 -4
  221. data/lua-hooks/ext/luajit/src/vm_arm.dasc +1 -1
  222. data/lua-hooks/ext/luajit/src/vm_arm64.dasc +255 -32
  223. data/lua-hooks/ext/luajit/src/vm_mips.dasc +26 -23
  224. data/lua-hooks/ext/luajit/src/vm_mips64.dasc +5062 -0
  225. data/lua-hooks/ext/luajit/src/vm_ppc.dasc +1 -1
  226. data/lua-hooks/ext/luajit/src/vm_x64.dasc +24 -25
  227. data/lua-hooks/ext/luajit/src/vm_x86.dasc +77 -4
  228. data/lua-hooks/libluahooks.darwin.a +0 -0
  229. data/lua-hooks/libluahooks.linux.a +0 -0
  230. data/lua-hooks/options.mk +1 -1
  231. metadata +37 -77
  232. data/lua-hooks/ext/all.c +0 -69
  233. data/lua-hooks/ext/libinjection/COPYING +0 -37
  234. data/lua-hooks/ext/libinjection/libinjection.h +0 -65
  235. data/lua-hooks/ext/libinjection/libinjection_html5.c +0 -847
  236. data/lua-hooks/ext/libinjection/libinjection_html5.h +0 -54
  237. data/lua-hooks/ext/libinjection/libinjection_sqli.c +0 -2301
  238. data/lua-hooks/ext/libinjection/libinjection_sqli.h +0 -295
  239. data/lua-hooks/ext/libinjection/libinjection_sqli_data.h +0 -9349
  240. data/lua-hooks/ext/libinjection/libinjection_xss.c +0 -531
  241. data/lua-hooks/ext/libinjection/libinjection_xss.h +0 -21
  242. data/lua-hooks/ext/libinjection/lualib.c +0 -145
  243. data/lua-hooks/ext/libinjection/module.mk +0 -5
  244. data/lua-hooks/ext/lpeg/HISTORY +0 -96
  245. data/lua-hooks/ext/lpeg/lpcap.c +0 -537
  246. data/lua-hooks/ext/lpeg/lpcap.h +0 -56
  247. data/lua-hooks/ext/lpeg/lpcode.c +0 -1014
  248. data/lua-hooks/ext/lpeg/lpcode.h +0 -40
  249. data/lua-hooks/ext/lpeg/lpeg-128.gif +0 -0
  250. data/lua-hooks/ext/lpeg/lpeg.html +0 -1445
  251. data/lua-hooks/ext/lpeg/lpprint.c +0 -244
  252. data/lua-hooks/ext/lpeg/lpprint.h +0 -36
  253. data/lua-hooks/ext/lpeg/lptree.c +0 -1303
  254. data/lua-hooks/ext/lpeg/lptree.h +0 -82
  255. data/lua-hooks/ext/lpeg/lptypes.h +0 -149
  256. data/lua-hooks/ext/lpeg/lpvm.c +0 -364
  257. data/lua-hooks/ext/lpeg/lpvm.h +0 -58
  258. data/lua-hooks/ext/lpeg/makefile +0 -55
  259. data/lua-hooks/ext/lpeg/module.mk +0 -6
  260. data/lua-hooks/ext/lpeg/re.html +0 -498
  261. data/lua-hooks/ext/lua-cmsgpack/.gitignore +0 -13
  262. data/lua-hooks/ext/lua-cmsgpack/CMakeLists.txt +0 -45
  263. data/lua-hooks/ext/lua-cmsgpack/README.md +0 -115
  264. data/lua-hooks/ext/lua-cmsgpack/lua_cmsgpack.c +0 -970
  265. data/lua-hooks/ext/lua-cmsgpack/module.mk +0 -2
  266. data/lua-hooks/ext/lua-cmsgpack/test.lua +0 -570
  267. data/lua-hooks/ext/lua-snapshot/LICENSE +0 -7
  268. data/lua-hooks/ext/lua-snapshot/Makefile +0 -12
  269. data/lua-hooks/ext/lua-snapshot/README.md +0 -18
  270. data/lua-hooks/ext/lua-snapshot/dump.lua +0 -15
  271. data/lua-hooks/ext/lua-snapshot/module.mk +0 -2
  272. data/lua-hooks/ext/lua-snapshot/snapshot.c +0 -462
  273. data/lua-hooks/ext/luautf8/README.md +0 -152
  274. data/lua-hooks/ext/luautf8/lutf8lib.c +0 -1274
  275. data/lua-hooks/ext/luautf8/module.mk +0 -2
  276. data/lua-hooks/ext/luautf8/unidata.h +0 -3064
  277. data/lua-hooks/ext/module.mk +0 -15
  278. data/lua-hooks/ext/modules.h +0 -17
  279. data/lua-hooks/ext/perf/luacpu.c +0 -114
  280. data/lua-hooks/ext/perf/lualoadavg.c +0 -40
  281. data/lua-hooks/ext/perf/luameminfo.c +0 -38
  282. data/lua-hooks/ext/perf/luaoslib.c +0 -203
  283. data/lua-hooks/ext/perf/module.mk +0 -5
  284. data/lua-hooks/ext/sha1/luasha1.c +0 -74
  285. data/lua-hooks/ext/sha1/module.mk +0 -5
  286. data/lua-hooks/ext/sha1/sha1.c +0 -145
  287. data/lua-hooks/ext/sha2/luasha256.c +0 -77
  288. data/lua-hooks/ext/sha2/module.mk +0 -5
  289. data/lua-hooks/ext/sha2/sha256.c +0 -196
  290. data/lua-hooks/ext/sysutils/lua_utils.c +0 -56
  291. data/lua-hooks/ext/sysutils/module.mk +0 -2
@@ -1,6 +1,6 @@
1
1
  /*
2
2
  ** Definitions for PPC CPUs.
3
- ** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h
3
+ ** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
4
4
  */
5
5
 
6
6
  #ifndef _LJ_TARGET_PPC_H
@@ -1,6 +1,6 @@
1
1
  /*
2
2
  ** Definitions for x86 and x64 CPUs.
3
- ** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h
3
+ ** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
4
4
  */
5
5
 
6
6
  #ifndef _LJ_TARGET_X86_H
@@ -22,7 +22,7 @@
22
22
  _(XMM0) _(XMM1) _(XMM2) _(XMM3) _(XMM4) _(XMM5) _(XMM6) _(XMM7)
23
23
  #endif
24
24
  #define VRIDDEF(_) \
25
- _(MRM)
25
+ _(MRM) _(RIP)
26
26
 
27
27
  #define RIDENUM(name) RID_##name,
28
28
 
@@ -31,6 +31,7 @@ enum {
31
31
  FPRDEF(RIDENUM) /* Floating-point registers (FPRs). */
32
32
  RID_MAX,
33
33
  RID_MRM = RID_MAX, /* Pseudo-id for ModRM operand. */
34
+ RID_RIP = RID_MAX+5, /* Pseudo-id for RIP (x64 only), rm bits = 5. */
34
35
 
35
36
  /* Calling conventions. */
36
37
  RID_SP = RID_ESP,
@@ -63,8 +64,10 @@ enum {
63
64
 
64
65
  /* -- Register sets ------------------------------------------------------- */
65
66
 
66
- /* Make use of all registers, except the stack pointer. */
67
- #define RSET_GPR (RSET_RANGE(RID_MIN_GPR, RID_MAX_GPR)-RID2RSET(RID_ESP))
67
+ /* Make use of all registers, except the stack pointer (and maybe DISPATCH). */
68
+ #define RSET_GPR (RSET_RANGE(RID_MIN_GPR, RID_MAX_GPR) \
69
+ - RID2RSET(RID_ESP) \
70
+ - LJ_GC64*RID2RSET(RID_DISPATCH))
68
71
  #define RSET_FPR (RSET_RANGE(RID_MIN_FPR, RID_MAX_FPR))
69
72
  #define RSET_ALL (RSET_GPR|RSET_FPR)
70
73
  #define RSET_INIT RSET_ALL
@@ -189,12 +192,18 @@ typedef struct {
189
192
  #define XO_f20f(o) ((uint32_t)(0x0ff2fc + (0x##o<<24)))
190
193
  #define XO_f30f(o) ((uint32_t)(0x0ff3fc + (0x##o<<24)))
191
194
 
195
+ #define XV_660f38(o) ((uint32_t)(0x79e2c4 + (0x##o<<24)))
196
+ #define XV_f20f38(o) ((uint32_t)(0x7be2c4 + (0x##o<<24)))
197
+ #define XV_f20f3a(o) ((uint32_t)(0x7be3c4 + (0x##o<<24)))
198
+ #define XV_f30f38(o) ((uint32_t)(0x7ae2c4 + (0x##o<<24)))
199
+
192
200
  /* This list of x86 opcodes is not intended to be complete. Opcodes are only
193
201
  ** included when needed. Take a look at DynASM or jit.dis_x86 to see the
194
202
  ** whole mess.
195
203
  */
196
204
  typedef enum {
197
205
  /* Fixed length opcodes. XI_* prefix. */
206
+ XI_O16 = 0x66,
198
207
  XI_NOP = 0x90,
199
208
  XI_XCHGa = 0x90,
200
209
  XI_CALL = 0xe8,
@@ -212,6 +221,7 @@ typedef enum {
212
221
  XI_PUSHi8 = 0x6a,
213
222
  XI_TESTb = 0x84,
214
223
  XI_TEST = 0x85,
224
+ XI_INT3 = 0xcc,
215
225
  XI_MOVmi = 0xc7,
216
226
  XI_GROUP5 = 0xff,
217
227
 
@@ -231,7 +241,14 @@ typedef enum {
231
241
  XI_FSCALE = 0xfdd9,
232
242
  XI_FYL2X = 0xf1d9,
233
243
 
244
+ /* VEX-encoded instructions. XV_* prefix. */
245
+ XV_RORX = XV_f20f3a(f0),
246
+ XV_SARX = XV_f30f38(f7),
247
+ XV_SHLX = XV_660f38(f7),
248
+ XV_SHRX = XV_f20f38(f7),
249
+
234
250
  /* Variable-length opcodes. XO_* prefix. */
251
+ XO_OR = XO_(0b),
235
252
  XO_MOV = XO_(8b),
236
253
  XO_MOVto = XO_(89),
237
254
  XO_MOVtow = XO_66(89),
@@ -1,6 +1,6 @@
1
1
  /*
2
2
  ** Trace management.
3
- ** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h
3
+ ** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
4
4
  */
5
5
 
6
6
  #define lj_trace_c
@@ -117,15 +117,26 @@ static void perftools_addtrace(GCtrace *T)
117
117
  }
118
118
  #endif
119
119
 
120
- /* Allocate space for copy of trace. */
121
- static GCtrace *trace_save_alloc(jit_State *J)
120
+ /* Allocate space for copy of T. */
121
+ GCtrace * LJ_FASTCALL lj_trace_alloc(lua_State *L, GCtrace *T)
122
122
  {
123
123
  size_t sztr = ((sizeof(GCtrace)+7)&~7);
124
- size_t szins = (J->cur.nins-J->cur.nk)*sizeof(IRIns);
124
+ size_t szins = (T->nins-T->nk)*sizeof(IRIns);
125
125
  size_t sz = sztr + szins +
126
- J->cur.nsnap*sizeof(SnapShot) +
127
- J->cur.nsnapmap*sizeof(SnapEntry);
128
- return lj_mem_newt(J->L, (MSize)sz, GCtrace);
126
+ T->nsnap*sizeof(SnapShot) +
127
+ T->nsnapmap*sizeof(SnapEntry);
128
+ GCtrace *T2 = lj_mem_newt(L, (MSize)sz, GCtrace);
129
+ char *p = (char *)T2 + sztr;
130
+ T2->gct = ~LJ_TTRACE;
131
+ T2->marked = 0;
132
+ T2->traceno = 0;
133
+ T2->ir = (IRIns *)p - T->nk;
134
+ T2->nins = T->nins;
135
+ T2->nk = T->nk;
136
+ T2->nsnap = T->nsnap;
137
+ T2->nsnapmap = T->nsnapmap;
138
+ memcpy(p, T->ir + T->nk, szins);
139
+ return T2;
129
140
  }
130
141
 
131
142
  /* Save current trace by copying and compacting it. */
@@ -139,12 +150,12 @@ static void trace_save(jit_State *J, GCtrace *T)
139
150
  setgcrefp(J2G(J)->gc.root, T);
140
151
  newwhite(J2G(J), T);
141
152
  T->gct = ~LJ_TTRACE;
142
- T->ir = (IRIns *)p - J->cur.nk;
143
- memcpy(p, J->cur.ir+J->cur.nk, szins);
153
+ T->ir = (IRIns *)p - J->cur.nk; /* The IR has already been copied above. */
144
154
  p += szins;
145
155
  TRACE_APPENDVEC(snap, nsnap, SnapShot)
146
156
  TRACE_APPENDVEC(snapmap, nsnapmap, SnapEntry)
147
157
  J->cur.traceno = 0;
158
+ J->curfinal = NULL;
148
159
  setgcrefp(J->trace[T->traceno], T);
149
160
  lj_gc_barriertrace(J2G(J), T->traceno);
150
161
  lj_gdbjit_addtrace(J, T);
@@ -284,7 +295,6 @@ int lj_trace_flushall(lua_State *L)
284
295
  memset(J->penalty, 0, sizeof(J->penalty));
285
296
  /* Free the whole machine code and invalidate all exit stub groups. */
286
297
  lj_mcode_free(J);
287
- lj_ir_k64_freeall(J);
288
298
  memset(J->exitstubgroup, 0, sizeof(J->exitstubgroup));
289
299
  lj_vmevent_send(L, TRACE,
290
300
  setstrV(L, L->top++, lj_str_newlit(L, "flush"));
@@ -297,13 +307,42 @@ void lj_trace_initstate(global_State *g)
297
307
  {
298
308
  jit_State *J = G2J(g);
299
309
  TValue *tv;
300
- /* Initialize SIMD constants. */
310
+
311
+ /* Initialize aligned SIMD constants. */
301
312
  tv = LJ_KSIMD(J, LJ_KSIMD_ABS);
302
313
  tv[0].u64 = U64x(7fffffff,ffffffff);
303
314
  tv[1].u64 = U64x(7fffffff,ffffffff);
304
315
  tv = LJ_KSIMD(J, LJ_KSIMD_NEG);
305
316
  tv[0].u64 = U64x(80000000,00000000);
306
317
  tv[1].u64 = U64x(80000000,00000000);
318
+
319
+ /* Initialize 32/64 bit constants. */
320
+ #if LJ_TARGET_X86ORX64
321
+ J->k64[LJ_K64_TOBIT].u64 = U64x(43380000,00000000);
322
+ #if LJ_32
323
+ J->k64[LJ_K64_M2P64_31].u64 = U64x(c1e00000,00000000);
324
+ #endif
325
+ J->k64[LJ_K64_2P64].u64 = U64x(43f00000,00000000);
326
+ J->k32[LJ_K32_M2P64_31] = LJ_64 ? 0xdf800000 : 0xcf000000;
327
+ #endif
328
+ #if LJ_TARGET_X86ORX64 || LJ_TARGET_MIPS64
329
+ J->k64[LJ_K64_M2P64].u64 = U64x(c3f00000,00000000);
330
+ #endif
331
+ #if LJ_TARGET_PPC
332
+ J->k32[LJ_K32_2P52_2P31] = 0x59800004;
333
+ J->k32[LJ_K32_2P52] = 0x59800000;
334
+ #endif
335
+ #if LJ_TARGET_PPC || LJ_TARGET_MIPS
336
+ J->k32[LJ_K32_2P31] = 0x4f000000;
337
+ #endif
338
+ #if LJ_TARGET_MIPS
339
+ J->k64[LJ_K64_2P31].u64 = U64x(41e00000,00000000);
340
+ #if LJ_64
341
+ J->k64[LJ_K64_2P63].u64 = U64x(43e00000,00000000);
342
+ J->k32[LJ_K32_2P63] = 0x5f000000;
343
+ J->k32[LJ_K32_M2P64] = 0xdf800000;
344
+ #endif
345
+ #endif
307
346
  }
308
347
 
309
348
  /* Free everything associated with the JIT compiler state. */
@@ -318,7 +357,6 @@ void lj_trace_freestate(global_State *g)
318
357
  }
319
358
  #endif
320
359
  lj_mcode_free(J);
321
- lj_ir_k64_freeall(J);
322
360
  lj_mem_freevec(g, J->snapmapbuf, J->sizesnapmap, SnapEntry);
323
361
  lj_mem_freevec(g, J->snapbuf, J->sizesnap, SnapShot);
324
362
  lj_mem_freevec(g, J->irbuf + J->irbotlim, J->irtoplim - J->irbotlim, IRIns);
@@ -403,7 +441,7 @@ static void trace_start(jit_State *J)
403
441
  J->postproc = LJ_POST_NONE;
404
442
  lj_resetsplit(J);
405
443
  J->retryrec = 0;
406
- J->ktracep = NULL;
444
+ J->ktrace = 0;
407
445
  setgcref(J->cur.startpt, obj2gco(J->pt));
408
446
 
409
447
  L = J->L;
@@ -415,6 +453,12 @@ static void trace_start(jit_State *J)
415
453
  if (J->parent) {
416
454
  setintV(L->top++, J->parent);
417
455
  setintV(L->top++, J->exitno);
456
+ } else {
457
+ BCOp op = bc_op(*J->pc);
458
+ if (op == BC_CALLM || op == BC_CALL || op == BC_ITERC) {
459
+ setintV(L->top++, J->exitno); /* Parent of stitched trace. */
460
+ setintV(L->top++, -1);
461
+ }
418
462
  }
419
463
  );
420
464
  lj_record_setup(J);
@@ -427,7 +471,7 @@ static void trace_stop(jit_State *J)
427
471
  BCOp op = bc_op(J->cur.startins);
428
472
  GCproto *pt = &gcref(J->cur.startpt)->pt;
429
473
  TraceNo traceno = J->cur.traceno;
430
- GCtrace *T = trace_save_alloc(J); /* Do this first. May throw OOM. */
474
+ GCtrace *T = J->curfinal;
431
475
  lua_State *L;
432
476
 
433
477
  switch (op) {
@@ -479,9 +523,6 @@ static void trace_stop(jit_State *J)
479
523
  lj_mcode_commit(J, J->cur.mcode);
480
524
  J->postproc = LJ_POST_NONE;
481
525
  trace_save(J, T);
482
- if (J->ktracep) { /* Patch K64Array slot with the final GCtrace pointer. */
483
- setgcV(J->L, J->ktracep, obj2gco(T), LJ_TTRACE);
484
- }
485
526
 
486
527
  L = J->L;
487
528
  lj_vmevent_send(L, TRACE,
@@ -515,6 +556,10 @@ static int trace_abort(jit_State *J)
515
556
 
516
557
  J->postproc = LJ_POST_NONE;
517
558
  lj_mcode_abort(J);
559
+ if (J->curfinal) {
560
+ lj_trace_free(J2G(J), J->curfinal);
561
+ J->curfinal = NULL;
562
+ }
518
563
  if (tvisnumber(L->top-1))
519
564
  e = (TraceError)numberVint(L->top-1);
520
565
  if (e == LJ_TRERR_MCODELM) {
@@ -849,7 +894,7 @@ int LJ_FASTCALL lj_trace_exit(jit_State *J, void *exptr)
849
894
  ERRNO_RESTORE
850
895
  switch (bc_op(*pc)) {
851
896
  case BC_CALLM: case BC_CALLMT:
852
- return (int)((BCReg)(L->top - L->base) - bc_a(*pc) - bc_c(*pc) + LJ_FR2);
897
+ return (int)((BCReg)(L->top - L->base) - bc_a(*pc) - bc_c(*pc) - LJ_FR2);
853
898
  case BC_RETM:
854
899
  return (int)((BCReg)(L->top - L->base) + 1 - bc_a(*pc) - bc_d(*pc));
855
900
  case BC_TSETM:
@@ -1,6 +1,6 @@
1
1
  /*
2
2
  ** Trace management.
3
- ** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h
3
+ ** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
4
4
  */
5
5
 
6
6
  #ifndef _LJ_TRACE_H
@@ -23,6 +23,7 @@ LJ_FUNC_NORET void lj_trace_err(jit_State *J, TraceError e);
23
23
  LJ_FUNC_NORET void lj_trace_err_info(jit_State *J, TraceError e);
24
24
 
25
25
  /* Trace management. */
26
+ LJ_FUNC GCtrace * LJ_FASTCALL lj_trace_alloc(lua_State *L, GCtrace *T);
26
27
  LJ_FUNC void LJ_FASTCALL lj_trace_free(global_State *g, GCtrace *T);
27
28
  LJ_FUNC void lj_trace_reenableproto(GCproto *pt);
28
29
  LJ_FUNC void lj_trace_flushproto(global_State *g, GCproto *pt);
@@ -1,6 +1,6 @@
1
1
  /*
2
2
  ** Trace compiler error messages.
3
- ** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h
3
+ ** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
4
4
  */
5
5
 
6
6
  /* This file may be included multiple times with different TREDEF macros. */
@@ -1,6 +1,6 @@
1
1
  /*
2
2
  ** Userdata handling.
3
- ** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h
3
+ ** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
4
4
  */
5
5
 
6
6
  #define lj_udata_c
@@ -1,6 +1,6 @@
1
1
  /*
2
2
  ** Userdata handling.
3
- ** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h
3
+ ** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
4
4
  */
5
5
 
6
6
  #ifndef _LJ_UDATA_H
@@ -1,6 +1,6 @@
1
1
  /*
2
2
  ** Assembler VM interface definitions.
3
- ** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h
3
+ ** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
4
4
  */
5
5
 
6
6
  #ifndef _LJ_VM_H
@@ -17,6 +17,10 @@ LJ_ASMF int lj_vm_cpcall(lua_State *L, lua_CFunction func, void *ud,
17
17
  LJ_ASMF int lj_vm_resume(lua_State *L, TValue *base, int nres1, ptrdiff_t ef);
18
18
  LJ_ASMF_NORET void LJ_FASTCALL lj_vm_unwind_c(void *cframe, int errcode);
19
19
  LJ_ASMF_NORET void LJ_FASTCALL lj_vm_unwind_ff(void *cframe);
20
+ #if LJ_ABI_WIN && LJ_TARGET_X86
21
+ LJ_ASMF_NORET void LJ_FASTCALL lj_vm_rtlunwind(void *cframe, void *excptrec,
22
+ void *unwinder, int errcode);
23
+ #endif
20
24
  LJ_ASMF void lj_vm_unwind_c_eh(void);
21
25
  LJ_ASMF void lj_vm_unwind_ff_eh(void);
22
26
  #if LJ_TARGET_X86ORX64
@@ -1,6 +1,6 @@
1
1
  /*
2
2
  ** VM event handling.
3
- ** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h
3
+ ** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
4
4
  */
5
5
 
6
6
  #include <stdio.h>
@@ -1,6 +1,6 @@
1
1
  /*
2
2
  ** VM event handling.
3
- ** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h
3
+ ** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
4
4
  */
5
5
 
6
6
  #ifndef _LJ_VMEVENT_H
@@ -1,6 +1,6 @@
1
1
  /*
2
2
  ** Math helper functions for assembler VM.
3
- ** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h
3
+ ** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
4
4
  */
5
5
 
6
6
  #define lj_vmmath_c
@@ -1,6 +1,6 @@
1
1
  /*
2
2
  ** LuaJIT core and libraries amalgamation.
3
- ** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h
3
+ ** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
4
4
  */
5
5
 
6
6
  /*
@@ -39,7 +39,8 @@
39
39
  #define lua_upvalueindex(i) (LUA_GLOBALSINDEX-(i))
40
40
 
41
41
 
42
- /* thread status; 0 is OK */
42
+ /* thread status */
43
+ #define LUA_OK 0
43
44
  #define LUA_YIELD 1
44
45
  #define LUA_ERRRUN 2
45
46
  #define LUA_ERRSYNTAX 3
@@ -347,6 +348,13 @@ LUA_API void *lua_upvalueid (lua_State *L, int idx, int n);
347
348
  LUA_API void lua_upvaluejoin (lua_State *L, int idx1, int n1, int idx2, int n2);
348
349
  LUA_API int lua_loadx (lua_State *L, lua_Reader reader, void *dt,
349
350
  const char *chunkname, const char *mode);
351
+ LUA_API const lua_Number *lua_version (lua_State *L);
352
+ LUA_API void lua_copy (lua_State *L, int fromidx, int toidx);
353
+ LUA_API lua_Number lua_tonumberx (lua_State *L, int idx, int *isnum);
354
+ LUA_API lua_Integer lua_tointegerx (lua_State *L, int idx, int *isnum);
355
+
356
+ /* From Lua 5.3. */
357
+ LUA_API int lua_isyieldable (lua_State *L);
350
358
 
351
359
 
352
360
  struct lua_Debug {
@@ -1,6 +1,6 @@
1
1
  /*
2
2
  ** Configuration header.
3
- ** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h
3
+ ** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
4
4
  */
5
5
 
6
6
  #ifndef luaconf_h
@@ -37,7 +37,7 @@
37
37
  #endif
38
38
  #define LUA_LROOT "/usr/local"
39
39
  #define LUA_LUADIR "/lua/5.1/"
40
- #define LUA_LJDIR "/luajit-2.1.0-beta2/"
40
+ #define LUA_LJDIR "/luajit-2.1.0-beta3/"
41
41
 
42
42
  #ifdef LUA_ROOT
43
43
  #define LUA_JROOT LUA_ROOT
@@ -79,7 +79,7 @@
79
79
  #define LUA_IGMARK "-"
80
80
  #define LUA_PATH_CONFIG \
81
81
  LUA_DIRSEP "\n" LUA_PATHSEP "\n" LUA_PATH_MARK "\n" \
82
- LUA_EXECDIR "\n" LUA_IGMARK
82
+ LUA_EXECDIR "\n" LUA_IGMARK "\n"
83
83
 
84
84
  /* Quoting in error messages. */
85
85
  #define LUA_QL(x) "'" x "'"
@@ -92,10 +92,6 @@
92
92
  #define LUAI_GCMUL 200 /* Run GC at 200% of allocation speed. */
93
93
  #define LUA_MAXCAPTURES 32 /* Max. pattern captures. */
94
94
 
95
- /* Compatibility with older library function names. */
96
- #define LUA_COMPAT_MOD /* OLD: math.mod, NEW: math.fmod */
97
- #define LUA_COMPAT_GFIND /* OLD: string.gfind, NEW: string.gmatch */
98
-
99
95
  /* Configuration for the frontend (the luajit executable). */
100
96
  #if defined(luajit_c)
101
97
  #define LUA_PROGNAME "luajit" /* Fallback frontend name. */
@@ -1,6 +1,6 @@
1
1
  /*
2
2
  ** LuaJIT frontend. Runs commands, scripts, read-eval-print (REPL) etc.
3
- ** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h
3
+ ** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
4
4
  **
5
5
  ** Major portions taken verbatim or adapted from the Lua interpreter.
6
6
  ** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h
@@ -124,7 +124,7 @@ static int docall(lua_State *L, int narg, int clear)
124
124
  #endif
125
125
  lua_remove(L, base); /* remove traceback function */
126
126
  /* force a complete garbage collection in case of errors */
127
- if (status != 0) lua_gc(L, LUA_GCCOLLECT, 0);
127
+ if (status != LUA_OK) lua_gc(L, LUA_GCCOLLECT, 0);
128
128
  return status;
129
129
  }
130
130
 
@@ -152,22 +152,15 @@ static void print_jit_status(lua_State *L)
152
152
  putc('\n', stdout);
153
153
  }
154
154
 
155
- static int getargs(lua_State *L, char **argv, int n)
155
+ static void createargtable(lua_State *L, char **argv, int argc, int argf)
156
156
  {
157
- int narg;
158
157
  int i;
159
- int argc = 0;
160
- while (argv[argc]) argc++; /* count total number of arguments */
161
- narg = argc - (n + 1); /* number of arguments to the script */
162
- luaL_checkstack(L, narg + 3, "too many arguments to script");
163
- for (i = n+1; i < argc; i++)
164
- lua_pushstring(L, argv[i]);
165
- lua_createtable(L, narg, n + 1);
158
+ lua_createtable(L, argc - argf, argf);
166
159
  for (i = 0; i < argc; i++) {
167
160
  lua_pushstring(L, argv[i]);
168
- lua_rawseti(L, -2, i - n);
161
+ lua_rawseti(L, -2, i - argf);
169
162
  }
170
- return narg;
163
+ lua_setglobal(L, "arg");
171
164
  }
172
165
 
173
166
  static int dofile(lua_State *L, const char *name)
@@ -256,9 +249,9 @@ static void dotty(lua_State *L)
256
249
  const char *oldprogname = progname;
257
250
  progname = NULL;
258
251
  while ((status = loadline(L)) != -1) {
259
- if (status == 0) status = docall(L, 0, 0);
252
+ if (status == LUA_OK) status = docall(L, 0, 0);
260
253
  report(L, status);
261
- if (status == 0 && lua_gettop(L) > 0) { /* any result to print? */
254
+ if (status == LUA_OK && lua_gettop(L) > 0) { /* any result to print? */
262
255
  lua_getglobal(L, "print");
263
256
  lua_insert(L, 1);
264
257
  if (lua_pcall(L, lua_gettop(L)-1, 0, 0) != 0)
@@ -273,21 +266,30 @@ static void dotty(lua_State *L)
273
266
  progname = oldprogname;
274
267
  }
275
268
 
276
- static int handle_script(lua_State *L, char **argv, int n)
269
+ static int handle_script(lua_State *L, char **argx)
277
270
  {
278
271
  int status;
279
- const char *fname;
280
- int narg = getargs(L, argv, n); /* collect arguments */
281
- lua_setglobal(L, "arg");
282
- fname = argv[n];
283
- if (strcmp(fname, "-") == 0 && strcmp(argv[n-1], "--") != 0)
272
+ const char *fname = argx[0];
273
+ if (strcmp(fname, "-") == 0 && strcmp(argx[-1], "--") != 0)
284
274
  fname = NULL; /* stdin */
285
275
  status = luaL_loadfile(L, fname);
286
- lua_insert(L, -(narg+1));
287
- if (status == 0)
276
+ if (status == LUA_OK) {
277
+ /* Fetch args from arg table. LUA_INIT or -e might have changed them. */
278
+ int narg = 0;
279
+ lua_getglobal(L, "arg");
280
+ if (lua_istable(L, -1)) {
281
+ do {
282
+ narg++;
283
+ lua_rawgeti(L, -narg, narg);
284
+ } while (!lua_isnil(L, -1));
285
+ lua_pop(L, 1);
286
+ lua_remove(L, -narg);
287
+ narg--;
288
+ } else {
289
+ lua_pop(L, 1);
290
+ }
288
291
  status = docall(L, narg, 0);
289
- else
290
- lua_pop(L, narg);
292
+ }
291
293
  return report(L, status);
292
294
  }
293
295
 
@@ -384,7 +386,8 @@ static int dobytecode(lua_State *L, char **argv)
384
386
  }
385
387
  for (argv++; *argv != NULL; narg++, argv++)
386
388
  lua_pushstring(L, *argv);
387
- return report(L, lua_pcall(L, narg, 0, 0));
389
+ report(L, lua_pcall(L, narg, 0, 0));
390
+ return -1;
388
391
  }
389
392
 
390
393
  /* check that argument has no extra characters at the end */
@@ -405,7 +408,7 @@ static int collectargs(char **argv, int *flags)
405
408
  switch (argv[i][1]) { /* Check option. */
406
409
  case '-':
407
410
  notail(argv[i]);
408
- return (argv[i+1] != NULL ? i+1 : 0);
411
+ return i+1;
409
412
  case '\0':
410
413
  return i;
411
414
  case 'i':
@@ -430,23 +433,23 @@ static int collectargs(char **argv, int *flags)
430
433
  case 'b': /* LuaJIT extension */
431
434
  if (*flags) return -1;
432
435
  *flags |= FLAGS_EXEC;
433
- return 0;
436
+ return i+1;
434
437
  case 'E':
435
438
  *flags |= FLAGS_NOENV;
436
439
  break;
437
440
  default: return -1; /* invalid option */
438
441
  }
439
442
  }
440
- return 0;
443
+ return i;
441
444
  }
442
445
 
443
- static int runargs(lua_State *L, char **argv, int n)
446
+ static int runargs(lua_State *L, char **argv, int argn)
444
447
  {
445
448
  int i;
446
- for (i = 1; i < n; i++) {
449
+ for (i = 1; i < argn; i++) {
447
450
  if (argv[i] == NULL) continue;
448
451
  lua_assert(argv[i][0] == '-');
449
- switch (argv[i][1]) { /* option */
452
+ switch (argv[i][1]) {
450
453
  case 'e': {
451
454
  const char *chunk = argv[i] + 2;
452
455
  if (*chunk == '\0') chunk = argv[++i];
@@ -460,10 +463,10 @@ static int runargs(lua_State *L, char **argv, int n)
460
463
  if (*filename == '\0') filename = argv[++i];
461
464
  lua_assert(filename != NULL);
462
465
  if (dolibrary(L, filename))
463
- return 1; /* stop if file fails */
466
+ return 1;
464
467
  break;
465
468
  }
466
- case 'j': { /* LuaJIT extension */
469
+ case 'j': { /* LuaJIT extension. */
467
470
  const char *cmd = argv[i] + 2;
468
471
  if (*cmd == '\0') cmd = argv[++i];
469
472
  lua_assert(cmd != NULL);
@@ -471,16 +474,16 @@ static int runargs(lua_State *L, char **argv, int n)
471
474
  return 1;
472
475
  break;
473
476
  }
474
- case 'O': /* LuaJIT extension */
477
+ case 'O': /* LuaJIT extension. */
475
478
  if (dojitopt(L, argv[i] + 2))
476
479
  return 1;
477
480
  break;
478
- case 'b': /* LuaJIT extension */
481
+ case 'b': /* LuaJIT extension. */
479
482
  return dobytecode(L, argv+i);
480
483
  default: break;
481
484
  }
482
485
  }
483
- return 0;
486
+ return LUA_OK;
484
487
  }
485
488
 
486
489
  static int handle_luainit(lua_State *L)
@@ -491,7 +494,7 @@ static int handle_luainit(lua_State *L)
491
494
  const char *init = getenv(LUA_INIT);
492
495
  #endif
493
496
  if (init == NULL)
494
- return 0; /* status OK */
497
+ return LUA_OK;
495
498
  else if (init[0] == '@')
496
499
  return dofile(L, init+1);
497
500
  else
@@ -508,45 +511,57 @@ static int pmain(lua_State *L)
508
511
  {
509
512
  struct Smain *s = &smain;
510
513
  char **argv = s->argv;
511
- int script;
514
+ int argn;
512
515
  int flags = 0;
513
516
  globalL = L;
514
517
  if (argv[0] && argv[0][0]) progname = argv[0];
515
- LUAJIT_VERSION_SYM(); /* linker-enforced version check */
516
- script = collectargs(argv, &flags);
517
- if (script < 0) { /* invalid args? */
518
+
519
+ LUAJIT_VERSION_SYM(); /* Linker-enforced version check. */
520
+
521
+ argn = collectargs(argv, &flags);
522
+ if (argn < 0) { /* Invalid args? */
518
523
  print_usage();
519
524
  s->status = 1;
520
525
  return 0;
521
526
  }
527
+
522
528
  if ((flags & FLAGS_NOENV)) {
523
529
  lua_pushboolean(L, 1);
524
530
  lua_setfield(L, LUA_REGISTRYINDEX, "LUA_NOENV");
525
531
  }
526
- lua_gc(L, LUA_GCSTOP, 0); /* stop collector during initialization */
527
- luaL_openlibs(L); /* open libraries */
532
+
533
+ /* Stop collector during library initialization. */
534
+ lua_gc(L, LUA_GCSTOP, 0);
535
+ luaL_openlibs(L);
528
536
  lua_gc(L, LUA_GCRESTART, -1);
537
+
538
+ createargtable(L, argv, s->argc, argn);
539
+
529
540
  if (!(flags & FLAGS_NOENV)) {
530
541
  s->status = handle_luainit(L);
531
- if (s->status != 0) return 0;
542
+ if (s->status != LUA_OK) return 0;
532
543
  }
544
+
533
545
  if ((flags & FLAGS_VERSION)) print_version();
534
- s->status = runargs(L, argv, (script > 0) ? script : s->argc);
535
- if (s->status != 0) return 0;
536
- if (script) {
537
- s->status = handle_script(L, argv, script);
538
- if (s->status != 0) return 0;
546
+
547
+ s->status = runargs(L, argv, argn);
548
+ if (s->status != LUA_OK) return 0;
549
+
550
+ if (s->argc > argn) {
551
+ s->status = handle_script(L, argv + argn);
552
+ if (s->status != LUA_OK) return 0;
539
553
  }
554
+
540
555
  if ((flags & FLAGS_INTERACTIVE)) {
541
556
  print_jit_status(L);
542
557
  dotty(L);
543
- } else if (script == 0 && !(flags & (FLAGS_EXEC|FLAGS_VERSION))) {
558
+ } else if (s->argc == argn && !(flags & (FLAGS_EXEC|FLAGS_VERSION))) {
544
559
  if (lua_stdin_is_tty()) {
545
560
  print_version();
546
561
  print_jit_status(L);
547
562
  dotty(L);
548
563
  } else {
549
- dofile(L, NULL); /* executes stdin as a file */
564
+ dofile(L, NULL); /* Executes stdin as a file. */
550
565
  }
551
566
  }
552
567
  return 0;
@@ -555,7 +570,7 @@ static int pmain(lua_State *L)
555
570
  int main(int argc, char **argv)
556
571
  {
557
572
  int status;
558
- lua_State *L = lua_open(); /* create state */
573
+ lua_State *L = lua_open();
559
574
  if (L == NULL) {
560
575
  l_message(argv[0], "cannot create state: not enough memory");
561
576
  return EXIT_FAILURE;
@@ -565,6 +580,6 @@ int main(int argc, char **argv)
565
580
  status = lua_cpcall(L, pmain, NULL);
566
581
  report(L, status);
567
582
  lua_close(L);
568
- return (status || smain.status) ? EXIT_FAILURE : EXIT_SUCCESS;
583
+ return (status || smain.status > 0) ? EXIT_FAILURE : EXIT_SUCCESS;
569
584
  }
570
585