-
Notifications
You must be signed in to change notification settings - Fork 10.9k
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
[libc] Update siginfo_t to match kernel definition #66560
Conversation
This patch updates the siginfo_t struct definition to match the definition from the kernel in here: https://github.com/torvalds/linux/blob/master/include/uapi/asm-generic/siginfo.h In particular, there are two main changes: 1. swap position of si_code and si_errno: si_code show come after si_errno in all systems except MIPS. Since we don't MIPS, the order is fixed for now, but can be easily \#ifdef'd if MIPS support is implemented in the future. 2. We add a union of structs that are filled depending on the signal raised. This change was required for the fork and spawn integration tests in rv32, since they fork/clone the running process, call wait/waitid/waitpid, and read the status, which was wrong in rv32 because wait/waitid/waitpid are implemented in rv32 using SYS_waitid. SYS_waitid takes a pointer to a siginfo_t and fills the proper fields in the struct. The previous siginfo_t definition was being incorrectly filled due to not taking into account the signal raised.
@llvm/pr-subscribers-libc ChangesThis patch updates the siginfo_t struct definition to match the definition from the kernel here: https://github.com/torvalds/linux/blob/master/include/uapi/asm-generic/siginfo.h In particular, there are two main changes:
This change was required for the fork and spawn integration tests in rv32, since they fork/clone the running process, call wait/waitid/waitpid, and read the status, which was wrong in rv32 because wait/waitid/waitpid are implemented in rv32 using SYS_waitid. SYS_waitid takes a pointer to a siginfo_t and fills the proper fields in the struct. The previous siginfo_t definition was being incorrectly filled due to not taking into account the signal raised.Full diff: https://github.com/llvm/llvm-project/pull/66560.diff 2 Files Affected:
diff --git a/libc/include/llvm-libc-types/CMakeLists.txt b/libc/include/llvm-libc-types/CMakeLists.txt
index 006986fd98fc850..3c0cc7bbc71dacb 100644
--- a/libc/include/llvm-libc-types/CMakeLists.txt
+++ b/libc/include/llvm-libc-types/CMakeLists.txt
@@ -63,7 +63,7 @@ add_header(struct_rusage HDR struct_rusage.h DEPENDS .struct_timeval)
add_header(struct_dirent HDR struct_dirent.h DEPENDS .ino_t .off_t)
add_header(struct_sched_param HDR struct_sched_param.h)
add_header(union_sigval HDR union_sigval.h)
-add_header(siginfo_t HDR siginfo_t.h DEPENDS .union_sigval .pid_t .uid_t)
+add_header(siginfo_t HDR siginfo_t.h DEPENDS .union_sigval .pid_t .uid_t .clock_t)
add_header(sig_atomic_t HDR sig_atomic_t.h)
add_header(sigset_t HDR sigset_t.h DEPENDS libc.include.llvm-libc-macros.signal_macros)
add_header(struct_sigaction HDR struct_sigaction.h DEPENDS .sigset_t .siginfo_t)
diff --git a/libc/include/llvm-libc-types/siginfo_t.h b/libc/include/llvm-libc-types/siginfo_t.h
index 59d39e046b66c7e..b4bbde00bfb266f 100644
--- a/libc/include/llvm-libc-types/siginfo_t.h
+++ b/libc/include/llvm-libc-types/siginfo_t.h
@@ -9,20 +9,95 @@
#ifndef __LLVM_LIBC_TYPES_SIGINFO_T_H__
#define __LLVM_LIBC_TYPES_SIGINFO_T_H__
+#include <llvm-libc-types/clock_t.h>
#include <llvm-libc-types/pid_t.h>
#include <llvm-libc-types/uid_t.h>
#include <llvm-libc-types/union_sigval.h>
typedef struct {
- int si_signo;
- int si_code;
- int si_errno;
- pid_t si_pid;
- uid_t si_uid;
- void *si_addr;
- int si_status;
- long si_band;
- union sigval si_value;
+ int si_signo; /* Signal number. */
+ int si_errno; /* If non-zero, an errno value associated with
+ this signal, as defined in <errno.h>. */
+ int si_code; /* Signal code. */
+ union {
+ /* kill() */
+ struct {
+ pid_t si_pid; /* sender's pid */
+ uid_t si_uid; /* sender's uid */
+ } _kill;
+
+ /* POSIX.1b timers */
+ struct {
+ int si_tid; /* timer id */
+ int _overrun; /* overrun count */
+ union sigval si_sigval; /* same as below */
+ } _timer;
+
+ /* POSIX.1b signals */
+ struct {
+ pid_t si_pid; /* sender's pid */
+ uid_t si_uid; /* sender's uid */
+ union sigval si_sigval;
+ } _rt;
+
+ /* SIGCHLD */
+ struct {
+ pid_t si_pid; /* which child */
+ uid_t si_uid; /* sender's uid */
+ int si_status; /* exit code */
+ clock_t si_utime;
+ clock_t si_stime;
+ } _sigchld;
+
+ /* SIGILL, SIGFPE, SIGSEGV, SIGBUS, SIGTRAP, SIGEMT */
+ struct {
+ void *si_addr; /* faulting insn/memory ref. */
+ short int si_addr_lsb; /* Valid LSB of the reported address. */
+ union {
+ /* used when si_code=SEGV_BNDERR */
+ struct {
+ void *_lower;
+ void *_upper;
+ } _addr_bnd;
+ /* used when si_code=SEGV_PKUERR */
+ __UINT32_TYPE__ _pkey;
+ } _bounds;
+ } _sigfault;
+
+ /* SIGPOLL */
+ struct {
+ long int si_band; /* POLL_IN, POLL_OUT, POLL_MSG */
+ int si_fd;
+ } _sigpoll;
+
+ /* SIGSYS */
+ struct {
+ void *_call_addr; /* calling user insn */
+ int _syscall; /* triggering system call number */
+ unsigned int _arch; /* AUDIT_ARCH_* of syscall */
+ } _sigsys;
+ } _sifields;
} siginfo_t;
+#define si_pid _sifields._kill.si_pid
+#define si_uid _sifields._kill.si_uid
+#define si_timerid _sifields._timer.si_tid
+#define si_overrun _sifields._timer.si_overrun
+#define si_status _sifields._sigchld.si_status
+#define si_utime _sifields._sigchld.si_utime
+#define si_stime _sifields._sigchld.si_stime
+#define si_value _sifields._rt.si_sigval
+#define si_int _sifields._rt.si_sigval.sival_int
+#define si_ptr _sifields._rt.si_sigval.sival_ptr
+#define si_addr _sifields._sigfault.si_addr
+#define si_addr_lsb _sifields._sigfault.si_addr_lsb
+#define si_lower _sifields._sigfault._bounds._addr_bnd._lower
+#define si_upper _sifields._sigfault._bounds._addr_bnd._upper
+#define si_pkey _sifields._sigfault._bounds._pkey
+#define si_band _sifields._sigpoll.si_band
+#define si_fd _sifields._sigpoll.si_fd
+#define si_call_addr _sifields._sigsys._call_addr
+#define si_syscall _sifields._sigsys._syscall
+#define si_arch _sifields._sigsys._arch
+
#endif // __LLVM_LIBC_TYPES_SIGINFO_T_H__
|
This patch updates the siginfo_t struct definition to match the definition from the kernel here:
https://github.com/torvalds/linux/blob/master/include/uapi/asm-generic/siginfo.h
In particular, there are two main changes:
swap position of si_code and si_errno: si_code show come after si_errno in all systems except MIPS. Since we don't MIPS, the order is fixed for now, but can be easily #ifdef'd if MIPS support is implemented in the future.
We add a union of structs that are filled depending on the signal raised.
This change was required for the fork and spawn integration tests in rv32, since they fork/clone the running process, call wait/waitid/waitpid, and read the status, which was wrong in rv32 because wait/waitid/waitpid are implemented in rv32 using SYS_waitid.
SYS_waitid takes a pointer to a siginfo_t and fills the proper fields in the struct. The previous siginfo_t definition was being incorrectly filled due to not taking into account the signal raised.