00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
#ifndef _HEAP_PAGE_I_
00027
#define _HEAP_PAGE_I_
00028
00029
#ifdef DEBUG_PAGE_HEAP
00030
00031
#include "heap.h"
00032
00033
#define DPH_INTERNAL_DEBUG 0 // change to 0 or #undef for production code
00034
00035
00036
00037
00038
00039
#define DPH_MAX_STACK_LENGTH 16
00040
00041
00042
00043
00044
00045
00046
00047
00048
#define DPH_CAPTURE_STACK_TRACE 1
00049
00050
00051
00052
00053
00054
typedef struct _DPH_HEAP_BLOCK DPH_HEAP_BLOCK, *PDPH_HEAP_BLOCK;
00055
00056
struct _DPH_HEAP_BLOCK {
00057
00058
00059
00060
00061
00062
00063 PDPH_HEAP_BLOCK pNextAlloc;
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080 PUCHAR pVirtualBlock;
00081 SIZE_T nVirtualBlockSize;
00082
00083 SIZE_T nVirtualAccessSize;
00084 PUCHAR pUserAllocation;
00085 SIZE_T nUserRequestedSize;
00086 SIZE_T nUserActualSize;
00087 PVOID UserValue;
00088 ULONG UserFlags;
00089
00090 PRTL_TRACE_BLOCK StackTrace;
00091 };
00092
00093
00094
typedef struct _DPH_HEAP_ROOT DPH_HEAP_ROOT, *PDPH_HEAP_ROOT;
00095
00096
struct _DPH_HEAP_ROOT {
00097
00098
00099
00100
00101
00102
00103 ULONG Signature;
00104 ULONG HeapFlags;
00105
00106
00107
00108
00109
00110 PRTL_CRITICAL_SECTION HeapCritSect;
00111 ULONG nRemoteLockAcquired;
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121 PDPH_HEAP_BLOCK pVirtualStorageListHead;
00122 PDPH_HEAP_BLOCK pVirtualStorageListTail;
00123 ULONG nVirtualStorageRanges;
00124 SIZE_T nVirtualStorageBytes;
00125
00126
00127
00128
00129
00130
00131
00132
00133 PDPH_HEAP_BLOCK pBusyAllocationListHead;
00134 PDPH_HEAP_BLOCK pBusyAllocationListTail;
00135 ULONG nBusyAllocations;
00136 SIZE_T nBusyAllocationBytesCommitted;
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146 PDPH_HEAP_BLOCK pFreeAllocationListHead;
00147 PDPH_HEAP_BLOCK pFreeAllocationListTail;
00148 ULONG nFreeAllocations;
00149 SIZE_T nFreeAllocationBytesCommitted;
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160 PDPH_HEAP_BLOCK pAvailableAllocationListHead;
00161 PDPH_HEAP_BLOCK pAvailableAllocationListTail;
00162 ULONG nAvailableAllocations;
00163 SIZE_T nAvailableAllocationBytesCommitted;
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174 PDPH_HEAP_BLOCK pUnusedNodeListHead;
00175 PDPH_HEAP_BLOCK pUnusedNodeListTail;
00176 ULONG nUnusedNodes;
00177
00178 SIZE_T nBusyAllocationBytesAccessible;
00179
00180
00181
00182
00183
00184
00185 PDPH_HEAP_BLOCK pNodePoolListHead;
00186 PDPH_HEAP_BLOCK pNodePoolListTail;
00187 ULONG nNodePools;
00188 SIZE_T nNodePoolBytes;
00189
00190
00191
00192
00193
00194 PDPH_HEAP_ROOT pNextHeapRoot;
00195 PDPH_HEAP_ROOT pPrevHeapRoot;
00196
00197 ULONG nUnProtectionReferenceCount;
00198 ULONG InsideAllocateNode;
00199
00200
00201
00202
00203
00204
00205
00206 ULONG ExtraFlags;
00207
00208
00209
00210
00211
00212
00213
00214
00215 ULONG
Seed;
00216 ULONG Counter[16];
00217
00218
00219
00220
00221
00222
00223
00224
00225 PVOID NormalHeap;
00226
00227
00228
00229
00230
00231 PRTL_TRACE_BLOCK CreateStackTrace;
00232 };
00233
00234
00235
00236
00237
00238
00239
#define DPH_COUNTER_SIZE_BELOW_1K 0
00240
#define DPH_COUNTER_SIZE_BELOW_4K 1
00241
#define DPH_COUNTER_SIZE_ABOVE_4K 2
00242
#define DPH_COUNTER_NO_BLOCK_INFORMATION 3
00243
#define DPH_COUNTER_NO_OF_ALLOCS 4
00244
#define DPH_COUNTER_NO_OF_REALLOCS 5
00245
#define DPH_COUNTER_NO_OF_FREES 6
00246
#define DPH_COUNTER_NO_OF_NORMAL_ALLOCS 7
00247
#define DPH_COUNTER_NO_OF_NORMAL_REALLOCS 8
00248
#define DPH_COUNTER_NO_OF_NORMAL_FREES 9
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
#define DPH_NORMAL_BLOCK_START_STAMP_ALLOCATED 0xABCDAAAA
00267
#define DPH_NORMAL_BLOCK_END_STAMP_ALLOCATED 0xDCBAAAAA
00268
#define DPH_NORMAL_BLOCK_START_STAMP_FREE (0xABCDAAAA - 1)
00269
#define DPH_NORMAL_BLOCK_END_STAMP_FREE (0xDCBAAAAA - 1)
00270
00271
#define DPH_PAGE_BLOCK_START_STAMP_ALLOCATED 0xABCDBBBB
00272
#define DPH_PAGE_BLOCK_END_STAMP_ALLOCATED 0xDCBABBBB
00273
#define DPH_PAGE_BLOCK_START_STAMP_FREE (0xABCDBBBB - 1)
00274
#define DPH_PAGE_BLOCK_END_STAMP_FREE (0xDCBABBBB - 1)
00275
00276
00277
#define DPH_BLOCK_INFORMATION_TRACE_SIZE 9
00278
00279
#define DPH_NORMAL_BLOCK_SUFFIX 0xA0
00280
#define DPH_PAGE_BLOCK_PREFIX 0xB0
00281
#define DPH_PAGE_BLOCK_INFIX 0xC0
00282
#define DPH_PAGE_BLOCK_SUFFIX 0xD0
00283
#define DPH_NORMAL_BLOCK_INFIX 0xE0
00284
#define DPH_FREE_BLOCK_INFIX 0xF0
00285
00286
typedef struct _DPH_BLOCK_INFORMATION {
00287
00288 ULONG StartStamp;
00289
00290 PVOID Heap;
00291 SIZE_T RequestedSize;
00292 SIZE_T ActualSize;
00293 LIST_ENTRY
FreeQueue;
00294 PVOID StackTrace;
00295
00296 ULONG EndStamp;
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306 } DPH_BLOCK_INFORMATION, * PDPH_BLOCK_INFORMATION;
00307
00308
00309
00310
00311
00312
#define DPH_SUCCESS 0x0000
00313
#define DPH_ERROR_CORRUPTED_START_STAMP 0x0001
00314
#define DPH_ERROR_CORRUPTED_END_STAMP 0x0002
00315
#define DPH_ERROR_CORRUPTED_HEAP_POINTER 0x0004
00316
#define DPH_ERROR_CORRUPTED_PREFIX_PATTERN 0x0008
00317
#define DPH_ERROR_CORRUPTED_SUFFIX_PATTERN 0x0010
00318
#define DPH_ERROR_RAISED_EXCEPTION 0x0020
00319
#define DPH_ERROR_NO_NORMAL_HEAP 0x0040
00320
#define DPH_ERROR_CORRUPTED_INFIX_PATTERN 0x0080
00321
00322
00323
#endif // DEBUG_PAGE_HEAP
00324
00325
#endif // _HEAP_PAGE_I_