diff options
author | Chris Lattner <sabre@nondot.org> | 2008-04-01 03:10:22 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2008-04-01 03:10:22 +0000 |
commit | bdbd2d710c665bcdf31cbed4b44cf3f94ba746e7 (patch) | |
tree | 7ad9a631dd43e31b57f7e0910fdc78d47eae484f /lib/System | |
parent | 558755ce1af80a44e9d5f399584e9b2112583796 (diff) |
Remove MappedFile support for mapping files for write and exec
and shared. This complicates the design, is not used, and probably
doesn't even work.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@49022 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/System')
-rw-r--r-- | lib/System/Unix/MappedFile.inc | 70 | ||||
-rw-r--r-- | lib/System/Win32/MappedFile.inc | 48 |
2 files changed, 12 insertions, 106 deletions
diff --git a/lib/System/Unix/MappedFile.inc b/lib/System/Unix/MappedFile.inc index dcfd1892f8..92dc666043 100644 --- a/lib/System/Unix/MappedFile.inc +++ b/lib/System/Unix/MappedFile.inc @@ -1,4 +1,4 @@ -//===- Unix/MappedFile.cpp - Unix MappedFile Implementation -----*- C++ -*-===// +//===- Unix/MappedFile.inc - Unix MappedFile Implementation -----*- C++ -*-===// // // The LLVM Compiler Infrastructure // @@ -11,11 +11,6 @@ // //===----------------------------------------------------------------------===// -//===----------------------------------------------------------------------===// -//=== WARNING: Implementation here must contain only generic UNIX code that -//=== is guaranteed to work on *all* UNIX variants. -//===----------------------------------------------------------------------===// - #include "Unix.h" #include "llvm/System/Process.h" @@ -44,16 +39,7 @@ namespace llvm { } bool MappedFile::initialize(std::string* ErrMsg) { - int mode = 0; - if (Options & READ_ACCESS) - if (Options & WRITE_ACCESS) - mode = O_RDWR; - else - mode = O_RDONLY; - else if (Options & WRITE_ACCESS) - mode = O_WRONLY; - - int FD = ::open(Path.c_str(), mode); + int FD = ::open(Path.c_str(), O_RDONLY); if (FD < 0) { MakeErrMsg(ErrMsg, "can't open file '" + Path.toString() + "'"); return true; @@ -80,8 +66,6 @@ void MappedFile::unmap() { assert(MapInfo && "MappedFile not initialized"); if (!isMapped()) return; - if (Options & WRITE_ACCESS) - ::msync(BasePtr, MapInfo->Size, MS_SYNC); ::munmap(BasePtr, MapInfo->Size); BasePtr = 0; // Mark this as non-mapped. } @@ -90,28 +74,13 @@ void* MappedFile::map(std::string* ErrMsg) { assert(MapInfo && "MappedFile not initialized"); if (isMapped()) return BasePtr; - int prot = PROT_NONE; - int flags = 0; + int prot = PROT_READ; + int flags = MAP_PRIVATE; #ifdef MAP_FILE flags |= MAP_FILE; #endif - if (Options == 0) { - prot = PROT_READ; - flags = MAP_PRIVATE; - } else { - if (Options & READ_ACCESS) - prot |= PROT_READ; - if (Options & WRITE_ACCESS) - prot |= PROT_WRITE; - if (Options & EXEC_ACCESS) - prot |= PROT_EXEC; - if (Options & SHARED_MAPPING) - flags |= MAP_SHARED; - else - flags |= MAP_PRIVATE; - } - size_t map_size = ((MapInfo->Size / Process::GetPageSize())+1) * - Process::GetPageSize(); + size_t PageSize = Process::GetPageSize(); + size_t map_size = ((MapInfo->Size / PageSize)+1) * PageSize; BasePtr = ::mmap(0, map_size, prot, flags, MapInfo->FD, 0); if (BasePtr == MAP_FAILED) { @@ -126,30 +95,3 @@ 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 current size to a page boundary - size_t cur_size = ((MapInfo->Size / Process::GetPageSize())+1) * - Process::GetPageSize(); - - // Adjust the new_size to a page boundary - new_size = ((new_size / Process::GetPageSize())+1) * - Process::GetPageSize(); - - // If the file needs to be extended - if (new_size > cur_size) { - // Ensure we can allocate at least the idodes necessary to handle the - // file size requested. - if ((off_t)-1 == ::lseek(MapInfo->FD, new_size, SEEK_SET)) - return MakeErrMsg(ErrMsg, "Can't lseek: "); - if (-1 == ::write(MapInfo->FD, "\0", 1)) - return MakeErrMsg(ErrMsg, "Can't write: "); - } - - // Put the mapping back into memory. - return map(ErrMsg); -} diff --git a/lib/System/Win32/MappedFile.inc b/lib/System/Win32/MappedFile.inc index de8eec3673..830905debc 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); -} - } |