Home » U++ Library support » U++ Core » Latest change on FileMapping::Map() wrong for win32
Latest change on FileMapping::Map() wrong for win32 [message #23384] |
Thu, 15 October 2009 19:36  |
hans
Messages: 44 Registered: March 2006 Location: Germany
|
Member |
|
|
Today svn update, file Stream.cpp, line 1342 is changed
from
if(!rawbase)
return false;
to
if(rawbase == (byte *)~0)
return false;
but the test for ~0 should go into the Linux section only,
as MapViewOfFile on windows returns NULL on
error.
greetings, Hans.
|
|
|
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;
}
|
|
|
|
Re: Latest change on FileMapping::Map() wrong for win32 [message #23510 is a reply to message #23428] |
Sun, 25 October 2009 19:04   |
hans
Messages: 44 Registered: March 2006 Location: Germany
|
Member |
|
|
Hi, the code for the return test is now OK (last SVN version),
but after some testing I found two other bugs.
In bool FileMapping::Map(int64 mapoffset, dword maplen) there is commented out (on windows version only) the write flag, this
leads to Access violation on write access. Should be
#ifdef PLATFORM_WIN32
rawbase = (byte *)MapViewOfFile(hmap, write ? FILE_MAP_WRITE : FILE_MAP_READ,
(dword)(rawoffset >> 32), (dword)(rawoffset >> 0), rawsize);
#else
More strangely, the
bool FileMapping::Create(const wchar *file, int64 filesize_, bool delete_share) function is wrong on windows too. The created file is zero size, so line
hmap = CreateFileMapping(hfile, NULL, PAGE_READWRITE, 0, 0, NULL);
fails.
It should set the file size, so please change to:
long lo = (dword)filesize_, hi = (dword)(filesize_ >> 32);
hmap = CreateFileMapping(hfile, NULL, PAGE_READWRITE, hi, lo, NULL);
Greetings,
Hans
[Updated on: Sun, 25 October 2009 19:15] Report message to a moderator
|
|
|
|
|
Goto Forum:
Current Time: Wed Apr 30 17:48:21 CEST 2025
Total time taken to generate the page: 0.08779 seconds
|