Changeset 8898 for trunk/src


Ignore:
Timestamp:
Jul 21, 2002, 11:17:28 AM (23 years ago)
Author:
sandervl
Message:

Use shared memory in high region (> 512MB) if available + Interface changes for shared memory allocation

Location:
trunk/src/kernel32
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kernel32/heapshared.cpp

    r8877 r8898  
    1 /* $Id: heapshared.cpp,v 1.9 2002-07-15 14:28:51 sandervl Exp $ */
     1/* $Id: heapshared.cpp,v 1.10 2002-07-21 09:17:28 sandervl Exp $ */
    22/*
    33 * Shared heap functions for OS/2
     
    1818#define INCL_DOSMEMMGR
    1919#include <os2wrap.h>
    20 #include <misc.h>
     20#include <string.h>
     21#include <dbglog.h>
    2122#include <heapshared.h>
     23#include "initterm.h"
    2224
    2325#define DBG_LOCALLOG    DBG_heapshared
    2426#include "dbglocal.h"
     27
     28#define MAX_HEAPSIZE            (2048*1024)
     29#define MAX_HEAPPAGES           (MAX_HEAPSIZE/PAGE_SIZE)
     30#define INCR_HEAPSIZE           (16*1024)
    2531
    2632//Global DLL Data
     
    3238#pragma data_seg()
    3339
     40static int     privateRefCount = 0;
     41
    3442void * _LNK_CONV getmoreShared(Heap_t pHeap, size_t *size, int *clean);
    3543void _LNK_CONV releaseShared(Heap_t pHeap, void *block, size_t size);
     
    3745//******************************************************************************
    3846//******************************************************************************
    39 BOOL InitializeSharedHeap()
     47BOOL SYSTEM InitializeSharedHeap()
    4048{
    4149    APIRET rc;
     50    ULONG  flAllocMem = 0, ulSysinfo;
     51
     52    //necessary until next WGSS update
     53    if(++privateRefCount > 1) {
     54        return TRUE;
     55    }
     56
     57    rc = DosQuerySysInfo(QSV_VIRTUALADDRESSLIMIT, QSV_VIRTUALADDRESSLIMIT, &ulSysinfo, sizeof(ulSysinfo));
     58    if (rc == 0 && ulSysinfo > 512)   //VirtualAddresslimit is in MB
     59    {
     60        flAllocMem = PAG_ANY;
     61    }
    4262
    4363    if(pSharedMem == NULL) {
    44             rc = DosAllocSharedMem(&pSharedMem, NULL, MAX_HEAPSIZE, PAG_READ|PAG_WRITE|OBJ_GETTABLE);
     64            rc = DosAllocSharedMem(&pSharedMem, NULL, MAX_HEAPSIZE, PAG_READ|PAG_WRITE|OBJ_GETTABLE|flAllocMem);
    4565            if(rc != 0) {
    4666                dprintf(("InitializeSharedHeap: DosAllocSharedMem failed with %d", rc));
    47                     return FALSE;
     67            return FALSE;
    4868            }
    4969            rc = DosSetMem(pSharedMem, INCR_HEAPSIZE, PAG_READ|PAG_WRITE|PAG_COMMIT);
    5070            if(rc != 0) {
    5171                DosFreeMem(pSharedMem);
    52                     dprintf(("InitializeSharedHeap: DosSetMem failed with %d", rc));
    53                     return FALSE;
     72                dprintf(("InitializeSharedHeap: DosSetMem failed with %d", rc));
     73                return FALSE;
    5474            }
    5575            sharedHeap = _ucreate(pSharedMem, INCR_HEAPSIZE, _BLOCK_CLEAN, _HEAP_REGULAR|_HEAP_SHARED,
     
    5878            if(sharedHeap == NULL) {
    5979                DosFreeMem(pSharedMem);
    60                     dprintf(("InitializeSharedHeap: _ucreate failed!"));
    61                     return FALSE;
     80                dprintf(("InitializeSharedHeap: _ucreate failed!"));
     81                return FALSE;
    6282            }
    6383            dprintf(("KERNEL32: First InitializeSharedHeap %x %x", pSharedMem, sharedHeap));
     
    82102//******************************************************************************
    83103//******************************************************************************
    84 void DestroySharedHeap()
     104void SYSTEM DestroySharedHeap()
    85105{
    86106    dprintf(("KERNEL32: DestroySharedHeap %d", refCount));
     107    if(--privateRefCount > 0) {
     108        return;
     109    }
    87110    if(--refCount == 0) {
    88111            if(sharedHeap) {
     
    132155    {
    133156        int nrpagesfree = GetPageRangeFree(i);
    134         if(nrpagesfree >= *size/PAGE_SIZE) {
     157        if(nrpagesfree >= *size/PAGE_SIZE)
     158        {
    135159                    newblock = (PVOID)((ULONG)pSharedMem + i*PAGE_SIZE);
    136160                    rc = DosSetMem(newblock, *size, PAG_READ|PAG_WRITE|PAG_COMMIT);
     
    171195//******************************************************************************
    172196//******************************************************************************
    173 DWORD  HeapGetSharedMemBase()
    174 {
    175     dprintf(("KERNEL32: HeapGetSharedMemBase()\n"));
    176     return (DWORD) pSharedMem;
    177 }
    178 //******************************************************************************
    179 //******************************************************************************
     197void * SYSTEM _smalloc(int size)
     198{
     199    return _umalloc(sharedHeap, size);
     200}
     201//******************************************************************************
     202//******************************************************************************
     203void * SYSTEM _smallocfill(int size, int filler)
     204{
     205    void *chunk;
     206
     207    chunk =  _umalloc(sharedHeap, size);
     208    if(chunk) {
     209        memset(chunk, 0, size);
     210    }
     211    return chunk;
     212}
     213//******************************************************************************
     214//******************************************************************************
  • trunk/src/kernel32/initkernel32.cpp

    r8880 r8898  
    1 /* $Id: initkernel32.cpp,v 1.21 2002-07-15 14:40:16 sandervl Exp $
     1/* $Id: initkernel32.cpp,v 1.22 2002-07-21 09:17:28 sandervl Exp $
    22 *
    33 * KERNEL32 DLL entry point
     
    134134            OpenPrivateLogFiles();
    135135
    136             if (InitializeSharedHeap() == FALSE)
    137                 return 0UL;
    138 
    139             if (InitializeCodeHeap() == FALSE)
    140                 return 0UL;
    141 
    142136            //SvL: Do it here instead of during the exe object creation
    143137            //(std handles can be used in win32 dll initialization routines
    144138            HMInitialize();             /* store standard handles within HandleManager */
    145 
    146             InitializeMemMaps();
    147 
    148             PROFILE_LoadOdinIni();
    149             dllHandle = RegisterLxDll(hModule, 0, (PVOID)&kernel32_PEResTab);
    150             if (dllHandle == 0)
    151                 return 0UL;
    152 
    153             //SvL: Kernel32 is a special case; pe.exe loads it, so increase
    154             //     the reference count here
    155             Win32DllBase *module = Win32DllBase::findModule(dllHandle);
    156             if (module)
    157             {
    158                 module->AddRef();
    159                 module->DisableUnload();
    160             }
    161139
    162140            /* knut: check for high memory support */
     
    174152            else
    175153                flAllocMem = 0;        // no high memory support
     154
     155            if (InitializeSharedHeap() == FALSE)
     156                return 0UL;
     157
     158            if (InitializeCodeHeap() == FALSE)
     159                return 0UL;
     160
     161            InitializeMemMaps();
     162
     163            PROFILE_LoadOdinIni();
     164            dllHandle = RegisterLxDll(hModule, 0, (PVOID)&kernel32_PEResTab);
     165            if (dllHandle == 0)
     166                return 0UL;
     167
     168            //SvL: Kernel32 is a special case; pe.exe loads it, so increase
     169            //     the reference count here
     170            Win32DllBase *module = Win32DllBase::findModule(dllHandle);
     171            if (module)
     172            {
     173                module->AddRef();
     174                module->DisableUnload();
     175            }
    176176
    177177            OSLibDosSetInitialMaxFileHandles(ODIN_DEFAULT_MAX_FILEHANDLES);
Note: See TracChangeset for help on using the changeset viewer.