mirror of
https://github.com/tianocore/edk2
synced 2026-08-27 00:23:19 -04:00
GCC 17 (upcoming release) is updating the type of __stack_chk_guard from a void * to a uintptr_t. This is only a type change, not a size change. However, it does cause the GCC 17 build to fail because of the type mismatch. uintptr_t is defined as unsigned long, which is not a type edk2 defines. It has the same size as UINTN on a given system, but on 64 bit systems we have the same type issue because UINTN is defined as unsigned long long, not unsigned long. To work around this and avoid defining a new type in edk2, use the compiler built in __UINTPTR_TYPE__ which is the underlying definition in GCC. This is a backwards compatible change with previous versions of GCC and CLANGDWARF but also fixes the upcoming definition change for GCC 17. Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
78 lines
2.4 KiB
C
78 lines
2.4 KiB
C
/** @file
|
|
This library provides stack cookie checking functions for symbols inserted by the compiler. This header
|
|
is not intended to be used directly by modules, but rather defines the expected interfaces to each supported
|
|
compiler, so that if the compiler interface is updated it is easier to track.
|
|
|
|
Copyright (c) Microsoft Corporation.
|
|
SPDX-License-Identifier: BSD-2-Clause-Patent
|
|
**/
|
|
|
|
#pragma once
|
|
|
|
#include <Base.h>
|
|
|
|
#if defined (__GNUC__) || defined (__clang__)
|
|
|
|
// The __stack_chk_guard is a random value placed on the stack between the stack variables
|
|
// and the return address so that continuously writing past the stack variables will cause
|
|
// the stack cookie to be overwritten. Before the function returns, the stack cookie value
|
|
// will be checked and if there is a mismatch then StackCheckLib handles the failure.
|
|
// __UINTPTR_TYPE__ will be the same bitwidth as UINTN, but is a different type that edk2 does
|
|
// not define (e.g. on X64 this is unsigned long) and so we cannot use UINTN here. Newer versions
|
|
// of GCC define this as uintptr_t, which is unsigned long on X64.
|
|
extern __UINTPTR_TYPE__ __stack_chk_guard;
|
|
|
|
/**
|
|
Called when a stack cookie check fails. The return address is the failing address.
|
|
|
|
**/
|
|
VOID
|
|
EFIAPI
|
|
__stack_chk_fail (
|
|
VOID
|
|
);
|
|
|
|
#elif defined (_MSC_VER)
|
|
|
|
// The __security_cookie is a random value placed on the stack between the stack variables
|
|
// and the return address so that continuously writing past the stack variables will cause
|
|
// the stack cookie to be overwritten. Before the function returns, the stack cookie value
|
|
// will be checked and if there is a mismatch then StackCheckLib handles the failure.
|
|
extern VOID *__security_cookie;
|
|
|
|
/**
|
|
Called when a buffer check fails. This functionality is dependent on MSVC
|
|
C runtime libraries and so is unsupported in UEFI.
|
|
|
|
**/
|
|
VOID
|
|
EFIAPI
|
|
__report_rangecheckfailure (
|
|
VOID
|
|
);
|
|
|
|
/**
|
|
The GS handler is for checking the stack cookie during SEH or
|
|
EH exceptions and is unsupported in UEFI.
|
|
|
|
**/
|
|
VOID
|
|
EFIAPI
|
|
__GSHandlerCheck (
|
|
VOID
|
|
);
|
|
|
|
/**
|
|
Checks the stack cookie value against __security_cookie and calls the
|
|
stack cookie failure handler if there is a mismatch.
|
|
|
|
@param UINTN CheckValue The value to check against __security_cookie
|
|
|
|
**/
|
|
VOID
|
|
EFIAPI
|
|
__security_check_cookie (
|
|
UINTN CheckValue
|
|
);
|
|
|
|
#endif // Compiler type
|