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.

80 lines
2.0 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 <wdm.h>
  15. #ifdef _WIN64
  16. #define DEFAULT_SECURITY_COOKIE 0x2B992DDFA23249D6
  17. #else
  18. #define DEFAULT_SECURITY_COOKIE 0xBB40E64E
  19. #endif
  20. DECLSPEC_SELECTANY DWORD_PTR __security_cookie = DEFAULT_SECURITY_COOKIE;
  21. NTSTATUS
  22. DriverEntry(
  23. IN PDRIVER_OBJECT DriverObject,
  24. IN PUNICODE_STRING RegistryPath
  25. );
  26. NTSTATUS
  27. GsDriverEntry(
  28. IN PDRIVER_OBJECT DriverObject,
  29. IN PUNICODE_STRING RegistryPath
  30. );
  31. #pragma alloc_text(INIT,GsDriverEntry)
  32. NTSTATUS
  33. GsDriverEntry(
  34. IN PDRIVER_OBJECT DriverObject,
  35. IN PUNICODE_STRING RegistryPath
  36. )
  37. {
  38. if (!__security_cookie || (__security_cookie == DEFAULT_SECURITY_COOKIE)) {
  39. // For kernel mode, we use KeTickCount. Even nicer would be to use rdtsc, but WDM still supports
  40. // 386/486 and rdtsc is pentium and above.
  41. #ifdef _X86_
  42. __security_cookie = (DWORD_PTR)(*((PKSYSTEM_TIME *)(&KeTickCount)))->LowPart ^ (DWORD_PTR) &__security_cookie;
  43. #else
  44. LARGE_INTEGER Count;
  45. KeQueryTickCount(&Count );
  46. __security_cookie = (DWORD_PTR)Count.QuadPart ^ (DWORD_PTR) &__security_cookie;
  47. #endif
  48. if (!__security_cookie) {
  49. __security_cookie = DEFAULT_SECURITY_COOKIE;
  50. }
  51. }
  52. return DriverEntry(DriverObject, RegistryPath);
  53. }
  54. void __cdecl __report_gsfailure(void)
  55. {
  56. //
  57. // Bugcheck as we can't trust the stack at this point. A
  58. // backtrace will point at the guilty party.
  59. //
  60. KeBugCheckEx(DRIVER_OVERRAN_STACK_BUFFER, 0, 0, 0, 0);
  61. }