2001-01-11 00:59:25 +01:00
|
|
|
/*
|
|
|
|
* msvcrt.dll exception handling
|
|
|
|
*
|
|
|
|
* Copyright 2000 Jon Griffiths
|
2005-05-13 19:44:28 +02:00
|
|
|
* Copyright 2005 Juan Lang
|
2001-01-11 00:59:25 +01:00
|
|
|
*
|
2002-03-10 00:29:33 +01:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
2001-01-12 21:41:03 +01:00
|
|
|
* FIXME: Incomplete support for nested exceptions/try block cleanup.
|
2001-01-11 00:59:25 +01:00
|
|
|
*/
|
2002-04-25 23:40:56 +02:00
|
|
|
|
2020-12-01 13:52:16 +01:00
|
|
|
#include <float.h>
|
2020-12-01 13:52:20 +01:00
|
|
|
#include <signal.h>
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2020-11-27 14:17:05 +01:00
|
|
|
#include <stdbool.h>
|
2003-09-06 01:08:26 +02:00
|
|
|
|
2011-02-01 16:40:31 +01:00
|
|
|
#include "ntstatus.h"
|
|
|
|
#define WIN32_NO_STATUS
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
2002-09-13 00:07:02 +02:00
|
|
|
#include "winternl.h"
|
2001-01-12 21:41:03 +01:00
|
|
|
#include "wine/exception.h"
|
2001-01-11 00:59:25 +01:00
|
|
|
#include "msvcrt.h"
|
2002-12-13 00:34:01 +01:00
|
|
|
#include "excpt.h"
|
2005-05-13 19:44:28 +02:00
|
|
|
#include "wincon.h"
|
2002-01-22 01:57:16 +01:00
|
|
|
#include "wine/debug.h"
|
|
|
|
|
2016-03-16 21:02:08 +01:00
|
|
|
#include "cppexcept.h"
|
|
|
|
|
2006-01-05 14:36:37 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(seh);
|
2001-01-11 00:59:25 +01:00
|
|
|
|
2018-01-10 07:21:42 +01:00
|
|
|
#if _MSVCR_VER>=70 && _MSVCR_VER<=71
|
2011-03-16 09:22:24 +01:00
|
|
|
static MSVCRT_security_error_handler security_error_handler;
|
2018-01-10 07:21:42 +01:00
|
|
|
#endif
|
2011-03-16 09:22:24 +01:00
|
|
|
|
2020-12-01 13:52:20 +01:00
|
|
|
static __sighandler_t sighandlers[NSIG] = { SIG_DFL };
|
2005-05-13 19:44:28 +02:00
|
|
|
|
|
|
|
static BOOL WINAPI msvcrt_console_handler(DWORD ctrlType)
|
|
|
|
{
|
|
|
|
BOOL ret = FALSE;
|
|
|
|
|
|
|
|
switch (ctrlType)
|
|
|
|
{
|
|
|
|
case CTRL_C_EVENT:
|
2020-12-01 13:52:20 +01:00
|
|
|
if (sighandlers[SIGINT])
|
2005-05-13 19:44:28 +02:00
|
|
|
{
|
2020-12-01 13:52:20 +01:00
|
|
|
if (sighandlers[SIGINT] != SIG_IGN)
|
|
|
|
sighandlers[SIGINT](SIGINT);
|
2005-05-13 19:44:28 +02:00
|
|
|
ret = TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-03-05 11:05:42 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* __pxcptinfoptrs (MSVCRT.@)
|
|
|
|
*/
|
2020-12-02 00:53:42 +01:00
|
|
|
void** CDECL __pxcptinfoptrs(void)
|
2013-03-05 11:05:42 +01:00
|
|
|
{
|
|
|
|
return (void**)&msvcrt_get_thread_data()->xcptinfo;
|
|
|
|
}
|
|
|
|
|
2010-05-12 17:15:29 +02:00
|
|
|
typedef void (CDECL *float_handler)(int, int);
|
2005-05-13 19:44:28 +02:00
|
|
|
|
|
|
|
/* The exception codes are actually NTSTATUS values */
|
2007-01-13 21:31:01 +01:00
|
|
|
static const struct
|
2005-05-13 19:44:28 +02:00
|
|
|
{
|
|
|
|
NTSTATUS status;
|
|
|
|
int signal;
|
|
|
|
} float_exception_map[] = {
|
2020-12-01 13:52:16 +01:00
|
|
|
{ EXCEPTION_FLT_DENORMAL_OPERAND, _FPE_DENORMAL },
|
|
|
|
{ EXCEPTION_FLT_DIVIDE_BY_ZERO, _FPE_ZERODIVIDE },
|
|
|
|
{ EXCEPTION_FLT_INEXACT_RESULT, _FPE_INEXACT },
|
|
|
|
{ EXCEPTION_FLT_INVALID_OPERATION, _FPE_INVALID },
|
|
|
|
{ EXCEPTION_FLT_OVERFLOW, _FPE_OVERFLOW },
|
|
|
|
{ EXCEPTION_FLT_STACK_CHECK, _FPE_STACKOVERFLOW },
|
|
|
|
{ EXCEPTION_FLT_UNDERFLOW, _FPE_UNDERFLOW },
|
2005-05-13 19:44:28 +02:00
|
|
|
};
|
|
|
|
|
2013-03-06 15:07:51 +01:00
|
|
|
static LONG msvcrt_exception_filter(struct _EXCEPTION_POINTERS *except)
|
2005-05-13 19:44:28 +02:00
|
|
|
{
|
|
|
|
LONG ret = EXCEPTION_CONTINUE_SEARCH;
|
2020-12-01 13:52:20 +01:00
|
|
|
__sighandler_t handler;
|
2005-05-13 19:44:28 +02:00
|
|
|
|
2005-05-19 16:21:21 +02:00
|
|
|
if (!except || !except->ExceptionRecord)
|
|
|
|
return EXCEPTION_CONTINUE_SEARCH;
|
|
|
|
|
2005-05-13 19:44:28 +02:00
|
|
|
switch (except->ExceptionRecord->ExceptionCode)
|
|
|
|
{
|
|
|
|
case EXCEPTION_ACCESS_VIOLATION:
|
2020-12-01 13:52:20 +01:00
|
|
|
if ((handler = sighandlers[SIGSEGV]) != SIG_DFL)
|
2005-05-13 19:44:28 +02:00
|
|
|
{
|
2020-12-01 13:52:20 +01:00
|
|
|
if (handler != SIG_IGN)
|
2007-02-08 21:33:33 +01:00
|
|
|
{
|
2020-12-02 00:53:42 +01:00
|
|
|
EXCEPTION_POINTERS **ep = (EXCEPTION_POINTERS**)__pxcptinfoptrs(), *old_ep;
|
2013-03-05 11:05:42 +01:00
|
|
|
|
|
|
|
old_ep = *ep;
|
|
|
|
*ep = except;
|
2020-12-01 13:52:20 +01:00
|
|
|
sighandlers[SIGSEGV] = SIG_DFL;
|
|
|
|
handler(SIGSEGV);
|
2013-03-05 11:05:42 +01:00
|
|
|
*ep = old_ep;
|
2007-02-08 21:33:33 +01:00
|
|
|
}
|
2005-05-13 19:44:28 +02:00
|
|
|
ret = EXCEPTION_CONTINUE_EXECUTION;
|
|
|
|
}
|
|
|
|
break;
|
2008-03-01 05:29:54 +01:00
|
|
|
/* According to msdn,
|
2005-05-13 19:44:28 +02:00
|
|
|
* the FPE signal handler takes as a second argument the type of
|
|
|
|
* floating point exception.
|
|
|
|
*/
|
|
|
|
case EXCEPTION_FLT_DENORMAL_OPERAND:
|
|
|
|
case EXCEPTION_FLT_DIVIDE_BY_ZERO:
|
|
|
|
case EXCEPTION_FLT_INEXACT_RESULT:
|
|
|
|
case EXCEPTION_FLT_INVALID_OPERATION:
|
|
|
|
case EXCEPTION_FLT_OVERFLOW:
|
|
|
|
case EXCEPTION_FLT_STACK_CHECK:
|
|
|
|
case EXCEPTION_FLT_UNDERFLOW:
|
2020-12-01 13:52:20 +01:00
|
|
|
if ((handler = sighandlers[SIGFPE]) != SIG_DFL)
|
2005-05-13 19:44:28 +02:00
|
|
|
{
|
2020-12-01 13:52:20 +01:00
|
|
|
if (handler != SIG_IGN)
|
2005-05-13 19:44:28 +02:00
|
|
|
{
|
2020-12-02 00:53:42 +01:00
|
|
|
EXCEPTION_POINTERS **ep = (EXCEPTION_POINTERS**)__pxcptinfoptrs(), *old_ep;
|
2008-10-21 22:44:27 +02:00
|
|
|
unsigned int i;
|
2020-12-01 13:52:16 +01:00
|
|
|
int float_signal = _FPE_INVALID;
|
2005-05-13 19:44:28 +02:00
|
|
|
|
2020-12-01 13:52:20 +01:00
|
|
|
sighandlers[SIGFPE] = SIG_DFL;
|
2018-07-26 00:05:52 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE(float_exception_map); i++)
|
2007-02-08 21:33:33 +01:00
|
|
|
{
|
2005-05-13 19:44:28 +02:00
|
|
|
if (float_exception_map[i].status ==
|
2007-02-08 21:33:33 +01:00
|
|
|
except->ExceptionRecord->ExceptionCode)
|
2005-05-13 19:44:28 +02:00
|
|
|
{
|
|
|
|
float_signal = float_exception_map[i].signal;
|
|
|
|
break;
|
|
|
|
}
|
2007-02-08 21:33:33 +01:00
|
|
|
}
|
2013-03-05 11:05:42 +01:00
|
|
|
|
|
|
|
old_ep = *ep;
|
|
|
|
*ep = except;
|
2020-12-01 13:52:20 +01:00
|
|
|
((float_handler)handler)(SIGFPE, float_signal);
|
2013-03-05 11:05:42 +01:00
|
|
|
*ep = old_ep;
|
2005-05-13 19:44:28 +02:00
|
|
|
}
|
|
|
|
ret = EXCEPTION_CONTINUE_EXECUTION;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case EXCEPTION_ILLEGAL_INSTRUCTION:
|
2008-03-24 21:53:49 +01:00
|
|
|
case EXCEPTION_PRIV_INSTRUCTION:
|
2020-12-01 13:52:20 +01:00
|
|
|
if ((handler = sighandlers[SIGILL]) != SIG_DFL)
|
2005-05-13 19:44:28 +02:00
|
|
|
{
|
2020-12-01 13:52:20 +01:00
|
|
|
if (handler != SIG_IGN)
|
2007-02-08 21:33:33 +01:00
|
|
|
{
|
2020-12-02 00:53:42 +01:00
|
|
|
EXCEPTION_POINTERS **ep = (EXCEPTION_POINTERS**)__pxcptinfoptrs(), *old_ep;
|
2013-03-05 11:05:42 +01:00
|
|
|
|
|
|
|
old_ep = *ep;
|
|
|
|
*ep = except;
|
2020-12-01 13:52:20 +01:00
|
|
|
sighandlers[SIGILL] = SIG_DFL;
|
|
|
|
handler(SIGILL);
|
2013-03-05 11:05:42 +01:00
|
|
|
*ep = old_ep;
|
2007-02-08 21:33:33 +01:00
|
|
|
}
|
2005-05-13 19:44:28 +02:00
|
|
|
ret = EXCEPTION_CONTINUE_EXECUTION;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void msvcrt_init_signals(void)
|
|
|
|
{
|
|
|
|
SetConsoleCtrlHandler(msvcrt_console_handler, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void msvcrt_free_signals(void)
|
|
|
|
{
|
|
|
|
SetConsoleCtrlHandler(msvcrt_console_handler, FALSE);
|
|
|
|
}
|
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* signal (MSVCRT.@)
|
2005-05-13 19:44:28 +02:00
|
|
|
* Some signals may never be generated except through an explicit call to
|
|
|
|
* raise.
|
2001-01-11 00:59:25 +01:00
|
|
|
*/
|
2020-12-02 00:53:42 +01:00
|
|
|
__sighandler_t CDECL signal(int sig, __sighandler_t func)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2020-12-01 13:52:20 +01:00
|
|
|
__sighandler_t ret = SIG_ERR;
|
2005-05-13 19:44:28 +02:00
|
|
|
|
|
|
|
TRACE("(%d, %p)\n", sig, func);
|
|
|
|
|
2020-12-01 13:52:20 +01:00
|
|
|
if (func == SIG_ERR) return SIG_ERR;
|
2005-05-13 19:44:28 +02:00
|
|
|
|
|
|
|
switch (sig)
|
|
|
|
{
|
|
|
|
/* Cases handled internally. Note SIGTERM is never generated by Windows,
|
|
|
|
* so we effectively mask it.
|
|
|
|
*/
|
2020-12-01 13:52:20 +01:00
|
|
|
case SIGABRT:
|
|
|
|
case SIGFPE:
|
|
|
|
case SIGILL:
|
|
|
|
case SIGSEGV:
|
|
|
|
case SIGINT:
|
|
|
|
case SIGTERM:
|
|
|
|
case SIGBREAK:
|
2005-05-13 19:44:28 +02:00
|
|
|
ret = sighandlers[sig];
|
|
|
|
sighandlers[sig] = func;
|
|
|
|
break;
|
|
|
|
default:
|
2020-12-01 13:52:20 +01:00
|
|
|
ret = SIG_ERR;
|
2005-05-13 19:44:28 +02:00
|
|
|
}
|
|
|
|
return ret;
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
2005-05-19 16:21:21 +02:00
|
|
|
|
2007-02-08 21:33:39 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* raise (MSVCRT.@)
|
|
|
|
*/
|
2020-12-02 00:53:42 +01:00
|
|
|
int CDECL raise(int sig)
|
2007-02-08 21:33:39 +01:00
|
|
|
{
|
2020-12-01 13:52:20 +01:00
|
|
|
__sighandler_t handler;
|
2007-02-08 21:33:39 +01:00
|
|
|
|
|
|
|
TRACE("(%d)\n", sig);
|
|
|
|
|
|
|
|
switch (sig)
|
|
|
|
{
|
2020-12-01 13:52:20 +01:00
|
|
|
case SIGFPE:
|
|
|
|
case SIGILL:
|
|
|
|
case SIGSEGV:
|
2007-02-08 21:33:39 +01:00
|
|
|
handler = sighandlers[sig];
|
2020-12-02 00:53:47 +01:00
|
|
|
if (handler == SIG_DFL) _exit(3);
|
2020-12-01 13:52:20 +01:00
|
|
|
if (handler != SIG_IGN)
|
2007-02-08 21:33:39 +01:00
|
|
|
{
|
2020-12-02 00:53:42 +01:00
|
|
|
EXCEPTION_POINTERS **ep = (EXCEPTION_POINTERS**)__pxcptinfoptrs(), *old_ep;
|
2013-03-05 11:05:42 +01:00
|
|
|
|
2020-12-01 13:52:20 +01:00
|
|
|
sighandlers[sig] = SIG_DFL;
|
2013-03-05 11:05:42 +01:00
|
|
|
|
|
|
|
old_ep = *ep;
|
|
|
|
*ep = NULL;
|
2020-12-01 13:52:20 +01:00
|
|
|
if (sig == SIGFPE)
|
2020-12-01 13:52:16 +01:00
|
|
|
((float_handler)handler)(sig, _FPE_EXPLICITGEN);
|
2007-02-08 21:33:39 +01:00
|
|
|
else
|
|
|
|
handler(sig);
|
2013-03-05 11:05:42 +01:00
|
|
|
*ep = old_ep;
|
|
|
|
}
|
|
|
|
break;
|
2020-12-01 13:52:20 +01:00
|
|
|
case SIGABRT:
|
|
|
|
case SIGINT:
|
|
|
|
case SIGTERM:
|
|
|
|
case SIGBREAK:
|
2013-03-05 11:05:42 +01:00
|
|
|
handler = sighandlers[sig];
|
2020-12-02 00:53:47 +01:00
|
|
|
if (handler == SIG_DFL) _exit(3);
|
2020-12-01 13:52:20 +01:00
|
|
|
if (handler != SIG_IGN)
|
2013-03-05 11:05:42 +01:00
|
|
|
{
|
2020-12-01 13:52:20 +01:00
|
|
|
sighandlers[sig] = SIG_DFL;
|
2013-03-05 11:05:42 +01:00
|
|
|
handler(sig);
|
2007-02-08 21:33:39 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-05-19 16:21:21 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _XcptFilter (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
int CDECL _XcptFilter(NTSTATUS ex, PEXCEPTION_POINTERS ptr)
|
2005-05-19 16:21:21 +02:00
|
|
|
{
|
2006-10-03 20:39:05 +02:00
|
|
|
TRACE("(%08x,%p)\n", ex, ptr);
|
2005-05-19 16:21:21 +02:00
|
|
|
/* I assume ptr->ExceptionRecord->ExceptionCode is the same as ex */
|
|
|
|
return msvcrt_exception_filter(ptr);
|
|
|
|
}
|
2009-10-03 13:13:37 +02:00
|
|
|
|
2010-04-12 17:52:32 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _abnormal_termination (MSVCRT.@)
|
|
|
|
*/
|
2020-12-16 13:50:15 +01:00
|
|
|
int CDECL __intrinsic_abnormal_termination(void)
|
2010-04-12 17:52:32 +02:00
|
|
|
{
|
|
|
|
FIXME("(void)stub\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-10-03 13:13:37 +02:00
|
|
|
/******************************************************************
|
2014-04-21 14:32:40 +02:00
|
|
|
* __uncaught_exception (MSVCRT.@)
|
2009-10-03 13:13:37 +02:00
|
|
|
*/
|
2020-12-02 00:53:42 +01:00
|
|
|
BOOL CDECL __uncaught_exception(void)
|
2009-10-03 13:13:37 +02:00
|
|
|
{
|
2018-03-20 15:36:54 +01:00
|
|
|
return msvcrt_get_thread_data()->processing_throw != 0;
|
2009-10-03 13:13:37 +02:00
|
|
|
}
|
2011-03-16 09:22:24 +01:00
|
|
|
|
2018-01-10 07:21:42 +01:00
|
|
|
#if _MSVCR_VER>=70 && _MSVCR_VER<=71
|
|
|
|
|
2014-04-21 14:32:40 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _set_security_error_handler (MSVCR70.@)
|
|
|
|
*/
|
2011-03-16 09:22:24 +01:00
|
|
|
MSVCRT_security_error_handler CDECL _set_security_error_handler(
|
|
|
|
MSVCRT_security_error_handler handler )
|
|
|
|
{
|
|
|
|
MSVCRT_security_error_handler old = security_error_handler;
|
|
|
|
|
|
|
|
TRACE("(%p)\n", handler);
|
|
|
|
|
|
|
|
security_error_handler = handler;
|
|
|
|
return old;
|
|
|
|
}
|
2013-10-25 14:12:43 +02:00
|
|
|
|
2014-04-21 14:32:40 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* __security_error_handler (MSVCR70.@)
|
|
|
|
*/
|
2013-10-25 14:12:43 +02:00
|
|
|
void CDECL __security_error_handler(int code, void *data)
|
|
|
|
{
|
|
|
|
if(security_error_handler)
|
|
|
|
security_error_handler(code, data);
|
|
|
|
else
|
|
|
|
FIXME("(%d, %p) stub\n", code, data);
|
|
|
|
|
2020-12-02 00:53:47 +01:00
|
|
|
_exit(3);
|
2013-10-25 14:12:43 +02:00
|
|
|
}
|
2014-04-17 13:07:21 +02:00
|
|
|
|
2018-01-10 07:21:42 +01:00
|
|
|
#endif /* _MSVCR_VER>=70 && _MSVCR_VER<=71 */
|
|
|
|
|
2018-01-07 06:05:31 +01:00
|
|
|
#if _MSVCR_VER>=110
|
2014-04-17 13:07:21 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* __crtSetUnhandledExceptionFilter (MSVCR110.@)
|
|
|
|
*/
|
2020-12-02 00:53:42 +01:00
|
|
|
LPTOP_LEVEL_EXCEPTION_FILTER CDECL __crtSetUnhandledExceptionFilter(LPTOP_LEVEL_EXCEPTION_FILTER filter)
|
2014-04-17 13:07:21 +02:00
|
|
|
{
|
|
|
|
return SetUnhandledExceptionFilter(filter);
|
|
|
|
}
|
2018-01-07 06:05:31 +01:00
|
|
|
#endif
|
2016-03-16 21:01:50 +01:00
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _CreateFrameInfo (MSVCR80.@)
|
|
|
|
*/
|
|
|
|
frame_info* CDECL _CreateFrameInfo(frame_info *fi, void *obj)
|
|
|
|
{
|
|
|
|
thread_data_t *data = msvcrt_get_thread_data();
|
|
|
|
|
|
|
|
TRACE("(%p, %p)\n", fi, obj);
|
|
|
|
|
|
|
|
fi->next = data->frame_info_head;
|
|
|
|
data->frame_info_head = fi;
|
|
|
|
fi->object = obj;
|
|
|
|
return fi;
|
|
|
|
}
|
2016-03-16 21:01:55 +01:00
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _FindAndUnlinkFrame (MSVCR80.@)
|
|
|
|
*/
|
|
|
|
void CDECL _FindAndUnlinkFrame(frame_info *fi)
|
|
|
|
{
|
|
|
|
thread_data_t *data = msvcrt_get_thread_data();
|
|
|
|
frame_info *cur = data->frame_info_head;
|
|
|
|
|
|
|
|
TRACE("(%p)\n", fi);
|
|
|
|
|
|
|
|
if (cur == fi)
|
|
|
|
{
|
|
|
|
data->frame_info_head = cur->next;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (; cur->next; cur = cur->next)
|
|
|
|
{
|
|
|
|
if (cur->next == fi)
|
|
|
|
{
|
|
|
|
cur->next = fi->next;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ERR("frame not found, native crashes in this case\n");
|
|
|
|
}
|
2016-03-16 21:02:04 +01:00
|
|
|
|
2016-03-16 21:03:19 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _IsExceptionObjectToBeDestroyed (MSVCR80.@)
|
|
|
|
*/
|
|
|
|
BOOL __cdecl _IsExceptionObjectToBeDestroyed(const void *obj)
|
|
|
|
{
|
|
|
|
frame_info *cur;
|
|
|
|
|
|
|
|
TRACE( "%p\n", obj );
|
|
|
|
|
|
|
|
for (cur = msvcrt_get_thread_data()->frame_info_head; cur; cur = cur->next)
|
|
|
|
{
|
|
|
|
if (cur->object == obj)
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2016-03-16 21:02:08 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* __DestructExceptionObject (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
void CDECL __DestructExceptionObject(EXCEPTION_RECORD *rec)
|
|
|
|
{
|
|
|
|
cxx_exception_type *info = (cxx_exception_type*) rec->ExceptionInformation[2];
|
|
|
|
void *object = (void*)rec->ExceptionInformation[1];
|
|
|
|
|
|
|
|
TRACE("(%p)\n", rec);
|
|
|
|
|
2016-03-18 12:40:25 +01:00
|
|
|
if (rec->ExceptionCode != CXX_EXCEPTION) return;
|
|
|
|
#ifndef __x86_64__
|
|
|
|
if (rec->NumberParameters != 3) return;
|
|
|
|
#else
|
|
|
|
if (rec->NumberParameters != 4) return;
|
|
|
|
#endif
|
|
|
|
if (rec->ExceptionInformation[0] < CXX_FRAME_MAGIC_VC6 ||
|
|
|
|
rec->ExceptionInformation[0] > CXX_FRAME_MAGIC_VC8) return;
|
|
|
|
|
2016-03-16 21:02:08 +01:00
|
|
|
if (!info || !info->destructor)
|
|
|
|
return;
|
|
|
|
|
|
|
|
#if defined(__i386__)
|
|
|
|
__asm__ __volatile__("call *%0" : : "r" (info->destructor), "c" (object) : "eax", "edx", "memory" );
|
|
|
|
#elif defined(__x86_64__)
|
|
|
|
((void (__cdecl*)(void*))(info->destructor+rec->ExceptionInformation[3]))(object);
|
|
|
|
#else
|
|
|
|
((void (__cdecl*)(void*))info->destructor)(object);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2016-03-16 21:02:04 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* __CxxRegisterExceptionObject (MSVCRT.@)
|
|
|
|
*/
|
2018-03-20 15:36:43 +01:00
|
|
|
BOOL CDECL __CxxRegisterExceptionObject(EXCEPTION_POINTERS *ep, cxx_frame_info *frame_info)
|
2016-03-16 21:02:04 +01:00
|
|
|
{
|
|
|
|
thread_data_t *data = msvcrt_get_thread_data();
|
|
|
|
|
2018-03-20 15:36:43 +01:00
|
|
|
TRACE("(%p, %p)\n", ep, frame_info);
|
2016-03-16 21:02:04 +01:00
|
|
|
|
2018-03-20 15:36:43 +01:00
|
|
|
if (!ep || !ep->ExceptionRecord)
|
2016-03-16 21:02:04 +01:00
|
|
|
{
|
|
|
|
frame_info->rec = (void*)-1;
|
2018-03-20 15:36:43 +01:00
|
|
|
frame_info->context = (void*)-1;
|
2016-03-16 21:02:04 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
frame_info->rec = data->exc_record;
|
2018-03-20 15:36:43 +01:00
|
|
|
frame_info->context = data->ctx_record;
|
|
|
|
data->exc_record = ep->ExceptionRecord;
|
|
|
|
data->ctx_record = ep->ContextRecord;
|
|
|
|
_CreateFrameInfo(&frame_info->frame_info, (void*)ep->ExceptionRecord->ExceptionInformation[1]);
|
2016-03-16 21:02:04 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
2016-03-16 21:02:45 +01:00
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* __CxxUnregisterExceptionObject (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
void CDECL __CxxUnregisterExceptionObject(cxx_frame_info *frame_info, BOOL in_use)
|
|
|
|
{
|
|
|
|
thread_data_t *data = msvcrt_get_thread_data();
|
|
|
|
|
2016-03-16 21:03:19 +01:00
|
|
|
TRACE("(%p)\n", frame_info);
|
2016-03-16 21:02:45 +01:00
|
|
|
|
|
|
|
if(frame_info->rec == (void*)-1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
_FindAndUnlinkFrame(&frame_info->frame_info);
|
2016-03-16 21:03:19 +01:00
|
|
|
if(data->exc_record->ExceptionCode == CXX_EXCEPTION && !in_use
|
|
|
|
&& _IsExceptionObjectToBeDestroyed((void*)data->exc_record->ExceptionInformation[1]))
|
2016-03-16 21:02:45 +01:00
|
|
|
__DestructExceptionObject(data->exc_record);
|
|
|
|
data->exc_record = frame_info->rec;
|
2018-03-20 15:36:43 +01:00
|
|
|
data->ctx_record = frame_info->context;
|
2016-03-16 21:02:45 +01:00
|
|
|
}
|
2016-04-11 23:19:00 +02:00
|
|
|
|
|
|
|
struct __std_exception_data {
|
2020-11-27 14:17:05 +01:00
|
|
|
char *what;
|
|
|
|
bool dofree;
|
2016-04-11 23:19:00 +02:00
|
|
|
};
|
|
|
|
|
2018-01-10 07:21:42 +01:00
|
|
|
#if _MSVCR_VER>=140
|
|
|
|
|
2016-04-11 23:19:00 +02:00
|
|
|
/*********************************************************************
|
2018-01-10 07:21:42 +01:00
|
|
|
* __std_exception_copy (UCRTBASE.@)
|
2016-04-11 23:19:00 +02:00
|
|
|
*/
|
2020-12-02 00:53:42 +01:00
|
|
|
void CDECL __std_exception_copy(const struct __std_exception_data *src,
|
2016-04-11 23:19:00 +02:00
|
|
|
struct __std_exception_data *dst)
|
|
|
|
{
|
|
|
|
TRACE("(%p %p)\n", src, dst);
|
|
|
|
|
|
|
|
if(src->dofree && src->what) {
|
2020-12-02 00:54:09 +01:00
|
|
|
dst->what = _strdup(src->what);
|
2016-04-11 23:19:00 +02:00
|
|
|
dst->dofree = 1;
|
|
|
|
} else {
|
|
|
|
dst->what = src->what;
|
|
|
|
dst->dofree = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
2018-01-10 07:21:42 +01:00
|
|
|
* __std_exception_destroy (UCRTBASE.@)
|
2016-04-11 23:19:00 +02:00
|
|
|
*/
|
2020-12-02 00:53:42 +01:00
|
|
|
void CDECL __std_exception_destroy(struct __std_exception_data *data)
|
2016-04-11 23:19:00 +02:00
|
|
|
{
|
|
|
|
TRACE("(%p)\n", data);
|
|
|
|
|
|
|
|
if(data->dofree)
|
2020-12-01 13:51:32 +01:00
|
|
|
free(data->what);
|
2016-04-11 23:19:00 +02:00
|
|
|
data->what = NULL;
|
|
|
|
data->dofree = 0;
|
|
|
|
}
|
2018-01-10 07:21:42 +01:00
|
|
|
|
2018-03-19 17:43:57 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* __current_exception (UCRTBASE.@)
|
|
|
|
*/
|
|
|
|
void** CDECL __current_exception(void)
|
|
|
|
{
|
|
|
|
TRACE("()\n");
|
|
|
|
return (void**)&msvcrt_get_thread_data()->exc_record;
|
|
|
|
}
|
|
|
|
|
2018-03-20 15:36:43 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* __current_exception_context (UCRTBASE.@)
|
|
|
|
*/
|
|
|
|
void** CDECL __current_exception_context(void)
|
|
|
|
{
|
|
|
|
TRACE("()\n");
|
|
|
|
return (void**)&msvcrt_get_thread_data()->ctx_record;
|
|
|
|
}
|
|
|
|
|
2018-03-20 15:36:48 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* __processing_throw (UCRTBASE.@)
|
|
|
|
*/
|
|
|
|
int* CDECL __processing_throw(void)
|
|
|
|
{
|
|
|
|
TRACE("()\n");
|
|
|
|
return &msvcrt_get_thread_data()->processing_throw;
|
|
|
|
}
|
|
|
|
|
2018-01-10 07:21:42 +01:00
|
|
|
#endif /* _MSVCR_VER>=140 */
|