187d2adbcSAndrew Rist /**************************************************************
287d2adbcSAndrew Rist *
387d2adbcSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
487d2adbcSAndrew Rist * or more contributor license agreements. See the NOTICE file
587d2adbcSAndrew Rist * distributed with this work for additional information
687d2adbcSAndrew Rist * regarding copyright ownership. The ASF licenses this file
787d2adbcSAndrew Rist * to you under the Apache License, Version 2.0 (the
887d2adbcSAndrew Rist * "License"); you may not use this file except in compliance
987d2adbcSAndrew Rist * with the License. You may obtain a copy of the License at
1087d2adbcSAndrew Rist *
1187d2adbcSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
1287d2adbcSAndrew Rist *
1387d2adbcSAndrew Rist * Unless required by applicable law or agreed to in writing,
1487d2adbcSAndrew Rist * software distributed under the License is distributed on an
1587d2adbcSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1687d2adbcSAndrew Rist * KIND, either express or implied. See the License for the
1787d2adbcSAndrew Rist * specific language governing permissions and limitations
1887d2adbcSAndrew Rist * under the License.
1987d2adbcSAndrew Rist *
2087d2adbcSAndrew Rist *************************************************************/
2187d2adbcSAndrew Rist
2287d2adbcSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir /* system headers */
25cdf0e10cSrcweir #include "system.h"
26cdf0e10cSrcweir #include <tchar.h>
27cdf0e10cSrcweir
28cdf0e10cSrcweir #include "file_url.h"
29cdf0e10cSrcweir #include "path_helper.hxx"
30cdf0e10cSrcweir
31cdf0e10cSrcweir #include <osl/diagnose.h>
32cdf0e10cSrcweir #include <osl/mutex.h>
33cdf0e10cSrcweir #include <osl/signal.h>
34cdf0e10cSrcweir #ifndef __MINGW32__
35cdf0e10cSrcweir #include <DbgHelp.h>
36cdf0e10cSrcweir #endif
37cdf0e10cSrcweir #include <ErrorRep.h>
38cdf0e10cSrcweir #include <systools/win32/uwinapi.h>
39747164b0SHerbert Dürr #include <eh.h>
40747164b0SHerbert Dürr #include <stdexcept>
41cdf0e10cSrcweir
42cdf0e10cSrcweir typedef struct _oslSignalHandlerImpl
43cdf0e10cSrcweir {
44cdf0e10cSrcweir oslSignalHandlerFunction Handler;
45cdf0e10cSrcweir void* pData;
46cdf0e10cSrcweir struct _oslSignalHandlerImpl* pNext;
47cdf0e10cSrcweir } oslSignalHandlerImpl;
48cdf0e10cSrcweir
49cdf0e10cSrcweir static sal_Bool bErrorReportingEnabled = sal_True;
50cdf0e10cSrcweir static sal_Bool bInitSignal = sal_False;
51cdf0e10cSrcweir static oslMutex SignalListMutex;
52cdf0e10cSrcweir static oslSignalHandlerImpl* SignalList;
53cdf0e10cSrcweir
54cdf0e10cSrcweir static long WINAPI SignalHandlerFunction(LPEXCEPTION_POINTERS lpEP);
55cdf0e10cSrcweir
InitSignal(void)56cdf0e10cSrcweir static sal_Bool InitSignal(void)
57cdf0e10cSrcweir {
58cdf0e10cSrcweir HMODULE hFaultRep;
59cdf0e10cSrcweir
60cdf0e10cSrcweir SignalListMutex = osl_createMutex();
61cdf0e10cSrcweir
62cdf0e10cSrcweir SetUnhandledExceptionFilter(SignalHandlerFunction);
63cdf0e10cSrcweir
64cdf0e10cSrcweir hFaultRep = LoadLibrary( "faultrep.dll" );
65cdf0e10cSrcweir if ( hFaultRep )
66cdf0e10cSrcweir {
67cdf0e10cSrcweir #ifdef __MINGW32__
68cdf0e10cSrcweir typedef BOOL (WINAPI *pfn_ADDEREXCLUDEDAPPLICATIONW)(LPCWSTR);
69cdf0e10cSrcweir #endif
70cdf0e10cSrcweir pfn_ADDEREXCLUDEDAPPLICATIONW pfn = (pfn_ADDEREXCLUDEDAPPLICATIONW)GetProcAddress( hFaultRep, "AddERExcludedApplicationW" );
71cdf0e10cSrcweir if ( pfn )
72cdf0e10cSrcweir pfn( L"SOFFICE.EXE" );
73cdf0e10cSrcweir FreeLibrary( hFaultRep );
74cdf0e10cSrcweir }
75cdf0e10cSrcweir
76cdf0e10cSrcweir return sal_True;
77cdf0e10cSrcweir }
78cdf0e10cSrcweir
DeInitSignal(void)79cdf0e10cSrcweir static sal_Bool DeInitSignal(void)
80cdf0e10cSrcweir {
81cdf0e10cSrcweir SetUnhandledExceptionFilter(NULL);
82cdf0e10cSrcweir
83cdf0e10cSrcweir osl_destroyMutex(SignalListMutex);
84cdf0e10cSrcweir
85cdf0e10cSrcweir return sal_False;
86cdf0e10cSrcweir }
87cdf0e10cSrcweir
CallSignalHandler(oslSignalInfo * pInfo)88cdf0e10cSrcweir static oslSignalAction CallSignalHandler(oslSignalInfo *pInfo)
89cdf0e10cSrcweir {
90cdf0e10cSrcweir oslSignalHandlerImpl* pHandler = SignalList;
91cdf0e10cSrcweir oslSignalAction Action = osl_Signal_ActCallNextHdl;
92cdf0e10cSrcweir
93cdf0e10cSrcweir while (pHandler != NULL)
94cdf0e10cSrcweir {
95cdf0e10cSrcweir if ((Action = pHandler->Handler(pHandler->pData, pInfo)) != osl_Signal_ActCallNextHdl)
96cdf0e10cSrcweir break;
97cdf0e10cSrcweir
98cdf0e10cSrcweir pHandler = pHandler->pNext;
99cdf0e10cSrcweir }
100cdf0e10cSrcweir
101cdf0e10cSrcweir return Action;
102cdf0e10cSrcweir }
103cdf0e10cSrcweir
104cdf0e10cSrcweir /*****************************************************************************/
105cdf0e10cSrcweir /* SignalHandlerFunction */
106cdf0e10cSrcweir /*****************************************************************************/
107cdf0e10cSrcweir
108cdf0e10cSrcweir #define REPORTENV_PARAM "-crashreportenv:"
109cdf0e10cSrcweir #define REPORTENV_PARAM2 "/crashreportenv:"
110cdf0e10cSrcweir
ReportCrash(LPEXCEPTION_POINTERS lpEP)111cdf0e10cSrcweir static BOOL ReportCrash( LPEXCEPTION_POINTERS lpEP )
112cdf0e10cSrcweir {
113cdf0e10cSrcweir BOOL fSuccess = FALSE;
114cdf0e10cSrcweir BOOL fAutoReport = FALSE;
115cdf0e10cSrcweir TCHAR szBuffer[1024];
116cdf0e10cSrcweir ::osl::LongPathBuffer< sal_Char > aPath( MAX_LONG_PATH );
117cdf0e10cSrcweir LPTSTR lpFilePart;
118cdf0e10cSrcweir PROCESS_INFORMATION ProcessInfo;
119cdf0e10cSrcweir STARTUPINFO StartupInfo;
120cdf0e10cSrcweir int argi;
121cdf0e10cSrcweir
122cdf0e10cSrcweir if ( !bErrorReportingEnabled )
123cdf0e10cSrcweir return FALSE;
124cdf0e10cSrcweir
125cdf0e10cSrcweir /* Check if crash reporter was disabled by command line */
126cdf0e10cSrcweir
127cdf0e10cSrcweir for ( argi = 1; argi < __argc; argi++ )
128cdf0e10cSrcweir {
129cdf0e10cSrcweir if (
130cdf0e10cSrcweir 0 == stricmp( __argv[argi], "-nocrashreport" ) ||
131cdf0e10cSrcweir 0 == stricmp( __argv[argi], "/nocrashreport" )
132cdf0e10cSrcweir )
133cdf0e10cSrcweir return FALSE;
134cdf0e10cSrcweir else if (
135cdf0e10cSrcweir 0 == stricmp( __argv[argi], "-autocrashreport" ) ||
136cdf0e10cSrcweir 0 == stricmp( __argv[argi], "/autocrashreport" )
137cdf0e10cSrcweir )
138cdf0e10cSrcweir fAutoReport = TRUE;
139cdf0e10cSrcweir else if (
140cdf0e10cSrcweir 0 == strnicmp( __argv[argi], REPORTENV_PARAM, strlen(REPORTENV_PARAM) ) ||
141cdf0e10cSrcweir 0 == strnicmp( __argv[argi], REPORTENV_PARAM2, strlen(REPORTENV_PARAM2) )
142cdf0e10cSrcweir )
143cdf0e10cSrcweir {
144cdf0e10cSrcweir const char *envparam = __argv[argi] + strlen(REPORTENV_PARAM);
145cdf0e10cSrcweir const char *delim = strchr(envparam, '=' );
146cdf0e10cSrcweir
147cdf0e10cSrcweir if ( delim )
148cdf0e10cSrcweir {
149cdf0e10cSrcweir CHAR *lpVariable;
150cdf0e10cSrcweir CHAR *lpValue;
151cdf0e10cSrcweir const char *variable = envparam;
152cdf0e10cSrcweir size_t variable_len = delim - envparam;
153cdf0e10cSrcweir const char *value = delim + 1;
154cdf0e10cSrcweir size_t value_len = strlen(envparam) - variable_len - 1;
155cdf0e10cSrcweir
156cdf0e10cSrcweir if ( '\"' == *value )
157cdf0e10cSrcweir {
158cdf0e10cSrcweir const char *quote;
159cdf0e10cSrcweir
160cdf0e10cSrcweir value++;
161cdf0e10cSrcweir value_len--;
162cdf0e10cSrcweir
163cdf0e10cSrcweir quote = strchr( value, '\"' );
164cdf0e10cSrcweir if ( quote )
165cdf0e10cSrcweir value_len = quote - value;
166cdf0e10cSrcweir }
167cdf0e10cSrcweir
168cdf0e10cSrcweir lpVariable = reinterpret_cast< CHAR* >( _alloca( variable_len + 1 ) );
169cdf0e10cSrcweir memcpy( lpVariable, variable, variable_len );
170cdf0e10cSrcweir lpVariable[variable_len] = 0;
171cdf0e10cSrcweir
172cdf0e10cSrcweir lpValue = reinterpret_cast< CHAR* >( _alloca( value_len + 1) );
173cdf0e10cSrcweir memcpy( lpValue, value, value_len );
174cdf0e10cSrcweir lpValue[value_len] = 0;
175cdf0e10cSrcweir
176cdf0e10cSrcweir SetEnvironmentVariable( lpVariable, lpValue );
177cdf0e10cSrcweir }
178cdf0e10cSrcweir }
179cdf0e10cSrcweir }
180cdf0e10cSrcweir
181cdf0e10cSrcweir if ( SearchPath( NULL, TEXT( "crashrep.exe" ), NULL, aPath.getBufSizeInSymbols(), aPath, &lpFilePart ) )
182cdf0e10cSrcweir {
183cdf0e10cSrcweir ZeroMemory( &StartupInfo, sizeof(StartupInfo) );
184cdf0e10cSrcweir StartupInfo.cb = sizeof(StartupInfo.cb);
185cdf0e10cSrcweir
186cdf0e10cSrcweir
187cdf0e10cSrcweir sntprintf( szBuffer, elementsof(szBuffer),
188cdf0e10cSrcweir _T("%s -p %u -excp 0x%p -t %u%s"),
189cdf0e10cSrcweir static_cast<sal_Char*>( aPath ),
190cdf0e10cSrcweir GetCurrentProcessId(),
191cdf0e10cSrcweir lpEP,
192cdf0e10cSrcweir GetCurrentThreadId(),
193cdf0e10cSrcweir fAutoReport ? _T(" -noui -send") : _T(" -noui") );
194cdf0e10cSrcweir
195cdf0e10cSrcweir if (
196cdf0e10cSrcweir CreateProcess(
197cdf0e10cSrcweir NULL,
198cdf0e10cSrcweir szBuffer,
199cdf0e10cSrcweir NULL,
200cdf0e10cSrcweir NULL,
201cdf0e10cSrcweir FALSE,
202cdf0e10cSrcweir #ifdef UNICODE
203cdf0e10cSrcweir CREATE_UNICODE_ENVIRONMENT,
204cdf0e10cSrcweir #else
205cdf0e10cSrcweir 0,
206cdf0e10cSrcweir #endif
207cdf0e10cSrcweir NULL, NULL, &StartupInfo, &ProcessInfo )
208cdf0e10cSrcweir )
209cdf0e10cSrcweir {
210cdf0e10cSrcweir DWORD dwExitCode;
211cdf0e10cSrcweir
212cdf0e10cSrcweir WaitForSingleObject( ProcessInfo.hProcess, INFINITE );
213cdf0e10cSrcweir if ( GetExitCodeProcess( ProcessInfo.hProcess, &dwExitCode ) && 0 == dwExitCode )
214cdf0e10cSrcweir
215cdf0e10cSrcweir fSuccess = TRUE;
216cdf0e10cSrcweir
217cdf0e10cSrcweir }
218cdf0e10cSrcweir }
219cdf0e10cSrcweir
220cdf0e10cSrcweir return fSuccess;
221cdf0e10cSrcweir }
222cdf0e10cSrcweir
223cdf0e10cSrcweir /*****************************************************************************/
224cdf0e10cSrcweir /* SignalHandlerFunction */
225cdf0e10cSrcweir /*****************************************************************************/
226cdf0e10cSrcweir
IsWin95A(void)227cdf0e10cSrcweir static BOOL WINAPI IsWin95A(void)
228cdf0e10cSrcweir {
229cdf0e10cSrcweir OSVERSIONINFO ovi;
230cdf0e10cSrcweir
231cdf0e10cSrcweir ZeroMemory( &ovi, sizeof(ovi) );
232cdf0e10cSrcweir ovi.dwOSVersionInfoSize = sizeof(ovi);
233cdf0e10cSrcweir
234cdf0e10cSrcweir if ( GetVersionEx( &ovi ) )
235cdf0e10cSrcweir /* See MSDN January 2000 documentation of GetVersionEx */
236cdf0e10cSrcweir return (ovi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) &&
237cdf0e10cSrcweir (ovi.dwMajorVersion <= 4) &&
238cdf0e10cSrcweir (ovi.dwMinorVersion == 0) &&
239cdf0e10cSrcweir (ovi.dwBuildNumber == 0x040003B6);
240cdf0e10cSrcweir
241cdf0e10cSrcweir /* Something wrent wrong. So assume we have an older operating prior Win95 */
242cdf0e10cSrcweir
243cdf0e10cSrcweir return TRUE;
244cdf0e10cSrcweir }
245cdf0e10cSrcweir
246cdf0e10cSrcweir /* magic Microsoft C++ compiler exception constant */
247cdf0e10cSrcweir #define EXCEPTION_MSC_CPP_EXCEPTION 0xe06d7363
248cdf0e10cSrcweir
SignalHandlerFunction(LPEXCEPTION_POINTERS lpEP)249cdf0e10cSrcweir static long WINAPI SignalHandlerFunction(LPEXCEPTION_POINTERS lpEP)
250cdf0e10cSrcweir {
251cdf0e10cSrcweir static sal_Bool bNested = sal_False;
252cdf0e10cSrcweir sal_Bool bRaiseCrashReporter = sal_False;
253cdf0e10cSrcweir oslSignalInfo Info;
254cdf0e10cSrcweir oslSignalAction Action;
255cdf0e10cSrcweir
256cdf0e10cSrcweir Info.UserSignal = lpEP->ExceptionRecord->ExceptionCode;
257cdf0e10cSrcweir Info.UserData = NULL;
258cdf0e10cSrcweir
259cdf0e10cSrcweir switch (lpEP->ExceptionRecord->ExceptionCode)
260cdf0e10cSrcweir {
261cdf0e10cSrcweir /* Transform unhandled exceptions into access violations.
262cdf0e10cSrcweir Microsoft C++ compiler (add more for other compilers if necessary).
263cdf0e10cSrcweir */
264cdf0e10cSrcweir case EXCEPTION_MSC_CPP_EXCEPTION:
265cdf0e10cSrcweir case EXCEPTION_ACCESS_VIOLATION:
266cdf0e10cSrcweir Info.Signal = osl_Signal_AccessViolation;
267cdf0e10cSrcweir bRaiseCrashReporter = sal_True;
268cdf0e10cSrcweir break;
269cdf0e10cSrcweir
270cdf0e10cSrcweir case EXCEPTION_INT_DIVIDE_BY_ZERO:
271cdf0e10cSrcweir Info.Signal = osl_Signal_IntegerDivideByZero;
272cdf0e10cSrcweir bRaiseCrashReporter = sal_True;
273cdf0e10cSrcweir break;
274cdf0e10cSrcweir
275cdf0e10cSrcweir case EXCEPTION_FLT_DIVIDE_BY_ZERO:
276cdf0e10cSrcweir Info.Signal = osl_Signal_FloatDivideByZero;
277cdf0e10cSrcweir bRaiseCrashReporter = sal_True;
278cdf0e10cSrcweir break;
279cdf0e10cSrcweir
280cdf0e10cSrcweir case EXCEPTION_BREAKPOINT:
281cdf0e10cSrcweir Info.Signal = osl_Signal_DebugBreak;
282cdf0e10cSrcweir break;
283cdf0e10cSrcweir
284cdf0e10cSrcweir default:
285cdf0e10cSrcweir Info.Signal = osl_Signal_System;
286cdf0e10cSrcweir bRaiseCrashReporter = sal_True;
287cdf0e10cSrcweir break;
288cdf0e10cSrcweir }
289cdf0e10cSrcweir
290cdf0e10cSrcweir if ( !bNested )
291cdf0e10cSrcweir {
292cdf0e10cSrcweir bNested = sal_True;
293cdf0e10cSrcweir
294cdf0e10cSrcweir if ( bRaiseCrashReporter && ReportCrash( lpEP ) || IsWin95A() )
295cdf0e10cSrcweir {
296cdf0e10cSrcweir CallSignalHandler(&Info);
297cdf0e10cSrcweir Action = osl_Signal_ActKillApp;
298cdf0e10cSrcweir }
299cdf0e10cSrcweir else
300cdf0e10cSrcweir Action = CallSignalHandler(&Info);
301cdf0e10cSrcweir }
302cdf0e10cSrcweir else
303cdf0e10cSrcweir Action = osl_Signal_ActKillApp;
304cdf0e10cSrcweir
305cdf0e10cSrcweir
306cdf0e10cSrcweir switch ( Action )
307cdf0e10cSrcweir {
308cdf0e10cSrcweir case osl_Signal_ActCallNextHdl:
309cdf0e10cSrcweir return (EXCEPTION_CONTINUE_SEARCH);
310cdf0e10cSrcweir
311cdf0e10cSrcweir case osl_Signal_ActAbortApp:
312cdf0e10cSrcweir return (EXCEPTION_EXECUTE_HANDLER);
313cdf0e10cSrcweir
314cdf0e10cSrcweir case osl_Signal_ActKillApp:
315cdf0e10cSrcweir SetErrorMode(SEM_NOGPFAULTERRORBOX);
316cdf0e10cSrcweir exit(255);
317cdf0e10cSrcweir break;
318cdf0e10cSrcweir default:
319cdf0e10cSrcweir break;
320cdf0e10cSrcweir }
321cdf0e10cSrcweir
322cdf0e10cSrcweir return (EXCEPTION_CONTINUE_EXECUTION);
323cdf0e10cSrcweir }
324cdf0e10cSrcweir
325cdf0e10cSrcweir /*****************************************************************************/
326cdf0e10cSrcweir /* osl_addSignalHandler */
327cdf0e10cSrcweir /*****************************************************************************/
osl_addSignalHandler(oslSignalHandlerFunction Handler,void * pData)328cdf0e10cSrcweir oslSignalHandler SAL_CALL osl_addSignalHandler(oslSignalHandlerFunction Handler, void* pData)
329cdf0e10cSrcweir {
330cdf0e10cSrcweir oslSignalHandlerImpl* pHandler;
331cdf0e10cSrcweir
332cdf0e10cSrcweir OSL_ASSERT(Handler != NULL);
333cdf0e10cSrcweir
334cdf0e10cSrcweir if (! bInitSignal)
335cdf0e10cSrcweir bInitSignal = InitSignal();
336cdf0e10cSrcweir
337cdf0e10cSrcweir pHandler = reinterpret_cast< oslSignalHandlerImpl* >( calloc( 1, sizeof(oslSignalHandlerImpl) ) );
338cdf0e10cSrcweir
339cdf0e10cSrcweir if (pHandler != NULL)
340cdf0e10cSrcweir {
341cdf0e10cSrcweir pHandler->Handler = Handler;
342cdf0e10cSrcweir pHandler->pData = pData;
343cdf0e10cSrcweir
344cdf0e10cSrcweir osl_acquireMutex(SignalListMutex);
345cdf0e10cSrcweir
346cdf0e10cSrcweir pHandler->pNext = SignalList;
347cdf0e10cSrcweir SignalList = pHandler;
348cdf0e10cSrcweir
349cdf0e10cSrcweir osl_releaseMutex(SignalListMutex);
350cdf0e10cSrcweir
351cdf0e10cSrcweir return (pHandler);
352cdf0e10cSrcweir }
353cdf0e10cSrcweir
354cdf0e10cSrcweir return (NULL);
355cdf0e10cSrcweir }
356cdf0e10cSrcweir
357cdf0e10cSrcweir /*****************************************************************************/
358cdf0e10cSrcweir /* osl_removeSignalHandler */
359cdf0e10cSrcweir /*****************************************************************************/
osl_removeSignalHandler(oslSignalHandler Handler)360cdf0e10cSrcweir sal_Bool SAL_CALL osl_removeSignalHandler(oslSignalHandler Handler)
361cdf0e10cSrcweir {
362cdf0e10cSrcweir oslSignalHandlerImpl *pHandler, *pPrevious = NULL;
363cdf0e10cSrcweir
364cdf0e10cSrcweir OSL_ASSERT(Handler != NULL);
365cdf0e10cSrcweir
366cdf0e10cSrcweir if (! bInitSignal)
367cdf0e10cSrcweir bInitSignal = InitSignal();
368cdf0e10cSrcweir
369cdf0e10cSrcweir osl_acquireMutex(SignalListMutex);
370cdf0e10cSrcweir
371cdf0e10cSrcweir pHandler = SignalList;
372cdf0e10cSrcweir
373cdf0e10cSrcweir while (pHandler != NULL)
374cdf0e10cSrcweir {
375cdf0e10cSrcweir if (pHandler == Handler)
376cdf0e10cSrcweir {
377cdf0e10cSrcweir if (pPrevious)
378cdf0e10cSrcweir pPrevious->pNext = pHandler->pNext;
379cdf0e10cSrcweir else
380cdf0e10cSrcweir SignalList = pHandler->pNext;
381cdf0e10cSrcweir
382cdf0e10cSrcweir osl_releaseMutex(SignalListMutex);
383cdf0e10cSrcweir
384cdf0e10cSrcweir if (SignalList == NULL)
385cdf0e10cSrcweir bInitSignal = DeInitSignal();
386cdf0e10cSrcweir
387cdf0e10cSrcweir free(pHandler);
388cdf0e10cSrcweir
389cdf0e10cSrcweir return (sal_True);
390cdf0e10cSrcweir }
391cdf0e10cSrcweir
392cdf0e10cSrcweir pPrevious = pHandler;
393cdf0e10cSrcweir pHandler = pHandler->pNext;
394cdf0e10cSrcweir }
395cdf0e10cSrcweir
396cdf0e10cSrcweir osl_releaseMutex(SignalListMutex);
397cdf0e10cSrcweir
398cdf0e10cSrcweir return (sal_False);
399cdf0e10cSrcweir }
400cdf0e10cSrcweir
401cdf0e10cSrcweir /*****************************************************************************/
402cdf0e10cSrcweir /* osl_raiseSignal */
403cdf0e10cSrcweir /*****************************************************************************/
osl_raiseSignal(sal_Int32 UserSignal,void * UserData)404cdf0e10cSrcweir oslSignalAction SAL_CALL osl_raiseSignal(sal_Int32 UserSignal, void* UserData)
405cdf0e10cSrcweir {
406cdf0e10cSrcweir oslSignalInfo Info;
407cdf0e10cSrcweir oslSignalAction Action;
408cdf0e10cSrcweir
409cdf0e10cSrcweir if (! bInitSignal)
410cdf0e10cSrcweir bInitSignal = InitSignal();
411cdf0e10cSrcweir
412cdf0e10cSrcweir osl_acquireMutex(SignalListMutex);
413cdf0e10cSrcweir
414cdf0e10cSrcweir Info.Signal = osl_Signal_User;
415cdf0e10cSrcweir Info.UserSignal = UserSignal;
416cdf0e10cSrcweir Info.UserData = UserData;
417cdf0e10cSrcweir
418cdf0e10cSrcweir Action = CallSignalHandler(&Info);
419cdf0e10cSrcweir
420cdf0e10cSrcweir osl_releaseMutex(SignalListMutex);
421cdf0e10cSrcweir
422cdf0e10cSrcweir return (Action);
423cdf0e10cSrcweir }
424cdf0e10cSrcweir
425cdf0e10cSrcweir /*****************************************************************************/
426cdf0e10cSrcweir /* osl_setErrorReporting */
427cdf0e10cSrcweir /*****************************************************************************/
428747164b0SHerbert Dürr
win_seh_translator(unsigned nSEHCode,_EXCEPTION_POINTERS * pExcPtrs)429747164b0SHerbert Dürr void win_seh_translator( unsigned nSEHCode, _EXCEPTION_POINTERS* pExcPtrs)
430747164b0SHerbert Dürr {
431*3752b850SHerbert Dürr (void*)pExcPtrs; // currently unused, but useful inside a debugger
432747164b0SHerbert Dürr const char* pSEHName = NULL;
4330b7f0425SHerbert Dürr switch( nSEHCode)
4340b7f0425SHerbert Dürr {
435747164b0SHerbert Dürr case EXCEPTION_ACCESS_VIOLATION: pSEHName = "SEH Exception: ACCESS VIOLATION"; break;
436747164b0SHerbert Dürr case EXCEPTION_DATATYPE_MISALIGNMENT: pSEHName = "SEH Exception: DATATYPE MISALIGNMENT"; break;
4370b7f0425SHerbert Dürr case EXCEPTION_BREAKPOINT: /*pSEHName = "SEH Exception: BREAKPOINT";*/ break;
4380b7f0425SHerbert Dürr case EXCEPTION_SINGLE_STEP: /*pSEHName = "SEH Exception: SINGLE STEP";*/ break;
439747164b0SHerbert Dürr case EXCEPTION_ARRAY_BOUNDS_EXCEEDED: pSEHName = "SEH Exception: ARRAY BOUNDS EXCEEDED"; break;
440747164b0SHerbert Dürr case EXCEPTION_FLT_DENORMAL_OPERAND: pSEHName = "SEH Exception: DENORMAL FLOAT OPERAND"; break;
441747164b0SHerbert Dürr case EXCEPTION_FLT_DIVIDE_BY_ZERO: pSEHName = "SEH Exception: FLOAT DIVIDE_BY_ZERO"; break;
442747164b0SHerbert Dürr case EXCEPTION_FLT_INEXACT_RESULT: pSEHName = "SEH Exception: FLOAT INEXACT RESULT"; break;
443747164b0SHerbert Dürr case EXCEPTION_FLT_INVALID_OPERATION: pSEHName = "SEH Exception: INVALID FLOAT OPERATION"; break;
444747164b0SHerbert Dürr case EXCEPTION_FLT_OVERFLOW: pSEHName = "SEH Exception: FLOAT OVERFLOW"; break;
445747164b0SHerbert Dürr case EXCEPTION_FLT_STACK_CHECK: pSEHName = "SEH Exception: FLOAT STACK_CHECK"; break;
446747164b0SHerbert Dürr case EXCEPTION_FLT_UNDERFLOW: pSEHName = "SEH Exception: FLOAT UNDERFLOW"; break;
447747164b0SHerbert Dürr case EXCEPTION_INT_DIVIDE_BY_ZERO: pSEHName = "SEH Exception: INTEGER DIVIDE_BY_ZERO"; break;
448747164b0SHerbert Dürr case EXCEPTION_INT_OVERFLOW: pSEHName = "SEH Exception: INTEGER OVERFLOW"; break;
449747164b0SHerbert Dürr case EXCEPTION_PRIV_INSTRUCTION: pSEHName = "SEH Exception: PRIVILEDGED INSTRUCTION"; break;
450747164b0SHerbert Dürr case EXCEPTION_IN_PAGE_ERROR: pSEHName = "SEH Exception: IN_PAGE_ERROR"; break;
451747164b0SHerbert Dürr case EXCEPTION_ILLEGAL_INSTRUCTION: pSEHName = "SEH Exception: ILLEGAL INSTRUCTION"; break;
452747164b0SHerbert Dürr case EXCEPTION_NONCONTINUABLE_EXCEPTION: pSEHName = "SEH Exception: NONCONTINUABLE EXCEPTION"; break;
453747164b0SHerbert Dürr case EXCEPTION_STACK_OVERFLOW: pSEHName = "SEH Exception: STACK OVERFLOW"; break;
454747164b0SHerbert Dürr case EXCEPTION_INVALID_DISPOSITION: pSEHName = "SEH Exception: INVALID DISPOSITION"; break;
455747164b0SHerbert Dürr case EXCEPTION_GUARD_PAGE: pSEHName = "SEH Exception: GUARD PAGE"; break;
456747164b0SHerbert Dürr case EXCEPTION_INVALID_HANDLE: pSEHName = "SEH Exception: INVALID HANDLE"; break;
457747164b0SHerbert Dürr // case EXCEPTION_POSSIBLE_DEADLOCK: pSEHName = "SEH Exception: POSSIBLE DEADLOCK"; break;
458747164b0SHerbert Dürr default: pSEHName = "Unknown SEH Exception"; break;
459747164b0SHerbert Dürr }
4600b7f0425SHerbert Dürr
4610b7f0425SHerbert Dürr if( pSEHName)
4620b7f0425SHerbert Dürr throw std::runtime_error( pSEHName);
463747164b0SHerbert Dürr }
464747164b0SHerbert Dürr
osl_setErrorReporting(sal_Bool bEnable)465cdf0e10cSrcweir sal_Bool SAL_CALL osl_setErrorReporting( sal_Bool bEnable )
466cdf0e10cSrcweir {
467cdf0e10cSrcweir sal_Bool bOld = bErrorReportingEnabled;
468cdf0e10cSrcweir bErrorReportingEnabled = bEnable;
469cdf0e10cSrcweir
470747164b0SHerbert Dürr if( !bEnable) // if the crash reporter is disabled
471747164b0SHerbert Dürr {
472747164b0SHerbert Dürr // fall back to handle Window's SEH events as C++ exceptions
473747164b0SHerbert Dürr _set_se_translator( win_seh_translator);
474747164b0SHerbert Dürr }
475747164b0SHerbert Dürr
476cdf0e10cSrcweir return bOld;
477cdf0e10cSrcweir }
478