diff options
| author | Jackson Stogel <jtstogel@gmail.com> | 2025-11-18 14:30:15 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-11-18 14:30:15 -0800 |
| commit | db71cc58ec9471c67c6b80996930a19222dd9f03 (patch) | |
| tree | 61e6f425b2439bbff2d0e7186ff8d4a5c1b7f16a /utils/bazel/llvm-project-overlay | |
| parent | 6665642ce40c70b65624a5aa67566725c5a87da5 (diff) | |
[libc] Implement pkey_alloc/free/get/set/mprotect for x86_64 linux (#162362)
This patch provides definitions for `pkey_*` functions for linux x86_64.
`pkey_alloc`, `pkey_free`, and `pkey_mprotect` are simple syscall
wrappers. `pkey_set` and `pkey_get` modify architecture-specific
registers. The logic for these live in architecture specific
directories:
* `libc/src/sys/mman/linux/x86_64/pkey_common.h` has a real
implementation
* `libc/src/sys/mman/linux/generic/pkey_common.h` contains stubs that
just return `ENOSYS`.
Diffstat (limited to 'utils/bazel/llvm-project-overlay')
3 files changed, 111 insertions, 1 deletions
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel index a27abbd5b386..bd48222856f2 100644 --- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel +++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel @@ -6974,6 +6974,17 @@ libc_function( ], ) +libc_support_library( + name = "mprotect_common", + hdrs = ["src/sys/mman/linux/mprotect_common.h"], + deps = [ + ":__support_common", + ":__support_error_or", + ":__support_osutil_syscall", + ":errno", + ], +) + libc_function( name = "mprotect", srcs = ["src/sys/mman/linux/mprotect.cpp"], @@ -6982,6 +6993,7 @@ libc_function( ":__support_common", ":__support_osutil_syscall", ":errno", + ":mprotect_common", ], ) @@ -7041,6 +7053,85 @@ libc_function( ) libc_function( + name = "pkey_alloc", + srcs = ["src/sys/mman/linux/pkey_alloc.cpp"], + hdrs = ["src/sys/mman/pkey_alloc.h"], + deps = [ + ":__support_common", + ":__support_osutil_syscall", + ":errno", + ], +) + +libc_function( + name = "pkey_free", + srcs = ["src/sys/mman/linux/pkey_free.cpp"], + hdrs = ["src/sys/mman/pkey_free.h"], + deps = [ + ":__support_common", + ":__support_osutil_syscall", + ":errno", + ], +) + +libc_function( + name = "pkey_get", + srcs = ["src/sys/mman/linux/pkey_get.cpp"], + hdrs = ["src/sys/mman/pkey_get.h"], + deps = [ + ":__support_common", + ":__support_error_or", + ":__support_osutil_syscall", + ":errno", + ":pkey_common", + ], +) + +libc_function( + name = "pkey_mprotect", + srcs = ["src/sys/mman/linux/pkey_mprotect.cpp"], + hdrs = ["src/sys/mman/pkey_mprotect.h"], + deps = [ + ":__support_common", + ":__support_osutil_syscall", + ":errno", + ":mprotect", + ":mprotect_common", + ":types_size_t", + ], +) + +libc_function( + name = "pkey_set", + srcs = ["src/sys/mman/linux/pkey_set.cpp"], + hdrs = ["src/sys/mman/pkey_set.h"], + deps = [ + ":__support_common", + ":__support_error_or", + ":__support_osutil_syscall", + ":errno", + ":pkey_common", + ], +) + +libc_support_library( + name = "pkey_common", + hdrs = [ + "src/sys/mman/linux/pkey_common.h", + ] + selects.with_or({ + PLATFORM_CPU_X86_64: ["src/sys/mman/linux/x86_64/pkey_common.h"], + "//conditions:default": ["src/sys/mman/linux/generic/pkey_common.h"], + }), + deps = [ + ":__support_common", + ":__support_error_or", + ":__support_macros_properties_architectures", + ":hdr_errno_macros", + ":hdr_stdint_proxy", + ], +) + +libc_function( name = "posix_madvise", srcs = ["src/sys/mman/linux/posix_madvise.cpp"], hdrs = ["src/sys/mman/posix_madvise.h"], diff --git a/utils/bazel/llvm-project-overlay/libc/test/UnitTest/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/test/UnitTest/BUILD.bazel index 522a2bd62db8..eb13ebd16a66 100644 --- a/utils/bazel/llvm-project-overlay/libc/test/UnitTest/BUILD.bazel +++ b/utils/bazel/llvm-project-overlay/libc/test/UnitTest/BUILD.bazel @@ -35,6 +35,7 @@ libc_test_library( srcs = [ "BazelFilePath.cpp", "ExecuteFunctionUnix.cpp", + "LibcDeathTestExecutors.cpp", "LibcTest.cpp", "LibcTestMain.cpp", ], diff --git a/utils/bazel/llvm-project-overlay/libc/test/src/sys/mman/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/test/src/sys/mman/BUILD.bazel index 6de76e2357b7..845c6e70f3bd 100644 --- a/utils/bazel/llvm-project-overlay/libc/test/src/sys/mman/BUILD.bazel +++ b/utils/bazel/llvm-project-overlay/libc/test/src/sys/mman/BUILD.bazel @@ -2,7 +2,7 @@ # See https://llvm.org/LICENSE.txt for license information. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -# Tests for LLVM libc socket.h functions. +# Tests for LLVM libc mman.h functions. load("//libc/test:libc_test_rules.bzl", "libc_test") @@ -96,6 +96,24 @@ libc_test( ) libc_test( + name = "pkey_test", + srcs = ["linux/pkey_test.cpp"], + deps = [ + "//libc:hdr_errno_macros", + "//libc:hdr_signal_macros", + "//libc:mmap", + "//libc:munmap", + "//libc:pkey_alloc", + "//libc:pkey_free", + "//libc:pkey_get", + "//libc:pkey_mprotect", + "//libc:pkey_set", + "//libc:types_size_t", + "//libc/test/UnitTest:test_logger", + ], +) + +libc_test( name = "posix_madvise_test", srcs = ["linux/posix_madvise_test.cpp"], deps = [ |
