Home » U++ Library support » U++ Core » Latest change on FileMapping::Map() wrong for win32
Re: Latest change on FileMapping::Map() wrong for win32 [message #23423 is a reply to message #23384] |
Sun, 18 October 2009 21:25   |
 |
mirek
Messages: 14256 Registered: November 2005
|
Ultimate Member |
|
|
Thank you. I have changed to code, please check:
bool FileMapping::Map(int64 mapoffset, dword maplen)
{
ASSERT(IsOpen());
if(maplen == 0)
return Unmap();
mapoffset = minmax<int64>(mapoffset, 0, filesize);
int gran = sMappingGranularity_();
int64 rawoff = mapoffset & -gran;
maplen = (dword)min<int64>(maplen, filesize - mapoffset);
dword rawsz = (dword)min<int64>((maplen + (dword)(mapoffset - rawoff) + gran - 1) & -gran, filesize - rawoff);
if(rawbase && (mapoffset < rawoffset || mapoffset + maplen > rawoffset + rawsize))
Unmap();
if(!rawbase) {
rawoffset = rawoff;
rawsize = rawsz;
#ifdef PLATFORM_WIN32
rawbase = (byte *)MapViewOfFile(hmap, /*write ? FILE_MAP_WRITE :*/ FILE_MAP_READ,
(dword)(rawoffset >> 32), (dword)(rawoffset >> 0), rawsize);
#else
rawbase = (byte *)mmap(0, rawsize,
PROT_READ | (write ? PROT_WRITE : 0),
#ifdef PLATFORM_FREEBSD
MAP_NOSYNC,
#else
MAP_SHARED,
#endif
hfile, (dword)rawoffset);
#endif
#ifdef PLATFORM_POSIX
if(rawbase == (byte *)~0)
#else
if(!rawbase)
#endif
return false;
}
offset = mapoffset;
size = maplen;
base = rawbase + (int)(offset - rawoffset);
return true;
}
|
|
|
Goto Forum:
Current Time: Wed Apr 30 19:29:27 CEST 2025
Total time taken to generate the page: 0.02236 seconds
|