From 4da66bfaa87c5ba2305856bf053b01f70dd34b62 Mon Sep 17 00:00:00 2001 From: Rom Walton Date: Wed, 27 Jun 2007 21:12:13 +0000 Subject: [PATCH] - DIAG: Visual Studio 2005 enforces parameter checking, and if a parameter is wrong it just terminates the process with a 0xc000000d. This is a shot in the dark but I think it is a good guess as to what is happening right now. lib/ diagnostics.C, .h diagnostics_win.C svn path=/trunk/boinc/; revision=13042 --- checkin_notes | 11 +++++++++++ lib/diagnostics.C | 3 +++ lib/diagnostics.h | 1 + lib/diagnostics_win.C | 30 ++++++++++++++++++++++++++++++ 4 files changed, 45 insertions(+) diff --git a/checkin_notes b/checkin_notes index 2de898c2a1..367ca5d8c3 100755 --- a/checkin_notes +++ b/checkin_notes @@ -6815,3 +6815,14 @@ Matt 27 June 2007 html/inc/ util.inc uotd.inc + +Rom 27 June 2007 + - DIAG: Visual Studio 2005 enforces parameter checking, and if + a parameter is wrong it just terminates the process with + a 0xc000000d. This is a shot in the dark but I think it + is a good guess as to what is happening right now. + + lib/ + diagnostics.C, .h + diagnostics_win.C + diff --git a/lib/diagnostics.C b/lib/diagnostics.C index f346ab43f6..6ced25d50a 100644 --- a/lib/diagnostics.C +++ b/lib/diagnostics.C @@ -137,6 +137,9 @@ int boinc_finish_diag() { int boinc_install_signal_handlers() { #ifdef _WIN32 SetUnhandledExceptionFilter(boinc_catch_signal); +#if _MSC_VER >= 1400 + _set_invalid_parameter_handler(boinc_catch_signal_invalid_parameter); +#endif #else //_WIN32 // register handlers for fatal internal signals diff --git a/lib/diagnostics.h b/lib/diagnostics.h index 320ab5f34a..76b8e6407b 100644 --- a/lib/diagnostics.h +++ b/lib/diagnostics.h @@ -114,6 +114,7 @@ extern int diagnostics_finish_unhandled_exception_monitor(); #ifdef _WIN32 extern UINT WINAPI diagnostics_unhandled_exception_monitor(LPVOID lpParameter); extern LONG CALLBACK boinc_catch_signal(EXCEPTION_POINTERS *ExceptionInfo); +extern void boinc_catch_signal_invalid_parameter(const wchar_t* expression, const wchar_t* function, const wchar_t* file, unsigned int line, uintptr_t pReserved); #else extern void boinc_catch_signal(int signal); extern void boinc_set_signal_handler(int sig, void(*handler)(int)); diff --git a/lib/diagnostics_win.C b/lib/diagnostics_win.C index 8b75ae6481..fdf064ced7 100644 --- a/lib/diagnostics_win.C +++ b/lib/diagnostics_win.C @@ -2164,4 +2164,34 @@ LONG CALLBACK boinc_catch_signal(PEXCEPTION_POINTERS pExPtrs) { } +// Starting with Visual Studio 2005 the C Runtime Library has really started to +// enforce parameter validation. Problem is that the parameter validation code +// uses its own structured exception handler and terminates without writing +// any useful output to stderr. Microsoft has created a hook an application +// developer can use to get more debugging information which is the purpose +// of this function. When an invalid parameter is passed to the C Runtime +// library this function will write whatever trace information it can and +// then throw a breakpoint exception to dump all the rest of the useful +// information. +void boinc_catch_signal_invalid_parameter( + const wchar_t* expression, const wchar_t* function, const wchar_t* file, unsigned int line, uintptr_t /* pReserved */ +) { + fprintf( + stderr, + "ERROR: Invalid parameter detected in function %s. File: %s Line: %d\n", + function, + file, + line + ); + fprintf( + stderr, + "ERROR: Expression: %s\n", + expression + ); + + // Cause a Debug Breakpoint. + DebugBreak(); +} + + const char *BOINC_RCSID_5967ad204d = "$Id$";