https://github.com/c8ef updated https://github.com/llvm/llvm-project/pull/239197
>From 7d21367e5c73b69b523f9336d65c8dcdbe835dc8 Mon Sep 17 00:00:00 2001 From: c8ef <[email protected]> Date: Thu, 5 Nov 2026 19:40:13 +0800 Subject: [PATCH] [libc] Use a syscall wrapper for pkey_free This PR move pkey_free behind the centralized syscall wrappers, following libc/docs/dev/syscall_wrapper_refactor.md. --- .../linux/syscall_wrappers/CMakeLists.txt | 13 +++++++ .../OSUtil/linux/syscall_wrappers/pkey_free.h | 39 +++++++++++++++++++ libc/src/sys/mman/linux/CMakeLists.txt | 7 ++-- libc/src/sys/mman/linux/pkey_free.cpp | 23 +++++------ .../llvm-project-overlay/libc/BUILD.bazel | 19 ++++++++- 5 files changed, 83 insertions(+), 18 deletions(-) create mode 100644 libc/src/__support/OSUtil/linux/syscall_wrappers/pkey_free.h diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt b/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt index 5f1cca5bf0ed62..9f78c261e35bed 100644 --- a/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt +++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt @@ -946,6 +946,19 @@ add_header_library( libc.src.__support.macros.config ) +add_header_library( + pkey_free + HDRS + pkey_free.h + DEPENDS + libc.hdr.errno_macros + 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( pkey_mprotect HDRS diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/pkey_free.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/pkey_free.h new file mode 100644 index 00000000000000..9a5f68aeacfddb --- /dev/null +++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/pkey_free.h @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// 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 pkey_free. +/// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_PKEY_FREE_H +#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_PKEY_FREE_H + +#include "hdr/errno_macros.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> pkey_free(int pkey) { +#if defined(SYS_pkey_free) + return syscall_checked<int>(SYS_pkey_free, pkey); +#else + return Error(ENOSYS); +#endif +} + +} // namespace linux_syscalls +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_PKEY_FREE_H diff --git a/libc/src/sys/mman/linux/CMakeLists.txt b/libc/src/sys/mman/linux/CMakeLists.txt index e4eda48e4f9702..d8426921f85dac 100644 --- a/libc/src/sys/mman/linux/CMakeLists.txt +++ b/libc/src/sys/mman/linux/CMakeLists.txt @@ -218,9 +218,10 @@ add_entrypoint_object( HDRS ../pkey_free.h DEPENDS - libc.include.sys_mman - libc.include.sys_syscall - libc.src.__support.OSUtil.osutil + libc.src.__support.OSUtil.linux.syscall_wrappers.pkey_free + 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/pkey_free.cpp b/libc/src/sys/mman/linux/pkey_free.cpp index 328ba0468252e4..ba665a2bd2d5e8 100644 --- a/libc/src/sys/mman/linux/pkey_free.cpp +++ b/libc/src/sys/mman/linux/pkey_free.cpp @@ -1,35 +1,32 @@ -//===---------- Linux implementation of the Linux pkey_free 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 pkey_free. +/// +//===----------------------------------------------------------------------===// #include "src/sys/mman/pkey_free.h" -#include "hdr/errno_macros.h" // For ENOSYS -#include "src/__support/OSUtil/syscall.h" // For internal syscall function. +#include "src/__support/OSUtil/linux/syscall_wrappers/pkey_free.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, pkey_free, (int pkey)) { -#if !defined(SYS_pkey_free) - libc_errno = ENOSYS; - return -1; -#else - int ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_pkey_free, pkey); - if (ret < 0) { - libc_errno = -ret; + auto result = linux_syscalls::pkey_free(pkey); + if (!result) { + libc_errno = result.error(); return -1; } return 0; -#endif } } // namespace LIBC_NAMESPACE_DECL diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel index f3a3a3ad118f70..713e09d071166b 100644 --- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel +++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel @@ -4613,6 +4613,22 @@ libc_support_library( ], ) +libc_support_library( + name = "__support_osutil_linux_syscall_wrappers_pkey_free", + hdrs = ["src/__support/OSUtil/linux/syscall_wrappers/pkey_free.h"], + target_compatible_with = select({ + "@platforms//os:linux": [], + "//conditions:default": ["@platforms//:incompatible"], + }), + deps = [ + ":__support_common", + ":__support_error_or", + ":__support_macros_config", + ":__support_osutil_syscall", + ":hdr_errno_macros", + ], +) + libc_support_library( name = "__support_osutil_linux_syscall_wrappers_pkey_mprotect", hdrs = ["src/__support/OSUtil/linux/syscall_wrappers/pkey_mprotect.h"], @@ -19871,9 +19887,8 @@ libc_function( ":__support_common", ":__support_libc_errno", ":__support_macros_config", - ":__support_osutil_syscall", + ":__support_osutil_linux_syscall_wrappers_pkey_free", ":errno", - ":hdr_errno_macros", ], ) _______________________________________________ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
