diff --git a/include/bits/unistd.h b/include/bits/unistd.h index 5781255e18..c57dc2c439 100644 --- a/include/bits/unistd.h +++ b/include/bits/unistd.h @@ -2,6 +2,7 @@ #define _BITS_UNISTD_H #define _POSIX_VERSION 200809L +#define _POSIX_REALTIME_SIGNALS 202405L #ifdef __cplusplus extern "C" { diff --git a/src/header/signal/linux.rs b/src/header/signal/linux.rs index 02e808c5a7..77bff6c317 100644 --- a/src/header/signal/linux.rs +++ b/src/header/signal/linux.rs @@ -91,6 +91,45 @@ pub const SIGSTKSZ: usize = 8096; pub const SI_QUEUE: i32 = -1; pub const SI_USER: i32 = 0; +pub const SI_TIMER: i32 = 1; +pub const SI_ASYNCIO: i32 = 2; +pub const SI_MESGQ: i32 = 3; + +// si_code values (signal-specific) +pub const ILL_ILLOPC: i32 = 1; +pub const ILL_ILLOPN: i32 = 2; +pub const ILL_ILLADR: i32 = 3; +pub const ILL_ILLTRP: i32 = 4; +pub const ILL_PRVOPC: i32 = 5; +pub const ILL_PRVREG: i32 = 6; +pub const ILL_COPROC: i32 = 7; +pub const ILL_BADSTK: i32 = 8; + +pub const FPE_INTDIV: i32 = 1; +pub const FPE_INTOVF: i32 = 2; +pub const FPE_FLTDIV: i32 = 3; +pub const FPE_FLTOVF: i32 = 4; +pub const FPE_FLTUND: i32 = 5; +pub const FPE_FLTRES: i32 = 6; +pub const FPE_FLTINV: i32 = 7; +pub const FPE_FLTSUB: i32 = 8; + +pub const SEGV_MAPERR: i32 = 1; +pub const SEGV_ACCERR: i32 = 2; + +pub const BUS_ADRALN: i32 = 1; +pub const BUS_ADRERR: i32 = 2; +pub const BUS_OBJERR: i32 = 3; + +pub const TRAP_BRKPT: i32 = 1; +pub const TRAP_TRACE: i32 = 2; + +pub const CLD_EXITED: i32 = 1; +pub const CLD_KILLED: i32 = 2; +pub const CLD_DUMPED: i32 = 3; +pub const CLD_TRAPPED: i32 = 4; +pub const CLD_STOPPED: i32 = 5; +pub const CLD_CONTINUED: i32 = 6; // Mirrors the ucontext_t struct from the libc crate on Linux. diff --git a/src/header/signal/redox.rs b/src/header/signal/redox.rs index 612dd61e52..6f8ba80a69 100644 --- a/src/header/signal/redox.rs +++ b/src/header/signal/redox.rs @@ -71,6 +71,45 @@ pub const SIGSTKSZ: usize = 8096; pub const SI_QUEUE: i32 = -1; pub const SI_USER: i32 = 0; +pub const SI_TIMER: i32 = 1; +pub const SI_ASYNCIO: i32 = 2; +pub const SI_MESGQ: i32 = 3; + +// si_code values (signal-specific) +pub const ILL_ILLOPC: i32 = 1; +pub const ILL_ILLOPN: i32 = 2; +pub const ILL_ILLADR: i32 = 3; +pub const ILL_ILLTRP: i32 = 4; +pub const ILL_PRVOPC: i32 = 5; +pub const ILL_PRVREG: i32 = 6; +pub const ILL_COPROC: i32 = 7; +pub const ILL_BADSTK: i32 = 8; + +pub const FPE_INTDIV: i32 = 1; +pub const FPE_INTOVF: i32 = 2; +pub const FPE_FLTDIV: i32 = 3; +pub const FPE_FLTOVF: i32 = 4; +pub const FPE_FLTUND: i32 = 5; +pub const FPE_FLTRES: i32 = 6; +pub const FPE_FLTINV: i32 = 7; +pub const FPE_FLTSUB: i32 = 8; + +pub const SEGV_MAPERR: i32 = 1; +pub const SEGV_ACCERR: i32 = 2; + +pub const BUS_ADRALN: i32 = 1; +pub const BUS_ADRERR: i32 = 2; +pub const BUS_OBJERR: i32 = 3; + +pub const TRAP_BRKPT: i32 = 1; +pub const TRAP_TRACE: i32 = 2; + +pub const CLD_EXITED: i32 = 1; +pub const CLD_KILLED: i32 = 2; +pub const CLD_DUMPED: i32 = 3; +pub const CLD_TRAPPED: i32 = 4; +pub const CLD_STOPPED: i32 = 5; +pub const CLD_CONTINUED: i32 = 6; pub(crate) type ucontext_t = ucontext; pub(crate) type mcontext_t = mcontext; diff --git a/src/platform/linux/signal.rs b/src/platform/linux/signal.rs index ec92d07dfa..6869603fe7 100644 --- a/src/platform/linux/signal.rs +++ b/src/platform/linux/signal.rs @@ -124,8 +124,12 @@ impl PalSignal for Sys { fn sigsuspend(mask: &sigset_t) -> Errno { unsafe { - e_raw(syscall!(RT_SIGSUSPEND, mask as *const sigset_t, NSIG / 8)) - .expect_err("must fail") + e_raw(syscall!( + RT_SIGSUSPEND, + mask as *const sigset_t, + size_of::() + )) + .expect_err("must fail") } } @@ -140,7 +144,7 @@ impl PalSignal for Sys { set as *const _, sig.map_or_else(core::ptr::null_mut, |s| s as *mut _), tp.map_or_else(core::ptr::null, |t| t as *const _), - NSIG / 8 + size_of::() )) .map(|_| ()) } diff --git a/tests/Makefile b/tests/Makefile index 32f2725fe2..9bdcb473cc 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -122,10 +122,7 @@ EXPECT_NAMES=\ unistd/getopt \ unistd/pipe \ unistd/rmdir \ - waitpid \ - waitpid_multiple \ - kill-waitpid \ - # unistd/sleep \ + unistd/sleep \ unistd/swab \ unistd/getopt_long \ unistd/write \ @@ -175,6 +172,7 @@ DYNAMIC_ONLY_NAMES=\ NAMES=\ $(EXPECT_NAMES) \ dirent/main \ + kill-waitpid \ net/if \ pty/forkpty \ psignal \ @@ -218,12 +216,10 @@ NAMES=\ signals/sigprocmask-9 \ signals/sigprocmask-10 \ signals/sigprocmask-11 \ - signals/sigprocmask-12 \ signals/sigpause-invalid \ signals/sigpause-revert \ signals/sigpause-suspend \ signals/sigprocmask-blocksingle \ - signals/sigprocmask-block \ signals/sigrelse-1 \ signals/sigrelse-2 \ signals/sigrelse-3 \ @@ -270,6 +266,8 @@ NAMES=\ grp/getgrgid_r \ grp/getgrnam_r \ grp/gr_iter \ + waitpid \ + waitpid_multiple \ sigqueue # resource/getrusage # time/times diff --git a/tests/expected/bins_dynamic/waitpid.stderr b/tests/expected/bins_dynamic/waitpid.stderr deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/expected/bins_dynamic/waitpid.stdout b/tests/expected/bins_dynamic/waitpid.stdout deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/expected/bins_static/waitpid.stderr b/tests/expected/bins_static/waitpid.stderr deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/expected/bins_static/waitpid.stdout b/tests/expected/bins_static/waitpid.stdout deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/signals/sigaddset-add.c b/tests/signals/sigaddset-add.c index 556d7781c6..bcbad4aba7 100644 --- a/tests/signals/sigaddset-add.c +++ b/tests/signals/sigaddset-add.c @@ -6,34 +6,34 @@ #include "signals_list.h" #include "../test_helpers.h" - // The sigaddset() function adds the individual signal specified by the signo to the signal set pointed to by set. +// The sigaddset() function adds the individual signal specified by the signo to the signal set pointed to by set. - // Applications shall call either sigemptyset() or sigfillset() at least once for each object of type sigset_t prior to any other use of that object. If such an object is not initialized in this way, but is nonetheless supplied as an argument to any of pthread_sigmask(), sigaction(), sigaddset(), sigdelset(), sigismember(), sigpending(), sigprocmask(), sigsuspend(), sigtimedwait(), sigwait(), or sigwaitinfo(), the results are undefined. +// Applications shall call either sigemptyset() or sigfillset() at least once for each object of type sigset_t prior to any other use of that object. If such an object is not initialized in this way, but is nonetheless supplied as an argument to any of pthread_sigmask(), sigaction(), sigaddset(), sigdelset(), sigismember(), sigpending(), sigprocmask(), sigsuspend(), sigtimedwait(), sigwait(), or sigwaitinfo(), the results are undefined. -void addset_test(sigset_t *sigset, int signal){ +void addset_test(sigset_t *sigset, int signal) +{ int status; status = sigismember(sigset, signal); ERROR_IF(sigismember, status, != 0); - + status = sigaddset(sigset, signal); ERROR_IF(sigaddset, status, != 0); status = sigismember(sigset, signal); ERROR_IF(sigismember, status, != 1); - } -int main() { +int main() +{ sigset_t sigset; - sigemptyset(&sigset); - -for (int i = 1; i < N_SIGNALS; i++){ - int sig = signals_list[i-1].signal; - - addset_test(&sigset, sig); - } + for (int i = 1; i < N_SIGNALS; i++) + { + sigemptyset(&sigset); + int sig = signals_list[i - 1].signal; + addset_test(&sigset, sig); + } } diff --git a/tests/signals/sigdelset-delete.c b/tests/signals/sigdelset-delete.c index 224d74a301..bfab99121a 100644 --- a/tests/signals/sigdelset-delete.c +++ b/tests/signals/sigdelset-delete.c @@ -9,8 +9,8 @@ // Applications should call either sigemptyset() or sigfillset() at least once for each object of type sigset_t prior to any other use of that object. If such an object is not initialized in this way, but is nonetheless supplied as an argument to any of pthread_sigmask(), sigaction(), sigaddset(), sigdelset(), sigismember(), sigpending(), sigprocmask(), sigsuspend(), sigtimedwait(), sigwait(), or sigwaitinfo(), the results are undefined. - -void delset_test(sigset_t *sigset, int signal){ +void delset_test(sigset_t *sigset, int signal) +{ int status; status = sigismember(sigset, signal); ERROR_IF(sigismember, status, != 1); @@ -20,17 +20,17 @@ void delset_test(sigset_t *sigset, int signal){ status = sigismember(sigset, signal); ERROR_IF(sigismember, status, != 0); - } -int main() { +int main() +{ sigset_t sigset; - sigfillset(&sigset); + for (int i = 1; i < N_SIGNALS; i++) + { + sigfillset(&sigset); - for (int i = 1; i < N_SIGNALS; i++){ - int sig = signals_list[i-1].signal; - delset_test(&sigset, sig); - } - + int sig = signals_list[i - 1].signal; + delset_test(&sigset, sig); + } } diff --git a/tests/signals/sigprocmask-12.c b/tests/signals/sigprocmask-12.c deleted file mode 100644 index fe01df4aa4..0000000000 --- a/tests/signals/sigprocmask-12.c +++ /dev/null @@ -1,63 +0,0 @@ -#define _XOPEN_SOURCE 600 - -#include -#include -#include -#include -#include -#include "../test_helpers.h" - -// An errno value of [EINVAL] shall be returned and the sigprocmask() function shall fail, if the value of -// the how argument is not equal to one of the defined values. - -int main(int argc, char *argv[]) -{ - int signo; - (void) signo; - int r=rand(); - sigset_t set; - - if (argc < 2) { - printf("Usage: %s [1|2|3|4]\n", argv[0]); - exit(EXIT_FAILURE); - } - - /* - Various error conditions - */ - switch (argv[1][0]) { - case '1': - signo=-1; - break; - case '2': - signo=-10000; - break; - case '3': - signo=INT32_MIN+1; - break; - case '4': - signo=INT32_MIN; - break; - default: - printf("Usage: %s [1|2|3|4]\n", argv[0]); - exit(EXIT_FAILURE); - } - - sigaddset(&set, SIGABRT); - - int status; - status = sigprocmask(r, &set, NULL); - ERROR_IF(sigprocmask, status, != -1); - ERROR_IF(sigprocmask, errno, != EINVAL); - // if (sigprocmask(r, &set, NULL) == -1) { - // if (EINVAL == errno) { - // printf ("errno set to EINVAL\n"); - // return EXIT_SUCCESS; - // } else { - // printf ("errno not set to EINVAL\n"); - // exit(EXIT_FAILURE); - // } - // } - - exit(EXIT_FAILURE); -} \ No newline at end of file diff --git a/tests/signals/sigprocmask-block.c b/tests/signals/sigprocmask-block.c deleted file mode 100644 index b1736bfa91..0000000000 --- a/tests/signals/sigprocmask-block.c +++ /dev/null @@ -1,77 +0,0 @@ -#include -#include -#include -#include "signals_list.h" -#include "../test_helpers.h" - -int handler_called = 0; - -void sig_handler(int signo) -{ - (void) signo; - handler_called = 1; -} - -int sigprocmask_block(int signum) -{ - int defaultsig = SIGALRM; - if (signum == SIGALRM) { - defaultsig = SIGHUP; - } - struct sigaction act; - sigset_t blocked_set1, blocked_set2, pending_set; - sigemptyset(&blocked_set1); - sigemptyset(&blocked_set2); - sigaddset(&blocked_set1, signum); - sigaddset(&blocked_set2, defaultsig); - - act.sa_handler = sig_handler; - act.sa_flags = 0; - sigemptyset(&act.sa_mask); - - int status; - status = sigaction(signum, &act, 0); - ERROR_IF(sigaction, status, == -1); - - status = sigaction(defaultsig, &act, 0); - ERROR_IF(sigaction, status, == -1); - - status = sigprocmask(SIG_SETMASK, &blocked_set1, NULL); - ERROR_IF(sigprocmask, status, == -1); - - status = sigprocmask(SIG_BLOCK, &blocked_set2, NULL); - ERROR_IF(sigprocmask, status, == -1); - - ERROR_IF(raise, signum, == -1); - ERROR_IF(raise, defaultsig, == -1); - - if (handler_called) { - printf("FAIL: Signal was not blocked\n"); - exit(EXIT_FAILURE); - } - - status = sigpending(&pending_set); - ERROR_IF(sigpending, status, == -1); - - status = sigismember(&pending_set, signum); - ERROR_IF(sigismember, status, != 1); - status = sigismember(&pending_set, defaultsig); - ERROR_IF(sigismember, status, != 1); - - act.sa_handler = SIG_IGN; - sigaction(signum, &act, 0); - sigaction(defaultsig, &act, 0); - - return EXIT_SUCCESS; -} - -int main(){ - for (int i=1; i #include #include +#include #include "test_helpers.h" @@ -35,8 +36,18 @@ void action(int sig, siginfo_t *info, void *context) int main(void) { + int status, fds[2]; + struct utsname utsname; + + status = uname(&utsname); + if (status == 0) { + if (strncmp(utsname.sysname, "Linux", 6) == 0) { + printf("Test is not supported on Linux, relibc's siginfo_t is not compatible.\n"); + return EXIT_SUCCESS; + } + } status = pipe(fds); ERROR_IF(pipe, status, == -1); diff --git a/tests/waitpid.c b/tests/waitpid.c index 09a8ffc537..70eabbbfee 100644 --- a/tests/waitpid.c +++ b/tests/waitpid.c @@ -33,4 +33,6 @@ int main(void) { for_code(42); for_code(255); // TODO: Also add coverage for e.g. WIFSTOPPED, WSTOPSIG, WTERMSIG, etc + + return EXIT_SUCCESS; }