Changeset 15101


Ignore:
Timestamp:
Oct 26, 2000, 7:21:39 PM (24 years ago)
Author:
sandervl
Message:

registry fixes (heap corruption) + VirtualAlloc change

Location:
tags/trunk/src/kernel32
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified tags/trunk/src/kernel32/Fileio.cpp

    r14954 r15101  
    1 /* $Id: Fileio.cpp,v 1.43 2000-10-02 18:39:32 sandervl Exp $ */
     1/* $Id: Fileio.cpp,v 1.44 2000-10-26 17:21:38 sandervl Exp $ */
    22
    33/*
    44 * Win32 File IO API functions for OS/2
    55 *
    6  * Copyright 1998 Sander van Leeuwen
     6 * Copyright 1998-2000 Sander van Leeuwen
    77 * Copyright 1998 Patrick Haller
    88 *
     
    8989 int    namelen;
    9090
    91   dprintf(("FindFirstFileA %s", lpFileName));
    92   if(lpFileName == NULL || lpFindFileData == NULL) {
    93   SetLastError(ERROR_INVALID_PARAMETER);
    94   return -1;
    95   }
    96   namelen = strlen(lpFileName);
    97   if(lpFileName[namelen-1] == '\\') {
    98   filename = (char *)alloca(namelen+1);
    99   strcpy(filename, lpFileName);
    100   filename[namelen-1] = 0;
    101   }
    102   else  filename = (char *)lpFileName;
    103 
    104   return (HANDLE)OSLibDosFindFirst(filename,lpFindFileData);
     91    dprintf(("FindFirstFileA %s", lpFileName));
     92    if(lpFileName == NULL || lpFindFileData == NULL) {
     93        SetLastError(ERROR_INVALID_PARAMETER);
     94        return -1;
     95    }
     96    namelen = strlen(lpFileName);
     97    if(lpFileName[namelen-1] == '\\') {
     98        filename = (char *)alloca(namelen+1);
     99        strcpy(filename, lpFileName);
     100        filename[namelen-1] = 0;
     101    }
     102    else  filename = (char *)lpFileName;
     103
     104    return (HANDLE)OSLibDosFindFirst(filename,lpFindFileData);
    105105}
    106106//******************************************************************************
     
    112112              DWORD *,count)
    113113{
    114   return (HANDLE)OSLibDosFindFirstMulti(lpFileName,lpFindFileData,count);
     114    return (HANDLE)OSLibDosFindFirstMulti(lpFileName,lpFindFileData,count);
    115115}
    116116//******************************************************************************
     
    124124  WIN32_FIND_DATAA wfda;
    125125
    126   astring = UnicodeToAsciiString((LPWSTR)lpFileName);
    127   rc = (HANDLE)OSLibDosFindFirst(astring,&wfda);
    128 
    129   if(rc == -1) {
     126    astring = UnicodeToAsciiString((LPWSTR)lpFileName);
     127    dprintf(("FindFirstFileW %s", astring));
     128    rc = (HANDLE)OSLibDosFindFirst(astring,&wfda);
     129
     130    if(rc == -1) {
    130131        memset(lpFindFileData, 0, sizeof(WIN32_FIND_DATAW));
    131   }
    132   else {
     132    }
     133    else {
    133134        // convert back the result structure
    134135        memcpy(lpFindFileData,
     
    143144                      wfda.cAlternateFileName,
    144145                      sizeof(wfda.cAlternateFileName));
    145   }
    146   FreeAsciiString(astring);
    147   return(rc);
     146    }
     147    FreeAsciiString(astring);
     148    return(rc);
    148149}
    149150//******************************************************************************
     
    153154              WIN32_FIND_DATAA *, lpFindFileData)
    154155{
    155   return OSLibDosFindNext(hFindFile,lpFindFileData);
     156    return OSLibDosFindNext(hFindFile,lpFindFileData);
    156157}
    157158//******************************************************************************
  • TabularUnified tags/trunk/src/kernel32/KERNEL32.CPP

    r14989 r15101  
    1 /* $Id: KERNEL32.CPP,v 1.56 2000-10-04 19:36:24 sandervl Exp $ */
     1/* $Id: KERNEL32.CPP,v 1.57 2000-10-26 17:21:38 sandervl Exp $ */
    22
    33/*
     
    178178//******************************************************************************
    179179//******************************************************************************
    180 UINT WIN32API GetACP(VOID)
    181 {
    182   dprintf(("KERNEL32:  GetACP\n"));
     180ODINFUNCTION0(UINT, GetACP)
     181{
    183182  return(O32_GetACP());
    184183}
  • TabularUnified tags/trunk/src/kernel32/registry.cpp

    r15077 r15101  
    1 /* $Id: registry.cpp,v 1.6 2000-10-21 14:30:47 sandervl Exp $ */
     1/* $Id: registry.cpp,v 1.7 2000-10-26 17:21:39 sandervl Exp $ */
    22
    33/*
     
    88 * Copyright 1998 Sander van Leeuwen
    99 * Copyright 1998 Patrick Haller
     10 *
     11 *
     12 * TODO: Many unicode apis are still wrong (missing unicode conversions and wrong sizes)!!!!!
    1013 *
    1114 * Project Odin Software License can be found in LICENSE.TXT
     
    439442  if(rc == ERROR_SUCCESS)
    440443  {
    441     astring = (char *)malloc(max(*arg4, *arg7));   //class & keyname
     444    astring = (char *)malloc(max(*arg4+1, *arg7+1));   //class & keyname
    442445    strcpy(astring, (char *)arg3);
    443446    AsciiToUnicode(astring, arg3);
     
    497500 *****************************************************************************/
    498501
    499 ODINFUNCTION8(LONG,RegEnumValueW,HKEY,   arg1,
    500                                  DWORD,  arg2,
    501                                  LPWSTR, arg3,
    502                                  LPDWORD,arg4,
    503                                  LPDWORD,arg5,
    504                                  LPDWORD,arg6,
    505                                  LPBYTE, arg7,
    506                                  LPDWORD,arg8)
     502ODINFUNCTION8(LONG,RegEnumValueW,HKEY,   hkey,
     503                                 DWORD,  iValue,
     504                                 LPWSTR, lpszValue,
     505                                 LPDWORD,lpcchValue,
     506                                 LPDWORD,lpdwReserved,
     507                                 LPDWORD,lpdwType,
     508                                 LPBYTE, lpbData,
     509                                 LPDWORD,lpcbData)
    507510{
    508511  char *astring;
    509   LONG  rc;
    510 
    511   rc = O32_RegEnumValue(ConvertKey(arg1),
    512                         arg2,
    513                         (char *)arg3,
    514                         arg4,
    515                         arg5,
    516                         arg6,
    517                         arg7,
    518                         arg8);
     512  LONG  rc, oldsize = 0;
     513
     514  if(lpcbData) {
     515    oldsize = *lpcbData;
     516  }
     517  rc = O32_RegEnumValue(ConvertKey(hkey),
     518                        iValue,
     519                        (char *)lpszValue,
     520                        lpcchValue,
     521                        lpdwReserved,
     522                        lpdwType,
     523                        lpbData,
     524                        lpcbData);
    519525  if(rc == ERROR_SUCCESS)
    520526  {
    521     astring = (char *)malloc(*arg4);
    522     strcpy(astring, (char *)arg3);
    523     AsciiToUnicode(astring, arg3);
     527    astring = (char *)malloc(*lpcchValue+1); //+ 0 terminator
     528    strcpy(astring, (char *)lpszValue);
     529    AsciiToUnicode(astring, lpszValue);
    524530    free(astring);
     531
     532    if(lpcbData && lpbData)
     533    {
     534        switch(*lpdwType) {
     535        case REG_SZ:
     536        case REG_EXPAND_SZ:
     537            if(oldsize < *lpcbData*sizeof(WCHAR)) {
     538                *lpcbData = *lpcbData*sizeof(WCHAR);
     539                return ERROR_MORE_DATA;
     540            }
     541            astring = (char *)malloc(*lpcbData);
     542            strcpy(astring, (char *)lpbData);
     543            lstrcpyAtoW((LPWSTR)lpbData, astring);
     544            free(astring);
     545            break;
     546        case REG_MULTI_SZ:
     547        case REG_LINK: //???
     548            dprintf(("ERROR: key data must be translated from Unicode to Ascii!!"));
     549            break;
     550        default:
     551            break;
     552        }
     553    }
     554
    525555  }
    526556  return(rc);
     
    712742 *****************************************************************************/
    713743
    714 ODINFUNCTION12(LONG,RegQueryInfoKeyW,HKEY,       arg1,
    715                                       LPWSTR,     arg2,
    716                                       LPDWORD,    arg3,
    717                                       LPDWORD,    arg4,
    718                                       LPDWORD,    arg5,
    719                                       LPDWORD,    arg6,
    720                                       LPDWORD,    arg7,
    721                                       LPDWORD,    arg8,
    722                                       LPDWORD,    arg9,
    723                                       LPDWORD,    arg10,
    724                                       LPDWORD,    arg11,
    725                                       LPFILETIME, arg12)
     744ODINFUNCTION12(LONG,RegQueryInfoKeyW,HKEY,       hkey,
     745                                     LPWSTR,     lpszClass,
     746                                     LPDWORD,    lpcchClass,
     747                                     LPDWORD,    lpdwReserved,
     748                                     LPDWORD,    lpcSubKeys,
     749                                     LPDWORD,    lpcchMaxSubKey,
     750                                     LPDWORD,    lpcchMaxClass,
     751                                     LPDWORD,    lpcValues,
     752                                     LPDWORD,    lpcchMaxValueName,
     753                                     LPDWORD,    lpcbMaxValueData,
     754                                     LPDWORD,    lpcbSecurityDescriptor,
     755                                     LPFILETIME, lpftLastWriteTime)
    726756{
    727757  char *astring;
    728758  LONG  rc;
    729759
    730   rc = O32_RegQueryInfoKey(ConvertKey(arg1),
    731                            (char *)arg2,
    732                            arg3,
    733                            arg4,
    734                            arg5,
    735                            arg6,
    736                            arg7,
    737                            arg8,
    738                            arg9,
    739                            arg10,
    740                            arg11,
    741                            arg12);
     760  rc = O32_RegQueryInfoKey(ConvertKey(hkey),
     761                           (char *)lpszClass,
     762                           lpcchClass,
     763                           lpdwReserved,
     764                           lpcSubKeys,
     765                           lpcchMaxSubKey,
     766                           lpcchMaxClass,
     767                           lpcValues,
     768                           lpcchMaxValueName,
     769                           lpcbMaxValueData,
     770                           lpcbSecurityDescriptor,
     771                           lpftLastWriteTime);
    742772  if(rc == ERROR_SUCCESS)
    743773  {
    744     if(*arg3) {
    745             astring = (char *)malloc(*arg3);
    746         strcpy(astring, (char *)arg2);
    747             AsciiToUnicode(astring, arg2);
     774    if(*lpcchClass) {
     775            astring = (char *)malloc(*lpcchClass+1); //returned length does NOT include 0 terminator
     776            strcpy(astring, (char *)lpszClass);
     777            AsciiToUnicode(astring, lpszClass);
    748778            free(astring);
    749779    }
    750     else    *arg2 = 0;
     780    else    *lpszClass = 0;
    751781  }
     782  //TODO: lpcbMaxValueData could be wrong for string key values!!! (as it's in bytes)
    752783  return(rc);
    753784}
     
    808839  {
    809840    if(pcbValue) {
    810             astring2 = (char *)malloc(*pcbValue);
     841            astring2 = (char *)malloc(*pcbValue);   //includes 0 terminator
    811842            strcpy(astring2, (char *)lpszValue);
    812843            AsciiToUnicode(astring2, lpszValue);
  • TabularUnified tags/trunk/src/kernel32/virtual.cpp

    r14847 r15101  
    1 /* $Id: virtual.cpp,v 1.34 2000-09-18 19:26:16 sandervl Exp $ */
     1/* $Id: virtual.cpp,v 1.35 2000-10-26 17:21:39 sandervl Exp $ */
    22
    33/*
     
    2828#include "oslibdos.h"
    2929
    30 #define DBG_LOCALLOG    DBG_virtual
     30#define DBG_LOCALLOG    DBG_virtual
    3131#include "dbglocal.h"
    3232
     
    4040 *
    4141 * RETURNS
    42  *      Handle: Success
    43  *      0: Mapping object does not exist
    44  *      NULL: Failure
     42 *  Handle: Success
     43 *  0: Mapping object does not exist
     44 *  NULL: Failure
    4545 */
    4646HANDLE WINAPI CreateFileMappingA(
     
    8282 *
    8383 * RETURNS
    84  *      Handle: Success
    85  *      NULL: Failure
     84 *  Handle: Success
     85 *  NULL: Failure
    8686 */
    8787HANDLE WINAPI OpenFileMappingA(
     
    113113 *
    114114 * RETURNS
    115  *      Starting address of mapped view
    116  *      NULL: Failure
     115 *  Starting address of mapped view
     116 *  NULL: Failure
    117117 */
    118118LPVOID WINAPI MapViewOfFile(
     
    134134 *
    135135 * RETURNS
    136  *      Starting address of mapped view
    137  *      NULL: Failure
     136 *  Starting address of mapped view
     137 *  NULL: Failure
    138138 */
    139139LPVOID WINAPI MapViewOfFileEx(
     
    155155 *
    156156 * RETURNS
    157  *      TRUE: Success
    158  *      FALSE: Failure
     157 *  TRUE: Success
     158 *  FALSE: Failure
    159159 */
    160160BOOL WINAPI FlushViewOfFile(
     
    185185 *
    186186 * NOTES
    187  *      Should addr be an LPCVOID?
     187 *  Should addr be an LPCVOID?
    188188 *
    189189 * RETURNS
    190  *      TRUE: Success
    191  *      FALSE: Failure
     190 *  TRUE: Success
     191 *  FALSE: Failure
    192192 */
    193193BOOL WINAPI UnmapViewOfFile(LPVOID addr /* [in] Address where mapped view begins */
     
    216216 *
    217217 * Helper function to map a file to memory:
    218  *  name                        -       file name
    219  *  [RETURN] ptr                -       pointer to mapped file
     218 *  name            -   file name
     219 *  [RETURN] ptr        -   pointer to mapped file
    220220 */
    221221HANDLE WINAPI VIRTUAL_MapFileW( LPCWSTR name , LPVOID *lpMapping, BOOL fReadIntoMemory)
     
    241241 *
    242242 * Helper function to map a file to memory:
    243  *  name                        -       file name
    244  *  [RETURN] ptr                -       pointer to mapped file
     243 *  name            -   file name
     244 *  [RETURN] ptr        -   pointer to mapped file
    245245 */
    246246HANDLE WINAPI VIRTUAL_MapFileA( LPCSTR name , LPVOID *lpMapping, BOOL fReadIntoMemory)
     
    277277  if (cbSize > 0x7fc00000)  /* 2Gb - 4Mb */
    278278  {
    279         dprintf(("VirtualAlloc: size too large"));
     279    dprintf(("VirtualAlloc: size too large"));
    280280        SetLastError( ERROR_OUTOFMEMORY );
    281281        return NULL;
     
    285285       (fdwAllocationType & ~(MEM_COMMIT | MEM_RESERVE)))
    286286  {
    287         dprintf(("VirtualAlloc: Invalid parameter"));
     287        dprintf(("VirtualAlloc: Invalid parameter"));
    288288        SetLastError( ERROR_INVALID_PARAMETER );
    289289        return NULL;
     
    295295        flag = PAG_COMMIT;
    296296  }
    297  
     297
    298298  if(fdwAllocationType & MEM_RESERVE) {
    299         //SvL: DosRead crashes if memory is initially reserved with write
     299    //SvL: DosRead crashes if memory is initially reserved with write
    300300        //     access disabled (OS/2 bug) even if the commit sets the page
    301301        //     flags to read/write:
    302         // DosSetMem does not alter the 16 bit selectors so if you change memory
    303         // attributes and then access the memory with a 16 bit API (such as DosRead),
    304         // it will have the old (alloc time) attributes
    305         flag |= PAG_READ|PAG_WRITE;
     302    // DosSetMem does not alter the 16 bit selectors so if you change memory
     303    // attributes and then access the memory with a 16 bit API (such as DosRead),
     304    // it will have the old (alloc time) attributes
     305    flag |= PAG_READ|PAG_WRITE;
    306306  }
    307307  if(fdwProtect & PAGE_READONLY)     flag |= PAG_READ;
     
    315315
    316316  if(fdwProtect & PAGE_GUARD) {
    317         dprintf(("ERROR: PAGE_GUARD bit set for VirtualAlloc -> we don't support this right now!"));
     317        dprintf(("ERROR: PAGE_GUARD bit set for VirtualAlloc -> we don't support this right now!"));
    318318        flag |= PAG_GUARD;
    319319  }
     
    326326  }
    327327
    328   if(lpvAddress) 
     328  if(lpvAddress)
    329329  {
    330330   Win32MemMap *map;
    331331   ULONG offset, nrpages, accessflags = 0;
    332332
    333         nrpages = cbSize >> PAGE_SHIFT;
    334         if(cbSize & 0xFFF)
    335                 nrpages++;
    336 
    337         if(flag & PAG_READ) {
    338                 accessflags |= MEMMAP_ACCESS_READ;
    339         }
    340         if(flag & PAG_WRITE) {
    341                 accessflags |= MEMMAP_ACCESS_WRITE;
    342         }
    343         if(flag & PAG_EXECUTE) {
    344                 accessflags |= MEMMAP_ACCESS_EXECUTE;
    345         }
    346         map = Win32MemMapView::findMapByView((ULONG)lpvAddress, &offset, accessflags);
    347         if(map) {
    348                 //TODO: We don't allow protection flag changes for mmaped files now
    349                 map->commitPage(offset, FALSE, nrpages);
    350                 return lpvAddress;
    351         }
     333    nrpages = cbSize >> PAGE_SHIFT;
     334    if(cbSize & 0xFFF)
     335        nrpages++;
     336
     337    if(flag & PAG_READ) {
     338        accessflags |= MEMMAP_ACCESS_READ;
     339    }
     340    if(flag & PAG_WRITE) {
     341        accessflags |= MEMMAP_ACCESS_WRITE;
     342    }
     343    if(flag & PAG_EXECUTE) {
     344        accessflags |= MEMMAP_ACCESS_EXECUTE;
     345    }
     346    map = Win32MemMapView::findMapByView((ULONG)lpvAddress, &offset, accessflags);
     347    if(map) {
     348        //TODO: We don't allow protection flag changes for mmaped files now
     349        map->commitPage(offset, FALSE, nrpages);
     350        return lpvAddress;
     351    }
    352352  }
    353353
     
    362362    if(rc == OSLIB_ERROR_ACCESS_DENIED && cbSize > 4096 )
    363363    { //knut: AND more than one page
    364       char *newbase = (char *)lpvAddress + ((cbSize-1) & 0xFFFFF000); //knut: lets not start after the last page!
    365       ULONG size, os2flags;
    366 
    367       while(newbase >= (char *)lpvAddress)
    368       {  //knut: should check first page to!!
    369         size     = 4096;
    370         os2flags = 0;
    371         rc = OSLibDosQueryMem(newbase, &size, &os2flags);
    372         if(rc)
    373           break;
    374 
    375         if(os2flags & PAG_COMMIT)
     364        char *newbase = (char *)lpvAddress + ((cbSize-1) & 0xFFFFF000); //knut: lets not start after the last page!
     365        ULONG size, os2flags;
     366
     367        while(newbase >= (char *)lpvAddress)
     368        {     //knut: should check first page to!!
     369            size     = 4096;
     370            os2flags = 0;
     371            rc = OSLibDosQueryMem(newbase, &size, &os2flags);
     372            if(rc)
     373                break;
     374
     375            if(os2flags & PAG_COMMIT)
     376            {
     377                newbase += 4096;
     378                break;
     379            }
     380            newbase -= 4096;
     381        }
     382
     383        if(rc == 0)
    376384        {
    377           newbase += 4096;
    378           break;
     385            //In case it wants to commit bytes that fall into the last
     386            //page of the previous commit command
     387            if(cbSize > ((int)newbase - (int)lpvAddress))
     388                rc = OSLibDosSetMem(newbase, cbSize - ((int)newbase - (int)lpvAddress), flag);
    379389        }
    380         newbase -= 4096;
    381       }
    382 
    383       if(rc == 0)
    384       {
    385         //In case it wants to commit bytes that fall into the last
    386         //page of the previous commit command
    387         if(cbSize > ((int)newbase - (int)lpvAddress))
    388                 rc = OSLibDosSetMem(newbase, cbSize - ((int)newbase - (int)lpvAddress), flag);
    389       }
    390       else      return(NULL);
     390        else  return(NULL);
    391391
    392392    }
    393393    else
    394394    {
    395         if(rc == OSLIB_ERROR_INVALID_ADDRESS) {
    396                 rc = OSLibDosAllocMem(&Address, cbSize, flag );
    397         }
    398         else
    399         if(rc)  dprintf(("Unexpected DosSetMem error %x", rc));
     395        if(rc == OSLIB_ERROR_INVALID_ADDRESS) {
     396            rc = OSLibDosAllocMem(&Address, cbSize, flag );
     397        }
     398        else {
     399            if(rc) {
     400                //check if the app tries to commit an already commited part of memory or change the protection flags
     401                ULONG size = cbSize, os2flags, newrc;
     402                newrc = OSLibDosQueryMem(lpvAddress, &size, &os2flags);
     403                if(newrc == 0) {
     404                    if(size >= cbSize && (os2flags & PAG_COMMIT)) {
     405                            dprintf(("VirtualAlloc: commit on committed memory"));
     406                            if((flag & (PAG_READ|PAG_WRITE|PAG_EXECUTE)) != (os2flags & (PAG_READ|PAG_WRITE|PAG_EXECUTE)))
     407                            {   //change protection flags
     408                                DWORD tmp;
     409                                if(VirtualProtect(lpvAddress, cbSize, fdwAllocationType, &tmp) == TRUE) {
     410                                    return lpvAddress;
     411                                }
     412                                dprintf(("ERROR: VirtualAlloc: commit on committed memory -> VirtualProtect failed!!"));
     413                                return NULL;
     414                            }
     415                            //else everything ok
     416                            return lpvAddress;
     417                    }
     418                    else    dprintf(("Unexpected DosSetMem error %x", rc));
     419                }
     420                else {
     421                    dprintf(("Unexpected DosQueryMem error %x", newrc));
     422                }
     423            }
     424        }
    400425    }
    401426  }
     
    446471    if(rc)
    447472    {
    448         if(rc == 32803) { //SvL: ERROR_ALIAS
    449                 dprintf(("KERNEL32:VirtualFree:OsLibSetMem rc = #%d; app tries to decommit aliased memory; ignore", rc));
    450                 return(TRUE);
    451         }
    452         dprintf(("KERNEL32:VirtualFree:OsLibSetMem rc = #%d\n", rc));
    453         SetLastError(ERROR_INVALID_ADDRESS);
    454         return(FALSE);
     473    if(rc == 32803) { //SvL: ERROR_ALIAS
     474            dprintf(("KERNEL32:VirtualFree:OsLibSetMem rc = #%d; app tries to decommit aliased memory; ignore", rc));
     475        return(TRUE);
     476    }
     477        dprintf(("KERNEL32:VirtualFree:OsLibSetMem rc = #%d\n", rc));
     478        SetLastError(ERROR_INVALID_ADDRESS);
     479    return(FALSE);
    455480    }
    456481  }
     
    492517  if(pfdwOldProtect == NULL) {
    493518        dprintf(("WARNING: pfdwOldProtect == NULL"));
    494         SetLastError(ERROR_INVALID_PARAMETER);
     519    SetLastError(ERROR_INVALID_PARAMETER);
    495520        return(FALSE);
    496521  }
     
    542567  cb = (cbSize & 0xFFF) + offset; // !!! added, some optimization :)
    543568  if( cb > 0 ) { // changed
    544         npages++;
     569    npages++;
    545570  }
    546571  if( cb > 4096 ) { // changed, note '>' sign ( not '>=' ) 4096 is exactly one page
    547         npages++;
     572    npages++;
    548573  }
    549574
     
    574599  if(pmbiBuffer == NULL || cbLength != sizeof(MEMORY_BASIC_INFORMATION)) // check parameters
    575600  {
    576         dprintf(("WARNING: invalid parameter"));
    577         SetLastError(ERROR_INVALID_PARAMETER);
    578         return 0;                             // nothing to return
     601    dprintf(("WARNING: invalid parameter"));
     602    SetLastError(ERROR_INVALID_PARAMETER);
     603        return 0;                             // nothing to return
    579604  }
    580605
     
    588613  if(rc)
    589614  {
    590         dprintf(("VirtualQuery - OSLibDosQueryMem %x %x returned %d\n",
    591                   lpBase, cbLength, rc));
    592         SetLastError(ERROR_INVALID_PARAMETER);
    593         return 0;
     615        dprintf(("VirtualQuery - OSLibDosQueryMem %x %x returned %d\n",
     616                  lpBase, cbLength, rc));
     617    SetLastError(ERROR_INVALID_PARAMETER);
     618        return 0;
    594619  }
    595620
     
    625650
    626651  if(!(dAttr & PAG_SHARED))
    627         pmbiBuffer->Type = MEM_PRIVATE;
     652        pmbiBuffer->Type = MEM_PRIVATE;
    628653
    629654  //TODO: This is not correct: AllocationProtect should contain the protection
     
    631656  pmbiBuffer->AllocationProtect = pmbiBuffer->Protect;
    632657  if(dAttr & PAG_BASE) {
    633         pmbiBuffer->AllocationBase = lpBase;
     658        pmbiBuffer->AllocationBase = lpBase;
    634659  }
    635660  else
    636661  {
    637         while(lpBase > 0)
    638         {
    639                 rc = OSLibDosQueryMem(lpBase, &cbRangeSize, &dAttr);
    640                 if(rc) {
    641                         dprintf(("VirtualQuery - OSLibDosQueryMem %x %x returned %d\n",
    642                                   lpBase, cbLength, rc));
    643                         break;
    644                 }
    645                 if(dAttr & PAG_BASE) {
    646                         pmbiBuffer->AllocationBase = lpBase;
    647                         break;
    648                 }
    649                 lpBase = (LPVOID)((ULONG)lpBase - PAGE_SIZE);
    650         }
     662        while(lpBase > 0)
     663        {
     664            rc = OSLibDosQueryMem(lpBase, &cbRangeSize, &dAttr);
     665            if(rc) {
     666                dprintf(("VirtualQuery - OSLibDosQueryMem %x %x returned %d\n",
     667                          lpBase, cbLength, rc));
     668                break;
     669            }
     670            if(dAttr & PAG_BASE) {
     671                pmbiBuffer->AllocationBase = lpBase;
     672                break;
     673            }
     674            lpBase = (LPVOID)((ULONG)lpBase - PAGE_SIZE);
     675    }
    651676  }
    652677  return sizeof(MEMORY_BASIC_INFORMATION);
     
    752777  if (cbSize > 0x7fc00000)  /* 2Gb - 4Mb */
    753778  {
    754         dprintf(("VirtualAllocShared: size too large"));
     779    dprintf(("VirtualAllocShared: size too large"));
    755780        SetLastError( ERROR_OUTOFMEMORY );
    756781        return NULL;
     
    760785       (fdwAllocationType & ~(MEM_COMMIT | MEM_RESERVE)))
    761786  {
    762         dprintf(("VirtualAllocShared: Invalid parameter"));
     787    dprintf(("VirtualAllocShared: Invalid parameter"));
    763788        SetLastError( ERROR_INVALID_PARAMETER );
    764789        return NULL;
     
    781806
    782807  if(fdwProtect & PAGE_GUARD) {
    783         dprintf(("ERROR: PAGE_GUARD bit set for VirtualAllocShared -> we don't support this right now!"));
     808    dprintf(("ERROR: PAGE_GUARD bit set for VirtualAllocShared -> we don't support this right now!"));
    784809        flag |= PAG_GUARD;
    785810  }
Note: See TracChangeset for help on using the changeset viewer.