[libc-commits] [libc] [libc] Implement sigsuspend in signal (PR #237223)
Leo Garcia via libc-commits
libc-commits at lists.llvm.org
Mon Nov 2 03:52:44 PST 2026
https://github.com/leogarci42 updated https://github.com/llvm/llvm-project/pull/237223
>From 5e61e6d48a617e8bced5e209966fa77c991cf7f9 Mon Sep 17 00:00:00 2001
From: leogarci42 <lg9752247 at gmail.com>
Date: Fri, 30 Oct 2026 14:40:31 +0100
Subject: [PATCH 1/2] [libc] Implement sigsuspend in signal (#236167)
Add the standard POSIX function sigsuspend to <signal.h>:
- Add low-level rt_sigsuspend system call wrapper in libc/src/__support/OSUtil/linux/syscall_wrappers/rt_sigsuspend.h.
- Add public header declaration in libc/src/signal/sigsuspend.h.
- Implement sigsuspend entrypoint in libc/src/signal/linux/sigsuspend.cpp.
- Declare sigsuspend in libc/include/signal.yaml.
- Register entrypoint for Linux (x86_64, aarch64, riscv) in architecture config files.
- Update CMakeLists.txt files across syscall wrappers, signal sources, and tests.
- Add unit tests in libc/test/src/signal/sigsuspend_test.cpp.
Fixes #236167.
---
libc/config/linux/aarch64/entrypoints.txt | 1 +
libc/config/linux/riscv/entrypoints.txt | 1 +
libc/config/linux/x86_64/entrypoints.txt | 1 +
libc/include/signal.yaml | 6 ++
.../linux/syscall_wrappers/CMakeLists.txt | 13 ++++
.../linux/syscall_wrappers/rt_sigsuspend.h | 34 +++++++++
libc/src/signal/CMakeLists.txt | 7 ++
libc/src/signal/linux/CMakeLists.txt | 12 ++++
libc/src/signal/linux/sigsuspend.cpp | 28 ++++++++
libc/src/signal/sigsuspend.h | 21 ++++++
libc/test/src/signal/CMakeLists.txt | 21 ++++++
libc/test/src/signal/sigsuspend_test.cpp | 69 +++++++++++++++++++
12 files changed, 214 insertions(+)
create mode 100644 libc/src/__support/OSUtil/linux/syscall_wrappers/rt_sigsuspend.h
create mode 100644 libc/src/signal/linux/sigsuspend.cpp
create mode 100644 libc/src/signal/sigsuspend.h
create mode 100644 libc/test/src/signal/sigsuspend_test.cpp
diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index b1163f266f1b62..f3108f759bba6c 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -1383,6 +1383,7 @@ if(LLVM_LIBC_FULL_BUILD)
libc.src.signal.sigismember
libc.src.signal.signal
libc.src.signal.sigprocmask
+ libc.src.signal.sigsuspend
# spawn.h entrypoints
libc.src.spawn.posix_spawn
diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index 839d4f539b916d..888f542fce2194 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -1569,6 +1569,7 @@ if(LLVM_LIBC_FULL_BUILD)
libc.src.signal.sigismember
libc.src.signal.signal
libc.src.signal.sigprocmask
+ libc.src.signal.sigsuspend
# spawn.h entrypoints
libc.src.spawn.posix_spawn
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index 483a4d371c5a95..6f18ff17510611 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -1595,6 +1595,7 @@ if(LLVM_LIBC_FULL_BUILD)
libc.src.signal.sigismember
libc.src.signal.signal
libc.src.signal.sigprocmask
+ libc.src.signal.sigsuspend
# spawn.h entrypoints
libc.src.spawn.posix_spawn
diff --git a/libc/include/signal.yaml b/libc/include/signal.yaml
index b763da7eeb6025..138c7c32ddea85 100644
--- a/libc/include/signal.yaml
+++ b/libc/include/signal.yaml
@@ -127,6 +127,12 @@ functions:
- type: int
- type: const sigset_t *__restrict
- type: sigset_t *__restrict
+ - name: sigsuspend
+ standards:
+ - posix
+ return_type: int
+ arguments:
+ - type: const sigset_t *
- name: pthread_sigmask
standards:
- posix
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt b/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
index 8cff89c818baaa..8b0501bc71fe39 100644
--- a/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
@@ -610,6 +610,19 @@ add_header_library(
libc.include.sys_syscall
)
+add_header_library(
+ rt_sigsuspend
+ HDRS
+ rt_sigsuspend.h
+ DEPENDS
+ libc.src.__support.OSUtil.osutil
+ libc.src.__support.common
+ libc.src.__support.error_or
+ libc.src.__support.macros.config
+ libc.hdr.types.sigset_t
+ libc.include.sys_syscall
+)
+
add_header_library(
raise
HDRS
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/rt_sigsuspend.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/rt_sigsuspend.h
new file mode 100644
index 00000000000000..a49cc0128946fa
--- /dev/null
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/rt_sigsuspend.h
@@ -0,0 +1,34 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Syscall wrapper for rt_sigsuspend.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_RT_SIGSUSPEND_H
+#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_RT_SIGSUSPEND_H
+
+#include "hdr/types/sigset_t.h"
+#include "src/__support/OSUtil/linux/syscall.h"
+#include "src/__support/common.h"
+#include "src/__support/error_or.h"
+#include "src/__support/macros/config.h"
+#include <sys/syscall.h>
+
+namespace LIBC_NAMESPACE_DECL {
+namespace linux_syscalls {
+
+LIBC_INLINE ErrorOr<int> rt_sigsuspend(const sigset_t *set) {
+ return syscall_checked<int>(SYS_rt_sigsuspend, set, sizeof(sigset_t));
+}
+
+} // namespace linux_syscalls
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_RT_SIGSUSPEND_H
diff --git a/libc/src/signal/CMakeLists.txt b/libc/src/signal/CMakeLists.txt
index 8da94d1eea85fd..0f7b1090a9d1d2 100644
--- a/libc/src/signal/CMakeLists.txt
+++ b/libc/src/signal/CMakeLists.txt
@@ -37,6 +37,13 @@ add_entrypoint_object(
.${LIBC_TARGET_OS}.sigprocmask
)
+add_entrypoint_object(
+ sigsuspend
+ ALIAS
+ DEPENDS
+ .${LIBC_TARGET_OS}.sigsuspend
+)
+
add_entrypoint_object(
pthread_sigmask
ALIAS
diff --git a/libc/src/signal/linux/CMakeLists.txt b/libc/src/signal/linux/CMakeLists.txt
index 77898cf9aab636..37853a7f2999d2 100644
--- a/libc/src/signal/linux/CMakeLists.txt
+++ b/libc/src/signal/linux/CMakeLists.txt
@@ -95,6 +95,18 @@ add_entrypoint_object(
libc.src.errno.errno
)
+add_entrypoint_object(
+ sigsuspend
+ SRCS
+ sigsuspend.cpp
+ HDRS
+ ../sigsuspend.h
+ DEPENDS
+ libc.hdr.types.sigset_t
+ libc.src.__support.OSUtil.linux.syscall_wrappers.rt_sigsuspend
+ libc.src.errno.errno
+)
+
add_entrypoint_object(
pthread_sigmask
SRCS
diff --git a/libc/src/signal/linux/sigsuspend.cpp b/libc/src/signal/linux/sigsuspend.cpp
new file mode 100644
index 00000000000000..1aabe12eaaf002
--- /dev/null
+++ b/libc/src/signal/linux/sigsuspend.cpp
@@ -0,0 +1,28 @@
+//===-- Linux implementation of sigsuspend --------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/signal/sigsuspend.h"
+
+#include "hdr/types/sigset_t.h"
+#include "src/__support/OSUtil/linux/syscall_wrappers/rt_sigsuspend.h"
+#include "src/__support/common.h"
+#include "src/__support/libc_errno.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(int, sigsuspend, (const sigset_t *set)) {
+ auto result = linux_syscalls::rt_sigsuspend(set);
+ if (result.has_value())
+ return 0;
+
+ libc_errno = result.error();
+ return -1;
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/signal/sigsuspend.h b/libc/src/signal/sigsuspend.h
new file mode 100644
index 00000000000000..3fd591669d77be
--- /dev/null
+++ b/libc/src/signal/sigsuspend.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for sigsuspend --------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_SIGNAL_SIGSUSPEND_H
+#define LLVM_LIBC_SRC_SIGNAL_SIGSUSPEND_H
+
+#include "hdr/types/sigset_t.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+int sigsuspend(const sigset_t *set);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_SIGNAL_SIGSUSPEND_H
diff --git a/libc/test/src/signal/CMakeLists.txt b/libc/test/src/signal/CMakeLists.txt
index dc1769c963b228..e9cac66e1bd6b3 100644
--- a/libc/test/src/signal/CMakeLists.txt
+++ b/libc/test/src/signal/CMakeLists.txt
@@ -55,6 +55,27 @@ add_libc_test(
libc.test.UnitTest.ErrnoSetterMatcher
)
+add_libc_test(
+ sigsuspend_test
+ SUITE
+ libc-signal-tests
+ SRCS
+ sigsuspend_test.cpp
+ DEPENDS
+ libc.hdr.errno_macros
+ libc.hdr.signal_macros
+ libc.hdr.types.sigset_t
+ libc.hdr.types.struct_sigaction
+ libc.src.signal.raise
+ libc.src.signal.sigaction
+ libc.src.signal.sigaddset
+ libc.src.signal.sigemptyset
+ libc.src.signal.sigprocmask
+ libc.src.signal.sigsuspend
+ libc.test.UnitTest.ErrnoCheckingTest
+ libc.test.UnitTest.ErrnoSetterMatcher
+)
+
add_libc_test(
pthread_sigmask_test
SUITE
diff --git a/libc/test/src/signal/sigsuspend_test.cpp b/libc/test/src/signal/sigsuspend_test.cpp
new file mode 100644
index 00000000000000..c5ecde7d8a250c
--- /dev/null
+++ b/libc/test/src/signal/sigsuspend_test.cpp
@@ -0,0 +1,69 @@
+//===-- Unittests for sigsuspend ------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "hdr/errno_macros.h"
+#include "hdr/signal_macros.h"
+#include "hdr/types/sigset_t.h"
+#include "hdr/types/struct_sigaction.h"
+#include "src/signal/raise.h"
+#include "src/signal/sigaction.h"
+#include "src/signal/sigaddset.h"
+#include "src/signal/sigemptyset.h"
+#include "src/signal/sigprocmask.h"
+#include "src/signal/sigsuspend.h"
+#include "test/UnitTest/ErrnoCheckingTest.h"
+#include "test/UnitTest/ErrnoSetterMatcher.h"
+#include "test/UnitTest/Test.h"
+
+static volatile bool signal_caught = false;
+
+static void test_sig_handler(int signo) {
+ if (signo == SIGUSR1)
+ signal_caught = true;
+}
+
+class LlvmLibcSigsuspendInterruptTest
+ : public LIBC_NAMESPACE::testing::ErrnoCheckingTest {
+ struct sigaction old_action{};
+ sigset_t old_mask{};
+
+public:
+ void SetUp() override {
+ ErrnoCheckingTest::SetUp();
+ signal_caught = false;
+ ASSERT_THAT(LIBC_NAMESPACE::sigprocmask(0, nullptr, &old_mask), Succeeds());
+ struct sigaction sa{};
+ sa.sa_handler = test_sig_handler;
+ ASSERT_THAT(LIBC_NAMESPACE::sigemptyset(&sa.sa_mask), Succeeds());
+ sa.sa_flags = 0;
+ ASSERT_THAT(LIBC_NAMESPACE::sigaction(SIGUSR1, &sa, &old_action),
+ Succeeds());
+ }
+
+ void TearDown() override {
+ LIBC_NAMESPACE::sigaction(SIGUSR1, &old_action, nullptr);
+ LIBC_NAMESPACE::sigprocmask(SIG_SETMASK, &old_mask, nullptr);
+ ErrnoCheckingTest::TearDown();
+ }
+};
+
+using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Fails;
+using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
+
+// This tests if it correctly catches a pending signal.
+TEST_F(LlvmLibcSigsuspendInterruptTest, SigsuspendCaughtByHandler) {
+ sigset_t block, empty;
+ EXPECT_THAT(LIBC_NAMESPACE::sigemptyset(&block), Succeeds());
+ EXPECT_THAT(LIBC_NAMESPACE::sigaddset(&block, SIGUSR1), Succeeds());
+ EXPECT_THAT(LIBC_NAMESPACE::sigprocmask(SIG_BLOCK, &block, nullptr),
+ Succeeds());
+ EXPECT_THAT(LIBC_NAMESPACE::raise(SIGUSR1), Succeeds());
+ EXPECT_THAT(LIBC_NAMESPACE::sigemptyset(&empty), Succeeds());
+ EXPECT_THAT(LIBC_NAMESPACE::sigsuspend(&empty), Fails(EINTR));
+ EXPECT_TRUE(signal_caught);
+}
>From f6ea264aa374b961ea5da2f39666c928cbc13d50 Mon Sep 17 00:00:00 2001
From: leogarci42 <lg9752247 at gmail.com>
Date: Mon, 2 Nov 2026 12:51:28 +0100
Subject: [PATCH 2/2] [libc] Fix sigsuspend test build
Move the ErrnoSetterMatcher using declarations before the test fixture so that Succeeds is visible in SetUp. This fixes the CI build failure.
---
libc/test/src/signal/sigsuspend_test.cpp | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/libc/test/src/signal/sigsuspend_test.cpp b/libc/test/src/signal/sigsuspend_test.cpp
index c5ecde7d8a250c..54ad3514400f6f 100644
--- a/libc/test/src/signal/sigsuspend_test.cpp
+++ b/libc/test/src/signal/sigsuspend_test.cpp
@@ -20,6 +20,9 @@
#include "test/UnitTest/ErrnoSetterMatcher.h"
#include "test/UnitTest/Test.h"
+using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Fails;
+using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
+
static volatile bool signal_caught = false;
static void test_sig_handler(int signo) {
@@ -52,9 +55,6 @@ class LlvmLibcSigsuspendInterruptTest
}
};
-using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Fails;
-using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
-
// This tests if it correctly catches a pending signal.
TEST_F(LlvmLibcSigsuspendInterruptTest, SigsuspendCaughtByHandler) {
sigset_t block, empty;
More information about the libc-commits
mailing list