[llvm-branch-commits] [libc] [llvm] [libc] Use a syscall wrapper for munlock (PR #243785)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Wed Nov 18 02:27:31 PST 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libc
Author: Connector Switch (c8ef)
<details>
<summary>Changes</summary>
This PR move munlock behind the centralized syscall wrappers, following libc/docs/dev/syscall_wrapper_refactor.md.
---
Full diff: https://github.com/llvm/llvm-project/pull/243785.diff
6 Files Affected:
- (modified) libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt (+13)
- (added) libc/src/__support/OSUtil/linux/syscall_wrappers/munlock.h (+34)
- (modified) libc/src/sys/mman/linux/CMakeLists.txt (+5-3)
- (modified) libc/src/sys/mman/linux/munlock.cpp (+11-7)
- (modified) utils/bazel/llvm-project-overlay/libc/src/__support/OSUtil/linux/syscall_wrappers/BUILD.bazel (+16)
- (modified) utils/bazel/llvm-project-overlay/libc/src/sys/mman/BUILD.bazel (+1-2)
``````````diff
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt b/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
index c332cf2cb6582..425033759ae99 100644
--- a/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
@@ -1150,6 +1150,19 @@ add_header_library(
libc.src.__support.macros.config
)
+add_header_library(
+ munlock
+ HDRS
+ munlock.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(
munmap
HDRS
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/munlock.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/munlock.h
new file mode 100644
index 0000000000000..b803b8c497932
--- /dev/null
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/munlock.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 munlock.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_MUNLOCK_H
+#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_MUNLOCK_H
+
+#include "hdr/types/size_t.h"
+#include "src/__support/OSUtil/linux/syscall.h" // 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> munlock(const void *addr, size_t len) {
+ return syscall_checked<int>(SYS_munlock, addr, len);
+}
+
+} // namespace linux_syscalls
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_MUNLOCK_H
diff --git a/libc/src/sys/mman/linux/CMakeLists.txt b/libc/src/sys/mman/linux/CMakeLists.txt
index 4180ba24ce7aa..38b3372b7c951 100644
--- a/libc/src/sys/mman/linux/CMakeLists.txt
+++ b/libc/src/sys/mman/linux/CMakeLists.txt
@@ -152,9 +152,11 @@ add_entrypoint_object(
HDRS
../munlock.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.munlock
+ 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/munlock.cpp b/libc/src/sys/mman/linux/munlock.cpp
index 9638949f5fcb3..225ff3ba198bb 100644
--- a/libc/src/sys/mman/linux/munlock.cpp
+++ b/libc/src/sys/mman/linux/munlock.cpp
@@ -1,25 +1,29 @@
-//===---------- Linux implementation of the munlock 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 munlock.
+///
+//===----------------------------------------------------------------------===//
#include "src/sys/mman/munlock.h"
-#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
-
+#include "src/__support/OSUtil/linux/syscall_wrappers/munlock.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, munlock, (const void *addr, size_t len)) {
- long ret = syscall_impl(SYS_munlock, cpp::bit_cast<long>(addr), len);
- if (ret < 0) {
- libc_errno = static_cast<int>(-ret);
+ auto result = linux_syscalls::munlock(addr, len);
+ if (!result) {
+ libc_errno = result.error();
return -1;
}
return 0;
diff --git a/utils/bazel/llvm-project-overlay/libc/src/__support/OSUtil/linux/syscall_wrappers/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/src/__support/OSUtil/linux/syscall_wrappers/BUILD.bazel
index b9cb62558e129..d32217d4a7d72 100644
--- a/utils/bazel/llvm-project-overlay/libc/src/__support/OSUtil/linux/syscall_wrappers/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/src/__support/OSUtil/linux/syscall_wrappers/BUILD.bazel
@@ -1626,6 +1626,22 @@ libc_support_library(
],
)
+libc_support_library(
+ name = "munlock",
+ hdrs = ["munlock.h"],
+ target_compatible_with = select({
+ "@platforms//os:linux": [],
+ "//conditions:default": ["@platforms//:incompatible"],
+ }),
+ deps = [
+ "//libc/hdr/types:size_t",
+ "//libc/src/__support:common",
+ "//libc/src/__support:error_or",
+ "//libc/src/__support/OSUtil:syscall",
+ "//libc/src/__support/macros:config",
+ ],
+)
+
libc_support_library(
name = "munmap",
hdrs = ["munmap.h"],
diff --git a/utils/bazel/llvm-project-overlay/libc/src/sys/mman/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/src/sys/mman/BUILD.bazel
index 4fa25b630ed9b..94a84c167e757 100644
--- a/utils/bazel/llvm-project-overlay/libc/src/sys/mman/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/src/sys/mman/BUILD.bazel
@@ -154,11 +154,10 @@ libc_function(
srcs = ["linux/munlock.cpp"],
hdrs = ["munlock.h"],
deps = [
- "//libc/hdr:sys_mman_macros",
"//libc/hdr/types:size_t",
"//libc/src/__support:common",
"//libc/src/__support:libc_errno",
- "//libc/src/__support/OSUtil:syscall",
+ "//libc/src/__support/OSUtil/linux/syscall_wrappers:munlock",
"//libc/src/__support/macros:config",
"//libc/src/errno",
],
``````````
</details>
https://github.com/llvm/llvm-project/pull/243785
More information about the llvm-branch-commits
mailing list