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.

81 lines
1.9 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. Jonathan Schwartz (JSchwart) 13-Dec-2001
  9. Revision History:
  10. Custom version of GS support functions for GDI drivers, which won't
  11. build if SEH (__try/__except) is used in the overflow LIB.
  12. --*/
  13. #include <nt.h>
  14. #include <ntrtl.h>
  15. #include <nturtl.h>
  16. #include <windows.h>
  17. #include <winddi.h>
  18. #include <bugcodes.h>
  19. #ifdef _WIN64
  20. #define DEFAULT_SECURITY_COOKIE 0x2B992DDFA23249D6
  21. #else
  22. #define DEFAULT_SECURITY_COOKIE 0xBB40E64E
  23. #endif
  24. typedef VOID (APIENTRY *ENG_BUGCHECK_EX)(ULONG, ULONG_PTR, ULONG_PTR, ULONG_PTR, ULONG_PTR);
  25. DECLSPEC_SELECTANY DWORD_PTR __security_cookie = DEFAULT_SECURITY_COOKIE;
  26. ENG_BUGCHECK_EX pfEngBugCheckEx;
  27. BOOL
  28. GsDrvEnableDriver(
  29. ULONG l1,
  30. ULONG l2,
  31. VOID *pv
  32. )
  33. {
  34. //
  35. // GDI drivers always run on NT so NtGetTickCount will always succeed
  36. //
  37. if (!__security_cookie || (__security_cookie == DEFAULT_SECURITY_COOKIE)) {
  38. __security_cookie = NtGetTickCount() ^ (DWORD_PTR) &__security_cookie;
  39. if (!__security_cookie) {
  40. __security_cookie = DEFAULT_SECURITY_COOKIE;
  41. }
  42. }
  43. //
  44. // GDI drivers built in the current tree but running downlevel can't link
  45. // statically to EngBugcheckEx since that was added to win32k.lib for .NET.
  46. //
  47. pfEngBugCheckEx = (ENG_BUGCHECK_EX) EngFindImageProcAddress(NULL, "EngBugCheckEx");
  48. return DrvEnableDriver(l1, l2, pv);
  49. }
  50. void __cdecl __report_gsfailure(void)
  51. {
  52. //
  53. // Bugcheck as we can't trust the stack at this point. A
  54. // backtrace will point at the guilty party. Because of
  55. // GDI driver constraints, no custom handlers are allowed.
  56. //
  57. if (pfEngBugCheckEx)
  58. {
  59. pfEngBugCheckEx(DRIVER_OVERRAN_STACK_BUFFER, 0, 0, 0, 0);
  60. }
  61. }