Skip to content

Commit 57614a3

Browse files
[libc][sys/wait][linux] add missing and clean up existing macros (#125572)
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
1 parent 5b98be4 commit 57614a3

File tree

1 file changed

+14
-31
lines changed

1 file changed

+14
-31
lines changed

libc/include/llvm-libc-macros/linux/sys-wait-macros.h

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,36 +9,19 @@
99
#ifndef LLVM_LIBC_MACROS_LINUX_SYS_WAIT_MACROS_H
1010
#define LLVM_LIBC_MACROS_LINUX_SYS_WAIT_MACROS_H
1111

12-
// Wait flags
13-
#define WNOHANG 1 // Do not block
14-
#define WUNTRACED 2 // Report is a child has stopped even if untraced
15-
#define WEXITED 4 // Report dead child
16-
#define WCONTINUED 8 // Report if a stopped child has been resumed by SIGCONT
17-
#define WSTOPPED WUNTRACED
18-
19-
// Wait status info macros
20-
#define __WEXITSTATUS(status) (((status)&0xff00) >> 8)
21-
#define __WTERMSIG(status) ((status)&0x7f)
22-
#define __WIFEXITED(status) (__WTERMSIG(status) == 0)
23-
24-
// Macros for constructing status values.
25-
#define __W_EXITCODE(ret, sig) ((ret) << 8 | (sig))
26-
#define __W_STOPCODE(sig) ((sig) << 8 | 0x7f)
27-
#define __W_CONTINUED 0xffff
28-
#define __WCOREFLAG 0x80
29-
30-
#define WEXITSTATUS(status) __WEXITSTATUS(status)
31-
#define WTERMSIG(status) __WTERMSIG(status)
32-
#define WIFEXITED(status) __WIFEXITED(status)
33-
34-
#define WCOREFLAG __WCOREFLAG
35-
#define W_EXITCODE(ret, sig) __W_EXITCODE(ret, sig)
36-
#define W_STOPCODE(sig) __W_STOPCODE(sig)
37-
38-
// First argument to waitid:
39-
#define P_ALL 0
40-
#define P_PID 1
41-
#define P_PGID 2
42-
#define P_PIDFD 3
12+
#include <linux/wait.h>
13+
14+
#define WCOREDUMP(status) ((status) & WCOREFLAG)
15+
#define WEXITSTATUS(status) (((status) & 0xff00) >> 8)
16+
#define WIFCONTINUED(status) ((status) == 0xffff)
17+
#define WIFEXITED(status) (WTERMSIG(status) == 0)
18+
#define WIFSIGNALED(status) ((WTERMSIG(status) + 1) >= 2)
19+
#define WIFSTOPPED(status) (WTERMSIG(status) == 0x7f)
20+
#define WSTOPSIG(status) WEXITSTATUS(status)
21+
#define WTERMSIG(status) ((status) & 0x7f)
22+
23+
#define WCOREFLAG 0x80
24+
#define W_EXITCODE(ret, sig) ((ret) << 8 | (sig))
25+
#define W_STOPCODE(sig) ((sig) << 8 | 0x7f)
4326

4427
#endif // LLVM_LIBC_MACROS_LINUX_SYS_WAIT_MACROS_H

0 commit comments

Comments
 (0)