commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r1094646 - in /commons/sandbox/runtime/trunk/src/main: java/org/apache/commons/runtime/platform/unix/Posix.java native/os/unix/execmem.c native/os/unix/posixapi.c
Date Mon, 18 Apr 2011 16:54:32 GMT
Author: mturk
Date: Mon Apr 18 16:54:32 2011
New Revision: 1094646

URL: http://svn.apache.org/viewvc?rev=1094646&view=rev
Log:
Add more Posix api methods. We'll use those where ever possible

Modified:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/Posix.java
    commons/sandbox/runtime/trunk/src/main/native/os/unix/execmem.c
    commons/sandbox/runtime/trunk/src/main/native/os/unix/posixapi.c

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/Posix.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/Posix.java?rev=1094646&r1=1094645&r2=1094646&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/Posix.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/Posix.java
Mon Apr 18 16:54:32 2011
@@ -36,6 +36,36 @@ final class Posix
         // No Instance
     }
 
+    /* open flags       */
+    public static final int O_APPEND            = 0x0001;
+    public static final int O_CREAT             = 0x0002;
+    public static final int O_EXCL              = 0x0004;
+    public static final int O_TRUNC             = 0x0008;
+    public static final int O_RDONLY            = 0x0010;
+    public static final int O_WRONLY            = 0x0020;
+    public static final int O_RDWR              = 0x0040;
+    public static final int O_ASYNC             = 0x0100;
+    public static final int O_SYNC              = 0x0200;
+
+    /* mmap prot        */
+    public static final int PROT_EXEC           = 0x0001;
+    public static final int PROT_READ           = 0x0002;
+    public static final int PROT_WRITE          = 0x0004;
+    public static final int PROT_NONE           = 0x0008;
+    
+    /* mmap flags       */
+    public static final int MAP_SHARED          = 0x0001;
+    public static final int MAP_PRIVATE         = 0x0002;
+    public static final int MAP_ANONYMOUS       = 0x0004;
+    public static final int MAP_EXECUTABLE      = 0x0008;
+
+    /* msync flags      */
+    public static final int MS_ASYNC            = 0x0001;
+    public static final int MS_SYNC             = 0x0002;
+    public static final int MS_INVALIDATE       = 0x0004;
+
+    
+    public static native int            open(String name, int flags, int mode);
     public static native int            close(int fd);
     public static native int            unlink(String name);
     public static native int            chmod(String name, int mode);
@@ -44,7 +74,10 @@ final class Posix
     public static native int            fchown(int fd, int uid, int gid);
     public static native int            chdir(String path);
     public static native int            fchdir(int fd);
-    public static native String         getcwd()
-        throws SystemException;
-
+    public static native String         getcwd();
+    public static native long           mmap(long addr, long length, int prot,
+                                             int flags, long offset);
+    public static native int            munmap(long addr, long length);
+    public static native int            msync(long addr, long length, int flags);
+    
 }

Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/execmem.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/execmem.c?rev=1094646&r1=1094645&r2=1094646&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/execmem.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/execmem.c Mon Apr 18 16:54:32 2011
@@ -48,28 +48,3 @@ ACR_JNI_EXPORT(jobject, ExecutableMemory
     _clazzn.u = 1;
     return (*env)->NewObject(env, _clazzn.i, J4MID(0000));
 }
-
-ACR_UNX_EXPORT(jlong, PosixExecutableMemory,  alloc0)(JNI_STDARGS, jint size)
-{
-    void *mem;
-
-    mem = mmap(0, size,
-               PROT_READ | PROT_WRITE | PROT_EXEC,
-               MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
-    if (mem == MAP_FAILED) {
-        ACR_THROW_BY_ERRNO();
-        mem = 0;
-    }
-    return P2J(mem);
-}
-
-ACR_UNX_EXPORT(jint, PosixExecutableMemory,  free0)(JNI_STDARGS, jlong addr, jint size)
-{
-    void *mem = J2P(addr, void *);
-
-
-    if (munmap(mem, size) == 0)
-        return 0;
-    else
-        return ACR_GET_OS_ERROR();
-}

Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/posixapi.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/posixapi.c?rev=1094646&r1=1094645&r2=1094646&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/posixapi.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/posixapi.c Mon Apr 18 16:54:32 2011
@@ -19,6 +19,42 @@
 #include "acr/port.h"
 #include "arch_opts.h"
 
+#include <sys/mman.h>
+
+ACR_JNI_EXPORT(jint, Posix, open)(JNI_STDARGS, jstring name,
+                                  jint flags, jint mode)
+{
+    int fd = -1;
+    int oflags = 0;
+
+    if (flags & 0x0001)
+        oflags |= O_APPEND;
+    if (flags & 0x0002)
+        oflags |= O_CREAT;
+    if (flags & 0x0004)
+        oflags |= O_EXCL;
+    if (flags & 0x0008)
+        oflags |= O_TRUNC;
+    if (flags & 0x0010)
+        oflags |= O_RDONLY;
+    if (flags & 0x0020)
+        oflags |= O_WRONLY;
+    if (flags & 0x0040)
+        oflags |= O_RDWR;
+    if (flags & 0x0100)
+        oflags |= O_ASYNC;
+    if (flags & 0x0200)
+        oflags |= O_SYNC;
+    
+    WITH_CSTR(name) {
+        fd = open(J2S(name), oflags, mode);
+        if (fd == -1)
+            ACR_SAVE_OS_ERROR();
+    } DONE_WITH_STR(name);
+
+    return fd;
+}
+
 ACR_JNI_EXPORT(jint, Posix, close)(JNI_STDARGS, jint fd)
 {
     if (r_close(fd) == 0)
@@ -118,3 +154,73 @@ ACR_JNI_EXPORT(jstring, Posix, getcwd)(J
     else
         return CSTR_TO_JSTRING(path);
 }
+
+ACR_UNX_EXPORT(jlong, Posix,  mmap)(JNI_STDARGS, jlong addr, jlong size,
+                                    jint prot, jint flags, jint fd, jlong offset)
+{
+    void *base = 0;
+    void *mem  = J2P(addr, void *);
+    int mflags = 0;
+    int mmprot = 0;
+
+    if (size > SIZE_T_MAX)
+        return ACR_EOVERFLOW;
+    if (prot & 0x01)
+        mmprot |= PROT_EXEC;
+    if (prot & 0x02)
+        mmprot |= PROT_READ;
+    if (prot & 0x04)
+        mmprot |= PROT_WRITE;
+    if (prot & 0x08)
+        mmprot |= PROT_NONE;
+
+    if (flags & 0x01)
+        mflags |= MAP_SHARED;
+    if (flags & 0x02)
+        mflags |= MAP_PRIVATE;
+    if (flags & 0x04)
+        mflags |= MAP_ANONYMOUS;
+    if (flags & 0x08)
+        mflags |= MAP_EXECUTABLE;
+
+    base = mmap(mem, (size_t)size, mmprot, mflags, fd, offset);
+    if (base == MAP_FAILED) {
+        ACR_SAVE_OS_ERROR();
+        return 0;
+    }
+    return P2J(base);
+}
+
+ACR_UNX_EXPORT(jint, Posix,  munmap)(JNI_STDARGS, jlong addr, jlong size)
+{
+    void *mem = J2P(addr, void *);
+
+    if (size > SIZE_T_MAX)
+        return ACR_EOVERFLOW;
+
+    if (munmap(mem, (size_t)size) == 0)
+        return 0;
+    else
+        return ACR_GET_OS_ERROR();
+}
+
+ACR_UNX_EXPORT(jint, Posix,  msync)(JNI_STDARGS, jlong addr, jlong length, jint flags)
+{
+    void *mem = J2P(addr, void *);
+    int   mflags = 0;
+
+    if (length > SIZE_T_MAX)
+        return ACR_EOVERFLOW;
+    /*  MS_ASYNC:1  MS_SYNC:2 MS_INVALIDATE:4 */
+    if (flags & 0x01)
+        mflags |= MS_ASYNC;
+    if (flags & 0x02)
+        mflags |= MS_SYNC;
+    if (flags & 0x04)
+        mflags |= MS_INVALIDATE;
+    
+    if (msync(mem, (size_t)length, mflags) == 0)
+        return 0;
+    else
+        return ACR_GET_OS_ERROR();
+}



Mime
View raw message