lok: vcl: fix multiple floatwin removal case more robustly.
[LibreOffice.git] / sal / osl / w32 / signal.cxx
blob79d0bcbd4e0379cccb880fdf422310e5bb4affa8
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <sal/config.h>
22 #include <stdlib.h>
24 #include <config_features.h>
26 #include <signalshared.hxx>
28 #include <systools/win32/uwinapi.h>
29 #include <errorrep.h>
31 namespace
33 long WINAPI signalHandlerFunction(LPEXCEPTION_POINTERS lpEP);
35 LPTOP_LEVEL_EXCEPTION_FILTER pPreviousHandler = nullptr;
38 bool onInitSignal()
40 pPreviousHandler = SetUnhandledExceptionFilter(signalHandlerFunction);
42 HMODULE hFaultRep = LoadLibraryW( L"faultrep.dll" );
43 if ( hFaultRep )
45 pfn_ADDEREXCLUDEDAPPLICATIONW pfn = reinterpret_cast<pfn_ADDEREXCLUDEDAPPLICATIONW>(GetProcAddress( hFaultRep, "AddERExcludedApplicationW" ));
46 if ( pfn )
47 pfn( L"SOFFICE.EXE" );
48 FreeLibrary( hFaultRep );
51 return true;
54 bool onDeInitSignal()
56 SetUnhandledExceptionFilter(pPreviousHandler);
58 return false;
61 namespace
63 /* magic Microsoft C++ compiler exception constant */
64 #define EXCEPTION_MSC_CPP_EXCEPTION 0xe06d7363
66 long WINAPI signalHandlerFunction(LPEXCEPTION_POINTERS lpEP)
68 #if HAVE_FEATURE_BREAKPAD
69 // we should make sure to call the breakpad handler as
70 // first step when we hit a problem
71 if (pPreviousHandler)
72 pPreviousHandler(lpEP);
73 #endif
75 static bool bNested = false;
77 oslSignalInfo info;
79 info.UserSignal = lpEP->ExceptionRecord->ExceptionCode;
80 info.UserData = nullptr;
82 switch (lpEP->ExceptionRecord->ExceptionCode)
84 /* Transform unhandled exceptions into access violations.
85 Microsoft C++ compiler (add more for other compilers if necessary).
87 case EXCEPTION_MSC_CPP_EXCEPTION:
88 case EXCEPTION_ACCESS_VIOLATION:
89 info.Signal = osl_Signal_AccessViolation;
90 break;
92 case EXCEPTION_INT_DIVIDE_BY_ZERO:
93 info.Signal = osl_Signal_IntegerDivideByZero;
94 break;
96 case EXCEPTION_FLT_DIVIDE_BY_ZERO:
97 info.Signal = osl_Signal_FloatDivideByZero;
98 break;
100 case EXCEPTION_BREAKPOINT:
101 info.Signal = osl_Signal_DebugBreak;
102 break;
104 default:
105 info.Signal = osl_Signal_System;
106 break;
109 oslSignalAction action;
111 if ( !bNested )
113 bNested = true;
114 action = callSignalHandler(&info);
116 else
117 action = osl_Signal_ActKillApp;
119 switch ( action )
121 case osl_Signal_ActCallNextHdl:
122 return EXCEPTION_CONTINUE_SEARCH;
124 case osl_Signal_ActAbortApp:
125 return EXCEPTION_EXECUTE_HANDLER;
127 case osl_Signal_ActKillApp:
128 SetErrorMode(SEM_NOGPFAULTERRORBOX);
129 exit(255);
130 break;
131 default:
132 break;
135 return EXCEPTION_CONTINUE_EXECUTION;
140 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */