Ignore:
Timestamp:
Aug 14, 2009, 5:18:10 PM (16 years ago)
Author:
vladest
Message:
  1. Attempt to add support for DosAllocMem at specific address
  2. Fixed crashes in Handle manager when its tries to access non initialized pointer
File:
1 edited

Legend:

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

    r21302 r21339  
    339339    if(dwProtect & PAGE_NOACCESS)     *lpdwOS2Attr |= PAG_READ; //can't do this in OS/2
    340340}
     341
     342
     343#define OBJ_LOCSPECIFIC 0x1000
    341344//******************************************************************************
    342345//NOTE: Do NOT set the last error to ERROR_SUCCESS if successful. Windows
     
    377380    remainder  = cbSize & 0xFFF;
    378381    cbSize    &= ~0xFFF;
    379     if(remainder) 
     382    if(remainder)
    380383        cbSize += PAGE_SIZE;
    381384
     
    398401        flag |= PAG_READ|PAG_WRITE;
    399402    }
    400    
     403
    401404    //just do this if other options are used
    402405    if(!(flag & (PAG_READ | PAG_WRITE | PAG_EXECUTE)) || flag == 0)
     
    410413        Win32MemMap *map;
    411414        ULONG offset, nrpages, accessflags = 0;
    412    
     415
    413416        nrpages = cbSize >> PAGE_SHIFT;
    414417        if(cbSize & 0xFFF)
     
    431434            return lpvAddress;
    432435        }
     436        /* trying to allocate memory at specified address */
     437        if(fdwAllocationType & MEM_RESERVE)
     438        {
     439            rc = OSLibDosAllocMem(&Address, cbSize, flag |OBJ_LOCSPECIFIC);
     440            dprintf(("Allocation at specified address: %x. rc: %i", Address, rc));
     441            if (rc)
     442            {
     443                SetLastError(ERROR_OUTOFMEMORY);
     444                return NULL;
     445            }
     446            dprintf(("Allocated at specified address: %x. rc: %i", Address, rc));
     447            return(Address);
     448        }
    433449    }
    434450
     
    443459        //might try to commit larger part with same base address
    444460        if(rc == OSLIB_ERROR_ACCESS_DENIED && cbSize > PAGE_SIZE )
    445         { 
    446             while(cbSize) 
     461        {
     462            while(cbSize)
    447463            {
    448464                //check if the app tries to commit an already commited part of memory or change the protection flags
    449465                ULONG size = cbSize, os2flags, newrc;
    450466                newrc = OSLibDosQueryMem(lpvAddress, &size, &os2flags);
    451                 if(newrc == 0) 
     467                if(newrc == 0)
    452468                {
    453                     if(os2flags & PAG_COMMIT) 
     469                    if(os2flags & PAG_COMMIT)
    454470                    {
    455471                        dprintf(("VirtualAlloc: commit on committed memory"));
     
    457473                        {   //change protection flags
    458474                            DWORD tmp;
    459                             if(VirtualProtect(lpvAddress, size, fdwProtect, &tmp) == FALSE) 
     475                            if(VirtualProtect(lpvAddress, size, fdwProtect, &tmp) == FALSE)
    460476                            {
    461477                                dprintf(("ERROR: VirtualAlloc: commit on committed memory -> VirtualProtect failed!!"));
     
    464480                        }
    465481                    }
    466                     else 
     482                    else
    467483                    {   //commit this page (or range of pages)
    468484                        rc = OSLibDosSetMem(lpvAddress, size, flag);
     
    489505            if(rc == OSLIB_ERROR_INVALID_ADDRESS) {
    490506                rc = OSLibDosAllocMem(&Address, cbSize, flag );
    491             }           
     507            }
    492508            else {
    493509                if(rc) {
Note: See TracChangeset for help on using the changeset viewer.