diff options
author | Vilas Bhat <vilasbhat@google.com> | 2024-03-27 18:25:48 +0000 |
---|---|---|
committer | Vilas Bhat <vilasbhat@google.com> | 2024-03-28 15:25:17 +0000 |
commit | 06bcd6a7017b09160b6e44d211665d1c33cf2181 (patch) | |
tree | 849c5bab757fae2517ea90b106a9be369a9a64eb | |
parent | 01013f3febfb22915493def49460284f58c65b63 (diff) | |
download | platform_testing-06bcd6a7017b09160b6e44d211665d1c33cf2181.tar.gz |
shell-as: Remove hardcoded PAGE_SIZE usage
Bug: 310232825
Test: Presubmit
Change-Id: I023021443d41206284136c6077b866b0de9d00f5
-rw-r--r-- | utils/shell-as/shell-code.cpp | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/utils/shell-as/shell-code.cpp b/utils/shell-as/shell-code.cpp index bdadf6c5a..ac9cacc3c 100644 --- a/utils/shell-as/shell-code.cpp +++ b/utils/shell-as/shell-code.cpp @@ -18,8 +18,7 @@ #include <sys/mman.h> #include <sys/types.h> - -#define PAGE_START(addr) ((uintptr_t)addr & ~(PAGE_SIZE - 1)) +#include <unistd.h> // Shell code that sets the SELinux context of the current process. // @@ -44,9 +43,13 @@ extern "C" int __trap_shell_code_signal; namespace shell_as { namespace { +uintptr_t PageStart(void (*addr)()) { + return ((uintptr_t)addr & ~(getpagesize() - 1)); +} + void EnsureShellcodeReadable(void (*start)(), void (*end)()) { - mprotect((void*)PAGE_START(start), - PAGE_START(end) - PAGE_START(start) + PAGE_SIZE, + mprotect((void*)PageStart(start), + PageStart(end) - PageStart(start) + getpagesize(), PROT_READ | PROT_EXEC); } } // namespace |