llvm.org GIT mirror llvm / 23ffec8
Make MappedFile::map return a const correct pointer, don't leak address space on Unix platforms. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@49026 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 11 years ago
3 changed file(s) with 5 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
6464 return initialize(ErrMsg);
6565 }
6666
67 /// unmap - Remove the mapped file from memory. If the file was mapped for
68 /// write access, the memory contents will be automatically synchronized
69 /// with the file's disk contents.
67 /// unmap - Remove the mapped file from memory.
7068 void unmap();
7169
7270 /// map - Reserve space for the file, map it into memory, and return a
7371 /// pointer to it. This returns the base memory address of the mapped file
7472 /// or 0 if an error occurred.
75 void *map(std::string* ErrMsg = 0);
73 const void *map(std::string* ErrMsg = 0);
7674
7775 void close() { if (MapInfo) terminate(); }
7876
5555 }
5656
5757 void MappedFile::terminate() {
58 unmap();
5859 assert(MapInfo && "MappedFile not initialized");
5960 ::close(MapInfo->FD);
6061 delete MapInfo;
6970 BasePtr = 0; // Mark this as non-mapped.
7071 }
7172
72 void* MappedFile::map(std::string* ErrMsg) {
73 const void* MappedFile::map(std::string* ErrMsg) {
7374 assert(MapInfo && "MappedFile not initialized");
7475 if (isMapped()) return BasePtr;
7576
7474 }
7575 }
7676
77 void* MappedFile::map(std::string* ErrMsg) {
77 const void* MappedFile::map(std::string* ErrMsg) {
7878 if (!isMapped()) {
7979 MapInfo->hMapping = CreateFileMapping(MapInfo->hFile, NULL, PAGE_READONLY,
8080 0, 0, NULL);