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.

153 lines
3.3 KiB

  1. /************************************************************/
  2. /* Windows Write, Copyright 1985-1992 Microsoft Corporation */
  3. /************************************************************/
  4. #define NOGDICAPMASKS
  5. #define NOVIRTUALKEYCODES
  6. #define NOWINMESSAGES
  7. #define NOWINSTYLES
  8. #define NOSYSMETRICS
  9. #define NOMENUS
  10. #define NOICON
  11. #define NOKEYSTATE
  12. #define NOSYSCOMMANDS
  13. #define NOSHOWWINDOW
  14. #define NOCTLMGR
  15. #define NOCLIPBOARD
  16. #define NOMSG
  17. #define NOGDI
  18. #define NOMB
  19. #define NOSOUND
  20. #define NOCOMM
  21. #define NOPEN
  22. #define NOBRUSH
  23. #define NOFONT
  24. #define NOWNDCLASS
  25. #include <windows.h>
  26. #include "mw.h"
  27. /*
  28. HeapManage.c - several routines to manage the heap, including changing
  29. the finger table, compacting the heap in general, and checking the
  30. heap for consistency.
  31. It also contains the routines which were once in heapNew.
  32. */
  33. #include "code.h"
  34. #include "heapDefs.h"
  35. #include "heapData.h"
  36. #define NOSTRUNDO
  37. #define NOSTRMERGE
  38. #include "str.h"
  39. #include "macro.h"
  40. #define NOUAC
  41. #include "cmddefs.h"
  42. #include "filedefs.h"
  43. #include "docdefs.h"
  44. extern CHAR (*rgbp)[cbSector];
  45. extern CHAR *rgibpHash;
  46. extern struct BPS *mpibpbps;
  47. extern int ibpMax;
  48. extern int iibpHashMax;
  49. extern int cwInitStorage;
  50. extern typeTS tsMruBps;
  51. FTryGrow(unsigned);
  52. PFGR HAllocate(cwRequest)
  53. unsigned cwRequest;
  54. {
  55. unsigned cb = cwRequest * sizeof(int);
  56. HANDLE hTemp;
  57. Assert(*(pLocalHeap+1) == 0);
  58. if (cwRequest >= 0x8000)
  59. {
  60. #ifdef DEBUG
  61. Assert(0);
  62. ErrorWithMsg(IDPMTRottenFile, " heapMan#1");
  63. #else
  64. Error(IDPMTRottenFile);
  65. #endif
  66. return((PFGR)hOverflow);
  67. }
  68. hTemp = LocalAlloc(LHND, cb);
  69. if (hTemp != NULL)
  70. return((PFGR)hTemp);
  71. else if (FTryGrow(cb))
  72. {
  73. return((PFGR)LocalAlloc(LHND, cb));
  74. }
  75. else
  76. {
  77. #ifdef DEBUG
  78. ErrorWithMsg(IDPMTNoMemory, " heapMan#1");
  79. #else
  80. Error(IDPMTNoMemory);
  81. #endif
  82. return((PFGR)hOverflow);
  83. }
  84. }
  85. FChngSizeH(pfgrChng, cwRequest, fShrink)
  86. PFGR pfgrChng;
  87. int cwRequest, fShrink;
  88. {
  89. unsigned cb = cwRequest * sizeof(int);
  90. #ifdef DEBUG
  91. PFGR pfgrNew;
  92. #endif
  93. Assert(*(pLocalHeap+1) == 0); /* Check for frozen heap */
  94. Assert(cwRequest >= 0);
  95. if ((
  96. #ifdef DEBUG
  97. pfgrNew =
  98. #endif
  99. (PFGR)LocalReAlloc( (HANDLE)pfgrChng, cb, LHND)) != NULL)
  100. {
  101. Assert( pfgrNew == pfgrChng ); /* Windows guarantees this for
  102. movable objects */
  103. return( TRUE );
  104. }
  105. else if (FTryGrow(cb))
  106. {
  107. #ifdef DEBUG
  108. pfgrNew =
  109. #endif
  110. (PFGR)LocalReAlloc( (HANDLE)pfgrChng, cb, LHND);
  111. Assert( pfgrNew != (PFGR)NULL );
  112. Assert( pfgrNew == pfgrChng );
  113. return( TRUE );
  114. }
  115. else
  116. {
  117. #ifdef DEBUG
  118. ErrorWithMsg( IDPMTNoMemory, " heapMan#2" );
  119. #else
  120. Error( IDPMTNoMemory );
  121. #endif
  122. return( FALSE );
  123. }
  124. }
  125. CHAR (**HszCreate(sz))[]
  126. CHAR sz[];
  127. { /* Creates a heap block containing sz */
  128. CHAR (**hsz)[];
  129. int cch = CchSz(sz);
  130. hsz = (CHAR (**)[]) HAllocate(CwFromCch(cch));
  131. if (FNoHeap(hsz))
  132. return (CHAR (**)[])hOverflow;
  133. bltbyte(sz, **hsz, cch);
  134. return hsz;
  135. }
  136.