You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mt...@apache.org on 2011/04/18 06:29:32 UTC

svn commit: r1094225 - in /commons/sandbox/runtime/trunk/src/main: java/org/apache/commons/runtime/ native/ native/include/acr/ native/os/darwin/ native/os/hpux/ native/os/unix/ native/os/win32/ native/shared/

Author: mturk
Date: Mon Apr 18 04:29:31 2011
New Revision: 1094225

URL: http://svn.apache.org/viewvc?rev=1094225&view=rev
Log:
Add more plafrom features

Added:
    commons/sandbox/runtime/trunk/src/main/native/os/darwin/os.c   (with props)
    commons/sandbox/runtime/trunk/src/main/native/os/hpux/os.c   (with props)
Modified:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Status.java
    commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in
    commons/sandbox/runtime/trunk/src/main/native/configure
    commons/sandbox/runtime/trunk/src/main/native/include/acr/error.h
    commons/sandbox/runtime/trunk/src/main/native/include/acr/jniapi.h
    commons/sandbox/runtime/trunk/src/main/native/os/unix/arch_opts.h
    commons/sandbox/runtime/trunk/src/main/native/os/unix/init.c
    commons/sandbox/runtime/trunk/src/main/native/os/unix/posixapi.c
    commons/sandbox/runtime/trunk/src/main/native/os/unix/procmutex.c
    commons/sandbox/runtime/trunk/src/main/native/os/unix/semaphore.c
    commons/sandbox/runtime/trunk/src/main/native/os/win32/arch_defs.h
    commons/sandbox/runtime/trunk/src/main/native/os/win32/init.c
    commons/sandbox/runtime/trunk/src/main/native/os/win32/semaphore.c
    commons/sandbox/runtime/trunk/src/main/native/os/win32/util.c
    commons/sandbox/runtime/trunk/src/main/native/os/win32/winapi.c
    commons/sandbox/runtime/trunk/src/main/native/shared/array.c
    commons/sandbox/runtime/trunk/src/main/native/shared/error.c
    commons/sandbox/runtime/trunk/src/main/native/shared/memory.c
    commons/sandbox/runtime/trunk/src/main/native/shared/native.c
    commons/sandbox/runtime/trunk/src/main/native/shared/pointer.c

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Status.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Status.java?rev=1094225&r1=1094224&r2=1094225&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Status.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Status.java Mon Apr 18 04:29:31 2011
@@ -29,6 +29,293 @@ public class Status
     {
         // No class instance
     }
+    /*
+     * Get Platform dependent error codes.
+     */
+    private static native void init0(int[] i);
+
+    static {
+        int [] i = new int[128];
+        init0(i);
+
+        OS_LAST_CANONERR    = i[0];
+        EPERM               = i[1];
+        ENOENT              = i[2];
+        ESRCH               = i[3];
+        EINTR               = i[4];
+        EIO                 = i[5];
+        ENXIO               = i[6];
+        E2BIG               = i[7];
+        ENOEXEC             = i[8];
+        EBADF               = i[9];
+        ECHILD              = i[10];
+        EDEADLK             = i[11];
+        ENOMEM              = i[12];
+        EACCES              = i[13];
+        EFAULT              = i[14];
+        ENOTBLK             = i[15];
+        EBUSY               = i[16];
+        EEXIST              = i[17];
+        EXDEV               = i[18];
+        ENODEV              = i[19];
+        ENOTDIR             = i[20];
+        EISDIR              = i[21];
+        EINVAL              = i[22];
+        ENFILE              = i[23];
+        EMFILE              = i[24];
+        ENOTTY              = i[25];
+        ETXTBSY             = i[26];
+        EFBIG               = i[27];
+        ENOSPC              = i[28];
+        ESPIPE              = i[29];
+        EROFS               = i[30];
+        EMLINK              = i[31];
+        EPIPE               = i[32];
+        EDOM                = i[33];
+        ERANGE              = i[34];
+        EAGAIN              = i[35];
+        EWOULDBLOCK         = i[36];
+        EINPROGRESS         = i[37];
+        EALREADY            = i[38];
+        ENOTSOCK            = i[39];
+        EDESTADDRREQ        = i[40];
+        EMSGSIZE            = i[41];
+        EPROTOTYPE          = i[42];
+        ENOPROTOOPT         = i[43];
+        EPROTONOSUPPORT     = i[44];
+        ESOCKTNOSUPPORT     = i[45];
+        EOPNOTSUPP          = i[46];
+        EPFNOSUPPORT        = i[47];
+        EAFNOSUPPORT        = i[48];
+        EADDRINUSE          = i[49];
+        EADDRNOTAVAIL       = i[50];
+        ENETDOWN            = i[51];
+        ENETUNREACH         = i[52];
+        ENETRESET           = i[53];
+        ECONNABORTED        = i[54];
+        ECONNRESET          = i[55];
+        ENOBUFS             = i[56];
+        EISCONN             = i[57];
+        ENOTCONN            = i[58];
+        ESHUTDOWN           = i[59];
+        ETOOMANYREFS        = i[60];
+        ETIMEDOUT           = i[61];
+        ECONNREFUSED        = i[62];
+        ELOOP               = i[63];
+        ENAMETOOLONG        = i[64];
+        EHOSTDOWN           = i[65];
+        EHOSTUNREACH        = i[66];
+        ENOTEMPTY           = i[67];
+        EPROCLIM            = i[68];
+        EUSERS              = i[69];
+        EDQUOT              = i[70];
+        ESTALE              = i[71];
+        EREMOTE             = i[72];
+        EBADRPC             = i[73];
+        ERPCMISMATCH        = i[74];
+        EPROGUNAVAIL        = i[75];
+        EPROGMISMATCH       = i[76];
+        EPROCUNAVAIL        = i[77];
+        ENOLCK              = i[78];
+        ENOSYS              = i[79];
+        EFTYPE              = i[80];
+        EAUTH               = i[81];
+        ENEEDAUTH           = i[82];
+        EIPSEC              = i[83];
+        ENOATTR             = i[84];
+        EILSEQ              = i[85];
+        ENOMEDIUM           = i[86];
+        EMEDIUMTYPE         = i[87];
+        EOVERFLOW           = i[88];
+        ECANCELED           = i[89];
+        EIDRM               = i[90];
+        ENOMSG              = i[91];
+
+    }
+
+    /* ACR CANONICAL ERROR VALUES */
+    /** Operation not permitted */
+    public static final int EPERM;
+    /** No such file or directory */
+    public static final int ENOENT;
+    /** No such process */
+    public static final int ESRCH;
+    /** Interrupted system call */
+    public static final int EINTR;
+    /** Input/output error */
+    public static final int EIO;
+    /** Device not configured */
+    public static final int ENXIO;
+    /** Argument list too long */
+    public static final int E2BIG;
+    /** Exec format error */
+    public static final int ENOEXEC;
+    /** Bad file descriptor */
+    public static final int EBADF;
+    /** No child processes */
+    public static final int ECHILD;
+    /** Resource deadlock avoided */
+    public static final int EDEADLK;
+    /** Cannot allocate memory */
+    public static final int ENOMEM;
+    /** Permission denied */
+    public static final int EACCES;
+    /** Bad address */
+    public static final int EFAULT;
+    /** Block device required */
+    public static final int ENOTBLK;
+    /** Device busy */
+    public static final int EBUSY;
+    /** File exists */
+    public static final int EEXIST;
+    /** Cross-device link */
+    public static final int EXDEV;
+    /** Operation not supported by device */
+    public static final int ENODEV;
+    /** Not a directory */
+    public static final int ENOTDIR;
+    /** Is a directory */
+    public static final int EISDIR;
+    /** Invalid argument */
+    public static final int EINVAL;
+    /** Too many open files in system */
+    public static final int ENFILE;
+    /** Too many open files */
+    public static final int EMFILE;
+    /** Inappropriate ioctl for device */
+    public static final int ENOTTY;
+    /** Text file busy */
+    public static final int ETXTBSY;
+    /** File too large */
+    public static final int EFBIG;
+    /** No space left on device */
+    public static final int ENOSPC;
+    /** Illegal seek */
+    public static final int ESPIPE;
+    /** Read-only file system */
+    public static final int EROFS;
+    /** Too many links */
+    public static final int EMLINK;
+    /** Broken pipe */
+    public static final int EPIPE;
+    /** Numerical argument out of domain */
+    public static final int EDOM;
+    /** Result too large */
+    public static final int ERANGE;
+    /** Resource temporarily unavailable */
+    public static final int EAGAIN;
+    /** Operation would block */
+    public static final int EWOULDBLOCK;
+    /** Operation now in progress */
+    public static final int EINPROGRESS;
+    /** Operation already in progress */
+    public static final int EALREADY;
+    /** Socket operation on non-socket */
+    public static final int ENOTSOCK;
+    /** Destination address required */
+    public static final int EDESTADDRREQ;
+    /** Message too long */
+    public static final int EMSGSIZE;
+    /** Protocol wrong type for socket */
+    public static final int EPROTOTYPE;
+    /** Protocol not available */
+    public static final int ENOPROTOOPT;
+    /** Protocol not supported */
+    public static final int EPROTONOSUPPORT;
+    /** Socket type not supported */
+    public static final int ESOCKTNOSUPPORT;
+    /** Operation not supported */
+    public static final int EOPNOTSUPP;
+    /** Protocol family not supported */
+    public static final int EPFNOSUPPORT;
+    /** Address family not supported by protocol family */
+    public static final int EAFNOSUPPORT;
+    /** Address already in use */
+    public static final int EADDRINUSE;
+    /** Can't assign requested address */
+    public static final int EADDRNOTAVAIL;
+    /** Network is down */
+    public static final int ENETDOWN;
+    /** Network is unreachable */
+    public static final int ENETUNREACH;
+    /** Network dropped connection on reset */
+    public static final int ENETRESET;
+    /** Software caused connection abort */
+    public static final int ECONNABORTED;
+    /** Connection reset by peer */
+    public static final int ECONNRESET;
+    /** No buffer space available */
+    public static final int ENOBUFS;
+    /** Socket is already connected */
+    public static final int EISCONN;
+    /** Socket is not connected */
+    public static final int ENOTCONN;
+    /** Can't send after socket shutdown */
+    public static final int ESHUTDOWN;
+    /** Too many references: can't splice */
+    public static final int ETOOMANYREFS;
+    /** Operation timed out */
+    public static final int ETIMEDOUT;
+    /** Connection refused */
+    public static final int ECONNREFUSED;
+    /** Too many levels of symbolic links */
+    public static final int ELOOP;
+    /** File name too long */
+    public static final int ENAMETOOLONG;
+    /** Host is down */
+    public static final int EHOSTDOWN;
+    /** No route to host */
+    public static final int EHOSTUNREACH;
+    /** Directory not empty */
+    public static final int ENOTEMPTY;
+    /** Too many processes */
+    public static final int EPROCLIM;
+    /** Too many users */
+    public static final int EUSERS;
+    /** Disk quota exceeded */
+    public static final int EDQUOT;
+    /** Stale NFS file handle */
+    public static final int ESTALE;
+    /** Too many levels of remote in path */
+    public static final int EREMOTE;
+    /** RPC struct is bad */
+    public static final int EBADRPC;
+    /** RPC version wrong */
+    public static final int ERPCMISMATCH;
+    /** RPC prog. not avail */
+    public static final int EPROGUNAVAIL;
+    /** Program version wrong */
+    public static final int EPROGMISMATCH;
+    /** Bad procedure for program */
+    public static final int EPROCUNAVAIL;
+    /** No locks available */
+    public static final int ENOLCK;
+    /** Function not implemented */
+    public static final int ENOSYS;
+    /** Inappropriate file type or format */
+    public static final int EFTYPE;
+    /** Authentication error */
+    public static final int EAUTH;
+    /** Need authenticator */
+    public static final int ENEEDAUTH;
+    /** IPsec processing failure */
+    public static final int EIPSEC;
+    /** Attribute not found */
+    public static final int ENOATTR;
+    /** Illegal byte sequence */
+    public static final int EILSEQ;
+    /** No medium found */
+    public static final int ENOMEDIUM;
+    /** Wrong Medium Type */
+    public static final int EMEDIUMTYPE;
+    /** Conversion overflow */
+    public static final int EOVERFLOW;
+    /** Operation canceled */
+    public static final int ECANCELED;
+    /** Identifier removed */
+    public static final int EIDRM;
+    /** No message of desired type */
+    public static final int ENOMSG;
 
     /* Hard coded definitions for acr/error.h
      */
@@ -39,7 +326,7 @@ public class Status
      *     on systems which don't have the corresponding errno.
      */
     private static final int OS_START_CANONERR      = 500000;
-    private static final int OS_LAST_CANONERR       = 500091;
+    private static final int OS_LAST_CANONERR;
     /**
      * ACR_OS_ERRSPACE_SIZE is the maximum number of errors you can fit
      *    into one of the error/status ranges below -- except for
@@ -153,5 +440,43 @@ public class Status
         return is0(3, s);
     }
 
+    /** Not enough memory */
+    public static boolean IS_ENOMEM(int s)
+    {
+        return is0(4, s);
+    }
+
+    /** Invalid value */
+    public static boolean IS_EINVAL(int s)
+    {
+        return is0(5, s);
+    }
+
+    /** Try again */
+    public static boolean IS_EAGAIN(int s)
+    {
+        return is0(6, s);
+    }
+
+    /** Operation timed out */
+    public static boolean IS_TIMEUP(int s)
+    {
+        return is0(7, s);
+    }
+
+    /** Obtain an error string for system error code.
+     *
+     * @param s error code
+     */
     public static native String describe(int s);
+
+    /** Return the calling thread's last-error code value.
+     *
+     * The last-error code is maintained on a per-thread basis.
+     * Multiple threads do not overwrite each others's last-error code.
+     * Commons runtime uses it's own per-thread storage for
+     * last-error code.
+     */
+    public static native int errno();
+    
 }

Modified: commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in?rev=1094225&r1=1094224&r2=1094225&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in (original)
+++ commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in Mon Apr 18 04:29:31 2011
@@ -69,15 +69,19 @@ UNIX_SOURCES=\
 	$(TOPDIR)/os/unix/time.c \
 	$(TOPDIR)/os/unix/util.c
 
+AIX_SOURCES=\
+	$(TOPDIR)/os/aix/os.c
+BSDX_SOURCES=\
+	$(TOPDIR)/os/bsdx/os.c
+DARWIN_SOURCES=\
+	$(TOPDIR)/os/darwin/os.c
+HPUX_SOURCES=\
+	$(TOPDIR)/os/hpux/os.c
 LINUX_SOURCES=\
 	$(TOPDIR)/os/linux/misc.c \
 	$(TOPDIR)/os/linux/os.c
-
-AIX_SOURCES=
-BSDX_SOURCES=
-DARWIN_SOURCES=
-HPUX_SOURCES=
-SOLARIS_SOURCES=
+SOLARIS_SOURCES=\
+	$(TOPDIR)/os/solaris/os.c
 
 LIBSOURCES=\
 	$(BZIP2_SOURCES) \

Modified: commons/sandbox/runtime/trunk/src/main/native/configure
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/configure?rev=1094225&r1=1094224&r2=1094225&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/configure (original)
+++ commons/sandbox/runtime/trunk/src/main/native/configure Mon Apr 18 04:29:31 2011
@@ -768,33 +768,6 @@ if [ ".$has_maintainer_mode" = .yes ]; t
 else
     varadds cppopts -DNDEBUG
 fi
-if [ ".$has_posix_mutex" = .yes ]; then
-    if [ ".$has_sysv_mutex_set" = .yes ]; then
-        echo "[ERROR] Cannot have both Posix and System V mutexes"
-        exit 22
-    fi
-    has_sysv_mutex=no
-fi
-if [ ".$has_fcntl_mutex" = .yes ]; then
-    if [ ".$has_sysv_mutex_set" = .yes ]; then
-        echo "[ERROR] Cannot have both File and System V mutexes"
-        exit 22
-    fi
-    if [ ".$has_posix_mutex_set" = .yes ]; then
-        echo "[ERROR] Cannot have both File and Posix mutexes"
-        exit 22
-    fi
-    has_sysv_mutex=no
-    has_posix_mutex=no
-fi
-
-if [ ".$has_sysv_mutex" = .yes ]; then
-    varadds cppopts -DUSE_SYSV_MUTEX
-elif [ ".$has_posix_mutex" = .yes ]; then
-    varadds cppopts -DUSE_POSIX_MUTEX
-else
-    varadds cppopts -DUSE_FCNTL_MUTEX
-fi
 varadds cppopts -DOCPR_API_EXPORT
 if [ ".$has_shared_version" = .yes ]; then
     sharedlib='$(SHAREDLIB)'
@@ -919,6 +892,12 @@ test_compile()
         test ".$rd" = "."  && rd=$2
         rc=$rd
     else
+        if [ ".$1" = .z ]; then
+            rv=""
+            test ".$rc" = ".1" && rv="`./$cccsrc 2>>$configlog`"
+            test ".$rv" = "."  && rv=$2
+            rc=$rv
+        fi
         test ".$rc" = .1 && rd=ok
     fi
     echo "Result: $rd" >>$configlog
@@ -976,7 +955,7 @@ EOF
 int main() {return 0;}
 EOF
     fi
-    rc=`test_compile 0 0 -l$1`
+    rc=`test_compile c 0 -l$1`
     echo $rc
 }
 
@@ -1089,7 +1068,7 @@ extern CPR_THREAD char tls_ea[8];
 CPR_THREAD char tls_ea[8]={0};
 int main () {printf("%d", tls_i+tls_sa[0]+tls_ea[0]);return 0;}
 EOF
-    rc=`test_compile x 0`
+    rc=`test_compile z 0`
     echo $rc
 }
 
@@ -1106,7 +1085,7 @@ int main () {sem_open("/x$$x",0,0,0);
 if (errno!=ENOSYS)rc=1;printf("%d", rc);return 0;
 }
 EOF
-    rc=`test_compile x 0`
+    rc=`test_compile z 0`
     echo $rc
 }
 
@@ -1124,7 +1103,7 @@ int main () {
 if(socket(AF_INET6,SOCK_STREAM,0)>= 0)rc = 1;printf("%d", rc);return 0;
 }
 EOF
-    rc=`test_compile x 0`
+    rc=`test_compile z 0`
     echo $rc
 }
 
@@ -1183,6 +1162,39 @@ else
     have_port_h=0
     have_kstat=0
 fi
+have_posixsem=`have_sem_open`
+if [ ".$has_posix_mutex" = .yes ]; then
+    if [ ".$has_sysv_mutex_set" = .yes ]; then
+        echo "[ERROR] Cannot have both Posix and System V mutexes"
+        exit 22
+    fi
+    if [ ".$have_posixsem" = 0 ]; then
+        echo "[ERROR] Posix semaphores are not supported"
+        exit 22
+    fi
+    have_posixsem=1
+    has_sysv_mutex=no
+fi
+if [ ".$has_fcntl_mutex" = .yes ]; then
+    if [ ".$has_sysv_mutex_set" = .yes ]; then
+        echo "[ERROR] Cannot have both File and System V mutexes"
+        exit 22
+    fi
+    if [ ".$has_posix_mutex_set" = .yes ]; then
+        echo "[ERROR] Cannot have both File and Posix mutexes"
+        exit 22
+    fi
+    has_sysv_mutex=no
+    has_posix_mutex=no
+fi
+
+if [ ".$has_sysv_mutex" = .yes ]; then
+    varadds cppopts -DUSE_SYSV_MUTEX
+elif [ ".$has_posix_mutex" = .yes ]; then
+    varadds cppopts -DUSE_POSIX_MUTEX
+else
+    varadds cppopts -DUSE_FCNTL_MUTEX
+fi
 
 have_ocsp=0
 have_openssl=0
@@ -1365,7 +1377,7 @@ extern "C" {
 #define HAVE_FUNCTION           `have_defined __FUNCTION__`
 #define HAVE_FUNCSIG            `have_defined __FUNCSIG__`
 #define HAVE_FUNC               `have_defined __func__`
-#define HAVE_POSIX_SEMAPHORE    `have_sem_open`
+#define HAVE_POSIX_SEMAPHORE    $have_posixsem
 #define HAVE_THREAD_LOCAL       `have_thread_local`
 #define HAVE_IPV6               `have_ipv6`
 
@@ -1416,7 +1428,7 @@ write_var()
 {
 
     eval "s=\$$2"
-    fmts=`echo $s | fmt -w72`
+    fmts=`echo $s | fmt`
     sIFS=$IFS
     IFS="
 "

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr/error.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr/error.h?rev=1094225&r1=1094224&r2=1094225&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr/error.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr/error.h Mon Apr 18 04:29:31 2011
@@ -1613,6 +1613,7 @@ ACR_INLINE(DWORD) AcrNetOsError()
 #define ACR_THROW_SYS_ERROR()   AcrThrowException(env, ACR_EX_ESYS, ACR_GET_OS_ERROR())
 #endif
 #define ACR_THROW_MSG(CL, MS)   AcrThrow(env, (CL), MS)
+#define ACR_THROW_BY_ERRNO()    AcrThrowByStatus(env, ACR_GET_OS_ERROR(), 0)
 
 #ifdef __cplusplus
 extern "C" {
@@ -1627,6 +1628,8 @@ AcrFatalError(JNI_STDENV,
 void
 AcrThrowByName(JNI_STDENV, const char *cls, const char *msg);
 void
+AcrThrowByStatus(JNI_STDENV, int err, const char *msg);
+void
 AcrThrow(JNI_STDENV, int cls, const char *msg);
 void
 AcrThrowClass(JNI_STDENV, const char *clazz, const char *msg);

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr/jniapi.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr/jniapi.h?rev=1094225&r1=1094224&r2=1094225&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr/jniapi.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr/jniapi.h Mon Apr 18 04:29:31 2011
@@ -34,13 +34,16 @@ typedef struct acr_tlsd_t  {
     acr_tls_destructor_t        dtor;
 } acr_tlsd_t;
 
+#define ACR_SAVE_ERROR(err)     AcrSetThreadError((err))
+#define ACR_SAVE_OS_ERROR()     AcrSetThreadError(ACR_GET_OS_ERROR())
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-JNIEnv *
-AcrGetJNIEnv(void);
+JNIEnv *AcrGetJNIEnv(void);
+void    AcrSetThreadError(int);
+int     AcrGetThreadError(void);
 
 #ifdef __cplusplus
 }

Added: commons/sandbox/runtime/trunk/src/main/native/os/darwin/os.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/darwin/os.c?rev=1094225&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/darwin/os.c (added)
+++ commons/sandbox/runtime/trunk/src/main/native/os/darwin/os.c Mon Apr 18 04:29:31 2011
@@ -0,0 +1,91 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "acr/jniapi.h"
+#include "acr/string.h"
+#include <sys/utsname.h>
+#include <sys/param.h>
+#include <sys/sysctl.h>
+
+static int            _sys_done = -1;
+static struct utsname _sys_buf;
+static int            _sys_ncpu = 0;
+static const char     _unknown[] = "unknown";
+
+ACR_JNI_EXPORT(jint, Os, getType)(JNI_STDARGS)
+{
+    UNREFERENCED_STDARGS;
+    return ACR_OS_DARWIN;
+}
+
+ACR_JNI_EXPORT(jint, Os, getNumCpu)(JNI_STDARGS)
+{
+    UNREFERENCED_STDARGS;
+    if (_sys_ncpu == 0) {
+        int    mib[2];
+        size_t len = sizeof(_sys_ncpu);
+
+        mib[0] = CTL_HW;
+        mib[1] = HW_NCPU;
+        if (sysctl(mib, 2, &_sys_ncpu,  &len, 0, 0) < 0)
+            _sys_ncpu = 1;
+    }
+    return _sys_ncpu;
+}
+
+ACR_JNI_EXPORT(jint, Os, init)(JNI_STDARGS)
+{
+    UNREFERENCED_STDARGS;
+    if (_sys_done == 0)
+        return 0;
+    _sys_done = uname(&_sys_buf);
+    if (_sys_done)
+        return errno;
+    else
+        return 0;
+}
+
+ACR_JNI_EXPORT(jstring, Os, getSysname)(JNI_STDARGS)
+{
+    if (_sys_done == 0)
+        return CSTR_TO_JSTRING(_sys_buf.sysname);
+    else
+        return CSTR_TO_JSTRING(_unknown);
+}
+
+ACR_JNI_EXPORT(jstring, Os, getNodename)(JNI_STDARGS)
+{
+    if (_sys_done == 0)
+        return CSTR_TO_JSTRING(_sys_buf.nodename);
+    else
+        return CSTR_TO_JSTRING(_unknown);
+}
+
+ACR_JNI_EXPORT(jstring, Os, getRelease)(JNI_STDARGS)
+{
+    if (_sys_done == 0)
+        return CSTR_TO_JSTRING(_sys_buf.release);
+    else
+        return CSTR_TO_JSTRING(_unknown);
+}
+
+ACR_JNI_EXPORT(jstring, Os, getVersion)(JNI_STDARGS)
+{
+    if (_sys_done == 0)
+        return CSTR_TO_JSTRING(_sys_buf.version);
+    else
+        return CSTR_TO_JSTRING(_unknown);
+}

Propchange: commons/sandbox/runtime/trunk/src/main/native/os/darwin/os.c
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/sandbox/runtime/trunk/src/main/native/os/hpux/os.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/hpux/os.c?rev=1094225&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/hpux/os.c (added)
+++ commons/sandbox/runtime/trunk/src/main/native/os/hpux/os.c Mon Apr 18 04:29:31 2011
@@ -0,0 +1,78 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "acr/jniapi.h"
+#include "acr/string.h"
+#include <sys/utsname.h>
+
+static int            _sys_done = -1;
+static struct utsname _sys_buf;
+static int            _sys_ncpu = 0;
+static const char     _unknown[] = "unknown";
+
+ACR_JNI_EXPORT(jint, Os, getType)(JNI_STDARGS)
+{
+    UNREFERENCED_STDARGS;
+    return ACR_OS_HPUX;
+}
+
+ACR_JNI_EXPORT(jint, Os, getNumCpu)(JNI_STDARGS)
+{
+    UNREFERENCED_STDARGS;
+    /* TODO: Get HP-UX number of CPU's */
+    return _sys_ncpu;
+}
+
+ACR_JNI_EXPORT(jint, Os, init)(JNI_STDARGS)
+{
+    UNREFERENCED_STDARGS;
+    if (_sys_done == 0)
+        return 0;
+    _sys_done = uname(&_sys_buf);
+    if (_sys_done)
+        return errno;
+    else
+        return 0;
+}
+
+ACR_JNI_EXPORT(jstring, Os, getSysname)(JNI_STDARGS)
+{
+    return CSTR_TO_JSTRING("hpux");
+}
+
+ACR_JNI_EXPORT(jstring, Os, getNodename)(JNI_STDARGS)
+{
+    if (_sys_done == 0)
+        return CSTR_TO_JSTRING(_sys_buf.nodename);
+    else
+        return CSTR_TO_JSTRING(_unknown);
+}
+
+ACR_JNI_EXPORT(jstring, Os, getRelease)(JNI_STDARGS)
+{
+    if (_sys_done == 0)
+        return CSTR_TO_JSTRING(_sys_buf.release);
+    else
+        return CSTR_TO_JSTRING(_unknown);
+}
+
+ACR_JNI_EXPORT(jstring, Os, getVersion)(JNI_STDARGS)
+{
+    if (_sys_done == 0)
+        return CSTR_TO_JSTRING(_sys_buf.version);
+    else
+        return CSTR_TO_JSTRING(_unknown);
+}

Propchange: commons/sandbox/runtime/trunk/src/main/native/os/hpux/os.c
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/arch_opts.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/arch_opts.h?rev=1094225&r1=1094224&r2=1094225&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/arch_opts.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/arch_opts.h Mon Apr 18 04:29:31 2011
@@ -19,18 +19,6 @@
 
 #include "acr/stddefs.h"
 
-#define THROW_STD_ERRORS()              \
-    if (errno == EEXIST)                \
-        ACR_THROW(ACR_EX_EEXIST, 0);    \
-    else if (errno == ENOENT)           \
-        ACR_THROW(ACR_EX_ENOENT, 0);    \
-    else if (errno == EACCES)           \
-        ACR_THROW(ACR_EX_EACCES, 0);    \
-    else if (errno == ENOSYS)           \
-        ACR_THROW(ACR_EX_ENOTIMPL, 0);  \
-    else                                \
-        ACR_THROW_SYS_ERROR()
-
 /* restartable close() */
 ACR_INLINE(int) r_close(int fd)
 {

Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/init.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/init.c?rev=1094225&r1=1094224&r2=1094225&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/init.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/init.c Mon Apr 18 04:29:31 2011
@@ -32,6 +32,7 @@ typedef struct tlsd_t
     ACR_RING_HEAD(_cr_tlsd_s, acr_tlsd_t) tlsd;
     JNIEnv      *env;
     int          attached;
+    int          error;
     acr_u64_t    id;
 } tlsd_t;
 
@@ -145,6 +146,26 @@ AcrGetJNIEnv()
     return tlsd->env;
 }
 
+void
+AcrSetThreadError(int e)
+{
+    tlsd_t *tlsd;
+
+    if ((tlsd = _threadkey_get()) != 0)
+        tlsd->error = e;
+}
+
+int
+AcrGetThreadError()
+{
+    tlsd_t *tlsd;
+
+    if ((tlsd = _threadkey_get()) != 0)
+        return tlsd->error;
+    else
+        return ACR_ENOMEM;
+}
+
 #if defined(__GNUC__) || defined(__SUNPRO_C)
 void __attribute__ ((constructor))
 AcrLibraryAttach(void)

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=1094225&r1=1094224&r2=1094225&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 04:29:31 2011
@@ -15,6 +15,7 @@
  */
 
 #include "acr/string.h"
+#include "acr/jniapi.h"
 #include "acr/port.h"
 #include "arch_opts.h"
 
@@ -111,7 +112,7 @@ ACR_JNI_EXPORT(jstring, Posix, getcwd)(J
     char path[ACR_PATH_MAX];
 
     if (getcwd(path, ACR_PATH_MAX) == 0) {
-        ACR_THROW_SYS_ERROR();
+        ACR_SAVE_OS_ERROR();
         return 0;
     }
     else

Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/procmutex.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/procmutex.c?rev=1094225&r1=1094224&r2=1094225&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/procmutex.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/procmutex.c Mon Apr 18 04:29:31 2011
@@ -116,12 +116,12 @@ ACR_UNX_EXPORT(jint, SysVMutex, create0)
 
         fd = open(J2S(name), O_WRONLY | O_CREAT | O_EXCL, 0660);
         if (fd == -1) {
-            THROW_STD_ERRORS();
+            ACR_THROW_BY_ERRNO();
             goto cleanup;
         }
         mkey = ftok(J2S(name), 'a');
         if (mkey == (key_t)-1) {
-            ACR_THROW_SYS_ERROR();                
+            ACR_THROW_SYS_ERROR();
             goto cleanup;
         }
         /* Write our header to shadow file
@@ -133,15 +133,15 @@ ACR_UNX_EXPORT(jint, SysVMutex, create0)
         hdr.magic   = ACR_MTX_MAGIC;
         hdr.value   = 1;
         if (r_write(fd,(const void *)&hdr, nbytes) == -1) {
-            ACR_THROW_SYS_ERROR();                
+            ACR_THROW_SYS_ERROR();
             goto cleanup;
         }
         flags |= IPC_EXCL;
         pd = semget(mkey, 1, flags | 0660);
         if (pd == -1) {
-            THROW_STD_ERRORS();
+            ACR_THROW_BY_ERRNO();
             goto cleanup;
-        }            
+        }
 
 cleanup:
         if (fd != -1)
@@ -156,8 +156,8 @@ cleanup:
                 pd = -1;
             }
         }
-    } DONE_WITH_STR(name);    
-    
+    } DONE_WITH_STR(name);
+
     return pd;
 }
 
@@ -171,26 +171,26 @@ ACR_UNX_EXPORT(jint, SysVMutex, open0)(J
 
         fd = open(J2S(name), O_RDONLY);
         if (fd == -1) {
-            THROW_STD_ERRORS();
+            ACR_THROW_BY_ERRNO();
             goto cleanup;
         }
         mkey = ftok(J2S(name), 'a');
         if (mkey == (key_t)-1) {
-            ACR_THROW_SYS_ERROR();                
+            ACR_THROW_SYS_ERROR();
             close(fd);
             goto cleanup;
         }
         pd = semget(mkey, 1, 0);
         if (pd == -1) {
-            THROW_STD_ERRORS();
+            ACR_THROW_BY_ERRNO();
             goto cleanup;
-        }            
+        }
 
 cleanup:
         if (fd != -1)
             close(fd);
-    } DONE_WITH_STR(name);    
-    
+    } DONE_WITH_STR(name);
+
     return pd;
 }
 
@@ -206,8 +206,8 @@ ACR_UNX_EXPORT(jint, SysVMutex, unlink0)
             rc = ACR_GET_OS_ERROR();
         if (unlink(J2S(name)) == -1 && rc == 0)
             rc = ACR_GET_OS_ERROR();
-    } DONE_WITH_STR(name);    
-    
+    } DONE_WITH_STR(name);
+
     return rc;
 }
 
@@ -276,10 +276,10 @@ ACR_UNX_EXPORT(jint, FcntlMutex, create0
     WITH_CSTR(name) {
         fd = open(J2S(name), O_WRONLY | O_CREAT | O_EXCL, 0660);
         if (fd == -1) {
-            THROW_STD_ERRORS();
+            ACR_THROW_BY_ERRNO();
         }
-    } DONE_WITH_STR(name);    
-    
+    } DONE_WITH_STR(name);
+
     return fd;
 }
 
@@ -290,10 +290,10 @@ ACR_UNX_EXPORT(jint, FcntlMutex, open0)(
     WITH_CSTR(name) {
         fd = open(J2S(name), O_RDONLY);
         if (fd == -1) {
-            THROW_STD_ERRORS();
+            ACR_THROW_BY_ERRNO();
         }
-    } DONE_WITH_STR(name);    
-    
+    } DONE_WITH_STR(name);
+
     return fd;
 }
 

Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/semaphore.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/semaphore.c?rev=1094225&r1=1094224&r2=1094225&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/semaphore.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/semaphore.c Mon Apr 18 04:29:31 2011
@@ -23,7 +23,7 @@
 #include <semaphore.h>
 
 #if !defined(SEM_FAILED)
-# define SEM_FAILED    (-1)
+# define SEM_FAILED    (sem_t *)(-1)
 #endif
 #if !defined(NAME_MAX)
 # define NAME_MAX      64
@@ -46,14 +46,14 @@ J_DECLARE_M_ID(0000) = {
 ACR_JNI_EXPORT(jobject, SemaphoreImpl, init0)(JNI_STDARGS)
 {
     if (_clazzn.u == 1)
-        return (*env)->NewObject(env, _clazzn.i, J4MID(0000));    
+        return (*env)->NewObject(env, _clazzn.i, J4MID(0000));
     if (AcrLoadClass(env, &_clazzn, 0) != 0) {
         ACR_THROW_MSG(ACR_EX_EINSTANCE, "PosixSemaphoreImpl not initialized");
         return 0;
     }
     R_LOAD_METHOD(0000, 0);
     _clazzn.u = 1;
-    return (*env)->NewObject(env, _clazzn.i, J4MID(0000));    
+    return (*env)->NewObject(env, _clazzn.i, J4MID(0000));
 }
 
 ACR_JNI_EXPORT(jboolean, Semaphore, unlink0)(JNI_STDARGS, jstring name)
@@ -62,7 +62,7 @@ ACR_JNI_EXPORT(jboolean, Semaphore, unli
     WITH_CSTR(name) {
         char *p;
         char buf[PATH_MAX] = "/";
-        
+
         strlcat(buf, J2S(name), PATH_MAX);
         for (p = &buf[1]; *p != '\0'; p++) {
             if (*p == '/')
@@ -90,15 +90,15 @@ ACR_UNX_EXPORT(jlong, PosixSemaphore, cr
     sem_t *sp = 0;
 
     WITH_CSTR(name) {
-        sp = sem_open(J2S(name), O_CREAT | O_EXCL, 0660, value);       
+        sp = sem_open(J2S(name), O_CREAT | O_EXCL, 0660, value);
         if (sp == SEM_FAILED) {
             if (errno == ENAMETOOLONG)
                 ACR_THROW(ACR_EX_EINVAL, 0);
             else
-                THROW_STD_ERRORS();
+                ACR_THROW_BY_ERRNO();
         }
-    } DONE_WITH_STR(name);    
-    
+    } DONE_WITH_STR(name);
+
     return P2J(sp);
 }
 
@@ -108,15 +108,15 @@ ACR_UNX_EXPORT(jlong, PosixSemaphore, op
     sem_t *sp = 0;
 
     WITH_CSTR(name) {
-        sp = sem_open(J2S(name), O_RDWR, 0, 0);       
+        sp = sem_open(J2S(name), O_RDWR, 0, 0);
         if (sp == SEM_FAILED) {
             if (errno == ENAMETOOLONG)
                 ACR_THROW(ACR_EX_EINVAL, 0);
             else
-                THROW_STD_ERRORS();
+                ACR_THROW_BY_ERRNO();
         }
-    } DONE_WITH_STR(name);    
-    
+    } DONE_WITH_STR(name);
+
     return P2J(sp);
 }
 
@@ -177,6 +177,6 @@ ACR_UNX_EXPORT(jint, PosixSemaphore, rel
 #else
 ACR_JNI_EXPORT(jobject, SemaphoreImpl, init0)(JNI_STDARGS)
 {
-    return 0;    
+    return 0;
 }
 #endif

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/arch_defs.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/arch_defs.h?rev=1094225&r1=1094224&r2=1094225&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/arch_defs.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/arch_defs.h Mon Apr 18 04:29:31 2011
@@ -60,8 +60,8 @@ typedef struct OVERLAPPED_VBUFF {
     DWORD      stat;
     DWORD      size;
     char       buff[1];
-} OVERLAPPED_VBUFF; 
- 
+} OVERLAPPED_VBUFF;
+
 #define SAFE_CLOSE_HANDLE(H)                                        \
     if ((H) != 0 && (H) != INVALID_HANDLE_VALUE) {                  \
         CloseHandle((H));                                           \
@@ -144,7 +144,7 @@ typedef struct _REPARSE_DATA_BUFFER {
  * end of DDK declarations
  * ---------------------------------------------------------------------
  */
- 
+
 ACR_INLINE(int) isblank(int c)
 {
     return c == ' ' || c == '\t';

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/init.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/init.c?rev=1094225&r1=1094224&r2=1094225&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/init.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/init.c Mon Apr 18 04:29:31 2011
@@ -39,6 +39,7 @@ typedef struct tlsd_t
     ACR_RING_HEAD(_cr_tlsd_s, acr_tlsd_t) tlsd;
     JNIEnv      *env;
     int          attached;
+    int          error;
     DWORD        id;
 } tlsd_t;
 
@@ -129,6 +130,26 @@ AcrGetJNIEnv()
     return tlsd->env;
 }
 
+void
+AcrSetThreadError(int e)
+{
+    tlsd_t *tlsd;
+
+    if ((tlsd = _threadkey_get()) != 0)
+        tlsd->error = e;
+}
+
+int
+AcrGetThreadError()
+{
+    tlsd_t *tlsd;
+
+    if ((tlsd = _threadkey_get()) != 0)
+        return tlsd->error;
+    else
+        return ACR_ENOMEM;
+}
+
 /* Called by the JVM when ACR is loaded */
 ACR_API(jint)
 JNI_OnLoad(JavaVM *vm, void *reserved)

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/semaphore.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/semaphore.c?rev=1094225&r1=1094224&r2=1094225&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/semaphore.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/semaphore.c Mon Apr 18 04:29:31 2011
@@ -73,16 +73,7 @@ ACR_WIN_EXPORT(jlong, WindowsSemaphore, 
     WITH_WSTR(name) {
         sp = CreateSemaphoreW(&sa, (LONG)value, (LONG)maxval, J2S(name));
         if (sp == 0) {
-            int rc = ACR_GET_OS_ERROR();
-            if (ACR_STATUS_IS_EEXIST(rc)) {
-                ACR_THROW(ACR_EX_EEXIST, 0);
-            }
-            else if (ACR_STATUS_IS_EACCES(rc)) {
-                ACR_THROW(ACR_EX_EACCES, 0);
-            }
-            else {
-                ACR_THROW(ACR_EX_ESYS, rc);
-            }
+            ACR_THROW_BY_ERRNO();
         }
     } DONE_WITH_STR(name);
 
@@ -97,16 +88,7 @@ ACR_WIN_EXPORT(jlong, WindowsSemaphore, 
     WITH_WSTR(name) {
         sp =  OpenSemaphoreW(READ_CONTROL | SEMAPHORE_MODIFY_STATE, FALSE, J2S(name));
         if (sp == 0) {
-            int rc = ACR_GET_OS_ERROR();
-            if (ACR_STATUS_IS_ENOENT(rc)) {
-                ACR_THROW(ACR_EX_ENOENT, 0);
-            }
-            else if (ACR_STATUS_IS_EACCES(rc)) {
-                ACR_THROW(ACR_EX_EACCES, 0);
-            }
-            else {
-                ACR_THROW(ACR_EX_ESYS, rc);
-            }
+            ACR_THROW_BY_ERRNO();
         }
     } DONE_WITH_STR(name);
 

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/util.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/util.c?rev=1094225&r1=1094224&r2=1094225&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/util.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/util.c Mon Apr 18 04:29:31 2011
@@ -106,7 +106,7 @@ int
 AcrLoadLateDLLs()
 {
     SYSDLL_TOKEN idx = SYSDLL_KERNEL32;
-    
+
     for (idx = SYSDLL_KERNEL32; idx < SYSDLL_DEFINED; idx++) {
         if (AcrGetLateDLL(idx) == 0 && (idx < SYSDLL_JVM)) {
             /* Unable to load required library

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/winapi.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/winapi.c?rev=1094225&r1=1094224&r2=1094225&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/winapi.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/winapi.c Mon Apr 18 04:29:31 2011
@@ -17,6 +17,7 @@
 #include "acr/string.h"
 #include "acr/debug.h"
 #include "acr/memory.h"
+#include "acr/jniapi.h"
 #include "acr/port.h"
 #include "acr/clazz.h"
 #include "acr/misc.h"
@@ -89,13 +90,16 @@ ACR_WIN_EXPORT(jlong, Win32, GetNullDacl
     PSECURITY_ATTRIBUTES pSA = GetSaWithNullDacl(env, JNI_FALSE);
     if (pSA != 0)
         return P2J(pSA->lpSecurityDescriptor);
-    else
+    else {
+        ACR_SAVE_OS_ERROR();
         return 0;
+    }
 }
 
 ACR_WIN_EXPORT(jlong, Win32, GetSaWithNullDacl)(JNI_STDARGS, jboolean inherit)
 {
-    return P2J(GetSaWithNullDacl(env, inherit));
+    PSECURITY_ATTRIBUTES pSA = GetSaWithNullDacl(env, inherit);
+    return P2J(pSA);
 }
 
 ACR_WIN_EXPORT(jlong, Win32, ConvertStringSecurityDescriptorToSecurityDescriptor)
@@ -105,7 +109,8 @@ ACR_WIN_EXPORT(jlong, Win32, ConvertStri
 
     WITH_WSTR(desc) {
         if (!ConvertStringSecurityDescriptorToSecurityDescriptorW(J2S(desc), rev, &pSD, 0)) {
-            ACR_THROW_SYS_ERROR();
+            ACR_SAVE_OS_ERROR();
+            pSD = 0;
         }
     } DONE_WITH_STR(desc);
 
@@ -133,11 +138,17 @@ ACR_WIN_EXPORT(jlong, Win32, GetCurrentP
 
     if (!OpenProcessToken(GetCurrentProcess(),
                           MAXIMUM_ALLOWED,
-                          &ptoken))
+                          &ptoken)) {
+        ACR_SAVE_OS_ERROR();
         return 0;
-    if (!DuplicateTokenEx(ptoken, MAXIMUM_ALLOWED, GetSaWithNullDacl(env, JNI_FALSE),
-                          SecurityIdentification, TokenPrimary,
+    }
+    if (!DuplicateTokenEx(ptoken,
+                          MAXIMUM_ALLOWED,
+                          GetSaWithNullDacl(env, JNI_FALSE),
+                          SecurityIdentification,
+                          TokenPrimary,
                           &dtoken)) {
+        ACR_SAVE_OS_ERROR();
         return 0;
     }
     CloseHandle(ptoken);
@@ -154,13 +165,13 @@ ACR_WIN_EXPORT(jlong, Win32, AllocateWel
         return 0;
     }
     if (!CreateWellKnownSid(type, 0, sid, &ss)) {
+        ACR_SAVE_OS_ERROR();
         AcrFree(sid);
         sid = 0;
     }
     return P2J(sid);
 }
 
-
 ACR_WIN_EXPORT(jint, Win32, WaitForSingleObject)(JNI_STDARGS, jlong handle, jint timeout)
 {
     DWORD ws = WaitForSingleObject(J2P(handle, HANDLE), (DWORD)timeout);

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/array.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/array.c?rev=1094225&r1=1094224&r2=1094225&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/array.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/array.c Mon Apr 18 04:29:31 2011
@@ -52,7 +52,7 @@ ACR_UTIL_EXPORT(jboolean, Array, memcpy0
     if (dcp == 0) {
         (*env)->ReleasePrimitiveArrayCritical(env, src, scp, 0);
         return JNI_FALSE;
-    }        
+    }
     memmove(dcp + (size_t)dstOff,
             scp + (size_t)srcOff, (size_t)nbytes);
     (*env)->ReleasePrimitiveArrayCritical(env, src, scp, 0);
@@ -147,7 +147,7 @@ ACR_UTIL_EXPORT(jint, Array, memcmp0)(JN
     dcp = (*env)->GetPrimitiveArrayCritical(env, dst, 0);
     if (dcp == 0) {
         (*env)->ReleasePrimitiveArrayCritical(env, src, scp, 0);
-        return -1;        
+        return -1;
     }
     rv = memcmp(dcp + (size_t)dstOff,
                 scp + (size_t)srcOff, (size_t)nbytes);

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/error.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/error.c?rev=1094225&r1=1094224&r2=1094225&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/error.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/error.c Mon Apr 18 04:29:31 2011
@@ -748,6 +748,126 @@ AcrReleaseExceptionClasses(JNI_STDENV)
     }
 }
 
+void
+AcrThrowByStatus(JNI_STDENV, int err, const char *msg)
+{
+    int cls = ACR_EX_ESYS;
+
+    if (ACR_STATUS_IS_EEXIST(err))
+        cls = ACR_EX_EEXIST;
+    else if (ACR_STATUS_IS_EEXIST(ENOENT))
+        cls = ACR_EX_ENOENT;
+    else if (ACR_STATUS_IS_EACCES(EACCES))
+        cls = ACR_EX_EACCES;
+    else if (ACR_STATUS_IS_EACCES(ENOMEM))
+        cls = ACR_EX_ENOMEM;
+    else if (ACR_STATUS_IS_EACCES(EINVAL))
+        cls = ACR_EX_EINVAL;
+    else if (err == ENOSYS)
+        cls = ACR_EX_ENOTIMPL;
+    AcrThrow(env, cls, msg);
+}
+
+ACR_JNI_EXPORT(void, io_Status, init0)(JNI_STDARGS, jintArray ra)
+{
+    jint i[92];
+
+    i[0]  = ACR_OS_LAST_CANONERR - ACR_OS_START_CANONERR;
+    i[1]  = ACR_EPERM;
+    i[2]  = ACR_ENOENT;
+    i[3]  = ACR_ESRCH;
+    i[4]  = ACR_EINTR;
+    i[5]  = ACR_EIO;
+    i[6]  = ACR_ENXIO;
+    i[7]  = ACR_E2BIG;
+    i[8]  = ACR_ENOEXEC;
+    i[9]  = ACR_EBADF;
+    i[10] = ACR_ECHILD;
+    i[11] = ACR_EDEADLK;
+    i[12] = ACR_ENOMEM;
+    i[13] = ACR_EACCES;
+    i[14] = ACR_EFAULT;
+    i[15] = ACR_ENOTBLK;
+    i[16] = ACR_EBUSY;
+    i[17] = ACR_EEXIST;
+    i[18] = ACR_EXDEV;
+    i[19] = ACR_ENODEV;
+    i[20] = ACR_ENOTDIR;
+    i[21] = ACR_EISDIR;
+    i[22] = ACR_EINVAL;
+    i[23] = ACR_ENFILE;
+    i[24] = ACR_EMFILE;
+    i[25] = ACR_ENOTTY;
+    i[26] = ACR_ETXTBSY;
+    i[27] = ACR_EFBIG;
+    i[28] = ACR_ENOSPC;
+    i[29] = ACR_ESPIPE;
+    i[30] = ACR_EROFS;
+    i[31] = ACR_EMLINK;
+    i[32] = ACR_EPIPE;
+    i[33] = ACR_EDOM;
+    i[34] = ACR_ERANGE;
+    i[35] = ACR_EAGAIN;
+    i[36] = ACR_EWOULDBLOCK;
+    i[37] = ACR_EINPROGRESS;
+    i[38] = ACR_EALREADY;
+    i[39] = ACR_ENOTSOCK;
+    i[40] = ACR_EDESTADDRREQ;
+    i[41] = ACR_EMSGSIZE;
+    i[42] = ACR_EPROTOTYPE;
+    i[43] = ACR_ENOPROTOOPT;
+    i[44] = ACR_EPROTONOSUPPORT;
+    i[45] = ACR_ESOCKTNOSUPPORT;
+    i[46] = ACR_EOPNOTSUPP;
+    i[47] = ACR_EPFNOSUPPORT;
+    i[48] = ACR_EAFNOSUPPORT;
+    i[49] = ACR_EADDRINUSE;
+    i[50] = ACR_EADDRNOTAVAIL;
+    i[51] = ACR_ENETDOWN;
+    i[52] = ACR_ENETUNREACH;
+    i[53] = ACR_ENETRESET;
+    i[54] = ACR_ECONNABORTED;
+    i[55] = ACR_ECONNRESET;
+    i[56] = ACR_ENOBUFS;
+    i[57] = ACR_EISCONN;
+    i[58] = ACR_ENOTCONN;
+    i[59] = ACR_ESHUTDOWN;
+    i[60] = ACR_ETOOMANYREFS;
+    i[61] = ACR_ETIMEDOUT;
+    i[62] = ACR_ECONNREFUSED;
+    i[63] = ACR_ELOOP;
+    i[64] = ACR_ENAMETOOLONG;
+    i[65] = ACR_EHOSTDOWN;
+    i[66] = ACR_EHOSTUNREACH;
+    i[67] = ACR_ENOTEMPTY;
+    i[68] = ACR_EPROCLIM;
+    i[69] = ACR_EUSERS;
+    i[70] = ACR_EDQUOT;
+    i[71] = ACR_ESTALE;
+    i[72] = ACR_EREMOTE;
+    i[73] = ACR_EBADRPC;
+    i[74] = ACR_ERPCMISMATCH;
+    i[75] = ACR_EPROGUNAVAIL;
+    i[76] = ACR_EPROGMISMATCH;
+    i[77] = ACR_EPROCUNAVAIL;
+    i[78] = ACR_ENOLCK;
+    i[79] = ACR_ENOSYS;
+    i[80] = ACR_EFTYPE;
+    i[81] = ACR_EAUTH;
+    i[82] = ACR_ENEEDAUTH;
+    i[83] = ACR_EIPSEC;
+    i[84] = ACR_ENOATTR;
+    i[85] = ACR_EILSEQ;
+    i[86] = ACR_ENOMEDIUM;
+    i[87] = ACR_EMEDIUMTYPE;
+    i[88] = ACR_EOVERFLOW;
+    i[89] = ACR_ECANCELED;
+    i[90] = ACR_EIDRM;
+    i[91] = ACR_ENOMSG;
+
+    (*env)->SetIntArrayRegion(env, ra, 0, 92, i);
+}
+
 ACR_JNI_EXPORT(jstring, Status, describe)(JNI_STDARGS, jint err)
 {
     char buf[ACR_MBUFF_SIZ] = "";
@@ -761,19 +881,44 @@ ACR_JNI_EXPORT(jboolean, Status, is0)(JN
     jboolean rv = JNI_FALSE;
     switch (what) {
         case 0:
-            if (ACR_STATUS_IS_EACCES(err)) rv = JNI_TRUE;
+            if (ACR_STATUS_IS_EACCES(err))
+                rv = JNI_TRUE;
         break;
         case 1:
-            if (ACR_STATUS_IS_EEXIST(err)) rv = JNI_TRUE;
+            if (ACR_STATUS_IS_EEXIST(err))
+                rv = JNI_TRUE;
         break;
         case 2:
-            if (ACR_STATUS_IS_ENOENT(err)) rv = JNI_TRUE;
+            if (ACR_STATUS_IS_ENOENT(err))
+                rv = JNI_TRUE;
         break;
         case 3:
-            if (ACR_STATUS_IS_EBUSY(err))  rv = JNI_TRUE;
+            if (ACR_STATUS_IS_EBUSY(err))
+                rv = JNI_TRUE;
+        break;
+        case 4:
+            if (ACR_STATUS_IS_ENOMEM(err))
+                rv = JNI_TRUE;
+        break;
+        case 5:
+            if (ACR_STATUS_IS_EINVAL(err))
+                rv = JNI_TRUE;
+        break;
+        case 6:
+            if (ACR_STATUS_IS_EAGAIN(err))
+                rv = JNI_TRUE;
+        break;
+        case 7:
+            if (ACR_STATUS_IS_TIMEUP(err))
+                rv = JNI_TRUE;
         break;
         default:
         break;
     }
     return rv;
 }
+
+ACR_JNI_EXPORT(jint, Status, errno)(JNI_STDARGS)
+{
+    return AcrGetThreadError();
+}

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=1094225&r1=1094224&r2=1094225&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/memory.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/memory.c Mon Apr 18 04:29:31 2011
@@ -266,7 +266,7 @@ ACR_JNI_EXPORT(jobject, Memory, malloc)(
             free(mem);
     }
     else {
-        ACR_THROW(ACR_EX_ENOMEM, 0);        
+        ACR_THROW(ACR_EX_ENOMEM, 0);
     }
     return ptr;
 }
@@ -290,7 +290,7 @@ ACR_JNI_EXPORT(jobject, Memory, calloc)(
             free(mem);
     }
     else {
-        ACR_THROW(ACR_EX_ENOMEM, 0);        
+        ACR_THROW(ACR_EX_ENOMEM, 0);
     }
     return ptr;
 }

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/native.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/native.c?rev=1094225&r1=1094224&r2=1094225&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/native.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/native.c Mon Apr 18 04:29:31 2011
@@ -40,7 +40,7 @@ ACR_JNI_EXPORT(jboolean, Native, init0)(
 ACR_JNI_EXPORT(void, Native, fini0)(JNI_STDARGS)
 {
     if (_loaded) {
-        _loaded = JNI_FALSE;    
+        _loaded = JNI_FALSE;
     }
 }
 

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/pointer.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/pointer.c?rev=1094225&r1=1094224&r2=1094225&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/pointer.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/pointer.c Mon Apr 18 04:29:31 2011
@@ -106,7 +106,7 @@ AcrGetPointer(JNI_STDARGS)
         if (oa != 0) {
             char *pa = oa + UNSAFE_FLD_OFF(0000);
             return J2P(*((jlong *)pa), void *);
-        }        
+        }
     }
     /* Fallback to a traditional method.
      */
@@ -126,7 +126,7 @@ AcrSetPointer(JNI_STDARGS, void *val)
             char *pa = oa + UNSAFE_FLD_OFF(0000);
             *((jlong *)pa) = P2J(val);
             return 0;
-        }        
+        }
     }
     /* Fallback to a traditional method.
      */
@@ -149,7 +149,7 @@ AcrSetPointerEx(JNI_STDARGS, void *val, 
             pa = oa + UNSAFE_FLD_OFF(0001);
             *((jlong *)pa) = P2J(len);
             return 0;
-        }        
+        }
     }
     /* Fallback to a traditional method.
      */