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.

95 lines
2.7 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 2002
  5. //
  6. // File: cichkstk.hxx
  7. //
  8. // Contents: Function for determining of the committed stack is about
  9. // to run out, since we can't recover from a failure to commit.
  10. //
  11. // Throws an exception if there is less than a page of memory
  12. // left. Even if there are sufficient resources to grow the
  13. // stack we abort the operation, which is typically a query
  14. // being parsed in a recursive function in a thread with a stack
  15. // of at least 16k.
  16. //
  17. // History: 09-may-02 dlee Created
  18. //
  19. //---------------------------------------------------------------------------
  20. #pragma once
  21. //+---------------------------------------------------------------------------
  22. //
  23. // Class: CTrackRecursionDepth<class T>
  24. //
  25. // Purpose: Increments and decrements recursion depth on a class T. The
  26. // class itself can decide if it should fail the request.
  27. //
  28. // History: 09-may-02 dlee Created
  29. //
  30. //----------------------------------------------------------------------------
  31. template <class T> class CTrackRecursionDepth
  32. {
  33. public:
  34. CTrackRecursionDepth( T & item ) :
  35. _item( item )
  36. {
  37. _item.IncrementRecursionDepth();
  38. }
  39. ~CTrackRecursionDepth()
  40. {
  41. _item.DecrementRecursionDepth();
  42. }
  43. private :
  44. T & _item;
  45. };
  46. //+---------------------------------------------------------------------------
  47. //
  48. // Function: ciThrowIfLowOnStack
  49. //
  50. // Purpose: Raises an exception if we're almost out of stack space
  51. //
  52. // History: 09-may-02 dlee Created
  53. //
  54. //----------------------------------------------------------------------------
  55. #if defined (_X86_)
  56. #define TeStackBase 4
  57. #define TeStackLimit 8
  58. #define cbLowStackRemaining 0x1000
  59. #pragma warning (disable:4035)
  60. __forceinline BYTE * CurrentStackLocation() { __asm mov eax, ebp }
  61. #pragma warning (default:4035)
  62. inline void ciThrowIfLowOnStack()
  63. {
  64. struct _TEB * pteb = NtCurrentTeb();
  65. BYTE * pb = (BYTE *) pteb;
  66. BYTE * pbStackLimit = * (BYTE **) (pb + TeStackLimit);
  67. BYTE * pbStackCurrent = CurrentStackLocation();
  68. Win4Assert( pbStackLimit <= pbStackCurrent );
  69. if ( ( pbStackCurrent - pbStackLimit ) < cbLowStackRemaining )
  70. THROW( CException( STATUS_INSUFFICIENT_RESOURCES ) );
  71. }
  72. #else // _X86_
  73. // Not implemented for other platforms yet.
  74. #define ciThrowIfLowOnStack()
  75. #endif // _X86_