[libc-commits] [libc] [libc] Refactor kill syscall into syscall_wrappers (PR #237798)
via libc-commits
libc-commits at lists.llvm.org
Sun Nov 1 15:55:44 PST 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libc
Author: Anshitha Yeruva (anshithayeruva)
<details>
<summary>Changes</summary>
This patch refactors the `kill` Linux syscall into a centralized header wrapper under `src/__support/OSUtil/linux/syscall_wrappers/kill.h` per the syscall wrapper refactoring guidelines.
Prerequisite for #<!-- -->237561.
---
Full diff: https://github.com/llvm/llvm-project/pull/237798.diff
4 Files Affected:
- (modified) libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt (+13)
- (added) libc/src/__support/OSUtil/linux/syscall_wrappers/kill.h (+35)
- (modified) libc/src/signal/linux/CMakeLists.txt (+4-3)
- (modified) libc/src/signal/linux/kill.cpp (+12-12)
``````````diff
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
``````````
</details>
https://github.com/llvm/llvm-project/pull/237798
More information about the libc-commits
mailing list