https://github.com/c8ef created https://github.com/llvm/llvm-project/pull/243785
This PR move munlock behind the centralized syscall wrappers, following libc/docs/dev/syscall_wrapper_refactor.md. >From b1106465c55866a74200108823057d4bdafb0923 Mon Sep 17 00:00:00 2001 From: c8ef <[email protected]> Date: Wed, 18 Nov 2026 18:25:07 +0800 Subject: [PATCH] [libc] Use a syscall wrapper for munlock --- .../linux/syscall_wrappers/CMakeLists.txt | 13 +++++++ .../OSUtil/linux/syscall_wrappers/munlock.h | 34 +++++++++++++++++++ libc/src/sys/mman/linux/CMakeLists.txt | 8 +++-- libc/src/sys/mman/linux/munlock.cpp | 18 ++++++---- .../OSUtil/linux/syscall_wrappers/BUILD.bazel | 16 +++++++++ .../libc/src/sys/mman/BUILD.bazel | 3 +- 6 files changed, 80 insertions(+), 12 deletions(-) create mode 100644 libc/src/__support/OSUtil/linux/syscall_wrappers/munlock.h diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt b/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt index c332cf2cb65826..425033759ae996 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 00000000000000..b803b8c497932d --- /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 4180ba24ce7aaf..38b3372b7c9513 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 9638949f5fcb3a..225ff3ba198bbe 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 b9cb62558e1291..d32217d4a7d722 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 4fa25b630ed9bf..94a84c167e757c 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", ], _______________________________________________ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
