diff options
author | bloodstalker <thabogre@gmail.com> | 2018-09-12 16:32:09 +0000 |
---|---|---|
committer | bloodstalker <thabogre@gmail.com> | 2018-09-12 16:32:09 +0000 |
commit | 1dfdeee85deabcb964438e2a1d96eb4d6d297cfd (patch) | |
tree | fd556eeb7adcd556b9f67e8809ee2a02f5d39650 | |
parent | finally fixed (diff) | |
download | faultreiber-1dfdeee85deabcb964438e2a1d96eb4d6d297cfd.tar.gz faultreiber-1dfdeee85deabcb964438e2a1d96eb4d6d297cfd.zip |
update
-rw-r--r-- | README.md | 28 | ||||
-rwxr-xr-x | main.py | 4 | ||||
-rw-r--r-- | test/autowasm.c | 8 |
3 files changed, 34 insertions, 6 deletions
@@ -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:<br/> -To run the demo, run `run.sh`, go to the `test` direcotory and run `make`. Then run the executable.<br/> +To run the demo, run `run.sh`, go to the `test` direcotory and run `make test` to run the executable.<br/> +To run `valgrind --leak-check=yes` run `make valgrind`.<br/> + +## 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.<br/> + +## 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.<br/> +The return type will be a C structure with type `{name}_lib_ret_t`. The struct is defined as:<br/> +```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.<br/> +A function named `release_all_{name}` will be generated in `aggregate.c` that releases almost all the memory.<br/> +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`:<br/> +```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.<br/> None-byte-sized raw reads are not supported.<br/> ## 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.<br/> To get a list of the targets the makfile supports you can run its `help` target.<br/> ## TODO @@ -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; |