@@ -18,33 +18,23 @@ extern "C" {
18
18
#include < Library/BaseLib.h>
19
19
#include < Library/UnitTestLib.h>
20
20
21
+ //
22
+ // If address sanitizer is enabled, then declare the function that is used to
23
+ // handle custom long jump implementation.
24
+ //
25
+ #ifdef __SANITIZE_ADDRESS__
26
+ void
27
+ __asan_handle_no_return (
28
+ );
29
+
30
+ #endif
31
+
21
32
// /
22
33
// / Point to jump buffer used with SetJump()/LongJump() to test if a function
23
34
// / under test generates an expected ASSERT() condition.
24
35
// /
25
36
BASE_LIBRARY_JUMP_BUFFER *gUnitTestExpectAssertFailureJumpBuffer = NULL ;
26
37
27
- /* *
28
- LongJump wrapper for host-based unit test environments that is declared
29
- NORETURN to avoid false positives from address sanitizer.
30
-
31
- @param JumpBuffer A pointer to CPU context buffer.
32
- @param Value The value to return when the SetJump() context is
33
- restored and must be non-zero.
34
- **/
35
- static
36
- VOID
37
- NORETURN
38
- EFIAPI
39
- HostLongJump (
40
- IN BASE_LIBRARY_JUMP_BUFFER *JumpBuffer,
41
- IN UINTN Value
42
- )
43
- {
44
- LongJump (JumpBuffer, Value);
45
- UNREACHABLE ();
46
- }
47
-
48
38
/* *
49
39
Unit test library replacement for DebugAssert() in DebugLib.
50
40
@@ -68,8 +58,18 @@ extern "C" {
68
58
69
59
if (gUnitTestExpectAssertFailureJumpBuffer != NULL ) {
70
60
UT_LOG_INFO (" Detected expected ASSERT: %a(%d): %a\n " , FileName, LineNumber, Description);
71
- HostLongJump (gUnitTestExpectAssertFailureJumpBuffer , 1 );
72
- UNREACHABLE ();
61
+
62
+ //
63
+ // If address sanitizer is enabled, then inform sanitizer that a no return
64
+ // function is being called that will reset to a previous stack frame.
65
+ // This is required to avoid false positives from the address sanitizer
66
+ // due to the use of a custom long jump implementation.
67
+ //
68
+ #ifdef __SANITIZE_ADDRESS__
69
+ __asan_handle_no_return ();
70
+ #endif
71
+
72
+ LongJump (gUnitTestExpectAssertFailureJumpBuffer , 1 );
73
73
} else {
74
74
if (GetActiveFrameworkHandle () != NULL ) {
75
75
AsciiStrCpyS (Message, sizeof (Message), " Detected unexpected ASSERT(" );
0 commit comments