Author: mturk Date: Wed Jun 17 07:15:23 2009 New Revision: 785489 URL: http://svn.apache.org/viewvc?rev=785489&view=rev Log: Add exception handling, so we don't crash the JVM is we write to invalid memory location
Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Native.java commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/File.java 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/shared/error.c commons/sandbox/runtime/trunk/src/main/native/shared/native.c commons/sandbox/runtime/trunk/src/main/native/test/testcase.c commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Native.java URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Native.java?rev=785489&r1=785488&r2=785489&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Native.java (original) +++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Native.java Wed Jun 17 07:15:23 2009 @@ -34,6 +34,7 @@ private static boolean initialized = false; private static native boolean init0() throws Throwable; + private static native void sseh0(boolean on); /** * Initialize Apache Commons Runtime native library. @@ -60,4 +61,17 @@ } return initialized; } + + public static void enableExceptionHandler() + throws Throwable + { + sseh0(true); + } + + public static void disableExceptionHandler() + throws Throwable + { + sseh0(false); + } + } Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/File.java URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/File.java?rev=785489&r1=785488&r2=785489&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/File.java (original) +++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/File.java Wed Jun 17 07:15:23 2009 @@ -54,7 +54,7 @@ private static native boolean attrs0(String pathname, int attr, int mask) throws IOException, SecurityException; - // Catched FileType Enum integer value. + // Cached FileType Enum integer value. private int fileType = -1; /* Private constructor used from native code @@ -264,9 +264,7 @@ { if (fileType < 0) fileType = ftype0(getPath()); - // XXX: The value should be obtained directly from - // FileType Enum. - return fileType == 6; + return fileType == FileType.LNK.valueOf(); } /** @@ -352,7 +350,7 @@ // Check is made wather it points to the same target mkslink0(getPath(), link); if (getPath().equals(target0(link))) { - return new File(link, 6); + return new File(link, FileType.LNK.valueOf()); } else { throw new IOException("Symlink exists and points to a different path"); Modified: commons/sandbox/runtime/trunk/src/main/native/configure URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/configure?rev=785489&r1=785488&r2=785489&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/configure (original) +++ commons/sandbox/runtime/trunk/src/main/native/configure Wed Jun 17 07:15:23 2009 @@ -504,23 +504,24 @@ echo $rc } -have_function() +have_function_body() { - printf "Checking for %-32s" "$1" 1>&2 cat > $test.c << EOF +#define $1 wrapper_$1 #ifdef __STDC__ #include <limits.h> #else #include <assert.h> #endif -char $1 (); +#undef $1 #if defined __stub_$1 || defined __stub___$1 choke me #endif -int main() { return (int) $1 ();} +char $1 (); +int main() { return $1 (); } EOF rc=0 - co="`$cc $ccflags $cppopts $test.c -o $test$exe 2>&1`" + co="`$cc $ccflags $cppopts $ldflags $test.c -o $test$exe 2>&1`" if [ ".$co" = "." ]; then rc=1 else @@ -529,6 +530,16 @@ fi fi rm -rf $test.* $test *.pdb >/dev/null 2>&1 || true + echo $rc +} + +have_function() +{ + printf "Checking for %-32s" "$1" 1>&2 + rc=`have_function_body $1 $2` + if [ $rc = 0 ]; then + rc=`have_function_body __$1 $2` + fi if [ $rc = 1 ]; then echo ok 1>&2 else @@ -576,7 +587,7 @@ int main() {printf("%d", sizeof($1));return 0;} EOF rc="" - $cc $ccflags $cppopts $test.c -o $test$exe >/dev/null 2>&1 + $cc $ccflags $cppopts $ldflags $test.c -o $test$exe >/dev/null 2>&1 if [ -x $test$exe ]; then rc=`./$test$exe 2>/dev/null` fi @@ -690,6 +701,7 @@ #define HAVE_ACCEPT4 `have_function accept4` #define HAVE_DUP3 `have_function dup3` #define HAVE_EPOLL_CREATE1 `have_function epoll_create1` +#define HAVE_SIGSETJMP `have_function sigsetjmp` #define HAVE_SOCK_CLOEXEC `have_sock_cloexec` #define HAVE_OFF64_T $have_off64t #define HAVE_LONG_LONG $have_long_long 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=785489&r1=785488&r2=785489&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 Wed Jun 17 07:15:23 2009 @@ -58,6 +58,78 @@ ACR_EX_LEN } acr_trowclass_e; +typedef enum { + ACR_SEH_NONE = 0, + ACR_SEH_CONTINUE, + ACR_SEH_THROW +} acr_seh_e; + +#ifdef ACR_WANT_MEMPROTECT +#ifdef _MSC_VER +#define SEH_ERROR GetExceptionCode() +#define ACR_TRY \ + int _seh_error = 0; \ + if (ACR_GetExceptionHandlerMode() != ACR_SEH_NONE) \ + _seh_error = 1; \ + __try { + +#define ACR_CATCH() \ + } __except(_seh_error ? EXCEPTION_EXECUTE_HANDLER : \ + EXCEPTION_CONTINUE_SEARCH) + +#else +#include <signal.h> +#include <setjmp.h> +#define SEH_ERROR _seh_error + +#if HAVE_SIGSETJMP +#define SEH_SETJMP(E) sigsetjmp((E), 0) +#define SEH_DOJUMP(E, V) siglongjmp((E), (V)) +#define SEH_JMPBUF sigjmp_buf +#else +#define SEH_SETJMP(E) setjmp((E)) +#define SEH_DOJUMP(E, V) longjmp((E), (V)) +#define SEH_JMPBUF jmp_buf +#endif +static SEH_JMPBUF _seh_catch; +static void _seh_handler(int val) +{ + if (val == SIGSEGV || val == SIGBUS) { + SEH_DOJUMP(_seh_catch, val); + } +} + +#define ACR_TRY \ + int _seh_error = 0; \ + { \ + void* _org_sigseg_handler = NULL; \ + void* _org_sigbus_handler = NULL; \ + int _org_setjmp_handler = 0; \ + if (ACR_GetExceptionHandlerMode() != ACR_SEH_NONE) { \ + _org_sigseg_handler = signal(SIGSEGV, _seh_handler); \ + _org_sigbus_handler = signal(SIGBUS, _seh_handler); \ + _org_setjmp_handler = 1; \ + if ((_seh_error = SEH_SETJMP(_seh_catch))) \ + goto _seh_catch_block; \ + } + +#define ACR_CATCH() \ +_seh_catch_block: \ + if (_org_setjmp_handler) { \ + signal(SIGSEGV, _org_sigseg_handler); \ + signal(SIGBUS, _org_sigbus_handler); \ + } } if (_seh_error) + +#endif +#else +#define ACR_TRY \ + int _seh_error = 0; \ + { \ +#define ACR_CATCH() \ + } } if (_seh_error) + +#endif /* HAVE_MEMPROTECT */ + /* * Convenience function to help throw any class * @param env JNI Environment @@ -111,7 +183,7 @@ /** * @defgroup apr_errno Error Codes - * @ingroup ACR + * @ingroup ACR * @{ */ @@ -121,9 +193,21 @@ * @param buf A buffer to hold the error string. * @param bufsize Size of the buffer to hold the string. */ -ACR_DECLARE(char *) ACR_GetErrorString(int statcode, char *buf, +ACR_DECLARE(char *) ACR_GetErrorString(int statcode, char *buf, acr_size_t bufsize); +/** + * Set internal memory protection exception handling mode. + * @param mode Exception handling mode. + */ +ACR_DECLARE(void) ACR_SetExceptionHandlerMode(acr_seh_e mode); + +/** + * Get the exception handling mode. + * @return Previously set exception handling mode. + */ +ACR_DECLARE(acr_seh_e) ACR_GetExceptionHandlerMode(void); + #if defined(DOXYGEN) /** * @def ACR_FROM_OS_ERROR(os_err_type syserr) @@ -141,7 +225,7 @@ * Fold an apr_status_t code back to the native platform defined error. * @param e The apr_status_t folded platform os error code. * @warning macro implementation; the statcode argument may be evaluated - * multiple times. If the statcode was not created by apr_get_os_error + * multiple times. If the statcode was not created by apr_get_os_error * or ACR_FROM_OS_ERROR, the results are undefined. */ #define ACR_TO_OS_ERROR(e) (e == 0 ? ACR_SUCCESS : e - ACR_OS_START_SYSERR) @@ -177,7 +261,7 @@ * @warning This is a macro implementation; the statcode argument may be evaluated * multiple times. If the statcode was not created by apr_get_os_error * or ACR_FROM_OS_ERROR, the results are undefined. This macro sets - * errno, or calls a WSASetLastError() style function, unfolding + * errno, or calls a WSASetLastError() style function, unfolding * socketcode with ACR_TO_OS_ERROR. */ @@ -186,13 +270,13 @@ /** * ACR_OS_START_ERROR is where the ACR specific error values start. */ -#define ACR_OS_START_ERROR 20000 +#define ACR_OS_START_ERROR 20000 /** * ACR_OS_ERRSPACE_SIZE is the maximum number of errors you can fit * into one of the error/status ranges below -- except for * ACR_OS_START_USERERR, which see. */ -#define ACR_OS_ERRSPACE_SIZE 50000 +#define ACR_OS_ERRSPACE_SIZE 50000 /** * ACR_UTIL_ERRSPACE_SIZE is the size of the space that is reserved for * use within apr-util. This space is reserved above that used by ACR @@ -201,7 +285,7 @@ * large enough amount that ACR has sufficient room for it's * codes. */ -#define ACR_UTIL_ERRSPACE_SIZE 20000 +#define ACR_UTIL_ERRSPACE_SIZE 20000 /** * ACR_OS_START_STATUS is where the ACR specific status codes start. */ @@ -221,7 +305,7 @@ * * In general applications should try and create unique error codes. To try * and assist in finding suitable ranges of numbers to use, the following - * ranges are known to be used by the listed applications. If your + * ranges are known to be used by the listed applications. If your * application defines error codes please advise the range of numbers it * uses to d...@apr.apache.org for inclusion in this list. * @@ -244,12 +328,12 @@ #define ACR_OS_START_CANONERR (ACR_OS_START_USERERR \ + (ACR_OS_ERRSPACE_SIZE * 10)) /** - * ACR_OS_START_EAIERR folds EAI_ error codes from getaddrinfo() into + * ACR_OS_START_EAIERR folds EAI_ error codes from getaddrinfo() into * apr_status_t values. */ #define ACR_OS_START_EAIERR (ACR_OS_START_CANONERR + ACR_OS_ERRSPACE_SIZE) /** - * ACR_OS_START_SYSERR folds platform-specific system error values into + * ACR_OS_START_SYSERR folds platform-specific system error values into * apr_status_t values. */ #define ACR_OS_START_SYSERR (ACR_OS_START_EAIERR + ACR_OS_ERRSPACE_SIZE) @@ -260,7 +344,7 @@ * The following attempts to show the relation of the various constants * used for mapping ACR Status codes. * - * 0 + * 0 * * 20,000 ACR_OS_START_ERROR * @@ -294,13 +378,13 @@ /** no error. */ #define ACR_SUCCESS 0 -/** +/** * @defgroup ACR_Error ACR Error Values * <PRE> * <b>ACR ERROR VALUES</b> - * ACR_ENOSTAT ACR was unable to perform a stat on the file + * ACR_ENOSTAT ACR was unable to perform a stat on the file * ACR_ENOPOOL ACR was not provided a pool with which to allocate memory - * ACR_EBADDATE ACR was given an invalid date + * ACR_EBADDATE ACR was given an invalid date * ACR_EINVALSOCK ACR was given an invalid socket * ACR_ENOPROC ACR was not given a process structure * ACR_ENOTIME ACR was not given a time structure @@ -311,7 +395,7 @@ * ACR_ENOTHREAD ACR was not given a thread structure * ACR_ENOTHDKEY ACR was not given a thread key structure * ACR_ENOSHMAVAIL There is no more shared memory available - * ACR_EDSOOPEN ACR was unable to open the dso object. For more + * ACR_EDSOOPEN ACR was unable to open the dso object. For more * information call apr_dso_error(). * ACR_EGENERAL General failure (specific information not available) * ACR_EBADIP The specified IP address is invalid @@ -332,17 +416,17 @@ * ACR_INCOMPLETE The operation was incomplete although some processing * was performed and the results are partially valid * ACR_BADCH Getopt found an option not in the option string - * ACR_BADARG Getopt found an option that is missing an argument + * ACR_BADARG Getopt found an option that is missing an argument * and an argument was specified in the option string * ACR_EOF ACR has encountered the end of the file * ACR_NOTFOUND ACR was unable to find the socket in the poll structure * ACR_ANONYMOUS ACR is using anonymous shared memory * ACR_FILEBASED ACR is using a file name as the key to the shared memory * ACR_KEYBASED ACR is using a shared key as the key to the shared memory - * ACR_EINIT Ininitalizer value. If no option has been found, but + * ACR_EINIT Ininitalizer value. If no option has been found, but * the status variable requires a value, this should be used - * ACR_ENOTIMPL The ACR function has not been implemented on this - * platform, either because nobody has gotten to it yet, + * ACR_ENOTIMPL The ACR function has not been implemented on this + * platform, either because nobody has gotten to it yet, * or the function is impossible on this platform. * ACR_EMISMATCH Two passwords do not match. * ACR_EABSOLUTE The given path was absolute. @@ -416,7 +500,7 @@ #define ACR_ERANGE (ACR_OS_START_ERROR + 102) #define ACR_ECLASSNOTFOUND (ACR_OS_START_ERROR + 103) -/** +/** * @defgroup ACR_STATUS_IS Status Value Tests * @warning For any particular error condition, more than one of these tests * may match. This is because platform-specific error codes may not @@ -427,16 +511,16 @@ * adjust the order of the tests accordingly. * @{ */ -/** - * ACR was unable to perform a stat on the file +/** + * ACR was unable to perform a stat on the file * @warning always use this test, as platform-specific variances may meet this - * more than one error code + * more than one error code */ #define ACR_STATUS_IS_ENOSTAT(s) ((s) == ACR_ENOSTAT) -/** - * ACR was not provided a pool with which to allocate memory +/** + * ACR was not provided a pool with which to allocate memory * @warning always use this test, as platform-specific variances may meet this - * more than one error code + * more than one error code */ #define ACR_STATUS_IS_ENOPOOL(s) ((s) == ACR_ENOPOOL) /** ACR was given an invalid date */ @@ -468,8 +552,8 @@ /** The specified netmask is invalid */ #define ACR_STATUS_IS_EBADMASK(s) ((s) == ACR_EBADMASK) /* empty slot: +18 */ -/** - * ACR was unable to open the dso object. +/** + * ACR was unable to open the dso object. * For more information call apr_dso_error(). */ #if defined(WIN32) @@ -506,7 +590,7 @@ /** @} */ -/** +/** * @addtogroup ACR_Error * @{ */ @@ -547,7 +631,7 @@ /** @see ACR_STATUS_IS_KEYBASED */ #define ACR_KEYBASED (ACR_OS_START_STATUS + 21) /** @see ACR_STATUS_IS_EINIT */ -#define ACR_EINIT (ACR_OS_START_STATUS + 22) +#define ACR_EINIT (ACR_OS_START_STATUS + 22) /** @see ACR_STATUS_IS_ENOTIMPL */ #define ACR_ENOTIMPL (ACR_OS_START_STATUS + 23) /** @see ACR_STATUS_IS_EMISMATCH */ @@ -556,156 +640,156 @@ #define ACR_EBUSY (ACR_OS_START_STATUS + 25) /** @} */ -/** +/** * @addtogroup ACR_STATUS_IS * @{ */ -/** - * Program is currently executing in the child +/** + * Program is currently executing in the child * @warning * always use this test, as platform-specific variances may meet this * more than one error code */ #define ACR_STATUS_IS_INCHILD(s) ((s) == ACR_INCHILD) -/** - * Program is currently executing in the parent +/** + * Program is currently executing in the parent * @warning * always use this test, as platform-specific variances may meet this - * more than one error code + * more than one error code */ #define ACR_STATUS_IS_INPARENT(s) ((s) == ACR_INPARENT) -/** - * The thread is detached +/** + * The thread is detached * @warning * always use this test, as platform-specific variances may meet this - * more than one error code + * more than one error code */ #define ACR_STATUS_IS_DETACH(s) ((s) == ACR_DETACH) -/** - * The thread is not detached +/** + * The thread is not detached * @warning * always use this test, as platform-specific variances may meet this - * more than one error code + * more than one error code */ #define ACR_STATUS_IS_NOTDETACH(s) ((s) == ACR_NOTDETACH) -/** +/** * The child has finished executing * @warning * always use this test, as platform-specific variances may meet this - * more than one error code + * more than one error code */ #define ACR_STATUS_IS_CHILD_DONE(s) ((s) == ACR_CHILD_DONE) -/** +/** * The child has not finished executing * @warning * always use this test, as platform-specific variances may meet this - * more than one error code + * more than one error code */ #define ACR_STATUS_IS_CHILD_NOTDONE(s) ((s) == ACR_CHILD_NOTDONE) -/** +/** * The operation did not finish before the timeout * @warning * always use this test, as platform-specific variances may meet this - * more than one error code + * more than one error code */ #define ACR_STATUS_IS_TIMEUP(s) ((s) == ACR_TIMEUP) -/** +/** * The operation was incomplete although some processing was performed * and the results are partially valid. * @warning * always use this test, as platform-specific variances may meet this - * more than one error code + * more than one error code */ #define ACR_STATUS_IS_INCOMPLETE(s) ((s) == ACR_INCOMPLETE) /* empty slot: +9 */ /* empty slot: +10 */ /* empty slot: +11 */ -/** +/** * Getopt found an option not in the option string * @warning * always use this test, as platform-specific variances may meet this - * more than one error code + * more than one error code */ #define ACR_STATUS_IS_BADCH(s) ((s) == ACR_BADCH) -/** - * Getopt found an option not in the option string and an argument was +/** + * Getopt found an option not in the option string and an argument was * specified in the option string * @warning * always use this test, as platform-specific variances may meet this - * more than one error code + * more than one error code */ #define ACR_STATUS_IS_BADARG(s) ((s) == ACR_BADARG) -/** +/** * ACR has encountered the end of the file * @warning * always use this test, as platform-specific variances may meet this - * more than one error code + * more than one error code */ #define ACR_STATUS_IS_EOF(s) ((s) == ACR_EOF) -/** +/** * ACR was unable to find the socket in the poll structure * @warning * always use this test, as platform-specific variances may meet this - * more than one error code + * more than one error code */ #define ACR_STATUS_IS_NOTFOUND(s) ((s) == ACR_NOTFOUND) /* empty slot: +16 */ /* empty slot: +17 */ /* empty slot: +18 */ -/** +/** * ACR is using anonymous shared memory * @warning * always use this test, as platform-specific variances may meet this - * more than one error code + * more than one error code */ #define ACR_STATUS_IS_ANONYMOUS(s) ((s) == ACR_ANONYMOUS) -/** +/** * ACR is using a file name as the key to the shared memory * @warning * always use this test, as platform-specific variances may meet this - * more than one error code + * more than one error code */ #define ACR_STATUS_IS_FILEBASED(s) ((s) == ACR_FILEBASED) -/** +/** * ACR is using a shared key as the key to the shared memory * @warning * always use this test, as platform-specific variances may meet this - * more than one error code + * more than one error code */ #define ACR_STATUS_IS_KEYBASED(s) ((s) == ACR_KEYBASED) -/** - * Ininitalizer value. If no option has been found, but +/** + * Ininitalizer value. If no option has been found, but * the status variable requires a value, this should be used * @warning * always use this test, as platform-specific variances may meet this - * more than one error code + * more than one error code */ #define ACR_STATUS_IS_EINIT(s) ((s) == ACR_EINIT) -/** - * The ACR function has not been implemented on this - * platform, either because nobody has gotten to it yet, +/** + * The ACR function has not been implemented on this + * platform, either because nobody has gotten to it yet, * or the function is impossible on this platform. * @warning * always use this test, as platform-specific variances may meet this - * more than one error code + * more than one error code */ #define ACR_STATUS_IS_ENOTIMPL(s) ((s) == ACR_ENOTIMPL) -/** +/** * Two passwords do not match. * @warning * always use this test, as platform-specific variances may meet this - * more than one error code + * more than one error code */ #define ACR_STATUS_IS_EMISMATCH(s) ((s) == ACR_EMISMATCH) -/** +/** * The given lock was busy * @warning always use this test, as platform-specific variances may meet this - * more than one error code + * more than one error code */ #define ACR_STATUS_IS_EBUSY(s) ((s) == ACR_EBUSY) /** @} */ -/** +/** * @addtogroup ACR_Error ACR Error Values * @{ */ @@ -794,8 +878,8 @@ #define ACR_ESPIPE (ACR_OS_START_CANONERR + 12) #endif -/** - * @see ACR_STATUS_IS_EAGAIN +/** + * @see ACR_STATUS_IS_EAGAIN * @warning use ACR_STATUS_IS_EAGAIN instead of just testing this value */ #ifdef EAGAIN @@ -834,7 +918,7 @@ #define ACR_EINPROGRESS (ACR_OS_START_CANONERR + 17) #endif -/** +/** * @see ACR_STATUS_IS_ECONNABORTED * @warning use ACR_STATUS_IS_ECONNABORTED instead of just testing this value */ @@ -1031,7 +1115,7 @@ #define ACR_GET_NETOS_ERROR() (errno) #define ACR_SET_NETOS_ERROR(e) (errno = (e)) -/** +/** * @addtogroup ACR_STATUS_IS * @{ */ @@ -1095,15 +1179,15 @@ /** operation now in progress */ #define ACR_STATUS_IS_EINPROGRESS(s) ((s) == ACR_EINPROGRESS) -/** - * Software caused connection abort +/** + * Software caused connection abort * @remark - * EPROTO on certain older kernels really means ECONNABORTED, so we need to + * EPROTO on certain older kernels really means ECONNABORTED, so we need to * ignore it for them. See discussion in new-httpd archives nh.9701 & nh.9603 * - * There is potentially a bug in Solaris 2.x x<6, and other boxes that + * There is potentially a bug in Solaris 2.x x<6, and other boxes that * implement tcp sockets in userland (i.e. on top of STREAMS). On these - * systems, EPROTO can actually result in a fatal loop. See PR#981 for + * systems, EPROTO can actually result in a fatal loop. See PR#981 for * example. It's hard to handle both uses of EPROTO. */ #ifdef EPROTO 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=785489&r1=785488&r2=785489&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/shared/error.c (original) +++ commons/sandbox/runtime/trunk/src/main/native/shared/error.c Wed Jun 17 07:15:23 2009 @@ -44,6 +44,7 @@ NULL }; +static acr_seh_e acr_seh_mode = ACR_SEH_NONE; /* * Convenience function to help throw any class @@ -486,6 +487,16 @@ } } +ACR_DECLARE(void) ACR_SetExceptionHandlerMode(acr_seh_e mode) +{ + acr_seh_mode = mode; +} + +ACR_DECLARE(acr_seh_e) ACR_GetExceptionHandlerMode() +{ + return acr_seh_mode; +} + ACR_JNI_EXPORT_DECLARE(void, io_Status, init0)(ACR_JNISTDARGS, jintArray ra) { 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=785489&r1=785488&r2=785489&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/shared/native.c (original) +++ commons/sandbox/runtime/trunk/src/main/native/shared/native.c Wed Jun 17 07:15:23 2009 @@ -34,3 +34,8 @@ return rv; } + +ACR_JNI_EXPORT_DECLARE(void, Native, sseh0)(ACR_JNISTDARGS, jboolean on) +{ + ACR_SetExceptionHandlerMode(on ? ACR_SEH_THROW : ACR_SEH_NONE); +} Modified: commons/sandbox/runtime/trunk/src/main/native/test/testcase.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/test/testcase.c?rev=785489&r1=785488&r2=785489&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/test/testcase.c (original) +++ commons/sandbox/runtime/trunk/src/main/native/test/testcase.c Wed Jun 17 07:15:23 2009 @@ -17,6 +17,7 @@ #include "acr.h" #include "acr_private.h" #include "acr_arch.h" +#define ACR_WANT_MEMPROTECT #include "acr_error.h" #include "acr_string.h" #include "acr_memory.h" @@ -315,6 +316,16 @@ return ACR_IoFileObjectCreate(_E, _PTEXT("/tmp/foo"), -1); } +ACR_JNI_EXPORT_DECLARE(void, TestPrivate, test030)(ACR_JNISTDARGS, int d) +{ + ACR_TRY { + void *p = NULL; + memset(p, 1, 100); + } ACR_CATCH() { + ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ERUNTIME, EFAULT); + } +} + ACR_JNI_EXPORT_DECLARE(jint, TestFile, ftest00)(ACR_JNISTDARGS, jint d) { Modified: commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java?rev=785489&r1=785488&r2=785489&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java (original) +++ commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java Wed Jun 17 07:15:23 2009 @@ -79,6 +79,7 @@ private static native String test028(int d); private static native File test029(int d); + private static native void test030(int d); private static native String test100(String s); @@ -583,6 +584,19 @@ assertEquals("Name", "foo", f.getName()); } + public void testMempotect() + throws Throwable + { + Native.enableExceptionHandler(); + try { + test030(0); + fail("Exception not thrown"); + } catch (Throwable t) { + assertSame("Wrong Exception class", + java.lang.RuntimeException.class, t.getClass()); + } + } + public void testModuleSSL() throws Throwable {