From a7e8b67c7c96d7e76b495ce2bed9f5f423870522 Mon Sep 17 00:00:00 2001 From: michi_cc Date: Mon, 23 Aug 2010 18:19:15 +0000 Subject: (svn r20598) -Codechange: [Win32] Replace the external x64 asm with a built-in Windows function. --- src/os/windows/crashlog_win.cpp | 19 ++- src/os/windows/masm64.rules | 266 ---------------------------------------- src/os/windows/win64.asm | 8 -- 3 files changed, 14 insertions(+), 279 deletions(-) delete mode 100644 src/os/windows/masm64.rules delete mode 100644 src/os/windows/win64.asm (limited to 'src') diff --git a/src/os/windows/crashlog_win.cpp b/src/os/windows/crashlog_win.cpp index 4bdb984f8..11791528b 100644 --- a/src/os/windows/crashlog_win.cpp +++ b/src/os/windows/crashlog_win.cpp @@ -10,6 +10,12 @@ /** @file crashlog_win.cpp Implementation of a crashlogger for Windows */ #include "../../stdafx.h" +#if defined(_MSC_VER) && defined(_M_AMD64) +/* Redefine WinNT version to get RtlCaptureContext prototype. */ +#undef _WIN32_WINNT +#undef NTDDI_VERSION +#define _WIN32_WINNT _WIN32_WINNT_WINXP +#endif /* defined(_MSC_VER) && defined(_M_AMD64) */ #include "../../crashlog.h" #include "win32.h" #include "../../core/alloc_func.hpp" @@ -408,10 +414,6 @@ static LONG WINAPI ExceptionHandler(EXCEPTION_POINTERS *ep) return EXCEPTION_EXECUTE_HANDLER; } -#ifdef _M_AMD64 -extern "C" void *_get_safe_esp(); -#endif - static void CDECL CustomAbort(int signal) { RaiseException(0xE1212012, 0, 0, NULL); @@ -421,7 +423,14 @@ static void CDECL CustomAbort(int signal) { #if defined(_MSC_VER) #ifdef _M_AMD64 - _safe_esp = _get_safe_esp(); + 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. */ + _safe_esp = (void *)(ctx.Rsp - 8); #else _asm { mov _safe_esp, esp diff --git a/src/os/windows/masm64.rules b/src/os/windows/masm64.rules deleted file mode 100644 index 62e6e0f8b..000000000 --- a/src/os/windows/masm64.rules +++ /dev/null @@ -1,266 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/os/windows/win64.asm b/src/os/windows/win64.asm deleted file mode 100644 index d95bc3898..000000000 --- a/src/os/windows/win64.asm +++ /dev/null @@ -1,8 +0,0 @@ - .CODE - -PUBLIC _get_safe_esp -_get_safe_esp: - MOV RAX,RSP - RET - - END -- cgit v1.2.3-70-g09d2