Ignore:
Timestamp:
Jun 18, 2009, 11:53:26 AM (16 years ago)
Author:
ydario
Message:

Kernel32 updates.

File:
1 edited

Legend:

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

    r9971 r21302  
    7474  //It's not allowed to map a file of length 0 according to MSDN. This time
    7575  //the docs are correct. (verified in NT4 SP6)
     76  //bird: It's not allowed to create a non-file based mapping with size 0.
    7677  //TODO: also need to verify access rights of the file handle (write maps need
    7778  //      write access obviously)
     
    8182      dwFileSizeLow = ::GetFileSize(hFile, &dwFileSizeHigh);
    8283      if(dwFileSizeHigh == 0 && dwFileSizeLow == 0) {
     84          /*
     85           * Two actions, if we can grow the file we should if not fail.
     86           */
     87          if (!(protect & PAGE_READWRITE)) /* TODO: check this and verify flags */
     88          {
    8389          dprintf(("CreateFileMappingA: not allowed to map a file with length 0!!"));
    84           return ERROR_FILE_INVALID;
     90              return ERROR_NOT_ENOUGH_MEMORY; /* XP returns this if the mapping is readonly, odd.. */
     91          }
     92          /*
     93           * Try extend the file.
     94           * (Not sure if we need to preserve the filepointer, but it doesn't hurt I think.)
     95           */
     96          LONG  lFilePosHigh = 0;
     97          DWORD dwFilePosLow = ::SetFilePointer(hFile, 0, &lFilePosHigh, FILE_CURRENT);
     98          LONG  lFileSizeHigh = size_high;
     99          if (   ::SetFilePointer(hFile, size_low, &lFileSizeHigh, FILE_BEGIN) == INVALID_SET_FILE_POINTER
     100              || !::SetEndOfFile(hFile))
     101          {
     102              ::SetFilePointer(hFile, dwFilePosLow, &lFilePosHigh, FILE_BEGIN);
     103              dprintf(("CreateFileMappingA: unable to grow file to 0x%#08x%08x bytes.\n", size_high, size_low));
     104              return ERROR_DISK_FULL;
     105          }
     106          ::SetFilePointer(hFile, dwFilePosLow, &lFilePosHigh, FILE_BEGIN);
    85107      }
    86108  }
Note: See TracChangeset for help on using the changeset viewer.