-
Notifications
You must be signed in to change notification settings - Fork 988
test(wasix): cover POSIX signal semantics (SA_SIGINFO, SA_RESETHAND, signal masks) #6838
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
446b8a0
test(wasix): cover sa_handler and SA_SIGINFO signal dispatch
Arshia001 0daae54
test(wasix): cover SA_RESETHAND disposition reset
Arshia001 28db01b
test(wasix): cover per-thread signal mask semantics
Arshia001 6c2d2d7
style(wasix): clang-format the signal fixtures
Arshia001 e7fc931
ci: bump the pinned wasix-libc sysroot to v2026-07-30.1
Arshia001 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| # Shared CI constants. Loaded into GITHUB_ENV by workflows that need them. | ||
| # Pinned wasix-libc sysroot (wasix-org/wasix-libc release tag). | ||
| WASIX_LIBC_SYSROOT_TAG=v2026-07-03.1 | ||
| WASIX_LIBC_SYSROOT_TAG=v2026-07-30.1 |
55 changes: 55 additions & 0 deletions
55
lib/wasix/tests/wasm_tests/signal/pthread-sigmask-inherit/main.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| //#MinimalLibc: v2026-07-30.1 | ||
| //#ExpectedStdout: child inherited the blocked mask | ||
|
|
||
| #include <assert.h> | ||
| #include <pthread.h> | ||
| #include <signal.h> | ||
| #include <stdio.h> | ||
| #include <string.h> | ||
|
|
||
| // A new thread inherits its creator's signal mask, and the mask is per-thread: | ||
| // unblocking in the child must not affect the parent. | ||
|
|
||
| static volatile int child_saw_blocked = 0; | ||
| static volatile int child_query_ok = 0; | ||
|
|
||
| static void* child(void* arg) { | ||
| (void)arg; | ||
|
|
||
| sigset_t mask; | ||
| sigemptyset(&mask); | ||
| child_query_ok = (pthread_sigmask(SIG_BLOCK, NULL, &mask) == 0); | ||
| child_saw_blocked = sigismember(&mask, SIGUSR1); | ||
|
|
||
| sigset_t unblock; | ||
| sigemptyset(&unblock); | ||
| sigaddset(&unblock, SIGUSR1); | ||
| pthread_sigmask(SIG_UNBLOCK, &unblock, NULL); | ||
|
|
||
| return NULL; | ||
| } | ||
|
|
||
| int main() { | ||
| sigset_t block; | ||
| sigemptyset(&block); | ||
| sigaddset(&block, SIGUSR1); | ||
| assert(pthread_sigmask(SIG_BLOCK, &block, NULL) == 0); | ||
|
|
||
| pthread_t thread; | ||
| assert(pthread_create(&thread, NULL, child, NULL) == 0); | ||
| assert(pthread_join(thread, NULL) == 0); | ||
|
|
||
| assert(child_query_ok && "pthread_sigmask should succeed in the child"); | ||
| assert(child_saw_blocked == 1 && | ||
| "child should inherit the creator's blocked mask"); | ||
|
|
||
| // The child unblocked SIGUSR1 for itself only; ours must still be blocked. | ||
| sigset_t mine; | ||
| sigemptyset(&mine); | ||
| assert(pthread_sigmask(SIG_BLOCK, NULL, &mine) == 0); | ||
| assert(sigismember(&mine, SIGUSR1) == 1 && | ||
| "the mask should be per-thread, not shared"); | ||
|
|
||
| printf("child inherited the blocked mask\n"); | ||
| return 0; | ||
| } |
61 changes: 61 additions & 0 deletions
61
lib/wasix/tests/wasm_tests/signal/sigaction-mask-blocks-other/main.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| //#MinimalLibc: v2026-07-30.1 | ||
| //#ExpectedStdout: usr2 deferred until handler returned | ||
|
|
||
| #include <assert.h> | ||
| #include <signal.h> | ||
| #include <stdio.h> | ||
| #include <string.h> | ||
|
|
||
| // sa_mask names *additional* signals to block while a handler runs, not just | ||
| // the one being delivered. A SIGUSR1 handler whose sa_mask contains SIGUSR2 | ||
| // must not be interrupted by SIGUSR2; that delivery is deferred until the | ||
| // handler returns. | ||
|
|
||
| static volatile sig_atomic_t usr2_calls = 0; | ||
| static volatile sig_atomic_t usr2_seen_inside = -1; | ||
|
|
||
| static void usr1_handler(int sig, siginfo_t* info, void* ucontext) { | ||
| (void)sig; | ||
| (void)info; | ||
| (void)ucontext; | ||
|
|
||
| raise(SIGUSR2); | ||
| // Sampled before returning: SIGUSR2 is in our sa_mask, so it must still be | ||
| // pending rather than already handled. | ||
| usr2_seen_inside = usr2_calls; | ||
| } | ||
|
|
||
| static void usr2_handler(int sig, siginfo_t* info, void* ucontext) { | ||
| (void)sig; | ||
| (void)info; | ||
| (void)ucontext; | ||
|
|
||
| usr2_calls++; | ||
| } | ||
|
|
||
| int main() { | ||
| struct sigaction sa; | ||
|
|
||
| memset(&sa, 0, sizeof(sa)); | ||
| sa.sa_sigaction = usr2_handler; | ||
| sa.sa_flags = SA_SIGINFO; | ||
| sigemptyset(&sa.sa_mask); | ||
| assert(sigaction(SIGUSR2, &sa, NULL) == 0); | ||
|
|
||
| memset(&sa, 0, sizeof(sa)); | ||
| sa.sa_sigaction = usr1_handler; | ||
| sa.sa_flags = SA_SIGINFO; | ||
| sigemptyset(&sa.sa_mask); | ||
| sigaddset(&sa.sa_mask, SIGUSR2); | ||
| assert(sigaction(SIGUSR1, &sa, NULL) == 0); | ||
|
|
||
| assert(raise(SIGUSR1) == 0); | ||
|
|
||
| assert(usr2_seen_inside == 0 && | ||
| "sa_mask should keep SIGUSR2 blocked inside the SIGUSR1 handler"); | ||
| assert(usr2_calls == 1 && | ||
| "SIGUSR2 should be delivered once the SIGUSR1 handler returns"); | ||
|
|
||
| printf("usr2 deferred until handler returned\n"); | ||
| return 0; | ||
| } |
60 changes: 60 additions & 0 deletions
60
lib/wasix/tests/wasm_tests/signal/sigaction-mask-defers/main.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| //#MinimalLibc: v2026-07-30.1 | ||
| //#ExpectedStdout: calls=5 max_depth=1 | ||
|
|
||
| #include <assert.h> | ||
| #include <signal.h> | ||
| #include <stdio.h> | ||
| #include <string.h> | ||
|
|
||
| // POSIX blocks the delivered signal for the duration of its handler (sa_mask | ||
| // plus the signal itself, the latter unless SA_NODEFER). So a signal re-raised | ||
| // from inside the handler is deferred and delivered once the handler returns, | ||
| // running the handler again sequentially rather than nesting it. | ||
| // | ||
| // The re-raise is gated on `calls < LIMIT` in guest code, so the recursion is | ||
| // bounded no matter how libc behaves: even with masking entirely broken this | ||
| // nests 5 deep rather than exhausting the stack. | ||
| // | ||
| // Paired with sigaction-nodefer-reenters, which is the same program with | ||
| // SA_NODEFER and therefore expects max_depth == LIMIT. | ||
|
|
||
| #define LIMIT 5 | ||
|
|
||
| static volatile sig_atomic_t calls = 0; | ||
| static volatile sig_atomic_t depth = 0; | ||
| static volatile sig_atomic_t max_depth = 0; | ||
|
|
||
| static void handler(int sig, siginfo_t* info, void* ucontext) { | ||
| (void)info; | ||
| (void)ucontext; | ||
|
|
||
| calls++; | ||
| depth++; | ||
| if (depth > max_depth) { | ||
| max_depth = depth; | ||
| } | ||
| if (calls < LIMIT) { | ||
| raise(sig); | ||
| } | ||
| depth--; | ||
| } | ||
|
|
||
| int main() { | ||
| struct sigaction sa; | ||
| memset(&sa, 0, sizeof(sa)); | ||
| sa.sa_sigaction = handler; | ||
| sa.sa_flags = SA_SIGINFO; | ||
| sigfillset(&sa.sa_mask); | ||
| assert(sigaction(SIGUSR1, &sa, NULL) == 0); | ||
|
|
||
| // Every deferred delivery is drained before the raise that triggered the | ||
| // first one returns, so no further syscall is needed to observe them. | ||
| assert(raise(SIGUSR1) == 0); | ||
|
|
||
| assert(calls == LIMIT && "handler should run once per raise"); | ||
| assert(max_depth == 1 && "a blocked signal must not re-enter its handler"); | ||
| assert(depth == 0 && "every invocation should have returned"); | ||
|
|
||
| printf("calls=%d max_depth=%d\n", (int)calls, (int)max_depth); | ||
| return 0; | ||
| } |
57 changes: 57 additions & 0 deletions
57
lib/wasix/tests/wasm_tests/signal/sigaction-nodefer-reenters/main.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| //#MinimalLibc: v2026-07-30.1 | ||
| //#ExpectedStdout: calls=5 max_depth=5 | ||
|
|
||
| #include <assert.h> | ||
| #include <signal.h> | ||
| #include <stdio.h> | ||
| #include <string.h> | ||
|
|
||
| // SA_NODEFER opts out of adding the delivered signal to the mask for the | ||
| // duration of its handler, so a signal re-raised from inside the handler | ||
| // re-enters it immediately instead of being deferred. | ||
| // | ||
| // sa_mask must be empty here: it is applied on top of SA_NODEFER, so a | ||
| // sigfillset() mask would block SIGUSR1 anyway and defeat the opt-out. | ||
| // | ||
| // The re-raise is gated on `calls < LIMIT` in guest code, bounding the nesting | ||
| // to 5 frames. Paired with sigaction-mask-defers, the same program without | ||
| // SA_NODEFER, which expects max_depth == 1. | ||
|
|
||
| #define LIMIT 5 | ||
|
|
||
| static volatile sig_atomic_t calls = 0; | ||
| static volatile sig_atomic_t depth = 0; | ||
| static volatile sig_atomic_t max_depth = 0; | ||
|
|
||
| static void handler(int sig, siginfo_t* info, void* ucontext) { | ||
| (void)info; | ||
| (void)ucontext; | ||
|
|
||
| calls++; | ||
| depth++; | ||
| if (depth > max_depth) { | ||
| max_depth = depth; | ||
| } | ||
| if (calls < LIMIT) { | ||
| raise(sig); | ||
| } | ||
| depth--; | ||
| } | ||
|
|
||
| int main() { | ||
| struct sigaction sa; | ||
| memset(&sa, 0, sizeof(sa)); | ||
| sa.sa_sigaction = handler; | ||
| sa.sa_flags = SA_SIGINFO | SA_NODEFER; | ||
| sigemptyset(&sa.sa_mask); | ||
| assert(sigaction(SIGUSR1, &sa, NULL) == 0); | ||
|
|
||
| assert(raise(SIGUSR1) == 0); | ||
|
|
||
| assert(calls == LIMIT && "handler should run once per raise"); | ||
| assert(max_depth == LIMIT && "SA_NODEFER should allow the handler to nest"); | ||
| assert(depth == 0 && "every invocation should have returned"); | ||
|
|
||
| printf("calls=%d max_depth=%d\n", (int)calls, (int)max_depth); | ||
| return 0; | ||
| } |
47 changes: 47 additions & 0 deletions
47
lib/wasix/tests/wasm_tests/signal/sigaction-resethand/main.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| //#MinimalLibc: v2026-07-30.1 | ||
| //#ExpectedStdout: resethand ok | ||
|
|
||
| #include <assert.h> | ||
| #include <signal.h> | ||
| #include <stdio.h> | ||
| #include <string.h> | ||
|
|
||
| // POSIX resets a handler installed with SA_RESETHAND to SIG_DFL on entry, so | ||
| // re-raising the same signal from inside the handler takes the default action | ||
| // instead of re-entering the handler. Node's `SignalExit` relies on exactly | ||
| // that: it re-raises to let the default disposition terminate the process. | ||
| // Without the reset it recurses until the stack is exhausted. | ||
| // | ||
| // The reset is asserted directly rather than by re-raising, because unbounded | ||
| // re-entry exhausts the host stack and would take the test process down with | ||
| // it instead of failing this one test. | ||
|
|
||
| static volatile sig_atomic_t calls = 0; | ||
|
|
||
| static void handler(int sig, siginfo_t* info, void* ucontext) { | ||
| (void)sig; | ||
| (void)info; | ||
| (void)ucontext; | ||
| calls++; | ||
| } | ||
|
|
||
| int main() { | ||
| struct sigaction sa; | ||
| memset(&sa, 0, sizeof(sa)); | ||
| sa.sa_sigaction = handler; | ||
| sa.sa_flags = SA_SIGINFO | SA_RESETHAND; | ||
| sigfillset(&sa.sa_mask); | ||
| assert(sigaction(SIGUSR1, &sa, NULL) == 0); | ||
|
|
||
| assert(raise(SIGUSR1) == 0); | ||
| assert(calls == 1 && "handler should have run once"); | ||
|
|
||
| struct sigaction old; | ||
| memset(&old, 0, sizeof(old)); | ||
| assert(sigaction(SIGUSR1, NULL, &old) == 0); | ||
| assert(old.sa_handler == SIG_DFL && | ||
| "SA_RESETHAND should reset the disposition to SIG_DFL"); | ||
|
|
||
| printf("resethand ok\n"); | ||
| return 0; | ||
| } |
58 changes: 58 additions & 0 deletions
58
lib/wasix/tests/wasm_tests/signal/sigaction-siginfo/main.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| //#MinimalLibc: v2026-07-30.1 | ||
| //#ExpectedStdout: plain handler ok | ||
| //#ExpectedStdout: siginfo handler ok | ||
|
|
||
| #include <assert.h> | ||
| #include <signal.h> | ||
| #include <stdio.h> | ||
| #include <string.h> | ||
|
|
||
| // A handler installed through `sa_sigaction` with `SA_SIGINFO` takes three | ||
| // arguments, while one installed through `sa_handler` takes a single one. On | ||
| // wasm these are distinct function types, so dispatching a three-argument | ||
| // handler through a one-argument `call_indirect` traps with "indirect call | ||
| // type mismatch" and kills the instance. Cover both dispatch forms. | ||
|
|
||
| static volatile sig_atomic_t plain_calls = 0; | ||
| static volatile sig_atomic_t info_calls = 0; | ||
| static volatile sig_atomic_t info_signo = 0; | ||
| static volatile sig_atomic_t info_arg_ok = 0; | ||
|
|
||
| static void plain_handler(int sig) { | ||
| (void)sig; | ||
| plain_calls++; | ||
| } | ||
|
|
||
| static void info_handler(int sig, siginfo_t* info, void* ucontext) { | ||
| (void)ucontext; | ||
| info_calls++; | ||
| info_signo = sig; | ||
| info_arg_ok = (info != NULL && info->si_signo == sig); | ||
| } | ||
|
|
||
| int main() { | ||
| struct sigaction sa; | ||
|
|
||
| memset(&sa, 0, sizeof(sa)); | ||
| sa.sa_handler = plain_handler; | ||
| sigfillset(&sa.sa_mask); | ||
| assert(sigaction(SIGUSR1, &sa, NULL) == 0); | ||
|
|
||
| assert(raise(SIGUSR1) == 0); | ||
| assert(plain_calls == 1 && "one-argument handler should have run"); | ||
| printf("plain handler ok\n"); | ||
|
|
||
| memset(&sa, 0, sizeof(sa)); | ||
| sa.sa_sigaction = info_handler; | ||
| sa.sa_flags = SA_SIGINFO; | ||
| sigfillset(&sa.sa_mask); | ||
| assert(sigaction(SIGUSR2, &sa, NULL) == 0); | ||
|
|
||
| assert(raise(SIGUSR2) == 0); | ||
| assert(info_calls == 1 && "three-argument handler should have run"); | ||
| assert(info_signo == SIGUSR2 && "handler should receive the signal number"); | ||
| assert(info_arg_ok && "handler should receive a populated siginfo_t"); | ||
| printf("siginfo handler ok\n"); | ||
|
|
||
| return 0; | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.