aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/utils
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2020-03-14 13:44:37 -0400
committerJack Lloyd <[email protected]>2020-03-14 19:07:42 -0400
commit51ee57c3558391aca7f212eb80ab881b3fe34e17 (patch)
treeae4c0230353fb655d28135d661cd5d1bb8c9bb0e /src/lib/utils
parent067be47bce177a4ff15a7d09d2c5c56f1708dd24 (diff)
Add baremetal (gcc-arm-none-eabi) build
Diffstat (limited to 'src/lib/utils')
-rw-r--r--src/lib/utils/cpuid/cpuid_arm.cpp9
-rw-r--r--src/lib/utils/os_utils.cpp24
2 files changed, 21 insertions, 12 deletions
diff --git a/src/lib/utils/cpuid/cpuid_arm.cpp b/src/lib/utils/cpuid/cpuid_arm.cpp
index ad9f63603..247464043 100644
--- a/src/lib/utils/cpuid/cpuid_arm.cpp
+++ b/src/lib/utils/cpuid/cpuid_arm.cpp
@@ -101,6 +101,8 @@ uint64_t flags_by_ios_machine_type(const std::string& machine)
uint64_t CPUID::CPUID_Data::detect_cpu_features(size_t* cache_line_size)
{
+ BOTAN_UNUSED(cache_line_size);
+
uint64_t detected_features = 0;
#if defined(BOTAN_TARGET_OS_HAS_GETAUXVAL) || defined(BOTAN_TARGET_OS_HAS_ELF_AUX_INFO)
@@ -145,8 +147,6 @@ uint64_t CPUID::CPUID_Data::detect_cpu_features(size_t* cache_line_size)
// plausibility check
if(dcache_line == 32 || dcache_line == 64 || dcache_line == 128)
*cache_line_size = static_cast<size_t>(dcache_line);
-#else
- BOTAN_UNUSED(cache_line_size);
#endif
const unsigned long hwcap_neon = OS::get_auxval(ARM_hwcap_bit::ARCH_hwcap_neon);
@@ -188,8 +188,7 @@ uint64_t CPUID::CPUID_Data::detect_cpu_features(size_t* cache_line_size)
::sysctlbyname("hw.machine", machine, &size, nullptr, 0);
detected_features = flags_by_ios_machine_type(machine);
- // No way to detect this on iOS?
- BOTAN_UNUSED(cache_line_size);
+ // No way to detect cache line size on iOS?
#elif defined(BOTAN_USE_GCC_INLINE_ASM) && defined(BOTAN_TARGET_ARCH_IS_ARM64)
@@ -224,8 +223,6 @@ uint64_t CPUID::CPUID_Data::detect_cpu_features(size_t* cache_line_size)
detected_features |= CPUID::CPUID_ARM_SHA2_BIT;
}
- BOTAN_UNUSED(cache_line_size);
-
#endif
return detected_features;
diff --git a/src/lib/utils/os_utils.cpp b/src/lib/utils/os_utils.cpp
index b0b59fc7c..9f3fb165e 100644
--- a/src/lib/utils/os_utils.cpp
+++ b/src/lib/utils/os_utils.cpp
@@ -458,15 +458,18 @@ int get_locked_fd()
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;
+
+#if (defined(BOTAN_TARGET_OS_HAS_POSIX1) && defined(BOTAN_TARGET_OS_HAS_POSIX_MLOCK)) || defined(BOTAN_TARGET_OS_HAS_VIRTUAL_LOCK)
+
result.reserve(count);
const size_t page_size = OS::system_page_size();
+#if defined(BOTAN_TARGET_OS_HAS_POSIX1) && defined(BOTAN_TARGET_OS_HAS_POSIX_MLOCK)
+ static const int locked_fd = get_locked_fd();
+#endif
+
for(size_t i = 0; i != count; ++i)
{
void* ptr = nullptr;
@@ -532,31 +535,40 @@ std::vector<void*> OS::allocate_locked_pages(size_t count)
result.push_back(ptr);
}
+#else
+ BOTAN_UNUSED(count);
+#endif
return result;
}
void OS::page_allow_access(void* page)
{
- const size_t page_size = OS::system_page_size();
#if defined(BOTAN_TARGET_OS_HAS_POSIX1)
+ const size_t page_size = OS::system_page_size();
::mprotect(page, page_size, PROT_READ | PROT_WRITE);
#elif defined(BOTAN_TARGET_OS_HAS_VIRTUAL_LOCK)
+ const size_t page_size = OS::system_page_size();
DWORD old_perms = 0;
::VirtualProtect(page, page_size, PAGE_READWRITE, &old_perms);
BOTAN_UNUSED(old_perms);
+#else
+ BOTAN_UNUSED(page);
#endif
}
void OS::page_prohibit_access(void* page)
{
- const size_t page_size = OS::system_page_size();
#if defined(BOTAN_TARGET_OS_HAS_POSIX1)
+ const size_t page_size = OS::system_page_size();
::mprotect(page, page_size, PROT_NONE);
#elif defined(BOTAN_TARGET_OS_HAS_VIRTUAL_LOCK)
+ const size_t page_size = OS::system_page_size();
DWORD old_perms = 0;
::VirtualProtect(page, page_size, PAGE_NOACCESS, &old_perms);
BOTAN_UNUSED(old_perms);
+#else
+ BOTAN_UNUSED(page);
#endif
}