harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From odea...@apache.org
Subject svn commit: r820629 - in /harmony/enhanced/classlib/trunk/modules/luni/src/main: java/org/apache/harmony/luni/platform/OSMemory.java java/org/apache/harmony/luni/platform/PlatformAddressFactory.java native/luni/unix/OSMemoryLinux32.c
Date Thu, 01 Oct 2009 12:29:21 GMT
Author: odeakin
Date: Thu Oct  1 12:29:20 2009
New Revision: 820629

URL: http://svn.apache.org/viewvc?rev=820629&view=rev
Log:
Further patch for HARMONY-6315 ([classlib][nio] FileChannel.map throws IOException when called
with size 0)

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/OSMemory.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/PlatformAddressFactory.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/unix/OSMemoryLinux32.c

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/OSMemory.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/OSMemory.java?rev=820629&r1=820628&r2=820629&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/OSMemory.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/OSMemory.java
Thu Oct  1 12:29:20 2009
@@ -546,11 +546,6 @@
 
 	public long mmap(long fileDescriptor, long alignment, long size,
 			int mapMode) throws IOException {
-		// if size is 0, call to mmap will fail, so return dummy address
-		if (size == 0)
-		{
-			return 0;
-		}
                 // No need to check mmapImpl return as it throws IOException in error cases
 		long address = mmapImpl(fileDescriptor, alignment, size, mapMode);
 		return address;

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/PlatformAddressFactory.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/PlatformAddressFactory.java?rev=820629&r1=820628&r2=820629&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/PlatformAddressFactory.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/PlatformAddressFactory.java
Thu Oct  1 12:29:20 2009
@@ -34,6 +34,11 @@
     }
     
     public static PlatformAddress allocMap(long fd, long start, long size, int mode) throws
IOException{
+        if (size == 0) {
+            // if size is 0, call to mmap has incorrect behaviour on 
+            // unix and windows, so return empty address
+            return mapOn(0, 0);
+        }
         long osAddress = PlatformAddress.osMemory.mmap(fd, start, size, mode);
         PlatformAddress newMemory = mapOn(osAddress, size);
         PlatformAddress.memorySpy.alloc(newMemory);

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/unix/OSMemoryLinux32.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/unix/OSMemoryLinux32.c?rev=820629&r1=820628&r2=820629&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/unix/OSMemoryLinux32.c
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/unix/OSMemoryLinux32.c
Thu Oct  1 12:29:20 2009
@@ -31,6 +31,7 @@
 #include "OSMemory.h"
 #include "IMemorySystem.h"
 #include "exceptions.h"
+#include "hyport.h"
 
 #ifdef ZOS
 #define FD_BIAS 1000
@@ -156,10 +157,9 @@
 JNIEXPORT jlong JNICALL Java_org_apache_harmony_luni_platform_OSMemory_mmapImpl
   (JNIEnv * env, jobject thiz, jlong fd, jlong alignment, jlong size, jint mmode)
 {
-  //PORT_ACCESS_FROM_ENV (env);
+  PORT_ACCESS_FROM_ENV (env);
   void *mapAddress = NULL;
   int prot, flags;
-  char errorString[102]; // 102 to contain the longest error message
 
   // Convert from Java mapping mode to port library mapping mode.
   switch (mmode)
@@ -177,41 +177,15 @@
 	flags = MAP_PRIVATE;
         break;
       default:
-    sprintf(errorString, "Map mode %d not recognised", mmode);
-    throwJavaIoIOException(env, errorString);
+    throwJavaIoIOException(env, "Map mode not recognised");
         return -1;
     }
 
   mapAddress = mmap(0, (size_t)(size&0x7fffffff), prot, flags, fd-FD_BIAS, (off_t)(alignment&0x7fffffff));
   if (mapAddress == MAP_FAILED)
     {
-      switch (errno)
-        {
-        case EACCES:
-          strcpy(errorString, "Call to mmap failed - a file descriptor refers to a non-regular
file.");
-          break;
-        case EAGAIN:
-          strcpy(errorString, "Call to mmap failed with error EAGAIN - the file has been
locked, or too much memory has been locked.");
-          break;
-        case EBADF:
-          strcpy(errorString, "Call to mmap failed with error EBADF - invalid file descriptor");
-          break;
-        case EINVAL:
-          strcpy(errorString, "Call to mmap failed with error EINVAL - invalid start, length
or offset.");
-          break;
-        case ENFILE:
-          strcpy(errorString, "Call to mmap failed with error ENFILE - number of open files
has reached the system limit.");
-          break;
-        case ENODEV:
-          strcpy(errorString, "Call to mmap failed with error ENODEV - filesystem does not
support memory mapping.");
-          break;
-        case ENOMEM:
-          strcpy(errorString, "Call to mmap failed with error ENOMEM - no memory is available");
-          break;
-        default:
-          sprintf(errorString, "Call to mmap returned with errno %d", errno);
-        }
-      throwJavaIoIOException(env, errorString);
+      hyerror_set_last_error(errno, HYPORT_ERROR_OPFAILED);
+      throwJavaIoIOException(env, hyerror_last_error_message());
       return -1;
     }
   return (jlong) ((IDATA)mapAddress);



Mime
View raw message