Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
1.8 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. gs_support.c
  5. Abstract:
  6. This module contains the support for the compiler /GS switch
  7. Author:
  8. Bryan Tuttle (bryant) 01-aug-2000
  9. Revision History:
  10. Initial version copied from CRT source. Code must be generic to link into
  11. usermode or kernemode. Limited to calling ntdll/ntoskrnl exports or using
  12. shared memory data.
  13. --*/
  14. #include <nt.h>
  15. #include <ntrtl.h>
  16. #include <nturtl.h>
  17. #include <windows.h>
  18. FARPROC __gs_AltFailFunction;
  19. extern FARPROC __gs_pfUnhandledExceptionFilter;
  20. void __cdecl __report_gsfailure(void)
  21. {
  22. //
  23. // Don't call DbgPrint by default since it generates a Ctrl-C
  24. // exception as part of outputting to the debugger and we
  25. // can't trust exception handling at this point.
  26. //
  27. // DbgPrint("***** Stack overwrite detected in %ws *****\n",
  28. // NtCurrentPeb()->ProcessParameters->CommandLine.Buffer);
  29. //
  30. // Fake an exception. We can't raise an exception for real since
  31. // the stack (and therefore exception handling) can't be trusted.
  32. //
  33. if (__gs_AltFailFunction) {
  34. __gs_AltFailFunction();
  35. }
  36. if (__gs_pfUnhandledExceptionFilter)
  37. {
  38. EXCEPTION_RECORD ExceptionRecord = {0};
  39. CONTEXT ContextRecord = {0};
  40. EXCEPTION_POINTERS ExceptionPointers;
  41. ExceptionRecord.ExceptionCode = STATUS_STACK_BUFFER_OVERRUN;
  42. ExceptionPointers.ExceptionRecord = &ExceptionRecord;
  43. ExceptionPointers.ContextRecord = &ContextRecord;
  44. SetUnhandledExceptionFilter(NULL); // Make sure any filter already in place is deleted.
  45. __gs_pfUnhandledExceptionFilter(&ExceptionPointers);
  46. }
  47. TerminateProcess(GetCurrentProcess(), ERROR_STACK_BUFFER_OVERRUN);
  48. }