[libc-commits] [libc] [libc][NFC] wrap prlimit64 and refactor getrlimit/setrlimit (PR #204306)
Jeff Bailey via libc-commits
libc-commits at lists.llvm.org
Wed Jun 17 02:59:24 PDT 2026
https://github.com/kaladron updated https://github.com/llvm/llvm-project/pull/204306
>From e7ddb7a112804e659f2d4003cd461b6b993d807b Mon Sep 17 00:00:00 2001
From: Jeff Bailey <jbailey at raspberryginger.com>
Date: Wed, 17 Jun 2026 08:29:32 +0100
Subject: [PATCH 1/3] [libc][NFC] wrap prlimit64 and refactor
getrlimit/setrlimit
Assisted-by: Automated tooling, human reviewed.
---
.../linux/syscall_wrappers/CMakeLists.txt | 13 ++++++++
.../OSUtil/linux/syscall_wrappers/prlimit.h | 30 +++++++++++++++++++
libc/src/sys/resource/linux/CMakeLists.txt | 6 ++--
libc/src/sys/resource/linux/getrlimit.cpp | 10 +++----
libc/src/sys/resource/linux/setrlimit.cpp | 10 +++----
5 files changed, 53 insertions(+), 16 deletions(-)
create mode 100644 libc/src/__support/OSUtil/linux/syscall_wrappers/prlimit.h
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt b/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
index 36af7ffa898f1..d558abb8f6b5d 100644
--- a/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
@@ -759,3 +759,16 @@ add_header_library(
libc.hdr.types.off_t
libc.include.sys_syscall
)
+
+add_header_library(
+ prlimit
+ HDRS
+ prlimit.h
+ DEPENDS
+ 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..961b3a95a63cc
--- /dev/null
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/prlimit.h
@@ -0,0 +1,30 @@
+//===-- Implementation header for prlimit -----------------------*- C++ -*-===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_LINUX_SYSCALL_WRAPPERS_PRLIMIT_H
+#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_LINUX_SYSCALL_WRAPPERS_PRLIMIT_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(int pid, int resource, const void *new_limit,
+ void *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..1b8f54ca47a93 100644
--- a/libc/src/sys/resource/linux/getrlimit.cpp
+++ b/libc/src/sys/resource/linux/getrlimit.cpp
@@ -9,19 +9,17 @@
#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..0e4396a1ac9ad 100644
--- a/libc/src/sys/resource/linux/setrlimit.cpp
+++ b/libc/src/sys/resource/linux/setrlimit.cpp
@@ -9,19 +9,17 @@
#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;
>From cf9dac4cc4d9b590c449c99427c8f57b7eb4635f Mon Sep 17 00:00:00 2001
From: Jeff Bailey <jbailey at raspberryginger.com>
Date: Wed, 17 Jun 2026 10:33:19 +0100
Subject: [PATCH 2/3] [libc][NFC] use correct types in prlimit wrapper
Assisted-by: Automated tooling, human reviewed.
---
.../__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt | 2 ++
libc/src/__support/OSUtil/linux/syscall_wrappers/prlimit.h | 7 +++++--
2 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt b/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
index d558abb8f6b5d..731e5a1d462ab 100644
--- a/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
@@ -765,6 +765,8 @@ add_header_library(
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
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/prlimit.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/prlimit.h
index 961b3a95a63cc..0b5afe09a6750 100644
--- a/libc/src/__support/OSUtil/linux/syscall_wrappers/prlimit.h
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/prlimit.h
@@ -9,6 +9,8 @@
#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"
@@ -18,8 +20,9 @@
namespace LIBC_NAMESPACE_DECL {
namespace linux_syscalls {
-LIBC_INLINE ErrorOr<int> prlimit(int pid, int resource, const void *new_limit,
- void *old_limit) {
+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);
}
>From 2421c8d6b46f614eae6fbd16d757de3e3b811223 Mon Sep 17 00:00:00 2001
From: Jeff Bailey <jbailey at raspberryginger.com>
Date: Wed, 17 Jun 2026 10:58:47 +0100
Subject: [PATCH 3/3] [libc][NFC] fix license header style in prlimit and
rlimit entrypoints
Assisted-by: Automated tooling, human reviewed.
---
libc/src/__support/OSUtil/linux/syscall_wrappers/prlimit.h | 7 ++++++-
libc/src/sys/resource/linux/getrlimit.cpp | 7 ++++++-
libc/src/sys/resource/linux/setrlimit.cpp | 7 ++++++-
3 files changed, 18 insertions(+), 3 deletions(-)
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/prlimit.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/prlimit.h
index 0b5afe09a6750..8eb436b82c431 100644
--- a/libc/src/__support/OSUtil/linux/syscall_wrappers/prlimit.h
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/prlimit.h
@@ -1,10 +1,15 @@
-//===-- Implementation header for prlimit -----------------------*- C++ -*-===//
+//===----------------------------------------------------------------------===//
//
// 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
diff --git a/libc/src/sys/resource/linux/getrlimit.cpp b/libc/src/sys/resource/linux/getrlimit.cpp
index 1b8f54ca47a93..1d8b58b8dd209 100644
--- a/libc/src/sys/resource/linux/getrlimit.cpp
+++ b/libc/src/sys/resource/linux/getrlimit.cpp
@@ -1,10 +1,15 @@
-//===-- 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"
diff --git a/libc/src/sys/resource/linux/setrlimit.cpp b/libc/src/sys/resource/linux/setrlimit.cpp
index 0e4396a1ac9ad..24ccd4cb24eff 100644
--- a/libc/src/sys/resource/linux/setrlimit.cpp
+++ b/libc/src/sys/resource/linux/setrlimit.cpp
@@ -1,10 +1,15 @@
-//===-- 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"
More information about the libc-commits
mailing list