[llvm-branch-commits] [libc] [llvm] [libc] Use a syscall wrapper for prctl (PR #243787)
Connector Switch via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Wed Nov 18 02:26:58 PST 2026
https://github.com/c8ef created https://github.com/llvm/llvm-project/pull/243787
This PR move prctl behind the centralized syscall wrappers, following libc/docs/dev/syscall_wrapper_refactor.md.
>From bc084b209dd04cd0b22405a8e00d250411bc5095 Mon Sep 17 00:00:00 2001
From: c8ef <c8ef at outlook.com>
Date: Wed, 18 Nov 2026 18:25:08 +0800
Subject: [PATCH] [libc] Use a syscall wrapper for prctl
---
libc/src/sys/prctl/linux/CMakeLists.txt | 6 +++--
libc/src/sys/prctl/linux/prctl.cpp | 22 +++++++++++--------
.../libc/src/sys/prctl/BUILD.bazel | 2 +-
3 files changed, 18 insertions(+), 12 deletions(-)
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 llvm-branch-commits
mailing list