2 Base Stack Check library for GCC/clang.
4 Use -fstack-protector-all compiler flag to make the compiler insert the
5 __stack_chk_guard "canary" value into the stack and check the value prior
6 to exiting the function. If the "canary" is overwritten __stack_chk_fail()
7 is called. This is GCC specific code.
9 Copyright (c) 2012, Apple Inc. All rights reserved.<BR>
10 SPDX-License-Identifier: BSD-2-Clause-Patent
15 #include <Library/BaseLib.h>
16 #include <Library/DebugLib.h>
17 #include <Library/PcdLib.h>
19 /// "canary" value that is inserted by the compiler into the stack frame.
20 VOID
*__stack_chk_guard
= (VOID
*)0x0AFF;
22 // If ASLR was enabled we could use
23 //void (*__stack_chk_guard)(void) = __stack_chk_fail;
26 Error path for compiler generated stack "canary" value check code. If the
27 stack canary has been overwritten this function gets called on exit of the
35 UINT8 DebugPropertyMask
;
37 DEBUG ((DEBUG_ERROR
, "STACK FAULT: Buffer Overflow in function %a.\n", __builtin_return_address(0)));
40 // Generate a Breakpoint, DeadLoop, or NOP based on PCD settings even if
41 // BaseDebugLibNull is in use.
43 DebugPropertyMask
= PcdGet8 (PcdDebugPropertyMask
);
44 if ((DebugPropertyMask
& DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED
) != 0) {
46 } else if ((DebugPropertyMask
& DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED
) != 0) {