[libc-commits] [libc] ed93dc8 - [libc] Use a syscall wrapper for prctl (#243787)
via libc-commits
libc-commits at lists.llvm.org
Sat Nov 28 22:41:30 PST 2026
Author: Connector Switch
Date: 2026-11-29T14:41:23+08:00
New Revision: ed93dc8f7a98c7dfdbf6f203bf72e6e9a82cde3e
URL: https://github.com/llvm/llvm-project/commit/ed93dc8f7a98c7dfdbf6f203bf72e6e9a82cde3e
DIFF: https://github.com/llvm/llvm-project/commit/ed93dc8f7a98c7dfdbf6f203bf72e6e9a82cde3e.diff
LOG: [libc] Use a syscall wrapper for prctl (#243787)
This PR move prctl behind the centralized syscall wrappers, following
libc/docs/dev/syscall_wrapper_refactor.md.
Added:
Modified:
libc/src/sys/prctl/linux/CMakeLists.txt
libc/src/sys/prctl/linux/prctl.cpp
utils/bazel/llvm-project-overlay/libc/src/sys/prctl/BUILD.bazel
Removed:
################################################################################
diff --git a/libc/src/sys/prctl/linux/CMakeLists.txt b/libc/src/sys/prctl/linux/CMakeLists.txt
index 735d22f83e615e..016dcac0a7e11c 100644
--- a/libc/src/sys/prctl/linux/CMakeLists.txt
+++ b/libc/src/sys/prctl/linux/CMakeLists.txt
@@ -5,7 +5,9 @@ add_entrypoint_object(
HDRS
../prctl.h
DEPENDS
- libc.include.sys_syscall
- libc.src.__support.OSUtil.osutil
+ libc.src.__support.OSUtil.linux.syscall_wrappers.prctl
+ libc.src.__support.common
+ libc.src.__support.libc_errno
+ libc.src.__support.macros.config
libc.src.errno.errno
)
diff --git a/libc/src/sys/prctl/linux/prctl.cpp b/libc/src/sys/prctl/linux/prctl.cpp
index b2e6765631ec75..d20b0227da82c0 100644
--- a/libc/src/sys/prctl/linux/prctl.cpp
+++ b/libc/src/sys/prctl/linux/prctl.cpp
@@ -1,34 +1,38 @@
-//===---------- Linux implementation of the prctl function ----------------===//
+//===----------------------------------------------------------------------===//
//
// 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 prctl.
+///
+//===----------------------------------------------------------------------===//
#include "src/sys/prctl/prctl.h"
-#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
+#include "src/__support/OSUtil/linux/syscall_wrappers/prctl.h"
+#include "src/__support/common.h"
#include "src/__support/libc_errno.h"
#include "src/__support/macros/config.h"
#include <stdarg.h>
-#include <sys/syscall.h> // For syscall numbers.
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(int, prctl, (int option, ...)) {
va_list vargs;
va_start(vargs, option);
- // Try to consume (and pass to syscall_impl) the maximum possible number of
+ // Try to consume (and pass to the syscall) the maximum possible number of
// arguments, even though for some "option" values only few will be provided.
unsigned long arg2 = va_arg(vargs, unsigned long);
unsigned long arg3 = va_arg(vargs, unsigned long);
unsigned long arg4 = va_arg(vargs, unsigned long);
unsigned long arg5 = va_arg(vargs, unsigned long);
va_end(vargs);
- long ret =
- LIBC_NAMESPACE::syscall_impl(SYS_prctl, option, arg2, arg3, arg4, arg5);
+ auto result = linux_syscalls::prctl(option, arg2, arg3, arg4, arg5);
// The manpage states that "... return the nonnegative values described
// above. All other option values return 0 on success. On error,
// -1 is returned, and errno is set to indicate the error."
@@ -36,11 +40,11 @@ LLVM_LIBC_FUNCTION(int, prctl, (int option, ...)) {
// (https://github.com/torvalds/linux/blob/bee0e7762ad2c6025b9f5245c040fcc36ef2bde8/kernel/sys.c#L2442),
// return value from the syscall is set to 0 on default so we do not need to
// set the value on success manually.
- if (ret < 0) {
- libc_errno = static_cast<int>(-ret);
+ if (!result) {
+ libc_errno = result.error();
return -1;
}
- return static_cast<int>(ret);
+ return static_cast<int>(result.value());
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/utils/bazel/llvm-project-overlay/libc/src/sys/prctl/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/src/sys/prctl/BUILD.bazel
index e94c60b40da72b..790fa3f770dba0 100644
--- a/utils/bazel/llvm-project-overlay/libc/src/sys/prctl/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/src/sys/prctl/BUILD.bazel
@@ -26,7 +26,7 @@ libc_function(
deps = [
"//libc/src/__support:common",
"//libc/src/__support:libc_errno",
- "//libc/src/__support/OSUtil:syscall",
+ "//libc/src/__support/OSUtil/linux/syscall_wrappers:prctl",
"//libc/src/__support/macros:config",
"//libc/src/errno",
],
More information about the libc-commits
mailing list