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.

108 lines
2.2 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. vfstack.c
  5. Abstract:
  6. This module contains code required to verify drivers don't improperly use
  7. thread stacks.
  8. Author:
  9. Adrian J. Oney (adriao) 09-May-1998
  10. Environment:
  11. Kernel mode.
  12. --*/
  13. #include "vfdef.h"
  14. #ifdef ALLOC_PRAGMA
  15. #pragma alloc_text(PAGEVRFY, VfStackSeedStack)
  16. #endif
  17. VOID
  18. FASTCALL
  19. VfStackSeedStack(
  20. IN ULONG Seed
  21. )
  22. /*++
  23. Description:
  24. This routine "seeds" the stack so that uninitialized variables are
  25. more easily ferreted out.
  26. Note if the thread subsequently does a usermode wait, the memory
  27. manager throws out the filled pages on stack swapout and on swapin
  28. replaces them with randomly filled ones.
  29. Arguments:
  30. Seed - Value to seed stack with.
  31. Return Value:
  32. None.
  33. --*/
  34. {
  35. #if !defined(_WIN64)
  36. KIRQL oldIrql;
  37. PKTHREAD Thread;
  38. PULONG StartingAddress;
  39. PULONG StackPointer;
  40. if (!VfSettingsIsOptionEnabled(NULL, VERIFIER_OPTION_SEEDSTACK)) {
  41. return;
  42. }
  43. Thread = KeGetCurrentThread ();
  44. StartingAddress = (PULONG) Thread->StackLimit;
  45. //
  46. // We are going below the stack pointer. Make sure no interrupt can occur.
  47. //
  48. KeRaiseIrql (HIGH_LEVEL, &oldIrql);
  49. _asm {
  50. mov StackPointer, esp
  51. }
  52. //
  53. // Check the stack bounds and don't fill if some caller is whacking the
  54. // stack pointer.
  55. //
  56. if ((StackPointer <= StartingAddress) || (StackPointer >= (PULONG)Thread->StackBase)) {
  57. KeLowerIrql (oldIrql);
  58. return;
  59. }
  60. //
  61. // We use the return value 0xFFFFFFFF, as it is an illegal return value. We
  62. // are trying to catch people who don't initialize NTSTATUS, and it's also
  63. // a good pointer trap too.
  64. //
  65. // Note RtlFillMemoryUlong is not used because calling it would use
  66. // additional stack which we don't want to have to account for in our
  67. // calculations.
  68. //
  69. while (StartingAddress < StackPointer) {
  70. *StartingAddress = Seed;
  71. StartingAddress += 1;
  72. }
  73. KeLowerIrql (oldIrql);
  74. #else
  75. UNREFERENCED_PARAMETER (Seed);
  76. #endif
  77. }