Subject: | Can't map with nonzero $offset under Windows |
Date: | Tue, 10 Jan 2012 11:55:58 +0100 |
To: | <bug-File-Map [...] rt.cpan.org> |
From: | "Neubauer, Ralf" <Ralf.Neubauer [...] wido.bv.aok.de> |
File::Map 0.40, ActivePerl 5.14.2 build 1402
use File::Map qw(:map :extra :constants);
map_file my $map, '/some/big/file', '<', 0x10000, 0x20000;
doesn't work under Windows. The same happens with
sys_map my $map2, 0x10000, PROT_READ, MAP_FILE, $fh2, 0x10000;
while
map_file my $map, '/some/big/file', '<', 0x00000, 0x20000;
and
map_file my $map, '/some/big/file', '<', 0x00000, 0x30000;
and
sys_map my $map2, 0x10000, PROT_READ, MAP_FILE, $fh2, 0;
work.
I assume this has something to do with the #ifdef WIN32 implementation of do_mapping() in Map.xs.
The two interesting calls are:
...
mapping = CreateFileMapping(file, NULL, winflags[prot].createflag, 0, length, NULL);
...
address = MapViewOfFile(mapping, viewflag, 0, offset, length);
...
According to the documentation of CreateFileMapping passing /length+offset/ instead of /length/ should be correct, else the mapping only maps the _first_ /length/ bytes of file, which doesn't include all of the /length/ bytes from /offset/.
Also the /0/ arguments of CreateFileMapping and MapViewOfFile take the high 32 bits of the length resp. the offset. If off_t wouldn't be long (32 bits) anyway (or Map.xs used another type), it would be easy to support large files under win32.
--
Ralf Neubauer
Wissenschaftliches Institut der AOK (WIdO)
Rosenthaler Straße 31
10178 Berlin
Tel: 030 34646-2583
Fax: 030 34646-2144
E-Mail: Ralf.Neubauer@wido.bv.aok.de