diff options
Diffstat (limited to 'lib/System/Win32/MappedFile.inc')
-rw-r--r-- | lib/System/Win32/MappedFile.inc | 48 |
1 files changed, 6 insertions, 42 deletions
diff --git a/lib/System/Win32/MappedFile.inc b/lib/System/Win32/MappedFile.inc index de8eec3..830905d 100644 --- a/lib/System/Win32/MappedFile.inc +++ b/lib/System/Win32/MappedFile.inc @@ -33,17 +33,13 @@ bool MappedFile::initialize(std::string* ErrMsg) { MapInfo->hFile = INVALID_HANDLE_VALUE; MapInfo->hMapping = NULL; - DWORD mode = Options & WRITE_ACCESS ? GENERIC_WRITE : GENERIC_READ; - DWORD disposition = Options & WRITE_ACCESS ? OPEN_ALWAYS : OPEN_EXISTING; - DWORD share = Options & WRITE_ACCESS ? FILE_SHARE_WRITE : FILE_SHARE_READ; - share = Options & SHARED_MAPPING ? share : 0; - MapInfo->hFile = CreateFile(Path.c_str(), mode, share, NULL, disposition, - FILE_ATTRIBUTE_NORMAL, NULL); + MapInfo->hFile = CreateFile(Path.c_str(), GENERIC_READ, 0, NULL, + OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (MapInfo->hFile == INVALID_HANDLE_VALUE) { delete MapInfo; MapInfo = NULL; return MakeErrMsg(ErrMsg, - std::string("Can't open file: ") + Path.toString()); + std::string("Can't open file: ") + Path.toString()); } LARGE_INTEGER size; @@ -81,19 +77,14 @@ void MappedFile::unmap() { void* MappedFile::map(std::string* ErrMsg) { if (!isMapped()) { - DWORD prot = PAGE_READONLY; - if (Options & EXEC_ACCESS) - prot = SEC_IMAGE; - else if (Options & WRITE_ACCESS) - prot = PAGE_READWRITE; - MapInfo->hMapping = CreateFileMapping(MapInfo->hFile, NULL, prot, 0, 0, NULL); + MapInfo->hMapping = CreateFileMapping(MapInfo->hFile, NULL, PAGE_READONLY, + 0, 0, NULL); if (MapInfo->hMapping == NULL) { MakeErrMsg(ErrMsg, std::string("Can't map file: ") + Path.toString()); return 0; } - prot = (Options & WRITE_ACCESS) ? FILE_MAP_WRITE : FILE_MAP_READ; - BasePtr = MapViewOfFileEx(MapInfo->hMapping, prot, 0, 0, 0, NULL); + BasePtr = MapViewOfFileEx(MapInfo->hMapping, FILE_MAP_READ, 0, 0, 0, NULL); if (BasePtr == NULL) { CloseHandle(MapInfo->hMapping); MapInfo->hMapping = NULL; @@ -109,32 +100,5 @@ size_t MappedFile::size() const { return MapInfo->size; } -bool MappedFile::resize(size_t new_size, std::string* ErrMsg) { - assert(MapInfo && "MappedFile not initialized"); - - // Take the mapping out of memory. - unmap(); - - // Adjust the new_size to a page boundary. - size_t pagesizem1 = Process::GetPageSize() - 1; - new_size = (new_size + pagesizem1) & ~pagesizem1; - - // If the file needs to be extended, do so. - if (new_size > MapInfo->size) { - LARGE_INTEGER eof; - eof.QuadPart = new_size; - if (!SetFilePointerEx(MapInfo->hFile, eof, NULL, FILE_BEGIN)) - return MakeErrMsg(ErrMsg, - std::string("Can't set end of file: ") + Path.toString()); - if (!SetEndOfFile(MapInfo->hFile)) - return MakeErrMsg(ErrMsg, - std::string("Can't set end of file: ") + Path.toString()); - MapInfo->size = new_size; - } - - // Remap the file. - return map(ErrMsg); -} - } |