immunio 0.15.4 → 0.16.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +0 -27
- data/ext/immunio/Rakefile +9 -0
- data/lib/immunio/plugins/active_record.rb +1 -1
- data/lib/immunio/plugins/active_record_relation.rb +1 -1
- data/lib/immunio/plugins/environment_reporter.rb +20 -0
- data/lib/immunio/rufus_lua_ext/ref.rb +1 -3
- data/lib/immunio/version.rb +1 -1
- data/lib/immunio/vm.rb +1 -2
- data/lua-hooks/Makefile +97 -0
- data/lua-hooks/ext/all.c +41 -52
- data/lua-hooks/ext/all.o +0 -0
- data/lua-hooks/ext/libinjection/libinjection_html5.o +0 -0
- data/lua-hooks/ext/libinjection/libinjection_sqli.o +0 -0
- data/lua-hooks/ext/libinjection/libinjection_xss.o +0 -0
- data/lua-hooks/ext/libinjection/lualib.c +2 -2
- data/lua-hooks/ext/lpeg/lpcap.c +2 -2
- data/lua-hooks/ext/lpeg/lpcap.o +0 -0
- data/lua-hooks/ext/lpeg/lpcode.c +2 -2
- data/lua-hooks/ext/lpeg/lpcode.h +1 -1
- data/lua-hooks/ext/lpeg/lpcode.o +0 -0
- data/lua-hooks/ext/lpeg/lpprint.o +0 -0
- data/lua-hooks/ext/lpeg/lptree.c +2 -2
- data/lua-hooks/ext/lpeg/lptypes.h +1 -1
- data/lua-hooks/ext/lpeg/lpvm.c +2 -2
- data/lua-hooks/ext/lpeg/lpvm.o +0 -0
- data/lua-hooks/ext/lua-cmsgpack/lua_cmsgpack.c +16 -3
- data/lua-hooks/ext/lua-snapshot/snapshot.c +14 -7
- data/lua-hooks/ext/luajit/COPYRIGHT +56 -0
- data/lua-hooks/ext/luajit/Makefile +159 -0
- data/lua-hooks/ext/luajit/README +16 -0
- data/lua-hooks/ext/luajit/doc/bluequad-print.css +166 -0
- data/lua-hooks/ext/luajit/doc/bluequad.css +325 -0
- data/lua-hooks/ext/luajit/doc/changes.html +804 -0
- data/lua-hooks/ext/luajit/doc/contact.html +104 -0
- data/lua-hooks/ext/luajit/doc/ext_c_api.html +189 -0
- data/lua-hooks/ext/luajit/doc/ext_ffi.html +332 -0
- data/lua-hooks/ext/luajit/doc/ext_ffi_api.html +570 -0
- data/lua-hooks/ext/luajit/doc/ext_ffi_semantics.html +1261 -0
- data/lua-hooks/ext/luajit/doc/ext_ffi_tutorial.html +603 -0
- data/lua-hooks/ext/luajit/doc/ext_jit.html +201 -0
- data/lua-hooks/ext/luajit/doc/ext_profiler.html +365 -0
- data/lua-hooks/ext/luajit/doc/extensions.html +448 -0
- data/lua-hooks/ext/luajit/doc/faq.html +186 -0
- data/lua-hooks/ext/luajit/doc/img/contact.png +0 -0
- data/lua-hooks/ext/luajit/doc/install.html +659 -0
- data/lua-hooks/ext/luajit/doc/luajit.html +236 -0
- data/lua-hooks/ext/luajit/doc/running.html +309 -0
- data/lua-hooks/ext/luajit/doc/status.html +118 -0
- data/lua-hooks/ext/luajit/dynasm/dasm_arm.h +456 -0
- data/lua-hooks/ext/luajit/dynasm/dasm_arm.lua +1125 -0
- data/lua-hooks/ext/luajit/dynasm/dasm_arm64.h +518 -0
- data/lua-hooks/ext/luajit/dynasm/dasm_arm64.lua +1166 -0
- data/lua-hooks/ext/luajit/dynasm/dasm_mips.h +416 -0
- data/lua-hooks/ext/luajit/dynasm/dasm_mips.lua +953 -0
- data/lua-hooks/ext/luajit/dynasm/dasm_ppc.h +419 -0
- data/lua-hooks/ext/luajit/dynasm/dasm_ppc.lua +1919 -0
- data/lua-hooks/ext/luajit/dynasm/dasm_proto.h +83 -0
- data/lua-hooks/ext/luajit/dynasm/dasm_x64.lua +12 -0
- data/lua-hooks/ext/luajit/dynasm/dasm_x86.h +471 -0
- data/lua-hooks/ext/luajit/dynasm/dasm_x86.lua +1945 -0
- data/lua-hooks/ext/luajit/dynasm/dynasm.lua +1094 -0
- data/lua-hooks/ext/luajit/etc/luajit.1 +88 -0
- data/lua-hooks/ext/luajit/etc/luajit.pc +25 -0
- data/lua-hooks/ext/luajit/src/Makefile +697 -0
- data/lua-hooks/ext/luajit/src/Makefile.dep +244 -0
- data/lua-hooks/ext/luajit/src/host/README +4 -0
- data/lua-hooks/ext/luajit/src/host/buildvm +0 -0
- data/lua-hooks/ext/luajit/src/host/buildvm.c +518 -0
- data/lua-hooks/ext/luajit/src/host/buildvm.h +105 -0
- data/lua-hooks/ext/luajit/src/host/buildvm.o +0 -0
- data/lua-hooks/ext/luajit/src/host/buildvm_arch.h +7449 -0
- data/lua-hooks/ext/luajit/src/host/buildvm_asm.c +345 -0
- data/lua-hooks/ext/luajit/src/host/buildvm_asm.o +0 -0
- data/lua-hooks/ext/luajit/src/host/buildvm_fold.c +229 -0
- data/lua-hooks/ext/luajit/src/host/buildvm_fold.o +0 -0
- data/lua-hooks/ext/luajit/src/host/buildvm_lib.c +457 -0
- data/lua-hooks/ext/luajit/src/host/buildvm_lib.o +0 -0
- data/lua-hooks/ext/luajit/src/host/buildvm_libbc.h +45 -0
- data/lua-hooks/ext/luajit/src/host/buildvm_peobj.c +368 -0
- data/lua-hooks/ext/luajit/src/host/buildvm_peobj.o +0 -0
- data/lua-hooks/ext/luajit/src/host/genlibbc.lua +197 -0
- data/lua-hooks/ext/luajit/src/host/genminilua.lua +428 -0
- data/lua-hooks/ext/luajit/src/host/minilua +0 -0
- data/lua-hooks/ext/luajit/src/host/minilua.c +7770 -0
- data/lua-hooks/ext/luajit/src/host/minilua.o +0 -0
- data/lua-hooks/ext/luajit/src/jit/bc.lua +190 -0
- data/lua-hooks/ext/luajit/src/jit/bcsave.lua +661 -0
- data/lua-hooks/ext/luajit/src/jit/dis_arm.lua +689 -0
- data/lua-hooks/ext/luajit/src/jit/dis_mips.lua +428 -0
- data/lua-hooks/ext/luajit/src/jit/dis_mipsel.lua +17 -0
- data/lua-hooks/ext/luajit/src/jit/dis_ppc.lua +591 -0
- data/lua-hooks/ext/luajit/src/jit/dis_x64.lua +17 -0
- data/lua-hooks/ext/luajit/src/jit/dis_x86.lua +838 -0
- data/lua-hooks/ext/luajit/src/jit/dump.lua +706 -0
- data/lua-hooks/ext/luajit/src/jit/p.lua +310 -0
- data/lua-hooks/ext/luajit/src/jit/v.lua +170 -0
- data/lua-hooks/ext/luajit/src/jit/vmdef.lua +362 -0
- data/lua-hooks/ext/luajit/src/jit/zone.lua +45 -0
- data/lua-hooks/ext/{lua → luajit/src}/lauxlib.h +10 -17
- data/lua-hooks/ext/luajit/src/lib_aux.c +356 -0
- data/lua-hooks/ext/luajit/src/lib_aux.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_aux_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_base.c +664 -0
- data/lua-hooks/ext/luajit/src/lib_base.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_base_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_bit.c +180 -0
- data/lua-hooks/ext/luajit/src/lib_bit.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_bit_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_debug.c +405 -0
- data/lua-hooks/ext/luajit/src/lib_debug.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_debug_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_ffi.c +872 -0
- data/lua-hooks/ext/luajit/src/lib_ffi.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_ffi_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_init.c +55 -0
- data/lua-hooks/ext/luajit/src/lib_init.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_init_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_io.c +541 -0
- data/lua-hooks/ext/luajit/src/lib_io.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_io_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_jit.c +767 -0
- data/lua-hooks/ext/luajit/src/lib_jit.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_jit_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_math.c +230 -0
- data/lua-hooks/ext/luajit/src/lib_math.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_math_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_os.c +292 -0
- data/lua-hooks/ext/luajit/src/lib_os.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_os_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_package.c +610 -0
- data/lua-hooks/ext/luajit/src/lib_package.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_package_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_string.c +752 -0
- data/lua-hooks/ext/luajit/src/lib_string.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_string_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_table.c +307 -0
- data/lua-hooks/ext/luajit/src/lib_table.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_table_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/libluajit.a +0 -0
- data/lua-hooks/ext/luajit/src/libluajit.so +0 -0
- data/lua-hooks/ext/luajit/src/lj.supp +26 -0
- data/lua-hooks/ext/luajit/src/lj_alloc.c +1398 -0
- data/lua-hooks/ext/luajit/src/lj_alloc.h +17 -0
- data/lua-hooks/ext/luajit/src/lj_alloc.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_alloc_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_api.c +1210 -0
- data/lua-hooks/ext/luajit/src/lj_api.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_api_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_arch.h +509 -0
- data/lua-hooks/ext/luajit/src/lj_asm.c +2278 -0
- data/lua-hooks/ext/luajit/src/lj_asm.h +17 -0
- data/lua-hooks/ext/luajit/src/lj_asm.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_asm_arm.h +2217 -0
- data/lua-hooks/ext/luajit/src/lj_asm_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_asm_mips.h +1833 -0
- data/lua-hooks/ext/luajit/src/lj_asm_ppc.h +2015 -0
- data/lua-hooks/ext/luajit/src/lj_asm_x86.h +2634 -0
- data/lua-hooks/ext/luajit/src/lj_bc.c +14 -0
- data/lua-hooks/ext/luajit/src/lj_bc.h +265 -0
- data/lua-hooks/ext/luajit/src/lj_bc.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_bc_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_bcdef.h +220 -0
- data/lua-hooks/ext/luajit/src/lj_bcdump.h +68 -0
- data/lua-hooks/ext/luajit/src/lj_bcread.c +457 -0
- data/lua-hooks/ext/luajit/src/lj_bcread.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_bcread_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_bcwrite.c +361 -0
- data/lua-hooks/ext/luajit/src/lj_bcwrite.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_bcwrite_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_buf.c +234 -0
- data/lua-hooks/ext/luajit/src/lj_buf.h +105 -0
- data/lua-hooks/ext/luajit/src/lj_buf.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_buf_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_carith.c +429 -0
- data/lua-hooks/ext/luajit/src/lj_carith.h +37 -0
- data/lua-hooks/ext/luajit/src/lj_carith.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_carith_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_ccall.c +984 -0
- data/lua-hooks/ext/luajit/src/lj_ccall.h +178 -0
- data/lua-hooks/ext/luajit/src/lj_ccall.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_ccall_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_ccallback.c +712 -0
- data/lua-hooks/ext/luajit/src/lj_ccallback.h +25 -0
- data/lua-hooks/ext/luajit/src/lj_ccallback.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_ccallback_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_cconv.c +752 -0
- data/lua-hooks/ext/luajit/src/lj_cconv.h +70 -0
- data/lua-hooks/ext/luajit/src/lj_cconv.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_cconv_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_cdata.c +288 -0
- data/lua-hooks/ext/luajit/src/lj_cdata.h +76 -0
- data/lua-hooks/ext/luajit/src/lj_cdata.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_cdata_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_char.c +43 -0
- data/lua-hooks/ext/luajit/src/lj_char.h +42 -0
- data/lua-hooks/ext/luajit/src/lj_char.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_char_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_clib.c +418 -0
- data/lua-hooks/ext/luajit/src/lj_clib.h +29 -0
- data/lua-hooks/ext/luajit/src/lj_clib.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_clib_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_cparse.c +1862 -0
- data/lua-hooks/ext/luajit/src/lj_cparse.h +65 -0
- data/lua-hooks/ext/luajit/src/lj_cparse.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_cparse_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_crecord.c +1834 -0
- data/lua-hooks/ext/luajit/src/lj_crecord.h +38 -0
- data/lua-hooks/ext/luajit/src/lj_crecord.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_crecord_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_ctype.c +635 -0
- data/lua-hooks/ext/luajit/src/lj_ctype.h +461 -0
- data/lua-hooks/ext/luajit/src/lj_ctype.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_ctype_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_debug.c +699 -0
- data/lua-hooks/ext/luajit/src/lj_debug.h +65 -0
- data/lua-hooks/ext/luajit/src/lj_debug.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_debug_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_def.h +365 -0
- data/lua-hooks/ext/luajit/src/lj_dispatch.c +557 -0
- data/lua-hooks/ext/luajit/src/lj_dispatch.h +138 -0
- data/lua-hooks/ext/luajit/src/lj_dispatch.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_dispatch_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_emit_arm.h +356 -0
- data/lua-hooks/ext/luajit/src/lj_emit_mips.h +211 -0
- data/lua-hooks/ext/luajit/src/lj_emit_ppc.h +238 -0
- data/lua-hooks/ext/luajit/src/lj_emit_x86.h +462 -0
- data/lua-hooks/ext/luajit/src/lj_err.c +794 -0
- data/lua-hooks/ext/luajit/src/lj_err.h +41 -0
- data/lua-hooks/ext/luajit/src/lj_err.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_err_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_errmsg.h +190 -0
- data/lua-hooks/ext/luajit/src/lj_ff.h +18 -0
- data/lua-hooks/ext/luajit/src/lj_ffdef.h +209 -0
- data/lua-hooks/ext/luajit/src/lj_ffrecord.c +1247 -0
- data/lua-hooks/ext/luajit/src/lj_ffrecord.h +24 -0
- data/lua-hooks/ext/luajit/src/lj_ffrecord.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_ffrecord_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_folddef.h +1138 -0
- data/lua-hooks/ext/luajit/src/lj_frame.h +259 -0
- data/lua-hooks/ext/luajit/src/lj_func.c +185 -0
- data/lua-hooks/ext/luajit/src/lj_func.h +24 -0
- data/lua-hooks/ext/luajit/src/lj_func.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_func_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_gc.c +845 -0
- data/lua-hooks/ext/luajit/src/lj_gc.h +134 -0
- data/lua-hooks/ext/luajit/src/lj_gc.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_gc_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_gdbjit.c +787 -0
- data/lua-hooks/ext/luajit/src/lj_gdbjit.h +22 -0
- data/lua-hooks/ext/luajit/src/lj_gdbjit.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_gdbjit_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_ir.c +505 -0
- data/lua-hooks/ext/luajit/src/lj_ir.h +577 -0
- data/lua-hooks/ext/luajit/src/lj_ir.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_ir_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_ircall.h +321 -0
- data/lua-hooks/ext/luajit/src/lj_iropt.h +161 -0
- data/lua-hooks/ext/luajit/src/lj_jit.h +440 -0
- data/lua-hooks/ext/luajit/src/lj_lex.c +482 -0
- data/lua-hooks/ext/luajit/src/lj_lex.h +86 -0
- data/lua-hooks/ext/luajit/src/lj_lex.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_lex_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_lib.c +303 -0
- data/lua-hooks/ext/luajit/src/lj_lib.h +115 -0
- data/lua-hooks/ext/luajit/src/lj_lib.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_lib_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_libdef.h +414 -0
- data/lua-hooks/ext/luajit/src/lj_load.c +168 -0
- data/lua-hooks/ext/luajit/src/lj_load.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_load_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_mcode.c +386 -0
- data/lua-hooks/ext/luajit/src/lj_mcode.h +30 -0
- data/lua-hooks/ext/luajit/src/lj_mcode.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_mcode_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_meta.c +477 -0
- data/lua-hooks/ext/luajit/src/lj_meta.h +38 -0
- data/lua-hooks/ext/luajit/src/lj_meta.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_meta_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_obj.c +50 -0
- data/lua-hooks/ext/luajit/src/lj_obj.h +976 -0
- data/lua-hooks/ext/luajit/src/lj_obj.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_obj_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_opt_dce.c +78 -0
- data/lua-hooks/ext/luajit/src/lj_opt_dce.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_opt_dce_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_opt_fold.c +2488 -0
- data/lua-hooks/ext/luajit/src/lj_opt_fold.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_opt_fold_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_opt_loop.c +449 -0
- data/lua-hooks/ext/luajit/src/lj_opt_loop.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_opt_loop_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_opt_mem.c +935 -0
- data/lua-hooks/ext/luajit/src/lj_opt_mem.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_opt_mem_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_opt_narrow.c +652 -0
- data/lua-hooks/ext/luajit/src/lj_opt_narrow.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_opt_narrow_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_opt_sink.c +245 -0
- data/lua-hooks/ext/luajit/src/lj_opt_sink.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_opt_sink_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_opt_split.c +856 -0
- data/lua-hooks/ext/luajit/src/lj_opt_split.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_opt_split_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_parse.c +2725 -0
- data/lua-hooks/ext/luajit/src/lj_parse.h +18 -0
- data/lua-hooks/ext/luajit/src/lj_parse.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_parse_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_profile.c +368 -0
- data/lua-hooks/ext/luajit/src/lj_profile.h +21 -0
- data/lua-hooks/ext/luajit/src/lj_profile.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_profile_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_recdef.h +270 -0
- data/lua-hooks/ext/luajit/src/lj_record.c +2554 -0
- data/lua-hooks/ext/luajit/src/lj_record.h +45 -0
- data/lua-hooks/ext/luajit/src/lj_record.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_record_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_snap.c +870 -0
- data/lua-hooks/ext/luajit/src/lj_snap.h +34 -0
- data/lua-hooks/ext/luajit/src/lj_snap.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_snap_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_state.c +300 -0
- data/lua-hooks/ext/luajit/src/lj_state.h +35 -0
- data/lua-hooks/ext/luajit/src/lj_state.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_state_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_str.c +197 -0
- data/lua-hooks/ext/luajit/src/lj_str.h +27 -0
- data/lua-hooks/ext/luajit/src/lj_str.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_str_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_strfmt.c +554 -0
- data/lua-hooks/ext/luajit/src/lj_strfmt.h +125 -0
- data/lua-hooks/ext/luajit/src/lj_strfmt.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_strfmt_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_strscan.c +547 -0
- data/lua-hooks/ext/luajit/src/lj_strscan.h +39 -0
- data/lua-hooks/ext/luajit/src/lj_strscan.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_strscan_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_tab.c +666 -0
- data/lua-hooks/ext/luajit/src/lj_tab.h +73 -0
- data/lua-hooks/ext/luajit/src/lj_tab.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_tab_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_target.h +164 -0
- data/lua-hooks/ext/luajit/src/lj_target_arm.h +270 -0
- data/lua-hooks/ext/luajit/src/lj_target_arm64.h +97 -0
- data/lua-hooks/ext/luajit/src/lj_target_mips.h +260 -0
- data/lua-hooks/ext/luajit/src/lj_target_ppc.h +280 -0
- data/lua-hooks/ext/luajit/src/lj_target_x86.h +345 -0
- data/lua-hooks/ext/luajit/src/lj_trace.c +859 -0
- data/lua-hooks/ext/luajit/src/lj_trace.h +54 -0
- data/lua-hooks/ext/luajit/src/lj_trace.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_trace_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_traceerr.h +63 -0
- data/lua-hooks/ext/luajit/src/lj_udata.c +34 -0
- data/lua-hooks/ext/luajit/src/lj_udata.h +14 -0
- data/lua-hooks/ext/luajit/src/lj_udata.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_udata_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_vm.S +2730 -0
- data/lua-hooks/ext/luajit/src/lj_vm.h +114 -0
- data/lua-hooks/ext/luajit/src/lj_vm.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_vm_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_vmevent.c +58 -0
- data/lua-hooks/ext/luajit/src/lj_vmevent.h +59 -0
- data/lua-hooks/ext/luajit/src/lj_vmevent.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_vmevent_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_vmmath.c +152 -0
- data/lua-hooks/ext/luajit/src/lj_vmmath.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_vmmath_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/ljamalg.c +96 -0
- data/lua-hooks/ext/{lua → luajit/src}/lua.h +12 -7
- data/lua-hooks/ext/luajit/src/lua.hpp +9 -0
- data/lua-hooks/ext/luajit/src/luaconf.h +156 -0
- data/lua-hooks/ext/luajit/src/luajit +0 -0
- data/lua-hooks/ext/luajit/src/luajit.c +570 -0
- data/lua-hooks/ext/luajit/src/luajit.h +79 -0
- data/lua-hooks/ext/luajit/src/luajit.o +0 -0
- data/lua-hooks/ext/luajit/src/lualib.h +43 -0
- data/lua-hooks/ext/luajit/src/msvcbuild.bat +114 -0
- data/lua-hooks/ext/luajit/src/ps4build.bat +103 -0
- data/lua-hooks/ext/luajit/src/psvitabuild.bat +93 -0
- data/lua-hooks/ext/luajit/src/vm_arm.dasc +4585 -0
- data/lua-hooks/ext/luajit/src/vm_arm64.dasc +3764 -0
- data/lua-hooks/ext/luajit/src/vm_mips.dasc +4355 -0
- data/lua-hooks/ext/luajit/src/vm_ppc.dasc +5252 -0
- data/lua-hooks/ext/luajit/src/vm_x64.dasc +4902 -0
- data/lua-hooks/ext/luajit/src/vm_x86.dasc +5710 -0
- data/lua-hooks/ext/luajit/src/xb1build.bat +101 -0
- data/lua-hooks/ext/luajit/src/xedkbuild.bat +92 -0
- data/lua-hooks/ext/luautf8/lutf8lib.c +3 -3
- data/lua-hooks/lib/boot.lua +37 -2
- metadata +372 -69
- data/lua-hooks/ext/bitop/README +0 -22
- data/lua-hooks/ext/bitop/bit.c +0 -189
- data/lua-hooks/ext/extconf.rb +0 -38
- data/lua-hooks/ext/lua/COPYRIGHT +0 -34
- data/lua-hooks/ext/lua/lapi.c +0 -1087
- data/lua-hooks/ext/lua/lapi.h +0 -16
- data/lua-hooks/ext/lua/lauxlib.c +0 -652
- data/lua-hooks/ext/lua/lbaselib.c +0 -659
- data/lua-hooks/ext/lua/lcode.c +0 -831
- data/lua-hooks/ext/lua/lcode.h +0 -76
- data/lua-hooks/ext/lua/ldblib.c +0 -398
- data/lua-hooks/ext/lua/ldebug.c +0 -638
- data/lua-hooks/ext/lua/ldebug.h +0 -33
- data/lua-hooks/ext/lua/ldo.c +0 -519
- data/lua-hooks/ext/lua/ldo.h +0 -57
- data/lua-hooks/ext/lua/ldump.c +0 -164
- data/lua-hooks/ext/lua/lfunc.c +0 -174
- data/lua-hooks/ext/lua/lfunc.h +0 -34
- data/lua-hooks/ext/lua/lgc.c +0 -710
- data/lua-hooks/ext/lua/lgc.h +0 -110
- data/lua-hooks/ext/lua/linit.c +0 -38
- data/lua-hooks/ext/lua/liolib.c +0 -556
- data/lua-hooks/ext/lua/llex.c +0 -463
- data/lua-hooks/ext/lua/llex.h +0 -81
- data/lua-hooks/ext/lua/llimits.h +0 -128
- data/lua-hooks/ext/lua/lmathlib.c +0 -263
- data/lua-hooks/ext/lua/lmem.c +0 -86
- data/lua-hooks/ext/lua/lmem.h +0 -49
- data/lua-hooks/ext/lua/loadlib.c +0 -705
- data/lua-hooks/ext/lua/loadlib_rel.c +0 -760
- data/lua-hooks/ext/lua/lobject.c +0 -214
- data/lua-hooks/ext/lua/lobject.h +0 -381
- data/lua-hooks/ext/lua/lopcodes.c +0 -102
- data/lua-hooks/ext/lua/lopcodes.h +0 -268
- data/lua-hooks/ext/lua/loslib.c +0 -243
- data/lua-hooks/ext/lua/lparser.c +0 -1339
- data/lua-hooks/ext/lua/lparser.h +0 -82
- data/lua-hooks/ext/lua/lstate.c +0 -214
- data/lua-hooks/ext/lua/lstate.h +0 -169
- data/lua-hooks/ext/lua/lstring.c +0 -111
- data/lua-hooks/ext/lua/lstring.h +0 -31
- data/lua-hooks/ext/lua/lstrlib.c +0 -871
- data/lua-hooks/ext/lua/ltable.c +0 -588
- data/lua-hooks/ext/lua/ltable.h +0 -40
- data/lua-hooks/ext/lua/ltablib.c +0 -287
- data/lua-hooks/ext/lua/ltm.c +0 -75
- data/lua-hooks/ext/lua/ltm.h +0 -54
- data/lua-hooks/ext/lua/lua.c +0 -392
- data/lua-hooks/ext/lua/lua.def +0 -131
- data/lua-hooks/ext/lua/lua.rc +0 -28
- data/lua-hooks/ext/lua/lua_dll.rc +0 -26
- data/lua-hooks/ext/lua/luac.c +0 -200
- data/lua-hooks/ext/lua/luac.rc +0 -1
- data/lua-hooks/ext/lua/luaconf.h +0 -763
- data/lua-hooks/ext/lua/luaconf.h.in +0 -724
- data/lua-hooks/ext/lua/luaconf.h.orig +0 -763
- data/lua-hooks/ext/lua/lualib.h +0 -53
- data/lua-hooks/ext/lua/lundump.c +0 -227
- data/lua-hooks/ext/lua/lundump.h +0 -36
- data/lua-hooks/ext/lua/lvm.c +0 -767
- data/lua-hooks/ext/lua/lvm.h +0 -36
- data/lua-hooks/ext/lua/lzio.c +0 -82
- data/lua-hooks/ext/lua/lzio.h +0 -67
- data/lua-hooks/ext/lua/print.c +0 -227
Binary file
|
Binary file
|
@@ -0,0 +1,872 @@
|
|
1
|
+
/*
|
2
|
+
** FFI library.
|
3
|
+
** Copyright (C) 2005-2015 Mike Pall. See Copyright Notice in luajit.h
|
4
|
+
*/
|
5
|
+
|
6
|
+
#define lib_ffi_c
|
7
|
+
#define LUA_LIB
|
8
|
+
|
9
|
+
#include <errno.h>
|
10
|
+
|
11
|
+
#include "lua.h"
|
12
|
+
#include "lauxlib.h"
|
13
|
+
#include "lualib.h"
|
14
|
+
|
15
|
+
#include "lj_obj.h"
|
16
|
+
|
17
|
+
#if LJ_HASFFI
|
18
|
+
|
19
|
+
#include "lj_gc.h"
|
20
|
+
#include "lj_err.h"
|
21
|
+
#include "lj_str.h"
|
22
|
+
#include "lj_tab.h"
|
23
|
+
#include "lj_meta.h"
|
24
|
+
#include "lj_ctype.h"
|
25
|
+
#include "lj_cparse.h"
|
26
|
+
#include "lj_cdata.h"
|
27
|
+
#include "lj_cconv.h"
|
28
|
+
#include "lj_carith.h"
|
29
|
+
#include "lj_ccall.h"
|
30
|
+
#include "lj_ccallback.h"
|
31
|
+
#include "lj_clib.h"
|
32
|
+
#include "lj_strfmt.h"
|
33
|
+
#include "lj_ff.h"
|
34
|
+
#include "lj_lib.h"
|
35
|
+
|
36
|
+
/* -- C type checks ------------------------------------------------------- */
|
37
|
+
|
38
|
+
/* Check first argument for a C type and returns its ID. */
|
39
|
+
static CTypeID ffi_checkctype(lua_State *L, CTState *cts, TValue *param)
|
40
|
+
{
|
41
|
+
TValue *o = L->base;
|
42
|
+
if (!(o < L->top)) {
|
43
|
+
err_argtype:
|
44
|
+
lj_err_argtype(L, 1, "C type");
|
45
|
+
}
|
46
|
+
if (tvisstr(o)) { /* Parse an abstract C type declaration. */
|
47
|
+
GCstr *s = strV(o);
|
48
|
+
CPState cp;
|
49
|
+
int errcode;
|
50
|
+
cp.L = L;
|
51
|
+
cp.cts = cts;
|
52
|
+
cp.srcname = strdata(s);
|
53
|
+
cp.p = strdata(s);
|
54
|
+
cp.param = param;
|
55
|
+
cp.mode = CPARSE_MODE_ABSTRACT|CPARSE_MODE_NOIMPLICIT;
|
56
|
+
errcode = lj_cparse(&cp);
|
57
|
+
if (errcode) lj_err_throw(L, errcode); /* Propagate errors. */
|
58
|
+
return cp.val.id;
|
59
|
+
} else {
|
60
|
+
GCcdata *cd;
|
61
|
+
if (!tviscdata(o)) goto err_argtype;
|
62
|
+
if (param && param < L->top) lj_err_arg(L, 1, LJ_ERR_FFI_NUMPARAM);
|
63
|
+
cd = cdataV(o);
|
64
|
+
return cd->ctypeid == CTID_CTYPEID ? *(CTypeID *)cdataptr(cd) : cd->ctypeid;
|
65
|
+
}
|
66
|
+
}
|
67
|
+
|
68
|
+
/* Check argument for C data and return it. */
|
69
|
+
static GCcdata *ffi_checkcdata(lua_State *L, int narg)
|
70
|
+
{
|
71
|
+
TValue *o = L->base + narg-1;
|
72
|
+
if (!(o < L->top && tviscdata(o)))
|
73
|
+
lj_err_argt(L, narg, LUA_TCDATA);
|
74
|
+
return cdataV(o);
|
75
|
+
}
|
76
|
+
|
77
|
+
/* Convert argument to C pointer. */
|
78
|
+
static void *ffi_checkptr(lua_State *L, int narg, CTypeID id)
|
79
|
+
{
|
80
|
+
CTState *cts = ctype_cts(L);
|
81
|
+
TValue *o = L->base + narg-1;
|
82
|
+
void *p;
|
83
|
+
if (o >= L->top)
|
84
|
+
lj_err_arg(L, narg, LJ_ERR_NOVAL);
|
85
|
+
lj_cconv_ct_tv(cts, ctype_get(cts, id), (uint8_t *)&p, o, CCF_ARG(narg));
|
86
|
+
return p;
|
87
|
+
}
|
88
|
+
|
89
|
+
/* Convert argument to int32_t. */
|
90
|
+
static int32_t ffi_checkint(lua_State *L, int narg)
|
91
|
+
{
|
92
|
+
CTState *cts = ctype_cts(L);
|
93
|
+
TValue *o = L->base + narg-1;
|
94
|
+
int32_t i;
|
95
|
+
if (o >= L->top)
|
96
|
+
lj_err_arg(L, narg, LJ_ERR_NOVAL);
|
97
|
+
lj_cconv_ct_tv(cts, ctype_get(cts, CTID_INT32), (uint8_t *)&i, o,
|
98
|
+
CCF_ARG(narg));
|
99
|
+
return i;
|
100
|
+
}
|
101
|
+
|
102
|
+
/* -- C type metamethods -------------------------------------------------- */
|
103
|
+
|
104
|
+
#define LJLIB_MODULE_ffi_meta
|
105
|
+
|
106
|
+
/* Handle ctype __index/__newindex metamethods. */
|
107
|
+
static int ffi_index_meta(lua_State *L, CTState *cts, CType *ct, MMS mm)
|
108
|
+
{
|
109
|
+
CTypeID id = ctype_typeid(cts, ct);
|
110
|
+
cTValue *tv = lj_ctype_meta(cts, id, mm);
|
111
|
+
TValue *base = L->base;
|
112
|
+
if (!tv) {
|
113
|
+
const char *s;
|
114
|
+
err_index:
|
115
|
+
s = strdata(lj_ctype_repr(L, id, NULL));
|
116
|
+
if (tvisstr(L->base+1)) {
|
117
|
+
lj_err_callerv(L, LJ_ERR_FFI_BADMEMBER, s, strVdata(L->base+1));
|
118
|
+
} else {
|
119
|
+
const char *key = tviscdata(L->base+1) ?
|
120
|
+
strdata(lj_ctype_repr(L, cdataV(L->base+1)->ctypeid, NULL)) :
|
121
|
+
lj_typename(L->base+1);
|
122
|
+
lj_err_callerv(L, LJ_ERR_FFI_BADIDXW, s, key);
|
123
|
+
}
|
124
|
+
}
|
125
|
+
if (!tvisfunc(tv)) {
|
126
|
+
if (mm == MM_index) {
|
127
|
+
cTValue *o = lj_meta_tget(L, tv, base+1);
|
128
|
+
if (o) {
|
129
|
+
if (tvisnil(o)) goto err_index;
|
130
|
+
copyTV(L, L->top-1, o);
|
131
|
+
return 1;
|
132
|
+
}
|
133
|
+
} else {
|
134
|
+
TValue *o = lj_meta_tset(L, tv, base+1);
|
135
|
+
if (o) {
|
136
|
+
copyTV(L, o, base+2);
|
137
|
+
return 0;
|
138
|
+
}
|
139
|
+
}
|
140
|
+
copyTV(L, base, L->top);
|
141
|
+
tv = L->top-1-LJ_FR2;
|
142
|
+
}
|
143
|
+
return lj_meta_tailcall(L, tv);
|
144
|
+
}
|
145
|
+
|
146
|
+
LJLIB_CF(ffi_meta___index) LJLIB_REC(cdata_index 0)
|
147
|
+
{
|
148
|
+
CTState *cts = ctype_cts(L);
|
149
|
+
CTInfo qual = 0;
|
150
|
+
CType *ct;
|
151
|
+
uint8_t *p;
|
152
|
+
TValue *o = L->base;
|
153
|
+
if (!(o+1 < L->top && tviscdata(o))) /* Also checks for presence of key. */
|
154
|
+
lj_err_argt(L, 1, LUA_TCDATA);
|
155
|
+
ct = lj_cdata_index(cts, cdataV(o), o+1, &p, &qual);
|
156
|
+
if ((qual & 1))
|
157
|
+
return ffi_index_meta(L, cts, ct, MM_index);
|
158
|
+
if (lj_cdata_get(cts, ct, L->top-1, p))
|
159
|
+
lj_gc_check(L);
|
160
|
+
return 1;
|
161
|
+
}
|
162
|
+
|
163
|
+
LJLIB_CF(ffi_meta___newindex) LJLIB_REC(cdata_index 1)
|
164
|
+
{
|
165
|
+
CTState *cts = ctype_cts(L);
|
166
|
+
CTInfo qual = 0;
|
167
|
+
CType *ct;
|
168
|
+
uint8_t *p;
|
169
|
+
TValue *o = L->base;
|
170
|
+
if (!(o+2 < L->top && tviscdata(o))) /* Also checks for key and value. */
|
171
|
+
lj_err_argt(L, 1, LUA_TCDATA);
|
172
|
+
ct = lj_cdata_index(cts, cdataV(o), o+1, &p, &qual);
|
173
|
+
if ((qual & 1)) {
|
174
|
+
if ((qual & CTF_CONST))
|
175
|
+
lj_err_caller(L, LJ_ERR_FFI_WRCONST);
|
176
|
+
return ffi_index_meta(L, cts, ct, MM_newindex);
|
177
|
+
}
|
178
|
+
lj_cdata_set(cts, ct, p, o+2, qual);
|
179
|
+
return 0;
|
180
|
+
}
|
181
|
+
|
182
|
+
/* Common handler for cdata arithmetic. */
|
183
|
+
static int ffi_arith(lua_State *L)
|
184
|
+
{
|
185
|
+
MMS mm = (MMS)(curr_func(L)->c.ffid - (int)FF_ffi_meta___eq + (int)MM_eq);
|
186
|
+
return lj_carith_op(L, mm);
|
187
|
+
}
|
188
|
+
|
189
|
+
/* The following functions must be in contiguous ORDER MM. */
|
190
|
+
LJLIB_CF(ffi_meta___eq) LJLIB_REC(cdata_arith MM_eq)
|
191
|
+
{
|
192
|
+
return ffi_arith(L);
|
193
|
+
}
|
194
|
+
|
195
|
+
LJLIB_CF(ffi_meta___len) LJLIB_REC(cdata_arith MM_len)
|
196
|
+
{
|
197
|
+
return ffi_arith(L);
|
198
|
+
}
|
199
|
+
|
200
|
+
LJLIB_CF(ffi_meta___lt) LJLIB_REC(cdata_arith MM_lt)
|
201
|
+
{
|
202
|
+
return ffi_arith(L);
|
203
|
+
}
|
204
|
+
|
205
|
+
LJLIB_CF(ffi_meta___le) LJLIB_REC(cdata_arith MM_le)
|
206
|
+
{
|
207
|
+
return ffi_arith(L);
|
208
|
+
}
|
209
|
+
|
210
|
+
LJLIB_CF(ffi_meta___concat) LJLIB_REC(cdata_arith MM_concat)
|
211
|
+
{
|
212
|
+
return ffi_arith(L);
|
213
|
+
}
|
214
|
+
|
215
|
+
/* Forward declaration. */
|
216
|
+
static int lj_cf_ffi_new(lua_State *L);
|
217
|
+
|
218
|
+
LJLIB_CF(ffi_meta___call) LJLIB_REC(cdata_call)
|
219
|
+
{
|
220
|
+
CTState *cts = ctype_cts(L);
|
221
|
+
GCcdata *cd = ffi_checkcdata(L, 1);
|
222
|
+
CTypeID id = cd->ctypeid;
|
223
|
+
CType *ct;
|
224
|
+
cTValue *tv;
|
225
|
+
MMS mm = MM_call;
|
226
|
+
if (cd->ctypeid == CTID_CTYPEID) {
|
227
|
+
id = *(CTypeID *)cdataptr(cd);
|
228
|
+
mm = MM_new;
|
229
|
+
} else {
|
230
|
+
int ret = lj_ccall_func(L, cd);
|
231
|
+
if (ret >= 0)
|
232
|
+
return ret;
|
233
|
+
}
|
234
|
+
/* Handle ctype __call/__new metamethod. */
|
235
|
+
ct = ctype_raw(cts, id);
|
236
|
+
if (ctype_isptr(ct->info)) id = ctype_cid(ct->info);
|
237
|
+
tv = lj_ctype_meta(cts, id, mm);
|
238
|
+
if (tv)
|
239
|
+
return lj_meta_tailcall(L, tv);
|
240
|
+
else if (mm == MM_call)
|
241
|
+
lj_err_callerv(L, LJ_ERR_FFI_BADCALL, strdata(lj_ctype_repr(L, id, NULL)));
|
242
|
+
return lj_cf_ffi_new(L);
|
243
|
+
}
|
244
|
+
|
245
|
+
LJLIB_CF(ffi_meta___add) LJLIB_REC(cdata_arith MM_add)
|
246
|
+
{
|
247
|
+
return ffi_arith(L);
|
248
|
+
}
|
249
|
+
|
250
|
+
LJLIB_CF(ffi_meta___sub) LJLIB_REC(cdata_arith MM_sub)
|
251
|
+
{
|
252
|
+
return ffi_arith(L);
|
253
|
+
}
|
254
|
+
|
255
|
+
LJLIB_CF(ffi_meta___mul) LJLIB_REC(cdata_arith MM_mul)
|
256
|
+
{
|
257
|
+
return ffi_arith(L);
|
258
|
+
}
|
259
|
+
|
260
|
+
LJLIB_CF(ffi_meta___div) LJLIB_REC(cdata_arith MM_div)
|
261
|
+
{
|
262
|
+
return ffi_arith(L);
|
263
|
+
}
|
264
|
+
|
265
|
+
LJLIB_CF(ffi_meta___mod) LJLIB_REC(cdata_arith MM_mod)
|
266
|
+
{
|
267
|
+
return ffi_arith(L);
|
268
|
+
}
|
269
|
+
|
270
|
+
LJLIB_CF(ffi_meta___pow) LJLIB_REC(cdata_arith MM_pow)
|
271
|
+
{
|
272
|
+
return ffi_arith(L);
|
273
|
+
}
|
274
|
+
|
275
|
+
LJLIB_CF(ffi_meta___unm) LJLIB_REC(cdata_arith MM_unm)
|
276
|
+
{
|
277
|
+
return ffi_arith(L);
|
278
|
+
}
|
279
|
+
/* End of contiguous ORDER MM. */
|
280
|
+
|
281
|
+
LJLIB_CF(ffi_meta___tostring)
|
282
|
+
{
|
283
|
+
GCcdata *cd = ffi_checkcdata(L, 1);
|
284
|
+
const char *msg = "cdata<%s>: %p";
|
285
|
+
CTypeID id = cd->ctypeid;
|
286
|
+
void *p = cdataptr(cd);
|
287
|
+
if (id == CTID_CTYPEID) {
|
288
|
+
msg = "ctype<%s>";
|
289
|
+
id = *(CTypeID *)p;
|
290
|
+
} else {
|
291
|
+
CTState *cts = ctype_cts(L);
|
292
|
+
CType *ct = ctype_raw(cts, id);
|
293
|
+
if (ctype_isref(ct->info)) {
|
294
|
+
p = *(void **)p;
|
295
|
+
ct = ctype_rawchild(cts, ct);
|
296
|
+
}
|
297
|
+
if (ctype_iscomplex(ct->info)) {
|
298
|
+
setstrV(L, L->top-1, lj_ctype_repr_complex(L, cdataptr(cd), ct->size));
|
299
|
+
goto checkgc;
|
300
|
+
} else if (ct->size == 8 && ctype_isinteger(ct->info)) {
|
301
|
+
setstrV(L, L->top-1, lj_ctype_repr_int64(L, *(uint64_t *)cdataptr(cd),
|
302
|
+
(ct->info & CTF_UNSIGNED)));
|
303
|
+
goto checkgc;
|
304
|
+
} else if (ctype_isfunc(ct->info)) {
|
305
|
+
p = *(void **)p;
|
306
|
+
} else if (ctype_isenum(ct->info)) {
|
307
|
+
msg = "cdata<%s>: %d";
|
308
|
+
p = (void *)(uintptr_t)*(uint32_t **)p;
|
309
|
+
} else {
|
310
|
+
if (ctype_isptr(ct->info)) {
|
311
|
+
p = cdata_getptr(p, ct->size);
|
312
|
+
ct = ctype_rawchild(cts, ct);
|
313
|
+
}
|
314
|
+
if (ctype_isstruct(ct->info) || ctype_isvector(ct->info)) {
|
315
|
+
/* Handle ctype __tostring metamethod. */
|
316
|
+
cTValue *tv = lj_ctype_meta(cts, ctype_typeid(cts, ct), MM_tostring);
|
317
|
+
if (tv)
|
318
|
+
return lj_meta_tailcall(L, tv);
|
319
|
+
}
|
320
|
+
}
|
321
|
+
}
|
322
|
+
lj_strfmt_pushf(L, msg, strdata(lj_ctype_repr(L, id, NULL)), p);
|
323
|
+
checkgc:
|
324
|
+
lj_gc_check(L);
|
325
|
+
return 1;
|
326
|
+
}
|
327
|
+
|
328
|
+
static int ffi_pairs(lua_State *L, MMS mm)
|
329
|
+
{
|
330
|
+
CTState *cts = ctype_cts(L);
|
331
|
+
CTypeID id = ffi_checkcdata(L, 1)->ctypeid;
|
332
|
+
CType *ct = ctype_raw(cts, id);
|
333
|
+
cTValue *tv;
|
334
|
+
if (ctype_isptr(ct->info)) id = ctype_cid(ct->info);
|
335
|
+
tv = lj_ctype_meta(cts, id, mm);
|
336
|
+
if (!tv)
|
337
|
+
lj_err_callerv(L, LJ_ERR_FFI_BADMM, strdata(lj_ctype_repr(L, id, NULL)),
|
338
|
+
strdata(mmname_str(G(L), mm)));
|
339
|
+
return lj_meta_tailcall(L, tv);
|
340
|
+
}
|
341
|
+
|
342
|
+
LJLIB_CF(ffi_meta___pairs)
|
343
|
+
{
|
344
|
+
return ffi_pairs(L, MM_pairs);
|
345
|
+
}
|
346
|
+
|
347
|
+
LJLIB_CF(ffi_meta___ipairs)
|
348
|
+
{
|
349
|
+
return ffi_pairs(L, MM_ipairs);
|
350
|
+
}
|
351
|
+
|
352
|
+
LJLIB_PUSH("ffi") LJLIB_SET(__metatable)
|
353
|
+
|
354
|
+
#include "lj_libdef.h"
|
355
|
+
|
356
|
+
/* -- C library metamethods ----------------------------------------------- */
|
357
|
+
|
358
|
+
#define LJLIB_MODULE_ffi_clib
|
359
|
+
|
360
|
+
/* Index C library by a name. */
|
361
|
+
static TValue *ffi_clib_index(lua_State *L)
|
362
|
+
{
|
363
|
+
TValue *o = L->base;
|
364
|
+
CLibrary *cl;
|
365
|
+
if (!(o < L->top && tvisudata(o) && udataV(o)->udtype == UDTYPE_FFI_CLIB))
|
366
|
+
lj_err_argt(L, 1, LUA_TUSERDATA);
|
367
|
+
cl = (CLibrary *)uddata(udataV(o));
|
368
|
+
if (!(o+1 < L->top && tvisstr(o+1)))
|
369
|
+
lj_err_argt(L, 2, LUA_TSTRING);
|
370
|
+
return lj_clib_index(L, cl, strV(o+1));
|
371
|
+
}
|
372
|
+
|
373
|
+
LJLIB_CF(ffi_clib___index) LJLIB_REC(clib_index 1)
|
374
|
+
{
|
375
|
+
TValue *tv = ffi_clib_index(L);
|
376
|
+
if (tviscdata(tv)) {
|
377
|
+
CTState *cts = ctype_cts(L);
|
378
|
+
GCcdata *cd = cdataV(tv);
|
379
|
+
CType *s = ctype_get(cts, cd->ctypeid);
|
380
|
+
if (ctype_isextern(s->info)) {
|
381
|
+
CTypeID sid = ctype_cid(s->info);
|
382
|
+
void *sp = *(void **)cdataptr(cd);
|
383
|
+
CType *ct = ctype_raw(cts, sid);
|
384
|
+
if (lj_cconv_tv_ct(cts, ct, sid, L->top-1, sp))
|
385
|
+
lj_gc_check(L);
|
386
|
+
return 1;
|
387
|
+
}
|
388
|
+
}
|
389
|
+
copyTV(L, L->top-1, tv);
|
390
|
+
return 1;
|
391
|
+
}
|
392
|
+
|
393
|
+
LJLIB_CF(ffi_clib___newindex) LJLIB_REC(clib_index 0)
|
394
|
+
{
|
395
|
+
TValue *tv = ffi_clib_index(L);
|
396
|
+
TValue *o = L->base+2;
|
397
|
+
if (o < L->top && tviscdata(tv)) {
|
398
|
+
CTState *cts = ctype_cts(L);
|
399
|
+
GCcdata *cd = cdataV(tv);
|
400
|
+
CType *d = ctype_get(cts, cd->ctypeid);
|
401
|
+
if (ctype_isextern(d->info)) {
|
402
|
+
CTInfo qual = 0;
|
403
|
+
for (;;) { /* Skip attributes and collect qualifiers. */
|
404
|
+
d = ctype_child(cts, d);
|
405
|
+
if (!ctype_isattrib(d->info)) break;
|
406
|
+
if (ctype_attrib(d->info) == CTA_QUAL) qual |= d->size;
|
407
|
+
}
|
408
|
+
if (!((d->info|qual) & CTF_CONST)) {
|
409
|
+
lj_cconv_ct_tv(cts, d, *(void **)cdataptr(cd), o, 0);
|
410
|
+
return 0;
|
411
|
+
}
|
412
|
+
}
|
413
|
+
}
|
414
|
+
lj_err_caller(L, LJ_ERR_FFI_WRCONST);
|
415
|
+
return 0; /* unreachable */
|
416
|
+
}
|
417
|
+
|
418
|
+
LJLIB_CF(ffi_clib___gc)
|
419
|
+
{
|
420
|
+
TValue *o = L->base;
|
421
|
+
if (o < L->top && tvisudata(o) && udataV(o)->udtype == UDTYPE_FFI_CLIB)
|
422
|
+
lj_clib_unload((CLibrary *)uddata(udataV(o)));
|
423
|
+
return 0;
|
424
|
+
}
|
425
|
+
|
426
|
+
#include "lj_libdef.h"
|
427
|
+
|
428
|
+
/* -- Callback function metamethods --------------------------------------- */
|
429
|
+
|
430
|
+
#define LJLIB_MODULE_ffi_callback
|
431
|
+
|
432
|
+
static int ffi_callback_set(lua_State *L, GCfunc *fn)
|
433
|
+
{
|
434
|
+
GCcdata *cd = ffi_checkcdata(L, 1);
|
435
|
+
CTState *cts = ctype_cts(L);
|
436
|
+
CType *ct = ctype_raw(cts, cd->ctypeid);
|
437
|
+
if (ctype_isptr(ct->info) && (LJ_32 || ct->size == 8)) {
|
438
|
+
MSize slot = lj_ccallback_ptr2slot(cts, *(void **)cdataptr(cd));
|
439
|
+
if (slot < cts->cb.sizeid && cts->cb.cbid[slot] != 0) {
|
440
|
+
GCtab *t = cts->miscmap;
|
441
|
+
TValue *tv = lj_tab_setint(L, t, (int32_t)slot);
|
442
|
+
if (fn) {
|
443
|
+
setfuncV(L, tv, fn);
|
444
|
+
lj_gc_anybarriert(L, t);
|
445
|
+
} else {
|
446
|
+
setnilV(tv);
|
447
|
+
cts->cb.cbid[slot] = 0;
|
448
|
+
cts->cb.topid = slot < cts->cb.topid ? slot : cts->cb.topid;
|
449
|
+
}
|
450
|
+
return 0;
|
451
|
+
}
|
452
|
+
}
|
453
|
+
lj_err_caller(L, LJ_ERR_FFI_BADCBACK);
|
454
|
+
return 0;
|
455
|
+
}
|
456
|
+
|
457
|
+
LJLIB_CF(ffi_callback_free)
|
458
|
+
{
|
459
|
+
return ffi_callback_set(L, NULL);
|
460
|
+
}
|
461
|
+
|
462
|
+
LJLIB_CF(ffi_callback_set)
|
463
|
+
{
|
464
|
+
GCfunc *fn = lj_lib_checkfunc(L, 2);
|
465
|
+
return ffi_callback_set(L, fn);
|
466
|
+
}
|
467
|
+
|
468
|
+
LJLIB_PUSH(top-1) LJLIB_SET(__index)
|
469
|
+
|
470
|
+
#include "lj_libdef.h"
|
471
|
+
|
472
|
+
/* -- FFI library functions ----------------------------------------------- */
|
473
|
+
|
474
|
+
#define LJLIB_MODULE_ffi
|
475
|
+
|
476
|
+
LJLIB_CF(ffi_cdef)
|
477
|
+
{
|
478
|
+
GCstr *s = lj_lib_checkstr(L, 1);
|
479
|
+
CPState cp;
|
480
|
+
int errcode;
|
481
|
+
cp.L = L;
|
482
|
+
cp.cts = ctype_cts(L);
|
483
|
+
cp.srcname = strdata(s);
|
484
|
+
cp.p = strdata(s);
|
485
|
+
cp.param = L->base+1;
|
486
|
+
cp.mode = CPARSE_MODE_MULTI|CPARSE_MODE_DIRECT;
|
487
|
+
errcode = lj_cparse(&cp);
|
488
|
+
if (errcode) lj_err_throw(L, errcode); /* Propagate errors. */
|
489
|
+
lj_gc_check(L);
|
490
|
+
return 0;
|
491
|
+
}
|
492
|
+
|
493
|
+
LJLIB_CF(ffi_new) LJLIB_REC(.)
|
494
|
+
{
|
495
|
+
CTState *cts = ctype_cts(L);
|
496
|
+
CTypeID id = ffi_checkctype(L, cts, NULL);
|
497
|
+
CType *ct = ctype_raw(cts, id);
|
498
|
+
CTSize sz;
|
499
|
+
CTInfo info = lj_ctype_info(cts, id, &sz);
|
500
|
+
TValue *o = L->base+1;
|
501
|
+
GCcdata *cd;
|
502
|
+
if ((info & CTF_VLA)) {
|
503
|
+
o++;
|
504
|
+
sz = lj_ctype_vlsize(cts, ct, (CTSize)ffi_checkint(L, 2));
|
505
|
+
}
|
506
|
+
if (sz == CTSIZE_INVALID)
|
507
|
+
lj_err_arg(L, 1, LJ_ERR_FFI_INVSIZE);
|
508
|
+
if (!(info & CTF_VLA) && ctype_align(info) <= CT_MEMALIGN)
|
509
|
+
cd = lj_cdata_new(cts, id, sz);
|
510
|
+
else
|
511
|
+
cd = lj_cdata_newv(L, id, sz, ctype_align(info));
|
512
|
+
setcdataV(L, o-1, cd); /* Anchor the uninitialized cdata. */
|
513
|
+
lj_cconv_ct_init(cts, ct, sz, cdataptr(cd),
|
514
|
+
o, (MSize)(L->top - o)); /* Initialize cdata. */
|
515
|
+
if (ctype_isstruct(ct->info)) {
|
516
|
+
/* Handle ctype __gc metamethod. Use the fast lookup here. */
|
517
|
+
cTValue *tv = lj_tab_getinth(cts->miscmap, -(int32_t)id);
|
518
|
+
if (tv && tvistab(tv) && (tv = lj_meta_fast(L, tabV(tv), MM_gc))) {
|
519
|
+
GCtab *t = cts->finalizer;
|
520
|
+
if (gcref(t->metatable)) {
|
521
|
+
/* Add to finalizer table, if still enabled. */
|
522
|
+
copyTV(L, lj_tab_set(L, t, o-1), tv);
|
523
|
+
lj_gc_anybarriert(L, t);
|
524
|
+
cd->marked |= LJ_GC_CDATA_FIN;
|
525
|
+
}
|
526
|
+
}
|
527
|
+
}
|
528
|
+
L->top = o; /* Only return the cdata itself. */
|
529
|
+
lj_gc_check(L);
|
530
|
+
return 1;
|
531
|
+
}
|
532
|
+
|
533
|
+
LJLIB_CF(ffi_cast) LJLIB_REC(ffi_new)
|
534
|
+
{
|
535
|
+
CTState *cts = ctype_cts(L);
|
536
|
+
CTypeID id = ffi_checkctype(L, cts, NULL);
|
537
|
+
CType *d = ctype_raw(cts, id);
|
538
|
+
TValue *o = lj_lib_checkany(L, 2);
|
539
|
+
L->top = o+1; /* Make sure this is the last item on the stack. */
|
540
|
+
if (!(ctype_isnum(d->info) || ctype_isptr(d->info) || ctype_isenum(d->info)))
|
541
|
+
lj_err_arg(L, 1, LJ_ERR_FFI_INVTYPE);
|
542
|
+
if (!(tviscdata(o) && cdataV(o)->ctypeid == id)) {
|
543
|
+
GCcdata *cd = lj_cdata_new(cts, id, d->size);
|
544
|
+
lj_cconv_ct_tv(cts, d, cdataptr(cd), o, CCF_CAST);
|
545
|
+
setcdataV(L, o, cd);
|
546
|
+
lj_gc_check(L);
|
547
|
+
}
|
548
|
+
return 1;
|
549
|
+
}
|
550
|
+
|
551
|
+
LJLIB_CF(ffi_typeof) LJLIB_REC(.)
|
552
|
+
{
|
553
|
+
CTState *cts = ctype_cts(L);
|
554
|
+
CTypeID id = ffi_checkctype(L, cts, L->base+1);
|
555
|
+
GCcdata *cd = lj_cdata_new(cts, CTID_CTYPEID, 4);
|
556
|
+
*(CTypeID *)cdataptr(cd) = id;
|
557
|
+
setcdataV(L, L->top-1, cd);
|
558
|
+
lj_gc_check(L);
|
559
|
+
return 1;
|
560
|
+
}
|
561
|
+
|
562
|
+
/* Internal and unsupported API. */
|
563
|
+
LJLIB_CF(ffi_typeinfo)
|
564
|
+
{
|
565
|
+
CTState *cts = ctype_cts(L);
|
566
|
+
CTypeID id = (CTypeID)ffi_checkint(L, 1);
|
567
|
+
if (id > 0 && id < cts->top) {
|
568
|
+
CType *ct = ctype_get(cts, id);
|
569
|
+
GCtab *t;
|
570
|
+
lua_createtable(L, 0, 4); /* Increment hash size if fields are added. */
|
571
|
+
t = tabV(L->top-1);
|
572
|
+
setintV(lj_tab_setstr(L, t, lj_str_newlit(L, "info")), (int32_t)ct->info);
|
573
|
+
if (ct->size != CTSIZE_INVALID)
|
574
|
+
setintV(lj_tab_setstr(L, t, lj_str_newlit(L, "size")), (int32_t)ct->size);
|
575
|
+
if (ct->sib)
|
576
|
+
setintV(lj_tab_setstr(L, t, lj_str_newlit(L, "sib")), (int32_t)ct->sib);
|
577
|
+
if (gcref(ct->name)) {
|
578
|
+
GCstr *s = gco2str(gcref(ct->name));
|
579
|
+
setstrV(L, lj_tab_setstr(L, t, lj_str_newlit(L, "name")), s);
|
580
|
+
}
|
581
|
+
lj_gc_check(L);
|
582
|
+
return 1;
|
583
|
+
}
|
584
|
+
return 0;
|
585
|
+
}
|
586
|
+
|
587
|
+
LJLIB_CF(ffi_istype) LJLIB_REC(.)
|
588
|
+
{
|
589
|
+
CTState *cts = ctype_cts(L);
|
590
|
+
CTypeID id1 = ffi_checkctype(L, cts, NULL);
|
591
|
+
TValue *o = lj_lib_checkany(L, 2);
|
592
|
+
int b = 0;
|
593
|
+
if (tviscdata(o)) {
|
594
|
+
GCcdata *cd = cdataV(o);
|
595
|
+
CTypeID id2 = cd->ctypeid == CTID_CTYPEID ? *(CTypeID *)cdataptr(cd) :
|
596
|
+
cd->ctypeid;
|
597
|
+
CType *ct1 = lj_ctype_rawref(cts, id1);
|
598
|
+
CType *ct2 = lj_ctype_rawref(cts, id2);
|
599
|
+
if (ct1 == ct2) {
|
600
|
+
b = 1;
|
601
|
+
} else if (ctype_type(ct1->info) == ctype_type(ct2->info) &&
|
602
|
+
ct1->size == ct2->size) {
|
603
|
+
if (ctype_ispointer(ct1->info))
|
604
|
+
b = lj_cconv_compatptr(cts, ct1, ct2, CCF_IGNQUAL);
|
605
|
+
else if (ctype_isnum(ct1->info) || ctype_isvoid(ct1->info))
|
606
|
+
b = (((ct1->info ^ ct2->info) & ~(CTF_QUAL|CTF_LONG)) == 0);
|
607
|
+
} else if (ctype_isstruct(ct1->info) && ctype_isptr(ct2->info) &&
|
608
|
+
ct1 == ctype_rawchild(cts, ct2)) {
|
609
|
+
b = 1;
|
610
|
+
}
|
611
|
+
}
|
612
|
+
setboolV(L->top-1, b);
|
613
|
+
setboolV(&G(L)->tmptv2, b); /* Remember for trace recorder. */
|
614
|
+
return 1;
|
615
|
+
}
|
616
|
+
|
617
|
+
LJLIB_CF(ffi_sizeof) LJLIB_REC(ffi_xof FF_ffi_sizeof)
|
618
|
+
{
|
619
|
+
CTState *cts = ctype_cts(L);
|
620
|
+
CTypeID id = ffi_checkctype(L, cts, NULL);
|
621
|
+
CTSize sz;
|
622
|
+
if (LJ_UNLIKELY(tviscdata(L->base) && cdataisv(cdataV(L->base)))) {
|
623
|
+
sz = cdatavlen(cdataV(L->base));
|
624
|
+
} else {
|
625
|
+
CType *ct = lj_ctype_rawref(cts, id);
|
626
|
+
if (ctype_isvltype(ct->info))
|
627
|
+
sz = lj_ctype_vlsize(cts, ct, (CTSize)ffi_checkint(L, 2));
|
628
|
+
else
|
629
|
+
sz = ctype_hassize(ct->info) ? ct->size : CTSIZE_INVALID;
|
630
|
+
if (LJ_UNLIKELY(sz == CTSIZE_INVALID)) {
|
631
|
+
setnilV(L->top-1);
|
632
|
+
return 1;
|
633
|
+
}
|
634
|
+
}
|
635
|
+
setintV(L->top-1, (int32_t)sz);
|
636
|
+
return 1;
|
637
|
+
}
|
638
|
+
|
639
|
+
LJLIB_CF(ffi_alignof) LJLIB_REC(ffi_xof FF_ffi_alignof)
|
640
|
+
{
|
641
|
+
CTState *cts = ctype_cts(L);
|
642
|
+
CTypeID id = ffi_checkctype(L, cts, NULL);
|
643
|
+
CTSize sz = 0;
|
644
|
+
CTInfo info = lj_ctype_info(cts, id, &sz);
|
645
|
+
setintV(L->top-1, 1 << ctype_align(info));
|
646
|
+
return 1;
|
647
|
+
}
|
648
|
+
|
649
|
+
LJLIB_CF(ffi_offsetof) LJLIB_REC(ffi_xof FF_ffi_offsetof)
|
650
|
+
{
|
651
|
+
CTState *cts = ctype_cts(L);
|
652
|
+
CTypeID id = ffi_checkctype(L, cts, NULL);
|
653
|
+
GCstr *name = lj_lib_checkstr(L, 2);
|
654
|
+
CType *ct = lj_ctype_rawref(cts, id);
|
655
|
+
CTSize ofs;
|
656
|
+
if (ctype_isstruct(ct->info) && ct->size != CTSIZE_INVALID) {
|
657
|
+
CType *fct = lj_ctype_getfield(cts, ct, name, &ofs);
|
658
|
+
if (fct) {
|
659
|
+
setintV(L->top-1, ofs);
|
660
|
+
if (ctype_isfield(fct->info)) {
|
661
|
+
return 1;
|
662
|
+
} else if (ctype_isbitfield(fct->info)) {
|
663
|
+
setintV(L->top++, ctype_bitpos(fct->info));
|
664
|
+
setintV(L->top++, ctype_bitbsz(fct->info));
|
665
|
+
return 3;
|
666
|
+
}
|
667
|
+
}
|
668
|
+
}
|
669
|
+
return 0;
|
670
|
+
}
|
671
|
+
|
672
|
+
LJLIB_CF(ffi_errno) LJLIB_REC(.)
|
673
|
+
{
|
674
|
+
int err = errno;
|
675
|
+
if (L->top > L->base)
|
676
|
+
errno = ffi_checkint(L, 1);
|
677
|
+
setintV(L->top++, err);
|
678
|
+
return 1;
|
679
|
+
}
|
680
|
+
|
681
|
+
LJLIB_CF(ffi_string) LJLIB_REC(.)
|
682
|
+
{
|
683
|
+
CTState *cts = ctype_cts(L);
|
684
|
+
TValue *o = lj_lib_checkany(L, 1);
|
685
|
+
const char *p;
|
686
|
+
size_t len;
|
687
|
+
if (o+1 < L->top && !tvisnil(o+1)) {
|
688
|
+
len = (size_t)ffi_checkint(L, 2);
|
689
|
+
lj_cconv_ct_tv(cts, ctype_get(cts, CTID_P_CVOID), (uint8_t *)&p, o,
|
690
|
+
CCF_ARG(1));
|
691
|
+
} else {
|
692
|
+
lj_cconv_ct_tv(cts, ctype_get(cts, CTID_P_CCHAR), (uint8_t *)&p, o,
|
693
|
+
CCF_ARG(1));
|
694
|
+
len = strlen(p);
|
695
|
+
}
|
696
|
+
L->top = o+1; /* Make sure this is the last item on the stack. */
|
697
|
+
setstrV(L, o, lj_str_new(L, p, len));
|
698
|
+
lj_gc_check(L);
|
699
|
+
return 1;
|
700
|
+
}
|
701
|
+
|
702
|
+
LJLIB_CF(ffi_copy) LJLIB_REC(.)
|
703
|
+
{
|
704
|
+
void *dp = ffi_checkptr(L, 1, CTID_P_VOID);
|
705
|
+
void *sp = ffi_checkptr(L, 2, CTID_P_CVOID);
|
706
|
+
TValue *o = L->base+1;
|
707
|
+
CTSize len;
|
708
|
+
if (tvisstr(o) && o+1 >= L->top)
|
709
|
+
len = strV(o)->len+1; /* Copy Lua string including trailing '\0'. */
|
710
|
+
else
|
711
|
+
len = (CTSize)ffi_checkint(L, 3);
|
712
|
+
memcpy(dp, sp, len);
|
713
|
+
return 0;
|
714
|
+
}
|
715
|
+
|
716
|
+
LJLIB_CF(ffi_fill) LJLIB_REC(.)
|
717
|
+
{
|
718
|
+
void *dp = ffi_checkptr(L, 1, CTID_P_VOID);
|
719
|
+
CTSize len = (CTSize)ffi_checkint(L, 2);
|
720
|
+
int32_t fill = 0;
|
721
|
+
if (L->base+2 < L->top && !tvisnil(L->base+2)) fill = ffi_checkint(L, 3);
|
722
|
+
memset(dp, fill, len);
|
723
|
+
return 0;
|
724
|
+
}
|
725
|
+
|
726
|
+
#define H_(le, be) LJ_ENDIAN_SELECT(0x##le, 0x##be)
|
727
|
+
|
728
|
+
/* Test ABI string. */
|
729
|
+
LJLIB_CF(ffi_abi) LJLIB_REC(.)
|
730
|
+
{
|
731
|
+
GCstr *s = lj_lib_checkstr(L, 1);
|
732
|
+
int b = 0;
|
733
|
+
switch (s->hash) {
|
734
|
+
#if LJ_64
|
735
|
+
case H_(849858eb,ad35fd06): b = 1; break; /* 64bit */
|
736
|
+
#else
|
737
|
+
case H_(662d3c79,d0e22477): b = 1; break; /* 32bit */
|
738
|
+
#endif
|
739
|
+
#if LJ_ARCH_HASFPU
|
740
|
+
case H_(e33ee463,e33ee463): b = 1; break; /* fpu */
|
741
|
+
#endif
|
742
|
+
#if LJ_ABI_SOFTFP
|
743
|
+
case H_(61211a23,c2e8c81c): b = 1; break; /* softfp */
|
744
|
+
#else
|
745
|
+
case H_(539417a8,8ce0812f): b = 1; break; /* hardfp */
|
746
|
+
#endif
|
747
|
+
#if LJ_ABI_EABI
|
748
|
+
case H_(2182df8f,f2ed1152): b = 1; break; /* eabi */
|
749
|
+
#endif
|
750
|
+
#if LJ_ABI_WIN
|
751
|
+
case H_(4ab624a8,4ab624a8): b = 1; break; /* win */
|
752
|
+
#endif
|
753
|
+
case H_(3af93066,1f001464): b = 1; break; /* le/be */
|
754
|
+
#if LJ_GC64
|
755
|
+
case H_(9e89d2c9,13c83c92): b = 1; break; /* gc64 */
|
756
|
+
#endif
|
757
|
+
default:
|
758
|
+
break;
|
759
|
+
}
|
760
|
+
setboolV(L->top-1, b);
|
761
|
+
setboolV(&G(L)->tmptv2, b); /* Remember for trace recorder. */
|
762
|
+
return 1;
|
763
|
+
}
|
764
|
+
|
765
|
+
#undef H_
|
766
|
+
|
767
|
+
LJLIB_PUSH(top-8) LJLIB_SET(!) /* Store reference to miscmap table. */
|
768
|
+
|
769
|
+
LJLIB_CF(ffi_metatype)
|
770
|
+
{
|
771
|
+
CTState *cts = ctype_cts(L);
|
772
|
+
CTypeID id = ffi_checkctype(L, cts, NULL);
|
773
|
+
GCtab *mt = lj_lib_checktab(L, 2);
|
774
|
+
GCtab *t = cts->miscmap;
|
775
|
+
CType *ct = ctype_get(cts, id); /* Only allow raw types. */
|
776
|
+
TValue *tv;
|
777
|
+
GCcdata *cd;
|
778
|
+
if (!(ctype_isstruct(ct->info) || ctype_iscomplex(ct->info) ||
|
779
|
+
ctype_isvector(ct->info)))
|
780
|
+
lj_err_arg(L, 1, LJ_ERR_FFI_INVTYPE);
|
781
|
+
tv = lj_tab_setinth(L, t, -(int32_t)id);
|
782
|
+
if (!tvisnil(tv))
|
783
|
+
lj_err_caller(L, LJ_ERR_PROTMT);
|
784
|
+
settabV(L, tv, mt);
|
785
|
+
lj_gc_anybarriert(L, t);
|
786
|
+
cd = lj_cdata_new(cts, CTID_CTYPEID, 4);
|
787
|
+
*(CTypeID *)cdataptr(cd) = id;
|
788
|
+
setcdataV(L, L->top-1, cd);
|
789
|
+
lj_gc_check(L);
|
790
|
+
return 1;
|
791
|
+
}
|
792
|
+
|
793
|
+
LJLIB_PUSH(top-7) LJLIB_SET(!) /* Store reference to finalizer table. */
|
794
|
+
|
795
|
+
LJLIB_CF(ffi_gc) LJLIB_REC(.)
|
796
|
+
{
|
797
|
+
GCcdata *cd = ffi_checkcdata(L, 1);
|
798
|
+
TValue *fin = lj_lib_checkany(L, 2);
|
799
|
+
CTState *cts = ctype_cts(L);
|
800
|
+
CType *ct = ctype_raw(cts, cd->ctypeid);
|
801
|
+
if (!(ctype_isptr(ct->info) || ctype_isstruct(ct->info) ||
|
802
|
+
ctype_isrefarray(ct->info)))
|
803
|
+
lj_err_arg(L, 1, LJ_ERR_FFI_INVTYPE);
|
804
|
+
lj_cdata_setfin(L, cd, gcval(fin), itype(fin));
|
805
|
+
L->top = L->base+1; /* Pass through the cdata object. */
|
806
|
+
return 1;
|
807
|
+
}
|
808
|
+
|
809
|
+
LJLIB_PUSH(top-5) LJLIB_SET(!) /* Store clib metatable in func environment. */
|
810
|
+
|
811
|
+
LJLIB_CF(ffi_load)
|
812
|
+
{
|
813
|
+
GCstr *name = lj_lib_checkstr(L, 1);
|
814
|
+
int global = (L->base+1 < L->top && tvistruecond(L->base+1));
|
815
|
+
lj_clib_load(L, tabref(curr_func(L)->c.env), name, global);
|
816
|
+
return 1;
|
817
|
+
}
|
818
|
+
|
819
|
+
LJLIB_PUSH(top-4) LJLIB_SET(C)
|
820
|
+
LJLIB_PUSH(top-3) LJLIB_SET(os)
|
821
|
+
LJLIB_PUSH(top-2) LJLIB_SET(arch)
|
822
|
+
|
823
|
+
#include "lj_libdef.h"
|
824
|
+
|
825
|
+
/* ------------------------------------------------------------------------ */
|
826
|
+
|
827
|
+
/* Create special weak-keyed finalizer table. */
|
828
|
+
static GCtab *ffi_finalizer(lua_State *L)
|
829
|
+
{
|
830
|
+
/* NOBARRIER: The table is new (marked white). */
|
831
|
+
GCtab *t = lj_tab_new(L, 0, 1);
|
832
|
+
settabV(L, L->top++, t);
|
833
|
+
setgcref(t->metatable, obj2gco(t));
|
834
|
+
setstrV(L, lj_tab_setstr(L, t, lj_str_newlit(L, "__mode")),
|
835
|
+
lj_str_newlit(L, "K"));
|
836
|
+
t->nomm = (uint8_t)(~(1u<<MM_mode));
|
837
|
+
return t;
|
838
|
+
}
|
839
|
+
|
840
|
+
/* Register FFI module as loaded. */
|
841
|
+
static void ffi_register_module(lua_State *L)
|
842
|
+
{
|
843
|
+
cTValue *tmp = lj_tab_getstr(tabV(registry(L)), lj_str_newlit(L, "_LOADED"));
|
844
|
+
if (tmp && tvistab(tmp)) {
|
845
|
+
GCtab *t = tabV(tmp);
|
846
|
+
copyTV(L, lj_tab_setstr(L, t, lj_str_newlit(L, LUA_FFILIBNAME)), L->top-1);
|
847
|
+
lj_gc_anybarriert(L, t);
|
848
|
+
}
|
849
|
+
}
|
850
|
+
|
851
|
+
LUALIB_API int luaopen_ffi(lua_State *L)
|
852
|
+
{
|
853
|
+
CTState *cts = lj_ctype_init(L);
|
854
|
+
settabV(L, L->top++, (cts->miscmap = lj_tab_new(L, 0, 1)));
|
855
|
+
cts->finalizer = ffi_finalizer(L);
|
856
|
+
LJ_LIB_REG(L, NULL, ffi_meta);
|
857
|
+
/* NOBARRIER: basemt is a GC root. */
|
858
|
+
setgcref(basemt_it(G(L), LJ_TCDATA), obj2gco(tabV(L->top-1)));
|
859
|
+
LJ_LIB_REG(L, NULL, ffi_clib);
|
860
|
+
LJ_LIB_REG(L, NULL, ffi_callback);
|
861
|
+
/* NOBARRIER: the key is new and lj_tab_newkey() handles the barrier. */
|
862
|
+
settabV(L, lj_tab_setstr(L, cts->miscmap, &cts->g->strempty), tabV(L->top-1));
|
863
|
+
L->top--;
|
864
|
+
lj_clib_default(L, tabV(L->top-1)); /* Create ffi.C default namespace. */
|
865
|
+
lua_pushliteral(L, LJ_OS_NAME);
|
866
|
+
lua_pushliteral(L, LJ_ARCH_NAME);
|
867
|
+
LJ_LIB_REG(L, NULL, ffi); /* Note: no global "ffi" created! */
|
868
|
+
ffi_register_module(L);
|
869
|
+
return 1;
|
870
|
+
}
|
871
|
+
|
872
|
+
#endif
|