From 1dfdeee85deabcb964438e2a1d96eb4d6d297cfd Mon Sep 17 00:00:00 2001 From: bloodstalker Date: Wed, 12 Sep 2018 21:02:09 +0430 Subject: update --- README.md | 28 +++++++++++++++++++++++++++- main.py | 4 ++-- test/autowasm.c | 8 +++++--- 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index a3af814..97e8ccd 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,31 @@ The `DEFINITION` node includes the definitions for the structures that are aggre ## Demo For a practical example, look at the example XML file under `resources`. The XML file describes the format of a WASM object file:
-To run the demo, run `run.sh`, go to the `test` direcotory and run `make`. Then run the executable.
+To run the demo, run `run.sh`, go to the `test` direcotory and run `make test` to run the executable.
+To run `valgrind --leak-check=yes` run `make valgrind`.
+ +## Memory Leaks +Code generated by faultreiber should not leak any memory if everything went according to plan during code-gen. If that's not the case let me knkow.
+ +## How to Use +A function named `read_aggr_{name}` will be generated that takes an `int _fd` file descriptor for the file that it will read.`{name}` is what you pass to faultreiber with the `--name` option.
+The return type will be a C structure with type `{name}_lib_ret_t`. The struct is defined as:
+```C +typedef struct { + name_obj_t obj; + void** void_train; + uint64_t* current_void_size; + uint64_t* current_void_count; +}name_lib_ret_t +``` +`{name}_obj_t` is a C structure defined in `aggregate.h` that holds all the read modules.
+A function named `release_all_{name}` will be generated in `aggregate.c` that releases almost all the memory.
+The proper order of realeasing the memory in the client code will be like below assuming the return value of `read_aggr_{name}` is stored in `lib_ret` and `--name` was passed a value of `wasm`:
+```C +release_all_wasm(lib_ret->void_train, lib_ret->current_void_count); +free(lib_ret->obj); +free(lib_ret); +``` ### Rules: @@ -80,6 +104,7 @@ The `FT::conditional` tag for a type means that the actual content of the node w --singlefile the generated code will be put in a single file --singlefilename SINGLEFILENAME name of the single file + --name will be used in generating some code identifiers ``` @@ -88,6 +113,7 @@ Big-Endian reads are not supported.
None-byte-sized raw reads are not supported.
## makefile +That would be on you but there is an example makefile in the `test` directory so you can take a look if you want.
To get a list of the targets the makfile supports you can run its `help` target.
## TODO diff --git a/main.py b/main.py index a6a886c..6f2fa31 100755 --- a/main.py +++ b/main.py @@ -583,8 +583,8 @@ class CodeGen(object): def gen_release(self): agg_source = open(self.aggregate_source, "a") agg_source_h = open(self.aggregate_source_h, "a") - agg_source_h.write("void release_all(void** void_train, uint64_t current_void_count);\n") - agg_source.write("void release_all(void** void_train, uint64_t current_void_count) {\n") + agg_source_h.write("void release_all_"+self.argparser.args.name+"(void** void_train, uint64_t current_void_count);\n") + agg_source.write("void release_all_"+self.argparser.args.name+"(void** void_train, uint64_t current_void_count) {\n") agg_source.write("for (int i=current_void_count-1;i>=0;--i) {\n") agg_source.write("free(void_train[i]);\n}\n") agg_source.write("free(void_train);\n") diff --git a/test/autowasm.c b/test/autowasm.c index cbc6e5a..dc0db84 100644 --- a/test/autowasm.c +++ b/test/autowasm.c @@ -34,7 +34,7 @@ int main (int argc, char** argv) { wasm_lib_ret_t* lib_ret = read_aggr_wasm(wasm); printf("finished reading\n"); -#if 0 +#if 1 printf("magic_number:%x\n", lib_ret->obj->magic_number_container->magic_number); printf("version:%x\n", lib_ret->obj->version_container->version); @@ -166,16 +166,18 @@ int main (int argc, char** argv) { 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); + release_all_wasm(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]); +#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; free(lib_ret->void_train[i]); } - free(lib_ret->void_train); +#endif + //free(lib_ret->void_train); free(lib_ret->obj); free(lib_ret); return 0; -- cgit v1.2.3