From efccea267d3989069d06d022d4679717356af026 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Sat, 27 Jul 2019 12:38:31 +0100 Subject: Darwin, monitoring anonymous locked pages via vm_stat tool. Userland applications are allowed taking ID from 240->255. The ID can be made dynamic later on if wished. --- src/lib/utils/os_utils.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/lib/utils/os_utils.cpp b/src/lib/utils/os_utils.cpp index 50ebbb072..daa5bb73f 100644 --- a/src/lib/utils/os_utils.cpp +++ b/src/lib/utils/os_utils.cpp @@ -430,11 +430,19 @@ std::vector OS::allocate_locked_pages(size_t count) #define PROT_MAX(p) 0 #endif const int pflags = PROT_READ | PROT_WRITE; +#if defined(BOTAN_TARGET_OS_IS_IOS) || defined(BOTAN_TARGET_OS_IS_MACOS) +// On Darwin, tagging anonymous pages allows vmmap to track these. +// Allowed from 240 to 255 for userland applications, taken an hardcoded +// value for now even though it can possibly intersect. + const int locked_fd = (255<<24); +#else + const int locked_fd = -1; +#endif ptr = ::mmap(nullptr, 2*page_size, pflags | PROT_MAX(pflags), MAP_ANONYMOUS | MAP_PRIVATE | MAP_NOCORE, - /*fd=*/-1, /*offset=*/0); + /*fd=*/locked_fd, /*offset=*/0); if(ptr == MAP_FAILED) { -- cgit v1.2.3