aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/build-data/os/android.txt1
-rw-r--r--src/build-data/os/linux.txt1
-rw-r--r--src/lib/utils/os_utils.cpp21
-rw-r--r--src/lib/utils/os_utils.h5
4 files changed, 28 insertions, 0 deletions
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
</target_features>
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
</target_features>
<aliases>
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 <mach/vm_statistics.h>
#endif
+#if defined(BOTAN_TARGET_OS_HAS_PRCTL)
+ #include <sys/prctl.h>
+ #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<void*> 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<uint8_t*>(ptr));
// Make guard page following the data page
@@ -655,6 +665,17 @@ void OS::free_locked_pages(const std::vector<void*>& 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<uintptr_t>(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.