[libc-commits] [libc] [llvm] [libc] Use a syscall wrapper for sigaltstack (PR #242252)
Connector Switch via libc-commits
libc-commits at lists.llvm.org
Fri Nov 13 02:51:21 PST 2026
https://github.com/c8ef created https://github.com/llvm/llvm-project/pull/242252
This PR move sigaltstack behind the centralized syscall wrappers, following libc/docs/dev/syscall_wrapper_refactor.md.
>From b002ab7cb5431ec3781b525dc18cf5d50e7fe47a Mon Sep 17 00:00:00 2001
From: c8ef <c8ef at outlook.com>
Date: Fri, 13 Nov 2026 18:46:04 +0800
Subject: [PATCH] [libc] Use a syscall wrapper for sigaltstack
---
.../linux/syscall_wrappers/CMakeLists.txt | 13 +++++
.../linux/syscall_wrappers/sigaltstack.h | 34 +++++++++++++
libc/src/signal/linux/CMakeLists.txt | 6 ++-
libc/src/signal/linux/sigaltstack.cpp | 11 ++--
.../llvm-project-overlay/libc/BUILD.bazel | 51 +++++++++++++++++++
5 files changed, 107 insertions(+), 8 deletions(-)
create mode 100644 libc/src/__support/OSUtil/linux/syscall_wrappers/sigaltstack.h
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt b/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
index 5e59166b73688..f1adb0ff19af9 100644
--- a/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
@@ -1497,6 +1497,19 @@ add_header_library(
libc.src.__support.macros.config
)
+add_header_library(
+ sigaltstack
+ HDRS
+ sigaltstack.h
+ DEPENDS
+ libc.hdr.types.stack_t
+ libc.include.sys_syscall
+ libc.src.__support.OSUtil.osutil
+ libc.src.__support.common
+ libc.src.__support.error_or
+ libc.src.__support.macros.config
+)
+
add_header_library(
symlink
HDRS
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/sigaltstack.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/sigaltstack.h
new file mode 100644
index 0000000000000..9bb576ba24032
--- /dev/null
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/sigaltstack.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 sigaltstack.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_SIGALTSTACK_H
+#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_SIGALTSTACK_H
+
+#include "hdr/types/stack_t.h"
+#include "src/__support/OSUtil/linux/syscall.h" // syscall_checked
+#include "src/__support/common.h"
+#include "src/__support/error_or.h"
+#include "src/__support/macros/config.h"
+#include <sys/syscall.h> // For syscall numbers.
+
+namespace LIBC_NAMESPACE_DECL {
+namespace linux_syscalls {
+
+LIBC_INLINE ErrorOr<int> sigaltstack(const stack_t *ss, stack_t *oss) {
+ return syscall_checked<int>(SYS_sigaltstack, ss, oss);
+}
+
+} // namespace linux_syscalls
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_SIGALTSTACK_H
diff --git a/libc/src/signal/linux/CMakeLists.txt b/libc/src/signal/linux/CMakeLists.txt
index c5e3749b2420d..5551d2196f8c7 100644
--- a/libc/src/signal/linux/CMakeLists.txt
+++ b/libc/src/signal/linux/CMakeLists.txt
@@ -90,11 +90,13 @@ add_entrypoint_object(
HDRS
../sigaltstack.h
DEPENDS
+ libc.hdr.errno_macros
libc.hdr.signal_macros
libc.hdr.types.stack_t
- libc.include.sys_syscall
+ libc.src.__support.OSUtil.linux.syscall_wrappers.sigaltstack
+ libc.src.__support.common
libc.src.__support.libc_errno
- libc.src.__support.OSUtil.osutil
+ libc.src.__support.macros.config
libc.src.errno.errno
)
diff --git a/libc/src/signal/linux/sigaltstack.cpp b/libc/src/signal/linux/sigaltstack.cpp
index a874cd1064e0b..d1d1d7dff8bb5 100644
--- a/libc/src/signal/linux/sigaltstack.cpp
+++ b/libc/src/signal/linux/sigaltstack.cpp
@@ -13,15 +13,14 @@
#include "src/signal/sigaltstack.h"
+#include "hdr/errno_macros.h"
#include "hdr/signal_macros.h"
#include "hdr/types/stack_t.h"
-#include "src/__support/OSUtil/syscall.h"
+#include "src/__support/OSUtil/linux/syscall_wrappers/sigaltstack.h"
#include "src/__support/common.h"
#include "src/__support/libc_errno.h"
#include "src/__support/macros/config.h"
-#include <sys/syscall.h>
-
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(int, sigaltstack,
@@ -39,9 +38,9 @@ LLVM_LIBC_FUNCTION(int, sigaltstack,
}
}
- int ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_sigaltstack, ss, oss);
- if (ret < 0) {
- libc_errno = -ret;
+ auto result = linux_syscalls::sigaltstack(ss, oss);
+ if (!result) {
+ libc_errno = result.error();
return -1;
}
return 0;
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index cb9e218e22e80..22a1a659adeed 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -721,6 +721,12 @@ libc_support_library(
],
)
+libc_support_library(
+ name = "llvm_libc_types_stack_t",
+ hdrs = ["include/llvm-libc-types/stack_t.h"],
+ deps = [":llvm_libc_types_size_t"],
+)
+
libc_support_library(
name = "llvm_libc_types_struct_sigaction",
hdrs = ["include/llvm-libc-types/struct_sigaction.h"],
@@ -1355,6 +1361,15 @@ libc_support_library(
}),
)
+libc_support_library(
+ name = "types_stack_t",
+ hdrs = ["hdr/types/stack_t.h"],
+ deps = select({
+ ":full_build": [":llvm_libc_types_stack_t"],
+ "//conditions:default": [],
+ }),
+)
+
libc_support_library(
name = "types_struct_sigaction",
hdrs = ["hdr/types/struct_sigaction.h"],
@@ -3360,6 +3375,22 @@ libc_support_library(
],
)
+libc_support_library(
+ name = "__support_osutil_linux_syscall_wrappers_sigaltstack",
+ hdrs = ["src/__support/OSUtil/linux/syscall_wrappers/sigaltstack.h"],
+ target_compatible_with = select({
+ "@platforms//os:linux": [],
+ "//conditions:default": ["@platforms//:incompatible"],
+ }),
+ deps = [
+ ":__support_common",
+ ":__support_error_or",
+ ":__support_macros_config",
+ ":__support_osutil_syscall",
+ ":types_stack_t",
+ ],
+)
+
libc_support_library(
name = "__support_osutil_linux_syscall_wrappers_socket",
hdrs = ["src/__support/OSUtil/linux/syscall_wrappers/socket.h"],
@@ -19141,6 +19172,26 @@ libc_function(
],
)
+libc_function(
+ name = "sigaltstack",
+ srcs = ["src/signal/linux/sigaltstack.cpp"],
+ hdrs = ["src/signal/sigaltstack.h"],
+ target_compatible_with = select({
+ "@platforms//os:linux": [],
+ "//conditions:default": ["@platforms//:incompatible"],
+ }),
+ deps = [
+ ":__support_common",
+ ":__support_libc_errno",
+ ":__support_macros_config",
+ ":__support_osutil_linux_syscall_wrappers_sigaltstack",
+ ":errno",
+ ":hdr_errno_macros",
+ ":hdr_signal_macros",
+ ":types_stack_t",
+ ],
+)
+
libc_function(
name = "signal",
srcs = ["src/signal/linux/signal.cpp"],
More information about the libc-commits
mailing list