commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r785496 - in /commons/sandbox/runtime/trunk/src/main: java/org/apache/commons/runtime/Pointer.java native/shared/memory.c
Date Wed, 17 Jun 2009 07:41:23 GMT
Author: mturk
Date: Wed Jun 17 07:41:23 2009
New Revision: 785496

URL: http://svn.apache.org/viewvc?rev=785496&view=rev
Log:
Protect memory access

Modified:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer.java
    commons/sandbox/runtime/trunk/src/main/native/shared/memory.c

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer.java?rev=785496&r1=785495&r2=785496&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer.java Wed
Jun 17 07:41:23 2009
@@ -26,7 +26,7 @@
 
     /*
      * Pointer can only be created from the native code.
-     * Suppress any instantiation except form internal classes.
+     * Suppress any instantiation except from internal classes.
      */
     protected Pointer()
     {
@@ -36,6 +36,10 @@
     private native void cleanup0()
         throws Throwable;
 
+	/* Used for finalize only.
+     * Doesn't throw exception in case of error
+     * returned from internal cleanup callback.
+     */
     private native void cleanup1()
         throws Throwable;
 

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/memory.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/memory.c?rev=785496&r1=785495&r2=785496&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/memory.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/memory.c Wed Jun 17 07:41:23 2009
@@ -17,6 +17,7 @@
 #include "acr.h"
 #include "acr_private.h"
 #include "acr_memory.h"
+#define  ACR_WANT_MEMPROTECT
 #include "acr_error.h"
 #include "acr_pointer.h"
 #include "acr_vm.h"
@@ -352,7 +353,7 @@
                                              jobject src, jlong off,
                                              jlong siz)
 {
-    jobject po;
+    jobject po = NULL;
     size_t  so  = (size_t)off;
     size_t  ss  = (size_t)siz;
     size_t  sl;
@@ -380,8 +381,12 @@
         return NULL;
     }
     /* Copy the original content */
-    memcpy(dp, sp + so, ss);
-    po = ACR_PointerCreate(_E, dp, ss, memory_pointer_cleanup);
+    ACR_TRY {
+        memcpy(dp, sp + so, ss);
+        po = ACR_PointerCreate(_E, dp, ss, memory_pointer_cleanup);
+    } ACR_CATCH() {
+        ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ERUNTIME, EFAULT);
+    }
     if (!po) {
         /* Destroy the the memory we failed to attach
          * to the new Pointer object.
@@ -420,7 +425,11 @@
     }
 
     /* Do a memcpy */
-    memcpy(d + dn, s + sn, cs);
+    ACR_TRY {
+        memcpy(d + dn, s + sn, cs);
+    } ACR_CATCH() {
+        ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ERUNTIME, EFAULT);
+    }
 }
 
 ACR_JNI_EXPORT_DECLARE(void, Memory, move)(ACR_JNISTDARGS, jobject src,
@@ -453,7 +462,11 @@
     }
 
     /* Do a memmove */
-    memmove(d + dn, s + sn, cs);
+    ACR_TRY {
+        memmove(d + dn, s + sn, cs);
+    } ACR_CATCH() {
+        ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ERUNTIME, EFAULT);
+    }
 }
 
 ACR_JNI_EXPORT_DECLARE(void, Memory, clear)(ACR_JNISTDARGS, jobject dst,
@@ -477,7 +490,11 @@
         return;
     }
     /* Do a memset */
-    memset(d + dn, 0, cs);
+    ACR_TRY {
+        memset(d + dn, 0, cs);
+    } ACR_CATCH() {
+        ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ERUNTIME, EFAULT);
+    }
 }
 
 ACR_JNI_EXPORT_DECLARE(void, Memory, set)(ACR_JNISTDARGS, jobject dst,
@@ -501,7 +518,11 @@
         return;
     }
     /* Do a memset */
-    memset(d + dn, c, cs);
+    ACR_TRY {
+        memset(d + dn, c, cs);
+    } ACR_CATCH() {
+        ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ERUNTIME, EFAULT);
+    }
 }
 
 ACR_JNI_EXPORT_DECLARE(jbyteArray, Memory, array0)(ACR_JNISTDARGS, jobject ptr,



Mime
View raw message