[libc-commits] [libc] [libc] Refactor kill syscall into syscall_wrappers (PR #237798)
Anshitha Yeruva via libc-commits
libc-commits at lists.llvm.org
Sun Nov 1 17:06:42 PST 2026
https://github.com/anshithayeruva updated https://github.com/llvm/llvm-project/pull/237798
>From fe7e2e6e59772e0c6e6ff2beca70abf0a83f7438 Mon Sep 17 00:00:00 2001
From: anshithayeruva <anshithayeruva18 at gmail.com>
Date: Mon, 2 Nov 2026 05:21:08 +0530
Subject: [PATCH 1/2] [libc] Refactor kill syscall into syscall_wrappers
---
.../linux/syscall_wrappers/CMakeLists.txt | 13 +++++++
.../OSUtil/linux/syscall_wrappers/kill.h | 35 +++++++++++++++++++
libc/src/signal/linux/CMakeLists.txt | 7 ++--
libc/src/signal/linux/kill.cpp | 24 ++++++-------
4 files changed, 64 insertions(+), 15 deletions(-)
create mode 100644 libc/src/__support/OSUtil/linux/syscall_wrappers/kill.h
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt b/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
index 05eb6f0fa6f776..f5e13ff25ce680 100644
--- a/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
@@ -1844,6 +1844,19 @@ add_header_library(
libc.include.sys_syscall
)
+add_header_library(
+ kill
+ HDRS
+ kill.h
+ DEPENDS
+ libc.hdr.types.pid_t
+ libc.src.__support.OSUtil.osutil
+ libc.src.__support.common
+ libc.src.__support.error_or
+ libc.src.__support.macros.config
+ libc.include.sys_syscall
+)
+
add_header_library(
tgkill
HDRS
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/kill.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/kill.h
new file mode 100644
index 00000000000000..9c8707626e1f47
--- /dev/null
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/kill.h
@@ -0,0 +1,35 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 kill.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_KILL_H
+#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_KILL_H
+
+#include "hdr/types/pid_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> kill(pid_t pid, int sig) {
+ return syscall_checked<int>(SYS_kill, pid, sig);
+}
+
+} // namespace linux_syscalls
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_KILL_H
+
diff --git a/libc/src/signal/linux/CMakeLists.txt b/libc/src/signal/linux/CMakeLists.txt
index 77898cf9aab636..b0d19e86b150b7 100644
--- a/libc/src/signal/linux/CMakeLists.txt
+++ b/libc/src/signal/linux/CMakeLists.txt
@@ -23,9 +23,10 @@ add_entrypoint_object(
../kill.h
DEPENDS
libc.hdr.types.pid_t
- libc.src.errno.errno
- libc.include.sys_syscall
- libc.src.__support.OSUtil.osutil
+ libc.src.__support.OSUtil.linux.syscall_wrappers.kill
+ libc.src.__support.common
+ libc.src.__support.libc_errno
+ libc.src.__support.macros.config
)
add_entrypoint_object(
diff --git a/libc/src/signal/linux/kill.cpp b/libc/src/signal/linux/kill.cpp
index 732ee1d353036e..9149d771f91f34 100644
--- a/libc/src/signal/linux/kill.cpp
+++ b/libc/src/signal/linux/kill.cpp
@@ -1,33 +1,33 @@
-//===-- Linux implementation of kill --------------------------------------===//
+//===----------------------------------------------------------------------===//
//
// 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
+/// Linux implementation of kill.
+///
+//===----------------------------------------------------------------------===//
#include "src/signal/kill.h"
-#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
+#include "hdr/types/pid_t.h"
+#include "src/__support/OSUtil/linux/syscall_wrappers/kill.h"
#include "src/__support/common.h"
#include "src/__support/libc_errno.h"
#include "src/__support/macros/config.h"
-#include <sys/syscall.h> // For syscall numbers.
-
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(int, kill, (pid_t pid, int sig)) {
- int ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_kill, pid, sig);
-
- // A negative return value indicates an error with the magnitude of the
- // value being the error code.
- if (ret != 0) {
- libc_errno = (ret > 0 ? ret : -ret);
+ auto result = linux_syscalls::kill(pid, sig);
+ if (!result.has_value()) {
+ libc_errno = result.error();
return -1;
}
-
- return ret; // always 0
+ return result.value();
}
} // namespace LIBC_NAMESPACE_DECL
>From 5fde484e5b0c18cdb43282baa3945f44448257ed Mon Sep 17 00:00:00 2001
From: anshithayeruva <anshithayeruva18 at gmail.com>
Date: Mon, 2 Nov 2026 06:36:24 +0530
Subject: [PATCH 2/2] [libc] Fix clang-format in kill syscall wrapper
---
libc/src/__support/OSUtil/linux/syscall_wrappers/kill.h | 1 -
1 file changed, 1 deletion(-)
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/kill.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/kill.h
index 9c8707626e1f47..198adcf9e8b2c6 100644
--- a/libc/src/__support/OSUtil/linux/syscall_wrappers/kill.h
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/kill.h
@@ -32,4 +32,3 @@ LIBC_INLINE ErrorOr<int> kill(pid_t pid, int sig) {
} // namespace LIBC_NAMESPACE_DECL
#endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_KILL_H
-
More information about the libc-commits
mailing list