From 88cc8a00f4a7fc34003b961c572d5a78462dd682 Mon Sep 17 00:00:00 2001 From: Mounir IDRASSI Date: Tue, 4 Jul 2017 11:19:53 +0200 Subject: Windows: correctly handle SEH exceptions during self-tests in order to disable CPU extended features in such case. --- src/Common/Tests.c | 41 ++++++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-) (limited to 'src/Common/Tests.c') diff --git a/src/Common/Tests.c b/src/Common/Tests.c index cf30e4a1..77a7aa2e 100644 --- a/src/Common/Tests.c +++ b/src/Common/Tests.c @@ -1355,18 +1355,45 @@ BOOL AutoTestAlgorithms (void) { BOOL result = TRUE; BOOL hwEncryptionEnabled = IsHwEncryptionEnabled(); +#if defined (_MSC_VER) && !defined (_UEFI) + BOOL exceptionCatched = FALSE; + __try + { +#endif + EnableHwEncryption (FALSE); - EnableHwEncryption (FALSE); + if (!DoAutoTestAlgorithms()) + result = FALSE; - if (!DoAutoTestAlgorithms()) - result = FALSE; + EnableHwEncryption (TRUE); - EnableHwEncryption (TRUE); + if (!DoAutoTestAlgorithms()) + result = FALSE; - if (!DoAutoTestAlgorithms()) - result = FALSE; + EnableHwEncryption (hwEncryptionEnabled); +#if defined (_MSC_VER) && !defined (_UEFI) + } + __except (EXCEPTION_EXECUTE_HANDLER) + { + exceptionCatched = TRUE; + } - EnableHwEncryption (hwEncryptionEnabled); + if (exceptionCatched) + { + /* unexepected exception raised. Disable all CPU extended feature and try again */ + EnableHwEncryption (hwEncryptionEnabled); + DisableCPUExtendedFeatures (); + __try + { + result = DoAutoTestAlgorithms(); + } + __except (EXCEPTION_EXECUTE_HANDLER) + { + /* exception still occuring. Report failure. */ + result = FALSE; + } + } +#endif return result; } -- cgit v1.2.3