Merge branch 'master' into jgrpp

This commit is contained in:
Jonathan G Rennison
2021-04-05 17:50:39 +01:00
164 changed files with 3493 additions and 2443 deletions

View File

@@ -615,7 +615,7 @@ static void ShowCrashlogWindow();
* Stack pointer for use when 'starting' the crash handler.
* Not static as gcc's inline assembly needs it that way.
*/
void *_safe_esp = nullptr;
thread_local void *_safe_esp = nullptr;
static LONG WINAPI ExceptionHandler(EXCEPTION_POINTERS *ep)
{
@@ -655,9 +655,9 @@ static LONG WINAPI ExceptionHandler(EXCEPTION_POINTERS *ep)
CloseConsoleLogIfActive();
void *crash_win_esp = _safe_esp;
if (!IsMainThread() || crash_win_esp == nullptr) {
/* _safe_esp is only valid for the main thread.
* Try to read the stack base from the thread environment block. */
if (crash_win_esp == nullptr) {
/* If _safe_esp is not set for the current thread,
* try to read the stack base from the thread environment block instead. */
#ifdef _M_AMD64
/* The stack pointer for AMD64 must always be 16-byte aligned inside a
* function. As we are simulating a function call with the safe ESP value,
@@ -705,28 +705,7 @@ static void CDECL CustomAbort(int signal)
/* static */ void CrashLog::InitialiseCrashLog()
{
#if defined(_M_AMD64) || defined(_M_ARM64)
CONTEXT ctx;
RtlCaptureContext(&ctx);
/* The stack pointer for AMD64 must always be 16-byte aligned inside a
* function. As we are simulating a function call with the safe ESP value,
* we need to subtract 8 for the imaginary return address otherwise stack
* alignment would be wrong in the called function. */
#if defined(_M_ARM64)
_safe_esp = (void *)(ctx.Sp - 8);
#else
_safe_esp = (void *)(ctx.Rsp - 8);
#endif
#else
#if defined(_MSC_VER)
_asm {
mov _safe_esp, esp
}
#else
asm("movl %esp, __safe_esp");
#endif
#endif
CrashLog::InitThread();
/* SIGABRT is not an unhandled exception, so we need to intercept it. */
signal(SIGABRT, CustomAbort);
@@ -743,6 +722,34 @@ static void CDECL CustomAbort(int signal)
}
}
/* static */ void CrashLog::InitThread()
{
#if defined(_M_AMD64) || defined(_M_ARM64)
CONTEXT ctx;
RtlCaptureContext(&ctx);
/* The stack pointer for AMD64 must always be 16-byte aligned inside a
* function. As we are simulating a function call with the safe ESP value,
* we need to subtract 8 for the imaginary return address otherwise stack
* alignment would be wrong in the called function. */
# if defined(_M_ARM64)
_safe_esp = (void *)(ctx.Sp - 8);
# else
_safe_esp = (void *)(ctx.Rsp - 8);
# endif
#else
void *safe_esp;
# if defined(_MSC_VER)
_asm {
mov safe_esp, esp
}
# else
asm("movl %esp, _safe_esp");
# endif
_safe_esp = safe_esp;
#endif
}
/* static */ void CrashLog::DesyncCrashLog(const std::string *log_in, std::string *log_out, const DesyncExtraInfo &info)
{
CrashLogWindows log(nullptr);