[llvm-branch-commits] [libc] [llvm] [libc] Use a syscall wrapper for remap_file_pages (PR #240074)
Connector Switch via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Sat Nov 7 16:20:35 PST 2026
https://github.com/c8ef created https://github.com/llvm/llvm-project/pull/240074
This PR move remap_file_pages behind the centralized syscall wrappers, following libc/docs/dev/syscall_wrapper_refactor.md.
>From 27cf3e04038bdc1baeafec9d1da73af8333e3d31 Mon Sep 17 00:00:00 2001
From: c8ef <c8ef at outlook.com>
Date: Sun, 8 Nov 2026 08:20:06 +0800
Subject: [PATCH] [libc] Use a syscall wrapper for remap_file_pages
This PR move remap_file_pages behind the centralized syscall wrappers, following libc/docs/dev/syscall_wrapper_refactor.md.
---
.../linux/syscall_wrappers/CMakeLists.txt | 13 ++++++
.../linux/syscall_wrappers/remap_file_pages.h | 41 +++++++++++++++++++
libc/src/sys/mman/linux/CMakeLists.txt | 8 ++--
libc/src/sys/mman/linux/remap_file_pages.cpp | 27 +++++-------
.../llvm-project-overlay/libc/BUILD.bazel | 19 ++++++++-
5 files changed, 87 insertions(+), 21 deletions(-)
create mode 100644 libc/src/__support/OSUtil/linux/syscall_wrappers/remap_file_pages.h
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt b/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
index d89bb6d8df7b14..65b0aaa04a4629 100644
--- a/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
@@ -1718,6 +1718,19 @@ add_header_library(
libc.src.__support.macros.config
)
+add_header_library(
+ remap_file_pages
+ HDRS
+ remap_file_pages.h
+ DEPENDS
+ libc.hdr.types.size_t
+ libc.include.sys_syscall
+ libc.src.__support.OSUtil.osutil
+ libc.src.__support.common
+ libc.src.__support.error_or
+ libc.src.__support.macros.config
+)
+
add_header_library(
rename
HDRS
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/remap_file_pages.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/remap_file_pages.h
new file mode 100644
index 00000000000000..1a56a6655f439f
--- /dev/null
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/remap_file_pages.h
@@ -0,0 +1,41 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 remap_file_pages.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_REMAP_FILE_PAGES_H
+#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_REMAP_FILE_PAGES_H
+
+#include "hdr/types/size_t.h"
+#include "src/__support/OSUtil/linux/syscall.h"
+#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> remap_file_pages(void *addr, size_t size, int prot,
+ size_t pgoff, int flags) {
+#ifdef SYS_remap_file_pages
+ return syscall_checked<int>(SYS_remap_file_pages, addr, size, prot, pgoff,
+ flags);
+#else
+#error "remap_file_pages syscall is not available."
+#endif
+}
+
+} // namespace linux_syscalls
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_REMAP_FILE_PAGES_H
diff --git a/libc/src/sys/mman/linux/CMakeLists.txt b/libc/src/sys/mman/linux/CMakeLists.txt
index c13d482e50600e..0cdb32ac696b29 100644
--- a/libc/src/sys/mman/linux/CMakeLists.txt
+++ b/libc/src/sys/mman/linux/CMakeLists.txt
@@ -274,9 +274,11 @@ add_entrypoint_object(
HDRS
../remap_file_pages.h
DEPENDS
- libc.include.sys_mman
- libc.include.sys_syscall
- libc.src.__support.OSUtil.osutil
+ libc.hdr.types.size_t
+ libc.src.__support.OSUtil.linux.syscall_wrappers.remap_file_pages
+ libc.src.__support.common
+ libc.src.__support.libc_errno
+ libc.src.__support.macros.config
libc.src.errno.errno
)
diff --git a/libc/src/sys/mman/linux/remap_file_pages.cpp b/libc/src/sys/mman/linux/remap_file_pages.cpp
index 58ae4017f62854..bf42c95751ed9e 100644
--- a/libc/src/sys/mman/linux/remap_file_pages.cpp
+++ b/libc/src/sys/mman/linux/remap_file_pages.cpp
@@ -1,39 +1,34 @@
-//===------- Linux implementation of the remap_file_pages 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 remap_file_pages.
+///
+//===----------------------------------------------------------------------===//
#include "src/sys/mman/remap_file_pages.h"
-#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
+#include "src/__support/OSUtil/linux/syscall_wrappers/remap_file_pages.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, remap_file_pages,
(void *addr, size_t size, int prot, size_t pgoff,
int flags)) {
-#ifdef SYS_remap_file_pages
- int ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_remap_file_pages,
- reinterpret_cast<long>(addr),
- size, prot, pgoff, flags);
-#else
-#error "remap_file_pages syscall is not available."
-#endif
-
- // A negative return value indicates an error with the magnitude of the
- // value being the error code.
- if (ret < 0) {
- libc_errno = -ret;
+ auto result =
+ linux_syscalls::remap_file_pages(addr, size, prot, pgoff, flags);
+ if (!result) {
+ libc_errno = result.error();
return -1;
}
-
return 0;
}
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index c50e9193ac4248..c22d9cc7202dd5 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -2952,6 +2952,22 @@ libc_support_library(
],
)
+libc_support_library(
+ name = "__support_osutil_linux_syscall_wrappers_remap_file_pages",
+ hdrs = ["src/__support/OSUtil/linux/syscall_wrappers/remap_file_pages.h"],
+ target_compatible_with = select({
+ "@platforms//os:linux": [],
+ "//conditions:default": ["@platforms//:incompatible"],
+ }),
+ deps = [
+ ":__support_common",
+ ":__support_error_or",
+ ":__support_macros_config",
+ ":__support_osutil_syscall",
+ ":types_size_t",
+ ],
+)
+
libc_support_library(
name = "__support_osutil_linux_syscall_wrappers_rename",
hdrs = ["src/__support/OSUtil/linux/syscall_wrappers/rename.h"],
@@ -20012,9 +20028,8 @@ libc_function(
":__support_common",
":__support_libc_errno",
":__support_macros_config",
- ":__support_osutil_syscall",
+ ":__support_osutil_linux_syscall_wrappers_remap_file_pages",
":errno",
- ":hdr_sys_mman_macros",
":types_size_t",
],
)
More information about the llvm-branch-commits
mailing list