From 092114e11c27de26a53aefa08547cc0bc44717ca Mon Sep 17 00:00:00 2001 From: Jack Lloyd Date: Wed, 13 Dec 2017 17:57:31 -0500 Subject: Test OS features by the feature vs the OS name --- src/lib/utils/calendar.cpp | 4 ++-- src/lib/utils/dyn_load/dyn_load.cpp | 21 ++++++++++----------- src/lib/utils/dyn_load/info.txt | 15 ++++----------- src/lib/utils/filesystem.cpp | 13 +++++++------ src/lib/utils/locking_allocator/info.txt | 11 ++++------- src/lib/utils/mutex.h | 4 +--- src/lib/utils/os_utils.cpp | 24 ++++++++++++------------ src/lib/utils/socket/socket.cpp | 10 +++++----- 8 files changed, 45 insertions(+), 57 deletions(-) (limited to 'src/lib/utils') diff --git a/src/lib/utils/calendar.cpp b/src/lib/utils/calendar.cpp index e902e411d..fe04f1d23 100644 --- a/src/lib/utils/calendar.cpp +++ b/src/lib/utils/calendar.cpp @@ -21,9 +21,9 @@ std::tm do_gmtime(std::time_t time_val) { std::tm tm; -#if defined(BOTAN_TARGET_OS_HAS_GMTIME_S) +#if defined(BOTAN_TARGET_OS_HAS_WIN32) ::gmtime_s(&tm, &time_val); // Windows -#elif defined(BOTAN_TARGET_OS_HAS_GMTIME_R) +#elif defined(BOTAN_TARGET_OS_HAS_POSIX1) ::gmtime_r(&time_val, &tm); // Unix/SUSv2 #else std::tm* tm_p = std::gmtime(&time_val); diff --git a/src/lib/utils/dyn_load/dyn_load.cpp b/src/lib/utils/dyn_load/dyn_load.cpp index 33288b8d1..b7f2649ef 100644 --- a/src/lib/utils/dyn_load/dyn_load.cpp +++ b/src/lib/utils/dyn_load/dyn_load.cpp @@ -8,9 +8,9 @@ #include #include -#if defined(BOTAN_TARGET_OS_HAS_DLOPEN) +#if defined(BOTAN_TARGET_OS_HAS_POSIX1) #include -#elif defined(BOTAN_TARGET_OS_HAS_LOADLIBRARY) +#elif defined(BOTAN_TARGET_OS_HAS_WIN32) #define NOMINMAX 1 #define _WINSOCKAPI_ // stop windows.h including winsock.h #include @@ -24,7 +24,7 @@ void raise_runtime_loader_exception(const std::string& lib_name, const char* msg) { throw Exception("Failed to load " + lib_name + ": " + - (msg ? msg : "Unknown error")); + (msg ? msg : "Unknown error")); } } @@ -33,13 +33,13 @@ Dynamically_Loaded_Library::Dynamically_Loaded_Library( const std::string& library) : m_lib_name(library), m_lib(nullptr) { -#if defined(BOTAN_TARGET_OS_HAS_DLOPEN) +#if defined(BOTAN_TARGET_OS_HAS_POSIX1) m_lib = ::dlopen(m_lib_name.c_str(), RTLD_LAZY); if(!m_lib) raise_runtime_loader_exception(m_lib_name, ::dlerror()); -#elif defined(BOTAN_TARGET_OS_HAS_LOADLIBRARY) +#elif defined(BOTAN_TARGET_OS_HAS_WIN32) m_lib = ::LoadLibraryA(m_lib_name.c_str()); if(!m_lib) @@ -52,9 +52,9 @@ Dynamically_Loaded_Library::Dynamically_Loaded_Library( Dynamically_Loaded_Library::~Dynamically_Loaded_Library() { -#if defined(BOTAN_TARGET_OS_HAS_DLOPEN) +#if defined(BOTAN_TARGET_OS_HAS_POSIX1) ::dlclose(m_lib); -#elif defined(BOTAN_TARGET_OS_HAS_LOADLIBRARY) +#elif defined(BOTAN_TARGET_OS_HAS_WIN32) ::FreeLibrary((HMODULE)m_lib); #endif } @@ -63,11 +63,10 @@ void* Dynamically_Loaded_Library::resolve_symbol(const std::string& symbol) { void* addr = nullptr; -#if defined(BOTAN_TARGET_OS_HAS_DLOPEN) +#if defined(BOTAN_TARGET_OS_HAS_POSIX1) addr = ::dlsym(m_lib, symbol.c_str()); -#elif defined(BOTAN_TARGET_OS_HAS_LOADLIBRARY) - addr = reinterpret_cast(::GetProcAddress((HMODULE)m_lib, - symbol.c_str())); +#elif defined(BOTAN_TARGET_OS_HAS_WIN32) + addr = reinterpret_cast(::GetProcAddress((HMODULE)m_lib, symbol.c_str())); #endif if(!addr) diff --git a/src/lib/utils/dyn_load/info.txt b/src/lib/utils/dyn_load/info.txt index 2caeac728..4dd4932a0 100644 --- a/src/lib/utils/dyn_load/info.txt +++ b/src/lib/utils/dyn_load/info.txt @@ -4,17 +4,10 @@ DYNAMIC_LOADER -> 20160310 load_on dep - -android -freebsd -linux -netbsd -openbsd -qnx -solaris -windows -darwin - + +posix1 +win32 + android -> dl diff --git a/src/lib/utils/filesystem.cpp b/src/lib/utils/filesystem.cpp index fd4aee1f0..29f73fcb3 100644 --- a/src/lib/utils/filesystem.cpp +++ b/src/lib/utils/filesystem.cpp @@ -13,14 +13,14 @@ #include #elif defined(BOTAN_HAS_BOOST_FILESYSTEM) #include -#elif defined(BOTAN_TARGET_OS_HAS_READDIR) +#elif defined(BOTAN_TARGET_OS_HAS_POSIX1) #include #include #include #include #include #include -#elif defined(BOTAN_TARGET_OS_TYPE_IS_WINDOWS) +#elif defined(BOTAN_TARGET_OS_HAS_WIN32) #define NOMINMAX 1 #define _WINSOCKAPI_ // stop windows.h including winsock.h #include @@ -74,7 +74,8 @@ std::vector impl_boost_filesystem(const std::string& dir_path) return out; } -#elif defined(BOTAN_TARGET_OS_HAS_READDIR) +#elif defined(BOTAN_TARGET_OS_HAS_POSIX1) + std::vector impl_readdir(const std::string& dir_path) { std::vector out; @@ -113,7 +114,7 @@ std::vector impl_readdir(const std::string& dir_path) return out; } -#elif defined(BOTAN_TARGET_OS_TYPE_IS_WINDOWS) +#elif defined(BOTAN_TARGET_OS_HAS_WIN32) std::vector impl_win32(const std::string& dir_path) { @@ -167,9 +168,9 @@ std::vector get_files_recursive(const std::string& dir) files = impl_stl_filesystem(dir); #elif defined(BOTAN_HAS_BOOST_FILESYSTEM) files = impl_boost_filesystem(dir); -#elif defined(BOTAN_TARGET_OS_HAS_READDIR) +#elif defined(BOTAN_TARGET_OS_HAS_POSIX1) files = impl_readdir(dir); -#elif defined(BOTAN_TARGET_OS_TYPE_IS_WINDOWS) +#elif defined(BOTAN_TARGET_OS_HAS_WIN32) files = impl_win32(dir); #else BOTAN_UNUSED(dir); diff --git a/src/lib/utils/locking_allocator/info.txt b/src/lib/utils/locking_allocator/info.txt index 5f848f62d..7dc3c059d 100644 --- a/src/lib/utils/locking_allocator/info.txt +++ b/src/lib/utils/locking_allocator/info.txt @@ -2,10 +2,7 @@ LOCKING_ALLOCATOR -> 20131128 - -linux -freebsd -openbsd -netbsd -windows - + +posix1 +virtual_lock + diff --git a/src/lib/utils/mutex.h b/src/lib/utils/mutex.h index 6e24815bb..34fed5c81 100644 --- a/src/lib/utils/mutex.h +++ b/src/lib/utils/mutex.h @@ -20,7 +20,7 @@ typedef std::mutex mutex_type; } -#elif defined(BOTAN_TARGET_OS_TYPE_IS_UNIKERNEL) || defined(BOTAN_TARGET_OS_IS_LLVM) +#else // No threads @@ -53,8 +53,6 @@ template using lock_guard_type = lock_guard; } -#else - #error "Threads unexpectedly disabled in non unikernel build" #endif #endif diff --git a/src/lib/utils/os_utils.cpp b/src/lib/utils/os_utils.cpp index 48890964a..0f3ab7a32 100644 --- a/src/lib/utils/os_utils.cpp +++ b/src/lib/utils/os_utils.cpp @@ -18,7 +18,7 @@ #include #endif -#if defined(BOTAN_TARGET_OS_TYPE_IS_UNIX) +#if defined(BOTAN_TARGET_OS_HAS_POSIX1) #include #include #include @@ -26,7 +26,7 @@ #include #include #include -#elif defined(BOTAN_TARGET_OS_TYPE_IS_WINDOWS) +#elif defined(BOTAN_TARGET_OS_HAS_WIN32) #define NOMINMAX 1 #include #endif @@ -63,11 +63,11 @@ void secure_scrub_memory(void* ptr, size_t n) uint32_t OS::get_process_id() { -#if defined(BOTAN_TARGET_OS_TYPE_IS_UNIX) +#if defined(BOTAN_TARGET_OS_HAS_POSIX1) return ::getpid(); -#elif defined(BOTAN_TARGET_OS_IS_WINDOWS) || defined(BOTAN_TARGET_OS_IS_MINGW) +#elif defined(BOTAN_TARGET_OS_HAS_WIN32) return ::GetCurrentProcessId(); -#elif defined(BOTAN_TARGET_OS_TYPE_IS_UNIKERNEL) || defined(BOTAN_TARGET_OS_IS_LLVM) +#elif defined(BOTAN_TARGET_OS_IS_INCLUDEOS) || defined(BOTAN_TARGET_OS_IS_LLVM) return 0; // truly no meaningful value #else #error "Missing get_process_id" @@ -78,7 +78,7 @@ uint64_t OS::get_processor_timestamp() { uint64_t rtc = 0; -#if defined(BOTAN_TARGET_OS_HAS_QUERY_PERF_COUNTER) +#if defined(BOTAN_TARGET_OS_HAS_WIN32) LARGE_INTEGER tv; ::QueryPerformanceCounter(&tv); rtc = tv.QuadPart; @@ -196,7 +196,7 @@ uint64_t OS::get_system_timestamp_ns() size_t OS::get_memory_locking_limit() { -#if defined(BOTAN_TARGET_OS_HAS_POSIX_MLOCK) +#if defined(BOTAN_TARGET_OS_HAS_POSIX1) /* * Linux defaults to only 64 KiB of mlockable memory per process * (too small) but BSDs offer a small fraction of total RAM (more @@ -282,7 +282,7 @@ size_t OS::get_memory_locking_limit() void* OS::allocate_locked_pages(size_t length) { -#if defined(BOTAN_TARGET_OS_HAS_POSIX_MLOCK) +#if defined(BOTAN_TARGET_OS_HAS_POSIX1) #if !defined(MAP_NOCORE) #define MAP_NOCORE 0 @@ -342,11 +342,11 @@ void OS::free_locked_pages(void* ptr, size_t length) if(ptr == nullptr || length == 0) return; -#if defined(BOTAN_TARGET_OS_HAS_POSIX_MLOCK) +#if defined(BOTAN_TARGET_OS_HAS_POSIX1) secure_scrub_memory(ptr, length); ::munlock(ptr, length); ::munmap(ptr, length); -#elif defined BOTAN_TARGET_OS_HAS_VIRTUAL_LOCK +#elif defined(BOTAN_TARGET_OS_HAS_VIRTUAL_LOCK) secure_scrub_memory(ptr, length); ::VirtualUnlock(ptr, length); ::VirtualFree(ptr, 0, MEM_RELEASE); @@ -356,7 +356,7 @@ void OS::free_locked_pages(void* ptr, size_t length) #endif } -#if defined(BOTAN_TARGET_OS_TYPE_IS_UNIX) +#if defined(BOTAN_TARGET_OS_HAS_POSIX1) namespace { static ::sigjmp_buf g_sigill_jmp_buf; @@ -373,7 +373,7 @@ int OS::run_cpu_instruction_probe(std::function probe_fn) { volatile int probe_result = -3; -#if defined(BOTAN_TARGET_OS_TYPE_IS_UNIX) +#if defined(BOTAN_TARGET_OS_HAS_POSIX1) struct sigaction old_sigaction; struct sigaction sigaction; diff --git a/src/lib/utils/socket/socket.cpp b/src/lib/utils/socket/socket.cpp index 1020a2f5d..b75b4981c 100644 --- a/src/lib/utils/socket/socket.cpp +++ b/src/lib/utils/socket/socket.cpp @@ -20,7 +20,7 @@ #include #include -#elif defined(BOTAN_TARGET_OS_TYPE_IS_UNIX) +#elif defined(BOTAN_TARGET_OS_HAS_SOCKETS) #include #include #include @@ -30,7 +30,7 @@ #include #include -#elif defined(BOTAN_TARGET_OS_TYPE_IS_WINDOWS) && !defined(BOTAN_TARGET_OS_IS_MINGW) +#elif defined(BOTAN_TARGET_OS_HAS_WINSOCK2) #define NOMINMAX 1 #include #include @@ -136,12 +136,12 @@ class Asio_Socket final : public OS::Socket boost::asio::ip::tcp::socket m_tcp; }; -#elif defined(BOTAN_TARGET_OS_TYPE_IS_UNIX) || (defined(BOTAN_TARGET_OS_TYPE_IS_WINDOWS) && !defined(BOTAN_TARGET_OS_IS_MINGW)) +#elif defined(BOTAN_TARGET_OS_HAS_SOCKETS) || defined(BOTAN_TARGET_OS_HAS_WINSOCK2) class BSD_Socket final : public OS::Socket { private: -#if defined(BOTAN_TARGET_OS_TYPE_IS_WINDOWS) +#if defined(BOTAN_TARGET_OS_HAS_WINSOCK2) typedef SOCKET socket_type; typedef int socket_op_ret_type; static socket_type invalid_socket() { return INVALID_SOCKET; } @@ -356,7 +356,7 @@ OS::open_socket(const std::string& hostname, #if defined(BOTAN_HAS_BOOST_ASIO) return std::unique_ptr(new Asio_Socket(hostname, service, timeout)); -#elif defined(BOTAN_TARGET_OS_TYPE_IS_UNIX) || (defined(BOTAN_TARGET_OS_TYPE_IS_WINDOWS) && !defined(BOTAN_TARGET_OS_IS_MINGW)) +#elif defined(BOTAN_TARGET_OS_HAS_SOCKETS) || defined(BOTAN_TARGET_OS_HAS_WINSOCK2) return std::unique_ptr(new BSD_Socket(hostname, service, timeout)); #else -- cgit v1.2.3