Changeset 2511 for trunk/src/win32k


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.

Location:
trunk/src/win32k
Files:
1 added
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/win32k/Makefile

    r2501 r2511  
    11################################################################################
    2 # $Id: Makefile,v 1.14 2000-01-22 18:20:55 bird Exp $
     2# $Id: Makefile,v 1.15 2000-01-24 18:18:59 bird Exp $
    33#
    44# Copyright 1998-1999 knut st. osmundsen
     
    154154        object\calltab.obj \
    155155        object\malloc.obj \
     156        object\smalloc_avl.obj \
     157        object\avl.obj \
     158        object\rmalloc_avl.obj \
    156159        object\new.obj \
    157160        object\stricmp.obj \
     
    159162        object\vsprintf.obj \
    160163        object\vprintf.obj \
    161         object\avl.obj \
    162164        object\ldr.obj \
    163165        object\myldrClose.obj \
  • trunk/src/win32k/dev32/d32init.c

    r2501 r2511  
    1 /* $Id: d32init.c,v 1.5 2000-01-22 18:20:57 bird Exp $
     1/* $Id: d32init.c,v 1.6 2000-01-24 18:18:59 bird Exp $
    22 *
    33 * d32init.c - 32-bits init routines.
     
    129129                    {
    130130                        if (strnicmp(pszTmp, "heapm", 5) == 0)
    131                             options.cbHeapMax = ul;
     131                            options.cbSwpHeapMax = ul;
    132132                        else
    133                             options.cbHeap = ul;
     133                            options.cbSwpHeapInit = ul;
    134134                    }
    135135                }
     
    189189                    {
    190190                        if (strnicmp(pszTmp, "resheapm", 8) == 0)
    191                             options.cbHeapMaxResident = ul;
     191                            options.cbResHeapMax = ul;
    192192                        else
    193                             options.cbHeapResident = ul;
     193                            options.cbResHeapInit = ul;
    194194                    }
    195195                }
     
    243243
    244244    /* heap min/max corrections */
    245     if (options.cbHeap > options.cbHeapMax)
    246         options.cbHeapMax = options.cbHeap;
    247     if (options.cbHeapResident > options.cbHeapMaxResident)
    248         options.cbHeapMaxResident = options.cbHeapResident;
     245    if (options.cbSwpHeapInit > options.cbSwpHeapMax)
     246        options.cbSwpHeapMax = options.cbSwpHeapInit;
     247    if (options.cbResHeapInit > options.cbResHeapMax)
     248        options.cbResHeapMax = options.cbResHeapInit;
    249249
    250250    /* Transfer version and build number from 16-bit probkrnl.c */
     
    277277     */
    278278    /* heap */
    279     if (heapInit(options.cbHeap) != NO_ERROR)
     279    if (heapInit(options.cbResHeapInit, options.cbResHeapMax,
     280                 options.cbSwpHeapInit, options.cbSwpHeapMax) != NO_ERROR)
    280281        return STATUS_DONE | STERR | ERROR_I24_QUIET_INIT_FAIL;
    281282
  • trunk/src/win32k/include/asmutils.h

    r1678 r2511  
    1 /* $Id: asmutils.h,v 1.3 1999-11-10 01:45:32 bird Exp $
     1/* $Id: asmutils.h,v 1.4 2000-01-24 18:18:59 bird Exp $
    22 *
    33 * Assembly utilities.
     
    2525extern void _System EnableInterrupts(void);  /* uniprocessor only */
    2626
    27 //extern void _System Int3(void);
    28 extern int _System Int3(void);
     27#if 0
     28    //extern void _System Int3(void);
     29    extern int _System Int3(void);
     30#else
     31    #include <builtin.h>
     32    #define Int3() __interrupt(3)
     33#endif
    2934
    3035//Negative offsets don't work yet?
  • trunk/src/win32k/include/malloc.h

    r1678 r2511  
    1 /* $Id: malloc.h,v 1.5 1999-11-10 01:45:32 bird Exp $
     1/* $Id: malloc.h,v 1.6 2000-01-24 18:18:59 bird Exp $
    22 *
    33 * Heap.
     
    2828*   Exported Functions and Variables                                           *
    2929*******************************************************************************/
    30 int      heapInit(unsigned);
    31 void *   malloc(unsigned);
    32 void *   realloc(void *, unsigned);
    33 void     free(void *);
    34 unsigned _memfree(void);
    35 unsigned _msize(void *);
    36 int      _validptr(void *);
    37 int      _validptr2(void *, unsigned);
    38 int      _heap_check(void);
    39 
    40 extern unsigned  _uHeapMinPtr;/* heap pointers are greater or equal to this.*/
    41 extern unsigned  _uHeapMaxPtr;/* heap pointers are less than this. */
     30int         heapInit(unsigned, unsigned, unsigned, unsigned);
     31void *      malloc(unsigned);
     32void *      realloc(void *, unsigned);
     33void        free(void *);
     34unsigned    _memfree(void);
     35unsigned    _msize(void *);
     36int         _validptr(void *);
     37int         _validptr2(void *, unsigned);
     38int         _heap_check(void);
    4239
    4340
     
    4542*   Defined Constants And Macros                                               *
    4643*******************************************************************************/
    47 #define MINPTR _uHeapMinPtr
    48 #define MAXPTR _uHeapMaxPtr
    49 
    5044/* HeapPointer assert - old ones... */
    5145#define ltasserthp(a)         if (!_validptr((void*)(a))){ _ltasserthp((void*)(a), #a,__FILE__,__LINE__); return FALSE;}
  • trunk/src/win32k/include/options.h

    r2501 r2511  
    1 /* $Id: options.h,v 1.5 2000-01-22 18:21:01 bird Exp $
     1/* $Id: options.h,v 1.6 2000-01-24 18:18:59 bird Exp $
    22 *
    33 * Options.
     
    3232#define INFOLEVEL_INFOALL    0x00000004UL
    3333
     34/* default heapsizes */
     35#define CB_SWP_INIT         (1024*512)
     36#define CB_SWP_MAX          (1024*1024*16)
     37#define CB_RES_INIT         (1024*256)
     38#define CB_RES_MAX          (1024*1024*10)
     39
     40
    3441/* Set defaults. */
    35 #define SET_OPTIONS_TO_DEFAULT(o)                       \
    36             o.fQuiet      = FALSE;                      \
    37             o.usCom       = OUTPUT_COM2;                \
    38             o.fLogging    = FALSE;                      \
    39             o.fKernel     = KF_UNI;                     \
    40             o.ulBuild     = ~0UL;                       \
    41             o.usVerMajor  = (unsigned short)~0;         \
    42             o.usVerMinor  = (unsigned short)~0;         \
    43             o.fPE         = FLAGS_PE_PE2LX;             \
    44             o.ulInfoLevel = INFOLEVEL_QUIET;            \
    45             o.fElf        = FALSE;                      \
    46             o.fScript     = FALSE;                      \
    47             o.fNoLoader   = FALSE;                      \
    48             o.cbHeap      = 0x100000; /* 1MB */         \
    49             o.cbHeapMax   = 0x100000; /* 1MB */         \
    50             o.cbHeapResident    = 0x10000; /* 64KB */   \
    51             o.cbHeapMaxResident = 0x1000;  /* 4KB */    \
     42#define SET_OPTIONS_TO_DEFAULT(o)                   \
     43            o.fQuiet        = FALSE;                \
     44            o.usCom         = OUTPUT_COM2;          \
     45            o.fLogging      = FALSE;                \
     46            o.fKernel       = KF_UNI;               \
     47            o.ulBuild       = ~0UL;                 \
     48            o.usVerMajor    = (unsigned short)~0;   \
     49            o.usVerMinor    = (unsigned short)~0;   \
     50            o.fPE           = FLAGS_PE_PE2LX;       \
     51            o.ulInfoLevel   = INFOLEVEL_QUIET;      \
     52            o.fElf          = FALSE;                \
     53            o.fScript       = FALSE;                \
     54            o.fNoLoader     = FALSE;                \
     55            o.cbSwpHeapInit = CB_SWP_INIT;          \
     56            o.cbSwpHeapMax  = CB_SWP_MAX;           \
     57            o.cbResHeapInit = CB_RES_INIT;          \
     58            o.cbResHeapMax  = CB_RES_MAX;
    5259
    5360
     
    5966{
    6067    /** @cat misc */
    61     BOOL        fQuiet;              /* Quiet initialization. */
     68    BOOL        fQuiet;                 /* Quiet initialization. */
    6269
    6370    /** @cat logging options */
    64     USHORT      usCom;               /* Output port no. */
    65     BOOL        fLogging;            /* Logging. */
     71    USHORT      usCom;                  /* Output port no. */
     72    BOOL        fLogging;               /* Logging. */
    6673
    6774    /** @cat kernel selection */
    68     ULONG       fKernel;            /* Smp or uni kernel. */
    69     ULONG       ulBuild;            /* Kernel build. */
    70     USHORT      usVerMajor;         /* OS/2 major ver - 20 */
    71     USHORT      usVerMinor;         /* OS/2 minor ver - 30,40 */
     75    ULONG       fKernel;                /* Smp or uni kernel. */
     76    ULONG       ulBuild;                /* Kernel build. */
     77    USHORT      usVerMajor;             /* OS/2 major ver - 20 */
     78    USHORT      usVerMinor;             /* OS/2 minor ver - 30,40 */
    7279
    7380    /** @cat Options affecting the generated LX executables */
    74     BOOL        fPE;                /* Flags set the type of conversion. */
    75     ULONG       ulInfoLevel;        /* Pe2Lx InfoLevel. */
     81    BOOL        fPE;                    /* Flags set the type of conversion. */
     82    ULONG       ulInfoLevel;            /* Pe2Lx InfoLevel. */
    7683
    7784    /** @cat Options affecting the generated ELF executables */
    78     BOOL        fElf;               /* Elf flags. */
     85    BOOL        fElf;                   /* Elf flags. */
    7986
    8087    /** @cat Options affecting the script executables */
    81     BOOL        fScript;            /* Script flags. */
     88    BOOL        fScript;                /* Script flags. */
    8289
    8390    /** @cat Options affecting the script executables */
    84     BOOL        fNoLoader;          /* No loader stuff. */
     91    BOOL        fNoLoader;              /* No loader stuff. */
    8592
    8693    /** @cat Options affecting the heap. */
    87     ULONG       cbHeap;             /* Initial heapsize. */
    88     ULONG       cbHeapMax;          /* Maximum heapsize. */
    89     ULONG       cbHeapResident;     /* Initial residentheapsize. */
    90     ULONG       cbHeapMaxResident;  /* Maxiumem residentheapsize. */
     94    ULONG       cbSwpHeapInit;          /* Initial heapsize. */
     95    ULONG       cbSwpHeapMax;           /* Maximum heapsize. */
     96    ULONG       cbResHeapInit;          /* Initial residentheapsize. */
     97    ULONG       cbResHeapMax;           /* Maxiumem residentheapsize. */
    9198};
    9299
     
    95102*   Global Variables                                                           *
    96103*******************************************************************************/
    97 extern struct options options; /* defined in d32globals.c */
     104extern struct options options;          /* defined in d32globals.c */
    98105
    99106#endif
  • trunk/src/win32k/misc/heaptest.c

    r2508 r2511  
    1 /* $Id: heaptest.c,v 1.4 2000-01-24 03:05:13 bird Exp $
     1/* $Id: heaptest.c,v 1.5 2000-01-24 18:18:59 bird Exp $
    22 *
    33 * Test of resident and swappable heaps.
     
    1313*   Defined Constants
    1414*******************************************************************************/
    15 #define NUMBER_OF_POINTERS      1024
    16 #define RANDOMTEST_ITERATIONS   65536*2
    17 #define Int3()          __interrupt(3)
    18 
     15#define NUMBER_OF_POINTERS      16384
     16#define RANDOMTEST_ITERATIONS   65536
     17#define EXTRA_HEAPCHECK
    1918
    2019/*******************************************************************************
     
    2524#include "smalloc.h"
    2625#include "macros.h"
     26#include "asmutils.h"
    2727#include <stdio.h>
    2828#include <stdlib.h>
    2929#include <memory.h>
    30 #include <builtin.h>
    3130
    3231
     
    4342    unsigned      crealloc;
    4443    int           i;
    45     int           fResTests = 0;
    46     int           fResSimple = 0;
    47     int           fResRandom = 0;
     44    int           fResTests = 1;
     45    int           fResSimple = 1;
     46    int           fResRandom = 1;
    4847    int           fSwpTests = 1;
    49     int           fSwpSimple = 0;
     48    int           fSwpSimple = 1;
    5049    int           fSwpRandom = 1;
    5150    enum   {malloc,realloc, free, unknown} enmLast = unknown;
     
    9897                        break;
    9998                }
    100                 memset(apv[i], 0xA, MIN(acb[i],16));
     99                memset(apv[i], 0xA, acb[i]);
    101100                cb += acb[i];
    102101            }
     
    113112                if (cb != ((acb[i] + 3) & ~3) && (cb < ((acb[i] + 3) & ~3) || cb > 52 + ((acb[i] + 3) & ~3)) )
    114113                    printf("size of avp[%d] (%d) != acb[%d] (%d)\n", i, cb, i, acb[i]);
     114                memset(apv[i], 0xF, acb[i]);
    115115                rfree(apv[i]);
    116116                enmLast = free;
     
    179179                            break;
    180180                        }
    181                         memset(apv[j], 0xA, MIN(acb[j],16));
     181                        memset(apv[j], 0xA, acb[j]);
    182182                        cAllocations++;
    183183                        cb += acb[j];
     
    236236                            apv[j] = pv;
    237237                            acb[j] = cb;
     238                            memset(apv[j], 0xB, acb[j]);
    238239                        }
    239240                        else
    240241                        {   /* free */
     242                            memset(apv[j], 0xF, acb[j]);
    241243                            rfree(apv[j]);
    242244                            enmLast = free;
     
    247249                    }
    248250                }
     251                #ifdef EXTRA_HEAPCHECK
    249252                _res_heap_check();
     253                #endif
    250254                if (RANDOMTEST_ITERATIONS/2 == i)
    251255                    _res_dump_subheaps();
     
    277281    if (fSwpTests)
    278282    {
     283        printf("\nSwappable heap tests\nSwappable heap tests\n");
    279284        if (fSwpSimple)
    280285        {
     
    282287             * Simple allocation test.
    283288             */
     289            printf("\nSimple swappable heap tests\nSimple swappable heap tests\n");
    284290            for (i = 0; i < NUMBER_OF_POINTERS; i++)
    285291            {
     
    299305                        break;
    300306                }
    301                 memset(apv[i], 0xA, MIN(acb[i],16));
     307                memset(apv[i], 0xA, acb[i]);
    302308                cb += acb[i];
    303309            }
     
    314320                if (cb != ((acb[i] + 3) & ~3) && (cb < ((acb[i] + 3) & ~3) || cb > 52 + ((acb[i] + 3) & ~3)) )
    315321                    printf("size of avp[%d] (%d) != acb[%d] (%d)\n", i, cb, i, acb[i]);
     322                memset(apv[i], 0xF, acb[i]);
    316323                sfree(apv[i]);
    317324                enmLast = free;
     
    340347             */
    341348            printf("\n"
    342                    "Random allocation and freeing test:\n");
     349                   "Random allocation and freeing test (swappable)\n"
     350                   "Random allocation and freeing test (swappable)\n"
     351                   );
    343352            for (i = 0; i < NUMBER_OF_POINTERS; i++)
    344353                apv[i] = NULL, acb[i] = 0;
     
    380389                            break;
    381390                        }
    382                         memset(apv[j], 0xA, MIN(acb[j],16));
     391                        memset(apv[j], 0xA, acb[j]);
    383392                        cAllocations++;
    384393                        cb += acb[j];
     
    437446                            apv[j] = pv;
    438447                            acb[j] = cb;
     448                            memset(apv[j], 0xB, acb[j]);
    439449                        }
    440450                        else
    441451                        {   /* free */
     452                            memset(apv[j], 0xF, acb[j]);
    442453                            sfree(apv[j]);
    443454                            enmLast = free;
     
    448459                    }
    449460                }
     461                #ifdef EXTRA_HEAPCHECK
    450462                _swp_heap_check();
     463                #endif
    451464                if (RANDOMTEST_ITERATIONS/2 == i)
     465                {
    452466                    _swp_dump_subheaps();
     467                    _res_dump_subheaps();
     468                }
    453469                if ((i % 2048) == 0)
    454470                    printf("i=%d cAllocations=%d\n", i, cAllocations);
     
    459475            printf("_swp_dump_subheaps:\n");
    460476            _swp_dump_subheaps();
     477            printf("_res_dump_subheaps:\n");
     478            _res_dump_subheaps();
    461479
    462480            printf("_swp_memfree - before heapmin: %d\n", _swp_memfree());
     
    466484            printf("_swp_dump_subheaps:\n");
    467485            _swp_dump_subheaps();
     486            printf("_res_dump_subheaps:\n");
     487            _res_dump_subheaps();
    468488        } /* fSwpRandom */
    469489    }
  • trunk/src/win32k/misc/malloc.c

    r1678 r2511  
    1 /* $Id: malloc.c,v 1.5 1999-11-10 01:45:36 bird Exp $
     1/* $Id: malloc.c,v 1.6 2000-01-24 18:19:00 bird Exp $
    22 *
    3  * Heap.
     3 * Common Heap - this forwards to the swappable heap!
    44 *
    55 * Note: This heap does very little checking on input.
    66 *       Use with care! We're running at Ring-0!
    77 *
    8  * Copyright (c) 1999 knut st. osmundsen
     8 * Copyright (c) 1999-2000 knut st. osmundsen
    99 *
    1010 * Project Odin Software License can be found in LICENSE.TXT
    1111 *
    1212 */
    13 
    14 #define static
    15 /******************************************************************************
    16 *  Defined macros and constants
    17 ******************************************************************************/
    18 #ifdef DEBUG
    19     #define DEBUG_ALLOC
    20 #endif
    21 
    22 #define SIGNATURE 0xBEEFFEEB
    23 /*#define CB_HDR (sizeof(MEMBLOCK) - 1) /* size of MEMBLOCK header (in bytes) */
    24 #define CB_HDR (int)&(((PMEMBLOCK)0)->achUserData[0])
    25 #define PNEXT_BLOCK(a) ((PMEMBLOCK)((unsigned)(a) + CB_HDR + (a)->cbSize))
    26 
    27 #define INCL_DOS
    28 #define INCL_DOSERRORS
    29 #ifdef RING0
    30     #define INCL_NOAPI
    31 #else
    32     #define INCL_DOSMEMMGR
    33 #endif
    34 
     13/*******************************************************************************
     14*   Defined Constants And Macros                                               *
     15*******************************************************************************/
     16#define INCL_NOAPI
    3517
    3618/******************************************************************************
     
    3820******************************************************************************/
    3921#include <os2.h>
    40 #ifdef RING0
    41     #include "dev32hlp.h"
    42     #include "asmutils.h"
    43 #else
    44     #include <builtin.h>
    45     #define Int3() __interrupt(3)
    46 #endif
    47 #include "log.h"
    48 #include "malloc.h"
    49 #include <memory.h>
     22#include "smalloc.h"
     23#include "rmalloc.h"
     24#include "options.h"
    5025
    51 
    52 /******************************************************************************
    53 *  Structs and Typedefs
    54 ******************************************************************************/
    55 #pragma pack(1)
    56 typedef struct _MEMBLOCK /* MB */
    57 {
    58 #ifdef DEBUG_ALLOC
    59    unsigned long     ulSignature;   /* should be SIGNATURE (0xBEEFFEEB) */
    60 #endif
    61    unsigned          cbSize;        /* size of user space (achBlock)*/
    62    struct _MEMBLOCK *pNext;
    63    unsigned char     achUserData[1];
    64 } MEMBLOCK, *PMEMBLOCK;
    65 #pragma pack()
    6626
    6727/******************************************************************************
    6828*  Global data
    6929******************************************************************************/
    70 /*#pragma info(nogen, nouni, noext)*/
    71 static PMEMBLOCK   pUsed;         /* pointer to the used memblock chain. */
    72 static PMEMBLOCK   pFree;         /* pointer to the free memblock chain. */
    73 static unsigned    cbFree;        /* bytes of free user memory in the heap.*/
    74 unsigned           _uHeapMinPtr;  /* heap pointers are greater or equal to this.*/
    75 unsigned           _uHeapMaxPtr;  /* heap pointers are less than this. */
    7630#ifndef RING0
    7731    char           fInited;       /* init flag */
    7832#endif
    7933
    80 /******************************************************************************
    81 *  Internal functions
    82 ******************************************************************************/
    83 static void         insertUsed(PMEMBLOCK pMemblock);
    84 static void         insertFree(PMEMBLOCK pMemblock);
    85 static PMEMBLOCK    getFreeMemblock(unsigned cbUserSize);
    86 static PMEMBLOCK    findBlock(PMEMBLOCK pMemblock, void *pvUser, int fWithin);
    8734
    8835
    8936/**
    90  * Inserts a memblock into the used chain
    91  * @param    pMemblock  Pointer to memblock which is to inserted.
    92  * @remark   Sorts on address.
     37 * Initiate the heap "subsystems" - both the resident and the swappable heaps.
     38 * @returns   0 on success, not 0 on error.
     39 * @param     cbResInit  Resident heap initial size.
     40 * @param     cbResMax   Resident heap maximum size.
     41 * @param     cbSwpInit  Swappable heap initial size.
     42 * @param     cbSwpMax   Swappable heap maximum size.
    9343 */
    94 static void insertUsed(PMEMBLOCK pMemblock)
     44int heapInit(unsigned cbResInit, unsigned cbResMax,
     45             unsigned cbSwpInit, unsigned cbSwpMax)
    9546{
    96     if (pUsed == NULL || pUsed > pMemblock)
    97     {
    98         pMemblock->pNext = pUsed;
    99         pUsed = pMemblock;
    100     }
    101     else
    102     {
    103         PMEMBLOCK pMb = pUsed;
    104         while (pMb->pNext != NULL && pMb->pNext < pMemblock)
    105             pMb = pMb->pNext;
     47    int rc;
    10648
    107         pMemblock->pNext = pMb->pNext;
    108         pMb->pNext= pMemblock;
    109     }
    110 }
    111 
    112 
    113 /**
    114  * Inserts a memblock into the free chain.
    115  * Merges blocks adjecent blocks.
    116  * @param    pMemblock  Pointer to memblock to insert into the free list.
    117  * @remark   Sorts on address.
    118  */
    119 static void insertFree(PMEMBLOCK pMemblock)
    120 {
    121     cbFree += pMemblock->cbSize;
    122     if (pMemblock < pFree || pFree == NULL)
    123     {
    124         /* test for merge with 2nd block */
    125         if (pFree != NULL && PNEXT_BLOCK(pMemblock) == pFree)
    126         {
    127             cbFree += pMemblock->cbSize + CB_HDR;
    128             pFree->cbSize += CB_HDR;
    129             #ifdef DEBUG_ALLOC
    130                 pMemblock->ulSignature = 0xF0EEEE0F;
    131             #endif
    132         }
    133         else
    134         {
    135            pMemblock->pNext = pFree;
    136            pFree = pMemblock;
    137 
    138         }
    139     }
    140     else
    141     {
    142         PMEMBLOCK pMb = pFree;
    143         while (pMb->pNext != NULL && pMb->pNext < pMemblock)
    144             pMb = pMb->pNext;
    145 
    146         /* test for merge with left block */
    147         if (PNEXT_BLOCK(pMb) == pMemblock)
    148         {
    149             pMb->cbSize += CB_HDR + pMemblock->cbSize;
    150             cbFree += CB_HDR;
    151             #ifdef DEBUG_ALLOC
    152                 pMemblock->ulSignature = 0xF0EEEE0F;
    153             #endif
    154             pMemblock = pMb;
    155         }
    156         else
    157         {
    158             pMemblock->pNext = pMb->pNext;
    159             pMb->pNext = pMemblock;
    160         }
    161 
    162         /* test for merge with right block */
    163         if (PNEXT_BLOCK(pMemblock) == pMemblock->pNext && pMemblock->pNext != NULL)
    164         {
    165             pMemblock->cbSize += CB_HDR + pMemblock->pNext->cbSize;
    166             cbFree += CB_HDR;
    167             #ifdef DEBUG_ALLOC
    168                 pMemblock->pNext->ulSignature = 0xF0EEEE0F;
    169             #endif
    170             pMemblock->pNext = pMemblock->pNext->pNext;
    171         }
    172     }
    173 }
    174 
    175 
    176 /**
    177  * Finds a free block at the requested size.
    178  * @returns  Pointer to block (not in free list any longer).
    179  * @param    cbUserSize  Bytes the user have requested.
    180  * @sketch   cbUserSize is aligned to nearest 4 bytes.
    181  *
    182  *
    183  */
    184 static PMEMBLOCK getFreeMemblock(unsigned cbUserSize)
    185 {
    186     PMEMBLOCK pBestFit     = NULL;
    187     PMEMBLOCK pBestFitPrev = NULL;
    188     PMEMBLOCK pCur  = pFree;
    189     PMEMBLOCK pPrev = NULL;
    190 
    191     cbUserSize = (cbUserSize + 3) & ~3;
    192 
    193     /* search for block */
    194     while (pCur != NULL)
    195     {
    196         /* check for perfect match first */
    197         if (pCur->cbSize == cbUserSize)
    198             break;
    199             /* TODO: The following test may need to be adjusted later. */
    200         else if (pCur->cbSize >= cbUserSize
    201                 && (pBestFit == NULL || pCur->cbSize < pBestFit->cbSize)
    202                 )
    203         {
    204             pBestFit = pCur;
    205             pBestFitPrev = pPrev;
    206         }
    207 
    208         /* next */
    209         pPrev = pCur;
    210         pCur = pCur->pNext;
    211     }
    212 
    213     /* link out block */
    214     if (pCur != NULL)
    215     {   /* prefect match */
    216         if (pPrev != NULL)
    217             pPrev->pNext = pCur->pNext;
    218         else
    219             pFree = pCur->pNext;
    220 
    221         cbFree -= cbUserSize;
    222     }
    223     else if (pBestFit != NULL)
    224     {   /* best fit */
    225         /* two cases 1) split block. 2) block is too small to be splitted. */
    226         if (pBestFit->cbSize > cbUserSize + CB_HDR)
    227         {
    228             pCur = (PMEMBLOCK)((unsigned)pBestFit + pBestFit->cbSize - cbUserSize);
    229             #ifdef DEBUG_ALLOC
    230                 pCur->ulSignature = SIGNATURE;
    231             #endif
    232             pCur->cbSize = cbUserSize;
    233             pBestFit->cbSize -= cbUserSize + CB_HDR;
    234 
    235             cbFree -= cbUserSize + CB_HDR;
    236         }
    237         else
    238         {
    239             if (pBestFitPrev != NULL)
    240                 pBestFitPrev->pNext = pBestFit->pNext;
    241             else
    242                 pFree = pBestFit->pNext;
    243             pCur = pBestFit;
    244 
    245             cbFree -= pCur->cbSize;
    246         }
    247     }
    248 
    249     return pCur;
    250 }
    251 
    252 
    253 /**
    254  * Finds a memory block starting the search at pMemblock.
    255  * @returns   Pointer to memblock if found.
    256  * @param     pMemblock  Start node.
    257  * @param     pvUser     User pointer to find the block to.
    258  * @param     fWithin    When this flag is set, the pointer may point anywhere within the block.
    259  */
    260 static PMEMBLOCK    findBlock(PMEMBLOCK pMemblock, void *pvUser, int fWithin)
    261 {
    262     if (pvUser != NULL && pMemblock != NULL)
    263     {
    264         if (fWithin)
    265             while (pMemblock != NULL &&
    266                    !(pvUser >= (void*)pMemblock && pvUser < (void*)PNEXT_BLOCK(pMemblock))
    267                    )
    268                 pMemblock = pMemblock->pNext;
    269         else
    270         {
    271             pvUser = (void*)((unsigned)pvUser - CB_HDR);
    272             while (pMemblock != NULL && pvUser != (void*)pMemblock)
    273                 pMemblock = pMemblock->pNext;
    274         }
    275     }
    276     else
    277         pMemblock = NULL;
    278 
    279     return pMemblock;
    280 }
    281 
    282 
    283 /**
    284  * Initiate the heap "subsystem".
    285  * @returns   0 on success, not 0 on error.
    286  * @param     cbSize  Heapsize in bytes.
    287  */
    288 int heapInit(unsigned cbSize)
    289 {
    290     pUsed = NULL;
    291 
    292     #ifdef RING0
    293         pFree = D32Hlp_VMAlloc(VMDHA_SWAP, cbSize, ~0UL);
    294     #else
    295         if (DosAllocMem((void*)&pFree, cbSize, PAG_COMMIT | PAG_READ | PAG_WRITE) != 0)
    296             pFree = NULL;
    297     #endif
    298     if (pFree == NULL)
    299     {
    300         kprintf(("unable to allocate heap memory.\n"));
    301         Int3();
    302         return -1;
    303     }
    304 
    305     #ifdef DEBUG_ALLOC
    306         pFree->ulSignature = SIGNATURE;
    307     #endif
    308     pFree->cbSize = cbSize - CB_HDR;
    309     pFree->pNext = NULL;
    310     cbFree = pFree->cbSize;
    311 
    312     _uHeapMinPtr = (unsigned)pFree + CB_HDR;
    313     _uHeapMaxPtr = (unsigned)pFree + cbSize;
    314 
    315     #ifdef DEBUG_ALLOC
    316         if (!_heap_check())
    317         {
    318             /* error! */
    319             kprintf(("%s: _heap_check failed!\n", "heapInit"));
    320             Int3();
    321             return -2;
    322         }
    323     #endif
     49    rc = resHeapInit(cbResInit, cbResMax);
     50    if (rc != 0)
     51        return rc;
     52    rc = swpHeapInit(cbSwpInit, cbSwpMax);
     53    if (rc != 0)
     54        return rc;
    32455    #ifdef RING3
    32556        fInited = TRUE;
     
    33869void * malloc(unsigned cbSize)
    33970{
    340     void *pvRet = NULL;
    341 
    342     #ifdef DEBUG_ALLOC
    343         if (!_heap_check())
    344         {
    345             kprintf(("%s: _heap_check failed!\n", "malloc"));
    346             return NULL;
    347         }
    348     #endif
    349 
    350     if (cbSize != 0)
    351     {
    352         PMEMBLOCK pMemblock = getFreeMemblock(cbSize);
    353         if (pMemblock != NULL)
    354         {
    355             insertUsed(pMemblock);
    356             pvRet = &pMemblock->achUserData[0];
    357         }
    358     }
    359     else
    360     {
    361         /* error! */
    362         kprintf(("%s: error cbSize = 0\n", "malloc"));
    363     }
    364 
    365     return pvRet;
     71    return smalloc(cbSize);
    36672}
    36773
     
    37581void *realloc(void *pv, unsigned cbNew)
    37682{
    377     PMEMBLOCK pMemblock;
    378     pMemblock = findBlock(pUsed, pv, FALSE);
    379     if (pMemblock != NULL)
    380     {
    381         void *pvRet;
    382 
    383         cbNew = (cbNew + 3) & ~3;
    384         if (cbNew <= pMemblock->cbSize)
    385         {   /* shrink block */
    386             pvRet = pv;
    387             if (cbNew + CB_HDR < pMemblock->cbSize)
    388             {   /* split block */
    389                 PMEMBLOCK pNewBlock = (PMEMBLOCK)((unsigned)pMemblock + CB_HDR + cbNew);
    390                 #ifdef DEBUG_ALLOC
    391                     pNewBlock->ulSignature = SIGNATURE;
    392                 #endif
    393                 pNewBlock->cbSize = pMemblock->cbSize - cbNew - CB_HDR;
    394                 pNewBlock->pNext = NULL;
    395                 pMemblock->cbSize = cbNew;
    396                 insertFree(pNewBlock);
    397             }
    398         }
    399         else
    400         {   /* expand block */
    401             pvRet = malloc(cbNew);
    402             if (pvRet != NULL)
    403             {
    404                 memcpy(pvRet, pv, pMemblock->cbSize);
    405                 free(pv);
    406             }
    407         }
    408         return pvRet;
    409     }
    410     return NULL;
     83    return srealloc(pv, cbNew);
    41184}
    41285
     
    41891void free(void *pv)
    41992{
    420     #ifdef DEBUG_ALLOC
    421         if (!_heap_check())
    422         {
    423             kprintf(("free: _heap_check failed!\n"));
    424             return;
    425         }
    426     #endif
    427 
    428     if (pv != NULL)
    429     {
    430         PMEMBLOCK pCur  = pUsed;
    431         PMEMBLOCK pPrev = NULL;
    432         pv = (void*)((int)pv - CB_HDR);
    433 
    434         while (pCur != NULL &&
    435         #ifdef DEBUG_ALLOC /* pointer within block */
    436                !(pv >= (void*)pCur && (void*)((unsigned)pv + CB_HDR) < (void*)PNEXT_BLOCK(pCur))
    437         #else
    438                pv != (void*)pCur
    439         #endif
    440                )
    441         {
    442             pPrev = pCur;
    443             pCur = pCur->pNext;
    444         }
    445 
    446         if (pCur != NULL)
    447         {
    448             if (pv == pCur)
    449             {
    450                 if (pPrev != NULL)
    451                     pPrev->pNext = pCur->pNext;
    452                 else
    453                     pUsed = pCur->pNext;
    454 
    455                 insertFree(pCur);
    456 
    457                 #ifdef DEBUG_ALLOC
    458                     if (!_heap_check())
    459                         kprintf(("%s: _heap_check failed 3!\n", "free"));
    460                 #endif
    461             }
    462             else
    463                 kprintf(("free: pv is not pointing to start of block.\n"));
    464         }
    465         else
    466             kprintf(("free: heap block not found!\n"));
    467     }
    468     else
    469         kprintf(("free: Free received a NULL pointer!\n"));
     93    sfree(pv);
    47094}
    47195
     
    477101unsigned _msize(void *pv)
    478102{
    479     PMEMBLOCK pBlock;
    480     #ifdef DEBUG_ALLOC
    481         if (!_heap_check())
    482             kprintf(("_msize: _heap_check failed!\n"));
    483     #endif
    484     pBlock = findBlock(pUsed, pv, FALSE);
    485     return pBlock != NULL ? pBlock->cbSize : 0;
     103    return _swp_msize(pv);
    486104}
    487105
     
    494112int _validptr(void *pv)
    495113{
    496     PMEMBLOCK pBlock;
    497 
    498     #ifdef DEBUG_ALLOC
    499         if (!_heap_check())
    500             kprintf(("_validptr: _heap_check failed!\n"));
    501     #endif
    502 
    503     pBlock = findBlock(pUsed, pv, TRUE);
    504     return pBlock != NULL;
     114    return _swp_validptr(pv);
    505115}
    506116
     
    514124int _validptr2(void *pv, unsigned cbSize)
    515125{
    516     PMEMBLOCK pBlock;
    517 
    518     #ifdef DEBUG_ALLOC
    519         if (!_heap_check())
    520             kprintf(("_validptr: _heap_check failed!\n"));
    521     #endif
    522 
    523     pBlock = findBlock(pUsed, pv, TRUE);
    524     return pBlock != NULL ? (pBlock->cbSize - ((unsigned)pv - (unsigned)pBlock - CB_HDR)) >= cbSize : FALSE;
     126    return _swp_validptr2(pv, cbSize);
    525127}
    526128
     
    536138unsigned _memfree(void)
    537139{
    538     #ifdef DEBUG_ALLOC
    539         if (!_heap_check())
    540             kprintf(("_memfree: _heap_check failed!\n"));
    541     #endif
    542     return cbFree;
     140    return _swp_memfree();
    543141}
    544142
     
    552150int _heap_check(void)
    553151{
    554     #ifdef DEBUG_ALLOC
    555         PMEMBLOCK pCurFree = pFree;
    556         PMEMBLOCK pCurUsed = pUsed;
    557 
    558         while (pCurFree != NULL || pCurUsed != NULL)
    559         {
    560             /** @sketch:
    561              * check signatures and for lost memory.
    562              *
    563              * three cases:
    564              *  1) pCurUsed adjecent to pCurUsed->pNext
    565              *  2) pCurUsed adjecent to pCurFree
    566              *  3) pCurFree adjecent to pCurFree->pNext
    567              *  4) pCurFree adjecent to pCurUsed
    568              *  5) pCurUsed is the last block
    569              *  6) pCurFree is the last block
    570              */
    571             #if 0
    572             if (pCurUsed != NULL && PNEXT_BLOCK(pCurUsed) == pCurUsed->pNext)       /* 1.*/
    573                 ;
    574             else if (pCurUsed != NULL && PNEXT_BLOCK(pCurUsed) == pCurFree)         /* 2.*/
    575                 ;
    576             else if (pCurFree != NULL && PNEXT_BLOCK(pCurFree) == pCurFree->pNext)  /* 3.*/
    577                 ;
    578             else if (pCurFree != NULL && PNEXT_BLOCK(pCurFree) == pCurUsed)         /* 4.*/
    579                 ;
    580             else if (pCurUsed != NULL && pCurFree == NULL && pCurUsed->pNext == NULL)   /* 5.*/
    581                 ;
    582             else if (pCurFree != NULL && pCurUsed == NULL && pCurFree->pNext == NULL)   /* 6.*/
    583                 ;
    584             else
    585             #else
    586             if (!( (pCurUsed != NULL && PNEXT_BLOCK(pCurUsed) == pCurUsed->pNext)    /* 1.*/
    587                 || (pCurUsed != NULL && PNEXT_BLOCK(pCurUsed) == pCurFree)           /* 2.*/
    588                 || (pCurFree != NULL && PNEXT_BLOCK(pCurFree) == pCurFree->pNext)    /* 3.*/
    589                 || (pCurFree != NULL && PNEXT_BLOCK(pCurFree) == pCurUsed)           /* 4.*/
    590                 || (pCurUsed != NULL && pCurFree == NULL && pCurUsed->pNext == NULL) /* 5.*/
    591                 || (pCurFree != NULL && pCurUsed == NULL && pCurFree->pNext == NULL) /* 6.*/
    592                  )
    593                )
    594             #endif
    595                 {
    596                 /* error hole */
    597                 kprintf(("_heap_check: internal error - memory hole!\n"));
    598                 return FALSE;
    599                 }
    600 
    601             /* check signature and advance to the next block */
    602             if (pCurUsed != NULL && (pCurFree == NULL || pCurUsed < pCurFree))
    603             {
    604                 if (pCurUsed->ulSignature != SIGNATURE)
    605                     return FALSE;
    606                 pCurUsed = pCurUsed->pNext;
    607             }
    608             else
    609             {
    610                 if (pCurFree->ulSignature != SIGNATURE)
    611                     return FALSE;
    612                 pCurFree = pCurFree->pNext;
    613             }
    614         }
    615     #endif
    616     return TRUE;
     152    return _swp_heap_check();
    617153}
    618154
     
    626162int _rmem_init(void)
    627163{
    628     int rc = heapInit(0x100000);
     164    int rc = heapInit(CB_RES_INIT, CB_RES_MAX, CB_SWP_INIT, CB_SWP_MAX);
    629165    return rc;
    630166}
  • trunk/src/win32k/misc/malloc_old.c

    r2510 r2511  
    1 /* $Id: malloc_old.c,v 1.1 2000-01-24 12:48:42 bird Exp $
     1/* $Id: malloc_old.c,v 1.2 2000-01-24 18:19:00 bird Exp $
    22 *
    33 * Heap.
     
    4040#ifdef RING0
    4141    #include "dev32hlp.h"
    42     #include "asmutils.h"
    43 #else
    44     #include <builtin.h>
    45     #define Int3() __interrupt(3)
    4642#endif
     43#include "asmutils.h"
    4744#include "log.h"
    4845#include "malloc.h"
  • 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 */
  • trunk/src/win32k/misc/smalloc_avl.c

    r2508 r2511  
    1 /* $Id: smalloc_avl.c,v 1.2 2000-01-24 03:05:14 bird Exp $
     1/* $Id: smalloc_avl.c,v 1.3 2000-01-24 18:19:00 bird Exp $
    22 *
    33 * Swappable Heap - AVL.
     
    1616*   Defined Constants And Macros                                               *
    1717*******************************************************************************/
     18#pragma info(notrd)
    1819#ifdef DEBUG
    1920    #define DEBUG_ALLOC
    20     #define ALLWAYS_HEAPCHECK
    21     #define SOMETIMES_HEAPCHECK
     21    #undef ALLWAYS_HEAPCHECK
     22    #undef SOMETIMES_HEAPCHECK
    2223#endif
    2324
     
    6061#ifdef RING0
    6162    #include "dev32hlp.h"
    62     #include "asmutils.h"
    63 #else
    64     #include <builtin.h>
    65     #define Int3() __interrupt(3)
    6663#endif
     64#include "asmutils.h"
    6765#include "log.h"
    6866#include "smalloc.h"
    6967#include "rmalloc.h"
    70 #include <memory.h>
    7168#include "dev32.h"
    7269#include "avl.h"
    7370#include "macros.h"
     71#include <memory.h>
    7472
    7573
     
    162160static PMEMBLOCK    swpFindUsedBlock(PHEAPANCHOR *ppha, void *pvUser);
    163161static PMEMBLOCK    swpFindWithinUsedBlock(PHEAPANCHOR *ppha, void *pvUser);
     162#ifdef DEBUG_ALLOC
    164163static int          swpCheckAVLTree(PMEMBLOCK pmb);
    165164static int          swpCheckAVLTreeFree(PAVLNODECORE pNode);
     165#endif
    166166static unsigned     _swp_dump_subheaps_callback(PMEMBLOCK pmb, PSUBHEAPS_CALLBACK_PARAM pCb);
    167167static unsigned     _swp_dump_allocated_callback(PMEMBLOCK pmb, PALLOCATED_CALLBACK_PARAM pParam);
     
    185185
    186186    unsigned long *pul;
    187     unsigned long  ul;
    188187    int            i = 0;
    189188    PMEMBLOCKCHUNK pmcLast = NULL;
     
    222221    while (pmc->achBitmap[i/8] & (0x1 << (i%8)))
    223222        i++;
    224     pmc->achBitmap[i/8] |=  0x1 << (i%8);
     223    pmc->achBitmap[i/8] |=  (0x1 << (i%8));
    225224    return &pmc->amb[i];
    226225    #endif
     
    251250        {
    252251            kprintf(("swpReleaseMemblock: the memblock requested to be freed are allread free!\n"));
    253             pmc->cFree++;
     252            pmc->cFree--;
    254253        }
    255254        #endif
    256         pmc->cFree--;
    257         pmc->achBitmap[i / 8] &= pmc->achBitmap[i / 8] & ~(0x1 << i % 8);
    258         #endif
     255        pmc->cFree++;
     256        pmc->achBitmap[i / 8] &= pmc->achBitmap[i / 8] & ~(0x1 << (i % 8));
    259257    }
    260258    else
    261259        kprintf(("swpReleaseMemblock: hmm pmb is not found within any pmc.\n"));
     260    #endif
    262261}
    263262
     
    368367    PMEMBLOCK   pmbRightParent;
    369368    PMEMBLOCK   pmbLeft;
    370     PMEMBLOCK   pmbTmp;
    371369
    372370    pha->cbFree += pmb->u2.cbSize;
     
    753751                    }
    754752                #endif
    755                 #ifdef RING3
    756                     fInited = TRUE;
     753                #ifndef RING0
     754                    fSwpInited = TRUE;
    757755                #endif
    758756
     
    920918                if (pvRet != NULL)
    921919                {
    922                     memcpy(pvRet, pv, pmb->u2.cbSize);
     920                    memcpy(pvRet, pv, pmb->u2.cbSize-CB_SIGNATURES);
    923921                    sfree(pv);
    924922                }
     
    10051003int _swp_validptr(void *pv)
    10061004{
    1007     PHEAPANCHOR pha;
    10081005    PMEMBLOCK   pmb;
    10091006
     
    10291026int _swp_validptr2(void *pv, unsigned cbSize)
    10301027{
    1031     PHEAPANCHOR pha;
    10321028    PMEMBLOCK   pmb;
    10331029
     
    10901086        AVLENUMDATA FreeEnumData;
    10911087        AVLENUMDATA UsedEnumData;
    1092         PMEMBLOCK pmbFree = (PMEMBLOCK)AVLBeginEnumTree(&pha->pcoreFree, &FreeEnumData, TRUE);
    1093         PMEMBLOCK pmbFreeNext = (PMEMBLOCK)AVLGetNextNode(&FreeEnumData);
    1094         PMEMBLOCK pmbUsed = (PMEMBLOCK)AVLBeginEnumTree(&pha->pcoreUsed, &UsedEnumData, TRUE);
    1095         PMEMBLOCK pmbUsedNext = (PMEMBLOCK)AVLGetNextNode(&UsedEnumData);
     1088        PMEMBLOCK pmbFree = (PMEMBLOCK)AVLBeginEnumTree(&pha->pcoreFree,
     1089                                                        (PAVLENUMDATA)SSToDS(&FreeEnumData), TRUE);
     1090        PMEMBLOCK pmbFreeNext = (PMEMBLOCK)AVLGetNextNode((PAVLENUMDATA)SSToDS(&FreeEnumData));
     1091        PMEMBLOCK pmbUsed = (PMEMBLOCK)AVLBeginEnumTree(&pha->pcoreUsed,
     1092                                                        (PAVLENUMDATA)SSToDS(&UsedEnumData), TRUE);
     1093        PMEMBLOCK pmbUsedNext = (PMEMBLOCK)AVLGetNextNode((PAVLENUMDATA)SSToDS(&UsedEnumData));
    10961094        PMEMBLOCK pmbLast = NULL;
    10971095        unsigned  cbFree = 0;
     
    12041202                pmbLast = pmbUsed;
    12051203                pmbUsed = pmbUsedNext;
    1206                 pmbUsedNext = (PMEMBLOCK)AVLGetNextNode(&UsedEnumData);
     1204                pmbUsedNext = (PMEMBLOCK)AVLGetNextNode((PAVLENUMDATA)SSToDS(&UsedEnumData));
    12071205            }
    12081206            else
     
    12441242                pmbLast = pmbFree;
    12451243                pmbFree = pmbFreeNext;
    1246                 pmbFreeNext = (PMEMBLOCK)AVLGetNextNode(&FreeEnumData);
     1244                pmbFreeNext = (PMEMBLOCK)AVLGetNextNode((PAVLENUMDATA)SSToDS(&FreeEnumData));
    12471245            }
    12481246        }
     
    13051303}
    13061304
    1307 
     1305#ifdef DEBUG_ALLOC
    13081306/**
    13091307 * Check the integrity of the a Free/Used AVL tree where Key == node pointer.
     
    13161314    {
    13171315        kprintf(("swpCheckAVLTree: Invalid Key!\n"));
     1316        Int3();
     1317        return -1;
     1318    }
     1319    if (pmb->u1.uData % ALIGNMENT != 0)
     1320    {
     1321        kprintf(("swpCheckAVLTree: Data is not correctly aligned, uData=0x%08x\n", pmb->u1.uData));
    13181322        Int3();
    13191323        return -1;
     
    13991403    return 0;
    14001404}
     1405#endif
    14011406
    14021407
     
    14061411void _swp_heapmin(void)
    14071412{
     1413    PMEMBLOCKCHUNK pmcLast;
     1414    PMEMBLOCKCHUNK pmc;
    14081415    PHEAPANCHOR pha = phaLast;
    14091416
     
    14381445            pha = pha->pPrev;
    14391446    }
     1447
     1448    pmcLast = NULL;
     1449    pmc = pmcFirst;
     1450    while (pmc != NULL)
     1451    {
     1452        #ifdef DEBUG_ALLOC
     1453        if (pmc->cFree > MEMBLOCKS_PER_CHUNK)
     1454        {
     1455            kprintf(("_swp_heapmin: internal heap error - pmc->cFree(%d) > MEMBLOCKS_PER_CHUNK(%d)\n",
     1456                     pmc->cFree, MEMBLOCKS_PER_CHUNK));
     1457        }
     1458        #endif
     1459        if (pmc->cFree == MEMBLOCKS_PER_CHUNK && pmcLast != NULL)
     1460        {
     1461            pmcLast->pNext = pmc->pNext;
     1462            rfree(pmc);
     1463            pmc = pmcLast->pNext;
     1464        }
     1465        else
     1466        {
     1467            pmcLast = pmc;
     1468            pmc = pmc->pNext;
     1469        }
     1470    }
    14401471}
    14411472
     
    14661497    while (pha != NULL)
    14671498    {
    1468         PMEMBLOCK pmb;
    1469         SUBHEAPS_CALLBACK_PARAM FreeParam = {0};
    1470         SUBHEAPS_CALLBACK_PARAM UsedParam = {0};
     1499        SUBHEAPS_CALLBACK_PARAM FreeParam = {0, 0};
     1500        SUBHEAPS_CALLBACK_PARAM UsedParam = {0, 0};
    14711501
    14721502        AVLDoWithAll(&pha->pcoreUsed, 1,
    1473                      (PAVLCALLBACK)_swp_dump_subheaps_callback, &UsedParam);
     1503                     (PAVLCALLBACK)_swp_dump_subheaps_callback, SSToDS(&UsedParam));
    14741504        AVLDoWithAll(&pha->pcoreFree, 1,
    1475                      (PAVLCALLBACK)_swp_dump_subheaps_callback, &FreeParam);
     1505                     (PAVLCALLBACK)_swp_dump_subheaps_callback, SSToDS(&FreeParam));
    14761506
    14771507        kprintf(("HeapAnchor %2d addr=0x%08x cbSize=%6d cbFree=%6d cbUsed=%6d cUsed=%4d cFree=%d\n",
     
    15151545{
    15161546    PHEAPANCHOR pha;
    1517     ALLOCATED_CALLBACK_PARAM Param = {0};
     1547    ALLOCATED_CALLBACK_PARAM Param = {cb, 0, 0};
    15181548
    15191549    kprintf(("----------------------------\n"
     
    15261556        /* iterate thru tree using callback */
    15271557        AVLDoWithAll((PPAVLNODECORE)&pha->pcoreUsed, TRUE,
    1528                      (PAVLCALLBACK)_swp_dump_allocated_callback, &Param);
     1558                     (PAVLCALLBACK)_swp_dump_allocated_callback, SSToDS(&Param));
    15291559
    15301560        /* next */
  • trunk/src/win32k/pe2lx/makefile

    r2071 r2511  
    11##############################################################################
    2 # $Id: makefile,v 1.9 1999-12-13 23:07:35 sandervl Exp $
     2# $Id: makefile,v 1.10 2000-01-24 18:19:01 bird Exp $
    33#
    44# PD-Win32 API
     
    2828
    2929
     30
    3031##############################################################################
    3132# Tools and Flags Addjustments
    3233##############################################################################
    33 CFLAGS     = $(CFLAGS)   -DRING3 -I$(PDWIN32_INCLUDE) -I$(WIN32K_INCLUDE) -DPE2LX \
     34CINCLUDES  = -I$(WIN32K_INCLUDE) -I$(PDWIN32_INCLUDE)
     35CFLAGS     = $(CINCLUDES) $(CFLAGS) -DRING3 -DPE2LX \
    3436             -Ge+ -Wall+ppt-ppc-inl-cnv-gnr-vft-gen-uni-ext- -Gm- -Gn- -Ti+ -Rn
    35 CXXFLAGS   = $(CXXFLAGS) -DRING3 -I$(PDWIN32_INCLUDE) -I$(WIN32K_INCLUDE) -DPE2LX \
     37CXXFLAGS   = $(CINCLUDES) $(CXXFLAGS) -DRING3 -DPE2LX \
    3638             -Ge+ -Wall+ppt-ppc-inl-cnv-gnr-vft- -Gm- -Gn- -Ti+ -Gx -Rn
    3739
     
    9395TARGET   = pe2lx
    9496
    95 OBJS     =  $(PE2LXOBJ)\pe2lx.$(OBJEXT)      \
    96             $(PE2LXOBJ)\pe2lxmain.$(OBJEXT)  \
    97             $(PE2LXOBJ)\modulebase.$(OBJEXT) \
    98             $(PE2LXOBJ)\malloc.$(OBJEXT)     \
    99             $(PE2LXOBJ)\new.$(OBJEXT)        \
    100             $(PE2LXOBJ)\stricmp.$(OBJEXT)    \
     97OBJS     =  $(PE2LXOBJ)\pe2lx.$(OBJEXT)         \
     98            $(PE2LXOBJ)\pe2lxmain.$(OBJEXT)     \
     99            $(PE2LXOBJ)\modulebase.$(OBJEXT)    \
     100            $(PE2LXOBJ)\malloc.$(OBJEXT)        \
     101            $(PE2LXOBJ)\smalloc_avl.$(OBJEXT)   \
     102            $(PE2LXOBJ)\avl.$(OBJEXT)           \
     103            $(PE2LXOBJ)\rmalloc_avl.$(OBJEXT)   \
     104            $(PE2LXOBJ)\new.$(OBJEXT)           \
     105            $(PE2LXOBJ)\stricmp.$(OBJEXT)       \
    101106            $(PE2LXOBJ)\vprintf.$(OBJEXT)
    102107
     
    111116
    112117
     118..\fastdep.exe:
     119    cd ..
     120    nmake fastdep.exe
     121    cd pe2lx
     122
     123depend:
     124    ..\fastdep.exe -o..\Object $(CINCLUDES) ..\misc\*.c* ..\include\*.h
     125
    113126##############################################################################
    114127# Cleanup
     
    118131
    119132
    120 ##############################################################################
    121 # dependencies by hand.
    122 ##############################################################################
    123 $(PE2LXOBJ)\pe2lx.$(OBJEXT):     \
    124     pe2lx.cpp \
    125     $(WIN32K_INCLUDE)\pe2lx.h \
    126     $(WIN32K_INCLUDE)\OS2Krnl.h \
    127     $(WIN32K_INCLUDE)\malloc.h \
    128     $(WIN32K_INCLUDE)\new.h
    129 
    130 $(PE2LXOBJ)\pe2lxmain.$(OBJEXT): \
    131     pe2lxmain.cpp \
    132     $(WIN32K_INCLUDE)\pe2lx.h \
    133     $(WIN32K_INCLUDE)\OS2Krnl.h
    134 
    135 $(PE2LXOBJ)\ModuleBase.$(OBJEXT): \
    136     $(WIN32K_LDR)\ModuleBase.cpp \
    137     $(WIN32K_INCLUDE)\malloc.h \
    138     $(WIN32K_INCLUDE)\vprintf.h \
    139     $(WIN32K_INCLUDE)\dev32.h \
    140     $(WIN32K_INCLUDE)\OS2Krnl.h \
    141     $(WIN32K_INCLUDE)\modulebase.h
    142 
    143 $(PE2LXOBJ)\malloc.$(OBJEXT): \
    144     $(WIN32K_MISC)\malloc.c \
    145     $(WIN32K_INCLUDE)\log.h \
    146     $(WIN32K_INCLUDE)\malloc.h
    147 
    148 $(PE2LXOBJ)\new.$(OBJEXT): \
    149     $(WIN32K_MISC)\new.cpp \
    150     $(WIN32K_INCLUDE)\new.h \
    151     $(WIN32K_INCLUDE)\malloc.h \
    152     $(WIN32K_INCLUDE)\log.h
    153 
    154 $(PE2LXOBJ)\vprintf.$(OBJEXT): \
    155     $(WIN32K_MISC)\vprintf.c \
    156     $(WIN32K_INCLUDE)\vprintf.h
    157 
    158 $(PE2LXOBJ)\stricmp.$(OBJEXT): \
    159     $(WIN32K_MISC)\stricmp.c
    160 
    161 
     133# !include .depend FIXME
Note: See TracChangeset for help on using the changeset viewer.