diff options
author | bloodstalker <thabogre@gmail.com> | 2018-06-01 08:07:09 +0000 |
---|---|---|
committer | bloodstalker <thabogre@gmail.com> | 2018-06-01 08:07:09 +0000 |
commit | c3531e8e096cf5f1ecc723acf602e157995267da (patch) | |
tree | 97eabe759383eb7b876fa15cd7cd42c270e6ef07 /bruiser/wasm | |
parent | added test files for the wasm linker. added two scripts to extra-tools (diff) | |
download | mutator-c3531e8e096cf5f1ecc723acf602e157995267da.tar.gz mutator-c3531e8e096cf5f1ecc723acf602e157995267da.zip |
fixed a bug with default.lua. added the blueprint for the wasm interface to bruiser.
Diffstat (limited to '')
-rw-r--r-- | bruiser/wasm.c | 32 | ||||
-rw-r--r-- | bruiser/wasm.h | 221 | ||||
-rwxr-xr-x | bruiser/wasm.sh | 7 | ||||
-rw-r--r-- | bruiser/wasm/test/linker/makefile | 44 |
4 files changed, 304 insertions, 0 deletions
diff --git a/bruiser/wasm.c b/bruiser/wasm.c new file mode 100644 index 0000000..ac5143c --- /dev/null +++ b/bruiser/wasm.c @@ -0,0 +1,32 @@ + +/***************************************************Project Mutator****************************************************/ +/*first line intentionally left blank.*/ +/*bruiser's wasm interface implementation*/ +/*Copyright (C) 2018 Farzad Sadeghi + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 3 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.*/ +/**********************************************************************************************************************/ +#include "./lua-5.3.4/src/lua.h" +#include "./lua-5.3.4/src/lauxlib.h" +#include "./lua-5.3.4/src/lualib.h" +#include "wasm.h" +/**********************************************************************************************************************/ + +#pragma weak main +int main(int argc, char** argv) { +} +/**********************************************************************************************************************/ +/*last line intentionally left blank.*/ + diff --git a/bruiser/wasm.h b/bruiser/wasm.h new file mode 100644 index 0000000..af02a20 --- /dev/null +++ b/bruiser/wasm.h @@ -0,0 +1,221 @@ + +/***************************************************Project Mutator****************************************************/ +/*first line intentionally left blank.*/ +/*bruiser's wasm interface implementation*/ +/*Copyright (C) 2018 Farzad Sadeghi + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 3 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.*/ +/**********************************************************************************************************************/ +#ifndef WASM_H +#define WASM_H +#include <inttypes.h> +#include "./lua-5.3.4/src/lua.h" +#include "./lua-5.3.4/src/lauxlib.h" +#include "./lua-5.3.4/src/lualib.h" + +#ifdef __cplusplus +extern "C" { +#endif + +//typedef varuint1 uint8_t; +//typedef varuint7 uint8_t; +//typedef varuint32 uint32_t; +//typedef varint1 int8_t; +//typedef varint7 int8_t; +//typedef varint32 int32_t; + +typedef uint8_t varint1; +typedef uint8_t varint7; +typedef uint32_t varint32; +typedef int8_t varuint1; +typedef int8_t varuint7; +typedef int32_t varuint32; + + enum value_type_t {f64_vt = -4, f32_vt, i64_vt, i32_vt}; + enum external_kind_t {Function, Table, Memory, Global}; + enum type_ctor_t {i32_ctor = -1, i64_ctor = -2, f32_ctor = -3, f64_ctor = -4, anyfunc_ctor = -16, func_ctor = -32, block_type_ctor = -64}; + + typedef struct { + varuint32 size; + char* code; + }init_expr_t; + + typedef struct { + varuint1 flags; + varuint32 initial; + varuint32 maximum; + } resizable_limit_t; + + typedef struct { + enum value_type_t value_type; + varuint1 mutability; + }global_type_t; + + typedef struct { + varint7 element_type; + resizable_limit_t* resizable_limit; + }table_type_t; + + typedef struct { + resizable_limit_t* resizable_limit; + }memory_type_t; + + // func_type + typedef struct { + varint7 form; + varuint32 param_count; + varint7* param_types; + varuint1 return_count; + varint7 * return_types; + }W_Type_Section_Entry; + + typedef struct { + varuint32 count; + W_Type_Section_Entry** entries; + }W_Type_Section; + + typedef struct { + varuint32 module_length; + char* module_str; + varuint32 field_len; + char* field_str; + enum external_kind_t kind; + // based on external_kind it can be 4 different types. thats why im casting to void*. + void* type; + }W_Import_Section_Entry; + + typedef struct { + int count; + W_Import_Section_Entry** entries; + }W_Import_Section; + + typedef struct { + varuint32 count; + // indexes into the type section + varuint32* types; + }W_Function_Section; + + typedef struct W_Table_Section { + varuint32 count; + table_type_t** entries; + }W_Table_Section; + + typedef struct { + varuint32 count; + memory_type_t** entries; + }W_Memory_Section; + + typedef struct { + global_type_t* type; + init_expr_t init; + }W_Global_Entry; + + typedef struct { + varuint32 count; + W_Global_Entry** globals; + }W_Global_Section; + + typedef struct { + varuint32 field_len; + char* field_str; + enum external_kind_t kind; + int varuint32; + }W_Export_Entry; + + typedef struct { + int count; + W_Export_Entry** entries; + }W_Export_Section; + + typedef struct { + varuint32 index; + }W_Start_Section; + + typedef struct { + varuint32 index; + init_expr_t offset; + varuint32 num_length; + varuint32* elems; + }W_Elem_Segment; + + typedef struct { + varuint32 count; + W_Elem_Segment** entries; + }W_Element_Section; + + typedef struct { + varuint32 count; + enum value_type_t type; + }W_Local_Entry; + + typedef struct W_Function_Body { + varuint32 body_size; + varuint32 local_count; + W_Local_Entry** locals; + char* code; + //char end = 0x0b; + }W_Function_Body; + + typedef struct { + varuint32 count; + W_Function_Body** bodies; + }W_Code_Section; + + typedef struct { + varuint32 index; + init_expr_t offset; + varuint32 size; + char* data; + }W_Data_Segment; + + typedef struct { + varuint32 count; + struct W_Data_Segment** entries; + }W_Data_Section; + +#if 0 + typedef struct W_Custom_Section {}; + typedef struct W_Name_Section {}; + typedef struct W_Relocation_Section {}; +#endif + + typedef struct Wasm_Module { + W_Import_Section import_section; + W_Function_Section function_section; + W_Table_Section table_section; + W_Memory_Section memory_section; + W_Global_Section global_section; + W_Export_Section export_section; + W_Start_Section start_section; + W_Element_Section element_section; + W_Code_Section code_section; + W_Data_Section data_section; + void** W_Custom_Sections; + char* name; + }Wasm_Module; + + // get the raw binary of the wasm module + // char* getWRaw(); + + // get wasm section raw binary by name + // char* get_W_Section_Raw(const char* section_name); + +#ifdef __cplusplus +} +#endif // end of extern c +#endif // end of header guard +/**********************************************************************************************************************/ +/*last line intentionally left blank.*/ + diff --git a/bruiser/wasm.sh b/bruiser/wasm.sh new file mode 100755 index 0000000..d8d4990 --- /dev/null +++ b/bruiser/wasm.sh @@ -0,0 +1,7 @@ +#!/bin/bash +cd $(dirname $0) +gcc wasm.c -o wasme +./wasme +rm ./wasme + + diff --git a/bruiser/wasm/test/linker/makefile b/bruiser/wasm/test/linker/makefile new file mode 100644 index 0000000..5cffbcc --- /dev/null +++ b/bruiser/wasm/test/linker/makefile @@ -0,0 +1,44 @@ +TARGET=file0 +CC=clang +CC?=clang +CC_FLAGS= +CC_EXTRA?= +CC_FLAGS+=$(CC_EXTRA) + +SRCS=$(wildcard *.c) +WASM=$(patsubst %.c, %.wasm, $(wildcard *.c)) + +.DEFAULT:all + +.PHONY:all clean help + +all:$(TARGET) wasmforce + +depend:.depend + +.depend:$(SRCS) + rm -rf .depend + $(CC) -MM $(CC_FLAGS) $^ > ./.depend + +-include ./.depend + +%.wasm:%.c + ../../../../extra-tools/llvm-wasm $< + +wasmforce:$(WASM) + @echo forcing generation of wasm and wast + +.c.o: + $(CC) $(CC_FLAGS) -c $< -o $@ + +$(TARGET): $(TARGET).o + $(CC) $^ $(LD_FLAGS) -o $@ + +clean: + rm -f *.s *.wasm *.wast *.bc *.o *~ $(TARGET) + rm .depend + +help: + @echo "all is the default target" + @echo "there is delete." + @echo "there is clean." |