From 41c632824c08ac2c9eea43b30d1b3515dd910df6 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Sat, 10 Aug 2013 23:33:54 -0400 Subject: [PATCH] fix definitions of WIFSTOPPED and WIFSIGNALED to support up to signal 127 mips has signal numbers up to 127 (formerly, up to 128, but the last one never worked right and caused kernel panic when used), so 127 in the "signal number" field of the wait status is insufficient for determining that the process was stopped. in addition, a nonzero value in the upper bits must be present, indicating the signal number which caused the process to be stopped. details on this issue can be seen in the email with message id CAAG0J9-d4BfEhbQovFqUAJ3QoOuXScrpsY1y95PrEPxA5DWedQ@mail.gmail.com on the linux-mips mailing list, archived at: http://www.linux-mips.org/archives/linux-mips/2013-06/msg00552.html and in the associated thread about fixing the mips kernel bug. commit 4a96b948687166da26a6c327e6c6733ad2336c5c fixed the corresponding issue in uClibc, but introduced a multiple-evaluation issue for the WIFSTOPPED macro. for the most part, none of these issues affected pure musl systems, since musl has up until now (incorrectly) defined SIGRTMAX as 64 on all archs, even mips. however, interpreting status of non-musl programs on mips may have caused problems. with this change, the full range of signal numbers can be made available on mips. --- include/stdlib.h | 4 ++-- include/sys/wait.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/stdlib.h b/include/stdlib.h index 0bcc9f4f..548bbca6 100644 --- a/include/stdlib.h +++ b/include/stdlib.h @@ -88,8 +88,8 @@ size_t wcstombs (char *__restrict, const wchar_t *__restrict, size_t); #define WTERMSIG(s) ((s) & 0x7f) #define WSTOPSIG(s) WEXITSTATUS(s) #define WIFEXITED(s) (!WTERMSIG(s)) -#define WIFSTOPPED(s) (((s) & 0xff) == 0x7f) -#define WIFSIGNALED(s) (((signed char) (((s) & 0x7f) + 1) >> 1) > 0) +#define WIFSTOPPED(s) ((short)((((s)&0xffff)*0x10001)>>8) > 0x7f00) +#define WIFSIGNALED(s) (((s)&0xffff)-1 < 0xffu) int posix_memalign (void **, size_t, size_t); int setenv (const char *, const char *, int); diff --git a/include/sys/wait.h b/include/sys/wait.h index b6dfe01d..a7ad7cd1 100644 --- a/include/sys/wait.h +++ b/include/sys/wait.h @@ -45,8 +45,8 @@ pid_t wait4 (pid_t, int *, int, struct rusage *); #define WSTOPSIG(s) WEXITSTATUS(s) #define WCOREDUMP(s) ((s) & 0x80) #define WIFEXITED(s) (!WTERMSIG(s)) -#define WIFSTOPPED(s) (((s) & 0xff) == 0x7f) -#define WIFSIGNALED(s) (((signed char) (((s) & 0x7f) + 1) >> 1) > 0) +#define WIFSTOPPED(s) ((short)((((s)&0xffff)*0x10001)>>8) > 0x7f00) +#define WIFSIGNALED(s) (((s)&0xffff)-1 < 0xffu) #define WIFCONTINUED(s) ((s) == 0xffff) #ifdef __cplusplus -- 2.25.1