diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/build-data/cc/clang.txt | 1 | ||||
-rw-r--r-- | src/build-data/os/emscripten.txt | 16 | ||||
-rw-r--r-- | src/cli/pubkey.cpp | 1 | ||||
-rw-r--r-- | src/lib/utils/os_utils.cpp | 18 | ||||
-rw-r--r-- | src/tests/test_os_utils.cpp | 10 | ||||
-rw-r--r-- | src/tests/test_rng.cpp | 4 |
6 files changed, 42 insertions, 8 deletions
diff --git a/src/build-data/cc/clang.txt b/src/build-data/cc/clang.txt index 47ab837b5..9cb7e4b21 100644 --- a/src/build-data/cc/clang.txt +++ b/src/build-data/cc/clang.txt @@ -42,6 +42,7 @@ linux -> "$(LINKER) -Wl,-rpath=\$$ORIGIN" freebsd -> "$(LINKER) -Wl,-rpath=\$$ORIGIN" default -> "$(LINKER)" llvm -> "llvm-link" +emscripten -> "em++" </binary_link_commands> <isa_flags> diff --git a/src/build-data/os/emscripten.txt b/src/build-data/os/emscripten.txt new file mode 100644 index 000000000..b865eff87 --- /dev/null +++ b/src/build-data/os/emscripten.txt @@ -0,0 +1,16 @@ + +obj_suffix bc + +static_suffix a +program_suffix .bc + +ar_command emar +ar_options cr + +use_stack_protector no + +<target_features> +filesystem +dev_random +posix1 +</target_features> diff --git a/src/cli/pubkey.cpp b/src/cli/pubkey.cpp index f95176c65..46655a6ae 100644 --- a/src/cli/pubkey.cpp +++ b/src/cli/pubkey.cpp @@ -11,6 +11,7 @@ #include <botan/base64.h> #include <botan/hex.h> +#include <botan/rng.h> #include <botan/pk_keys.h> #include <botan/x509_key.h> diff --git a/src/lib/utils/os_utils.cpp b/src/lib/utils/os_utils.cpp index 86e5443c3..0d98df867 100644 --- a/src/lib/utils/os_utils.cpp +++ b/src/lib/utils/os_utils.cpp @@ -28,6 +28,10 @@ #include <errno.h> #endif +#if defined(BOTAN_TARGET_OS_IS_EMSCRIPTEN) + #include <emscripten/emscripten.h> +#endif + #if defined(BOTAN_TARGET_OS_HAS_GETAUXVAL) #include <sys/auxv.h> #endif @@ -157,6 +161,10 @@ uint64_t OS::get_high_resolution_clock() if(uint64_t cpu_clock = OS::get_processor_timestamp()) return cpu_clock; +#if defined(BOTAN_TARGET_OS_IS_EMSCRIPTEN) + return emscripten_get_now(); +#endif + /* If we got here either we either don't have an asm instruction above, or (for x86) RDTSC is not available at runtime. Try some @@ -235,7 +243,7 @@ size_t OS::system_page_size() size_t OS::get_memory_locking_limit() { -#if defined(BOTAN_TARGET_OS_HAS_POSIX1) && defined(RLIMIT_MEMLOCK) +#if defined(BOTAN_TARGET_OS_HAS_POSIX1) && defined(BOTAN_TARGET_OS_HAS_POSIX_MLOCK) && defined(RLIMIT_MEMLOCK) /* * If RLIMIT_MEMLOCK is not defined, likely the OS does not support * unprivileged mlock calls. @@ -392,7 +400,8 @@ void OS::free_locked_pages(void* ptr, size_t length) #endif } -#if defined(BOTAN_TARGET_OS_HAS_POSIX1) +#if defined(BOTAN_TARGET_OS_HAS_POSIX1) && !defined(BOTAN_TARGET_OS_IS_EMSCRIPTEN) + namespace { static ::sigjmp_buf g_sigill_jmp_buf; @@ -403,13 +412,14 @@ void botan_sigill_handler(int) } } + #endif int OS::run_cpu_instruction_probe(std::function<int ()> probe_fn) { volatile int probe_result = -3; -#if defined(BOTAN_TARGET_OS_HAS_POSIX1) +#if defined(BOTAN_TARGET_OS_HAS_POSIX1) && !defined(BOTAN_TARGET_OS_IS_EMSCRIPTEN) struct sigaction old_sigaction; struct sigaction sigaction; @@ -453,6 +463,8 @@ int OS::run_cpu_instruction_probe(std::function<int ()> probe_fn) probe_result = -1; } +#else + BOTAN_UNUSED(probe_fn); #endif return probe_result; diff --git a/src/tests/test_os_utils.cpp b/src/tests/test_os_utils.cpp index b441b34ae..1cf1d4d65 100644 --- a/src/tests/test_os_utils.cpp +++ b/src/tests/test_os_utils.cpp @@ -92,15 +92,15 @@ class OS_Utils_Tests final : public Test Test::Result result("OS::get_high_resolution_clock"); - uint64_t hr_ts1 = Botan::OS::get_high_resolution_clock(); + const uint64_t hr_ts1 = Botan::OS::get_high_resolution_clock(); result.test_ne("high resolution timestamp value is never zero", hr_ts1, 0); - // do something that consumes a little time - Botan::OS::get_process_id(); + size_t counts = 0; + while(counts < 100 && (Botan::OS::get_high_resolution_clock() == hr_ts1)) + ++counts; - uint64_t hr_ts2 = Botan::OS::get_high_resolution_clock(); + result.test_lt("high resolution clock eventually changes value", counts, 128); - result.test_ne("high resolution timestamp does not duplicate", hr_ts1, hr_ts2); return result; } diff --git a/src/tests/test_rng.cpp b/src/tests/test_rng.cpp index a7a83134f..0b316335e 100644 --- a/src/tests/test_rng.cpp +++ b/src/tests/test_rng.cpp @@ -296,7 +296,11 @@ class Stateful_RNG_Tests : public Test pid_t pid = ::fork(); if(pid == -1) { +#if defined(BOTAN_TARGET_OS_IS_EMSCRIPTEN) + result.test_note("failed to fork process"); +#else result.test_failure("failed to fork process"); +#endif return result; } else if(pid != 0) |