]>
Commit | Line | Data |
---|---|---|
5e5fb415 AF |
1 | /** @file\r |
2 | Base Stack Check library for GCC/clang.\r | |
3 | \r | |
4 | Use -fstack-protector-all compiler flag to make the compiler insert the\r | |
5 | __stack_chk_guard "canary" value into the stack and check the value prior\r | |
6 | to exiting the function. If the "canary" is overwritten __stack_chk_fail()\r | |
7 | is called. This is GCC specific code.\r | |
8 | \r | |
9 | Copyright (c) 2012, Apple Inc. All rights reserved.<BR>\r | |
9344f092 | 10 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
5e5fb415 AF |
11 | \r |
12 | **/\r | |
13 | \r | |
14 | #include <Base.h>\r | |
15 | #include <Library/BaseLib.h>\r | |
16 | #include <Library/DebugLib.h>\r | |
17 | #include <Library/PcdLib.h>\r | |
18 | \r | |
19 | /// "canary" value that is inserted by the compiler into the stack frame.\r | |
66c6d4d6 | 20 | VOID *__stack_chk_guard = (VOID*)0x0AFF;\r |
5e5fb415 AF |
21 | \r |
22 | // If ASLR was enabled we could use\r | |
23 | //void (*__stack_chk_guard)(void) = __stack_chk_fail;\r | |
24 | \r | |
25 | /**\r | |
26 | Error path for compiler generated stack "canary" value check code. If the\r | |
27 | stack canary has been overwritten this function gets called on exit of the\r | |
28 | function.\r | |
29 | **/\r | |
30 | VOID\r | |
31 | __stack_chk_fail (\r | |
32 | VOID\r | |
33 | )\r | |
34 | {\r | |
35 | UINT8 DebugPropertyMask;\r | |
36 | \r | |
37 | DEBUG ((DEBUG_ERROR, "STACK FAULT: Buffer Overflow in function %a.\n", __builtin_return_address(0)));\r | |
38 | \r | |
39 | //\r | |
40 | // Generate a Breakpoint, DeadLoop, or NOP based on PCD settings even if\r | |
41 | // BaseDebugLibNull is in use.\r | |
42 | //\r | |
43 | DebugPropertyMask = PcdGet8 (PcdDebugPropertyMask);\r | |
44 | if ((DebugPropertyMask & DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED) != 0) {\r | |
45 | CpuBreakpoint ();\r | |
46 | } else if ((DebugPropertyMask & DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED) != 0) {\r | |
47 | CpuDeadLoop ();\r | |
48 | }\r | |
49 | }\r |