Ignore:
Timestamp:
Jan 24, 2000, 7:19:01 PM (26 years ago)
Author:
bird
Message:

Heapchanges: Heap is splitted into a swappable and a resident. The heaps
are dynamically growable.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/win32k/misc/rmalloc_avl.c

    r2508 r2511  
    1 /* $Id: rmalloc_avl.c,v 1.4 2000-01-24 03:05:14 bird Exp $
     1/* $Id: rmalloc_avl.c,v 1.5 2000-01-24 18:19:00 bird Exp $
    22 *
    33 * Resident Heap - AVL.
     
    1616*   Defined Constants And Macros                                               *
    1717*******************************************************************************/
     18#pragma info(notrd)
    1819#ifdef DEBUG
    1920    #define DEBUG_ALLOC
    20     #define ALLWAYS_HEAPCHECK
     21    #undef ALLWAYS_HEAPCHECK
     22    #undef SOMETIMES_HEAPCHECK
    2123#endif
    2224
     
    4143#endif
    4244
    43 
    4445/******************************************************************************
    4546*  Headerfiles
     
    4849#ifdef RING0
    4950    #include "dev32hlp.h"
    50     #include "asmutils.h"
    51 #else
    52     #include <builtin.h>
    53     #define Int3() __interrupt(3)
    5451#endif
     52#include "asmutils.h"
    5553#include "log.h"
    5654#include "rmalloc.h"
    57 #include <memory.h>
    5855#include "dev32.h"
    5956#include "avl.h"
    6057#include "macros.h"
     58#include <memory.h>
    6159
    6260
     
    139137static PMEMBLOCK    resFindUsedBlock(PHEAPANCHOR *ppha, void *pvUser);
    140138static PMEMBLOCK    resFindWithinUsedBlock(PHEAPANCHOR *ppha, void *pvUser);
     139#ifdef DEBUG_ALLOC
    141140static int          resCheckAVLTree(PMEMBLOCK pmb);
    142141static int          resCheckAVLTreeFree(PAVLNODECORE pNode);
     142#endif
    143143static unsigned     _res_dump_subheaps_callback(PMEMBLOCK pmb, PSUBHEAPS_CALLBACK_PARAM pCb);
    144144static unsigned     _res_dump_allocated_callback(PMEMBLOCK pmb, PALLOCATED_CALLBACK_PARAM pParam);
     
    252252    PMEMBLOCKFREE   pmbfRightParent;
    253253    PMEMBLOCKFREE   pmbfLeft;
    254     PMEMBLOCKFREE   pmbfTmp;
    255254
    256255    pha->cbFree += pmb->cbSize;
     
    592591    resInsertFree(phaFirst, pmb);
    593592
    594     #ifdef ALLWAYS_HEAPCHECK
     593    #if defined(ALLWAYS_HEAPCHECK) || defined(SOMETIMES_HEAPCHECK)
    595594        if (!_res_heap_check())
    596595        {   /* error! */
     
    602601        }
    603602    #endif
    604     #ifdef RING3
    605         fInited = TRUE;
     603    #ifndef RING0
     604        fResInited = TRUE;
    606605    #endif
    607606    return 0;
     
    618617void * rmalloc(unsigned cbSize)
    619618{
    620     #ifdef ALLWAYS_HEAPCHECK
     619    #if defined(ALLWAYS_HEAPCHECK) || defined(SOMETIMES_HEAPCHECK)
    621620    if (!_res_heap_check())
    622621    {
     
    655654    PHEAPANCHOR pha;
    656655
    657     #ifdef ALLWAYS_HEAPCHECK
     656    #if defined(ALLWAYS_HEAPCHECK) || defined(SOMETIMES_HEAPCHECK)
    658657    if (!_res_heap_check())
    659658    {
     
    778777void rfree(void *pv)
    779778{
    780     #ifdef ALLWAYS_HEAPCHECK
    781         if (!_res_heap_check())
    782         {
    783             kprintf(("rfree: _res_heap_check failed!\n"));
    784             return;
    785         }
     779    #if defined(ALLWAYS_HEAPCHECK) || defined(SOMETIMES_HEAPCHECK)
     780    if (!_res_heap_check())
     781    {
     782        kprintf(("rfree: _res_heap_check failed!\n"));
     783        return;
     784    }
    786785    #endif
    787786
     
    825824
    826825    #ifdef ALLWAYS_HEAPCHECK
    827         if (!_res_heap_check())
    828             kprintf(("_res_msize: _res_heap_check failed!\n"));
     826    if (!_res_heap_check())
     827        kprintf(("_res_msize: _res_heap_check failed!\n"));
    829828    #endif
    830829
     
    841840int _res_validptr(void *pv)
    842841{
    843     PHEAPANCHOR pha;
    844842    PMEMBLOCK   pmb;
    845843
    846844    #ifdef ALLWAYS_HEAPCHECK
    847         if (!_res_heap_check())
    848             kprintf(("_res_validptr: _res_heap_check failed!\n"));
     845    if (!_res_heap_check())
     846        kprintf(("_res_validptr: _res_heap_check failed!\n"));
    849847    #endif
    850848
     
    862860int _res_validptr2(void *pv, unsigned cbSize)
    863861{
    864     PHEAPANCHOR pha;
    865862    PMEMBLOCK   pmb;
    866863
    867864    #ifdef ALLWAYS_HEAPCHECK
    868         if (!_res_heap_check())
    869             kprintf(("_res_validptr: _res_heap_check failed!\n"));
     865    if (!_res_heap_check())
     866        kprintf(("_res_validptr: _res_heap_check failed!\n"));
    870867    #endif
    871868
     
    889886
    890887    #ifdef ALLWAYS_HEAPCHECK
    891         if (!_res_heap_check())
    892             kprintf(("_res_memfree: _res_heap_check failed!\n"));
     888    if (!_res_heap_check())
     889        kprintf(("_res_memfree: _res_heap_check failed!\n"));
    893890    #endif
    894891
     
    917914        AVLENUMDATA FreeEnumData;
    918915        AVLENUMDATA UsedEnumData;
    919         PMEMBLOCK pmbFree = (PMEMBLOCK)AVLBeginEnumTree((PPAVLNODECORE)&pha->pmbFree, &FreeEnumData, TRUE);
    920         PMEMBLOCK pmbFreeNext = (PMEMBLOCK)AVLGetNextNode(&FreeEnumData);
    921         PMEMBLOCK pmbUsed = (PMEMBLOCK)AVLBeginEnumTree((PPAVLNODECORE)&pha->pmbUsed, &UsedEnumData, TRUE);
    922         PMEMBLOCK pmbUsedNext = (PMEMBLOCK)AVLGetNextNode(&UsedEnumData);
     916        PMEMBLOCK pmbFree = (PMEMBLOCK)AVLBeginEnumTree((PPAVLNODECORE)&pha->pmbFree,
     917                                                        SSToDS(&FreeEnumData), TRUE);
     918        PMEMBLOCK pmbFreeNext = (PMEMBLOCK)AVLGetNextNode(SSToDS(&FreeEnumData));
     919        PMEMBLOCK pmbUsed = (PMEMBLOCK)AVLBeginEnumTree((PPAVLNODECORE)&pha->pmbUsed,
     920                                                        SSToDS(&UsedEnumData), TRUE);
     921        PMEMBLOCK pmbUsedNext = (PMEMBLOCK)AVLGetNextNode(SSToDS(&UsedEnumData));
    923922        PMEMBLOCK pmbLast = NULL;
    924923        unsigned  cbFree = 0;
     
    10311030                pmbLast = pmbUsed;
    10321031                pmbUsed = pmbUsedNext;
    1033                 pmbUsedNext = (PMEMBLOCK)AVLGetNextNode(&UsedEnumData);
     1032                pmbUsedNext = (PMEMBLOCK)AVLGetNextNode(SSToDS(&UsedEnumData));
    10341033            }
    10351034            else
     
    10711070                pmbLast = pmbFree;
    10721071                pmbFree = pmbFreeNext;
    1073                 pmbFreeNext = (PMEMBLOCK)AVLGetNextNode(&FreeEnumData);
     1072                pmbFreeNext = (PMEMBLOCK)AVLGetNextNode(SSToDS(&FreeEnumData));
    10741073            }
    10751074        }
     
    11331132
    11341133
     1134#ifdef DEBUG_ALLOC
    11351135/**
    11361136 * Check the integrity of the a Free/Used AVL tree where Key == node pointer.
     
    11431143    {
    11441144        kprintf(("resCheckAVLTree: Invalid Key!\n"));
     1145        Int3();
     1146        return -1;
     1147    }
     1148    if (pmb->core.Key % ALIGNMENT != 0)
     1149    {
     1150        kprintf(("resCheckAVLTree: Data is not correctly aligned, uData=0x%08x\n", pmb->core.Key));
    11451151        Int3();
    11461152        return -1;
     
    12231229    return 0;
    12241230}
     1231#endif
    12251232
    12261233
     
    12891296    while (pha != NULL)
    12901297    {
    1291         PMEMBLOCK pmb;
    1292         SUBHEAPS_CALLBACK_PARAM FreeParam = {0};
    1293         SUBHEAPS_CALLBACK_PARAM UsedParam = {0};
     1298        SUBHEAPS_CALLBACK_PARAM FreeParam = {0, 0};
     1299        SUBHEAPS_CALLBACK_PARAM UsedParam = {0, 0};
    12941300
    12951301        AVLDoWithAll((PPAVLNODECORE)&pha->pmbUsed, 1,
    1296                      (PAVLCALLBACK)_res_dump_subheaps_callback, &UsedParam);
     1302                     (PAVLCALLBACK)_res_dump_subheaps_callback, SSToDS(&UsedParam));
    12971303        AVLDoWithAll((PPAVLNODECORE)&pha->pmbFree, 1,
    1298                      (PAVLCALLBACK)_res_dump_subheaps_callback, &FreeParam);
     1304                     (PAVLCALLBACK)_res_dump_subheaps_callback, SSToDS(&FreeParam));
    12991305
    13001306        kprintf(("HeapAnchor %2d addr=0x%08x cbSize=%6d cbFree=%6d cbUsed=%6d cUsed=%4d cFree=%d\n",
     
    13381344{
    13391345    PHEAPANCHOR pha;
    1340     ALLOCATED_CALLBACK_PARAM Param = {0};
     1346    ALLOCATED_CALLBACK_PARAM Param = {cb, 0, 0};
    13411347
    13421348    kprintf(("----------------------------\n"
     
    13491355        /* iterate thru tree using callback */
    13501356        AVLDoWithAll((PPAVLNODECORE)&pha->pmbUsed, TRUE,
    1351                      (PAVLCALLBACK)_res_dump_allocated_callback, &Param);
     1357                     (PAVLCALLBACK)_res_dump_allocated_callback, SSToDS(&Param));
    13521358
    13531359        /* next */
Note: See TracChangeset for help on using the changeset viewer.