From ee52ce30795a547bb4524e1166238ec44ef6e950 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Sat, 2 Apr 2022 18:00:33 +0100 Subject: new util to name the data pages for now linux and especially android which supports it since a lot longer. --- src/build-data/os/android.txt | 1 + src/build-data/os/linux.txt | 1 + src/lib/utils/os_utils.cpp | 21 +++++++++++++++++++++ src/lib/utils/os_utils.h | 5 +++++ 4 files changed, 28 insertions(+) (limited to 'src') diff --git a/src/build-data/os/android.txt b/src/build-data/os/android.txt index 54cdf4560..ea18cbde6 100644 --- a/src/build-data/os/android.txt +++ b/src/build-data/os/android.txt @@ -26,4 +26,5 @@ sockets threads thread_local filesystem +prctl diff --git a/src/build-data/os/linux.txt b/src/build-data/os/linux.txt index daf98f2b6..5752a0c94 100644 --- a/src/build-data/os/linux.txt +++ b/src/build-data/os/linux.txt @@ -19,6 +19,7 @@ sockets threads thread_local filesystem +prctl diff --git a/src/lib/utils/os_utils.cpp b/src/lib/utils/os_utils.cpp index 403f7ac0c..0f3c2dfdc 100644 --- a/src/lib/utils/os_utils.cpp +++ b/src/lib/utils/os_utils.cpp @@ -67,6 +67,14 @@ #include #endif +#if defined(BOTAN_TARGET_OS_HAS_PRCTL) + #include + #if !defined(PR_SET_VMA) + #define PR_SET_VMA 0x53564d41 + #define PR_SET_VMA_ANON_NAME 0 + #endif +#endif + namespace Botan { // Not defined in OS namespace for historical reasons @@ -587,6 +595,8 @@ std::vector OS::allocate_locked_pages(size_t count) std::memset(ptr, 0, 3*page_size); // zero data page and both guard pages + // Attempts to name the data page + page_named(ptr, 3*page_size); // Make guard page preceeding the data page page_prohibit_access(static_cast(ptr)); // Make guard page following the data page @@ -655,6 +665,17 @@ void OS::free_locked_pages(const std::vector& pages) } } +void OS::page_named(void* page, size_t size) + { + static constexpr char name[] = "Botan"; +#if defined(BOTAN_TARGET_OS_HAS_PRCTL) + int r = prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, reinterpret_cast(page), size, name); + BOTAN_UNUSED(r); +#else + BOTAN_UNUSED(page, size); +#endif + } + #if defined(BOTAN_TARGET_OS_HAS_POSIX1) && !defined(BOTAN_TARGET_OS_IS_EMSCRIPTEN) namespace { diff --git a/src/lib/utils/os_utils.h b/src/lib/utils/os_utils.h index a70ce2ee1..62dfdeeaf 100644 --- a/src/lib/utils/os_utils.h +++ b/src/lib/utils/os_utils.h @@ -149,6 +149,11 @@ void page_prohibit_access(void* page); */ void page_allow_access(void* page); +/** +* Set a ID to a page's range expressed by size bytes +*/ +void page_named(void* page, size_t size); + /** * Run a probe instruction to test for support for a CPU instruction. -- cgit v1.2.3