diff --git a/test/run-tests.py b/test/run-tests.py index 2eb7ebbf4a..96ba81ec28 100755 --- a/test/run-tests.py +++ b/test/run-tests.py @@ -177,6 +177,10 @@ def Decode(s): expected_lines = [Decode(line) for line in expected.splitlines() if line] actual_lines = [Decode(line) for line in actual.splitlines() if line] + + expected_lines = [line for line in expected_lines if not line.startswith("##")] + actual_lines = [line for line in actual_lines if not line.startswith("##")] + return list( difflib.unified_diff(expected_lines, actual_lines, fromfile='expected', tofile='actual', lineterm='')) diff --git a/test/spec-wasm2c-prefix.c b/test/spec-wasm2c-prefix.c index bc86f8fd4e..89583a447c 100644 --- a/test/spec-wasm2c-prefix.c +++ b/test/spec-wasm2c-prefix.c @@ -448,8 +448,9 @@ static void posix_install_signal_handler(void) { ss.ss_sp = malloc(SIGSTKSZ); ss.ss_flags = 0; ss.ss_size = SIGSTKSZ; + printf("##sigaltstack specsetup: %p, NULL\n", &ss); if (sigaltstack(&ss, NULL) != 0) { - perror("sigaltstack failed"); + perror("sigaltstack specsetup failed"); abort(); } @@ -478,8 +479,9 @@ static void posix_cleanup_signal_handler(void) { /* disable and free altstack */ stack_t ss; ss.ss_flags = SS_DISABLE; + printf("##sigaltstack specshutdown: %p, NULL\n", &ss); if (sigaltstack(&ss, NULL) != 0) { - perror("sigaltstack failed"); + perror("sigaltstack specshutdown failed"); abort(); } free(ss.ss_sp); diff --git a/wasm2c/README.md b/wasm2c/README.md index b7ab3bca2e..9fc620d3ce 100644 --- a/wasm2c/README.md +++ b/wasm2c/README.md @@ -720,3 +720,16 @@ void w2c_host_buf_done(w2c_host* instance, u32 ptr, u32 size) { printf("%s -> %.*s\n", instance->input, (int)size, &instance->memory.data[ptr]); } ``` +## Troubleshooting + +``` +error: No definition for WASM_RT_THREAD_LOCAL for this platform. +``` + +If you see the above error, wasm2c does not know how to define thread_local variables in your platform. You can address this in one of three ways + +1. If your compiler supports C11, pass in `-std=c11` as a compilation flag. Otherwise, you can either + +2. If you know how to define thread local variables in your compiler, define `WASM_RT_THREAD_LOCAL` macro as a compilation flag with the correct thread_local keywords. e.g., `-DWASM_RT_THREAD_LOCAL=__thread` + +3. If you can guarantee that at most one thread of your application will be running wasm2c sandboxes at any given time, you can pass the flag `-DWASM_RT_SINGLE_THREAD_ONLY` to simply define thread_local variables as global values. diff --git a/wasm2c/wasm-rt-impl.c b/wasm2c/wasm-rt-impl.c index e7d99cce8f..8379142d01 100644 --- a/wasm2c/wasm-rt-impl.c +++ b/wasm2c/wasm-rt-impl.c @@ -168,8 +168,9 @@ static void os_cleanup_signal_handler(void) { static bool os_has_altstack_installed() { /* check for altstack already in place */ stack_t ss; + // printf("##sigaltstack check: NULL, %p\n", &ss); if (sigaltstack(NULL, &ss) != 0) { - perror("sigaltstack failed"); + perror("sigaltstack check failed"); abort(); } @@ -198,8 +199,9 @@ static void os_allocate_and_install_altstack(void) { ss.ss_sp = g_alt_stack; ss.ss_flags = 0; ss.ss_size = SIGSTKSZ; + // printf("##sigaltstack install: %p, NULL\n", &ss); if (sigaltstack(&ss, NULL) != 0) { - perror("sigaltstack failed"); + perror("sigaltstack install failed"); abort(); } } @@ -211,22 +213,24 @@ static void os_disable_and_deallocate_altstack(void) { /* verify altstack was still in place */ stack_t ss; + // printf("##sigaltstack dealloc: NULL, %p\n", &ss); if (sigaltstack(NULL, &ss) != 0) { - perror("sigaltstack failed"); + perror("sigaltstack dealloc check failed"); abort(); } if ((!g_alt_stack) || (ss.ss_flags & SS_DISABLE) || (ss.ss_sp != g_alt_stack) || (ss.ss_size != SIGSTKSZ)) { - DEBUG_PRINTF( + printf( "wasm-rt warning: alternate stack was modified unexpectedly\n"); return; } /* disable and free */ ss.ss_flags = SS_DISABLE; + // printf("##sigaltstack free: %p, NULL\n", &ss); if (sigaltstack(&ss, NULL) != 0) { - perror("sigaltstack failed"); + perror("sigaltstack free failed"); abort(); } assert(!os_has_altstack_installed()); diff --git a/wasm2c/wasm-rt.h b/wasm2c/wasm-rt.h index d58a37b812..efb8640ad9 100644 --- a/wasm2c/wasm-rt.h +++ b/wasm2c/wasm-rt.h @@ -75,15 +75,19 @@ extern "C" { #endif +#ifndef WASM_RT_THREAD_LOCAL #ifdef WASM_RT_C11_AVAILABLE #define WASM_RT_THREAD_LOCAL _Thread_local #elif defined(_MSC_VER) #define WASM_RT_THREAD_LOCAL __declspec(thread) -#elif (defined(__GNUC__) || defined(__clang__)) && !defined(__APPLE__) +#elif defined(__GNUC__) || defined(__clang__) // Disabled on Apple systems due to sporadic test failures. #define WASM_RT_THREAD_LOCAL __thread -#else +#elif WASM_RT_SINGLE_THREAD_ONLY #define WASM_RT_THREAD_LOCAL +#else +#error "No definition for WASM_RT_THREAD_LOCAL for this platform." +#endif #endif /**