[libc-commits] [libc] f63d8d6 - [libc][NFC] wrap prlimit64 and refactor getrlimit/setrlimit (#204306)
via libc-commits
libc-commits at lists.llvm.org
Wed Jun 17 03:36:46 PDT 2026
Author: Jeff Bailey
Date: 2026-06-17T11:36:41+01:00
New Revision: f63d8d67a3ff11d06607f2f0cfedfd88d877e9de
URL: https://github.com/llvm/llvm-project/commit/f63d8d67a3ff11d06607f2f0cfedfd88d877e9de
DIFF: https://github.com/llvm/llvm-project/commit/f63d8d67a3ff11d06607f2f0cfedfd88d877e9de.diff
LOG: [libc][NFC] wrap prlimit64 and refactor getrlimit/setrlimit (#204306)
Assisted-by: Automated tooling, human reviewed.
Added:
libc/src/__support/OSUtil/linux/syscall_wrappers/prlimit.h
Modified:
libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
libc/src/sys/resource/linux/CMakeLists.txt
libc/src/sys/resource/linux/getrlimit.cpp
libc/src/sys/resource/linux/setrlimit.cpp
Removed:
################################################################################
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt b/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
index 36af7ffa898f1..731e5a1d462ab 100644
--- a/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
@@ -759,3 +759,18 @@ add_header_library(
libc.hdr.types.off_t
libc.include.sys_syscall
)
+
+add_header_library(
+ prlimit
+ HDRS
+ prlimit.h
+ DEPENDS
+ libc.hdr.types.pid_t
+ libc.hdr.types.struct_rlimit
+ libc.src.__support.OSUtil.osutil
+ libc.src.__support.common
+ libc.src.__support.error_or
+ libc.src.__support.macros.config
+ libc.include.sys_syscall
+)
+
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/prlimit.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/prlimit.h
new file mode 100644
index 0000000000000..8eb436b82c431
--- /dev/null
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/prlimit.h
@@ -0,0 +1,38 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 prlimit64.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_LINUX_SYSCALL_WRAPPERS_PRLIMIT_H
+#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_LINUX_SYSCALL_WRAPPERS_PRLIMIT_H
+
+#include "hdr/types/pid_t.h"
+#include "hdr/types/struct_rlimit.h"
+#include "src/__support/OSUtil/linux/syscall.h" // For 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> prlimit(pid_t pid, int resource,
+ const struct rlimit *new_limit,
+ struct rlimit *old_limit) {
+ return syscall_checked<int>(SYS_prlimit64, pid, resource, new_limit,
+ old_limit);
+}
+
+} // namespace linux_syscalls
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_LINUX_SYSCALL_WRAPPERS_PRLIMIT_H
diff --git a/libc/src/sys/resource/linux/CMakeLists.txt b/libc/src/sys/resource/linux/CMakeLists.txt
index 9f0fdad3b0fdf..ac59621f96f13 100644
--- a/libc/src/sys/resource/linux/CMakeLists.txt
+++ b/libc/src/sys/resource/linux/CMakeLists.txt
@@ -7,8 +7,7 @@ add_entrypoint_object(
DEPENDS
libc.hdr.types.struct_rlimit
libc.include.sys_resource
- libc.include.sys_syscall
- libc.src.__support.OSUtil.osutil
+ libc.src.__support.OSUtil.linux.syscall_wrappers.prlimit
libc.src.errno.errno
)
@@ -21,7 +20,6 @@ add_entrypoint_object(
DEPENDS
libc.hdr.types.struct_rlimit
libc.include.sys_resource
- libc.include.sys_syscall
- libc.src.__support.OSUtil.osutil
+ libc.src.__support.OSUtil.linux.syscall_wrappers.prlimit
libc.src.errno.errno
)
diff --git a/libc/src/sys/resource/linux/getrlimit.cpp b/libc/src/sys/resource/linux/getrlimit.cpp
index a3234ebf4f90b..1d8b58b8dd209 100644
--- a/libc/src/sys/resource/linux/getrlimit.cpp
+++ b/libc/src/sys/resource/linux/getrlimit.cpp
@@ -1,27 +1,30 @@
-//===-- Linux implementation of getrlimit ---------------------------------===//
+//===----------------------------------------------------------------------===//
//
// 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 getrlimit.
+///
+//===----------------------------------------------------------------------===//
#include "src/sys/resource/getrlimit.h"
#include "hdr/types/struct_rlimit.h"
-#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
+#include "src/__support/OSUtil/linux/syscall_wrappers/prlimit.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, getrlimit, (int res, struct rlimit *limits)) {
- int ret =
- LIBC_NAMESPACE::syscall_impl<int>(SYS_prlimit64, 0, res, nullptr, limits);
- if (ret < 0) {
- libc_errno = -ret;
+ auto result = linux_syscalls::prlimit(0, res, nullptr, limits);
+ if (!result) {
+ libc_errno = result.error();
return -1;
}
return 0;
diff --git a/libc/src/sys/resource/linux/setrlimit.cpp b/libc/src/sys/resource/linux/setrlimit.cpp
index e2c2b379e7087..24ccd4cb24eff 100644
--- a/libc/src/sys/resource/linux/setrlimit.cpp
+++ b/libc/src/sys/resource/linux/setrlimit.cpp
@@ -1,27 +1,30 @@
-//===-- Linux implementation of setrlimit ---------------------------------===//
+//===----------------------------------------------------------------------===//
//
// 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 setrlimit.
+///
+//===----------------------------------------------------------------------===//
#include "src/sys/resource/setrlimit.h"
#include "hdr/types/struct_rlimit.h"
-#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
+#include "src/__support/OSUtil/linux/syscall_wrappers/prlimit.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, setrlimit, (int res, const struct rlimit *limits)) {
- int ret =
- LIBC_NAMESPACE::syscall_impl<int>(SYS_prlimit64, 0, res, limits, nullptr);
- if (ret < 0) {
- libc_errno = -ret;
+ auto result = linux_syscalls::prlimit(0, res, limits, nullptr);
+ if (!result) {
+ libc_errno = result.error();
return -1;
}
return 0;
More information about the libc-commits
mailing list