Source code of Windows XP (NT5)
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.

145 lines
2.7 KiB

  1. /*++
  2. Copyright (c) 1993 Microsoft Corporation
  3. Module Name:
  4. memory.c
  5. Abstract:
  6. Memory handling routines for Windows NT Setup API dll.
  7. Author:
  8. Ted Miller (tedm) 11-Jan-1995
  9. Revision History:
  10. Jamie Hunter (jamiehun) 13-Feb-1998
  11. Improved this further for debugging
  12. added linked list,
  13. alloc tracing,
  14. memory fills
  15. and memory leak detection
  16. jamiehun 30-April-1998
  17. Added some more consistancy checks
  18. Put try/except around access
  19. jimschm 27-Oct-1998
  20. Wrote fast allocation routines to speed up setupapi.dll on Win9x
  21. --*/
  22. #include "precomp.h"
  23. #pragma hdrstop
  24. //
  25. // String to be used when displaying insufficient memory msg box.
  26. // We load it at process attach time so we can be guaranteed of
  27. // being able to display it.
  28. //
  29. PCTSTR OutOfMemoryString;
  30. #if MEM_DBG
  31. DWORD g_Track = 0;
  32. PCSTR g_TrackFile = NULL;
  33. UINT g_TrackLine = 0;
  34. DWORD g_MemoryFlags = 0; // set this to 1 in the debugger to catch some extra dbg assertions.
  35. DWORD g_DbgAllocNum = -1; // set g_MemoryFlags to 1 and this to the allocation number you want
  36. // to catch if the same number allocation leaks every time.
  37. VOID
  38. SetTrackFileAndLine (
  39. PCSTR File,
  40. UINT Line
  41. )
  42. {
  43. if (!g_Track) {
  44. g_TrackFile = File;
  45. g_TrackLine = Line;
  46. }
  47. g_Track++;
  48. }
  49. VOID
  50. ClrTrackFileAndLine (
  51. VOID
  52. )
  53. {
  54. if (g_Track) {
  55. g_Track--;
  56. if (!g_Track) {
  57. g_TrackFile = NULL;
  58. g_TrackLine = 0;
  59. }
  60. }
  61. }
  62. PVOID MyDebugMalloc(
  63. IN DWORD Size,
  64. IN PCSTR Filename,
  65. IN DWORD Line,
  66. IN DWORD Tag
  67. )
  68. {
  69. return pSetupDebugMallocWithTag(Size,
  70. g_TrackFile ? g_TrackFile : Filename,
  71. g_TrackLine ? g_TrackLine : Line,
  72. Tag
  73. );
  74. }
  75. #endif
  76. BOOL
  77. MemoryInitializeEx(
  78. IN BOOL Attach
  79. )
  80. {
  81. if (Attach) {
  82. OutOfMemoryString = MyLoadString(IDS_OUTOFMEMORY);
  83. return(OutOfMemoryString != NULL);
  84. } else {
  85. MyFree(OutOfMemoryString);
  86. return(TRUE);
  87. }
  88. }
  89. VOID
  90. pSetupOutOfMemory(
  91. IN HWND Owner OPTIONAL
  92. )
  93. {
  94. //
  95. // Don't popup a dialog if we're not running interactively...
  96. //
  97. if(!(GlobalSetupFlags & PSPGF_NONINTERACTIVE)) {
  98. MYASSERT(OutOfMemoryString);
  99. //
  100. // Use special combination of flags that guarantee
  101. // display of the message box regardless of available memory.
  102. //
  103. MessageBox(
  104. Owner,
  105. OutOfMemoryString,
  106. NULL,
  107. MB_ICONHAND | MB_SYSTEMMODAL | MB_OK | MB_SETFOREGROUND
  108. );
  109. }
  110. }