[sys] Use a jump buffer to exit to main

This allows tracy to clean up properly. However, Sys_Quit will use the
jump buffer (sys_exit_jmpbuf) only if it has been set, so the use of
Sys_setjmp is optional.
This commit is contained in:
Bill Currie 2023-12-05 18:54:57 +09:00
parent df51e1a18d
commit d908016606
10 changed files with 39 additions and 0 deletions

View file

@ -206,6 +206,8 @@ typedef intptr_t sys_jmpbuf[5];
#define Sys_setjmp(jmpbuf) __builtin_setjmp(jmpbuf)
void Sys_longjmp (sys_jmpbuf jmpbuf) __attribute__((noreturn));
extern sys_jmpbuf sys_exit_jmpbuf;
///@}
#endif//__QF_sys_h

View file

@ -540,11 +540,16 @@ Sys_Init_Cvars (void)
Cvar_Register (&sys_sleep_cvar, 0, 0);
}
static sys_jmpbuf sys_exit_cmpbuf;
sys_jmpbuf sys_exit_jmpbuf;
VISIBLE void
Sys_Quit (void)
{
Sys_Shutdown ();
if (memcmp (sys_exit_cmpbuf, sys_exit_jmpbuf, sizeof (sys_exit_cmpbuf))) {
Sys_longjmp (sys_exit_jmpbuf);
}
exit (0);
}

View file

@ -68,6 +68,10 @@ main (int argc, const char **argv)
{
double time, oldtime, newtime;
if (Sys_setjmp (sys_exit_jmpbuf)) {
exit (0);
}
memset (&host_parms, 0, sizeof (host_parms));
COM_InitArgv (argc, argv);

View file

@ -66,6 +66,10 @@ main (int argc, const char **argv)
double time, oldtime, newtime;
int i;
if (Sys_setjmp (sys_exit_jmpbuf)) {
exit (0);
}
memset (&host_parms, 0, sizeof (host_parms));
// dedicated server ONLY!

View file

@ -163,6 +163,10 @@ WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,
if (hPrevInstance)
return 0;
if (Sys_setjmp (sys_exit_jmpbuf)) {
exit (0);
}
startup ();
global_hInstance = hInstance;

View file

@ -49,6 +49,10 @@ main (int argc, const char **argv)
double time, oldtime, newtime;
int i;
if (Sys_setjmp (sys_exit_jmpbuf)) {
exit (0);
}
memset (&host_parms, 0, sizeof (host_parms));
// dedicated server ONLY!

View file

@ -65,6 +65,10 @@ main (int argc, const char **argv)
{
double time, oldtime, newtime;
if (Sys_setjmp (sys_exit_jmpbuf)) {
exit (0);
}
memset (&host_parms, 0, sizeof (host_parms));
COM_InitArgv (argc, argv);

View file

@ -127,6 +127,10 @@ WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,
if (hPrevInstance)
return 0;
if (Sys_setjmp (sys_exit_jmpbuf)) {
exit (0);
}
startup ();
global_hInstance = hInstance;

View file

@ -112,6 +112,10 @@ main (int argc, const char **argv)
{
double time, oldtime, newtime;
if (Sys_setjmp (sys_exit_jmpbuf)) {
exit (0);
}
startup ();
memset (&host_parms, 0, sizeof (host_parms));

View file

@ -70,6 +70,10 @@ main (int argc, const char **argv)
{
double time, oldtime, newtime;
if (Sys_setjmp (sys_exit_jmpbuf)) {
exit (0);
}
startup ();
memset (&host_parms, 0, sizeof (host_parms));