|
From: Matt Z. <md...@de...> - 2003-04-27 23:19:35
|
On Sun, Apr 27, 2003 at 04:23:58PM -0400, Matt Zimmerman wrote:
> I have not yet been able to reproduce it with any test programs, mostly
> because I don't understand what is going on in gcc here.
So I built gcc for debugging and spent some time tracking this down, and it
turned out that the buffer wasn't null-terminated in this case, while it was
in the working case:
(gdb) print (*parse_in->buffer).buf[21621]
$16 = 10 '\n'
(gdb) print (*parse_in->buffer).buf[21622]
$17 = 59 ';'
vs.
(gdb) print (*parse_in->buffer).buf[21621]
$19 = 10 '\n'
(gdb) print (*parse_in->buffer).buf[21622]
$20 = 0 '\0'
shortly thereafter, I came upon this comment in src/gcc/cppfiles.c:
/* Use mmap if the file is big enough to be worth it (controlled
by MMAP_THRESHOLD) and if we can safely count on there being
at least one readable NUL byte after the end of the file's
contents. This is true for all tested operating systems when
the file size is not an exact multiple of the page size. */
And wrote a simple test program to look at the byte just after the end of an
mmaped region (/ is ubd, /mnt is hostfs):
sh-2.05b# ./mmaptest /etc/motd
0
sh-2.05b# ./mmaptest /etc/motd
0
sh-2.05b# ./mmaptest /etc/motd
0
sh-2.05b# ./mmaptest /etc/motd
0
sh-2.05b# ./mmaptest /etc/motd
0
sh-2.05b# ./mmaptest /mnt/etc/motd
0
sh-2.05b# ./mmaptest /mnt/etc/motd
8
sh-2.05b# ./mmaptest /mnt/etc/motd
8
sh-2.05b# ./mmaptest /mnt/etc/motd
8
It always comes up with a zero everywhere except on hostfs. It seems like
this should be as simple as zeroing the page, since it only expects this
when the size is not a multiple of the page size. I wouldn't know where to
change this in UML, though.
--
- mdz
|