/* * mini-posix.c: POSIX signal handling support for Mono. * * Authors: * Mono Team (mono-list@lists.ximian.com) * * Copyright 2001-2003 Ximian, Inc. * Copyright 2003-2008 Ximian, Inc. * * See LICENSE for licensing information. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "mono/metadata/profiler.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "mini.h" #include #include #include "trace.h" #include "version.h" #include "jit-icalls.h" void mono_runtime_install_handlers (void) { #ifndef MONO_CROSS_COMPILE win32_seh_init(); win32_seh_set_handler(SIGFPE, mono_sigfpe_signal_handler); win32_seh_set_handler(SIGILL, mono_sigill_signal_handler); win32_seh_set_handler(SIGSEGV, mono_sigsegv_signal_handler); if (mini_get_debug_options ()->handle_sigint) win32_seh_set_handler(SIGINT, mono_sigint_signal_handler); #endif } void mono_runtime_cleanup_handlers (void) { #ifndef MONO_CROSS_COMPILE win32_seh_cleanup(); #endif } /* mono_chain_signal: * * Call the original signal handler for the signal given by the arguments, which * should be the same as for a signal handler. Returns TRUE if the original handler * was called, false otherwise. */ gboolean SIG_HANDLER_SIGNATURE (mono_chain_signal) { MonoJitTlsData *jit_tls = mono_native_tls_get_value (mono_jit_tls_id); jit_tls->mono_win_chained_exception_needs_run = TRUE; return TRUE; } static HANDLE win32_main_thread; static MMRESULT win32_timer; static void CALLBACK win32_time_proc (UINT uID, UINT uMsg, DWORD dwUser, DWORD dw1, DWORD dw2) { CONTEXT context; context.ContextFlags = CONTEXT_CONTROL; if (GetThreadContext (win32_main_thread, &context)) { #ifdef _WIN64 mono_profiler_stat_hit ((guchar *) context.Rip, &context); #else mono_profiler_stat_hit ((guchar *) context.Eip, &context); #endif } } void mono_runtime_setup_stat_profiler (void) { static int inited = 0; TIMECAPS timecaps; if (inited) return; inited = 1; if (timeGetDevCaps (&timecaps, sizeof (timecaps)) != TIMERR_NOERROR) return; if ((win32_main_thread = OpenThread (READ_CONTROL | THREAD_GET_CONTEXT, FALSE, GetCurrentThreadId ())) == NULL) return; if (timeBeginPeriod (1) != TIMERR_NOERROR) return; if ((win32_timer = timeSetEvent (1, 0, win32_time_proc, 0, TIME_PERIODIC)) == 0) { timeEndPeriod (1); return; } } void mono_runtime_shutdown_stat_profiler (void) { } gboolean mono_thread_state_init_from_handle (MonoThreadUnwindState *tctx, MonoThreadInfo *info) { g_error ("Windows systems haven't been ported to support mono_thread_state_init_from_handle"); return FALSE; }