[libc-commits] [libc] 8d7ca08 - [libc] Update siginfo_t to match kernel definition (#66560)
via libc-commits
libc-commits at lists.llvm.org
Thu Sep 21 07:59:07 PDT 2023
Author: Mikhail R. Gadelha
Date: 2023-09-21T10:59:03-04:00
New Revision: 8d7ca08b9f5bf5ab6c5a0c5e68dd5643036544cb
URL: https://github.com/llvm/llvm-project/commit/8d7ca08b9f5bf5ab6c5a0c5e68dd5643036544cb
DIFF: https://github.com/llvm/llvm-project/commit/8d7ca08b9f5bf5ab6c5a0c5e68dd5643036544cb.diff
LOG: [libc] Update siginfo_t to match kernel definition (#66560)
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:
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.
Added:
Modified:
libc/include/llvm-libc-types/CMakeLists.txt
libc/include/llvm-libc-types/siginfo_t.h
Removed:
################################################################################
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..ef8af78a88be690 100644
--- a/libc/include/llvm-libc-types/siginfo_t.h
+++ b/libc/include/llvm-libc-types/siginfo_t.h
@@ -9,20 +9,101 @@
#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>
+#define SI_MAX_SIZE 128
+
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 {
+ int _si_pad[SI_MAX_SIZE / sizeof(int)];
+
+ /* 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;
+#undef SI_MAX_SIZE
+
+#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__
More information about the libc-commits
mailing list