Merge branch 'evil-signal-mutex-hack' into 'master'

Add evil mutex bypass hack in console

Closes #795

See merge request KartKrew/Kart!1766
This commit is contained in:
Eidolon 2024-01-03 21:20:24 +00:00
commit a68c863087
6 changed files with 23 additions and 9 deletions

View file

@ -44,8 +44,12 @@
#ifdef HAVE_THREADS #ifdef HAVE_THREADS
I_mutex con_mutex; I_mutex con_mutex;
# define Lock_state() I_lock_mutex(&con_mutex) // g_in_exiting_signal_handler is an evil hack
# define Unlock_state() I_unlock_mutex(con_mutex) // to avoid infinite SIGABRT recursion in the signal handler
// due to poisoned locks or mach-o kernel not supporting locks in signals
// or something like that. idk
# define Lock_state() if (!g_in_exiting_signal_handler) { I_lock_mutex(&con_mutex); }
# define Unlock_state() if (!g_in_exiting_signal_handler) { I_unlock_mutex(con_mutex); }
#else/*HAVE_THREADS*/ #else/*HAVE_THREADS*/
# define Lock_state() # define Lock_state()
# define Unlock_state() # define Unlock_state()

View file

@ -34,6 +34,9 @@ extern UINT8 graphics_started;
*/ */
extern UINT8 keyboard_started; extern UINT8 keyboard_started;
/** \brief Set to true when inside a signal handler that will exit the program. */
extern boolean g_in_exiting_signal_handler;
/** \brief The I_GetFreeMem function /** \brief The I_GetFreeMem function
\param total total memory in the system \param total total memory in the system

View file

@ -7,9 +7,11 @@
// terms of the GNU General Public License, version 2. // terms of the GNU General Public License, version 2.
// See the 'LICENSE' file for more details. // See the 'LICENSE' file for more details.
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
/// \file k_botitem.c /// \file k_botitem.cpp
/// \brief Bot item usage logic /// \brief Bot item usage logic
#include <algorithm>
#include <tracy/tracy/Tracy.hpp> #include <tracy/tracy/Tracy.hpp>
#include "doomdef.h" #include "doomdef.h"

View file

@ -7,9 +7,11 @@
// terms of the GNU General Public License, version 2. // terms of the GNU General Public License, version 2.
// See the 'LICENSE' file for more details. // See the 'LICENSE' file for more details.
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
/// \file k_botsearch.c /// \file k_botsearch.cpp
/// \brief Bot blockmap search functions /// \brief Bot blockmap search functions
#include <algorithm>
#include <tracy/tracy/Tracy.hpp> #include <tracy/tracy/Tracy.hpp>
#include "doomdef.h" #include "doomdef.h"

View file

@ -4473,7 +4473,7 @@ static void K_drawKartMinimap(void)
MiniWaypoint(waypoint_t* wp) : waypoint(wp), rank(K_RankMinimapWaypoint(wp)) {} MiniWaypoint(waypoint_t* wp) : waypoint(wp), rank(K_RankMinimapWaypoint(wp)) {}
bool operator<(const MiniWaypoint& b) { return rank < b.rank; } bool operator<(const MiniWaypoint& b) const noexcept { return rank < b.rank; }
}; };
std::vector<MiniWaypoint> waypoints; std::vector<MiniWaypoint> waypoints;

View file

@ -208,6 +208,7 @@ SDL_bool consolevent = SDL_FALSE;
SDL_bool framebuffer = SDL_FALSE; SDL_bool framebuffer = SDL_FALSE;
UINT8 keyboard_started = false; UINT8 keyboard_started = false;
boolean g_in_exiting_signal_handler = false;
#ifdef UNIXBACKTRACE #ifdef UNIXBACKTRACE
#define STDERR_WRITE(string) if (fd != -1) I_OutputMsg("%s", string) #define STDERR_WRITE(string) if (fd != -1) I_OutputMsg("%s", string)
@ -428,6 +429,8 @@ static void I_ReportSignal(int num, int coredumped)
#ifndef NEWSIGNALHANDLER #ifndef NEWSIGNALHANDLER
FUNCNORETURN static ATTRNORETURN void signal_handler(INT32 num) FUNCNORETURN static ATTRNORETURN void signal_handler(INT32 num)
{ {
g_in_exiting_signal_handler = true;
if (g_main_thread_id != std::this_thread::get_id()) if (g_main_thread_id != std::this_thread::get_id())
{ {
// Do not attempt any sort of recovery if this signal triggers off the main thread // Do not attempt any sort of recovery if this signal triggers off the main thread