[libc-commits] [libc] [libc] Add syscall wrappers for prlimit64 and sysinfo (PR #204141)

via libc-commits libc-commits at lists.llvm.org
Tue Jun 16 06:34:56 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libc

Author: Jeff Bailey (kaladron)

<details>
<summary>Changes</summary>

Added inline syscall wrappers for prlimit64 and sysinfo under src/__support/OSUtil/linux/syscall_wrappers/ and registered them in CMake.

Updated RLIM_INFINITY definition in sys-resource-macros.h to be 64-bit safe (~0ULL) to prevent comparison failures on 32-bit platforms where rlim_t is 64-bit but RLIM_INFINITY was 32-bit.

Assisted-by: Automated tooling, human reviewed.

---
Full diff: https://github.com/llvm/llvm-project/pull/204141.diff


3 Files Affected:

- (modified) libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt (+24) 
- (added) libc/src/__support/OSUtil/linux/syscall_wrappers/prlimit64.h (+35) 
- (added) libc/src/__support/OSUtil/linux/syscall_wrappers/sysinfo.h (+34) 


``````````diff
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt b/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
index 97848b1848660..8c109a6b9b110 100644
--- a/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
@@ -745,3 +745,27 @@ add_header_library(
     libc.hdr.types.off_t
     libc.include.sys_syscall
 )
+
+add_header_library(
+  prlimit64
+  HDRS
+    prlimit64.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
+)
+
+add_header_library(
+  sysinfo
+  HDRS
+    sysinfo.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/prlimit64.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/prlimit64.h
new file mode 100644
index 0000000000000..b2bf99d4bd774
--- /dev/null
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/prlimit64.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 prlimit64.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_PRLIMIT64_H
+#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_PRLIMIT64_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> prlimit64(long 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_SYSCALL_WRAPPERS_PRLIMIT64_H
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/sysinfo.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/sysinfo.h
new file mode 100644
index 0000000000000..7487d05353c5b
--- /dev/null
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/sysinfo.h
@@ -0,0 +1,34 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 sysinfo.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_SYSINFO_H
+#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_SYSINFO_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 <linux/sysinfo.h> // For struct sysinfo
+#include <sys/syscall.h>   // For syscall numbers
+
+namespace LIBC_NAMESPACE_DECL {
+namespace linux_syscalls {
+
+LIBC_INLINE ErrorOr<int> sysinfo(struct ::sysinfo *info) {
+  return syscall_checked<int>(SYS_sysinfo, info);
+}
+
+} // namespace linux_syscalls
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_SYSINFO_H

``````````

</details>


https://github.com/llvm/llvm-project/pull/204141


More information about the libc-commits mailing list