public inbox for java-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Patch: FYI: fix mmap bug in natFileChannelImplPosix.cc
@ 2007-04-03  1:05 Tom Tromey
  2007-04-03  9:34 ` Andrew Haley
  0 siblings, 1 reply; 2+ messages in thread
From: Tom Tromey @ 2007-04-03  1:05 UTC (permalink / raw)
  To: GCJ-patches

I'm checking this in on the trunk and the RH 4.1 branch.

This fixes a bug in how we mmap() files for use in MappedByteBufferImpl.
The bug is that if we are mapping for write, and the file is shorter
than the requested length, then we must make the file the desired
length, or else the mapped segment won't be long enough.

This fixes a bug found by the Animal Shelter Manager program (actually
by the underlying database it uses, I think).

Tom

Index: ChangeLog
from  Tom Tromey  <tromey@redhat.com>
	http://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=205157
	* gnu/java/nio/channels/natFileChannelPosix.cc (mapImpl): Extend
	file, when writing, if it is too short.

Index: gnu/java/nio/channels/natFileChannelPosix.cc
===================================================================
--- gnu/java/nio/channels/natFileChannelPosix.cc	(revision 123436)
+++ gnu/java/nio/channels/natFileChannelPosix.cc	(working copy)
@@ -1,7 +1,7 @@
 
 // natFileChannelImplPosix.cc - Native part of FileChannelImpl class.
 
-/* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2006  Free Software Foundation
+/* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2006, 2007  Free Software Foundation
 
    This file is part of libgcj.
 
@@ -499,6 +499,18 @@
     {
       prot = PROT_READ|PROT_WRITE;
       flags = mmode == '+' ? MAP_SHARED : MAP_PRIVATE;
+
+      // If the file is too short, we must extend it.  While using
+      // ftruncate() to extend a file is not portable in general, it
+      // should work on all systems where you can mmap() a file.
+      struct stat st;
+      if (fstat (fd, &st) == -1)
+	throw new IOException (JvNewStringLatin1 (strerror (errno)));
+      if (position + size > st.st_size)
+	{
+	  if (ftruncate (fd, position + size) == -1)
+	    throw new IOException (JvNewStringLatin1 (strerror (errno)));
+	}
     }
   jint page_size = ::getpagesize();
   jint offset = position & ~(page_size-1);

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Patch: FYI: fix mmap bug in natFileChannelImplPosix.cc
  2007-04-03  1:05 Patch: FYI: fix mmap bug in natFileChannelImplPosix.cc Tom Tromey
@ 2007-04-03  9:34 ` Andrew Haley
  0 siblings, 0 replies; 2+ messages in thread
From: Andrew Haley @ 2007-04-03  9:34 UTC (permalink / raw)
  To: Tom Tromey; +Cc: GCJ-patches

Tom Tromey writes:
 > I'm checking this in on the trunk and the RH 4.1 branch.
 > 
 > This fixes a bug in how we mmap() files for use in MappedByteBufferImpl.
 > The bug is that if we are mapping for write, and the file is shorter
 > than the requested length, then we must make the file the desired
 > length, or else the mapped segment won't be long enough.
 > 
 > This fixes a bug found by the Animal Shelter Manager program (actually
 > by the underlying database it uses, I think).

Ah, thank you.  This also fixes a bug I found in hsqldb startup.

For what it's worth, I'm not convinced that the spec really requires
such a change, but some apps do.

Andrew.

-- 
Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SL4 1TE, UK
Registered in England and Wales No. 3798903

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2007-04-03  9:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-04-03  1:05 Patch: FYI: fix mmap bug in natFileChannelImplPosix.cc Tom Tromey
2007-04-03  9:34 ` Andrew Haley

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).