Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions test/run-tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=''))
Expand Down
6 changes: 4 additions & 2 deletions test/spec-wasm2c-prefix.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -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);
Expand Down
13 changes: 13 additions & 0 deletions wasm2c/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
14 changes: 9 additions & 5 deletions wasm2c/wasm-rt-impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -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();
}
}
Expand All @@ -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());
Expand Down
8 changes: 6 additions & 2 deletions wasm2c/wasm-rt.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand Down
Loading