aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2017-12-13 17:57:31 -0500
committerJack Lloyd <[email protected]>2017-12-30 14:15:51 -0500
commit092114e11c27de26a53aefa08547cc0bc44717ca (patch)
tree38b26479b272cd6fa60deb2b995f0d116087b331 /src/lib
parent2d3cee8b02a1823ef05eedbbd3e435131460635a (diff)
Test OS features by the feature vs the OS name
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/entropy/darwin_secrandom/info.txt7
-rw-r--r--src/lib/entropy/dev_random/info.txt19
-rw-r--r--src/lib/entropy/getentropy/info.txt6
-rw-r--r--src/lib/entropy/proc_walk/info.txt16
-rw-r--r--src/lib/entropy/win32_stats/info.txt8
-rw-r--r--src/lib/filters/fd_unix/info.txt18
-rw-r--r--src/lib/rng/system_rng/info.txt27
-rw-r--r--src/lib/utils/calendar.cpp4
-rw-r--r--src/lib/utils/dyn_load/dyn_load.cpp21
-rw-r--r--src/lib/utils/dyn_load/info.txt15
-rw-r--r--src/lib/utils/filesystem.cpp13
-rw-r--r--src/lib/utils/locking_allocator/info.txt11
-rw-r--r--src/lib/utils/mutex.h4
-rw-r--r--src/lib/utils/os_utils.cpp24
-rw-r--r--src/lib/utils/socket/socket.cpp10
15 files changed, 69 insertions, 134 deletions
diff --git a/src/lib/entropy/darwin_secrandom/info.txt b/src/lib/entropy/darwin_secrandom/info.txt
index 477818818..c1943a04a 100644
--- a/src/lib/entropy/darwin_secrandom/info.txt
+++ b/src/lib/entropy/darwin_secrandom/info.txt
@@ -6,10 +6,9 @@ ENTROPY_SRC_DARWIN_SECRANDOM -> 20150925
darwin_secrandom.h
</header:internal>
-<os>
-darwin
-ios
-</os>
+<os_features>
+security_framework
+</os_features>
<frameworks>
darwin -> Security
diff --git a/src/lib/entropy/dev_random/info.txt b/src/lib/entropy/dev_random/info.txt
index d22f18211..3872411f3 100644
--- a/src/lib/entropy/dev_random/info.txt
+++ b/src/lib/entropy/dev_random/info.txt
@@ -6,19 +6,6 @@ ENTROPY_SRC_DEV_RANDOM -> 20131128
dev_random.h
</header:internal>
-<os>
-aix
-android
-cygwin
-darwin
-dragonfly
-freebsd
-haiku
-hpux
-hurd
-linux
-netbsd
-openbsd
-qnx
-solaris
-</os>
+<os_features>
+dev_random,posix1
+</os_features>
diff --git a/src/lib/entropy/getentropy/info.txt b/src/lib/entropy/getentropy/info.txt
index a44299cbe..886e57151 100644
--- a/src/lib/entropy/getentropy/info.txt
+++ b/src/lib/entropy/getentropy/info.txt
@@ -6,6 +6,6 @@ ENTROPY_SRC_GETENTROPY -> 20170327
getentropy.h
</header:internal>
-<os>
-openbsd
-</os>
+<os_features>
+getentropy
+</os_features>
diff --git a/src/lib/entropy/proc_walk/info.txt b/src/lib/entropy/proc_walk/info.txt
index f93d0cb3f..2bba7e276 100644
--- a/src/lib/entropy/proc_walk/info.txt
+++ b/src/lib/entropy/proc_walk/info.txt
@@ -6,16 +6,6 @@ ENTROPY_SRC_PROC_WALKER -> 20131128
proc_walk.h
</header:internal>
-<os>
-android
-aix
-cygwin
-darwin
-dragonfly
-hpux
-hurd
-linux
-netbsd
-qnx
-solaris
-</os>
+<os_features>
+posix1,proc_fs
+</os_features>
diff --git a/src/lib/entropy/win32_stats/info.txt b/src/lib/entropy/win32_stats/info.txt
index 7c84fc235..68abae34e 100644
--- a/src/lib/entropy/win32_stats/info.txt
+++ b/src/lib/entropy/win32_stats/info.txt
@@ -6,11 +6,9 @@ ENTROPY_SRC_WIN32 -> 20131128
es_win32.h
</header:internal>
-<os>
-windows
-cygwin
-mingw
-</os>
+<os_features>
+win32
+</os_features>
<libs>
windows -> user32.lib
diff --git a/src/lib/filters/fd_unix/info.txt b/src/lib/filters/fd_unix/info.txt
index 4679cb4d5..41e7a23a5 100644
--- a/src/lib/filters/fd_unix/info.txt
+++ b/src/lib/filters/fd_unix/info.txt
@@ -4,18 +4,6 @@ PIPE_UNIXFD_IO -> 20131128
load_on auto
-<os>
-android
-aix
-cygwin
-darwin
-dragonfly
-freebsd
-haiku
-hpux
-linux
-netbsd
-openbsd
-qnx
-solaris
-</os>
+<os_features>
+posix1
+</os_features>
diff --git a/src/lib/rng/system_rng/info.txt b/src/lib/rng/system_rng/info.txt
index 0c04fa21c..8f25bf84c 100644
--- a/src/lib/rng/system_rng/info.txt
+++ b/src/lib/rng/system_rng/info.txt
@@ -2,27 +2,12 @@
SYSTEM_RNG -> 20141202
</defines>
-<os>
-aix
-android
-cygwin
-darwin
-dragonfly
-freebsd
-haiku
-hpux
-hurd
-includeos
-ios
-linux
-mingw
-netbsd
-openbsd
-qnx
-solaris
-windows
-winphone
-</os>
+<os_features>
+dev_random,posix1
+arc4random
+crypto_ng
+cryptgenrandom
+</os_features>
<libs>
windows -> advapi32.lib
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 <botan/dyn_load.h>
#include <botan/exceptn.h>
-#if defined(BOTAN_TARGET_OS_HAS_DLOPEN)
+#if defined(BOTAN_TARGET_OS_HAS_POSIX1)
#include <dlfcn.h>
-#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 <windows.h>
@@ -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<void*>(::GetProcAddress((HMODULE)m_lib,
- symbol.c_str()));
+#elif defined(BOTAN_TARGET_OS_HAS_WIN32)
+ addr = reinterpret_cast<void*>(::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
-<os>
-android
-freebsd
-linux
-netbsd
-openbsd
-qnx
-solaris
-windows
-darwin
-</os>
+<os_features>
+posix1
+win32
+</os_features>
<libs>
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 <filesystem>
#elif defined(BOTAN_HAS_BOOST_FILESYSTEM)
#include <boost/filesystem.hpp>
-#elif defined(BOTAN_TARGET_OS_HAS_READDIR)
+#elif defined(BOTAN_TARGET_OS_HAS_POSIX1)
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include <deque>
#include <memory>
#include <functional>
-#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 <windows.h>
@@ -74,7 +74,8 @@ std::vector<std::string> 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<std::string> impl_readdir(const std::string& dir_path)
{
std::vector<std::string> out;
@@ -113,7 +114,7 @@ std::vector<std::string> 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<std::string> impl_win32(const std::string& dir_path)
{
@@ -167,9 +168,9 @@ std::vector<std::string> 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
</defines>
-<os>
-linux
-freebsd
-openbsd
-netbsd
-windows
-</os>
+<os_features>
+posix1
+virtual_lock
+</os_features>
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<typename T> using lock_guard_type = lock_guard<T>;
}
-#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 <string.h>
#endif
-#if defined(BOTAN_TARGET_OS_TYPE_IS_UNIX)
+#if defined(BOTAN_TARGET_OS_HAS_POSIX1)
#include <sys/types.h>
#include <sys/resource.h>
#include <sys/mman.h>
@@ -26,7 +26,7 @@
#include <setjmp.h>
#include <unistd.h>
#include <errno.h>
-#elif defined(BOTAN_TARGET_OS_TYPE_IS_WINDOWS)
+#elif defined(BOTAN_TARGET_OS_HAS_WIN32)
#define NOMINMAX 1
#include <windows.h>
#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<int ()> 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 <boost/asio.hpp>
#include <boost/asio/system_timer.hpp>
-#elif defined(BOTAN_TARGET_OS_TYPE_IS_UNIX)
+#elif defined(BOTAN_TARGET_OS_HAS_SOCKETS)
#include <sys/socket.h>
#include <sys/time.h>
#include <netinet/in.h>
@@ -30,7 +30,7 @@
#include <errno.h>
#include <fcntl.h>
-#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 <winsock2.h>
#include <ws2tcpip.h>
@@ -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<OS::Socket>(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<OS::Socket>(new BSD_Socket(hostname, service, timeout));
#else