diff --git a/fail.just b/fail.just index 87e067d..0b96cae 100644 --- a/fail.just +++ b/fail.just @@ -9,9 +9,9 @@ trace module: -e {{ BUILD_DIR }}-{{ module }}/system.elf \ -i {{ BUILD_DIR }}-{{ module }}/system.iso \ -- \ - -Wf,--start-symbol=start_trace \ - -Wf,--save-symbol=start_trace \ - -Wf,--end-symbol=stop_trace \ + -Wf,--start-symbol=fail_start_trace \ + -Wf,--save-symbol=fail_start_trace \ + -Wf,--end-symbol=fail_stop_trace \ -Wf,--state-file={{ BUILD_DIR }}-{{ module }}/state \ -Wf,--trace-file={{ BUILD_DIR }}-{{ module }}/trace.pb \ -Wf,--elf-file={{ BUILD_DIR }}-{{ module }}/system.elf @@ -62,7 +62,7 @@ import module: [group("4: fail")] server module: {{ FAIL_SERVER }} \ - --port {{FAIL_SERVER_PORT}} \ + --port {{ FAIL_SERVER_PORT }} \ --database-option-file ./db.conf \ -v {{ module }} \ -b % \ @@ -87,12 +87,13 @@ client module: -i {{ BUILD_DIR }}-{{ module }}/system.iso \ -j {{ num_cpus() }} \ -- \ - -Wf,--server-port={{FAIL_SERVER_PORT}} \ + -Wf,--server-port={{ FAIL_SERVER_PORT }} \ -Wf,--state-dir={{ BUILD_DIR }}-{{ module }}/state \ -Wf,--trap \ -Wf,--timeout=500000 \ - -Wf,--ok-marker=ok_marker \ - -Wf,--fail-marker=fail_marker \ + -Wf,--ok-marker=fail_marker_positive \ + -Wf,--fail-marker=fail_marker_negative \ + -Wf,--detected-marker=fail_marker_detected \ > /dev/null @echo "Next step: \"just result {{ module }}\" or \"just resultbrowser\"" @@ -127,4 +128,4 @@ result-csv module: [doc("Start the FAIL* resultbrowser")] [group("4: fail")] resultbrowser: - {{ RESULT_BROWSER }} -c ./db.conf --host=0.0.0.0 --port={{RESULTBROWSER_PORT}} + {{ RESULT_BROWSER }} -c ./db.conf --host=0.0.0.0 --port={{ RESULTBROWSER_PORT }} diff --git a/targets/c-host/fail.c b/targets/c-host/fail.c index f4a1a3b..932df8b 100644 --- a/targets/c-host/fail.c +++ b/targets/c-host/fail.c @@ -1,17 +1,23 @@ -#include "lib.h" +#include "../lib.h" + +void fail_start_trace(void) {} +void fail_stop_trace(void) {} +void fail_marker_positive(void) {} +void fail_marker_negative(void) {} +void fail_marker_detected(void) {} int wasm_module(void); MAIN() { int result; - MARKER(start_trace); + fail_start_trace(); result = wasm_module(); - MARKER(stop_trace); + fail_stop_trace(); if (result == 100) { - MARKER(ok_marker); + fail_marker_positive(); } else { - MARKER(fail_marker); + fail_marker_negative(); } } diff --git a/targets/c-host/lib.h b/targets/lib.h similarity index 63% rename from targets/c-host/lib.h rename to targets/lib.h index daabf67..0f74c1e 100644 --- a/targets/c-host/lib.h +++ b/targets/lib.h @@ -1,4 +1,5 @@ -#pragma once +#ifndef _include_fail_h +#define _include_fail_h #define INLINE __attribute__((always_inline)) inline #define NOINLINE __attribute__((noinline)) @@ -6,25 +7,15 @@ #define __QUOTE(x) #x #define QUOTE(x) __QUOTE(x) -#ifndef ARCH_ASM_CLOBBER_ALL -#define ARCH_ASM_CLOBBER_ALL "eax", "ebx", "ecx", "edx", "esi", "edi", "ebp" -#endif +#define MAIN() void os_main(void) +#define POSIX_PRINTF(...) -#ifndef MARKER +#define ARCH_ASM_CLOBBER_ALL "eax", "ebx", "ecx", "edx", "esi", "edi", "ebp" #define MARKER(str) \ __asm__ volatile(QUOTE(str) ":" \ : /* no inputs */ \ : /* no outputs */ \ : "memory", ARCH_ASM_CLOBBER_ALL) -#endif - -#ifndef MAIN -#define MAIN() void os_main(void) -#endif - -#ifndef POSIX_PRINTF -#define POSIX_PRINTF(...) -#endif typedef __UINT8_TYPE__ uint8_t; typedef __UINT16_TYPE__ uint16_t; @@ -33,3 +24,17 @@ typedef __UINT32_TYPE__ uint32_t; typedef __INT8_TYPE__ int8_t; typedef __INT16_TYPE__ int16_t; typedef __INT32_TYPE__ int32_t; + +// Mark start of injection +void __attribute__((noinline)) fail_start_trace(void); +// Mark end of injection +void __attribute__((noinline)) fail_stop_trace(void); + +// everything ok: valid code and right values +void __attribute__((noinline)) fail_marker_positive(void); +// everything ok: valid code but wrong values +void __attribute__((noinline)) fail_marker_negative(void); +// invalid code +void __attribute__((noinline)) fail_marker_detected(void); + +#endif diff --git a/targets/wasm-host/fail.c b/targets/wasm-host/fail.c index bc6d82c..8c487d0 100644 --- a/targets/wasm-host/fail.c +++ b/targets/wasm-host/fail.c @@ -1,10 +1,16 @@ -#include "lib.h" +#include "../lib.h" #include "bh_platform.h" #include "wasm_export.h" #include "__WASM_ARRAY_FILE__" +void fail_start_trace(void) {} +void fail_stop_trace(void) {} +void fail_marker_positive(void) {} +void fail_marker_negative(void) {} +void fail_marker_detected(void) {} + #define STACK_SIZE (4 * 1024) #define HEAP_SIZE STACK_SIZE #define RUNTIME_POOL_SIZE 4 * STACK_SIZE @@ -55,19 +61,19 @@ MAIN() { uint32_t args[1] = {0}; /* call an arbitrary WASM function */ - MARKER(start_trace); + fail_start_trace(); if (!wasm_runtime_call_wasm(exec_env, func, 0, args)) { /* function wasn't called correctly */ } - MARKER(stop_trace); - - uint32_t result = args[0]; + fail_stop_trace(); /* the return value is stored in args[0] */ + uint32_t result = args[0]; + if (result == 100) { - MARKER(ok_marker); + fail_marker_positive(); } else { - MARKER(fail_marker); + fail_marker_negative(); } wasm_runtime_destroy_exec_env(exec_env); diff --git a/targets/wasm-host/lib.h b/targets/wasm-host/lib.h deleted file mode 100644 index daabf67..0000000 --- a/targets/wasm-host/lib.h +++ /dev/null @@ -1,35 +0,0 @@ -#pragma once - -#define INLINE __attribute__((always_inline)) inline -#define NOINLINE __attribute__((noinline)) - -#define __QUOTE(x) #x -#define QUOTE(x) __QUOTE(x) - -#ifndef ARCH_ASM_CLOBBER_ALL -#define ARCH_ASM_CLOBBER_ALL "eax", "ebx", "ecx", "edx", "esi", "edi", "ebp" -#endif - -#ifndef MARKER -#define MARKER(str) \ - __asm__ volatile(QUOTE(str) ":" \ - : /* no inputs */ \ - : /* no outputs */ \ - : "memory", ARCH_ASM_CLOBBER_ALL) -#endif - -#ifndef MAIN -#define MAIN() void os_main(void) -#endif - -#ifndef POSIX_PRINTF -#define POSIX_PRINTF(...) -#endif - -typedef __UINT8_TYPE__ uint8_t; -typedef __UINT16_TYPE__ uint16_t; -typedef __UINT32_TYPE__ uint32_t; - -typedef __INT8_TYPE__ int8_t; -typedef __INT16_TYPE__ int16_t; -typedef __INT32_TYPE__ int32_t; diff --git a/wasm.just b/wasm.just index c882ed1..552de9f 100644 --- a/wasm.just +++ b/wasm.just @@ -22,7 +22,6 @@ CROSS_CFLAGS_NOWASM := "\ -ffunction-sections \ -fdata-sections \ -ffreestanding \ --fomit-frame-pointer \ -ggdb3 \ " CROSS_LDFLAGS_NOWASM := "\ @@ -114,7 +113,7 @@ CROSS_INCLUDES := f"\ # LINUX-POSIX -LINUX_CFLAGS := f"-I./targets/wasm-host {{ LINUX_CFLAGS_NOWASM }}" +LINUX_CFLAGS := f"-I./targets/wasm-host {{LINUX_CFLAGS_NOWASM}}" LINUX_LDFLAGS := f"-Wl,-rpath,{{LIBIWASM_LINUX_DEBUG}} -L{{LIBIWASM_LINUX_DEBUG}} -liwasm {{LINUX_LDFLAGS_NOWASM}}" LINUX_INCLUDES := f"\ -I{{WAMR_ROOT}}/core/iwasm/include \ @@ -216,7 +215,6 @@ build-c-host-linux module: -c targets/c-host/linux.c \ -o {{ BUILD_DIR }}-{{ module }}/c_host.o - [doc("Insert the C function into the host program (no WASM)")] [group("2: build host")] build-c-host module target="fail":