aboutsummaryrefslogtreecommitdiffstats
path: root/bruiser
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xbruiser/autogen/wasm/ft.sh3
-rw-r--r--bruiser/autogen/wasm/ft/autowasm.c8
-rw-r--r--bruiser/autogen/wasm/ft/makefile34
-rw-r--r--bruiser/autogen/wasm/ltg/makefile2
-rw-r--r--bruiser/bruiser.cpp51
m---------bruiser/faultreiber0
-rw-r--r--bruiser/lua-scripts/wasmtest.lua142
m---------bruiser/tablegen0
8 files changed, 204 insertions, 36 deletions
diff --git a/bruiser/autogen/wasm/ft.sh b/bruiser/autogen/wasm/ft.sh
index a7f5ac6..71a4c20 100755
--- a/bruiser/autogen/wasm/ft.sh
+++ b/bruiser/autogen/wasm/ft.sh
@@ -1,5 +1,6 @@
#!/bin/sh
cd $(dirname $0)
"../../faultreiber/faultreiber.py" --name wasm --outdir ./ft/ --datetime --xml ./wasm.xml --calloc --voidtraininitsize 60 --voidtrainfactor 1.9
-#"clang-format" -i ./test/read.c ./test/structs.c ./test/structs.h ./test/aggregate.c ./test/aggregate.h ./test/read.h
+#"../../faultreiber/faultreiber.py" --name wasm --outdir ./ft/ --datetime --xml ./wasm.xml --luaalloc --voidtraininitsize 60 --voidtrainfactor 1.9 --luaheaders ../../../lua-5.3.4/src
+"clang-format" -i ./ft/read.c ./ft/structs.c ./ft/structs.h ./ft/aggregate.c ./ft/aggregate.h ./ft/read.h
#"less" ./test/structs.h
diff --git a/bruiser/autogen/wasm/ft/autowasm.c b/bruiser/autogen/wasm/ft/autowasm.c
index 42bf474..617bd42 100644
--- a/bruiser/autogen/wasm/ft/autowasm.c
+++ b/bruiser/autogen/wasm/ft/autowasm.c
@@ -9,12 +9,14 @@
#include "./aggregate.h"
#include "./read.h"
#include "./structs.h"
+#include "../../../lua-5.3.4/src/lua.h"
#pragma weak main
int main(int argc, char **argv) {
const rlim_t kStackSize = 160 * 1024 * 1024; // min stack size = 16 MB
struct rlimit rl;
int result;
+ lua_State* LS = luaL_newstate();
result = getrlimit(RLIMIT_STACK, &rl);
if (result == 0) {
@@ -27,10 +29,10 @@ int main(int argc, char **argv) {
}
}
int wasm = open("./test.wasm", O_RDONLY);
- wasm_lib_ret_t *lib_ret = read_aggr_wasm(wasm);
+#if 0
+ wasm_lib_ret_t *lib_ret = read_aggr_wasm(wasm, LS);
printf("finished reading\n");
-#if 0
printf("magic_number:%x\n",
lib_ret->obj->magic_number_container->magic_number);
printf("version:%x\n", lib_ret->obj->version_container->version);
@@ -240,6 +242,7 @@ int main(int argc, char **argv) {
// free(lib_ret->void_train[2]);
// free(lib_ret->void_train[1]);
// free(lib_ret->void_train[0]);
+#if 0
for (int i = lib_ret->current_void_count - 1; i >= 0; --i) {
printf("%d:0x%x ", i, lib_ret->void_train[i]);
// if (i == 1) continue;
@@ -248,5 +251,6 @@ int main(int argc, char **argv) {
free(lib_ret->void_train);
free(lib_ret->obj);
free(lib_ret);
+#endif
return 0;
}
diff --git a/bruiser/autogen/wasm/ft/makefile b/bruiser/autogen/wasm/ft/makefile
index b02dcfc..08e0ffe 100644
--- a/bruiser/autogen/wasm/ft/makefile
+++ b/bruiser/autogen/wasm/ft/makefile
@@ -1,13 +1,14 @@
+TARGET=autowasm
SHELL=bash
SHELL?=bash
-TARGET=autowasm
CC=clang
CC?=clang
-CC_FLAGS=-fpic
+CC_FLAGS= -fPIC
CC_EXTRA?=
CTAGS_I_PATH?=./
LD_FLAGS=
-EXTRA_LD_FLAGS?=
+LIB_LUA=../../../lua-5.3.4/src/liblua.a
+EXTRA_LD_FLAGS?=-lm -ldl
ADD_SANITIZERS_CC= -g -fsanitize=address -fno-omit-frame-pointer
ADD_SANITIZERS_LD= -g -fsanitize=address
MEM_SANITIZERS_CC= -g -fsanitize=memory -fno-omit-frame-pointer
@@ -62,8 +63,8 @@ depend:.depend
.depend:$(SRCS)
rm -rf .depend
$(CC) -MM $(CC_FLAGS) $^ > ./.depend
- echo $(patsubst %.o:, %.odbg:, $(shell $(CC) -MM $(CC_FLAGS) $^)) | sed -r 's/[a-z0-9\-\_]+\.odbg/\n&/g' >> ./.depend
- echo $(patsubst %.o:, %.ocov:, $(shell $(CC) -MM $(CC_FLAGS) $^)) | sed -r 's/[a-z0-9\-\_]+\.ocov/\n&/g' >> ./.depend
+ echo $(patsubst %.o:, %.odbg:, $(shell $(CC) -MM $(CC_FLAGS) $^)) | sed -r 's/[A-Za-z0-9\-\_]+\.odbg/\n&/g' >> ./.depend
+ echo $(patsubst %.o:, %.ocov:, $(shell $(CC) -MM $(CC_FLAGS) $^)) | sed -r 's/[A-Za-z0-9\-\_]+\.ocov/\n&/g' >> ./.depend
-include ./.depend
@@ -76,16 +77,19 @@ depend:.depend
%.ocov:%.c
$(CC) $(CC_FLAGS) $(COV_CC) -c $< -o $@
-$(TARGET): $(TARGET).o read.o aggregate.o structs.o
- $(CC) $^ $(LD_FLAGS) -o $@
+$(LIB_LUA):
+ $(MAKE) -C ../../../lua-5.3.4/src linux
+
+$(TARGET): $(TARGET).o $(LIB_LUA) read.o aggregate.o structs.o
+ $(CC) $(LD_FLAGS) $^ -o $@
-$(TARGET)-static: $(TARGET).o read.o aggregate.o structs.o
+$(TARGET)-static: $(TARGET).o $(LIB_LUA) read.o aggregate.o structs.o
$(CC) $^ $(LD_FLAGS) -static -o $@
-$(TARGET)-dbg: $(TARGET).odbg read.odbg aggregate.odbg structs.odbg
+$(TARGET)-dbg: $(TARGET).odbg $(LIB_LUA) read.odbg aggregate.odbg structs.odbg
$(CC) $^ $(LD_FLAGS) -g -o $@
-$(TARGET)-cov: $(TARGET).ocov read.ocov aggregate.ocov structs.ocov
+$(TARGET)-cov: $(TARGET).ocov $(LIB_LUA) read.ocov aggregate.ocov structs.ocov
$(CC) $^ $(LD_FLAGS) $(COV_LD) -o $@
cov:
@@ -117,13 +121,13 @@ tags:$(SRCS)
$(TARGET).so: $(TARGET).o read.o aggregate.o structs.o
$(CC) $^ $(LD_FLAGS) -shared -o $@
-$(TARGET).a: $(TARGET).o read.o aggregate.o structs.o
- ar rcs $(TARGET).a $(TARGET).o read.o aggregate.o structs.o
+$(TARGET).a: $(LIB_LUA) read.o aggregate.o structs.o
+ ar rcs $(TARGET).a read.o aggregate.o structs.o
-$(TARGET).adbg: $(TARGET).odbg read.odbg aggregate.odbg structs.odbg
- ar rcs $(TARGET).adbg $(TARGET).odbg read.odbg aggregate.odbg structs.odbg
+$(TARGET).adbg: $(LIB_LUA) read.odbg aggregate.odbg structs.odbg
+ ar rcs $(TARGET).adbg read.odbg aggregate.odbg structs.odbg
-$(TARGET).acov: $(TARGET).ocov read.ocov aggregate.ocov structs.ocov
+$(TARGET).acov: $(LIB_LUA) read.ocov aggregate.ocov structs.ocov
ar rcs $(TARGET).acov $(TARGET).ocov read.ocov aggregate.ocov structs.ocov
valgrind: $(TARGET)
diff --git a/bruiser/autogen/wasm/ltg/makefile b/bruiser/autogen/wasm/ltg/makefile
index e21fdaf..41d6c5a 100644
--- a/bruiser/autogen/wasm/ltg/makefile
+++ b/bruiser/autogen/wasm/ltg/makefile
@@ -56,7 +56,7 @@ LD_FLAGS+=$(EXTRA_LD_FLAGS)
.PHONY:all clean help ASM SO TAGS
-all: A ADBG
+all:A ADBG
everything:$(TARGET) A ASM SO $(TARGET)-static $(TARGET)-dbg TAGS $(TARGET)-cov
diff --git a/bruiser/bruiser.cpp b/bruiser/bruiser.cpp
index 6e73a44..7081b2b 100644
--- a/bruiser/bruiser.cpp
+++ b/bruiser/bruiser.cpp
@@ -1424,6 +1424,7 @@ class LuaWrapper {
}
PRINT_WITH_COLOR_LB(RED, "before");
wasm_lib_ret_t* lib_ret = read_aggr_wasm(wasm_file);
+ //wasm_lib_ret_t* lib_ret = read_aggr_wasm(wasm_file, __ls);
PRINT_WITH_COLOR_LB(RED, "after");
close(wasm_file);
@@ -1535,6 +1536,7 @@ class LuaWrapper {
printf("data seg count:%d\n", lib_ret->obj->W_Data_Section_container->count);
for (int i = 0; i < lib_ret->obj->W_Data_Section_container->count; ++i) {
+ printf("number:%d\n", i+1);
printf("index:%d\n", lib_ret->obj->W_Data_Section_container->entries[i]->index);
printf("size:%d\n", lib_ret->obj->W_Data_Section_container->entries[i]->size);
printf("code:\n");
@@ -1564,7 +1566,7 @@ class LuaWrapper {
new_magic_number(__ls);
lua_settable(__ls, -3);
}
- //PRINT_WITH_COLOR_LB(BLUE, "magic");
+ PRINT_WITH_COLOR_LB(BLUE, "magic");
if (lib_ret->obj->w32_version_container != NULL) {
lua_pushstring(__ls, "version");
@@ -1572,7 +1574,7 @@ class LuaWrapper {
new_w32_version(__ls);
lua_settable(__ls, -3);
}
- //PRINT_WITH_COLOR_LB(BLUE, "version");
+ PRINT_WITH_COLOR_LB(BLUE, "version");
if (lib_ret->obj->W_Type_Section_container != NULL) {
lua_pushstring(__ls, "type_section");
@@ -1580,7 +1582,7 @@ class LuaWrapper {
new_W_Type_Section(__ls);
lua_settable(__ls, -3);
}
- //PRINT_WITH_COLOR_LB(BLUE, "type section");
+ PRINT_WITH_COLOR_LB(BLUE, "type section");
if (lib_ret->obj->W_Import_Section_container != NULL) {
lua_pushstring(__ls, "import_section");
@@ -1588,7 +1590,7 @@ class LuaWrapper {
new_W_Import_Section(__ls);
lua_settable(__ls, -3);
}
- //PRINT_WITH_COLOR_LB(BLUE, "import section");
+ PRINT_WITH_COLOR_LB(BLUE, "import section");
if (lib_ret->obj->W_Function_Section_container != NULL) {
lua_pushstring(__ls, "function_section");
@@ -1596,7 +1598,7 @@ class LuaWrapper {
new_W_Function_Section(__ls);
lua_settable(__ls, -3);
}
- //PRINT_WITH_COLOR_LB(BLUE, "function section");
+ PRINT_WITH_COLOR_LB(BLUE, "function section");
if (lib_ret->obj->W_Table_Section_container != NULL) {
lua_pushstring(__ls, "table_section");
@@ -1604,7 +1606,7 @@ class LuaWrapper {
new_W_Table_Section(__ls);
lua_settable(__ls, -3);
}
- //PRINT_WITH_COLOR_LB(BLUE, "table section");
+ PRINT_WITH_COLOR_LB(BLUE, "table section");
if (lib_ret->obj->W_Memory_Section_container != NULL) {
lua_pushstring(__ls, "memory_section");
@@ -1612,7 +1614,7 @@ class LuaWrapper {
new_W_Memory_Section(__ls);
lua_settable(__ls, -3);
}
- //PRINT_WITH_COLOR_LB(BLUE, "memory section");
+ PRINT_WITH_COLOR_LB(BLUE, "memory section");
if (lib_ret->obj->W_Global_Section_container != NULL) {
lua_pushstring(__ls, "global_section");
@@ -1620,7 +1622,7 @@ class LuaWrapper {
new_W_Global_Section(__ls);
lua_settable(__ls, -3);
}
- //PRINT_WITH_COLOR_LB(BLUE, "global section");
+ PRINT_WITH_COLOR_LB(BLUE, "global section");
if (lib_ret->obj->W_Export_Section_container != NULL) {
lua_pushstring(__ls, "export_section");
@@ -1628,7 +1630,7 @@ class LuaWrapper {
new_W_Export_Section(__ls);
lua_settable(__ls, -3);
}
- //PRINT_WITH_COLOR_LB(BLUE, "export section");
+ PRINT_WITH_COLOR_LB(BLUE, "export section");
if (lib_ret->obj->W_Start_Section_container != NULL) {
lua_pushstring(__ls, "start_section");
@@ -1636,7 +1638,7 @@ class LuaWrapper {
new_W_Start_Section(__ls);
lua_settable(__ls, -3);
}
- //PRINT_WITH_COLOR_LB(BLUE, "start section");
+ PRINT_WITH_COLOR_LB(BLUE, "start section");
if (lib_ret->obj->W_Element_Section_container != NULL) {
lua_pushstring(__ls, "element_section");
@@ -1644,15 +1646,38 @@ class LuaWrapper {
new_W_Element_Section(__ls);
lua_settable(__ls, -3);
}
- //PRINT_WITH_COLOR_LB(BLUE, "element section");
+ PRINT_WITH_COLOR_LB(BLUE, "element section");
if (lib_ret->obj->W_Code_Section_container != NULL) {
lua_pushstring(__ls, "code_section");
W_Code_Section_push_args(__ls, lib_ret->obj->W_Code_Section_container);
new_W_Code_Section(__ls);
+ lua_pushlightuserdata(__ls, lib_ret->obj->W_Code_Section_container);
+ lua_pushvalue(__ls, -2);
+ lua_settable(__ls, LUA_REGISTRYINDEX);
+#if 1
+ for (int ii = 0; ii < lib_ret->obj->W_Code_Section_container->count; ++ii) {
+ W_Function_Body_push_args(__ls, lib_ret->obj->W_Code_Section_container->bodies[ii]);
+ new_W_Function_Body(__ls);
+ lua_pushlightuserdata(__ls, lib_ret->obj->W_Code_Section_container->bodies[ii]);
+ lua_pushvalue(__ls, -2);
+ lua_settable(__ls, LUA_REGISTRYINDEX);
+ lua_pop(__ls, 1);
+ }
+#endif
lua_settable(__ls, -3);
+#if 0
+ for (int i = 0; i < lib_ret->obj->W_Code_Section_container->count; ++i) {
+ W_Function_Body_push_args(__ls, lib_ret->obj->W_Code_Section_container->bodies[i]);
+ new_W_Function_Body(__ls);
+ for (int j = 0; j < lib_ret->obj->W_Code_Section_container->bodies[i]->local_count; ++j) {
+ W_Local_Entry_push_args(__ls, lib_ret->obj->W_Code_Section_container->bodies[i]->locals[j]);
+ new_W_Local_Entry(__ls);
+ }
+ }
+#endif
}
- //PRINT_WITH_COLOR_LB(BLUE, "code section");
+ PRINT_WITH_COLOR_LB(BLUE, "code section");
if (lib_ret->obj->W_Data_Section_container != NULL) {
lua_pushstring(__ls, "data_section");
@@ -1660,7 +1685,7 @@ class LuaWrapper {
new_W_Data_Section(__ls);
lua_settable(__ls, -3);
}
- //PRINT_WITH_COLOR_LB(BLUE, "data section");
+ PRINT_WITH_COLOR_LB(BLUE, "data section");
if (lib_ret->obj->W_Custom_Section_container != NULL) {
}
return 1;
diff --git a/bruiser/faultreiber b/bruiser/faultreiber
-Subproject da65d18f0ebf28cb8a829a946d51d7111f6b493
+Subproject 29635ce7e1f3fa2e8aeb1c6b3938ab10786cad0
diff --git a/bruiser/lua-scripts/wasmtest.lua b/bruiser/lua-scripts/wasmtest.lua
index b863081..c568b31 100644
--- a/bruiser/lua-scripts/wasmtest.lua
+++ b/bruiser/lua-scripts/wasmtest.lua
@@ -30,7 +30,6 @@ function libwasm.dump_import_section(a)
io.write("count:"..tostring(a["import_section"]:count()).."\n")
io.write("entries"..tostring(a["import_section"]:entries()).."\n")
for k, v in pairs(a["import_section"]:entries()) do
- --print(k, v, type(v))
io.write("module length:"..v:module_length().."\t")
io.write("module str:"..v:module_str().."\t")
io.write("field len:"..v:field_len().."\t")
@@ -370,6 +369,98 @@ function libwasm.demo_setters(wasm_path)
end
--FIXME-entries
+ local entry1 = W_Import_Section_Entry()
+ local entry2 = W_Import_Section_Entry()
+ local entry3 = W_Import_Section_Entry()
+ local entry4 = W_Import_Section_Entry()
+ local kind0 = 12345
+ local rsz = resizable_limit_t(111,222,333)
+ local rsz1 = resizable_limit_t(11,22,33)
+ local kind1 = table_type_t(10, rsz)
+ kind1:set_resizable_limit(rsz)
+ local kind2 = memory_type_t(rsz1)
+ kind2:set_resizable_limit(rsz1)
+ local kind3 = global_type_t(13,13)
+
+ entry1:set_module_length(3)
+ entry1:set_module_str("env")
+ entry1:set_field_len(2)
+ entry1:set_field_str("ab")
+ entry1:set_kind(0)
+ entry1:set_type(kind0)
+
+ entry2:set_module_length(3)
+ entry2:set_module_str("env")
+ entry2:set_field_len(3)
+ entry2:set_field_str("abc")
+ entry2:set_kind(1)
+ entry2:set_type(kind1)
+
+ entry3:set_module_length(3)
+ entry3:set_module_str("env")
+ entry3:set_field_len(4)
+ entry3:set_field_str("abcd")
+ entry3:set_kind(2)
+ entry3:set_type(kind2)
+
+ entry4:set_module_length(3)
+ entry4:set_module_str("env")
+ entry4:set_field_len(5)
+ entry4:set_field_str("abcde")
+ entry4:set_kind(3)
+ entry4:set_type(kind3)
+
+ local entries = {}
+ entries[1] = entry1
+ entries[2] = entry2
+ entries[3] = entry3
+ entries[4] = entry4
+
+ a["import_section"]:set_count(4)
+ pre = a["import_section"]:entries()
+ a["import_section"]:set_entries(entries)
+ post = a["import_section"]:entries()
+
+ print(colors("%{red}".."start of import seciton entry contests for settter."))
+ for k,v in pairs(a["import_section"]:entries()) do
+ print(k, v)
+ print("module_length: "..v:module_length())
+ print("module_str: "..v:module_str())
+ print("field_len: "..v:field_len())
+ print("field_str: "..v:field_str())
+ print("kind: "..v:kind())
+ --print(v:type())
+ --print(colors("%{green}"..type(v:type()).."\n"))
+ --[[
+ if v:kind() == 0 then
+ v:set_type(54321)
+ print(v:type())
+ end
+ ]]--
+ if v:kind() == 1 then
+ --io.write(colors("%{blue}"..v:type():element_type().."\n"))
+ io.write(colors("%{blue}"..v:type():resizable_limit():flags().."\n"))
+ io.write(colors("%{blue}"..v:type():resizable_limit():initial().."\n"))
+ io.write(colors("%{blue}"..v:type():resizable_limit():maximum().."\n"))
+ end
+ if v:kind() == 2 then
+ io.write(colors("%{blue}"..v:type():resizable_limit():initial().."\n"))
+ io.write(colors("%{blue}"..v:type():resizable_limit():maximum().."\n"))
+ io.write(colors("%{blue}"..v:type():resizable_limit():flags().."\n"))
+ end
+ if v:kind() == 3 then
+ io.write(colors("%{blue}"..v:type():value_type().."\n"))
+ io.write(colors("%{blue}"..v:type():mutability().."\n"))
+ end
+ end
+
+ if pre == post then
+ io.write(colors("%{red}".."import_section:entries:failure\n"))
+ else
+ io.write(colors("%{green}".."import_section:entries:pass\n"))
+ end
+
+ print(colors("%{red}".."end of import seciton entry contests for settter."))
end
end
@@ -911,10 +1002,53 @@ function libwasm.demo_setters(wasm_path)
end
+--FIXME-fixed?
+function libwasm.demo_setter_aux()
+ require("wasmextra")
+ local rsz = resizable_limit_t(111,222,333)
+ local zz = resizable_limit_t(11,22,33)
+ local kind1 = table_type_t(10, rsz)
+ local kind2 = memory_type_t(rsz)
+ local kind3 = global_type_t(1,1)
+ print(rsz:flags())
+ print(rsz:initial())
+ print(rsz:maximum())
+ rsz:set_flags(100)
+ rsz:set_initial(200)
+ rsz:set_maximum(300)
+ print(rsz:flags())
+ print(rsz:initial())
+ print(rsz:maximum())
+
+ print(kind1:element_type())
+ print(kind1:resizable_limit())
+ kind1:set_element_type(17)
+ kind1:set_resizable_limit(zz)
+ print(kind1:element_type())
+ print(kind1:resizable_limit())
+ io.write(colors("%{blue}"..kind1:resizable_limit():initial().."\n"))
+ io.write(colors("%{blue}"..kind1:resizable_limit():maximum().."\n"))
+ io.write(colors("%{blue}"..kind1:resizable_limit():flags().."\n"))
+
+ print(kind2:resizable_limit())
+ kind2:set_resizable_limit(zz)
+ print(kind2:resizable_limit())
+ print("max after set:"..kind2:resizable_limit():maximum())
+
+ print(kind3:value_type())
+ print(kind3:mutability())
+ kind3:set_value_type(0)
+ kind3:set_mutability(0)
+ print(kind3:value_type())
+ print(kind3:mutability())
+end
+
+--libwasm.demo_setters("/home/bloodstalker/devi/hell2/bruiser/autogen/wasm/test/read.wasm")
--libwasm.dev("/home/bloodstalker/devi/hell2/bruiser/autogen/wasm/ft/test.wasm")
---libwasm.demo_getters("/home/bloodstalker/extra/faultreiber/test/read.wasm")
---libwasm.demo_getters("/home/bloodstalker/devi/hell2/bruiser/autogen/wasm/test/read.wasm")
-libwasm.demo_setters("/home/bloodstalker/devi/hell2/bruiser/autogen/wasm/ft/test.wasm")
+libwasm.demo_getters("/home/bloodstalker/devi/hell2/bruiser/autogen/wasm/test/read.wasm")
+--libwasm.demo_setters("/home/bloodstalker/devi/hell2/bruiser/autogen/wasm/ft/test.wasm")
--libwasm.dump_all("/home/bloodstalker/devi/hell2/bruiser/autogen/wasm/ft/test.wasm")
+--libwasm.dump_all("/home/bloodstalker/devi/hell2/bruiser/autogen/wasm/test/read.wasm")
+--libwasm.demo_setter_aux()
return libwasm
diff --git a/bruiser/tablegen b/bruiser/tablegen
-Subproject 47c85761f66dadd4e492a641fbd66893649ea83
+Subproject 4e1ea95b5e599c765fa8f3c634730ff9c9bd6ec