Changeset 4796 for trunk/src


Ignore:
Timestamp:
Dec 13, 2000, 12:57:16 AM (25 years ago)
Author:
sandervl
Message:

GetVolumeInformation bugfix + invalid VirtualFree calls corrected + free named shared memory

Location:
trunk/src/kernel32
Files:
5 edited

Legend:

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

    r4763 r4796  
    1 /* $Id: disk.cpp,v 1.23 2000-12-07 12:00:23 sandervl Exp $ */
     1/* $Id: disk.cpp,v 1.24 2000-12-12 23:57:15 sandervl Exp $ */
    22
    33/*
     
    304304        }
    305305    }
    306     if(lpFileSystemNameBuffer || lpMaximumComponentLength) {
     306    if(lpFileSystemNameBuffer || lpMaximumComponentLength || lpFileSystemFlags) {
    307307        if(!lpFileSystemNameBuffer) {
    308308            lpFileSystemNameBuffer = tmpstring;
  • trunk/src/kernel32/mmap.cpp

    r4496 r4796  
    1 /* $Id: mmap.cpp,v 1.45 2000-10-18 17:09:33 sandervl Exp $ */
     1/* $Id: mmap.cpp,v 1.46 2000-12-12 23:57:16 sandervl Exp $ */
    22
    33/*
     
    5757                 fClosed(FALSE)
    5858{
    59   globalmapMutex.enter(VMUTEX_WAIT_FOREVER, &hGlobalMapMutex);
    60   next    = memmaps;
    61   memmaps = this;
    62   globalmapMutex.leave(&hGlobalMapMutex);
    63 
    64   hMemFile   = hfile;
    65 
    66   mSize      = size;
    67   mProtFlags = fdwProtect;
    68   mProcessId  = GetCurrentProcess();
    69 
    70   if(lpszName) {
    71     lpszMapName = (char *)_smalloc(strlen(lpszName)+1);
    72     strcpy(lpszMapName, lpszName);
    73   }
    74   else  lpszMapName = NULL;
     59    globalmapMutex.enter(VMUTEX_WAIT_FOREVER, &hGlobalMapMutex);
     60    next    = memmaps;
     61    memmaps = this;
     62    globalmapMutex.leave(&hGlobalMapMutex);
     63
     64    hMemFile   = hfile;
     65
     66    mSize      = size;
     67    mProtFlags = fdwProtect;
     68    mProcessId  = GetCurrentProcess();
     69
     70    if(lpszName) {
     71        lpszMapName = (char *)_smalloc(strlen(lpszName)+1);
     72        strcpy(lpszMapName, lpszName);
     73    }
     74    else  lpszMapName = NULL;
    7575}
    7676//******************************************************************************
     
    8181                 fClosed(FALSE)
    8282{
    83   globalmapMutex.enter(VMUTEX_WAIT_FOREVER, &hGlobalMapMutex);
    84   next    = memmaps;
    85   memmaps = this;
    86   globalmapMutex.leave(&hGlobalMapMutex);
    87 
    88   hMemFile   = -1;
    89 
    90   mSize      = size;
    91   mProtFlags = PAGE_READWRITE;
    92   mProcessId = GetCurrentProcess();
    93 
    94   pMapping   = (LPVOID)baseAddress;
    95 
    96   image      = pImage;
    97   lpszMapName= NULL;
     83    globalmapMutex.enter(VMUTEX_WAIT_FOREVER, &hGlobalMapMutex);
     84    next    = memmaps;
     85    memmaps = this;
     86    globalmapMutex.leave(&hGlobalMapMutex);
     87
     88    hMemFile   = -1;
     89
     90    mSize      = size;
     91    mProtFlags = PAGE_READWRITE;
     92    mProcessId = GetCurrentProcess();
     93
     94    pMapping   = (LPVOID)baseAddress;
     95
     96    image      = pImage;
     97    lpszMapName= NULL;
    9898}
    9999//******************************************************************************
     
    101101BOOL Win32MemMap::Init(HANDLE hMemMap)
    102102{
    103   mapMutex.enter();
    104   if(hMemFile != -1)
    105   {
     103    mapMutex.enter();
     104    if(hMemFile != -1)
     105    {
    106106#if 0
    107107        if(DuplicateHandle(mProcessId, hMemFile, GetCurrentProcess(),
    108108                           &hMemFile, 0, FALSE, DUPLICATE_SAME_ACCESS) == FALSE)
    109109#else
    110     DWORD dwOdinOptions;
    111 
    112     if(!(mProtFlags & PAGE_READWRITE)) {
    113         dwOdinOptions = DUPLICATE_ACCESS_READ | DUPLICATE_SHARE_DENYNONE;
    114     }
    115     else    dwOdinOptions = DUPLICATE_ACCESS_READWRITE | DUPLICATE_SHARE_DENYNONE;
     110        DWORD dwOdinOptions;
     111
     112        if(!(mProtFlags & PAGE_READWRITE)) {
     113                dwOdinOptions = DUPLICATE_ACCESS_READ | DUPLICATE_SHARE_DENYNONE;
     114        }
     115        else    dwOdinOptions = DUPLICATE_ACCESS_READWRITE | DUPLICATE_SHARE_DENYNONE;
    116116
    117117        if(HMDuplicateHandleOdin(mProcessId, hMemFile, GetCurrentProcess(),
     
    119119#endif
    120120        {
    121         dprintf(("Win32MemMap::Init: DuplicateHandle failed!"));
    122         goto fail;
    123         }
    124     mSize = SetFilePointer(hMemFile, 0, NULL, FILE_BEGIN);
    125     mSize = SetFilePointer(hMemFile, 0, NULL, FILE_END);
    126     if(mSize == -1) {
    127         dprintf(("Win32MemMap::init: SetFilePointer failed to set pos end"));
    128         goto fail;
    129     }
    130     //SvL: Temporary limitation of size (Warp Server Advanced doesn't allow
     121            dprintf(("Win32MemMap::Init: DuplicateHandle failed!"));
     122            goto fail;
     123        }
     124        mSize = SetFilePointer(hMemFile, 0, NULL, FILE_BEGIN);
     125        mSize = SetFilePointer(hMemFile, 0, NULL, FILE_END);
     126        if(mSize == -1) {
     127            dprintf(("Win32MemMap::init: SetFilePointer failed to set pos end"));
     128            goto fail;
     129        }
     130        //SvL: Temporary limitation of size (Warp Server Advanced doesn't allow
    131131        //     one to reserve more than 450 MB (unless you override the virtual
    132132        //     memory max limit) of continuous memory; (Warp 4 much less))
    133     if(mSize > 64*1024*1024) {
    134         mSize = 64*1024*1024;
    135     }
    136   }
    137 
    138   dprintf(("CreateFileMappingA for file %x, prot %x size %d, name %s", hMemFile, mProtFlags, mSize, lpszMapName));
    139   this->hMemMap = hMemMap;
    140   mapMutex.leave();
    141   return TRUE;
     133        if(mSize > 64*1024*1024) {
     134            mSize = 64*1024*1024;
     135        }
     136    }
     137
     138    dprintf(("CreateFileMappingA for file %x, prot %x size %d, name %s", hMemFile, mProtFlags, mSize, lpszMapName));
     139    this->hMemMap = hMemMap;
     140    mapMutex.leave();
     141    return TRUE;
    142142fail:
    143   mapMutex.leave();
    144   return FALSE;
     143    mapMutex.leave();
     144    return FALSE;
    145145}
    146146//******************************************************************************
     
    148148Win32MemMap::~Win32MemMap()
    149149{
    150   Win32MemMapView::deleteViews(this); //delete all views of our memory mapped file
    151 
    152   dprintf(("Win32MemMap dtor: deleting view %x %x", pMapping, mSize));
    153 
    154   mapMutex.enter();
    155   if(lpszMapName) {
    156     free(lpszMapName);
    157   }
    158   if(pMapping && !image) {
     150    Win32MemMapView::deleteViews(this); //delete all views of our memory mapped file
     151
     152    dprintf(("Win32MemMap dtor: deleting view %x %x", pMapping, mSize));
     153
     154    mapMutex.enter();
    159155    if(lpszMapName) {
    160         OSLibDosFreeMem(pMapping);
    161     }
    162     else    VirtualFree(pMapping, mSize, MEM_RELEASE);
    163 
    164     pMapping = NULL;
    165   }
    166   if(hMemFile != -1) {
    167     dprintf(("Win32MemMap dtor: closing memory file %x", hMemFile));
    168     CloseHandle(hMemFile);
    169     hMemFile = -1;
    170   }
    171   mapMutex.leave();
    172 
    173   globalmapMutex.enter(VMUTEX_WAIT_FOREVER, &hGlobalMapMutex);
    174   Win32MemMap *map = memmaps;
    175 
    176   if(map == this) {
    177     memmaps = next;
    178   }
    179   else {
    180     while(map->next) {
    181         if(map->next == this)
    182             break;
    183         map = map->next;
    184     }
    185     if(map->next) {
    186          map->next = next;
    187     }
    188     else dprintf(("Win32MemMap::~Win32MemMap: map not found!! (%x)", this));
    189   }
    190   globalmapMutex.leave(&hGlobalMapMutex);
     156        free(lpszMapName);
     157    }
     158    if(pMapping && !image) {
     159        if(lpszMapName) {
     160                OSLibDosFreeMem(pMapping);
     161        }
     162        else    VirtualFree(pMapping, 0, MEM_RELEASE);
     163
     164        pMapping = NULL;
     165    }
     166    if(hMemFile != -1) {
     167        dprintf(("Win32MemMap dtor: closing memory file %x", hMemFile));
     168        CloseHandle(hMemFile);
     169        hMemFile = -1;
     170    }
     171    mapMutex.leave();
     172
     173    globalmapMutex.enter(VMUTEX_WAIT_FOREVER, &hGlobalMapMutex);
     174    Win32MemMap *map = memmaps;
     175
     176    if(map == this) {
     177        memmaps = next;
     178    }
     179    else {
     180        while(map->next) {
     181            if(map->next == this)
     182                break;
     183            map = map->next;
     184        }
     185        if(map->next) {
     186            map->next = next;
     187        }
     188        else dprintf(("Win32MemMap::~Win32MemMap: map not found!! (%x)", this));
     189    }
     190    globalmapMutex.leave(&hGlobalMapMutex);
    191191}
    192192//******************************************************************************
     
    196196void Win32MemMap::close()
    197197{
    198   fClosed = TRUE;
    199   if(nrMappings == 0) {
     198#ifdef DEBUG
     199    dprintf(("Win32MemMap::close %s", lpszMapName));
     200#endif
     201    fClosed = TRUE;
     202    if(nrMappings == 0) {
    200203        delete this;
    201   }
     204    }
    202205}
    203206//******************************************************************************
     
    307310BOOL Win32MemMap::unmapViewOfFile(Win32MemMapView *view)
    308311{
    309   dprintf(("Win32MemMap::unmapViewOfFile %x (nrmaps=%d)", view, nrMappings));
    310   mapMutex.enter();
    311 
    312   if(nrMappings == 0)
    313     goto fail;
    314 
    315   delete view;
    316 
    317   if(--nrMappings == 0) {
    318     VirtualFree(pMapping, mSize, MEM_RELEASE);
    319     pMapping = NULL;
    320   }
    321   mapMutex.leave();
    322 
    323   //if there are no more mappings left and the memory map's handle has been
    324   //closed, then delete the object
    325   if(nrMappings == 0 && fClosed) {
    326     delete this;
    327   }
    328   return TRUE;
     312    dprintf(("Win32MemMap::unmapViewOfFile %x (nrmaps=%d)", view, nrMappings));
     313    mapMutex.enter();
     314
     315    if(nrMappings == 0)
     316        goto fail;
     317
     318    delete view;
     319
     320    if(--nrMappings == 0) {
     321        VirtualFree(pMapping, 0, MEM_RELEASE);
     322        pMapping = NULL;
     323    }
     324    mapMutex.leave();
     325
     326    //if there are no more mappings left and the memory map's handle has been
     327    //closed, then delete the object
     328    if(nrMappings == 0 && fClosed) {
     329        delete this;
     330    }
     331    return TRUE;
    329332fail:
    330   mapMutex.leave();
    331   if(nrMappings == 0 && fClosed) {
    332     delete this;
    333   }
    334   return FALSE;
     333    mapMutex.leave();
     334    if(nrMappings == 0 && fClosed) {
     335        delete this;
     336    }
     337    return FALSE;
    335338}
    336339//******************************************************************************
     
    340343 DWORD processId = GetCurrentProcess();
    341344
    342   mapMutex.enter();
    343   ULONG memFlags = (mProtFlags & (PAGE_READONLY | PAGE_READWRITE | PAGE_WRITECOPY));
    344   ULONG fAlloc   = 0;
    345   Win32MemMapView *mapview;
    346 
    347   //@@@PH: if(fdwAccess & ~(FILE_MAP_WRITE|FILE_MAP_READ|FILE_MAP_COPY))
    348   // Docs say FILE_MAP_ALL_ACCESS is same as FILE_MAP_WRITE. Doesn't match reality though.
    349   if(fdwAccess & ~FILE_MAP_ALL_ACCESS)
    350     goto parmfail;
    351   if((fdwAccess & FILE_MAP_WRITE) && !(mProtFlags & PAGE_READWRITE))
    352     goto parmfail;
    353   if((fdwAccess & FILE_MAP_READ) && !(mProtFlags & (PAGE_READWRITE|PAGE_READONLY)))
    354     goto parmfail;
    355 
    356   //@@@PH
    357   if (fdwAccess != FILE_MAP_ALL_ACCESS)
    358     if((fdwAccess & FILE_MAP_COPY) && !(mProtFlags & PAGE_WRITECOPY))
    359       goto parmfail;
    360 
    361   if(offset+size > mSize && (!(fdwAccess & FILE_MAP_WRITE) || hMemFile == -1))
    362     goto parmfail;
    363 
    364   //SvL: TODO: Doesn't work for multiple views
    365   if(offset+size > mSize) {
    366     mSize = offset+size;
    367   }
     345    mapMutex.enter();
     346    ULONG memFlags = (mProtFlags & (PAGE_READONLY | PAGE_READWRITE | PAGE_WRITECOPY));
     347    ULONG fAlloc   = 0;
     348    Win32MemMapView *mapview;
     349
     350    //@@@PH: if(fdwAccess & ~(FILE_MAP_WRITE|FILE_MAP_READ|FILE_MAP_COPY))
     351    // Docs say FILE_MAP_ALL_ACCESS is same as FILE_MAP_WRITE. Doesn't match reality though.
     352    if(fdwAccess & ~FILE_MAP_ALL_ACCESS)
     353        goto parmfail;
     354    if((fdwAccess & FILE_MAP_WRITE) && !(mProtFlags & PAGE_READWRITE))
     355        goto parmfail;
     356    if((fdwAccess & FILE_MAP_READ) && !(mProtFlags & (PAGE_READWRITE|PAGE_READONLY)))
     357        goto parmfail;
     358
     359    //@@@PH
     360    if (fdwAccess != FILE_MAP_ALL_ACCESS)
     361        if((fdwAccess & FILE_MAP_COPY) && !(mProtFlags & PAGE_WRITECOPY))
     362        goto parmfail;
     363
     364    if(offset+size > mSize && (!(fdwAccess & FILE_MAP_WRITE) || hMemFile == -1))
     365        goto parmfail;
     366
     367    //SvL: TODO: Doesn't work for multiple views
     368    if(offset+size > mSize) {
     369        mSize = offset+size;
     370    }
    368371
    369372//TODO: If committed, read file into memory
    370373#if 0
    371   if(mProtFlags & SEC_COMMIT)
    372     fAlloc |= MEM_COMMIT;
    373   else
    374   if(mProtFlags & SEC_RESERVE)
    375     fAlloc |= MEM_RESERVE;
     374    if(mProtFlags & SEC_COMMIT)
     375        fAlloc |= MEM_COMMIT;
     376    else
     377    if(mProtFlags & SEC_RESERVE)
     378        fAlloc |= MEM_RESERVE;
    376379#else
    377   fAlloc = MEM_RESERVE;
     380    fAlloc = MEM_RESERVE;
    378381#endif
    379382
    380   //Memory has already been allocated for executable image maps (only used internally)
    381   if(!pMapping && nrMappings == 0) {//if not mapped, reserve/commit entire view
    382     //SvL: Always read/write access or else ReadFile will crash once we
    383     //     start committing pages.
    384     //     This is most likely an OS/2 bug and doesn't happen in Aurora
     383    //Memory has already been allocated for executable image maps (only used internally)
     384    if(!pMapping && nrMappings == 0) {//if not mapped, reserve/commit entire view
     385        //SvL: Always read/write access or else ReadFile will crash once we
     386        //     start committing pages.
     387        //     This is most likely an OS/2 bug and doesn't happen in Aurora
    385388        //     when allocating memory with the PAG_ANY bit set. (without this
    386389        //     flag it will also crash)
    387     if(hMemFile == -1 && lpszMapName) {
    388         pMapping = VirtualAllocShared(mSize, fAlloc, PAGE_READWRITE, lpszMapName);
    389     }
    390     else {
    391         pMapping = VirtualAlloc(0, mSize, fAlloc, PAGE_READWRITE);
    392     }
    393     if(pMapping == NULL) {
    394         dprintf(("Win32MemMap::mapFileView: VirtualAlloc %x %x %x failed!", mSize, fAlloc, memFlags));
     390        if(hMemFile == -1 && lpszMapName) {
     391            pMapping = VirtualAllocShared(mSize, fAlloc, PAGE_READWRITE, lpszMapName);
     392        }
     393        else {
     394            pMapping = VirtualAlloc(0, mSize, fAlloc, PAGE_READWRITE);
     395        }
     396        if(pMapping == NULL) {
     397            dprintf(("Win32MemMap::mapFileView: VirtualAlloc %x %x %x failed!", mSize, fAlloc, memFlags));
     398            goto fail;
     399        }
     400        //Windows NT seems to commit memory for memory maps, regardsless of the SEC_COMMIT flag
     401        if((hMemFile == -1 && !image)) {//commit memory
     402            VirtualAlloc(pMapping, mSize, MEM_COMMIT, PAGE_READWRITE);
     403        }
     404        if(hMemFile != -1 && (mProtFlags & SEC_COMMIT)) {
     405            DWORD nrPages = mSize >> PAGE_SHIFT;
     406            if(mSize & 0xFFF)
     407                nrPages++;
     408
     409            commitPage(0, FALSE, nrPages);
     410        }
     411    }
     412    mapview = new Win32MemMapView(this, offset, (size == 0) ? mSize : size, fdwAccess);
     413    if(mapview == NULL) {
    395414        goto fail;
    396415    }
    397     //Windows NT seems to commit memory for memory maps, regardsless of the SEC_COMMIT flag
    398     if((hMemFile == -1 && !image)) {//commit memory
    399         VirtualAlloc(pMapping, mSize, MEM_COMMIT, PAGE_READWRITE);
    400     }
    401     if(hMemFile != -1 && (mProtFlags & SEC_COMMIT)) {
    402         DWORD nrPages = mSize >> PAGE_SHIFT;
    403         if(mSize & 0xFFF)
    404             nrPages++;
    405 
    406         commitPage(0, FALSE, nrPages);
    407     }
    408   }
    409   mapview = new Win32MemMapView(this, offset, (size == 0) ? mSize : size, fdwAccess);
    410   if(mapview == NULL) {
    411     goto fail;
    412   }
    413   if(mapview->everythingOk() == FALSE) {
    414     dprintf(("Win32MemMap::mapFileView: !mapview->everythingOk"));
    415     delete mapview;
    416     goto fail;
    417   }
    418   nrMappings++;
    419   mapMutex.leave();
    420   return mapview->getViewAddr();
     416    if(mapview->everythingOk() == FALSE) {
     417        dprintf(("Win32MemMap::mapFileView: !mapview->everythingOk"));
     418        delete mapview;
     419        goto fail;
     420    }
     421    nrMappings++;
     422    mapMutex.leave();
     423    return mapview->getViewAddr();
    421424
    422425parmfail:
    423   dprintf(("Win32MemMap::mapFileView: ERROR_INVALID_PARAMETER"));
    424   SetLastError(ERROR_INVALID_PARAMETER);
     426    dprintf(("Win32MemMap::mapFileView: ERROR_INVALID_PARAMETER"));
     427    SetLastError(ERROR_INVALID_PARAMETER);
    425428fail:
    426   mapMutex.leave();
    427   return 0;
     429    mapMutex.leave();
     430    return 0;
    428431}
    429432//******************************************************************************
     
    586589 Win32MemMapView *tmpview  = mapviews;
    587590
    588   errorState = 0;
    589   mParentMap = map;
    590   mSize    = size;
    591   mOffset  = offset;
    592   mProcessId = GetCurrentProcess();
    593 
    594   switch(fdwAccess) {
    595   case FILE_MAP_READ:
    596     accessAttr = PAG_READ;
    597     mfAccess   = MEMMAP_ACCESS_READ;
    598     break;
    599   case FILE_MAP_ALL_ACCESS:
    600   case FILE_MAP_WRITE:
    601   case FILE_MAP_WRITE|FILE_MAP_READ:
    602   case FILE_MAP_COPY:
    603     accessAttr = (PAG_READ|PAG_WRITE);
    604     mfAccess   = MEMMAP_ACCESS_READ | MEMMAP_ACCESS_WRITE;
    605     break;
    606   }
    607   if(map->getMemName() != NULL && map->getFileHandle() == -1) {
    608     //shared memory map, so map it into our address space
    609     if(OSLibDosGetNamedSharedMem((LPVOID *)&viewaddr, map->getMemName()) != OSLIB_NOERROR) {
    610         dprintf(("new OSLibDosGetNamedSharedMem FAILED"));
    611         SetLastError(ERROR_NOT_ENOUGH_MEMORY);
    612         errorState = 1;
     591    errorState = 0;
     592    mParentMap = map;
     593    mSize    = size;
     594    mOffset  = offset;
     595    mProcessId = GetCurrentProcess();
     596    pShareViewAddr = NULL;
     597
     598    switch(fdwAccess) {
     599    case FILE_MAP_READ:
     600        accessAttr = PAG_READ;
     601        mfAccess   = MEMMAP_ACCESS_READ;
     602        break;
     603    case FILE_MAP_ALL_ACCESS:
     604    case FILE_MAP_WRITE:
     605    case FILE_MAP_WRITE|FILE_MAP_READ:
     606    case FILE_MAP_COPY:
     607        accessAttr = (PAG_READ|PAG_WRITE);
     608        mfAccess   = MEMMAP_ACCESS_READ | MEMMAP_ACCESS_WRITE;
     609        break;
     610    }
     611    if(map->getMemName() != NULL && map->getFileHandle() == -1) {
     612        //shared memory map, so map it into our address space
     613        if(OSLibDosGetNamedSharedMem((LPVOID *)&viewaddr, map->getMemName()) != OSLIB_NOERROR) {
     614            dprintf(("new OSLibDosGetNamedSharedMem FAILED"));
     615            SetLastError(ERROR_NOT_ENOUGH_MEMORY);
     616            errorState = 1;
     617            return;
     618        }
     619        pShareViewAddr = viewaddr;
     620    }
     621
     622    //view == memory mapping for executable images (only used internally)
     623    if(map->getImage()) {
     624        pMapView = map->getMappingAddr();
     625    }
     626    else {
     627        if(OSLibDosAliasMem(viewaddr, size, &pMapView, accessAttr) != OSLIB_NOERROR) {
     628            dprintf(("new OSLibDosAliasMem FAILED"));
     629            SetLastError(ERROR_NOT_ENOUGH_MEMORY);
     630            errorState = 1;
     631            return;
     632        }
     633    }
     634    dprintf(("Win32MemMapView::Win32MemMapView: created %x (alias for %x), size %d", pMapView, viewaddr, size));
     635
     636    globalviewMutex.enter();
     637    if(tmpview == NULL || tmpview->getViewAddr() > pMapView) {
     638        next     = mapviews;
     639        mapviews = this;
     640    }
     641    else {
     642        while(tmpview->next) {
     643            if(tmpview->next->getViewAddr() > pMapView) {
     644                break;
     645            }
     646            tmpview = tmpview->next;
     647        }
     648        next          = tmpview->next;
     649        tmpview->next = this;
     650    }
     651    globalviewMutex.leave();
     652}
     653//******************************************************************************
     654//******************************************************************************
     655Win32MemMapView::~Win32MemMapView()
     656{
     657    if(errorState != 0)
    613658        return;
    614     }
    615   }
    616 
    617   //view == memory mapping for executable images (only used internally)
    618   if(map->getImage()) {
    619     pMapView = map->getMappingAddr();
    620   }
    621   else {
    622     if(OSLibDosAliasMem(viewaddr, size, &pMapView, accessAttr) != OSLIB_NOERROR) {
    623         dprintf(("new OSLibDosAliasMem FAILED"));
    624         SetLastError(ERROR_NOT_ENOUGH_MEMORY);
    625         errorState = 1;
    626         return;
    627     }
    628   }
    629 
    630   dprintf(("Win32MemMapView::Win32MemMapView: created %x (alias for %x), size %d", pMapView, viewaddr, size));
    631 
    632   globalviewMutex.enter();
    633   if(tmpview == NULL || tmpview->getViewAddr() > pMapView) {
    634     next     = mapviews;
    635     mapviews = this;
    636   }
    637   else {
    638     while(tmpview->next) {
    639         if(tmpview->next->getViewAddr() > pMapView) {
    640             break;
    641         }
    642         tmpview = tmpview->next;
    643     }
    644     next          = tmpview->next;
    645     tmpview->next = this;
    646   }
    647   globalviewMutex.leave();
    648 }
    649 //******************************************************************************
    650 //******************************************************************************
    651 Win32MemMapView::~Win32MemMapView()
    652 {
    653   if(errorState != 0)
    654     return;
    655 
    656   dprintf(("Win32MemMapView dtor: deleting view %x %x", mOffset, mSize));
    657 
    658   if(mfAccess & MEMMAP_ACCESS_WRITE)
    659     mParentMap->flushView(mOffset, mSize);
    660 
    661   //Don't free memory for executable image map views (only used internally)
    662   if(!mParentMap->getImage())
    663     OSLibDosFreeMem(pMapView);
    664 
    665   globalviewMutex.enter();
    666   Win32MemMapView *view = mapviews;
    667 
    668   if(view == this) {
    669     mapviews = next;
    670   }
    671   else {
    672     while(view->next) {
    673         if(view->next == this)
    674             break;
    675         view = view->next;
    676     }
    677     if(view->next) {
    678         view->next = next;
    679     }
    680     else    dprintf(("Win32MemMapView::~Win32MemMapView: map not found!! (%x)", this));
    681   }
    682   globalviewMutex.leave();
     659
     660    dprintf(("Win32MemMapView dtor: deleting view %x %x", mOffset, mSize));
     661
     662    if(mfAccess & MEMMAP_ACCESS_WRITE)
     663        mParentMap->flushView(mOffset, mSize);
     664
     665    //Don't free memory for executable image map views (only used internally)
     666    if(!mParentMap->getImage())
     667        OSLibDosFreeMem(pMapView);
     668
     669    if(pShareViewAddr) {
     670        OSLibDosFreeMem(pShareViewAddr);
     671    }
     672
     673    globalviewMutex.enter();
     674    Win32MemMapView *view = mapviews;
     675
     676    if(view == this) {
     677        mapviews = next;
     678    }
     679    else {
     680        while(view->next) {
     681            if(view->next == this)
     682                break;
     683            view = view->next;
     684        }
     685        if(view->next) {
     686                view->next = next;
     687        }
     688        else    dprintf(("Win32MemMapView::~Win32MemMapView: map not found!! (%x)", this));
     689    }
     690    globalviewMutex.leave();
    683691}
    684692//******************************************************************************
  • trunk/src/kernel32/mmap.h

    r4496 r4796  
    1 /* $Id: mmap.h,v 1.17 2000-10-18 17:09:33 sandervl Exp $ */
     1/* $Id: mmap.h,v 1.18 2000-12-12 23:57:16 sandervl Exp $ */
    22
    33/*
     
    1717
    1818#ifndef PAGE_SIZE
    19 #define PAGE_SIZE       4096
     19#define PAGE_SIZE       4096
    2020#endif
    2121#ifndef PAGE_SHIFT
    22 #define PAGE_SHIFT      12
     22#define PAGE_SHIFT  12
    2323#endif
    2424
    2525//commit 4 pages at once when the app accesses it
    26 #define NRPAGES_TOCOMMIT        16
     26#define NRPAGES_TOCOMMIT    16
    2727
    28 #define MEMMAP_ACCESS_READ      1
    29 #define MEMMAP_ACCESS_WRITE     2
    30 #define MEMMAP_ACCESS_EXECUTE   4
     28#define MEMMAP_ACCESS_READ  1
     29#define MEMMAP_ACCESS_WRITE 2
     30#define MEMMAP_ACCESS_EXECUTE   4
    3131
    3232class Win32MemMapView;
     
    7373
    7474#ifdef __DEBUG_ALLOC__
    75         void *operator new(size_t size, const char *filename, size_t lineno)
    76         {
    77                 return _umalloc(sharedHeap, size);
    78         }
    79         void operator delete(void *location, const char *filename, size_t lineno)
    80         {
    81                 free(location);
    82         }
     75    void *operator new(size_t size, const char *filename, size_t lineno)
     76    {
     77        return _umalloc(sharedHeap, size);
     78    }
     79    void operator delete(void *location, const char *filename, size_t lineno)
     80    {
     81        free(location);
     82    }
    8383#else
    84         void *operator new(size_t size)
    85         {
    86                 return _umalloc(sharedHeap, size);
    87         }
    88         void operator delete(void *location)
    89         {
    90                 free(location);
    91         }
     84    void *operator new(size_t size)
     85    {
     86        return _umalloc(sharedHeap, size);
     87    }
     88    void operator delete(void *location)
     89    {
     90        free(location);
     91    }
    9292#endif
    9393
     
    112112private:
    113113   static Win32MemMap *memmaps;
    114           Win32MemMap *next;
     114      Win32MemMap *next;
    115115};
    116116//******************************************************************************
     
    138138
    139139#ifdef __DEBUG_ALLOC__
    140         void *operator new(size_t size, const char *filename, size_t lineno)
    141         {
    142                 return _umalloc(sharedHeap, size);
    143         }
    144         void operator delete(void *location, const char *filename, size_t lineno)
    145         {
    146                 free(location);
    147         }
     140    void *operator new(size_t size, const char *filename, size_t lineno)
     141    {
     142        return _umalloc(sharedHeap, size);
     143    }
     144    void operator delete(void *location, const char *filename, size_t lineno)
     145    {
     146        free(location);
     147    }
    148148#else
    149         void *operator new(size_t size)
    150         {
    151                 return _umalloc(sharedHeap, size);
    152         }
    153         void operator delete(void *location)
    154         {
    155                 free(location);
    156         }
     149    void *operator new(size_t size)
     150    {
     151        return _umalloc(sharedHeap, size);
     152    }
     153    void operator delete(void *location)
     154    {
     155        free(location);
     156    }
    157157#endif
    158158
     
    161161   ULONG  mProcessId;
    162162   ULONG  mfAccess, mOffset;
    163    void  *pMapView;
     163   void  *pMapView, *pShareViewAddr;
    164164
    165165   Win32MemMap *mParentMap;
  • trunk/src/kernel32/virtual.cpp

    r4592 r4796  
    1 /* $Id: virtual.cpp,v 1.37 2000-11-14 21:16:26 sandervl Exp $ */
     1/* $Id: virtual.cpp,v 1.38 2000-12-12 23:57:16 sandervl Exp $ */
    22
    33/*
     
    453453  if ( (FreeType & MEM_RELEASE) && (cbSize   != 0) )
    454454  {
     455    dprintf(("WARNING: VirtualFree: invalid parameter!!"));
    455456    SetLastError(ERROR_INVALID_PARAMETER);
    456457    return(FALSE);
     
    460461       (FreeType & MEM_RELEASE) )
    461462  {
     463    dprintf(("WARNING: VirtualFree: invalid parameter!!"));
    462464    SetLastError(ERROR_INVALID_PARAMETER);
    463465    return(FALSE);
  • trunk/src/kernel32/wintls.cpp

    r4658 r4796  
    1 /* $Id: wintls.cpp,v 1.16 2000-11-21 11:35:09 sandervl Exp $ */
     1/* $Id: wintls.cpp,v 1.17 2000-12-12 23:57:16 sandervl Exp $ */
    22/*
    33 * Win32 TLS API functions
     
    128128   tlsmem = TlsGetValue(tlsIndex);
    129129   if(tlsmem) {
    130         VirtualFree(tlsmem, tlsTotalSize, MEM_RELEASE);
     130        VirtualFree(tlsmem, 0, MEM_RELEASE);
    131131   }
    132132   else {
Note: See TracChangeset for help on using the changeset viewer.