Skip to content

Commit

Permalink
xrCore: fix build on x64
Browse files Browse the repository at this point in the history
  • Loading branch information
Xottab-DUTY committed Aug 11, 2017
1 parent 512bed8 commit b2dad67
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 19 deletions.
24 changes: 19 additions & 5 deletions src/xrCore/Debug/StackTrace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Copyright (c) 1997-2000 John Robbins -- All rights reserved.
#include <psapi.h>
#pragma comment(lib, "psapi.lib")

#include "Common/Platform.hpp"

/*//////////////////////////////////////////////////////////////////////
File Scope Defines
//////////////////////////////////////////////////////////////////////*/
Expand Down Expand Up @@ -77,7 +79,16 @@ LPCTSTR __stdcall GetFirstStackTraceString(DWORD dwOpts, EXCEPTION_POINTERS* pEx
// Initialize the STACKFRAME structure.
ZeroMemory(&g_stFrame, sizeof(STACKFRAME));

#ifdef _X86_
#if defined(XR_X64)
g_stFrame.AddrPC.Offset = pExPtrs->ContextRecord->Rip;
g_stFrame.AddrPC.Mode = AddrModeFlat;
g_stFrame.AddrReturn.Offset = 0;
g_stFrame.AddrReturn.Mode = AddrModeFlat;
g_stFrame.AddrStack.Offset = pExPtrs->ContextRecord->Rsp;
g_stFrame.AddrStack.Mode = AddrModeFlat;
g_stFrame.AddrFrame.Offset = pExPtrs->ContextRecord->Rbp;
g_stFrame.AddrFrame.Mode = AddrModeFlat;
#elif defined(XR_X86)
g_stFrame.AddrPC.Offset = pExPtrs->ContextRecord->Eip;
g_stFrame.AddrPC.Mode = AddrModeFlat;
g_stFrame.AddrStack.Offset = pExPtrs->ContextRecord->Esp;
Expand Down Expand Up @@ -106,8 +117,11 @@ LPCTSTR __stdcall GetNextStackTraceString(DWORD dwOpts, EXCEPTION_POINTERS* pExP
return InternalGetStackTraceString(dwOpts, pExPtrs);
}

BOOL __stdcall ReadCurrentProcessMemory(
HANDLE, LPCVOID lpBaseAddress, LPVOID lpBuffer, DWORD nSize, LPDWORD lpNumberOfBytesRead)
#ifndef XR_X64
BOOL __stdcall ReadCurrentProcessMemory(HANDLE, LPCVOID lpBaseAddress, LPVOID lpBuffer, DWORD nSize, LPDWORD lpNumberOfBytesRead)
#else
BOOL __stdcall ReadCurrentProcessMemory(HANDLE, LPCVOID lpBaseAddress, LPVOID lpBuffer, DWORD nSize, SIZE_T* lpNumberOfBytesRead)
#endif
{
return ReadProcessMemory(GetCurrentProcess(), lpBaseAddress, lpBuffer, nSize, lpNumberOfBytesRead);
}
Expand Down Expand Up @@ -199,7 +213,7 @@ LPCTSTR __stdcall InternalGetStackTraceString(DWORD dwOpts, EXCEPTION_POINTERS*
}

// ASSERT(iCurr < (BUFF_SIZE - MAX_PATH));
DWORD dwDisp;
DWORD_PTR dwDisp;
// Output the symbol name?
if ((dwOpts & GSTSO_SYMBOL) == GSTSO_SYMBOL)
{
Expand Down Expand Up @@ -251,7 +265,7 @@ LPCTSTR __stdcall InternalGetStackTraceString(DWORD dwOpts, EXCEPTION_POINTERS*
ZeroMemory(&g_stLine, sizeof(IMAGEHLP_LINE));
g_stLine.SizeOfStruct = sizeof(IMAGEHLP_LINE);

if (SymGetLineFromAddr(hProcess, g_stFrame.AddrPC.Offset, &dwDisp, &g_stLine) == TRUE)
if (SymGetLineFromAddr(hProcess, g_stFrame.AddrPC.Offset, (PDWORD)&dwDisp, &g_stLine) == TRUE)
{
iCurr += wsprintf(g_szBuff + iCurr, _T(", "));

Expand Down
10 changes: 7 additions & 3 deletions src/xrCore/Debug/SymbolEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ scope, so I didn’t wrap them with this class.
#include <DbgHelp.h>
#include <tchar.h>

#include "Common/Platform.hpp"

// Include these in case the user forgets to link against them.
#pragma comment(lib, "dbghelp.lib")
#pragma comment(lib, "version.lib")
Expand Down Expand Up @@ -105,9 +107,7 @@ class SymbolEngine

dwVerSize = GetFileVersionInfoSize(szImageHlp, &dwVerInfoHandle);
if (dwVerSize == 0)
{
return false;
}

// Got the version size, now get the version information.
LPVOID lpData = (LPVOID) new TCHAR[dwVerSize];
Expand Down Expand Up @@ -176,7 +176,7 @@ class SymbolEngine
return ::SymEnumerateSymbols(m_hProcess, BaseOfDll, EnumSymbolsCallback, UserContext);
}

BOOL SymGetSymFromAddr(IN DWORD dwAddr, OUT PDWORD pdwDisplacement, OUT PIMAGEHLP_SYMBOL Symbol)
BOOL SymGetSymFromAddr(IN DWORD dwAddr, OUT PDWORD_PTR pdwDisplacement, OUT PIMAGEHLP_SYMBOL Symbol)
{
return ::SymGetSymFromAddr(m_hProcess, dwAddr, pdwDisplacement, Symbol);
}
Expand Down Expand Up @@ -247,7 +247,11 @@ class SymbolEngine
}

BOOL SymSetSearchPath(IN LPSTR SearchPath) { return ::SymSetSearchPath(m_hProcess, SearchPath); }
#ifdef XR_X64
BOOL SymRegisterCallback(IN PSYMBOL_REGISTERED_CALLBACK CallbackFunction, IN ULONG64 UserContext)
#else
BOOL SymRegisterCallback(IN PSYMBOL_REGISTERED_CALLBACK CallbackFunction, IN PVOID UserContext)
#endif
{
return ::SymRegisterCallback(m_hProcess, CallbackFunction, UserContext);
}
Expand Down
6 changes: 6 additions & 0 deletions src/xrCore/Math/MathUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,31 @@ namespace XRay
{
namespace Math
{
#ifdef XR_X86
Skin1WFunc Skin1W;
Skin2WFunc Skin2W;
Skin3WFunc Skin3W;
Skin4WFunc Skin4W;
#endif
PLCCalcFunc PLCCalc;

void Initialize()
{
static bool initialized = false;
if (initialized)
return;
#ifdef XR_X86
Skin1W = Skin1W_SSE;
Skin2W = Skin2W_SSE;
Skin3W = Skin3W_SSE;
Skin4W = Skin4W_SSE;
Skin4W_MTs = Skin4W_SSE;
#endif
PLCCalc = PLCCalc_SSE;
#ifdef XR_X86
if (ttapi_GetWorkerCount() > 1)
Skin4W = Skin4W_MT;
#endif
initialized = true;
}

Expand Down
3 changes: 3 additions & 0 deletions src/xrCore/Math/MathUtil.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pragma once
#include "Common/Platform.hpp"
#include "xrCore/xrCore.h"
#include "xrCore/_vector3d.h"

Expand All @@ -22,11 +23,13 @@ namespace XRay
{
namespace Math
{
#ifdef XR_X86
extern XRCORE_API Skin1WFunc Skin1W;
extern XRCORE_API Skin2WFunc Skin2W;
extern XRCORE_API Skin3WFunc Skin3W;
extern XRCORE_API Skin4WFunc Skin4W;
extern XRCORE_API PLCCalcFunc PLCCalc;
#endif

void XRCORE_API Initialize();
} // namespace Math
Expand Down
4 changes: 3 additions & 1 deletion src/xrCore/Math/SkinXW_SSE.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "stdafx.h"
#include "Common/Platform.hpp"
#include "SkinXW_SSE.hpp"
#ifdef _EDITOR
#include "SkeletonX.h"
Expand All @@ -12,6 +13,7 @@ namespace XRay
{
namespace Math
{
#ifdef XR_X86
#define transform_dir(idx, res, SX, SY, SZ, T1) \
\
__asm movzx eax, \
Expand Down Expand Up @@ -408,6 +410,6 @@ void Skin1W_SSE(vertRender* D, vertBoned1W* S, u32 vCount, CBoneInstance* Bones)
// ------------------------------------------------------------------
}
}

#endif
} // namespace Util3D
} // namespace XRay
2 changes: 2 additions & 0 deletions src/xrCore/Math/SkinXW_SSE.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ namespace XRay
{
namespace Math
{
#ifdef XR_X86
void Skin1W_SSE(vertRender* D, vertBoned1W* S, u32 vCount, CBoneInstance* Bones);
void Skin2W_SSE(vertRender* D, vertBoned2W* S, u32 vCount, CBoneInstance* Bones);
void Skin3W_SSE(vertRender* D, vertBoned3W* S, u32 vCount, CBoneInstance* Bones);
void Skin4W_SSE(vertRender* D, vertBoned4W* S, u32 vCount, CBoneInstance* Bones);
#endif
} // namespace Math
} // namespace XRay
2 changes: 1 addition & 1 deletion src/xrCore/Threading/ttapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ void SetThreadName(DWORD dwThreadID, LPCSTR szThreadName)
}
__try
{
RaiseException(0x406D1388, 0, sizeof(info) / sizeof(DWORD), (DWORD*)&info);
RaiseException(0x406D1388, 0, sizeof(info) / sizeof(DWORD), (ULONG_PTR*)&info);
}
__except (EXCEPTION_CONTINUE_EXECUTION)
{
Expand Down
8 changes: 7 additions & 1 deletion src/xrCore/_math.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,26 +36,31 @@ XRCORE_API void m24(void)
_control87(_PC_24, MCW_PC);
_control87(_RC_CHOP, MCW_RC);
}

XRCORE_API void m24r(void)
{
_control87(_PC_24, MCW_PC);
_control87(_RC_NEAR, MCW_RC);
}

XRCORE_API void m53(void)
{
_control87(_PC_53, MCW_PC);
_control87(_RC_CHOP, MCW_RC);
}

XRCORE_API void m53r(void)
{
_control87(_PC_53, MCW_PC);
_control87(_RC_NEAR, MCW_RC);
}

XRCORE_API void m64(void)
{
_control87(_PC_64, MCW_PC);
_control87(_RC_CHOP, MCW_RC);
}

XRCORE_API void m64r(void)
{
_control87(_PC_64, MCW_PC);
Expand Down Expand Up @@ -277,6 +282,7 @@ struct THREAD_NAME
DWORD dwThreadID;
DWORD dwFlags;
};

void thread_name(const char* name)
{
THREAD_NAME tn;
Expand All @@ -286,7 +292,7 @@ void thread_name(const char* name)
tn.dwFlags = 0;
__try
{
RaiseException(0x406D1388, 0, sizeof(tn) / sizeof(DWORD), (DWORD*)&tn);
RaiseException(0x406D1388, 0, sizeof(tn) / sizeof(DWORD), (ULONG_PTR*)&tn);
}
__except (EXCEPTION_CONTINUE_EXECUTION)
{
Expand Down
2 changes: 1 addition & 1 deletion src/xrCore/cpuid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ unsigned int query_processor_info(processor_info* pinfo)
pinfo->stepping = cpui[0] & 0xf;

// Calculate available processors
DWORD pa_mask_save, sa_mask_stub = 0;
ULONG_PTR pa_mask_save, sa_mask_stub = 0;
GetProcessAffinityMask(GetCurrentProcess(), &pa_mask_save, &sa_mask_stub);

DWORD returnedLength = 0;
Expand Down
6 changes: 3 additions & 3 deletions src/xrCore/xrCore.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -590,12 +590,12 @@
<ProjectReference Include="..\..\Externals\cryptlib.vcxproj">
<Project>{c39f4b46-6e89-4074-902e-ca57073044d2}</Project>
</ProjectReference>
<ProjectReference Include="..\..\Externals\lzo.vcxproj">
<Project>{614aa57f-58d7-45a8-a5ff-93f04b05fac6}</Project>
</ProjectReference>
<ProjectReference Include="..\..\Externals\pugixml_vs2017_static.vcxproj">
<Project>{07cf01c0-b887-499d-ad9c-799cb6a9fe64}</Project>
</ProjectReference>
<ProjectReference Include="$(xrExternals)lzo.vcxproj">
<Project>{614aa57f-58d7-45a8-a5ff-93f04b05fac6}</Project>
</ProjectReference>
<ProjectReference Include="..\utils\xrMiscMath\xrMiscMath.vcxproj">
<Project>{7885cf3c-ee04-4c67-9467-1fbf9a36b037}</Project>
</ProjectReference>
Expand Down
18 changes: 14 additions & 4 deletions src/xrCore/xrDebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,18 @@ static BOOL bException = FALSE;

namespace
{
#ifdef XR_X64
extern "C" void * _ReturnAddress(void);
DWORD_PTR GetInstructionPtr()
{
return (DWORD_PTR)_ReturnAddress();
}
#else
void __declspec(naked, noinline) * __cdecl GetInstructionPtr()
{
#ifdef _WIN64
_asm mov rax, [rsp] _asm retn
#else
_asm mov eax, [esp] _asm retn
#endif
}
#endif
}

xrDebug::UnhandledExceptionFilter xrDebug::PrevFilter = nullptr;
Expand Down Expand Up @@ -86,9 +90,15 @@ size_t xrDebug::BuildStackTrace(char* buffer, size_t capacity, size_t lineCapaci
context.ContextFlags = CONTEXT_FULL;
if (GetThreadContext(GetCurrentThread(), &context))
{
#if defined(XR_X64)
context.Rip = GetInstructionPtr();
context.Rbp = (DWORD64)&ebp;
context.Rsp = (DWORD64)&context;
#elif defined(XR_X86)
context.Eip = (DWORD)GetInstructionPtr();
context.Ebp = (DWORD)&ebp;
context.Esp = (DWORD)&context;
#endif
ex_ptrs.ContextRecord = &context;
ex_ptrs.ExceptionRecord = 0;
return BuildStackTrace(&ex_ptrs, buffer, capacity, lineCapacity);
Expand Down

0 comments on commit b2dad67

Please sign in to comment.