Changeset 21339 for trunk/src


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
Location:
trunk/src/kernel32
Files:
7 edited

Legend:

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

    r21332 r21339  
    8585// this is the size of our currently static handle table
    8686#define MAX_OS2_HMHANDLES       (4*1024)
    87 
     87#define ERROR_SYS_INTERNAL      328
    8888
    8989/*****************************************************************************
     
    589589  if (HMGlobals.fIsInitialized != TRUE)
    590590  {
    591  
    592 #ifdef RAS 
    593     RasRegisterObjectTracking(&rthHandles, "KERNEL32 handles", 
    594                               0, RAS_TRACK_FLAG_LOGOBJECTCONTENT, 
     591
     592#ifdef RAS
     593    RasRegisterObjectTracking(&rthHandles, "KERNEL32 handles",
     594                              0, RAS_TRACK_FLAG_LOGOBJECTCONTENT,
    595595                              LogObjectContent_Handle, NULL);
    596596#endif
     
    15041504
    15051505  /*
    1506    * Based on testcase (5) and MSDN: 
     1506   * Based on testcase (5) and MSDN:
    15071507   *      "OF_PARSE   Fills the OFSTRUCT structure but carries out no other action."
    15081508   */
     
    17781778
    17791779  pHMHandle = &TabWin32Handles[iIndex];               /* call device handler */
     1780
     1781  if (!pHMHandle || !pHMHandle->pDeviceHandler)
     1782      return ERROR_SYS_INTERNAL;
     1783
    17801784  fResult = pHMHandle->pDeviceHandler->ReadFile(&pHMHandle->hmHandleData,
    17811785                                                lpBuffer,
     
    18291833
    18301834  pHMHandle = &TabWin32Handles[iIndex];               /* call device handler */
     1835
     1836  if (!pHMHandle || !pHMHandle->pDeviceHandler)
     1837      return ERROR_SYS_INTERNAL;
     1838
    18311839  fResult = pHMHandle->pDeviceHandler->WriteFile(&pHMHandle->hmHandleData,
    18321840                                                 lpBuffer,
     
    18661874
    18671875  pHMHandle = &TabWin32Handles[iIndex];               /* call device handler */
     1876
     1877  if (!pHMHandle || !pHMHandle->pDeviceHandler)
     1878      return ERROR_SYS_INTERNAL;
     1879
    18681880  dwResult = pHMHandle->pDeviceHandler->GetFileType(&pHMHandle->hmHandleData);
    18691881
     
    19061918
    19071919  pHMHandle = &TabWin32Handles[iIndex];               /* call device handler */
     1920
     1921  if (!pHMHandle || !pHMHandle->pDeviceHandler)
     1922      return ERROR_SYS_INTERNAL;
     1923
    19081924  dwResult = pHMHandle->pDeviceHandler->_DeviceRequest(&pHMHandle->hmHandleData,
    19091925                                                       ulRequestCode,
     
    19121928                                                       arg3,
    19131929                                                       arg4);
    1914 
    19151930  return (dwResult);                                  /* deliver return code */
    19161931}
     
    19451960
    19461961  pHMHandle = &TabWin32Handles[iIndex];               /* call device handler */
     1962
     1963  if (!pHMHandle || !pHMHandle->pDeviceHandler)
     1964      return ERROR_SYS_INTERNAL;
     1965
    19471966  dwResult = pHMHandle->pDeviceHandler->GetFileInformationByHandle(&pHMHandle->hmHandleData,
    19481967                                                       pHFI);
     
    19791998
    19801999  pHMHandle = &TabWin32Handles[iIndex];               /* call device handler */
     2000
     2001  if (!pHMHandle || !pHMHandle->pDeviceHandler)
     2002      return ERROR_SYS_INTERNAL;
     2003
    19812004  bResult = pHMHandle->pDeviceHandler->SetEndOfFile(&pHMHandle->hmHandleData);
    19822005
     
    20152038
    20162039  pHMHandle = &TabWin32Handles[iIndex];               /* call device handler */
     2040
     2041  if (!pHMHandle || !pHMHandle->pDeviceHandler)
     2042      return ERROR_SYS_INTERNAL;
     2043
    20172044  bResult = pHMHandle->pDeviceHandler->SetFileTime(&pHMHandle->hmHandleData,
    20182045                                                   (LPFILETIME)pFT1,
     
    20512078
    20522079  pHMHandle = &TabWin32Handles[iIndex];               /* call device handler */
     2080
     2081  if (!pHMHandle || !pHMHandle->pDeviceHandler)
     2082      return ERROR_SYS_INTERNAL;
     2083
    20532084  bResult = pHMHandle->pDeviceHandler->GetFileTime(&pHMHandle->hmHandleData,
    20542085                                                   (LPFILETIME)pFT1,
     
    20872118
    20882119  pHMHandle = &TabWin32Handles[iIndex];               /* call device handler */
     2120
     2121  if (!pHMHandle || !pHMHandle->pDeviceHandler)
     2122      return ERROR_SYS_INTERNAL;
     2123
    20892124  dwResult = pHMHandle->pDeviceHandler->GetFileSize(&pHMHandle->hmHandleData,
    20902125                                                    pSize);
     
    21332168
    21342169  pHMHandle = &TabWin32Handles[iIndex];               /* call device handler */
     2170
     2171  if (!pHMHandle || !pHMHandle->pDeviceHandler)
     2172      return ERROR_SYS_INTERNAL;
     2173
    21352174  dwResult = pHMHandle->pDeviceHandler->SetFilePointer(&pHMHandle->hmHandleData,
    21362175                                                       lDistanceToMove,
     
    21952234
    21962235  pHMHandle = &TabWin32Handles[iIndex];               /* call device handler */
     2236
     2237  if (!pHMHandle || !pHMHandle->pDeviceHandler)
     2238      return ERROR_SYS_INTERNAL;
     2239
    21972240  dwResult = pHMHandle->pDeviceHandler->LockFile(&pHMHandle->hmHandleData,
    21982241                                                 arg2,
     
    22422285
    22432286  pHMHandle = &TabWin32Handles[iIndex];               /* call device handler */
     2287
     2288  if (!pHMHandle || !pHMHandle->pDeviceHandler)
     2289      return ERROR_SYS_INTERNAL;
     2290
    22442291  dwResult = pHMHandle->pDeviceHandler->LockFileEx(&pHMHandle->hmHandleData,
    22452292                                                   dwFlags,
     
    22852332
    22862333  pHMHandle = &TabWin32Handles[iIndex];               /* call device handler */
     2334
     2335  if (!pHMHandle || !pHMHandle->pDeviceHandler)
     2336      return ERROR_SYS_INTERNAL;
     2337
    22872338  dwResult = pHMHandle->pDeviceHandler->UnlockFile(&pHMHandle->hmHandleData,
    22882339                                                   arg2,
     
    23302381
    23312382  pHMHandle = &TabWin32Handles[iIndex];               /* call device handler */
     2383
     2384  if (!pHMHandle || !pHMHandle->pDeviceHandler)
     2385      return ERROR_SYS_INTERNAL;
     2386
    23322387  dwResult = pHMHandle->pDeviceHandler->UnlockFileEx(&pHMHandle->hmHandleData,
    23332388                                                     dwReserved,
     
    24302485  }
    24312486  pHMHandle = &TabWin32Handles[iIndex];               /* call device handler */
     2487
     2488  if (!pHMHandle || !pHMHandle->pDeviceHandler)
     2489      return ERROR_SYS_INTERNAL;
     2490
    24322491  dwResult = pHMHandle->pDeviceHandler->WaitForSingleObject(&pHMHandle->hmHandleData,
    24332492                                                            dwTimeout);
     
    24662525
    24672526  pHMHandle = &TabWin32Handles[iIndex];               /* call device handler */
     2527
     2528  if (!pHMHandle || !pHMHandle->pDeviceHandler)
     2529      return ERROR_SYS_INTERNAL;
     2530
    24682531  dwResult = pHMHandle->pDeviceHandler->WaitForSingleObjectEx(&pHMHandle->hmHandleData,
    24692532                                                              dwTimeout,
     
    25012564
    25022565  pHMHandle = &TabWin32Handles[iIndex];               /* call device handler */
     2566
     2567  if (!pHMHandle || !pHMHandle->pDeviceHandler)
     2568      return ERROR_SYS_INTERNAL;
     2569
    25032570  dwResult = pHMHandle->pDeviceHandler->FlushFileBuffers(&pHMHandle->hmHandleData);
    25042571
     
    25372604
    25382605  pHMHandle = &TabWin32Handles[iIndex];               /* call device handler */
     2606
     2607  if (!pHMHandle || !pHMHandle->pDeviceHandler)
     2608      return ERROR_SYS_INTERNAL;
     2609
    25392610  dwResult = pHMHandle->pDeviceHandler->GetOverlappedResult(&pHMHandle->hmHandleData,
    25402611                                                            lpOverlapped,
     
    25732644
    25742645  pHMHandle = &TabWin32Handles[iIndex];               /* call device handler */
     2646
     2647  if (!pHMHandle || !pHMHandle->pDeviceHandler)
     2648      return ERROR_SYS_INTERNAL;
     2649
    25752650  dwResult = pHMHandle->pDeviceHandler->ReleaseMutex(&pHMHandle->hmHandleData);
    25762651
     
    29202995
    29212996  pHMHandle = &TabWin32Handles[iIndex];               /* call device handler */
     2997
     2998  if (!pHMHandle || !pHMHandle->pDeviceHandler)
     2999      return ERROR_SYS_INTERNAL;
     3000
    29223001  dwResult = pHMHandle->pDeviceHandler->ReleaseSemaphore(&pHMHandle->hmHandleData,
    29233002                                                         cReleaseCount,
     
    31083187
    31093188  pHMHandle = &TabWin32Handles[iIndex];               /* call device handler */
     3189
     3190  if (!pHMHandle || !pHMHandle->pDeviceHandler)
     3191      return NULL;
     3192
    31103193  lpResult = pHMHandle->pDeviceHandler->MapViewOfFileEx(&pHMHandle->hmHandleData,
    31113194                                                      dwDesiredAccess,
     
    33203403
    33213404  pHMHandle = &TabWin32Handles[iIndex];               /* call device handler */
     3405
     3406  if (!pHMHandle || !pHMHandle->pDeviceHandler)
     3407      return ERROR_SYS_INTERNAL;
     3408
    33223409  fResult = pHMHandle->pDeviceHandler->DeviceIoControl(&pHMHandle->hmHandleData,
    33233410                                                dwIoControlCode,
     
    33713458
    33723459  pHMHandle = &TabWin32Handles[iIndex];               /* call device handler */
     3460
     3461  if (!pHMHandle || !pHMHandle->pDeviceHandler)
     3462      return ERROR_SYS_INTERNAL;
     3463
    33733464  fResult = pHMHandle->pDeviceHandler->CancelIo(&pHMHandle->hmHandleData);
    33743465
  • trunk/src/kernel32/dbglog.cpp

    r21302 r21339  
    258258
    259259static BOOL fDisableThread[5] = {0};
    260 static BOOL fFlushLines = FALSE;
     260static BOOL fFlushLines = TRUE;
    261261
    262262static char *pszLastLogEntry = NULL;
     
    275275#endif
    276276
    277 //#define LOG_TIME
     277#define LOG_TIME
    278278//#define SHOW_FPU_CONTROLREG
    279279#define WIN32_IP_LOGGING
  • trunk/src/kernel32/oslibdos.cpp

    r21336 r21339  
    13321332  // PH Note: for a negative 32-bit seek, the OS/2 64-bit version
    13331333  // needs to be skipped.
    1334   if( (f64BitIO) && (OffsetHigh) &&
     1334#if 0 /* doesnt works at all with flash 10 */
     1335  if( (f64BitIO) && (OffsetHigh) && ((DWORD)OffsetHigh != 0xAAAAAAAA) &&
    13351336     (*OffsetHigh != 0xAAAAAAAA) &&
    13361337     (*OffsetHigh != 0)) //workaround for flash10 video
     
    13451346  }
    13461347  else
     1348#endif
    13471349      rc = DosSetFilePtr(hFile, OffsetLow, method, &newoffset);
    13481350
  • trunk/src/kernel32/oslibmem.cpp

    r21302 r21339  
    204204    return 0;
    205205}
     206
     207//***************************************************************************
     208//Allocation memory at address helper
     209//***************************************************************************
     210#define OBJ_LOCSPECIFIC         0x00001000UL
     211
     212int allocAtAddress(void *pvReq, ULONG cbReq, ULONG fReq)
     213{
     214    dprintf(("DosAllocMemEx pvReq=%p cbReq=%lu fReq=%#lx\n", pvReq, cbReq, fReq));
     215    PVOID           apvTmps[3000];
     216    ULONG           cbTmp;
     217    ULONG           fTmp;
     218    int             iTmp;
     219    int             rcRet = ERROR_NOT_ENOUGH_MEMORY;
     220
     221    /*
     222     * Adjust flags and size.
     223     */
     224    if ((ULONG)pvReq < 0x20000000 /*512MB*/)
     225        fReq &= ~OBJ_ANY;
     226    else
     227        fReq |= OBJ_ANY;
     228    cbReq = (cbReq + 0xfff) & ~0xfff;
     229
     230    /*
     231     * Allocation loop.
     232     * This algorithm is not optimal!
     233     */
     234    fTmp  = fReq & ~(PAG_COMMIT);
     235    cbTmp = 1*1024*1024; /* 1MB*/
     236    for (iTmp = 0; iTmp < sizeof(apvTmps) / sizeof(apvTmps[0]); iTmp++)
     237    {
     238        PVOID   pvNew = NULL;
     239        int     rc;
     240
     241        /* Allocate chunk. */
     242        rc = DosAllocMem(&pvNew, cbReq, fReq);
     243        apvTmps[iTmp] = pvNew;
     244        if (rc)
     245            break;
     246
     247        /*
     248         * Passed it?
     249         * Then retry with the requested size.
     250         */
     251        if (pvNew > pvReq)
     252        {
     253            if (cbTmp <= cbReq)
     254                break;
     255            DosFreeMem(pvNew);
     256            cbTmp = cbReq;
     257            iTmp--;
     258            continue;
     259        }
     260
     261        /*
     262         * Does the allocated object touch into the requested one?
     263         */
     264        if ((char *)pvNew + cbTmp > (char *)pvReq)
     265        {
     266            /*
     267             * Yes, we've found the requested address!
     268             */
     269            apvTmps[iTmp] = NULL;
     270            DosFreeMem(pvNew);
     271
     272            /*
     273             * Adjust the allocation size to fill the gap between the
     274             * one we just got and the requested one.
     275             * If no gap we'll attempt the real allocation.
     276             */
     277            cbTmp = (ULONG)pvReq - (ULONG)pvNew;
     278            if (cbTmp)
     279            {
     280                iTmp--;
     281                continue;
     282            }
     283
     284            rc = DosAllocMem(&pvNew, cbReq, fReq);
     285            if (rc || (char *)pvNew > (char *)pvReq)
     286                break; /* we failed! */
     287            if (pvNew == pvReq)
     288            {
     289                rcRet = 0;
     290                break;
     291            }
     292
     293            /*
     294             * We've got an object which start is below the one we
     295             * requested. This is probably caused by the requested object
     296             * fitting in somewhere our tmp objects didn't.
     297             * So, we'll have loop and retry till all such holes are filled.
     298             */
     299            apvTmps[iTmp] = pvNew;
     300        }
     301    }
     302
     303    /*
     304     * Cleanup reserved memory and return.
     305     */
     306    while (iTmp-- > 0)
     307        if (apvTmps[iTmp])
     308            DosFreeMem(apvTmps[iTmp]);
     309
     310    return rcRet;
     311}
     312
    206313//******************************************************************************
    207314//Allocate memory aligned at 64kb boundary
     
    239346     */
    240347
    241     rc = DosAllocMem(&pvMemAddr, cbSize, flFlags | fMemFlags);
     348    if (flFlags & OBJ_LOCSPECIFIC)
     349    {
     350        rc = allocAtAddress(&pvMemAddr, cbSize, (flFlags & ~OBJ_LOCSPECIFIC) | fMemFlags);
     351    } else
     352    {
     353        rc = DosAllocMem(&pvMemAddr, cbSize, flFlags | fMemFlags);
     354    }
    242355    if(rc) {
    243356        dprintf(("!ERROR!: DosAllocMem failed with rc %d", rc));
  • 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) {
  • trunk/src/kernel32/winimagebase.cpp

    r10397 r21339  
    413413      *fNEExe = FALSE;
    414414
    415   if (!findDll(szFileName, filename, sizeof(filename)))
     415  if (!findDll(ODINHelperStripUNC(szFileName), filename, sizeof(filename)))
    416416  {
    417417        dprintf(("KERNEL32:Win32ImageBase::isPEImage(%s) findDll failed to find the file.\n",
  • trunk/src/kernel32/wprocess.cpp

    r21302 r21339  
    946946     *  Endif
    947947     */
    948     strcpy(szModname, lpszLibFile);
     948    strcpy(szModname, ODINHelperStripUNC((char*)lpszLibFile));
    949949    strupr(szModname);
    950950    dot = strchr(szModname, '.');
Note: See TracChangeset for help on using the changeset viewer.