switch fail markers to function symbols

This commit is contained in:
2026-04-01 21:17:01 +02:00
parent 353dfae39c
commit 39d2e1c51f
6 changed files with 53 additions and 72 deletions

View File

@ -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
@ -91,8 +91,9 @@ client module:
-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\""

View File

@ -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();
}
}

View File

@ -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

View File

@ -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);

View File

@ -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;

View File

@ -22,7 +22,6 @@ CROSS_CFLAGS_NOWASM := "\
-ffunction-sections \
-fdata-sections \
-ffreestanding \
-fomit-frame-pointer \
-ggdb3 \
"
CROSS_LDFLAGS_NOWASM := "\
@ -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":