VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/BaseStackCheckLib/BaseStackCheckGcc.c@ 85716

Last change on this file since 85716 was 80721, checked in by vboxsync, 5 years ago

Devices/EFI/FirmwareNew: Start upgrade process to edk2-stable201908 (compiles on Windows and works to some extent), bugref:4643

  • Property svn:eol-style set to native
File size: 1.4 KB
Line 
1/** @file
2 Base Stack Check library for GCC/clang.
3
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.
8
9 Copyright (c) 2012, Apple Inc. All rights reserved.<BR>
10 SPDX-License-Identifier: BSD-2-Clause-Patent
11
12**/
13
14#include <Base.h>
15#include <Library/BaseLib.h>
16#include <Library/DebugLib.h>
17#include <Library/PcdLib.h>
18
19/// "canary" value that is inserted by the compiler into the stack frame.
20VOID *__stack_chk_guard = (VOID*)0x0AFF;
21
22// If ASLR was enabled we could use
23//void (*__stack_chk_guard)(void) = __stack_chk_fail;
24
25/**
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
28 function.
29**/
30VOID
31__stack_chk_fail (
32 VOID
33 )
34{
35 UINT8 DebugPropertyMask;
36
37 DEBUG ((DEBUG_ERROR, "STACK FAULT: Buffer Overflow in function %a.\n", __builtin_return_address(0)));
38
39 //
40 // Generate a Breakpoint, DeadLoop, or NOP based on PCD settings even if
41 // BaseDebugLibNull is in use.
42 //
43 DebugPropertyMask = PcdGet8 (PcdDebugPropertyMask);
44 if ((DebugPropertyMask & DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED) != 0) {
45 CpuBreakpoint ();
46 } else if ((DebugPropertyMask & DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED) != 0) {
47 CpuDeadLoop ();
48 }
49}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette