]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/BaseStackCheckLib/BaseStackCheckGcc.c
MdePkg/Library/BaseLib/AArch64: Comment style harmonization
[mirror_edk2.git] / MdePkg / Library / BaseStackCheckLib / BaseStackCheckGcc.c
CommitLineData
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
10 This program and the accompanying materials\r
11 are licensed and made available under the terms and conditions of the BSD License\r
12 which accompanies this distribution. The full text of the license may be found at\r
13 http://opensource.org/licenses/bsd-license.php.\r
14\r
15 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
16 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
17\r
18**/\r
19\r
20#include <Base.h>\r
21#include <Library/BaseLib.h>\r
22#include <Library/DebugLib.h>\r
23#include <Library/PcdLib.h>\r
24\r
25/// "canary" value that is inserted by the compiler into the stack frame.\r
66c6d4d6 26VOID *__stack_chk_guard = (VOID*)0x0AFF;\r
5e5fb415
AF
27\r
28// If ASLR was enabled we could use\r
29//void (*__stack_chk_guard)(void) = __stack_chk_fail;\r
30\r
31/**\r
32 Error path for compiler generated stack "canary" value check code. If the\r
33 stack canary has been overwritten this function gets called on exit of the\r
34 function.\r
35**/\r
36VOID\r
37__stack_chk_fail (\r
38 VOID\r
39 )\r
40{\r
41 UINT8 DebugPropertyMask;\r
42\r
43 DEBUG ((DEBUG_ERROR, "STACK FAULT: Buffer Overflow in function %a.\n", __builtin_return_address(0)));\r
44\r
45 //\r
46 // Generate a Breakpoint, DeadLoop, or NOP based on PCD settings even if\r
47 // BaseDebugLibNull is in use.\r
48 //\r
49 DebugPropertyMask = PcdGet8 (PcdDebugPropertyMask);\r
50 if ((DebugPropertyMask & DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED) != 0) {\r
51 CpuBreakpoint ();\r
52 } else if ((DebugPropertyMask & DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED) != 0) {\r
53 CpuDeadLoop ();\r
54 }\r
55}\r