aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2019-09-06 07:16:57 -0400
committerJack Lloyd <[email protected]>2019-09-06 07:16:57 -0400
commit1cfc302453b3b72790ec8c8424f14fdd711435fd (patch)
treed00bfb35a06edf195a0904b63bc401be43e3a39c /src/lib
parentcc6b42d71b0cdc2ebfa2b33b5039991f2d79f606 (diff)
Style tweaks
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/utils/os_utils.cpp59
1 files changed, 34 insertions, 25 deletions
diff --git a/src/lib/utils/os_utils.cpp b/src/lib/utils/os_utils.cpp
index 843e68638..a27e9117f 100644
--- a/src/lib/utils/os_utils.cpp
+++ b/src/lib/utils/os_utils.cpp
@@ -60,30 +60,6 @@
#endif
namespace Botan {
-namespace {
-int get_locked_fd()
- {
-#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.
- static constexpr int default_locked_fd = 255;
- int locked_fd = default_locked_fd;
-
- if (size_t locked_fdl = OS::read_env_variable_sz("BOTAN_LOCKED_FD", default_locked_fd))
- {
- if (locked_fdl < 240 || locked_fdl > 255)
- {
- locked_fdl = default_locked_fd;
- }
- locked_fd = static_cast<int>(locked_fdl);
- }
- return VM_MAKE_TAG(locked_fd);
-#else
- return -1;
-#endif
- }
-}
// Not defined in OS namespace for historical reasons
void secure_scrub_memory(void* ptr, size_t n)
@@ -429,8 +405,42 @@ size_t OS::read_env_variable_sz(const std::string& name, size_t def)
return def;
}
+#if defined(BOTAN_TARGET_OS_HAS_POSIX1) && defined(BOTAN_TARGET_OS_HAS_POSIX_MLOCK)
+
+namespace {
+
+int get_locked_fd()
+ {
+#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
+ static constexpr int default_locked_fd = 255;
+ int locked_fd = default_locked_fd;
+
+ if(size_t locked_fdl = OS::read_env_variable_sz("BOTAN_LOCKED_FD", default_locked_fd))
+ {
+ if(locked_fdl < 240 || locked_fdl > 255)
+ {
+ locked_fdl = default_locked_fd;
+ }
+ locked_fd = static_cast<int>(locked_fdl);
+ }
+ return VM_MAKE_TAG(locked_fd);
+#else
+ return -1;
+#endif
+ }
+
+}
+
+#endif
+
std::vector<void*> OS::allocate_locked_pages(size_t count)
{
+#if defined(BOTAN_TARGET_OS_HAS_POSIX1) && defined(BOTAN_TARGET_OS_HAS_POSIX_MLOCK)
+ static const int locked_fd = get_locked_fd();
+#endif
+
std::vector<void*> result;
result.reserve(count);
@@ -458,7 +468,6 @@ std::vector<void*> OS::allocate_locked_pages(size_t count)
#define PROT_MAX(p) 0
#endif
const int pflags = PROT_READ | PROT_WRITE;
- static const int locked_fd = get_locked_fd();
ptr = ::mmap(nullptr, 2*page_size,
pflags | PROT_MAX(pflags),