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 2009/09/15 19:38:51 UTC
svn commit: r815409 - in /commons/sandbox/runtime/trunk/src/main/native:
os/win32/main.c os/win32/signals.c test/testsuite.c
Author: mturk
Date: Tue Sep 15 17:38:51 2009
New Revision: 815409
URL: http://svn.apache.org/viewvc?rev=815409&view=rev
Log:
Extend default signal handler
Modified:
commons/sandbox/runtime/trunk/src/main/native/os/win32/main.c
commons/sandbox/runtime/trunk/src/main/native/os/win32/signals.c
commons/sandbox/runtime/trunk/src/main/native/test/testsuite.c
Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/main.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/main.c?rev=815409&r1=815408&r2=815409&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/main.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/main.c Tue Sep 15 17:38:51 2009
@@ -170,7 +170,7 @@
NULL, NULL, NULL, NULL, NULL
};
-FARPROC acr_load_dll_func(acr_dlltoken_e fnLib, const char* fnName, int ordinal)
+FARPROC acr_load_dll_func(acr_dlltoken_e fnLib, const char* fnName, int undec)
{
FARPROC fp = NULL;
if (!late_dll_handles[fnLib]) {
@@ -185,10 +185,18 @@
if (!late_dll_handles[fnLib])
return NULL;
}
- if (ordinal)
- fp = GetProcAddress(late_dll_handles[fnLib],
- (const char *)0 + (((acr_ptr_t)ordinal) & 0xFFFF));
- if (fp == NULL && fnName) {
+ if (undec) {
+ char name[256];
+ sprintf(name, "_%s@%d", fnName, undec);
+ fp = GetProcAddress(late_dll_handles[fnLib], name);
+ if (!fp) {
+ /* Try with double stack size
+ */
+ sprintf(name, "_%s@%d", fnName, undec * 2);
+ fp = GetProcAddress(late_dll_handles[fnLib], name);
+ }
+ }
+ if (fp == NULL) {
/* Try function name if ordinal failed */
fp = GetProcAddress(late_dll_handles[fnLib], fnName);
}
Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/signals.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/signals.c?rev=815409&r1=815408&r2=815409&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/signals.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/signals.c Tue Sep 15 17:38:51 2009
@@ -25,6 +25,7 @@
#include "acr.h"
#include "acr_private.h"
+#define ACR_WANT_LATE_DLL
#include "acr_arch.h"
#include "acr_port.h"
#include "acr_clazz.h"
@@ -64,6 +65,7 @@
static HANDLE sig_pipe_handle = INVALID_HANDLE_VALUE;
static wchar_t sig_pipe_name[64];
static BYTE sig_pipe_salt[ACR_SHA1_DIGEST_LENGTH];
+static DWORD proc_priority_class = NORMAL_PRIORITY_CLASS;
typedef struct sig_pipe_data_t {
OVERLAPPED ctx;
@@ -133,10 +135,47 @@
static void default_signal_handler(int sig)
{
JNIEnv *_E;
+ DWORD dw;
switch (sig) {
+ case SIGSTOP:
+ dw = GetPriorityClass(GetCurrentProcess());
+ if (dw != IDLE_PRIORITY_CLASS) {
+ proc_priority_class = dw;
+ /* Not really a stop but as close as we can get
+ * Since MSDN says it will work during idle time
+ * on busy system this should be as close to the stopped
+ * as it can be
+ */
+ SetPriorityClass(GetCurrentProcess(), IDLE_PRIORITY_CLASS);
+ }
+#if defined(DEBUG)
+ else {
+ fprintf(stdout, "[native] Already susspended from 0x%08X\n",
+ proc_priority_class);
+ fflush(stdout);
+
+ }
+#endif
+ break;
+ case SIGCONT:
+ dw = GetPriorityClass(GetCurrentProcess());
+ if (dw == IDLE_PRIORITY_CLASS)
+ SetPriorityClass(GetCurrentProcess(), proc_priority_class);
+ else
+ proc_priority_class = dw;
+ break;
+ case SIGABRT:
+#if defined(_MSC_VER) && (_MSC_VER >= 1400)
+ /* Visual C++ 2005 and later
+ */
+ _set_abort_behavior(0, _WRITE_ABORT_MSG);
+#endif
+ abort();
+ break;
+ case SIGTERM:
case SIGKILL:
- /* Call the System.exit(9)
+ /* Call the System.exit()
*/
if (ACR_SystemExit(NULL, sig)) {
/* System.exit failed, calll the _exit so we
@@ -145,8 +184,6 @@
_exit(sig);
}
break;
- case SIGTERM:
- break;
case SIGBUS:
case SIGSEGV:
_E = ACR_GetJNIEnv();
@@ -160,6 +197,18 @@
ExitProcess(sig);
}
break;
+ case SIGQUIT:
+ _E = ACR_GetJNIEnv();
+ if (IS_VALID_HANDLE(_E)) {
+ JVM_DumpAllStacks(_E, NULL);
+ }
+ else {
+ fprintf(stderr, "[native] Missing JNIEnv - %s\n", strsignal(sig));
+ fprintf(stderr, "[native] Terminating ...\n");
+ fflush(stderr);
+ ExitProcess(sig);
+ }
+ break;
default:
/* Do nothing */
#if defined(DEBUG)
@@ -185,10 +234,15 @@
switch (sig) {
case CTRL_C_EVENT:
- posix_signal = SIGINT;
+ /* CTRL+C by default exits the process
+ */
+ posix_signal = SIGTERM;
break;
case CTRL_BREAK_EVENT:
- posix_signal = SIGINT;
+ /* This is to simulate kill -3
+ * and get the thread dump
+ */
+ posix_signal = SIGQUIT;
break;
case CTRL_CLOSE_EVENT:
/* If interactive process this happens on close console.
@@ -471,6 +525,9 @@
running = 0;
return rc;
}
+ sigemptyset(¤t_signal_queue);
+ sigemptyset(¤t_signal_mask);
+
/*
* Create a simple unnamed signaling event.
* We use auto-reset event meaning that if multiple
@@ -500,18 +557,19 @@
for (i = 0; i < ACR_NUMSIG; i++)
signal_handlers[i] = SIG_IGN;
- signal_handlers[SIGBUS] = default_signal_handler;
- signal_handlers[SIGSEGV] = default_signal_handler;
- signal_handlers[SIGKILL] = default_signal_handler;
+ signal_handlers[SIGABRT] = SIG_DFL;
+ signal_handlers[SIGBUS] = SIG_DFL;
+ signal_handlers[SIGSEGV] = SIG_DFL;
+ signal_handlers[SIGKILL] = SIG_DFL;
+ signal_handlers[SIGSTOP] = SIG_DFL;
+ signal_handlers[SIGCONT] = SIG_DFL;
+
/* Default handlers for console events.
*/
-#if defined(DEBUG)
- signal_handlers[SIGINT] = default_signal_handler;
-#else
+ signal_handlers[SIGHUP] = SIG_DFL;
signal_handlers[SIGINT] = SIG_DFL;
-#endif
+ signal_handlers[SIGQUIT] = SIG_DFL;
signal_handlers[SIGTERM] = SIG_DFL;
- signal_handlers[SIGHUP] = SIG_DFL;
memset(sig_pipe_salt, 0, sizeof(sig_pipe_salt));
/* Get the global signal pipe name.
@@ -573,7 +631,6 @@
SIG_PF sig = signal_handlers[i];
switch (i) {
case SIGKILL:
- case SIGQUIT:
case SIGTERM:
rc = ACR_INCOMPLETE;
break;
@@ -586,14 +643,13 @@
sigdelset(¤t_signal_queue, i);
if (sig != SIG_IGN && sig != SIG_ERR) {
LeaveCriticalSection(&signal_lock);
- if (sig != SIG_DFL) {
- (*sig)(i);
+ if (sig == SIG_DFL) {
+ default_signal_handler(i);
}
else {
- /* TODO: Handle defaults
+ /* ###: Can we have SIG_ACK and others here ?
*/
-
-
+ (*sig)(i);
}
EnterCriticalSection(&signal_lock);
break;
@@ -603,6 +659,9 @@
break;
}
}
+ /* Empty queue in case we break before
+ * handling all events
+ */
sigemptyset(¤t_signal_queue);
LeaveCriticalSection(&signal_lock);
Modified: commons/sandbox/runtime/trunk/src/main/native/test/testsuite.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/test/testsuite.c?rev=815409&r1=815408&r2=815409&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/test/testsuite.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/test/testsuite.c Tue Sep 15 17:38:51 2009
@@ -542,9 +542,12 @@
ppid = atoi(argv[0]);
if (ppid == 0)
return ACR_EINVAL;
- rc = ACR_RaiseSignal(NULL, SIGINT, ppid);
- rc = ACR_RaiseSignal(NULL, SIGINT, ppid);
- rc = ACR_RaiseSignal(NULL, SIGBUS, ppid);
+ rc = ACR_RaiseSignal(NULL, SIGINT, ppid);
+ rc = ACR_RaiseSignal(NULL, SIGSTOP, ppid);
+ rc = ACR_RaiseSignal(NULL, SIGSTOP, ppid);
+ rc = ACR_RaiseSignal(NULL, SIGCONT, ppid);
+ rc = ACR_RaiseSignal(NULL, SIGQUIT, ppid);
+ rc = ACR_RaiseSignal(NULL, SIGBUS, ppid);
if (rc) {
char buf[256];
fprintf(stderr, ACR_GetErrorString(rc, buf, sizeof(buf)));