[CMAKE] Fix GCC -fstack-protector usage
[reactos.git] / sdk / lib / gcc_ssp / gcc_ssp.c
index 58e662c..cb3664d 100644 (file)
@@ -1,23 +1,65 @@
 
-#define FAST_FAIL_STACK_COOKIE_CHECK_FAILURE 2
+#ifdef _GCC_SSP_MSVCRT_
 
-/* Should be random :-/ */
-void * __stack_chk_guard = (void*)0xf00df00d;
+#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_)
 
-#if 0
-void __stack_chk_guard_setup()
+#include <windef.h>
+#include <wingdi.h>
+#include <winddi.h>
+#include <stdarg.h>
+
+static inline
+void
+print_caller_helper(char* fmt, ...)
 {
-    unsigned char * p;
-    p = (unsigned char *)&__stack_chk_guard; // *** Notice that this takes the address of __stack_chk_guard  ***
+    va_list args;
 
-    /* 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 ***
+    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*)0xb00fbeefbaafb00f;
+
 void __stack_chk_fail()
 {
-    /* Like __fastfail */
-    __asm__("int $0x29" : : "c"(FAST_FAIL_STACK_COOKIE_CHECK_FAILURE) : "memory");
+    print_caller();
+    __asm__("int $3");
 }