mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-12 17:32:19 +00:00
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
This commit is contained in:
parent
37db5d67f9
commit
23ffec8258
@ -65,15 +65,13 @@ namespace sys {
|
|||||||
return initialize(ErrMsg);
|
return initialize(ErrMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// unmap - Remove the mapped file from memory. If the file was mapped for
|
/// unmap - Remove the mapped file from memory.
|
||||||
/// write access, the memory contents will be automatically synchronized
|
|
||||||
/// with the file's disk contents.
|
|
||||||
void unmap();
|
void unmap();
|
||||||
|
|
||||||
/// map - Reserve space for the file, map it into memory, and return a
|
/// map - Reserve space for the file, map it into memory, and return a
|
||||||
/// pointer to it. This returns the base memory address of the mapped file
|
/// pointer to it. This returns the base memory address of the mapped file
|
||||||
/// or 0 if an error occurred.
|
/// or 0 if an error occurred.
|
||||||
void *map(std::string* ErrMsg = 0);
|
const void *map(std::string* ErrMsg = 0);
|
||||||
|
|
||||||
void close() { if (MapInfo) terminate(); }
|
void close() { if (MapInfo) terminate(); }
|
||||||
|
|
||||||
|
@ -56,6 +56,7 @@ bool MappedFile::initialize(std::string* ErrMsg) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MappedFile::terminate() {
|
void MappedFile::terminate() {
|
||||||
|
unmap();
|
||||||
assert(MapInfo && "MappedFile not initialized");
|
assert(MapInfo && "MappedFile not initialized");
|
||||||
::close(MapInfo->FD);
|
::close(MapInfo->FD);
|
||||||
delete MapInfo;
|
delete MapInfo;
|
||||||
@ -70,7 +71,7 @@ void MappedFile::unmap() {
|
|||||||
BasePtr = 0; // Mark this as non-mapped.
|
BasePtr = 0; // Mark this as non-mapped.
|
||||||
}
|
}
|
||||||
|
|
||||||
void* MappedFile::map(std::string* ErrMsg) {
|
const void* MappedFile::map(std::string* ErrMsg) {
|
||||||
assert(MapInfo && "MappedFile not initialized");
|
assert(MapInfo && "MappedFile not initialized");
|
||||||
if (isMapped()) return BasePtr;
|
if (isMapped()) return BasePtr;
|
||||||
|
|
||||||
|
@ -75,7 +75,7 @@ void MappedFile::unmap() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void* MappedFile::map(std::string* ErrMsg) {
|
const void* MappedFile::map(std::string* ErrMsg) {
|
||||||
if (!isMapped()) {
|
if (!isMapped()) {
|
||||||
MapInfo->hMapping = CreateFileMapping(MapInfo->hFile, NULL, PAGE_READONLY,
|
MapInfo->hMapping = CreateFileMapping(MapInfo->hFile, NULL, PAGE_READONLY,
|
||||||
0, 0, NULL);
|
0, 0, NULL);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user