From 02de82e7cc707b786c52fd5d41c1d3eabab453c8 Mon Sep 17 00:00:00 2001 From: Nick Desaulniers Date: Mon, 3 Feb 2025 09:11:30 -0800 Subject: [PATCH 1/4] [libc][sys/wait][linux] add missing and clean up existing macros This patch does a few things: - replace macro definitions with an inclusion of the linux/wait.h kernel header. - WNOHANG - WUNTRACED - WEXITED - WCONTINUED - WSTOPPED - P_ALL - P_PID - P_PGID - P_PIDFD - Add missing macro definitions mandated by POSIX. Some are needed to build LLVM. - WCOREDUMP - WIFCONTINUED - WIFSIGNALELD - WIFSTOPPED - WSTOPSIG - Remove glibc style __W* macros. Users should stick with the POSIX macros. We can re-add them if necessary. - __WEXITSTATUS - __WTERMSIG - __WIFEXITED - __WIFSIGNALED - __WIFSTOPPED - __WIFCONTINUED - __WCOREDUMP - __W_EXITCODE - __W_STOPCODE - __W_CONTINUED - __WCOREFLAG Fixes: #124944 From c52b9ec2a12f514a99109c58a2875b51b4889a65 Mon Sep 17 00:00:00 2001 From: Nick Desaulniers Date: Mon, 3 Feb 2025 09:13:57 -0800 Subject: [PATCH 2/4] Replace macros defined by linux/wait.h. Just include that kernel header. --- .../llvm-libc-macros/linux/sys-wait-macros.h | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/libc/include/llvm-libc-macros/linux/sys-wait-macros.h b/libc/include/llvm-libc-macros/linux/sys-wait-macros.h index c101638fdae34..3808ecb5e6d88 100644 --- a/libc/include/llvm-libc-macros/linux/sys-wait-macros.h +++ b/libc/include/llvm-libc-macros/linux/sys-wait-macros.h @@ -9,12 +9,7 @@ #ifndef LLVM_LIBC_MACROS_LINUX_SYS_WAIT_MACROS_H #define LLVM_LIBC_MACROS_LINUX_SYS_WAIT_MACROS_H -// Wait flags -#define WNOHANG 1 // Do not block -#define WUNTRACED 2 // Report is a child has stopped even if untraced -#define WEXITED 4 // Report dead child -#define WCONTINUED 8 // Report if a stopped child has been resumed by SIGCONT -#define WSTOPPED WUNTRACED +#include // Wait status info macros #define __WEXITSTATUS(status) (((status)&0xff00) >> 8) @@ -35,10 +30,4 @@ #define W_EXITCODE(ret, sig) __W_EXITCODE(ret, sig) #define W_STOPCODE(sig) __W_STOPCODE(sig) -// First argument to waitid: -#define P_ALL 0 -#define P_PID 1 -#define P_PGID 2 -#define P_PIDFD 3 - #endif // LLVM_LIBC_MACROS_LINUX_SYS_WAIT_MACROS_H From bda908fcca7b9eb2feaf7e5a709f92428f9bab06 Mon Sep 17 00:00:00 2001 From: Nick Desaulniers Date: Mon, 3 Feb 2025 09:15:50 -0800 Subject: [PATCH 3/4] add missing POSIX mandated macros --- .../llvm-libc-macros/linux/sys-wait-macros.h | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/libc/include/llvm-libc-macros/linux/sys-wait-macros.h b/libc/include/llvm-libc-macros/linux/sys-wait-macros.h index 3808ecb5e6d88..ec0baa40c98cf 100644 --- a/libc/include/llvm-libc-macros/linux/sys-wait-macros.h +++ b/libc/include/llvm-libc-macros/linux/sys-wait-macros.h @@ -12,9 +12,13 @@ #include // Wait status info macros -#define __WEXITSTATUS(status) (((status)&0xff00) >> 8) -#define __WTERMSIG(status) ((status)&0x7f) +#define __WEXITSTATUS(status) (((status) & 0xff00) >> 8) +#define __WTERMSIG(status) ((status) & 0x7f) #define __WIFEXITED(status) (__WTERMSIG(status) == 0) +#define __WIFSIGNALED(status) ((__WTERMSIG(status) + 1) >= 2) +#define __WIFSTOPPED(status) (__WTERMSIG(status) == 0x7f) +#define __WIFCONTINUED(status) ((status) == __W_CONTINUED) +#define __WCOREDUMP(status) ((status) & __WCOREFLAG) // Macros for constructing status values. #define __W_EXITCODE(ret, sig) ((ret) << 8 | (sig)) @@ -22,9 +26,14 @@ #define __W_CONTINUED 0xffff #define __WCOREFLAG 0x80 +#define WCOREDUMP(status) ((status) & __WCOREFLAG) #define WEXITSTATUS(status) __WEXITSTATUS(status) -#define WTERMSIG(status) __WTERMSIG(status) +#define WIFCONTINUED(status) __WIFCONTINUED(status) #define WIFEXITED(status) __WIFEXITED(status) +#define WIFSIGNALED(status) __WIFSIGNALED(status) +#define WIFSTOPPED(status) __WIFSTOPPED(status) +#define WSTOPSIG(status) WEXITSTATUS(status) +#define WTERMSIG(status) __WTERMSIG(status) #define WCOREFLAG __WCOREFLAG #define W_EXITCODE(ret, sig) __W_EXITCODE(ret, sig) From 8b2a96172843130cfd7848da9045b4fcdfa78361 Mon Sep 17 00:00:00 2001 From: Nick Desaulniers Date: Mon, 3 Feb 2025 09:24:40 -0800 Subject: [PATCH 4/4] git rid of glibc style __W* macros; users should not use those --- .../llvm-libc-macros/linux/sys-wait-macros.h | 35 ++++++------------- 1 file changed, 10 insertions(+), 25 deletions(-) diff --git a/libc/include/llvm-libc-macros/linux/sys-wait-macros.h b/libc/include/llvm-libc-macros/linux/sys-wait-macros.h index ec0baa40c98cf..d01cfa71ba390 100644 --- a/libc/include/llvm-libc-macros/linux/sys-wait-macros.h +++ b/libc/include/llvm-libc-macros/linux/sys-wait-macros.h @@ -11,32 +11,17 @@ #include -// Wait status info macros -#define __WEXITSTATUS(status) (((status) & 0xff00) >> 8) -#define __WTERMSIG(status) ((status) & 0x7f) -#define __WIFEXITED(status) (__WTERMSIG(status) == 0) -#define __WIFSIGNALED(status) ((__WTERMSIG(status) + 1) >= 2) -#define __WIFSTOPPED(status) (__WTERMSIG(status) == 0x7f) -#define __WIFCONTINUED(status) ((status) == __W_CONTINUED) -#define __WCOREDUMP(status) ((status) & __WCOREFLAG) - -// Macros for constructing status values. -#define __W_EXITCODE(ret, sig) ((ret) << 8 | (sig)) -#define __W_STOPCODE(sig) ((sig) << 8 | 0x7f) -#define __W_CONTINUED 0xffff -#define __WCOREFLAG 0x80 - -#define WCOREDUMP(status) ((status) & __WCOREFLAG) -#define WEXITSTATUS(status) __WEXITSTATUS(status) -#define WIFCONTINUED(status) __WIFCONTINUED(status) -#define WIFEXITED(status) __WIFEXITED(status) -#define WIFSIGNALED(status) __WIFSIGNALED(status) -#define WIFSTOPPED(status) __WIFSTOPPED(status) +#define WCOREDUMP(status) ((status) & WCOREFLAG) +#define WEXITSTATUS(status) (((status) & 0xff00) >> 8) +#define WIFCONTINUED(status) ((status) == 0xffff) +#define WIFEXITED(status) (WTERMSIG(status) == 0) +#define WIFSIGNALED(status) ((WTERMSIG(status) + 1) >= 2) +#define WIFSTOPPED(status) (WTERMSIG(status) == 0x7f) #define WSTOPSIG(status) WEXITSTATUS(status) -#define WTERMSIG(status) __WTERMSIG(status) +#define WTERMSIG(status) ((status) & 0x7f) -#define WCOREFLAG __WCOREFLAG -#define W_EXITCODE(ret, sig) __W_EXITCODE(ret, sig) -#define W_STOPCODE(sig) __W_STOPCODE(sig) +#define WCOREFLAG 0x80 +#define W_EXITCODE(ret, sig) ((ret) << 8 | (sig)) +#define W_STOPCODE(sig) ((sig) << 8 | 0x7f) #endif // LLVM_LIBC_MACROS_LINUX_SYS_WAIT_MACROS_H