2001-01-11 00:59:25 +01:00
|
|
|
/*
|
|
|
|
* msvcrt.dll exit functions
|
|
|
|
*
|
|
|
|
* Copyright 2000 Jon Griffiths
|
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
|
2001-01-11 00:59:25 +01:00
|
|
|
*/
|
2003-03-15 23:25:01 +01:00
|
|
|
#include <stdio.h>
|
2001-01-11 00:59:25 +01:00
|
|
|
#include "msvcrt.h"
|
2002-02-21 21:22:00 +01:00
|
|
|
#include "mtdll.h"
|
2003-03-15 23:25:01 +01:00
|
|
|
#include "winuser.h"
|
2002-01-22 01:57:16 +01:00
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
|
2001-01-11 00:59:25 +01:00
|
|
|
|
|
|
|
/* MT */
|
2002-02-21 21:22:00 +01:00
|
|
|
#define LOCK_EXIT _mlock(_EXIT_LOCK1)
|
|
|
|
#define UNLOCK_EXIT _munlock(_EXIT_LOCK1)
|
2001-01-11 00:59:25 +01:00
|
|
|
|
2010-08-25 14:46:47 +02:00
|
|
|
static MSVCRT_purecall_handler purecall_handler = NULL;
|
2001-01-11 00:59:25 +01:00
|
|
|
|
2018-06-23 14:58:28 +02:00
|
|
|
static MSVCRT__onexit_table_t MSVCRT_atexit_table;
|
2018-07-09 18:04:09 +02:00
|
|
|
|
2017-09-20 16:06:13 +02:00
|
|
|
typedef void (__stdcall *_tls_callback_type)(void*,ULONG,void*);
|
|
|
|
static _tls_callback_type tls_atexit_callback;
|
|
|
|
|
2019-03-29 11:37:27 +01:00
|
|
|
static CRITICAL_SECTION MSVCRT_onexit_cs;
|
|
|
|
static CRITICAL_SECTION_DEBUG MSVCRT_onexit_cs_debug =
|
|
|
|
{
|
|
|
|
0, 0, &MSVCRT_onexit_cs,
|
|
|
|
{ &MSVCRT_onexit_cs_debug.ProcessLocksList, &MSVCRT_onexit_cs_debug.ProcessLocksList },
|
|
|
|
0, 0, { (DWORD_PTR)(__FILE__ ": MSVCRT_onexit_cs") }
|
|
|
|
};
|
|
|
|
static CRITICAL_SECTION MSVCRT_onexit_cs = { &MSVCRT_onexit_cs_debug, -1, 0, 0, 0, 0 };
|
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
extern int MSVCRT_app_type;
|
2011-04-05 17:06:45 +02:00
|
|
|
extern MSVCRT_wchar_t *MSVCRT__wpgmptr;
|
2001-01-11 00:59:25 +01:00
|
|
|
|
2011-01-19 23:21:11 +01:00
|
|
|
static unsigned int MSVCRT_abort_behavior = MSVCRT__WRITE_ABORT_MSG | MSVCRT__CALL_REPORTFAULT;
|
2011-01-30 23:34:38 +01:00
|
|
|
static int MSVCRT_error_mode = MSVCRT__OUT_TO_DEFAULT;
|
2011-01-19 23:21:11 +01:00
|
|
|
|
2008-07-03 09:08:22 +02:00
|
|
|
void (*CDECL _aexit_rtn)(int) = MSVCRT__exit;
|
2004-01-13 06:45:05 +01:00
|
|
|
|
2019-03-29 11:37:27 +01:00
|
|
|
static int initialize_onexit_table(MSVCRT__onexit_table_t *table)
|
|
|
|
{
|
|
|
|
if (!table)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (table->_first == table->_end)
|
|
|
|
table->_last = table->_end = table->_first = NULL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int register_onexit_function(MSVCRT__onexit_table_t *table, MSVCRT__onexit_t func)
|
|
|
|
{
|
|
|
|
if (!table)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
EnterCriticalSection(&MSVCRT_onexit_cs);
|
|
|
|
if (!table->_first)
|
|
|
|
{
|
|
|
|
table->_first = MSVCRT_calloc(32, sizeof(void *));
|
|
|
|
if (!table->_first)
|
|
|
|
{
|
|
|
|
WARN("failed to allocate initial table.\n");
|
|
|
|
LeaveCriticalSection(&MSVCRT_onexit_cs);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
table->_last = table->_first;
|
|
|
|
table->_end = table->_first + 32;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* grow if full */
|
|
|
|
if (table->_last == table->_end)
|
|
|
|
{
|
|
|
|
int len = table->_end - table->_first;
|
|
|
|
MSVCRT__onexit_t *tmp = MSVCRT_realloc(table->_first, 2 * len * sizeof(void *));
|
|
|
|
if (!tmp)
|
|
|
|
{
|
|
|
|
WARN("failed to grow table.\n");
|
|
|
|
LeaveCriticalSection(&MSVCRT_onexit_cs);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
table->_first = tmp;
|
|
|
|
table->_end = table->_first + 2 * len;
|
|
|
|
table->_last = table->_first + len;
|
|
|
|
}
|
|
|
|
|
|
|
|
*table->_last = func;
|
|
|
|
table->_last++;
|
|
|
|
LeaveCriticalSection(&MSVCRT_onexit_cs);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int execute_onexit_table(MSVCRT__onexit_table_t *table)
|
|
|
|
{
|
|
|
|
MSVCRT__onexit_t *func;
|
|
|
|
MSVCRT__onexit_table_t copy;
|
|
|
|
|
|
|
|
if (!table)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
EnterCriticalSection(&MSVCRT_onexit_cs);
|
|
|
|
if (!table->_first || table->_first >= table->_last)
|
|
|
|
{
|
|
|
|
LeaveCriticalSection(&MSVCRT_onexit_cs);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
copy._first = table->_first;
|
|
|
|
copy._last = table->_last;
|
|
|
|
copy._end = table->_end;
|
|
|
|
memset(table, 0, sizeof(*table));
|
|
|
|
initialize_onexit_table(table);
|
|
|
|
LeaveCriticalSection(&MSVCRT_onexit_cs);
|
|
|
|
|
|
|
|
for (func = copy._last - 1; func >= copy._first; func--)
|
|
|
|
{
|
|
|
|
if (*func)
|
|
|
|
(*func)();
|
|
|
|
}
|
|
|
|
|
|
|
|
MSVCRT_free(copy._first);
|
|
|
|
return 0;
|
|
|
|
}
|
2018-06-23 14:58:28 +02:00
|
|
|
|
|
|
|
static void call_atexit(void)
|
|
|
|
{
|
|
|
|
/* Note: should only be called with the exit lock held */
|
|
|
|
if (tls_atexit_callback) tls_atexit_callback(NULL, DLL_PROCESS_DETACH, NULL);
|
2019-03-29 11:37:27 +01:00
|
|
|
execute_onexit_table(&MSVCRT_atexit_table);
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* __dllonexit (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
MSVCRT__onexit_t CDECL __dllonexit(MSVCRT__onexit_t func, MSVCRT__onexit_t **start, MSVCRT__onexit_t **end)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2004-03-16 20:17:11 +01:00
|
|
|
MSVCRT__onexit_t *tmp;
|
2001-01-22 20:28:07 +01:00
|
|
|
int len;
|
|
|
|
|
|
|
|
TRACE("(%p,%p,%p)\n", func, start, end);
|
|
|
|
|
|
|
|
if (!start || !*start || !end || !*end)
|
|
|
|
{
|
|
|
|
FIXME("bad table\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
len = (*end - *start);
|
|
|
|
|
|
|
|
TRACE("table start %p-%p, %d entries\n", *start, *end, len);
|
|
|
|
|
|
|
|
if (++len <= 0)
|
|
|
|
return NULL;
|
|
|
|
|
2011-10-18 04:48:33 +02:00
|
|
|
tmp = MSVCRT_realloc(*start, len * sizeof(*tmp));
|
2001-01-22 20:28:07 +01:00
|
|
|
if (!tmp)
|
|
|
|
return NULL;
|
|
|
|
*start = tmp;
|
|
|
|
*end = tmp + len;
|
|
|
|
tmp[len - 1] = func;
|
|
|
|
TRACE("new table start %p-%p, %d entries\n", *start, *end, len);
|
|
|
|
return func;
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _exit (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
void CDECL MSVCRT__exit(int exitcode)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
TRACE("(%d)\n", exitcode);
|
|
|
|
ExitProcess(exitcode);
|
|
|
|
}
|
|
|
|
|
2003-03-15 23:25:01 +01:00
|
|
|
/* Print out an error message with an option to debug */
|
2011-04-05 17:06:45 +02:00
|
|
|
static void DoMessageBoxW(const MSVCRT_wchar_t *lead, const MSVCRT_wchar_t *message)
|
2003-03-15 23:25:01 +01:00
|
|
|
{
|
2019-11-06 12:48:09 +01:00
|
|
|
static const MSVCRT_wchar_t message_format[] = {'%','l','s','\n','\n','P','r','o','g','r','a','m',':',' ','%','l','s','\n',
|
|
|
|
'%','l','s','\n','\n','P','r','e','s','s',' ','O','K',' ','t','o',' ','e','x','i','t',' ','t','h','e',' ',
|
2011-04-05 17:06:45 +02:00
|
|
|
'p','r','o','g','r','a','m',',',' ','o','r',' ','C','a','n','c','e','l',' ','t','o',' ','s','t','a','r','t',' ',
|
2016-12-23 12:38:56 +01:00
|
|
|
't','h','e',' ','W','i','n','e',' ','d','e','b','u','g','g','e','r','.','\n',0};
|
2016-12-22 23:06:35 +01:00
|
|
|
static const WCHAR title[] =
|
|
|
|
{'W','i','n','e',' ','C','+','+',' ','R','u','n','t','i','m','e',' ','L','i','b','r','a','r','y',0};
|
2011-04-05 17:06:45 +02:00
|
|
|
|
|
|
|
MSGBOXPARAMSW msgbox;
|
|
|
|
MSVCRT_wchar_t text[2048];
|
2003-03-15 23:25:01 +01:00
|
|
|
INT ret;
|
|
|
|
|
2018-07-26 00:05:52 +02:00
|
|
|
MSVCRT__snwprintf(text, ARRAY_SIZE(text), message_format, lead, MSVCRT__wpgmptr, message);
|
2003-03-15 23:25:01 +01:00
|
|
|
|
|
|
|
msgbox.cbSize = sizeof(msgbox);
|
|
|
|
msgbox.hwndOwner = GetActiveWindow();
|
|
|
|
msgbox.hInstance = 0;
|
2016-12-22 23:06:35 +01:00
|
|
|
msgbox.lpszText = text;
|
|
|
|
msgbox.lpszCaption = title;
|
2003-03-15 23:25:01 +01:00
|
|
|
msgbox.dwStyle = MB_OKCANCEL|MB_ICONERROR;
|
|
|
|
msgbox.lpszIcon = NULL;
|
|
|
|
msgbox.dwContextHelpId = 0;
|
|
|
|
msgbox.lpfnMsgBoxCallback = NULL;
|
|
|
|
msgbox.dwLanguageId = LANG_NEUTRAL;
|
|
|
|
|
2011-04-05 17:06:45 +02:00
|
|
|
ret = MessageBoxIndirectW(&msgbox);
|
2003-03-15 23:25:01 +01:00
|
|
|
if (ret == IDCANCEL)
|
|
|
|
DebugBreak();
|
|
|
|
}
|
|
|
|
|
2011-04-05 17:06:45 +02:00
|
|
|
static void DoMessageBox(const char *lead, const char *message)
|
|
|
|
{
|
|
|
|
MSVCRT_wchar_t leadW[1024], messageW[1024];
|
|
|
|
|
|
|
|
MSVCRT_mbstowcs(leadW, lead, 1024);
|
|
|
|
MSVCRT_mbstowcs(messageW, message, 1024);
|
|
|
|
|
2011-08-06 13:51:16 +02:00
|
|
|
DoMessageBoxW(leadW, messageW);
|
2011-04-05 17:06:45 +02:00
|
|
|
}
|
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _amsg_exit (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
void CDECL _amsg_exit(int errnum)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
TRACE("(%d)\n", errnum);
|
2011-01-30 23:34:38 +01:00
|
|
|
|
|
|
|
if ((MSVCRT_error_mode == MSVCRT__OUT_TO_MSGBOX) ||
|
|
|
|
((MSVCRT_error_mode == MSVCRT__OUT_TO_DEFAULT) && (MSVCRT_app_type == 2)))
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2003-03-15 23:25:01 +01:00
|
|
|
char text[32];
|
2020-06-08 17:20:39 +02:00
|
|
|
MSVCRT_sprintf(text, "Error: R60%d",errnum);
|
2003-03-15 23:25:01 +01:00
|
|
|
DoMessageBox("Runtime error!", text);
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
2003-03-15 23:25:01 +01:00
|
|
|
else
|
|
|
|
_cprintf("\nruntime error R60%d\n",errnum);
|
2004-01-13 06:45:05 +01:00
|
|
|
_aexit_rtn(255);
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* abort (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
void CDECL MSVCRT_abort(void)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2003-03-15 23:25:01 +01:00
|
|
|
TRACE("()\n");
|
2011-01-19 23:21:11 +01:00
|
|
|
|
|
|
|
if (MSVCRT_abort_behavior & MSVCRT__WRITE_ABORT_MSG)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2011-01-30 23:34:38 +01:00
|
|
|
if ((MSVCRT_error_mode == MSVCRT__OUT_TO_MSGBOX) ||
|
|
|
|
((MSVCRT_error_mode == MSVCRT__OUT_TO_DEFAULT) && (MSVCRT_app_type == 2)))
|
2011-01-19 23:21:11 +01:00
|
|
|
{
|
|
|
|
DoMessageBox("Runtime error!", "abnormal program termination");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
_cputs("\nabnormal program termination\n");
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
2007-02-08 21:33:45 +01:00
|
|
|
MSVCRT_raise(MSVCRT_SIGABRT);
|
|
|
|
/* in case raise() returns */
|
2001-01-11 00:59:25 +01:00
|
|
|
MSVCRT__exit(3);
|
|
|
|
}
|
|
|
|
|
2018-01-10 07:21:43 +01:00
|
|
|
#if _MSVCR_VER>=80
|
2011-01-19 23:21:11 +01:00
|
|
|
/*********************************************************************
|
2014-04-21 14:32:40 +02:00
|
|
|
* _set_abort_behavior (MSVCR80.@)
|
2011-01-19 23:21:11 +01:00
|
|
|
*/
|
|
|
|
unsigned int CDECL MSVCRT__set_abort_behavior(unsigned int flags, unsigned int mask)
|
|
|
|
{
|
|
|
|
unsigned int old = MSVCRT_abort_behavior;
|
|
|
|
|
|
|
|
TRACE("%x, %x\n", flags, mask);
|
|
|
|
if (mask & MSVCRT__CALL_REPORTFAULT)
|
|
|
|
FIXME("_WRITE_CALL_REPORTFAULT unhandled\n");
|
|
|
|
|
|
|
|
MSVCRT_abort_behavior = (MSVCRT_abort_behavior & ~mask) | (flags & mask);
|
|
|
|
return old;
|
|
|
|
}
|
2018-01-10 07:21:43 +01:00
|
|
|
#endif
|
2011-01-19 23:21:11 +01:00
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
/*********************************************************************
|
2011-04-05 17:06:45 +02:00
|
|
|
* _wassert (MSVCRT.@)
|
2001-01-11 00:59:25 +01:00
|
|
|
*/
|
2011-04-05 17:06:45 +02:00
|
|
|
void CDECL MSVCRT__wassert(const MSVCRT_wchar_t* str, const MSVCRT_wchar_t* file, unsigned int line)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2011-04-05 17:06:45 +02:00
|
|
|
static const MSVCRT_wchar_t assertion_failed[] = {'A','s','s','e','r','t','i','o','n',' ','f','a','i','l','e','d','!',0};
|
2019-11-06 12:48:04 +01:00
|
|
|
static const MSVCRT_wchar_t format_msgbox[] = {'F','i','l','e',':',' ','%','l','s','\n','L','i','n','e',':',' ','%','d',
|
|
|
|
'\n','\n','E','x','p','r','e','s','s','i','o','n',':',' ','\"','%','l','s','\"',0};
|
2011-04-05 17:06:45 +02:00
|
|
|
static const MSVCRT_wchar_t format_console[] = {'A','s','s','e','r','t','i','o','n',' ','f','a','i','l','e','d',':',' ',
|
2019-11-06 12:48:04 +01:00
|
|
|
'%','l','s',',',' ','f','i','l','e',' ','%','l','s',',',' ','l','i','n','e',' ','%','d','\n','\n',0};
|
2011-04-05 17:06:45 +02:00
|
|
|
|
|
|
|
TRACE("(%s,%s,%d)\n", debugstr_w(str), debugstr_w(file), line);
|
|
|
|
|
2011-01-30 23:34:38 +01:00
|
|
|
if ((MSVCRT_error_mode == MSVCRT__OUT_TO_MSGBOX) ||
|
|
|
|
((MSVCRT_error_mode == MSVCRT__OUT_TO_DEFAULT) && (MSVCRT_app_type == 2)))
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2011-04-05 17:06:45 +02:00
|
|
|
MSVCRT_wchar_t text[2048];
|
|
|
|
MSVCRT__snwprintf(text, sizeof(text), format_msgbox, file, line, str);
|
|
|
|
DoMessageBoxW(assertion_failed, text);
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
2003-03-15 23:25:01 +01:00
|
|
|
else
|
2020-06-29 22:12:22 +02:00
|
|
|
MSVCRT_fwprintf(MSVCRT_stderr, format_console, str, file, line);
|
2011-04-05 17:06:45 +02:00
|
|
|
|
2007-02-08 21:33:45 +01:00
|
|
|
MSVCRT_raise(MSVCRT_SIGABRT);
|
2003-03-15 23:25:01 +01:00
|
|
|
MSVCRT__exit(3);
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
2011-04-05 17:06:45 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _assert (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
void CDECL MSVCRT__assert(const char* str, const char* file, unsigned int line)
|
|
|
|
{
|
|
|
|
MSVCRT_wchar_t strW[1024], fileW[1024];
|
|
|
|
|
|
|
|
MSVCRT_mbstowcs(strW, str, 1024);
|
|
|
|
MSVCRT_mbstowcs(fileW, file, 1024);
|
|
|
|
|
|
|
|
MSVCRT__wassert(strW, fileW, line);
|
|
|
|
}
|
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _c_exit (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
void CDECL MSVCRT__c_exit(void)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
TRACE("(void)\n");
|
|
|
|
/* All cleanup is done on DLL detach; Return to caller */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _cexit (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
void CDECL MSVCRT__cexit(void)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
TRACE("(void)\n");
|
2005-10-21 17:55:20 +02:00
|
|
|
LOCK_EXIT;
|
2018-06-23 14:58:28 +02:00
|
|
|
call_atexit();
|
2005-10-21 17:55:20 +02:00
|
|
|
UNLOCK_EXIT;
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _onexit (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
MSVCRT__onexit_t CDECL MSVCRT__onexit(MSVCRT__onexit_t func)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
TRACE("(%p)\n",func);
|
|
|
|
|
|
|
|
if (!func)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
LOCK_EXIT;
|
2019-03-29 11:37:27 +01:00
|
|
|
register_onexit_function(&MSVCRT_atexit_table, func);
|
2001-01-11 00:59:25 +01:00
|
|
|
UNLOCK_EXIT;
|
2018-06-23 14:58:28 +02:00
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
return func;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* exit (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
void CDECL MSVCRT_exit(int exitcode)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2011-02-21 22:49:59 +01:00
|
|
|
HMODULE hmscoree;
|
|
|
|
static const WCHAR mscoreeW[] = {'m','s','c','o','r','e','e',0};
|
2011-11-05 09:03:45 +01:00
|
|
|
void (WINAPI *pCorExitProcess)(int);
|
2011-02-21 22:49:59 +01:00
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
TRACE("(%d)\n",exitcode);
|
2005-10-21 17:55:20 +02:00
|
|
|
MSVCRT__cexit();
|
2011-02-21 22:49:59 +01:00
|
|
|
|
|
|
|
hmscoree = GetModuleHandleW(mscoreeW);
|
|
|
|
|
|
|
|
if (hmscoree)
|
|
|
|
{
|
|
|
|
pCorExitProcess = (void*)GetProcAddress(hmscoree, "CorExitProcess");
|
|
|
|
|
|
|
|
if (pCorExitProcess)
|
|
|
|
pCorExitProcess(exitcode);
|
|
|
|
}
|
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
ExitProcess(exitcode);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* atexit (MSVCRT.@)
|
|
|
|
*/
|
2018-07-09 18:03:41 +02:00
|
|
|
int CDECL MSVCRT_atexit(void (__cdecl *func)(void))
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
TRACE("(%p)\n", func);
|
2004-03-16 20:17:11 +01:00
|
|
|
return MSVCRT__onexit((MSVCRT__onexit_t)func) == (MSVCRT__onexit_t)func ? 0 : -1;
|
2015-08-26 23:06:35 +02:00
|
|
|
}
|
|
|
|
|
2019-03-29 11:37:27 +01:00
|
|
|
#if _MSVCR_VER >= 140
|
|
|
|
static MSVCRT__onexit_table_t MSVCRT_quick_exit_table;
|
|
|
|
|
2018-07-09 18:03:51 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _crt_at_quick_exit (UCRTBASE.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCRT__crt_at_quick_exit(void (__cdecl *func)(void))
|
|
|
|
{
|
2018-07-09 18:04:09 +02:00
|
|
|
TRACE("(%p)\n", func);
|
2019-03-29 11:37:27 +01:00
|
|
|
return register_onexit_function(&MSVCRT_quick_exit_table, (MSVCRT__onexit_t)func);
|
2018-07-09 18:03:51 +02:00
|
|
|
}
|
|
|
|
|
2018-07-09 18:04:03 +02:00
|
|
|
/*********************************************************************
|
2019-03-29 11:37:27 +01:00
|
|
|
* quick_exit (UCRTBASE.@)
|
2018-07-09 18:04:03 +02:00
|
|
|
*/
|
|
|
|
void CDECL MSVCRT_quick_exit(int exitcode)
|
|
|
|
{
|
2018-07-09 18:04:09 +02:00
|
|
|
TRACE("(%d)\n", exitcode);
|
|
|
|
|
2019-03-29 11:37:27 +01:00
|
|
|
execute_onexit_table(&MSVCRT_quick_exit_table);
|
2018-07-09 18:04:03 +02:00
|
|
|
MSVCRT__exit(exitcode);
|
|
|
|
}
|
|
|
|
|
2015-08-26 23:06:35 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _crt_atexit (UCRTBASE.@)
|
|
|
|
*/
|
2018-07-09 18:03:41 +02:00
|
|
|
int CDECL MSVCRT__crt_atexit(void (__cdecl *func)(void))
|
2015-08-26 23:06:35 +02:00
|
|
|
{
|
|
|
|
TRACE("(%p)\n", func);
|
|
|
|
return MSVCRT__onexit((MSVCRT__onexit_t)func) == (MSVCRT__onexit_t)func ? 0 : -1;
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
2019-03-29 11:37:27 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _initialize_onexit_table (UCRTBASE.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCRT__initialize_onexit_table(MSVCRT__onexit_table_t *table)
|
|
|
|
{
|
|
|
|
TRACE("(%p)\n", table);
|
|
|
|
|
|
|
|
return initialize_onexit_table(table);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _register_onexit_function (UCRTBASE.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCRT__register_onexit_function(MSVCRT__onexit_table_t *table, MSVCRT__onexit_t func)
|
|
|
|
{
|
|
|
|
TRACE("(%p %p)\n", table, func);
|
|
|
|
|
|
|
|
return register_onexit_function(table, func);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _execute_onexit_table (UCRTBASE.@)
|
|
|
|
*/
|
|
|
|
int CDECL MSVCRT__execute_onexit_table(MSVCRT__onexit_table_t *table)
|
|
|
|
{
|
|
|
|
TRACE("(%p)\n", table);
|
|
|
|
|
|
|
|
return execute_onexit_table(table);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-09-20 16:06:13 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _register_thread_local_exe_atexit_callback (UCRTBASE.@)
|
|
|
|
*/
|
|
|
|
void CDECL _register_thread_local_exe_atexit_callback(_tls_callback_type callback)
|
|
|
|
{
|
|
|
|
TRACE("(%p)\n", callback);
|
|
|
|
tls_atexit_callback = callback;
|
|
|
|
}
|
|
|
|
|
2018-01-04 05:33:03 +01:00
|
|
|
#if _MSVCR_VER>=71
|
2014-04-21 14:32:40 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _set_purecall_handler (MSVCR71.@)
|
|
|
|
*/
|
2010-08-25 14:46:47 +02:00
|
|
|
MSVCRT_purecall_handler CDECL _set_purecall_handler(MSVCRT_purecall_handler function)
|
|
|
|
{
|
|
|
|
MSVCRT_purecall_handler ret = purecall_handler;
|
|
|
|
|
|
|
|
TRACE("(%p)\n", function);
|
|
|
|
purecall_handler = function;
|
|
|
|
return ret;
|
|
|
|
}
|
2018-01-04 05:33:03 +01:00
|
|
|
#endif
|
2002-02-22 22:20:39 +01:00
|
|
|
|
2018-01-04 05:33:03 +01:00
|
|
|
#if _MSVCR_VER>=80
|
2017-11-24 19:17:08 +01:00
|
|
|
/*********************************************************************
|
2018-01-04 05:33:03 +01:00
|
|
|
* _get_purecall_handler (MSVCR80.@)
|
2017-11-24 19:17:08 +01:00
|
|
|
*/
|
|
|
|
MSVCRT_purecall_handler CDECL _get_purecall_handler(void)
|
|
|
|
{
|
|
|
|
TRACE("\n");
|
|
|
|
return purecall_handler;
|
|
|
|
}
|
2018-01-04 05:33:03 +01:00
|
|
|
#endif
|
2017-11-24 19:17:08 +01:00
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _purecall (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
void CDECL _purecall(void)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
TRACE("(void)\n");
|
2010-08-25 14:46:47 +02:00
|
|
|
|
|
|
|
if(purecall_handler)
|
|
|
|
purecall_handler();
|
2004-06-25 03:19:15 +02:00
|
|
|
_amsg_exit( 25 );
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
2011-01-30 23:34:38 +01:00
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* _set_error_mode (MSVCRT.@)
|
|
|
|
*
|
|
|
|
* Set the error mode, which describes where the C run-time writes error messages.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* mode - the new error mode
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* The old error mode.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
int CDECL _set_error_mode(int mode)
|
|
|
|
{
|
|
|
|
|
|
|
|
const int old = MSVCRT_error_mode;
|
|
|
|
if ( MSVCRT__REPORT_ERRMODE != mode ) {
|
|
|
|
MSVCRT_error_mode = mode;
|
|
|
|
}
|
|
|
|
return old;
|
|
|
|
}
|