-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[libc] Implement pkey_alloc/free/get/set/mprotect for x86_64 linux #162362
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 13 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
6eb5a45
Implement pkey alloc/free/get/set/mprotect for x86_64 linux
jtstogel 7147a2a
Add pkey_* to generated sys/mman.h. Fix formatting.
jtstogel 50f264e
Add license headers.
jtstogel e67b0c5
Prefer direct use of 'asm volatile' over LIBC_INLINE_ASM.
jtstogel 30b1d22
Use instrinsics instead of asm. Don't depend on mprotect entrypoint.
jtstogel c1f6650
Merge branch 'main' into add-pkey-x86
jtstogel 1780027
Remove dependency on mprotect entrypoint from pkey_mprotect.
jtstogel ee0b312
Format files.
jtstogel 75b4ab6
Fix standard specification in mman.yaml
jtstogel 45324d7
Merge branch 'main' into add-pkey-x86
jtstogel b37cb4b
Disable sanitizers for pkey_test.
jtstogel 2211955
Deduplicate logic for picking architecture-specific pkey_common.h.
jtstogel 0704290
Merge branch 'main' into add-pkey-x86
jtstogel becf3db
Fix select condition in BUILD.bazel
jtstogel df5632d
Merge branch 'main' into add-pkey-x86
jtstogel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| add_header_library( | ||
| pkey_common | ||
| HDRS | ||
| pkey_common.h | ||
| DEPENDS | ||
| libc.hdr.errno_macros | ||
| libc.src.__support.common | ||
| libc.src.__support.error_or | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| //===---------- Generic stub implementations for pkey functionality. ------===// | ||
| // | ||
| // 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 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #ifndef LLVM_SYS_MMAN_LINUX_GENERIC_PKEY_COMMON_H_ | ||
| #define LLVM_SYS_MMAN_LINUX_GENERIC_PKEY_COMMON_H_ | ||
|
|
||
| #include "hdr/errno_macros.h" // For ENOSYS | ||
| #include "src/__support/common.h" | ||
| #include "src/__support/error_or.h" | ||
|
|
||
| namespace LIBC_NAMESPACE_DECL { | ||
| namespace pkey_common { | ||
|
|
||
| LIBC_INLINE ErrorOr<int> pkey_get([[maybe_unused]] int pkey) { | ||
| return Error(ENOSYS); | ||
| } | ||
|
|
||
| LIBC_INLINE ErrorOr<int> pkey_set([[maybe_unused]] int pkey, | ||
| [[maybe_unused]] unsigned int access_rights) { | ||
| return Error(ENOSYS); | ||
| } | ||
|
|
||
| } // namespace pkey_common | ||
| } // namespace LIBC_NAMESPACE_DECL | ||
|
|
||
| #endif // LLVM_SYS_MMAN_LINUX_GENERIC_PKEY_COMMON_H_ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| //===---------- Shared Linux implementation of POSIX mprotect. ------------===// | ||
| // | ||
| // 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 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "src/__support/OSUtil/syscall.h" // For internal syscall function. | ||
| #include "src/__support/common.h" | ||
| #include "src/__support/error_or.h" | ||
| #include "src/__support/libc_errno.h" | ||
| #include "src/__support/macros/attributes.h" | ||
| #include "src/__support/macros/config.h" | ||
| #include <sys/syscall.h> // For syscall numbers. | ||
|
|
||
| namespace LIBC_NAMESPACE_DECL { | ||
|
|
||
| namespace mprotect_common { | ||
|
|
||
| // This function is currently linux only. It has to be refactored suitably if | ||
| // mprotect is to be supported on non-linux operating systems also. | ||
| LIBC_INLINE ErrorOr<int> mprotect_impl(void *addr, size_t size, int prot) { | ||
| int ret = LIBC_NAMESPACE::syscall_impl<int>( | ||
| SYS_mprotect, reinterpret_cast<long>(addr), size, prot); | ||
|
|
||
| // A negative return value indicates an error with the magnitude of the | ||
| // value being the error code. | ||
| if (ret < 0) { | ||
| return Error(-ret); | ||
| } | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| } // namespace mprotect_common | ||
|
|
||
| } // namespace LIBC_NAMESPACE_DECL |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| //===---------- Linux implementation of the Linux pkey_alloc 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 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "src/sys/mman/pkey_alloc.h" | ||
|
|
||
| #include "hdr/errno_macros.h" // For ENOSYS | ||
| #include "src/__support/OSUtil/syscall.h" // For internal syscall function. | ||
| #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_alloc, | ||
| (unsigned int flags, unsigned int access_rights)) { | ||
| #if !defined(SYS_pkey_alloc) | ||
| libc_errno = ENOSYS; | ||
| return -1; | ||
|
Comment on lines
+24
to
+25
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. generally for syscall wrappers like this we don't bother with the |
||
| #else | ||
| int ret = | ||
| LIBC_NAMESPACE::syscall_impl<int>(SYS_pkey_alloc, flags, access_rights); | ||
| if (ret < 0) { | ||
| libc_errno = -ret; | ||
| return -1; | ||
| } | ||
| return static_cast<int>(ret); | ||
| #endif | ||
| } | ||
|
|
||
| } // namespace LIBC_NAMESPACE_DECL | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| //===---------- Linux implementation of the Linux pkey_mprotect 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 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "src/__support/macros/properties/architectures.h" | ||
|
|
||
| #if defined(LIBC_TARGET_ARCH_IS_X86_64) | ||
| #include "src/sys/mman/linux/x86_64/pkey_common.h" | ||
| #else | ||
| #include "src/sys/mman/linux/generic/pkey_common.h" | ||
| #endif |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.