[CMAKE] Fix GCC -fstack-protector usage

This commit is contained in:
Jérôme Gardou 2020-12-31 17:56:39 +01:00
parent a853102a7b
commit c8d07514c8
15 changed files with 121 additions and 35 deletions

View file

@ -1,23 +1,65 @@
#define FAST_FAIL_STACK_COOKIE_CHECK_FAILURE 2
#ifdef _GCC_SSP_MSVCRT_
#include <windef.h>
#include <winbase.h>
#include <stdio.h>
#define print_caller() do { \
char buffer[64]; \
_snprintf(buffer, sizeof(buffer), "STACK PROTECTOR FAULT AT %p\n", __builtin_extract_return_addr(__builtin_return_address (0))); \
OutputDebugStringA(buffer); \
} while(0)
#elif defined(_GCC_SSP_WIN32K_)
#include <windef.h>
#include <wingdi.h>
#include <winddi.h>
#include <stdarg.h>
static inline
void
print_caller_helper(char* fmt, ...)
{
va_list args;
va_start(args, fmt);
EngDebugPrint("", fmt, args);
va_end(args);
}
#define print_caller() print_caller_helper("STACK PROTECTOR FAULT AT %p\n", __builtin_extract_return_addr(__builtin_return_address(0)))
#elif defined(_GCC_SSP_SCSIPORT_)
#include <ntddk.h>
#include <srb.h>
#define print_caller() ScsiDebugPrint(0, "STACK PROTECTOR FAULT AT %p\n", __builtin_extract_return_addr(__builtin_return_address(0)))
#elif defined(_GCC_SSP_VIDEOPRT_)
#include <ntdef.h>
#include <miniport.h>
#include <video.h>
#define print_caller() VideoPortDebugPrint(0, "STACK PROTECTOR FAULT AT %p\n", __builtin_extract_return_addr(__builtin_return_address(0)))
#else
#include <ntdef.h>
#include <debug.h>
#define print_caller() DbgPrint("STACK PROTECTOR FAULT AT %p\n", __builtin_extract_return_addr(__builtin_return_address(0)))
#endif
/* Should be random :-/ */
void * __stack_chk_guard = (void*)0xf00df00d;
#if 0
void __stack_chk_guard_setup()
{
unsigned char * p;
p = (unsigned char *)&__stack_chk_guard; // *** Notice that this takes the address of __stack_chk_guard ***
/* If you have the ability to generate random numbers in your kernel then use them,
otherwise for 32-bit code: */
*p = 0x00000aff; // *** p is &__stack_chk_guard so *p writes to __stack_chk_guard rather than *__stack_chk_guard ***
}
#endif
void * __stack_chk_guard = (void*)0xb00fbeefbaafb00f;
void __stack_chk_fail()
{
/* Like __fastfail */
__asm__("int $0x29" : : "c"(FAST_FAIL_STACK_COOKIE_CHECK_FAILURE) : "memory");
print_caller();
__asm__("int $3");
}