diff options
-rw-r--r-- | src/lib/utils/os_utils.cpp | 34 | ||||
-rw-r--r-- | src/lib/utils/os_utils.h | 3 | ||||
-rw-r--r-- | src/tests/test_os_utils.cpp | 4 |
3 files changed, 11 insertions, 30 deletions
diff --git a/src/lib/utils/os_utils.cpp b/src/lib/utils/os_utils.cpp index fc401c3c1..fe45ad82f 100644 --- a/src/lib/utils/os_utils.cpp +++ b/src/lib/utils/os_utils.cpp @@ -360,26 +360,17 @@ int OS::run_cpu_instruction_probe(std::function<int ()> probe_fn) if(rc != 0) throw Exception("run_cpu_instruction_probe sigaction failed"); - try - { - rc = ::sigsetjmp(g_sigill_jmp_buf, /*save sigs*/1); + rc = ::sigsetjmp(g_sigill_jmp_buf, /*save sigs*/1); - if(rc == 0) - { - // first call to sigsetjmp - probe_result = probe_fn(); - } - else if(rc == 1) - { - // non-local return from siglongjmp in signal handler: return error - probe_result = -1; - } - else - throw Exception("run_cpu_instruction_probe unexpected sigsetjmp return value"); + if(rc == 0) + { + // first call to sigsetjmp + probe_result = probe_fn(); } - catch(...) + else if(rc == 1) { - probe_result = -2; + // non-local return from siglongjmp in signal handler: return error + probe_result = -1; } // Restore old SIGILL handler, if any @@ -392,14 +383,7 @@ int OS::run_cpu_instruction_probe(std::function<int ()> probe_fn) // Windows SEH __try { - try - { - probe_result = probe_fn(); - } - catch(...) - { - probe_result = -2; - } + probe_result = probe_fn(); } __except(::GetExceptionCode() == EXCEPTION_ILLEGAL_INSTRUCTION ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH) diff --git a/src/lib/utils/os_utils.h b/src/lib/utils/os_utils.h index a1693bcc5..cae1192f1 100644 --- a/src/lib/utils/os_utils.h +++ b/src/lib/utils/os_utils.h @@ -98,9 +98,10 @@ void free_locked_pages(void* ptr, size_t length); * thread safe. It should only be called in a single-threaded context * (ie, at static init time). * +* If probe_fn throws an exception the result is undefined. +* * Return codes: * -1 illegal instruction detected -* -2 exception thrown */ int BOTAN_DLL run_cpu_instruction_probe(std::function<int ()> probe_fn); diff --git a/src/tests/test_os_utils.cpp b/src/tests/test_os_utils.cpp index 58858a4c2..d779f41de 100644 --- a/src/tests/test_os_utils.cpp +++ b/src/tests/test_os_utils.cpp @@ -146,10 +146,6 @@ class OS_Utils_Tests : public Test result.confirm("Correct result returned by working probe fn", run_rc == 5); - std::function<int ()> throw_fn = []() -> int { throw 3.14159; return 5; }; - const int throw_rc = Botan::OS::run_cpu_instruction_probe(throw_fn); - result.confirm("Error return if probe function threw exception", throw_rc < 0); - std::function<int ()> crash_probe; #if defined(BOTAN_TARGET_COMPILER_IS_MSVC) |