Skip to content

Commit b2dad67

Browse files
committed
xrCore: fix build on x64
1 parent 512bed8 commit b2dad67

File tree

11 files changed

+66
-19
lines changed

11 files changed

+66
-19
lines changed

src/xrCore/Debug/StackTrace.cpp

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ Copyright (c) 1997-2000 John Robbins -- All rights reserved.
1313
#include <psapi.h>
1414
#pragma comment(lib, "psapi.lib")
1515

16+
#include "Common/Platform.hpp"
17+
1618
/*//////////////////////////////////////////////////////////////////////
1719
File Scope Defines
1820
//////////////////////////////////////////////////////////////////////*/
@@ -77,7 +79,16 @@ LPCTSTR __stdcall GetFirstStackTraceString(DWORD dwOpts, EXCEPTION_POINTERS* pEx
7779
// Initialize the STACKFRAME structure.
7880
ZeroMemory(&g_stFrame, sizeof(STACKFRAME));
7981

80-
#ifdef _X86_
82+
#if defined(XR_X64)
83+
g_stFrame.AddrPC.Offset = pExPtrs->ContextRecord->Rip;
84+
g_stFrame.AddrPC.Mode = AddrModeFlat;
85+
g_stFrame.AddrReturn.Offset = 0;
86+
g_stFrame.AddrReturn.Mode = AddrModeFlat;
87+
g_stFrame.AddrStack.Offset = pExPtrs->ContextRecord->Rsp;
88+
g_stFrame.AddrStack.Mode = AddrModeFlat;
89+
g_stFrame.AddrFrame.Offset = pExPtrs->ContextRecord->Rbp;
90+
g_stFrame.AddrFrame.Mode = AddrModeFlat;
91+
#elif defined(XR_X86)
8192
g_stFrame.AddrPC.Offset = pExPtrs->ContextRecord->Eip;
8293
g_stFrame.AddrPC.Mode = AddrModeFlat;
8394
g_stFrame.AddrStack.Offset = pExPtrs->ContextRecord->Esp;
@@ -106,8 +117,11 @@ LPCTSTR __stdcall GetNextStackTraceString(DWORD dwOpts, EXCEPTION_POINTERS* pExP
106117
return InternalGetStackTraceString(dwOpts, pExPtrs);
107118
}
108119

109-
BOOL __stdcall ReadCurrentProcessMemory(
110-
HANDLE, LPCVOID lpBaseAddress, LPVOID lpBuffer, DWORD nSize, LPDWORD lpNumberOfBytesRead)
120+
#ifndef XR_X64
121+
BOOL __stdcall ReadCurrentProcessMemory(HANDLE, LPCVOID lpBaseAddress, LPVOID lpBuffer, DWORD nSize, LPDWORD lpNumberOfBytesRead)
122+
#else
123+
BOOL __stdcall ReadCurrentProcessMemory(HANDLE, LPCVOID lpBaseAddress, LPVOID lpBuffer, DWORD nSize, SIZE_T* lpNumberOfBytesRead)
124+
#endif
111125
{
112126
return ReadProcessMemory(GetCurrentProcess(), lpBaseAddress, lpBuffer, nSize, lpNumberOfBytesRead);
113127
}
@@ -199,7 +213,7 @@ LPCTSTR __stdcall InternalGetStackTraceString(DWORD dwOpts, EXCEPTION_POINTERS*
199213
}
200214

201215
// ASSERT(iCurr < (BUFF_SIZE - MAX_PATH));
202-
DWORD dwDisp;
216+
DWORD_PTR dwDisp;
203217
// Output the symbol name?
204218
if ((dwOpts & GSTSO_SYMBOL) == GSTSO_SYMBOL)
205219
{
@@ -251,7 +265,7 @@ LPCTSTR __stdcall InternalGetStackTraceString(DWORD dwOpts, EXCEPTION_POINTERS*
251265
ZeroMemory(&g_stLine, sizeof(IMAGEHLP_LINE));
252266
g_stLine.SizeOfStruct = sizeof(IMAGEHLP_LINE);
253267

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

src/xrCore/Debug/SymbolEngine.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ scope, so I didn’t wrap them with this class.
1414
#include <DbgHelp.h>
1515
#include <tchar.h>
1616

17+
#include "Common/Platform.hpp"
18+
1719
// Include these in case the user forgets to link against them.
1820
#pragma comment(lib, "dbghelp.lib")
1921
#pragma comment(lib, "version.lib")
@@ -105,9 +107,7 @@ class SymbolEngine
105107

106108
dwVerSize = GetFileVersionInfoSize(szImageHlp, &dwVerInfoHandle);
107109
if (dwVerSize == 0)
108-
{
109110
return false;
110-
}
111111

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

179-
BOOL SymGetSymFromAddr(IN DWORD dwAddr, OUT PDWORD pdwDisplacement, OUT PIMAGEHLP_SYMBOL Symbol)
179+
BOOL SymGetSymFromAddr(IN DWORD dwAddr, OUT PDWORD_PTR pdwDisplacement, OUT PIMAGEHLP_SYMBOL Symbol)
180180
{
181181
return ::SymGetSymFromAddr(m_hProcess, dwAddr, pdwDisplacement, Symbol);
182182
}
@@ -247,7 +247,11 @@ class SymbolEngine
247247
}
248248

249249
BOOL SymSetSearchPath(IN LPSTR SearchPath) { return ::SymSetSearchPath(m_hProcess, SearchPath); }
250+
#ifdef XR_X64
251+
BOOL SymRegisterCallback(IN PSYMBOL_REGISTERED_CALLBACK CallbackFunction, IN ULONG64 UserContext)
252+
#else
250253
BOOL SymRegisterCallback(IN PSYMBOL_REGISTERED_CALLBACK CallbackFunction, IN PVOID UserContext)
254+
#endif
251255
{
252256
return ::SymRegisterCallback(m_hProcess, CallbackFunction, UserContext);
253257
}

src/xrCore/Math/MathUtil.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,31 @@ namespace XRay
2222
{
2323
namespace Math
2424
{
25+
#ifdef XR_X86
2526
Skin1WFunc Skin1W;
2627
Skin2WFunc Skin2W;
2728
Skin3WFunc Skin3W;
2829
Skin4WFunc Skin4W;
30+
#endif
2931
PLCCalcFunc PLCCalc;
3032

3133
void Initialize()
3234
{
3335
static bool initialized = false;
3436
if (initialized)
3537
return;
38+
#ifdef XR_X86
3639
Skin1W = Skin1W_SSE;
3740
Skin2W = Skin2W_SSE;
3841
Skin3W = Skin3W_SSE;
3942
Skin4W = Skin4W_SSE;
4043
Skin4W_MTs = Skin4W_SSE;
44+
#endif
4145
PLCCalc = PLCCalc_SSE;
46+
#ifdef XR_X86
4247
if (ttapi_GetWorkerCount() > 1)
4348
Skin4W = Skin4W_MT;
49+
#endif
4450
initialized = true;
4551
}
4652

src/xrCore/Math/MathUtil.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#pragma once
2+
#include "Common/Platform.hpp"
23
#include "xrCore/xrCore.h"
34
#include "xrCore/_vector3d.h"
45

@@ -22,11 +23,13 @@ namespace XRay
2223
{
2324
namespace Math
2425
{
26+
#ifdef XR_X86
2527
extern XRCORE_API Skin1WFunc Skin1W;
2628
extern XRCORE_API Skin2WFunc Skin2W;
2729
extern XRCORE_API Skin3WFunc Skin3W;
2830
extern XRCORE_API Skin4WFunc Skin4W;
2931
extern XRCORE_API PLCCalcFunc PLCCalc;
32+
#endif
3033

3134
void XRCORE_API Initialize();
3235
} // namespace Math

src/xrCore/Math/SkinXW_SSE.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "stdafx.h"
2+
#include "Common/Platform.hpp"
23
#include "SkinXW_SSE.hpp"
34
#ifdef _EDITOR
45
#include "SkeletonX.h"
@@ -12,6 +13,7 @@ namespace XRay
1213
{
1314
namespace Math
1415
{
16+
#ifdef XR_X86
1517
#define transform_dir(idx, res, SX, SY, SZ, T1) \
1618
\
1719
__asm movzx eax, \
@@ -408,6 +410,6 @@ void Skin1W_SSE(vertRender* D, vertBoned1W* S, u32 vCount, CBoneInstance* Bones)
408410
// ------------------------------------------------------------------
409411
}
410412
}
411-
413+
#endif
412414
} // namespace Util3D
413415
} // namespace XRay

src/xrCore/Math/SkinXW_SSE.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ namespace XRay
1212
{
1313
namespace Math
1414
{
15+
#ifdef XR_X86
1516
void Skin1W_SSE(vertRender* D, vertBoned1W* S, u32 vCount, CBoneInstance* Bones);
1617
void Skin2W_SSE(vertRender* D, vertBoned2W* S, u32 vCount, CBoneInstance* Bones);
1718
void Skin3W_SSE(vertRender* D, vertBoned3W* S, u32 vCount, CBoneInstance* Bones);
1819
void Skin4W_SSE(vertRender* D, vertBoned4W* S, u32 vCount, CBoneInstance* Bones);
20+
#endif
1921
} // namespace Math
2022
} // namespace XRay

src/xrCore/Threading/ttapi.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ void SetThreadName(DWORD dwThreadID, LPCSTR szThreadName)
9898
}
9999
__try
100100
{
101-
RaiseException(0x406D1388, 0, sizeof(info) / sizeof(DWORD), (DWORD*)&info);
101+
RaiseException(0x406D1388, 0, sizeof(info) / sizeof(DWORD), (ULONG_PTR*)&info);
102102
}
103103
__except (EXCEPTION_CONTINUE_EXECUTION)
104104
{

src/xrCore/_math.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,26 +36,31 @@ XRCORE_API void m24(void)
3636
_control87(_PC_24, MCW_PC);
3737
_control87(_RC_CHOP, MCW_RC);
3838
}
39+
3940
XRCORE_API void m24r(void)
4041
{
4142
_control87(_PC_24, MCW_PC);
4243
_control87(_RC_NEAR, MCW_RC);
4344
}
45+
4446
XRCORE_API void m53(void)
4547
{
4648
_control87(_PC_53, MCW_PC);
4749
_control87(_RC_CHOP, MCW_RC);
4850
}
51+
4952
XRCORE_API void m53r(void)
5053
{
5154
_control87(_PC_53, MCW_PC);
5255
_control87(_RC_NEAR, MCW_RC);
5356
}
57+
5458
XRCORE_API void m64(void)
5559
{
5660
_control87(_PC_64, MCW_PC);
5761
_control87(_RC_CHOP, MCW_RC);
5862
}
63+
5964
XRCORE_API void m64r(void)
6065
{
6166
_control87(_PC_64, MCW_PC);
@@ -277,6 +282,7 @@ struct THREAD_NAME
277282
DWORD dwThreadID;
278283
DWORD dwFlags;
279284
};
285+
280286
void thread_name(const char* name)
281287
{
282288
THREAD_NAME tn;
@@ -286,7 +292,7 @@ void thread_name(const char* name)
286292
tn.dwFlags = 0;
287293
__try
288294
{
289-
RaiseException(0x406D1388, 0, sizeof(tn) / sizeof(DWORD), (DWORD*)&tn);
295+
RaiseException(0x406D1388, 0, sizeof(tn) / sizeof(DWORD), (ULONG_PTR*)&tn);
290296
}
291297
__except (EXCEPTION_CONTINUE_EXECUTION)
292298
{

src/xrCore/cpuid.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ unsigned int query_processor_info(processor_info* pinfo)
127127
pinfo->stepping = cpui[0] & 0xf;
128128

129129
// Calculate available processors
130-
DWORD pa_mask_save, sa_mask_stub = 0;
130+
ULONG_PTR pa_mask_save, sa_mask_stub = 0;
131131
GetProcessAffinityMask(GetCurrentProcess(), &pa_mask_save, &sa_mask_stub);
132132

133133
DWORD returnedLength = 0;

src/xrCore/xrCore.vcxproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -590,12 +590,12 @@
590590
<ProjectReference Include="..\..\Externals\cryptlib.vcxproj">
591591
<Project>{c39f4b46-6e89-4074-902e-ca57073044d2}</Project>
592592
</ProjectReference>
593+
<ProjectReference Include="..\..\Externals\lzo.vcxproj">
594+
<Project>{614aa57f-58d7-45a8-a5ff-93f04b05fac6}</Project>
595+
</ProjectReference>
593596
<ProjectReference Include="..\..\Externals\pugixml_vs2017_static.vcxproj">
594597
<Project>{07cf01c0-b887-499d-ad9c-799cb6a9fe64}</Project>
595598
</ProjectReference>
596-
<ProjectReference Include="$(xrExternals)lzo.vcxproj">
597-
<Project>{614aa57f-58d7-45a8-a5ff-93f04b05fac6}</Project>
598-
</ProjectReference>
599599
<ProjectReference Include="..\utils\xrMiscMath\xrMiscMath.vcxproj">
600600
<Project>{7885cf3c-ee04-4c67-9467-1fbf9a36b037}</Project>
601601
</ProjectReference>

src/xrCore/xrDebug.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,18 @@ static BOOL bException = FALSE;
4848

4949
namespace
5050
{
51+
#ifdef XR_X64
52+
extern "C" void * _ReturnAddress(void);
53+
DWORD_PTR GetInstructionPtr()
54+
{
55+
return (DWORD_PTR)_ReturnAddress();
56+
}
57+
#else
5158
void __declspec(naked, noinline) * __cdecl GetInstructionPtr()
5259
{
53-
#ifdef _WIN64
54-
_asm mov rax, [rsp] _asm retn
55-
#else
5660
_asm mov eax, [esp] _asm retn
57-
#endif
5861
}
62+
#endif
5963
}
6064

6165
xrDebug::UnhandledExceptionFilter xrDebug::PrevFilter = nullptr;
@@ -86,9 +90,15 @@ size_t xrDebug::BuildStackTrace(char* buffer, size_t capacity, size_t lineCapaci
8690
context.ContextFlags = CONTEXT_FULL;
8791
if (GetThreadContext(GetCurrentThread(), &context))
8892
{
93+
#if defined(XR_X64)
94+
context.Rip = GetInstructionPtr();
95+
context.Rbp = (DWORD64)&ebp;
96+
context.Rsp = (DWORD64)&context;
97+
#elif defined(XR_X86)
8998
context.Eip = (DWORD)GetInstructionPtr();
9099
context.Ebp = (DWORD)&ebp;
91100
context.Esp = (DWORD)&context;
101+
#endif
92102
ex_ptrs.ContextRecord = &context;
93103
ex_ptrs.ExceptionRecord = 0;
94104
return BuildStackTrace(&ex_ptrs, buffer, capacity, lineCapacity);

0 commit comments

Comments
 (0)