Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
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 Go to next message
hans is currently offline  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 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
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 #23428 is a reply to message #23423] Sun, 18 October 2009 21:55 Go to previous messageGo to next message
rylek is currently offline  rylek
Messages: 79
Registered: November 2005
Member
Ah, thanks, sorry, my stupidity Smile.

Tomas
Re: Latest change on FileMapping::Map() wrong for win32 [message #23510 is a reply to message #23428] Sun, 25 October 2009 19:04 Go to previous messageGo to next message
hans is currently offline  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

Re: Latest change on FileMapping::Map() wrong for win32 [message #23696 is a reply to message #23384] Sun, 15 November 2009 19:29 Go to previous messageGo to next message
hans is currently offline  hans
Messages: 44
Registered: March 2006
Location: Germany
Member
Hi,
change is not in SVN yet.

Anything wrong with my code or thoughs?

greetings,
Hans
Re: Latest change on FileMapping::Map() wrong for win32 [message #23697 is a reply to message #23696] Sun, 15 November 2009 21:11 Go to previous message
rylek is currently offline  rylek
Messages: 79
Registered: November 2005
Member
Hello Hans!

I've just posted your fixes to the Stream.cpp file.

Regards

Tomas
Previous Topic: Deepcopying One container
Next Topic: FtpClient use with Progress FIX
Goto Forum:
  


Current Time: Sat Apr 20 00:42:17 CEST 2024

Total time taken to generate the page: 2.91982 seconds