According to the spec, this case is undefined. However, if we do
attempt to read the data in a nonexistent region we'll get a bus
error. It makes sense to throw a helpful exception, and it seems that
at least one Java program relies on this behaviour.
This isn't a complete solution. At some point we'll need to catch the
bus error and do something appropriate.
Andrew.
2006-11-01 Andrew Haley <[EMAIL PROTECTED]>
* gnu/java/nio/channels/natFileChannelPosix.cc (mapImpl): Throw
IOException if requested region is not completely contained within
file.
Index: gnu/java/nio/channels/natFileChannelPosix.cc
===================================================================
--- gnu/java/nio/channels/natFileChannelPosix.cc (revision 118387)
+++ gnu/java/nio/channels/natFileChannelPosix.cc (working copy)
@@ -513,6 +513,17 @@
throw new IOException (JvNewStringLatin1 (strerror (errno)));
buf->implPtr = reinterpret_cast<RawData*> (ptr);
buf->implLen = size+align;
+
+ struct stat st;
+
+ if (fstat (fd, &st))
+ throw new IOException (JvNewStringLatin1 (strerror (errno)));
+
+ if (size+position > st.st_size)
+ throw new IOException (JvNewStringLatin1
+ ("mmap: requested region not completely "
+ "contained within file\n"));
+
return buf;
#else
throw new IOException (JvNewStringUTF ("mmap not implemented"));