[libc-commits] [libc] [libc] Make siginfo_t the kernel's 128 bytes (PR #239979)
via libc-commits
libc-commits at lists.llvm.org
Sat Nov 7 06:45:48 PST 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libc
Author: Mike Lothian (FireBurn)
<details>
<summary>Changes</summary>
The padding in siginfo_t's union took the whole of SI_MAX_SIZE without
leaving out the fields in front of it, so the type came to 144 bytes on
a 64 bit target. The fields were where the kernel puts them, and only
the size was wrong, which a program copying one or sizing a buffer for
one would see.
The kernel works the padding out from what comes before the union: three
ints, and on a 64 bit target the space that aligns the union for a
pointer. This does the same.
Assisted-by: Claude
---
Full diff: https://github.com/llvm/llvm-project/pull/239979.diff
2 Files Affected:
- (modified) libc/include/llvm-libc-types/siginfo_t.h (+6-1)
- (modified) libc/test/src/signal/sigaction_test.cpp (+6)
``````````diff
diff --git a/libc/include/llvm-libc-types/siginfo_t.h b/libc/include/llvm-libc-types/siginfo_t.h
index 67366e40b1ebc4..b868a2c2778a31 100644
--- a/libc/include/llvm-libc-types/siginfo_t.h
+++ b/libc/include/llvm-libc-types/siginfo_t.h
@@ -15,6 +15,11 @@
#include "union_sigval.h"
#define SI_MAX_SIZE 128
+// The union follows three ints and, on a 64 bit target, the padding that
+// aligns it for a pointer, so that the whole comes to SI_MAX_SIZE as the
+// kernel's does.
+#define __SI_PAD_SIZE \
+ ((SI_MAX_SIZE - (sizeof(void *) == 8 ? 4 : 3) * sizeof(int)) / sizeof(int))
typedef struct {
int si_signo; /* Signal number. */
@@ -22,7 +27,7 @@ typedef struct {
this signal, as defined in <errno.h>. */
int si_code; /* Signal code. */
union {
- int _si_pad[SI_MAX_SIZE / sizeof(int)];
+ int _si_pad[__SI_PAD_SIZE];
/* kill() */
struct {
diff --git a/libc/test/src/signal/sigaction_test.cpp b/libc/test/src/signal/sigaction_test.cpp
index c26cc4927e70fe..bebbeb51f4db8c 100644
--- a/libc/test/src/signal/sigaction_test.cpp
+++ b/libc/test/src/signal/sigaction_test.cpp
@@ -154,6 +154,12 @@ struct SiginfoTest {
}
};
+// The kernel hands a handler 128 bytes of siginfo_t, its SI_MAX_SIZE, whatever
+// the target, and gives waitid and sigtimedwait no more room than that.
+TEST(LlvmLibcSigaction, SiginfoIsTheKernelsSize) {
+ EXPECT_EQ(sizeof(siginfo_t), size_t(128));
+}
+
// Verify that SA_SIGINFO invokes the sa_sigaction handler with siginfo_t.
TEST(LlvmLibcSigaction, Siginfo) {
SiginfoTest::received = false;
``````````
</details>
https://github.com/llvm/llvm-project/pull/239979
More information about the libc-commits
mailing list