41 private const int SIGINT = 2;
42 private const int SIGILL = 4;
43 private const int SIGFPE = 8;
44 private const int SIGSEGV = 11;
45 private const int SIGTERM = 15;
46 private const int SIGBREAK = 21;
47 private const int SIGABRT = 22;
49 private static Dictionary<int, long> handler =
new Dictionary<int, long>();
52 private delegate Boolean ConsoleCtrlDelegate(CtrlTypes CtrlType);
55 private enum CtrlTypes : uint
60 CTRL_LOGOFF_EVENT = 5,
65 private sealed class CriticalCtrlHandler : CriticalFinalizerObject
67 private ConsoleCtrlDelegate consoleCtrlDelegate;
70 [DllImport(
"kernel32.dll")]
71 private static extern bool SetConsoleCtrlHandler(ConsoleCtrlDelegate e,
bool add);
73 internal CriticalCtrlHandler()
75 consoleCtrlDelegate =
new ConsoleCtrlDelegate(ConsoleCtrlCheck);
76 ok = SetConsoleCtrlHandler(consoleCtrlDelegate,
true);
79 [SecuritySafeCritical]
80 ~CriticalCtrlHandler()
84 SetConsoleCtrlHandler(consoleCtrlDelegate,
false);
89 private static object defaultConsoleCtrlDelegate;
91 private static bool ConsoleCtrlCheck(CtrlTypes ctrlType)
96 case CtrlTypes.CTRL_BREAK_EVENT:
107 private static void DumpAllJavaThreads()
109 Console.WriteLine(DateTime.Now.ToString(
"yyyy-MM-dd HH:mm:ss"));
110 global::java.util.Map traces = global::java.lang.Thread.getAllStackTraces();
111 Console.WriteLine(
"Full thread dump IKVM.NET {0} ({1} bit):",
Assembly.GetExecutingAssembly().GetName().Version, IntPtr.Size * 8);
112 global::java.util.Iterator entries = traces.entrySet().iterator();
113 while (entries.hasNext())
115 global::java.util.Map.Entry entry = (global::java.util.Map.Entry)entries.next();
116 global::java.lang.Thread thread = (global::java.lang.Thread)entry.getKey();
117 Console.WriteLine(
"\n\"{0}\"{1} prio={2} tid=0x{3:X8}", thread.getName(), thread.isDaemon() ?
" daemon" :
"", thread.getPriority(), thread.getId());
118 Console.WriteLine(
" java.lang.Thread.State: " + thread.getState());
119 global::java.lang.StackTraceElement[] trace = (global::java.lang.StackTraceElement[])entry.getValue();
120 for (
int i = 0; i < trace.Length; i++)
122 Console.WriteLine(
"\tat {0}", trace[i]);
132 if (Environment.OSVersion.Platform == PlatformID.Win32NT)
156 [SecuritySafeCritical]
157 private static void RegisterCriticalCtrlHandler()
159 defaultConsoleCtrlDelegate =
new CriticalCtrlHandler();
163 public static long handle0(
int sig,
long nativeH)
166 handler.TryGetValue(sig, out oldHandler);
170 if (defaultConsoleCtrlDelegate ==
null && Environment.OSVersion.Platform == PlatformID.Win32NT)
174 RegisterCriticalCtrlHandler();
176 catch (SecurityException)
192 handler[sig] = nativeH;
199 global::java.security.AccessController.doPrivileged(global::ikvm.runtime.Delegates.toPrivilegedAction(delegate
201 global::java.lang.Class clazz = typeof(global::sun.misc.Signal);
202 global::java.lang.reflect.Method dispatch = clazz.getDeclaredMethod(
"dispatch", global::java.lang.Integer.TYPE);
203 dispatch.setAccessible(true);
204 dispatch.invoke(null, global::java.lang.Integer.valueOf(sig));