diff options
-rwxr-xr-x | main.py | 2 | ||||
-rw-r--r-- | test/autowasm.c | 43 | ||||
-rw-r--r-- | test/makefile | 3 | ||||
-rw-r--r-- | text.py | 2 |
4 files changed, 45 insertions, 5 deletions
@@ -447,7 +447,7 @@ class CodeGen(object): else: read_source.write(static + inline + text.c_read_elem_sig.replace("YYY", elem.attrib["name"]).replace("XXX", elem.attrib["name"]+pointer)) read_source.write("*dummy = malloc(sizeof(" + elem.attrib["name"] + "));\n") - read_source.write(text.c_void_manager_proto.replace("XXX", "dummy")); + read_source.write(text.c_void_manager_proto.replace("XXX", "*dummy")); read_source.write(text.c_read_gen.replace("XXX", "(*dummy)->" + elem.attrib["name"]).replace("YYY", type_resolver(elem, self.def_elems))) read_source.write("return *dummy;\n") read_source.write(text.c_function_close + "\n") diff --git a/test/autowasm.c b/test/autowasm.c index 87478c1..cbc6e5a 100644 --- a/test/autowasm.c +++ b/test/autowasm.c @@ -4,6 +4,7 @@ #include <stdio.h> #include <stdlib.h> #include <unistd.h> +#include <sys/resource.h> #include "./structs.h" #include "./read.h" @@ -12,14 +13,31 @@ #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; + + result = getrlimit(RLIMIT_STACK, &rl); + if (result == 0) + { + if (rl.rlim_cur < kStackSize) + { + rl.rlim_cur = kStackSize; + result = setrlimit(RLIMIT_STACK, &rl); + if (result != 0) + { + fprintf(stderr, "setrlimit returned result = %d\n", result); + } + } + } int wasm = open("./test.wasm", O_RDONLY); wasm_lib_ret_t* lib_ret = read_aggr_wasm(wasm); 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); - printf("fuck\n"); printf("type section id:%d\n", lib_ret->obj->W_Type_Section_container->id); printf("type section payloadlength:%d\n", lib_ret->obj->W_Type_Section_container->payloadlength); printf("type_section entry count:%d\n", lib_ret->obj->W_Type_Section_container->count); @@ -139,7 +157,26 @@ int main (int argc, char** argv) { } printf("\n"); } - - release_all(lib_ret->void_train, lib_ret->current_void_count); +#endif + + printf("sizeof magic:%d\n", sizeof(magic_number)); + printf("sizeof version:%d\n", sizeof(version)); + printf("current void count:%d\n", lib_ret->current_void_count); + printf("void_train first:0x%x\n", lib_ret->void_train[0]); + printf("void_train first:0x%x\n", lib_ret->void_train[1]); + printf("void_train self address:0x%x\n", lib_ret->void_train); + //free(lib_ret->void_train[0]); + //release_all(lib_ret->void_train, lib_ret->current_void_count); + //free(lib_ret->void_train[2]); + //free(lib_ret->void_train[1]); + //free(lib_ret->void_train[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; + free(lib_ret->void_train[i]); + } + free(lib_ret->void_train); + free(lib_ret->obj); + free(lib_ret); return 0; } diff --git a/test/makefile b/test/makefile index 4f2c90d..05d4215 100644 --- a/test/makefile +++ b/test/makefile @@ -118,6 +118,9 @@ $(TARGET).so: $(TARGET).o read.o aggregate.o structs.o $(TARGET).a: $(TARGET).o read.o aggregate.o structs.o ar rcs $(TARGET).a $(TARGET).o +valgrind: $(TARGET) + valgrind --leak-check=yes $(TARGET) + clean: rm -f *.o *.dis *.odbg *.ocov *~ $(TARGET) $(TARGET).so $(TARGET)-static $(TARGET)-dbg $(TARGET).a $(TARGET)-cov @@ -96,7 +96,7 @@ void void_manager(void* ptr, void*** void_train, uint64_t* current_void_size, ui } } (*void_train)[*current_void_count] = ptr; - ++*current_void_count; + (*current_void_count)++; }""" c_read_leb_128_s_sig = "int64_t read_leb_128_s(int _fd, int max_size);\n" |