home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / nsprpub / lib / msgc / src / win32gc.c < prev   
Encoding:
C/C++ Source or Header  |  1998-04-08  |  3.3 KB  |  111 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /*
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  * 
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  * 
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. /*
  20.  * GC related routines
  21.  *
  22.  */
  23. #include <windows.h>
  24. #include "prlog.h"
  25.  
  26. extern PRLogModuleInfo* _pr_msgc_lm;
  27.  
  28. #define GC_VMBASE               0x40000000
  29. #define GC_VMLIMIT              0x00FFFFFF
  30.  
  31. /************************************************************************/
  32. /*
  33. ** Machine dependent GC Heap management routines:
  34. **    _MD_GrowGCHeap
  35. */
  36. /************************************************************************/
  37.  
  38. void *baseaddr = (void*) GC_VMBASE;
  39. void *lastaddr = (void*) GC_VMBASE;
  40.  
  41. void _MD_InitGC() {}
  42.  
  43. void *_MD_GrowGCHeap(PRUint32 *sizep)
  44. {
  45.     void *addr;
  46.     size_t size;
  47.  
  48.     /* Reserve a block of memory for the GC */
  49.     if( lastaddr == baseaddr ) {
  50.         addr = VirtualAlloc( (void *)GC_VMBASE, GC_VMLIMIT, MEM_RESERVE, PAGE_READWRITE );
  51.  
  52.         /* 
  53.         ** If the GC_VMBASE address is already mapped, then let the OS choose a 
  54.         ** base address that is available...
  55.         */
  56.         if (addr == NULL) {
  57.             addr = VirtualAlloc( NULL, GC_VMLIMIT, MEM_RESERVE, PAGE_READWRITE );
  58.  
  59.             baseaddr = lastaddr = addr;
  60.             if (addr == NULL) {
  61.                 PR_LOG(_pr_msgc_lm, PR_LOG_ALWAYS, ("GC: unable to allocate heap: LastError=%ld",
  62.                        GetLastError()));
  63.                 return 0;
  64.             }
  65.         }
  66.     }
  67.     size = *sizep;
  68.  
  69.     /* Extend the mapping */
  70.     addr = VirtualAlloc( lastaddr, size, MEM_COMMIT, PAGE_READWRITE );
  71.     if (addr == NULL) {
  72.         return 0;
  73.     }
  74.  
  75.     lastaddr = ((char*)addr + size);
  76.     PR_LOG(_pr_msgc_lm, PR_LOG_ALWAYS,
  77.        ("GC: heap extends from %08x to %08x",
  78.         baseaddr, (long)baseaddr + (char*)lastaddr - (char*)baseaddr));
  79.  
  80.     return addr;
  81. }
  82.  
  83. PRBool _MD_ExtendGCHeap(char *base, PRInt32 oldSize, PRInt32 newSize) {
  84.   void* addr;
  85.  
  86.   addr = VirtualAlloc( base + oldSize, newSize - oldSize,
  87.                MEM_COMMIT, PAGE_READWRITE );
  88.   if (NULL == addr) {
  89.     PR_LOG(_pr_msgc_lm, PR_LOG_ALWAYS, ("GC: unable to extend heap: LastError=%ld",
  90.              GetLastError()));
  91.     return PR_FALSE;
  92.   }
  93.   if (base + oldSize != (char*)addr) {
  94.     PR_LOG(_pr_msgc_lm, PR_LOG_ALWAYS, ("GC: segment extension returned %x instead of %x",
  95.              addr, base + oldSize));
  96.     VirtualFree(addr, newSize - oldSize, MEM_DECOMMIT);
  97.     return PR_FALSE;
  98.   }
  99.   lastaddr = base + newSize;
  100.   PR_LOG(_pr_msgc_lm, PR_LOG_ALWAYS,
  101.      ("GC: heap now extends from %p to %p",
  102.       base, base + newSize));
  103.   return PR_TRUE;
  104. }
  105.  
  106.  
  107. void _MD_FreeGCSegment(void *base, PRInt32 len)
  108. {
  109.      (void)VirtualFree(base, 0, MEM_RELEASE);
  110. }
  111.