[libc-commits] [libc] [libc] Implement sigwait (PR #237572)
Anshitha Yeruva via libc-commits
libc-commits at lists.llvm.org
Fri Nov 6 17:58:48 PST 2026
================
@@ -0,0 +1,44 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+/// Unittests for sigwait.
+///
+//===----------------------------------------------------------------------===//
+
+#include "src/signal/sigwait.h"
+
+#include "hdr/errno_macros.h"
+#include "hdr/signal_macros.h"
+#include "hdr/types/sigset_t.h"
+#include "src/signal/raise.h"
+#include "src/signal/sigaddset.h"
+#include "src/signal/sigemptyset.h"
+#include "src/signal/sigprocmask.h"
+#include "test/UnitTest/Test.h"
+
+TEST(LlvmLibcSigwaitTest, WaitPendingSignal) {
+ // Block SIGUSR1 so raising it leaves it pending without terminating.
+ sigset_t mask;
+ ASSERT_EQ(LIBC_NAMESPACE::sigemptyset(&mask), 0);
+ ASSERT_EQ(LIBC_NAMESPACE::sigaddset(&mask, SIGUSR1), 0);
+
+ sigset_t oldset;
+ ASSERT_EQ(LIBC_NAMESPACE::sigprocmask(SIG_BLOCK, &mask, &oldset), 0);
+
+ // Raise SIGUSR1. It is now queued/pending for this thread.
+ ASSERT_EQ(LIBC_NAMESPACE::raise(SIGUSR1), 0);
+
+ // sigwait should immediately catch and dequeue SIGUSR1.
+ int sig = 0;
+ ASSERT_EQ(LIBC_NAMESPACE::sigwait(&mask, &sig), 0);
----------------
anshithayeruva wrote:
I checked the Linux kernel implementation for rt_sigtimedwait, and it only returns EINVAL if sigsetsize is wrong or if timeout nanoseconds are invalid. Since we hardcode sizeof(sigset_t) and pass nullptr for timeout, there doesn't seem to be a way to trigger EINVAL from userspace on Linux.
https://github.com/llvm/llvm-project/pull/237572
More information about the libc-commits
mailing list