Converted the process heap list to a standard list.
This commit is contained in:
parent
8328c61a01
commit
03c3b4e7e0
|
@ -113,7 +113,7 @@ typedef struct tagSUBHEAP
|
||||||
typedef struct tagHEAP
|
typedef struct tagHEAP
|
||||||
{
|
{
|
||||||
SUBHEAP subheap; /* First sub-heap */
|
SUBHEAP subheap; /* First sub-heap */
|
||||||
struct tagHEAP *next; /* Next heap for this process */
|
struct list entry; /* Entry in process heap list */
|
||||||
RTL_CRITICAL_SECTION critSection; /* Critical section for serialization */
|
RTL_CRITICAL_SECTION critSection; /* Critical section for serialization */
|
||||||
FREE_LIST_ENTRY freeList[HEAP_NB_FREE_LISTS]; /* Free lists */
|
FREE_LIST_ENTRY freeList[HEAP_NB_FREE_LISTS]; /* Free lists */
|
||||||
DWORD flags; /* Heap flags */
|
DWORD flags; /* Heap flags */
|
||||||
|
@ -126,9 +126,7 @@ typedef struct tagHEAP
|
||||||
#define HEAP_MIN_BLOCK_SIZE (8+sizeof(ARENA_FREE)) /* Min. heap block size */
|
#define HEAP_MIN_BLOCK_SIZE (8+sizeof(ARENA_FREE)) /* Min. heap block size */
|
||||||
#define COMMIT_MASK 0xffff /* bitmask for commit/decommit granularity */
|
#define COMMIT_MASK 0xffff /* bitmask for commit/decommit granularity */
|
||||||
|
|
||||||
static HANDLE processHeap; /* main process heap */
|
static HEAP *processHeap; /* main process heap */
|
||||||
|
|
||||||
static HEAP *firstHeap; /* head of secondary heaps list */
|
|
||||||
|
|
||||||
static BOOL HEAP_IsRealArena( HEAP *heapPtr, DWORD flags, LPCVOID block, BOOL quiet );
|
static BOOL HEAP_IsRealArena( HEAP *heapPtr, DWORD flags, LPCVOID block, BOOL quiet );
|
||||||
|
|
||||||
|
@ -190,7 +188,8 @@ static void HEAP_Dump( HEAP *heap )
|
||||||
char *ptr;
|
char *ptr;
|
||||||
|
|
||||||
DPRINTF( "Heap: %p\n", heap );
|
DPRINTF( "Heap: %p\n", heap );
|
||||||
DPRINTF( "Next: %p Sub-heaps: %p", heap->next, &heap->subheap );
|
DPRINTF( "Next: %p Sub-heaps: %p",
|
||||||
|
LIST_ENTRY( heap->entry.next, HEAP, entry ), &heap->subheap );
|
||||||
subheap = &heap->subheap;
|
subheap = &heap->subheap;
|
||||||
while (subheap->next)
|
while (subheap->next)
|
||||||
{
|
{
|
||||||
|
@ -592,7 +591,6 @@ static BOOL HEAP_InitSubHeap( HEAP *heap, LPVOID address, DWORD flags,
|
||||||
|
|
||||||
subheap->headerSize = ROUND_SIZE( sizeof(HEAP) );
|
subheap->headerSize = ROUND_SIZE( sizeof(HEAP) );
|
||||||
subheap->next = NULL;
|
subheap->next = NULL;
|
||||||
heap->next = NULL;
|
|
||||||
heap->flags = flags;
|
heap->flags = flags;
|
||||||
heap->magic = HEAP_MAGIC;
|
heap->magic = HEAP_MAGIC;
|
||||||
|
|
||||||
|
@ -1060,12 +1058,15 @@ HANDLE WINAPI RtlCreateHeap( ULONG flags, PVOID addr, SIZE_T totalSize, SIZE_T c
|
||||||
if (processHeap)
|
if (processHeap)
|
||||||
{
|
{
|
||||||
HEAP *heapPtr = subheap->heap;
|
HEAP *heapPtr = subheap->heap;
|
||||||
RtlLockHeap( processHeap );
|
RtlEnterCriticalSection( &processHeap->critSection );
|
||||||
heapPtr->next = firstHeap;
|
list_add_head( &processHeap->entry, &heapPtr->entry );
|
||||||
firstHeap = heapPtr;
|
RtlLeaveCriticalSection( &processHeap->critSection );
|
||||||
RtlUnlockHeap( processHeap );
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
processHeap = subheap->heap; /* assume the first heap we create is the process main heap */
|
||||||
|
list_init( &processHeap->entry );
|
||||||
}
|
}
|
||||||
else processHeap = subheap->heap; /* assume the first heap we create is the process main heap */
|
|
||||||
|
|
||||||
return (HANDLE)subheap;
|
return (HANDLE)subheap;
|
||||||
}
|
}
|
||||||
|
@ -1092,15 +1093,11 @@ HANDLE WINAPI RtlDestroyHeap( HANDLE heap )
|
||||||
if (!heapPtr) return heap;
|
if (!heapPtr) return heap;
|
||||||
|
|
||||||
if (heap == processHeap) return heap; /* cannot delete the main process heap */
|
if (heap == processHeap) return heap; /* cannot delete the main process heap */
|
||||||
else /* remove it from the per-process list */
|
|
||||||
{
|
/* remove it from the per-process list */
|
||||||
HEAP **pptr;
|
RtlEnterCriticalSection( &processHeap->critSection );
|
||||||
RtlLockHeap( processHeap );
|
list_remove( &heapPtr->entry );
|
||||||
pptr = &firstHeap;
|
RtlLeaveCriticalSection( &processHeap->critSection );
|
||||||
while (*pptr && *pptr != heapPtr) pptr = &(*pptr)->next;
|
|
||||||
if (*pptr) *pptr = (*pptr)->next;
|
|
||||||
RtlUnlockHeap( processHeap );
|
|
||||||
}
|
|
||||||
|
|
||||||
RtlDeleteCriticalSection( &heapPtr->critSection );
|
RtlDeleteCriticalSection( &heapPtr->critSection );
|
||||||
subheap = &heapPtr->subheap;
|
subheap = &heapPtr->subheap;
|
||||||
|
@ -1636,18 +1633,17 @@ HW_end:
|
||||||
*/
|
*/
|
||||||
ULONG WINAPI RtlGetProcessHeaps( ULONG count, HANDLE *heaps )
|
ULONG WINAPI RtlGetProcessHeaps( ULONG count, HANDLE *heaps )
|
||||||
{
|
{
|
||||||
ULONG total;
|
ULONG total = 1; /* main heap */
|
||||||
HEAP *ptr;
|
struct list *ptr;
|
||||||
|
|
||||||
if (!processHeap) return 0; /* should never happen */
|
RtlEnterCriticalSection( &processHeap->critSection );
|
||||||
total = 1; /* main heap */
|
LIST_FOR_EACH( ptr, &processHeap->entry ) total++;
|
||||||
RtlLockHeap( processHeap );
|
|
||||||
for (ptr = firstHeap; ptr; ptr = ptr->next) total++;
|
|
||||||
if (total <= count)
|
if (total <= count)
|
||||||
{
|
{
|
||||||
*heaps++ = (HANDLE)processHeap;
|
*heaps++ = processHeap;
|
||||||
for (ptr = firstHeap; ptr; ptr = ptr->next) *heaps++ = (HANDLE)ptr;
|
LIST_FOR_EACH( ptr, &processHeap->entry )
|
||||||
|
*heaps++ = LIST_ENTRY( ptr, HEAP, entry );
|
||||||
}
|
}
|
||||||
RtlUnlockHeap( processHeap );
|
RtlLeaveCriticalSection( &processHeap->critSection );
|
||||||
return total;
|
return total;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue