ReactOS 0.4.16-dev-2104-gb84fa49
exit.c File Reference
#include <conio.h>
#include <process.h>
#include <signal.h>
#include <stdio.h>
#include "msvcrt.h"
#include "mtdll.h"
#include "winuser.h"
#include "wine/debug.h"
Include dependency graph for exit.c:

Go to the source code of this file.

Macros

#define LOCK_EXIT   _lock(_EXIT_LOCK1)
 
#define UNLOCK_EXIT   _unlock(_EXIT_LOCK1)
 

Typedefs

typedef void(__stdcall_tls_callback_type) (void *, ULONG, void *)
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (msvcrt)
 
static int initialize_onexit_table (_onexit_table_t *table)
 
static int register_onexit_function (_onexit_table_t *table, _onexit_t func)
 
static int execute_onexit_table (_onexit_table_t *table)
 
static void call_atexit (void)
 
_onexit_t CDECL __dllonexit (_onexit_t func, _onexit_t **start, _onexit_t **end)
 
void CDECL _exit (int exitcode)
 
static void DoMessageBoxW (const wchar_t *lead, const wchar_t *message)
 
static void DoMessageBox (const char *lead, const char *message)
 
void CDECL _amsg_exit (int errnum)
 
void CDECL abort (void)
 
void DECLSPEC_NORETURN CDECL _wassert (const wchar_t *str, const wchar_t *file, unsigned int line)
 
void DECLSPEC_NORETURN CDECL _assert (const char *str, const char *file, unsigned int line)
 
void CDECL _c_exit (void)
 
void CDECL _cexit (void)
 
_onexit_t CDECL _onexit (_onexit_t func)
 
void CDECL exit (int exitcode)
 
int CDECL MSVCRT_atexit (void(__cdecl *func)(void))
 
void CDECL _register_thread_local_exe_atexit_callback (_tls_callback_type callback)
 
void CDECL _purecall (void)
 
int CDECL _set_error_mode (int mode)
 

Variables

static _purecall_handler purecall_handler = NULL
 
static _onexit_table_t MSVCRT_atexit_table
 
static _tls_callback_type tls_atexit_callback
 
static CRITICAL_SECTION MSVCRT_onexit_cs = { &MSVCRT_onexit_cs_debug, -1, 0, 0, 0, 0 }
 
static CRITICAL_SECTION_DEBUG MSVCRT_onexit_cs_debug
 
int MSVCRT_app_type
 
wchar_tMSVCRT__wpgmptr
 
static int MSVCRT_error_mode = _OUT_TO_DEFAULT
 
void(* CDECL )(int) = _exit
 

Macro Definition Documentation

◆ LOCK_EXIT

#define LOCK_EXIT   _lock(_EXIT_LOCK1)

Definition at line 32 of file exit.c.

◆ UNLOCK_EXIT

#define UNLOCK_EXIT   _unlock(_EXIT_LOCK1)

Definition at line 33 of file exit.c.

Typedef Documentation

◆ _tls_callback_type

typedef void(__stdcall * _tls_callback_type) (void *, ULONG, void *)

Definition at line 39 of file exit.c.

Function Documentation

◆ __dllonexit()

_onexit_t CDECL __dllonexit ( _onexit_t  func,
_onexit_t **  start,
_onexit_t **  end 
)

Definition at line 154 of file exit.c.

155{
156 _onexit_t *tmp;
157 int len;
158
159 TRACE("(%p,%p,%p)\n", func, start, end);
160
161 if (!start || !*start || !end || !*end)
162 {
163 FIXME("bad table\n");
164 return NULL;
165 }
166
167 len = (*end - *start);
168
169 TRACE("table start %p-%p, %d entries\n", *start, *end, len);
170
171 if (++len <= 0)
172 return NULL;
173
174 tmp = realloc(*start, len * sizeof(*tmp));
175 if (!tmp)
176 return NULL;
177 *start = tmp;
178 *end = tmp + len;
179 tmp[len - 1] = func;
180 TRACE("new table start %p-%p, %d entries\n", *start, *end, len);
181 return func;
182}
#define FIXME(fmt,...)
Definition: precomp.h:53
#define realloc
Definition: debug_ros.c:6
#define NULL
Definition: types.h:112
int(__cdecl * _onexit_t)(void)
GLuint start
Definition: gl.h:1545
GLuint GLuint end
Definition: gl.h:1545
GLenum func
Definition: glext.h:6028
GLenum GLsizei len
Definition: glext.h:6722
#define TRACE(s)
Definition: solgame.cpp:4

◆ _amsg_exit()

void CDECL _amsg_exit ( int  errnum)

Definition at line 233 of file exit.c.

234{
235 TRACE("(%d)\n", errnum);
236
239 {
240 char text[32];
241 sprintf(text, "Error: R60%d",errnum);
242 DoMessageBox("Runtime error!", text);
243 }
244 else
245 _cprintf("\nruntime error R60%d\n",errnum);
246 _aexit_rtn(255);
247}
aexit_t _aexit_rtn
Definition: amsg.c:39
const WCHAR * text
Definition: package.c:1794
int WINAPIV _cprintf(const char *format,...)
Definition: console.c:563
static void DoMessageBox(const char *lead, const char *message)
Definition: exit.c:220
int MSVCRT_app_type
Definition: data.c:59
static int MSVCRT_error_mode
Definition: exit.c:58
#define _OUT_TO_MSGBOX
Definition: stdlib.h:75
#define _OUT_TO_DEFAULT
Definition: stdlib.h:73
#define sprintf
Definition: sprintf.c:45

Referenced by _purecall(), and msvcrt_get_thread_data().

◆ _assert()

void DECLSPEC_NORETURN CDECL _assert ( const char str,
const char file,
unsigned int  line 
)

Definition at line 314 of file exit.c.

315{
316 wchar_t strW[1024], fileW[1024];
317
318 mbstowcs(strW, str, 1024);
319 mbstowcs(fileW, file, 1024);
320
322}
void DECLSPEC_NORETURN CDECL _wassert(const wchar_t *str, const wchar_t *file, unsigned int line)
Definition: exit.c:293
static const WCHAR fileW[]
Definition: url.c:111
WCHAR strW[12]
Definition: clipboard.c:2025
const WCHAR * str
mbstowcs
Definition: stdlib.h:925
Definition: fci.c:127
Definition: parser.c:49

◆ _c_exit()

void CDECL _c_exit ( void  )

Definition at line 327 of file exit.c.

328{
329 TRACE("(void)\n");
330 /* All cleanup is done on DLL detach; Return to caller */
331}

◆ _cexit()

void CDECL _cexit ( void  )

Definition at line 336 of file exit.c.

337{
338 TRACE("(void)\n");
339 LOCK_EXIT;
340 call_atexit();
342}
#define LOCK_EXIT
Definition: exit.c:32
#define UNLOCK_EXIT
Definition: exit.c:33
static void call_atexit(void)
Definition: exit.c:144

Referenced by exit().

◆ _exit()

void CDECL _exit ( int  exitcode)

Definition at line 187 of file exit.c.

188{
189 TRACE("(%d)\n", exitcode);
190 ExitProcess(exitcode);
191}
VOID WINAPI ExitProcess(IN UINT uExitCode)
Definition: proc.c:1489

Referenced by _amsg_exit(), _CrtHandleDbgReport(), _default_handler(), _wassert(), abort(), common_assert_to_message_box(), do_spawnT(), execute_command(), fork_helper(), msvcrt_spawn(), parse_object_parts(), raise(), START_TEST(), subprocess(), Test__aexit_rtn(), and thread_start().

◆ _onexit()

_onexit_t __cdecl _onexit ( _onexit_t  func)

Definition at line 347 of file exit.c.

348{
349 TRACE("(%p)\n",func);
350
351 if (!func)
352 return NULL;
353
354 LOCK_EXIT;
357
358 return func;
359}
static _onexit_table_t MSVCRT_atexit_table
Definition: exit.c:37
static int register_onexit_function(_onexit_table_t *table, _onexit_t func)
Definition: exit.c:72

Referenced by atexit(), and MSVCRT_atexit().

◆ _purecall()

void CDECL _purecall ( void  )

Definition at line 494 of file exit.c.

495{
496 TRACE("(void)\n");
497
500 _amsg_exit( 25 );
501}
static _purecall_handler purecall_handler
Definition: exit.c:35
void CDECL _amsg_exit(int errnum)
Definition: exit.c:233

◆ _register_thread_local_exe_atexit_callback()

void CDECL _register_thread_local_exe_atexit_callback ( _tls_callback_type  callback)

Definition at line 460 of file exit.c.

461{
462 TRACE("(%p)\n", callback);
464}
static _tls_callback_type tls_atexit_callback
Definition: exit.c:40
static IPrintDialogCallback callback
Definition: printdlg.c:326

◆ _set_error_mode()

int CDECL _set_error_mode ( int  mode)

Definition at line 515 of file exit.c.

516{
517
518 const int old = MSVCRT_error_mode;
519 if ( _REPORT_ERRMODE != mode ) {
521 }
522 return old;
523}
#define _REPORT_ERRMODE
Definition: stdlib.h:76
GLenum mode
Definition: glext.h:6217

Referenced by common_assert(), and should_write_error_to_console().

◆ _wassert()

void DECLSPEC_NORETURN CDECL _wassert ( const wchar_t str,
const wchar_t file,
unsigned int  line 
)

Definition at line 293 of file exit.c.

294{
295 ERR("(%s,%s,%d)\n", debugstr_w(str), debugstr_w(file), line);
296
299 {
300 wchar_t text[2048];
301 _snwprintf(text, sizeof(text), L"File: %ls\nLine: %d\n\nExpression: \"%ls\"", file, line, str);
302 DoMessageBoxW(L"Assertion failed!", text);
303 }
304 else
305 fwprintf(stderr, L"Assertion failed: %ls, file %ls, line %d\n\n", str, file, line);
306
307 raise(SIGABRT);
308 _exit(3);
309}
#define ERR(fmt,...)
Definition: precomp.h:57
int CDECL raise(int sig)
Definition: except.c:682
static void DoMessageBoxW(const wchar_t *lead, const wchar_t *message)
Definition: exit.c:194
void CDECL _exit(int exitcode)
Definition: exit.c:187
int WINAPIV fwprintf(FILE *file, const wchar_t *format,...)
Definition: file.c:5628
#define stderr
_ACRTIMP int __cdecl _snwprintf(wchar_t *, size_t, const wchar_t *,...)
Definition: wcs.c:1493
#define SIGABRT
Definition: signal.h:31
#define L(x)
Definition: resources.c:13
#define debugstr_w
Definition: kernel32.h:32

Referenced by _assert().

◆ abort()

void CDECL abort ( void  )

Definition at line 252 of file exit.c.

253{
254 TRACE("()\n");
255
256#if (_MSVCR_VER > 0 && _MSVCR_VER < 100) || _MSVCR_VER == 120 || defined(_DEBUG)
257 if (MSVCRT_abort_behavior & _WRITE_ABORT_MSG)
258 {
261 {
262 DoMessageBox("Runtime error!", "abnormal program termination");
263 }
264 else
265 _cputs("\nabnormal program termination\n");
266 }
267#endif
268 raise(SIGABRT);
269 /* in case raise() returns */
270 _exit(3);
271}
int CDECL _cputs(const char *str)
Definition: console.c:78
#define _WRITE_ABORT_MSG
Definition: stdlib.h:79

◆ call_atexit()

static void call_atexit ( void  )
static

Definition at line 144 of file exit.c.

145{
146 /* Note: should only be called with the exit lock held */
149}
#define DLL_PROCESS_DETACH
Definition: compat.h:130
static int execute_onexit_table(_onexit_table_t *table)
Definition: exit.c:113

Referenced by _cexit().

◆ DoMessageBox()

static void DoMessageBox ( const char lead,
const char message 
)
static

Definition at line 220 of file exit.c.

221{
222 wchar_t leadW[1024], messageW[1024];
223
224 mbstowcs(leadW, lead, 1024);
225 mbstowcs(messageW, message, 1024);
226
227 DoMessageBoxW(leadW, messageW);
228}
static const WCHAR messageW[]
Definition: error.c:33
Definition: tftpd.h:60

Referenced by _amsg_exit(), and abort().

◆ DoMessageBoxW()

static void DoMessageBoxW ( const wchar_t lead,
const wchar_t message 
)
static

Definition at line 194 of file exit.c.

195{
196 MSGBOXPARAMSW msgbox;
197 wchar_t text[2048];
198 INT ret;
199
200 _snwprintf(text, ARRAY_SIZE(text), L"%ls\n\nProgram: %ls\n%ls\n\n"
201 L"Press OK to exit the program, or Cancel to start the Wine debugger.\n",
202 lead, MSVCRT__wpgmptr, message);
203
204 msgbox.cbSize = sizeof(msgbox);
205 msgbox.hwndOwner = GetActiveWindow();
206 msgbox.hInstance = 0;
207 msgbox.lpszText = text;
208 msgbox.lpszCaption = L"Wine C++ Runtime Library";
210 msgbox.lpszIcon = NULL;
211 msgbox.dwContextHelpId = 0;
212 msgbox.lpfnMsgBoxCallback = NULL;
213 msgbox.dwLanguageId = LANG_NEUTRAL;
214
215 ret = MessageBoxIndirectW(&msgbox);
216 if (ret == IDCANCEL)
217 DebugBreak();
218}
#define ARRAY_SIZE(A)
Definition: main.h:20
wchar_t * MSVCRT__wpgmptr
Definition: data.c:61
return ret
Definition: mutex.c:146
#define LANG_NEUTRAL
Definition: nls.h:22
DWORD dwLanguageId
Definition: winuser.h:3447
LPCWSTR lpszCaption
Definition: winuser.h:3442
DWORD_PTR dwContextHelpId
Definition: winuser.h:3445
HWND hwndOwner
Definition: winuser.h:3439
LPCWSTR lpszIcon
Definition: winuser.h:3444
MSGBOXCALLBACK lpfnMsgBoxCallback
Definition: winuser.h:3446
LPCWSTR lpszText
Definition: winuser.h:3441
HINSTANCE hInstance
Definition: winuser.h:3440
DWORD dwStyle
Definition: winuser.h:3443
int32_t INT
Definition: typedefs.h:58
void WINAPI DebugBreak(void)
HWND WINAPI GetActiveWindow(void)
Definition: winpos.c:138
#define IDCANCEL
Definition: winuser.h:842
#define MB_ICONERROR
Definition: winuser.h:798
#define MB_OKCANCEL
Definition: winuser.h:815
int WINAPI MessageBoxIndirectW(_In_ CONST MSGBOXPARAMSW *lpmbp)

Referenced by _wassert(), and DoMessageBox().

◆ execute_onexit_table()

static int execute_onexit_table ( _onexit_table_t table)
static

Definition at line 113 of file exit.c.

114{
116 _PVFV *func;
117
118 if (!table)
119 return -1;
120
122 if (!table->_first || table->_first >= table->_last)
123 {
125 return 0;
126 }
127 copy._first = table->_first;
128 copy._last = table->_last;
129 copy._end = table->_end;
130 memset(table, 0, sizeof(*table));
133
134 for (func = copy._last - 1; func >= copy._first; func--)
135 {
136 if (*func)
137 (*func)();
138 }
139
140 free(copy._first);
141 return 0;
142}
INT copy(TCHAR source[MAX_PATH], TCHAR dest[MAX_PATH], INT append, DWORD lpdwFlags, BOOL bTouch)
Definition: copy.c:51
#define free
Definition: debug_ros.c:5
static CRITICAL_SECTION MSVCRT_onexit_cs
Definition: exit.c:42
static int initialize_onexit_table(_onexit_table_t *table)
Definition: exit.c:62
void(__cdecl * _PVFV)(void)
#define memset(x, y, z)
Definition: compat.h:39
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)

Referenced by call_atexit().

◆ exit()

void CDECL exit ( int  exitcode)

Definition at line 364 of file exit.c.

365{
367 void (WINAPI *pCorExitProcess)(int);
368
369 TRACE("(%d)\n",exitcode);
370 _cexit();
371
372 hmscoree = GetModuleHandleW(L"mscoree");
373
374 if (hmscoree)
375 {
376 pCorExitProcess = (void*)GetProcAddress(hmscoree, "CorExitProcess");
377
378 if (pCorExitProcess)
379 pCorExitProcess(exitcode);
380 }
381
382 ExitProcess(exitcode);
383}
#define GetProcAddress(x, y)
Definition: compat.h:753
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:838
void CDECL _cexit(void)
Definition: exit.c:336
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
static HMODULE hmscoree
Definition: fusion.c:24
#define WINAPI
Definition: msvc.h:6

◆ initialize_onexit_table()

static int initialize_onexit_table ( _onexit_table_t table)
static

Definition at line 62 of file exit.c.

63{
64 if (!table)
65 return -1;
66
67 if (table->_first == table->_end)
68 table->_last = table->_end = table->_first = NULL;
69 return 0;
70}

Referenced by execute_onexit_table().

◆ MSVCRT_atexit()

int CDECL MSVCRT_atexit ( void(__cdecl *func)(void )

Definition at line 388 of file exit.c.

389{
390 TRACE("(%p)\n", func);
391 return _onexit((_onexit_t)func) == (_onexit_t)func ? 0 : -1;
392}
_onexit_t CDECL _onexit(_onexit_t func)
Definition: exit.c:347

◆ register_onexit_function()

static int register_onexit_function ( _onexit_table_t table,
_onexit_t  func 
)
static

Definition at line 72 of file exit.c.

73{
74 if (!table)
75 return -1;
76
78 if (!table->_first)
79 {
80 table->_first = calloc(32, sizeof(void *));
81 if (!table->_first)
82 {
83 WARN("failed to allocate initial table.\n");
85 return -1;
86 }
87 table->_last = table->_first;
88 table->_end = table->_first + 32;
89 }
90
91 /* grow if full */
92 if (table->_last == table->_end)
93 {
94 int len = table->_end - table->_first;
95 _PVFV *tmp = realloc(table->_first, 2 * len * sizeof(void *));
96 if (!tmp)
97 {
98 WARN("failed to grow table.\n");
100 return -1;
101 }
102 table->_first = tmp;
103 table->_end = table->_first + 2 * len;
104 table->_last = table->_first + len;
105 }
106
107 *table->_last = (_PVFV)func;
108 table->_last++;
110 return 0;
111}
#define WARN(fmt,...)
Definition: precomp.h:61
#define calloc
Definition: rosglue.h:14

Referenced by _onexit().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( msvcrt  )

Variable Documentation

◆ CDECL

void(* CDECL) (int) ( int  ) = _exit

Definition at line 60 of file exit.c.

◆ MSVCRT__wpgmptr

wchar_t* MSVCRT__wpgmptr
extern

Definition at line 61 of file data.c.

Referenced by __p__wpgmptr(), _get_wpgmptr(), DoMessageBoxW(), msvcrt_free_args(), and msvcrt_init_args().

◆ MSVCRT_app_type

int MSVCRT_app_type
extern

Definition at line 59 of file data.c.

Referenced by __set_app_type(), _amsg_exit(), _wassert(), and abort().

◆ MSVCRT_atexit_table

_onexit_table_t MSVCRT_atexit_table
static

Definition at line 37 of file exit.c.

Referenced by _onexit(), and call_atexit().

◆ MSVCRT_error_mode

int MSVCRT_error_mode = _OUT_TO_DEFAULT
static

Definition at line 58 of file exit.c.

Referenced by _amsg_exit(), _set_error_mode(), _wassert(), and abort().

◆ MSVCRT_onexit_cs

static CRITICAL_SECTION MSVCRT_onexit_cs = { &MSVCRT_onexit_cs_debug, -1, 0, 0, 0, 0 }
static

Definition at line 42 of file exit.c.

Referenced by execute_onexit_table(), and register_onexit_function().

◆ MSVCRT_onexit_cs_debug

CRITICAL_SECTION_DEBUG MSVCRT_onexit_cs_debug
static
Initial value:
=
{
0, 0, { (DWORD_PTR)(__FILE__ ": MSVCRT_onexit_cs") }
}
static CRITICAL_SECTION_DEBUG MSVCRT_onexit_cs_debug
Definition: exit.c:43
#define DWORD_PTR
Definition: treelist.c:76

Definition at line 43 of file exit.c.

◆ purecall_handler

_purecall_handler purecall_handler = NULL
static

Definition at line 35 of file exit.c.

Referenced by _purecall().

◆ tls_atexit_callback

_tls_callback_type tls_atexit_callback
static

Definition at line 40 of file exit.c.

Referenced by _register_thread_local_exe_atexit_callback(), and call_atexit().