Changeset 2511 for trunk/src/win32k
- Timestamp:
- Jan 24, 2000, 7:19:01 PM (26 years ago)
- Location:
- trunk/src/win32k
- Files:
-
- 1 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/win32k/Makefile
r2501 r2511 1 1 ################################################################################ 2 # $Id: Makefile,v 1.1 4 2000-01-22 18:20:55bird Exp $2 # $Id: Makefile,v 1.15 2000-01-24 18:18:59 bird Exp $ 3 3 # 4 4 # Copyright 1998-1999 knut st. osmundsen … … 154 154 object\calltab.obj \ 155 155 object\malloc.obj \ 156 object\smalloc_avl.obj \ 157 object\avl.obj \ 158 object\rmalloc_avl.obj \ 156 159 object\new.obj \ 157 160 object\stricmp.obj \ … … 159 162 object\vsprintf.obj \ 160 163 object\vprintf.obj \ 161 object\avl.obj \162 164 object\ldr.obj \ 163 165 object\myldrClose.obj \ -
trunk/src/win32k/dev32/d32init.c
r2501 r2511 1 /* $Id: d32init.c,v 1. 5 2000-01-22 18:20:57bird Exp $1 /* $Id: d32init.c,v 1.6 2000-01-24 18:18:59 bird Exp $ 2 2 * 3 3 * d32init.c - 32-bits init routines. … … 129 129 { 130 130 if (strnicmp(pszTmp, "heapm", 5) == 0) 131 options.cb HeapMax = ul;131 options.cbSwpHeapMax = ul; 132 132 else 133 options.cb Heap= ul;133 options.cbSwpHeapInit = ul; 134 134 } 135 135 } … … 189 189 { 190 190 if (strnicmp(pszTmp, "resheapm", 8) == 0) 191 options.cb HeapMaxResident= ul;191 options.cbResHeapMax = ul; 192 192 else 193 options.cb HeapResident = ul;193 options.cbResHeapInit = ul; 194 194 } 195 195 } … … 243 243 244 244 /* heap min/max corrections */ 245 if (options.cb Heap > options.cbHeapMax)246 options.cb HeapMax = options.cbHeap;247 if (options.cb HeapResident > options.cbHeapMaxResident)248 options.cb HeapMaxResident = options.cbHeapResident;245 if (options.cbSwpHeapInit > options.cbSwpHeapMax) 246 options.cbSwpHeapMax = options.cbSwpHeapInit; 247 if (options.cbResHeapInit > options.cbResHeapMax) 248 options.cbResHeapMax = options.cbResHeapInit; 249 249 250 250 /* Transfer version and build number from 16-bit probkrnl.c */ … … 277 277 */ 278 278 /* heap */ 279 if (heapInit(options.cbHeap) != NO_ERROR) 279 if (heapInit(options.cbResHeapInit, options.cbResHeapMax, 280 options.cbSwpHeapInit, options.cbSwpHeapMax) != NO_ERROR) 280 281 return STATUS_DONE | STERR | ERROR_I24_QUIET_INIT_FAIL; 281 282 -
trunk/src/win32k/include/asmutils.h
r1678 r2511 1 /* $Id: asmutils.h,v 1. 3 1999-11-10 01:45:32bird Exp $1 /* $Id: asmutils.h,v 1.4 2000-01-24 18:18:59 bird Exp $ 2 2 * 3 3 * Assembly utilities. … … 25 25 extern void _System EnableInterrupts(void); /* uniprocessor only */ 26 26 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 29 34 30 35 //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:32bird Exp $1 /* $Id: malloc.h,v 1.6 2000-01-24 18:18:59 bird Exp $ 2 2 * 3 3 * Heap. … … 28 28 * Exported Functions and Variables * 29 29 *******************************************************************************/ 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. */ 30 int heapInit(unsigned, unsigned, unsigned, 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); 42 39 43 40 … … 45 42 * Defined Constants And Macros * 46 43 *******************************************************************************/ 47 #define MINPTR _uHeapMinPtr48 #define MAXPTR _uHeapMaxPtr49 50 44 /* HeapPointer assert - old ones... */ 51 45 #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:01bird Exp $1 /* $Id: options.h,v 1.6 2000-01-24 18:18:59 bird Exp $ 2 2 * 3 3 * Options. … … 32 32 #define INFOLEVEL_INFOALL 0x00000004UL 33 33 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 34 41 /* 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.cb Heap = 0x100000; /* 1MB */\49 o.cb HeapMax = 0x100000; /* 1MB */\50 o.cb HeapResident = 0x10000; /* 64KB */\51 o.cb HeapMaxResident = 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; 52 59 53 60 … … 59 66 { 60 67 /** @cat misc */ 61 BOOL fQuiet; /* Quiet initialization. */68 BOOL fQuiet; /* Quiet initialization. */ 62 69 63 70 /** @cat logging options */ 64 USHORT usCom; /* Output port no. */65 BOOL fLogging; /* Logging. */71 USHORT usCom; /* Output port no. */ 72 BOOL fLogging; /* Logging. */ 66 73 67 74 /** @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 */ 72 79 73 80 /** @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. */ 76 83 77 84 /** @cat Options affecting the generated ELF executables */ 78 BOOL fElf; /* Elf flags. */85 BOOL fElf; /* Elf flags. */ 79 86 80 87 /** @cat Options affecting the script executables */ 81 BOOL fScript; /* Script flags. */88 BOOL fScript; /* Script flags. */ 82 89 83 90 /** @cat Options affecting the script executables */ 84 BOOL fNoLoader; /* No loader stuff. */91 BOOL fNoLoader; /* No loader stuff. */ 85 92 86 93 /** @cat Options affecting the heap. */ 87 ULONG cb Heap;/* Initial heapsize. */88 ULONG cb HeapMax;/* Maximum heapsize. */89 ULONG cb HeapResident;/* Initial residentheapsize. */90 ULONG cb HeapMaxResident;/* Maxiumem residentheapsize. */94 ULONG cbSwpHeapInit; /* Initial heapsize. */ 95 ULONG cbSwpHeapMax; /* Maximum heapsize. */ 96 ULONG cbResHeapInit; /* Initial residentheapsize. */ 97 ULONG cbResHeapMax; /* Maxiumem residentheapsize. */ 91 98 }; 92 99 … … 95 102 * Global Variables * 96 103 *******************************************************************************/ 97 extern struct options options; /* defined in d32globals.c */104 extern struct options options; /* defined in d32globals.c */ 98 105 99 106 #endif -
trunk/src/win32k/misc/heaptest.c
r2508 r2511 1 /* $Id: heaptest.c,v 1. 4 2000-01-24 03:05:13bird Exp $1 /* $Id: heaptest.c,v 1.5 2000-01-24 18:18:59 bird Exp $ 2 2 * 3 3 * Test of resident and swappable heaps. … … 13 13 * Defined Constants 14 14 *******************************************************************************/ 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 19 18 20 19 /******************************************************************************* … … 25 24 #include "smalloc.h" 26 25 #include "macros.h" 26 #include "asmutils.h" 27 27 #include <stdio.h> 28 28 #include <stdlib.h> 29 29 #include <memory.h> 30 #include <builtin.h>31 30 32 31 … … 43 42 unsigned crealloc; 44 43 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; 48 47 int fSwpTests = 1; 49 int fSwpSimple = 0;48 int fSwpSimple = 1; 50 49 int fSwpRandom = 1; 51 50 enum {malloc,realloc, free, unknown} enmLast = unknown; … … 98 97 break; 99 98 } 100 memset(apv[i], 0xA, MIN(acb[i],16));99 memset(apv[i], 0xA, acb[i]); 101 100 cb += acb[i]; 102 101 } … … 113 112 if (cb != ((acb[i] + 3) & ~3) && (cb < ((acb[i] + 3) & ~3) || cb > 52 + ((acb[i] + 3) & ~3)) ) 114 113 printf("size of avp[%d] (%d) != acb[%d] (%d)\n", i, cb, i, acb[i]); 114 memset(apv[i], 0xF, acb[i]); 115 115 rfree(apv[i]); 116 116 enmLast = free; … … 179 179 break; 180 180 } 181 memset(apv[j], 0xA, MIN(acb[j],16));181 memset(apv[j], 0xA, acb[j]); 182 182 cAllocations++; 183 183 cb += acb[j]; … … 236 236 apv[j] = pv; 237 237 acb[j] = cb; 238 memset(apv[j], 0xB, acb[j]); 238 239 } 239 240 else 240 241 { /* free */ 242 memset(apv[j], 0xF, acb[j]); 241 243 rfree(apv[j]); 242 244 enmLast = free; … … 247 249 } 248 250 } 251 #ifdef EXTRA_HEAPCHECK 249 252 _res_heap_check(); 253 #endif 250 254 if (RANDOMTEST_ITERATIONS/2 == i) 251 255 _res_dump_subheaps(); … … 277 281 if (fSwpTests) 278 282 { 283 printf("\nSwappable heap tests\nSwappable heap tests\n"); 279 284 if (fSwpSimple) 280 285 { … … 282 287 * Simple allocation test. 283 288 */ 289 printf("\nSimple swappable heap tests\nSimple swappable heap tests\n"); 284 290 for (i = 0; i < NUMBER_OF_POINTERS; i++) 285 291 { … … 299 305 break; 300 306 } 301 memset(apv[i], 0xA, MIN(acb[i],16));307 memset(apv[i], 0xA, acb[i]); 302 308 cb += acb[i]; 303 309 } … … 314 320 if (cb != ((acb[i] + 3) & ~3) && (cb < ((acb[i] + 3) & ~3) || cb > 52 + ((acb[i] + 3) & ~3)) ) 315 321 printf("size of avp[%d] (%d) != acb[%d] (%d)\n", i, cb, i, acb[i]); 322 memset(apv[i], 0xF, acb[i]); 316 323 sfree(apv[i]); 317 324 enmLast = free; … … 340 347 */ 341 348 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 ); 343 352 for (i = 0; i < NUMBER_OF_POINTERS; i++) 344 353 apv[i] = NULL, acb[i] = 0; … … 380 389 break; 381 390 } 382 memset(apv[j], 0xA, MIN(acb[j],16));391 memset(apv[j], 0xA, acb[j]); 383 392 cAllocations++; 384 393 cb += acb[j]; … … 437 446 apv[j] = pv; 438 447 acb[j] = cb; 448 memset(apv[j], 0xB, acb[j]); 439 449 } 440 450 else 441 451 { /* free */ 452 memset(apv[j], 0xF, acb[j]); 442 453 sfree(apv[j]); 443 454 enmLast = free; … … 448 459 } 449 460 } 461 #ifdef EXTRA_HEAPCHECK 450 462 _swp_heap_check(); 463 #endif 451 464 if (RANDOMTEST_ITERATIONS/2 == i) 465 { 452 466 _swp_dump_subheaps(); 467 _res_dump_subheaps(); 468 } 453 469 if ((i % 2048) == 0) 454 470 printf("i=%d cAllocations=%d\n", i, cAllocations); … … 459 475 printf("_swp_dump_subheaps:\n"); 460 476 _swp_dump_subheaps(); 477 printf("_res_dump_subheaps:\n"); 478 _res_dump_subheaps(); 461 479 462 480 printf("_swp_memfree - before heapmin: %d\n", _swp_memfree()); … … 466 484 printf("_swp_dump_subheaps:\n"); 467 485 _swp_dump_subheaps(); 486 printf("_res_dump_subheaps:\n"); 487 _res_dump_subheaps(); 468 488 } /* fSwpRandom */ 469 489 } -
trunk/src/win32k/misc/malloc.c
r1678 r2511 1 /* $Id: malloc.c,v 1. 5 1999-11-10 01:45:36bird Exp $1 /* $Id: malloc.c,v 1.6 2000-01-24 18:19:00 bird Exp $ 2 2 * 3 * Heap.3 * Common Heap - this forwards to the swappable heap! 4 4 * 5 5 * Note: This heap does very little checking on input. 6 6 * Use with care! We're running at Ring-0! 7 7 * 8 * Copyright (c) 1999 knut st. osmundsen8 * Copyright (c) 1999-2000 knut st. osmundsen 9 9 * 10 10 * Project Odin Software License can be found in LICENSE.TXT 11 11 * 12 12 */ 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 35 17 36 18 /****************************************************************************** … … 38 20 ******************************************************************************/ 39 21 #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" 50 25 51 52 /******************************************************************************53 * Structs and Typedefs54 ******************************************************************************/55 #pragma pack(1)56 typedef struct _MEMBLOCK /* MB */57 {58 #ifdef DEBUG_ALLOC59 unsigned long ulSignature; /* should be SIGNATURE (0xBEEFFEEB) */60 #endif61 unsigned cbSize; /* size of user space (achBlock)*/62 struct _MEMBLOCK *pNext;63 unsigned char achUserData[1];64 } MEMBLOCK, *PMEMBLOCK;65 #pragma pack()66 26 67 27 /****************************************************************************** 68 28 * Global data 69 29 ******************************************************************************/ 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. */76 30 #ifndef RING0 77 31 char fInited; /* init flag */ 78 32 #endif 79 33 80 /******************************************************************************81 * Internal functions82 ******************************************************************************/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);87 34 88 35 89 36 /** 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. 93 43 */ 94 static void insertUsed(PMEMBLOCK pMemblock) 44 int heapInit(unsigned cbResInit, unsigned cbResMax, 45 unsigned cbSwpInit, unsigned cbSwpMax) 95 46 { 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; 106 48 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; 324 55 #ifdef RING3 325 56 fInited = TRUE; … … 338 69 void * malloc(unsigned cbSize) 339 70 { 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); 366 72 } 367 73 … … 375 81 void *realloc(void *pv, unsigned cbNew) 376 82 { 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); 411 84 } 412 85 … … 418 91 void free(void *pv) 419 92 { 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); 470 94 } 471 95 … … 477 101 unsigned _msize(void *pv) 478 102 { 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); 486 104 } 487 105 … … 494 112 int _validptr(void *pv) 495 113 { 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); 505 115 } 506 116 … … 514 124 int _validptr2(void *pv, unsigned cbSize) 515 125 { 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); 525 127 } 526 128 … … 536 138 unsigned _memfree(void) 537 139 { 538 #ifdef DEBUG_ALLOC 539 if (!_heap_check()) 540 kprintf(("_memfree: _heap_check failed!\n")); 541 #endif 542 return cbFree; 140 return _swp_memfree(); 543 141 } 544 142 … … 552 150 int _heap_check(void) 553 151 { 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(); 617 153 } 618 154 … … 626 162 int _rmem_init(void) 627 163 { 628 int rc = heapInit( 0x100000);164 int rc = heapInit(CB_RES_INIT, CB_RES_MAX, CB_SWP_INIT, CB_SWP_MAX); 629 165 return rc; 630 166 } -
trunk/src/win32k/misc/malloc_old.c
r2510 r2511 1 /* $Id: malloc_old.c,v 1. 1 2000-01-24 12:48:42bird Exp $1 /* $Id: malloc_old.c,v 1.2 2000-01-24 18:19:00 bird Exp $ 2 2 * 3 3 * Heap. … … 40 40 #ifdef RING0 41 41 #include "dev32hlp.h" 42 #include "asmutils.h"43 #else44 #include <builtin.h>45 #define Int3() __interrupt(3)46 42 #endif 43 #include "asmutils.h" 47 44 #include "log.h" 48 45 #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:14bird Exp $1 /* $Id: rmalloc_avl.c,v 1.5 2000-01-24 18:19:00 bird Exp $ 2 2 * 3 3 * Resident Heap - AVL. … … 16 16 * Defined Constants And Macros * 17 17 *******************************************************************************/ 18 #pragma info(notrd) 18 19 #ifdef DEBUG 19 20 #define DEBUG_ALLOC 20 #define ALLWAYS_HEAPCHECK 21 #undef ALLWAYS_HEAPCHECK 22 #undef SOMETIMES_HEAPCHECK 21 23 #endif 22 24 … … 41 43 #endif 42 44 43 44 45 /****************************************************************************** 45 46 * Headerfiles … … 48 49 #ifdef RING0 49 50 #include "dev32hlp.h" 50 #include "asmutils.h"51 #else52 #include <builtin.h>53 #define Int3() __interrupt(3)54 51 #endif 52 #include "asmutils.h" 55 53 #include "log.h" 56 54 #include "rmalloc.h" 57 #include <memory.h>58 55 #include "dev32.h" 59 56 #include "avl.h" 60 57 #include "macros.h" 58 #include <memory.h> 61 59 62 60 … … 139 137 static PMEMBLOCK resFindUsedBlock(PHEAPANCHOR *ppha, void *pvUser); 140 138 static PMEMBLOCK resFindWithinUsedBlock(PHEAPANCHOR *ppha, void *pvUser); 139 #ifdef DEBUG_ALLOC 141 140 static int resCheckAVLTree(PMEMBLOCK pmb); 142 141 static int resCheckAVLTreeFree(PAVLNODECORE pNode); 142 #endif 143 143 static unsigned _res_dump_subheaps_callback(PMEMBLOCK pmb, PSUBHEAPS_CALLBACK_PARAM pCb); 144 144 static unsigned _res_dump_allocated_callback(PMEMBLOCK pmb, PALLOCATED_CALLBACK_PARAM pParam); … … 252 252 PMEMBLOCKFREE pmbfRightParent; 253 253 PMEMBLOCKFREE pmbfLeft; 254 PMEMBLOCKFREE pmbfTmp;255 254 256 255 pha->cbFree += pmb->cbSize; … … 592 591 resInsertFree(phaFirst, pmb); 593 592 594 #if def ALLWAYS_HEAPCHECK593 #if defined(ALLWAYS_HEAPCHECK) || defined(SOMETIMES_HEAPCHECK) 595 594 if (!_res_heap_check()) 596 595 { /* error! */ … … 602 601 } 603 602 #endif 604 #if def RING3605 f Inited = TRUE;603 #ifndef RING0 604 fResInited = TRUE; 606 605 #endif 607 606 return 0; … … 618 617 void * rmalloc(unsigned cbSize) 619 618 { 620 #if def ALLWAYS_HEAPCHECK619 #if defined(ALLWAYS_HEAPCHECK) || defined(SOMETIMES_HEAPCHECK) 621 620 if (!_res_heap_check()) 622 621 { … … 655 654 PHEAPANCHOR pha; 656 655 657 #if def ALLWAYS_HEAPCHECK656 #if defined(ALLWAYS_HEAPCHECK) || defined(SOMETIMES_HEAPCHECK) 658 657 if (!_res_heap_check()) 659 658 { … … 778 777 void rfree(void *pv) 779 778 { 780 #if def ALLWAYS_HEAPCHECK781 782 783 784 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 } 786 785 #endif 787 786 … … 825 824 826 825 #ifdef ALLWAYS_HEAPCHECK 827 828 826 if (!_res_heap_check()) 827 kprintf(("_res_msize: _res_heap_check failed!\n")); 829 828 #endif 830 829 … … 841 840 int _res_validptr(void *pv) 842 841 { 843 PHEAPANCHOR pha;844 842 PMEMBLOCK pmb; 845 843 846 844 #ifdef ALLWAYS_HEAPCHECK 847 848 845 if (!_res_heap_check()) 846 kprintf(("_res_validptr: _res_heap_check failed!\n")); 849 847 #endif 850 848 … … 862 860 int _res_validptr2(void *pv, unsigned cbSize) 863 861 { 864 PHEAPANCHOR pha;865 862 PMEMBLOCK pmb; 866 863 867 864 #ifdef ALLWAYS_HEAPCHECK 868 869 865 if (!_res_heap_check()) 866 kprintf(("_res_validptr: _res_heap_check failed!\n")); 870 867 #endif 871 868 … … 889 886 890 887 #ifdef ALLWAYS_HEAPCHECK 891 892 888 if (!_res_heap_check()) 889 kprintf(("_res_memfree: _res_heap_check failed!\n")); 893 890 #endif 894 891 … … 917 914 AVLENUMDATA FreeEnumData; 918 915 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)); 923 922 PMEMBLOCK pmbLast = NULL; 924 923 unsigned cbFree = 0; … … 1031 1030 pmbLast = pmbUsed; 1032 1031 pmbUsed = pmbUsedNext; 1033 pmbUsedNext = (PMEMBLOCK)AVLGetNextNode( &UsedEnumData);1032 pmbUsedNext = (PMEMBLOCK)AVLGetNextNode(SSToDS(&UsedEnumData)); 1034 1033 } 1035 1034 else … … 1071 1070 pmbLast = pmbFree; 1072 1071 pmbFree = pmbFreeNext; 1073 pmbFreeNext = (PMEMBLOCK)AVLGetNextNode( &FreeEnumData);1072 pmbFreeNext = (PMEMBLOCK)AVLGetNextNode(SSToDS(&FreeEnumData)); 1074 1073 } 1075 1074 } … … 1133 1132 1134 1133 1134 #ifdef DEBUG_ALLOC 1135 1135 /** 1136 1136 * Check the integrity of the a Free/Used AVL tree where Key == node pointer. … … 1143 1143 { 1144 1144 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)); 1145 1151 Int3(); 1146 1152 return -1; … … 1223 1229 return 0; 1224 1230 } 1231 #endif 1225 1232 1226 1233 … … 1289 1296 while (pha != NULL) 1290 1297 { 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}; 1294 1300 1295 1301 AVLDoWithAll((PPAVLNODECORE)&pha->pmbUsed, 1, 1296 (PAVLCALLBACK)_res_dump_subheaps_callback, &UsedParam);1302 (PAVLCALLBACK)_res_dump_subheaps_callback, SSToDS(&UsedParam)); 1297 1303 AVLDoWithAll((PPAVLNODECORE)&pha->pmbFree, 1, 1298 (PAVLCALLBACK)_res_dump_subheaps_callback, &FreeParam);1304 (PAVLCALLBACK)_res_dump_subheaps_callback, SSToDS(&FreeParam)); 1299 1305 1300 1306 kprintf(("HeapAnchor %2d addr=0x%08x cbSize=%6d cbFree=%6d cbUsed=%6d cUsed=%4d cFree=%d\n", … … 1338 1344 { 1339 1345 PHEAPANCHOR pha; 1340 ALLOCATED_CALLBACK_PARAM Param = { 0};1346 ALLOCATED_CALLBACK_PARAM Param = {cb, 0, 0}; 1341 1347 1342 1348 kprintf(("----------------------------\n" … … 1349 1355 /* iterate thru tree using callback */ 1350 1356 AVLDoWithAll((PPAVLNODECORE)&pha->pmbUsed, TRUE, 1351 (PAVLCALLBACK)_res_dump_allocated_callback, &Param);1357 (PAVLCALLBACK)_res_dump_allocated_callback, SSToDS(&Param)); 1352 1358 1353 1359 /* next */ -
trunk/src/win32k/misc/smalloc_avl.c
r2508 r2511 1 /* $Id: smalloc_avl.c,v 1. 2 2000-01-24 03:05:14bird Exp $1 /* $Id: smalloc_avl.c,v 1.3 2000-01-24 18:19:00 bird Exp $ 2 2 * 3 3 * Swappable Heap - AVL. … … 16 16 * Defined Constants And Macros * 17 17 *******************************************************************************/ 18 #pragma info(notrd) 18 19 #ifdef DEBUG 19 20 #define DEBUG_ALLOC 20 # defineALLWAYS_HEAPCHECK21 # defineSOMETIMES_HEAPCHECK21 #undef ALLWAYS_HEAPCHECK 22 #undef SOMETIMES_HEAPCHECK 22 23 #endif 23 24 … … 60 61 #ifdef RING0 61 62 #include "dev32hlp.h" 62 #include "asmutils.h"63 #else64 #include <builtin.h>65 #define Int3() __interrupt(3)66 63 #endif 64 #include "asmutils.h" 67 65 #include "log.h" 68 66 #include "smalloc.h" 69 67 #include "rmalloc.h" 70 #include <memory.h>71 68 #include "dev32.h" 72 69 #include "avl.h" 73 70 #include "macros.h" 71 #include <memory.h> 74 72 75 73 … … 162 160 static PMEMBLOCK swpFindUsedBlock(PHEAPANCHOR *ppha, void *pvUser); 163 161 static PMEMBLOCK swpFindWithinUsedBlock(PHEAPANCHOR *ppha, void *pvUser); 162 #ifdef DEBUG_ALLOC 164 163 static int swpCheckAVLTree(PMEMBLOCK pmb); 165 164 static int swpCheckAVLTreeFree(PAVLNODECORE pNode); 165 #endif 166 166 static unsigned _swp_dump_subheaps_callback(PMEMBLOCK pmb, PSUBHEAPS_CALLBACK_PARAM pCb); 167 167 static unsigned _swp_dump_allocated_callback(PMEMBLOCK pmb, PALLOCATED_CALLBACK_PARAM pParam); … … 185 185 186 186 unsigned long *pul; 187 unsigned long ul;188 187 int i = 0; 189 188 PMEMBLOCKCHUNK pmcLast = NULL; … … 222 221 while (pmc->achBitmap[i/8] & (0x1 << (i%8))) 223 222 i++; 224 pmc->achBitmap[i/8] |= 0x1 << (i%8);223 pmc->achBitmap[i/8] |= (0x1 << (i%8)); 225 224 return &pmc->amb[i]; 226 225 #endif … … 251 250 { 252 251 kprintf(("swpReleaseMemblock: the memblock requested to be freed are allread free!\n")); 253 pmc->cFree ++;252 pmc->cFree--; 254 253 } 255 254 #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)); 259 257 } 260 258 else 261 259 kprintf(("swpReleaseMemblock: hmm pmb is not found within any pmc.\n")); 260 #endif 262 261 } 263 262 … … 368 367 PMEMBLOCK pmbRightParent; 369 368 PMEMBLOCK pmbLeft; 370 PMEMBLOCK pmbTmp;371 369 372 370 pha->cbFree += pmb->u2.cbSize; … … 753 751 } 754 752 #endif 755 #if def RING3756 f Inited = TRUE;753 #ifndef RING0 754 fSwpInited = TRUE; 757 755 #endif 758 756 … … 920 918 if (pvRet != NULL) 921 919 { 922 memcpy(pvRet, pv, pmb->u2.cbSize );920 memcpy(pvRet, pv, pmb->u2.cbSize-CB_SIGNATURES); 923 921 sfree(pv); 924 922 } … … 1005 1003 int _swp_validptr(void *pv) 1006 1004 { 1007 PHEAPANCHOR pha;1008 1005 PMEMBLOCK pmb; 1009 1006 … … 1029 1026 int _swp_validptr2(void *pv, unsigned cbSize) 1030 1027 { 1031 PHEAPANCHOR pha;1032 1028 PMEMBLOCK pmb; 1033 1029 … … 1090 1086 AVLENUMDATA FreeEnumData; 1091 1087 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)); 1096 1094 PMEMBLOCK pmbLast = NULL; 1097 1095 unsigned cbFree = 0; … … 1204 1202 pmbLast = pmbUsed; 1205 1203 pmbUsed = pmbUsedNext; 1206 pmbUsedNext = (PMEMBLOCK)AVLGetNextNode( &UsedEnumData);1204 pmbUsedNext = (PMEMBLOCK)AVLGetNextNode((PAVLENUMDATA)SSToDS(&UsedEnumData)); 1207 1205 } 1208 1206 else … … 1244 1242 pmbLast = pmbFree; 1245 1243 pmbFree = pmbFreeNext; 1246 pmbFreeNext = (PMEMBLOCK)AVLGetNextNode( &FreeEnumData);1244 pmbFreeNext = (PMEMBLOCK)AVLGetNextNode((PAVLENUMDATA)SSToDS(&FreeEnumData)); 1247 1245 } 1248 1246 } … … 1305 1303 } 1306 1304 1307 1305 #ifdef DEBUG_ALLOC 1308 1306 /** 1309 1307 * Check the integrity of the a Free/Used AVL tree where Key == node pointer. … … 1316 1314 { 1317 1315 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)); 1318 1322 Int3(); 1319 1323 return -1; … … 1399 1403 return 0; 1400 1404 } 1405 #endif 1401 1406 1402 1407 … … 1406 1411 void _swp_heapmin(void) 1407 1412 { 1413 PMEMBLOCKCHUNK pmcLast; 1414 PMEMBLOCKCHUNK pmc; 1408 1415 PHEAPANCHOR pha = phaLast; 1409 1416 … … 1438 1445 pha = pha->pPrev; 1439 1446 } 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 } 1440 1471 } 1441 1472 … … 1466 1497 while (pha != NULL) 1467 1498 { 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}; 1471 1501 1472 1502 AVLDoWithAll(&pha->pcoreUsed, 1, 1473 (PAVLCALLBACK)_swp_dump_subheaps_callback, &UsedParam);1503 (PAVLCALLBACK)_swp_dump_subheaps_callback, SSToDS(&UsedParam)); 1474 1504 AVLDoWithAll(&pha->pcoreFree, 1, 1475 (PAVLCALLBACK)_swp_dump_subheaps_callback, &FreeParam);1505 (PAVLCALLBACK)_swp_dump_subheaps_callback, SSToDS(&FreeParam)); 1476 1506 1477 1507 kprintf(("HeapAnchor %2d addr=0x%08x cbSize=%6d cbFree=%6d cbUsed=%6d cUsed=%4d cFree=%d\n", … … 1515 1545 { 1516 1546 PHEAPANCHOR pha; 1517 ALLOCATED_CALLBACK_PARAM Param = { 0};1547 ALLOCATED_CALLBACK_PARAM Param = {cb, 0, 0}; 1518 1548 1519 1549 kprintf(("----------------------------\n" … … 1526 1556 /* iterate thru tree using callback */ 1527 1557 AVLDoWithAll((PPAVLNODECORE)&pha->pcoreUsed, TRUE, 1528 (PAVLCALLBACK)_swp_dump_allocated_callback, &Param);1558 (PAVLCALLBACK)_swp_dump_allocated_callback, SSToDS(&Param)); 1529 1559 1530 1560 /* next */ -
trunk/src/win32k/pe2lx/makefile
r2071 r2511 1 1 ############################################################################## 2 # $Id: makefile,v 1. 9 1999-12-13 23:07:35 sandervlExp $2 # $Id: makefile,v 1.10 2000-01-24 18:19:01 bird Exp $ 3 3 # 4 4 # PD-Win32 API … … 28 28 29 29 30 30 31 ############################################################################## 31 32 # Tools and Flags Addjustments 32 33 ############################################################################## 33 CFLAGS = $(CFLAGS) -DRING3 -I$(PDWIN32_INCLUDE) -I$(WIN32K_INCLUDE) -DPE2LX \ 34 CINCLUDES = -I$(WIN32K_INCLUDE) -I$(PDWIN32_INCLUDE) 35 CFLAGS = $(CINCLUDES) $(CFLAGS) -DRING3 -DPE2LX \ 34 36 -Ge+ -Wall+ppt-ppc-inl-cnv-gnr-vft-gen-uni-ext- -Gm- -Gn- -Ti+ -Rn 35 CXXFLAGS = $(C XXFLAGS) -DRING3 -I$(PDWIN32_INCLUDE) -I$(WIN32K_INCLUDE)-DPE2LX \37 CXXFLAGS = $(CINCLUDES) $(CXXFLAGS) -DRING3 -DPE2LX \ 36 38 -Ge+ -Wall+ppt-ppc-inl-cnv-gnr-vft- -Gm- -Gn- -Ti+ -Gx -Rn 37 39 … … 93 95 TARGET = pe2lx 94 96 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) \ 97 OBJS = $(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) \ 101 106 $(PE2LXOBJ)\vprintf.$(OBJEXT) 102 107 … … 111 116 112 117 118 ..\fastdep.exe: 119 cd .. 120 nmake fastdep.exe 121 cd pe2lx 122 123 depend: 124 ..\fastdep.exe -o..\Object $(CINCLUDES) ..\misc\*.c* ..\include\*.h 125 113 126 ############################################################################## 114 127 # Cleanup … … 118 131 119 132 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.