Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

heappagi.h

Go to the documentation of this file.
00001 /*++ 00002 00003 Copyright (c) 1994-2000 Microsoft Corporation 00004 00005 Module Name: 00006 00007 heappagi.h 00008 00009 Abstract: 00010 00011 The following definitions are internal to the debug heap manager, 00012 but are placed in this include file so that debugger extensions 00013 can reference the same structure definitions. The following 00014 definitions are not intended to be referenced externally except 00015 by debugger extensions. 00016 00017 Author: 00018 00019 Tom McGuire (TomMcg) 06-Jan-1995 00020 Silviu Calinoiu (SilviuC) 22-Feb-2000 00021 00022 Revision History: 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 // Stack trace size. 00037 // 00038 00039 #define DPH_MAX_STACK_LENGTH 16 00040 00041 // 00042 // Capture stacktraces in any context (x86/alpha, fre/chk). On alpha 00043 // the stack acquisition function will fail and no stack trace will be 00044 // acquired but in case we will find a better algorithm the page heap 00045 // code will automatically take advantage of that. 00046 // 00047 00048 #define DPH_CAPTURE_STACK_TRACE 1 00049 00050 // 00051 // DPH_HEAP_BLOCK 00052 // 00053 00054 typedef struct _DPH_HEAP_BLOCK DPH_HEAP_BLOCK, *PDPH_HEAP_BLOCK; 00055 00056 struct _DPH_HEAP_BLOCK { 00057 00058 // 00059 // Singly linked list of allocations (pNextAlloc must be 00060 // first member in structure). 00061 // 00062 00063 PDPH_HEAP_BLOCK pNextAlloc; 00064 00065 // 00066 // | PAGE_READWRITE | PAGE_NOACCESS | 00067 // |____________________|___||_________________________| 00068 // 00069 // ^pVirtualBlock ^pUserAllocation 00070 // 00071 // |---------------- nVirtualBlockSize ----------------| 00072 // 00073 // |---nVirtualAccessSize----| 00074 // 00075 // |---| nUserRequestedSize 00076 // 00077 // |----| nUserActualSize 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 // Maintain a signature (DPH_HEAP_SIGNATURE) as the 00100 // first value in the heap root structure. 00101 // 00102 00103 ULONG Signature; 00104 ULONG HeapFlags; 00105 00106 // 00107 // Access to this heap is synchronized with a critical section. 00108 // 00109 00110 PRTL_CRITICAL_SECTION HeapCritSect; 00111 ULONG nRemoteLockAcquired; 00112 00113 // 00114 // The "VirtualStorage" list only uses the pVirtualBlock, 00115 // nVirtualBlockSize, and nVirtualAccessSize fields of the 00116 // HEAP_ALLOCATION structure. This is the list of virtual 00117 // allocation entries that all the heap allocations are 00118 // taken from. 00119 // 00120 00121 PDPH_HEAP_BLOCK pVirtualStorageListHead; 00122 PDPH_HEAP_BLOCK pVirtualStorageListTail; 00123 ULONG nVirtualStorageRanges; 00124 SIZE_T nVirtualStorageBytes; 00125 00126 // 00127 // The "Busy" list is the list of active heap allocations. 00128 // It is stored in LIFO order to improve temporal locality 00129 // for linear searches since most initial heap allocations 00130 // tend to remain permanent throughout a process's lifetime. 00131 // 00132 00133 PDPH_HEAP_BLOCK pBusyAllocationListHead; 00134 PDPH_HEAP_BLOCK pBusyAllocationListTail; 00135 ULONG nBusyAllocations; 00136 SIZE_T nBusyAllocationBytesCommitted; 00137 00138 // 00139 // The "Free" list is the list of freed heap allocations, stored 00140 // in FIFO order to increase the length of time a freed block 00141 // remains on the freed list without being used to satisfy an 00142 // allocation request. This increases the odds of catching 00143 // a reference-after-freed bug in an app. 00144 // 00145 00146 PDPH_HEAP_BLOCK pFreeAllocationListHead; 00147 PDPH_HEAP_BLOCK pFreeAllocationListTail; 00148 ULONG nFreeAllocations; 00149 SIZE_T nFreeAllocationBytesCommitted; 00150 00151 // 00152 // The "Available" list is stored in address-sorted order to facilitate 00153 // coalescing. When an allocation request cannot be satisfied from the 00154 // "Available" list, it is attempted from the free list. If it cannot 00155 // be satisfied from the free list, the free list is coalesced into the 00156 // available list. If the request still cannot be satisfied from the 00157 // coalesced available list, new VM is added to the available list. 00158 // 00159 00160 PDPH_HEAP_BLOCK pAvailableAllocationListHead; 00161 PDPH_HEAP_BLOCK pAvailableAllocationListTail; 00162 ULONG nAvailableAllocations; 00163 SIZE_T nAvailableAllocationBytesCommitted; 00164 00165 // 00166 // The "UnusedNode" list is simply a list of available node 00167 // entries to place "Busy", "Free", or "Virtual" entries. 00168 // When freed nodes get coalesced into a single free node, 00169 // the other "unused" node goes on this list. When a new 00170 // node is needed (like an allocation not satisfied from the 00171 // free list), the node comes from this list if it's not empty. 00172 // 00173 00174 PDPH_HEAP_BLOCK pUnusedNodeListHead; 00175 PDPH_HEAP_BLOCK pUnusedNodeListTail; 00176 ULONG nUnusedNodes; 00177 00178 SIZE_T nBusyAllocationBytesAccessible; 00179 00180 // 00181 // Node pools need to be tracked so they can be protected 00182 // from app scribbling on them. 00183 // 00184 00185 PDPH_HEAP_BLOCK pNodePoolListHead; 00186 PDPH_HEAP_BLOCK pNodePoolListTail; 00187 ULONG nNodePools; 00188 SIZE_T nNodePoolBytes; 00189 00190 // 00191 // Doubly linked list of DPH heaps in process is tracked through this. 00192 // 00193 00194 PDPH_HEAP_ROOT pNextHeapRoot; 00195 PDPH_HEAP_ROOT pPrevHeapRoot; 00196 00197 ULONG nUnProtectionReferenceCount; 00198 ULONG InsideAllocateNode; // only for debugging 00199 00200 // 00201 // These are extra flags used to control page heap behavior. 00202 // During heap creation the current value of the global page heap 00203 // flags (process wise) is written into this field. 00204 // 00205 00206 ULONG ExtraFlags; 00207 00208 // 00209 // Seed for the random generator used to decide from where 00210 // should we make an allocation (normal or verified heap). 00211 // The field is protected by the critical section associated 00212 // with each page heap. 00213 // 00214 00215 ULONG Seed; 00216 ULONG Counter[16]; 00217 00218 // 00219 // `NormalHeap' is used in case we want to combine verified allocations 00220 // with normal ones. This is useful to minimize memory impact. Without 00221 // this feature certain processes that are very heap intensive cannot 00222 // be verified at all. 00223 // 00224 00225 PVOID NormalHeap; 00226 00227 // 00228 // Heap creation stack trace. 00229 // 00230 00231 PRTL_TRACE_BLOCK CreateStackTrace; 00232 }; 00233 00234 00235 // 00236 // Page heap and global counters 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 // DPH_BLOCK_INFORMATION 00252 // 00253 // This structure is stored in every page heap allocated block 00254 // if allocation size permits to stuff the info. It is completely 00255 // redundant information. Its purpose is to ease debugging. 00256 // 00257 // If there is not enough empty space in the allocation (e.g. size 00258 // of the allocation is close to PAGE_SIZE) then we will not force 00259 // this information because this will modify the required size of 00260 // the block and the memory usage pattern. 00261 // 00262 // This information is not saved if the catch backward overruns 00263 // flag is set. 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 //silviuc:obsolete 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 // (SilviuC): This structure needs to be 8-byte aligned. 00300 // If it is not, applications expecting aligned blocks will get 00301 // unaligned ones because this structure will prefix their 00302 // allocations. Internet Explorer is one such application 00303 // that stops working in these conditions. 00304 // 00305 00306 } DPH_BLOCK_INFORMATION, * PDPH_BLOCK_INFORMATION; 00307 00308 // 00309 // Error reasons used in debug messages 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_

Generated on Sat May 15 19:40:16 2004 for test by doxygen 1.3.7