From 191b46e84fffc86890c8a4d47cf37ffb29386a9f Mon Sep 17 00:00:00 2001 From: dreg_fr33project Date: Tue, 11 Nov 2014 09:12:57 +0100 Subject: [PATCH 1/2] last ymm support changes --- SDK/C/TitanEngine.h | 20 ++- TitanEngine/TitanEngine.Debugger.Context.cpp | 175 +++++++++++++++++++ TitanEngine/definitions.h | 1 + TitanEngine/stdafx.h | 18 ++ 4 files changed, 213 insertions(+), 1 deletion(-) diff --git a/SDK/C/TitanEngine.h b/SDK/C/TitanEngine.h index 94e21ee..974439a 100644 --- a/SDK/C/TitanEngine.h +++ b/SDK/C/TitanEngine.h @@ -297,7 +297,22 @@ #define UE_x87_ST5 84 #define UE_x87_ST6 85 #define UE_x87_ST7 86 - +#define UE_YMM0 87 +#define UE_YMM1 88 +#define UE_YMM2 89 +#define UE_YMM3 90 +#define UE_YMM4 91 +#define UE_YMM5 92 +#define UE_YMM6 93 +#define UE_YMM7 94 +#define UE_YMM8 95 +#define UE_YMM9 96 +#define UE_YMM10 97 +#define UE_YMM11 98 +#define UE_YMM12 99 +#define UE_YMM13 100 +#define UE_YMM14 101 +#define UE_YMM15 102 #ifndef CONTEXT_EXTENDED_REGISTERS #define CONTEXT_EXTENDED_REGISTERS 0 @@ -361,8 +376,10 @@ typedef struct DWORD MxCsr; #ifdef _WIN64 M128A XmmRegisters[16]; + BYTE YmmRegisters[32 * 16]; #else // x86 M128A XmmRegisters[8]; + BYTE YmmRegisters[32 * 8]; #endif } TITAN_ENGINE_CONTEXT_t; @@ -817,6 +834,7 @@ __declspec(dllexport) ULONG_PTR TITCALL GetContextData(DWORD IndexOfRegister); __declspec(dllexport) bool TITCALL SetContextFPUDataEx(HANDLE hActiveThread, void* FPUSaveArea); __declspec(dllexport) bool TITCALL SetContextDataEx(HANDLE hActiveThread, DWORD IndexOfRegister, ULONG_PTR NewRegisterValue); __declspec(dllexport) bool TITCALL SetContextData(DWORD IndexOfRegister, ULONG_PTR NewRegisterValue); +__declspec(dllexport) bool TITCALL GetAVXContext(HANDLE hActiveThread, TITAN_ENGINE_CONTEXT_t* titcontext); __declspec(dllexport) void TITCALL ClearExceptionNumber(); __declspec(dllexport) long TITCALL CurrentExceptionNumber(); __declspec(dllexport) bool TITCALL MatchPatternEx(HANDLE hProcess, void* MemoryToCheck, int SizeOfMemoryToCheck, void* PatternToMatch, int SizeOfPatternToMatch, PBYTE WildCard); diff --git a/TitanEngine/TitanEngine.Debugger.Context.cpp b/TitanEngine/TitanEngine.Debugger.Context.cpp index bcc4084..92aa296 100644 --- a/TitanEngine/TitanEngine.Debugger.Context.cpp +++ b/TitanEngine/TitanEngine.Debugger.Context.cpp @@ -273,6 +273,8 @@ __declspec(dllexport) bool TITCALL _GetFullContextDataEx(HANDLE hActiveThread, T memcpy(&(titcontext->XmmRegisters[i]), & DBGContext.ExtendedRegisters[(10 + i) * 16], 16); #endif + GetAVXContext(hActiveThread, titcontext); + return true; } @@ -1020,6 +1022,38 @@ __declspec(dllexport) bool TITCALL SetContextDataEx(HANDLE hActiveThread, DWORD memcpy(((uint64_t*) GetRegisterAreaOf87register(titcontext.RegisterArea, x87r0_position, 7)), (char*) NewRegisterValue, 10); } + else if(IndexOfRegister == UE_YMM0) + memcpy(& (titcontext.YmmRegisters[32 * 0]), (void*) NewRegisterValue, 32); + else if(IndexOfRegister == UE_YMM1) + memcpy(& (titcontext.YmmRegisters[32 * 1]), (void*) NewRegisterValue, 32); + else if(IndexOfRegister == UE_YMM2) + memcpy(& (titcontext.YmmRegisters[32 * 2]), (void*) NewRegisterValue, 32); + else if(IndexOfRegister == UE_YMM3) + memcpy(& (titcontext.YmmRegisters[32 * 3]), (void*) NewRegisterValue, 32); + else if(IndexOfRegister == UE_YMM4) + memcpy(& (titcontext.YmmRegisters[32 * 4]), (void*) NewRegisterValue, 32); + else if(IndexOfRegister == UE_YMM5) + memcpy(& (titcontext.YmmRegisters[32 * 5]), (void*) NewRegisterValue, 32); + else if(IndexOfRegister == UE_YMM6) + memcpy(& (titcontext.YmmRegisters[32 * 6]), (void*) NewRegisterValue, 32); + else if(IndexOfRegister == UE_YMM7) + memcpy(& (titcontext.YmmRegisters[32 * 7]), (void*) NewRegisterValue, 32); + else if(IndexOfRegister == UE_YMM8) + memcpy(& (titcontext.YmmRegisters[32 * 8]), (void*) NewRegisterValue, 32); + else if(IndexOfRegister == UE_YMM9) + memcpy(& (titcontext.YmmRegisters[32 * 9]), (void*) NewRegisterValue, 32); + else if(IndexOfRegister == UE_YMM10) + memcpy(& (titcontext.YmmRegisters[32 * 10]), (void*) NewRegisterValue, 32); + else if(IndexOfRegister == UE_YMM11) + memcpy(& (titcontext.YmmRegisters[32 * 11]), (void*) NewRegisterValue, 32); + else if(IndexOfRegister == UE_YMM12) + memcpy(& (titcontext.YmmRegisters[32 * 12]), (void*) NewRegisterValue, 32); + else if(IndexOfRegister == UE_YMM13) + memcpy(& (titcontext.YmmRegisters[32 * 13]), (void*) NewRegisterValue, 32); + else if(IndexOfRegister == UE_YMM14) + memcpy(& (titcontext.YmmRegisters[32 * 14]), (void*) NewRegisterValue, 32); + else if(IndexOfRegister == UE_YMM15) + memcpy(& (titcontext.YmmRegisters[32 * 15]), (void*) NewRegisterValue, 32); else { ResumeThread(hActiveThread); @@ -1040,3 +1074,144 @@ __declspec(dllexport) bool TITCALL SetContextData(DWORD IndexOfRegister, ULONG_P EngineCloseHandle(hActiveThread); return ContextReturn; } + +#undef CONTEXT_XSTATE + +#if defined(_M_X64) +#define CONTEXT_XSTATE (0x00100040) +#else +#define CONTEXT_XSTATE (0x00010040) +#endif + + +#define XSTATE_AVX (XSTATE_GSSE) +#define XSTATE_MASK_AVX (XSTATE_MASK_GSSE) + +typedef DWORD64(WINAPI* PGETENABLEDXSTATEFEATURES)(); +PGETENABLEDXSTATEFEATURES pfnGetEnabledXStateFeatures = NULL; + +typedef BOOL (WINAPI* PINITIALIZECONTEXT)(PVOID Buffer, DWORD ContextFlags, PCONTEXT* Context, PDWORD ContextLength); +PINITIALIZECONTEXT pfnInitializeContext = NULL; + +typedef BOOL (WINAPI* PGETXSTATEFEATURESMASK)(PCONTEXT Context, PDWORD64 FeatureMask); +PGETXSTATEFEATURESMASK pfnGetXStateFeaturesMask = NULL; + +typedef PVOID(WINAPI* LOCATEXSTATEFEATURE)(PCONTEXT Context, DWORD FeatureId, PDWORD Length); +LOCATEXSTATEFEATURE pfnLocateXStateFeature = NULL; + +typedef BOOL (WINAPI* SETXSTATEFEATURESMASK)(PCONTEXT Context, DWORD64 FeatureMask); +SETXSTATEFEATURESMASK pfnSetXStateFeaturesMask = NULL; + +bool InitXState(void) +{ + bool returnf = false; + static bool init = false; + + if(init) + return true; + + HMODULE hm = GetModuleHandleA("kernel32.dll"); + if(hm == NULL) + { + return returnf; + } + pfnGetEnabledXStateFeatures = (PGETENABLEDXSTATEFEATURES)GetProcAddress(hm, "GetEnabledXStateFeatures"); + pfnInitializeContext = (PINITIALIZECONTEXT)GetProcAddress(hm, "InitializeContext"); + pfnGetXStateFeaturesMask = (PGETXSTATEFEATURESMASK)GetProcAddress(hm, "GetXStateFeaturesMask"); + pfnLocateXStateFeature = (LOCATEXSTATEFEATURE)GetProcAddress(hm, "LocateXStateFeature"); + pfnSetXStateFeaturesMask = (SETXSTATEFEATURESMASK)GetProcAddress(hm, "SetXStateFeaturesMask"); + + if + ( + pfnGetEnabledXStateFeatures == NULL + || pfnInitializeContext == NULL + || pfnGetXStateFeaturesMask == NULL + || pfnLocateXStateFeature == NULL + || pfnSetXStateFeaturesMask == NULL + ) + { + return returnf; + } + init = true; + + return true; +} + +__declspec(dllexport) bool TITCALL GetAVXContext(HANDLE hActiveThread, TITAN_ENGINE_CONTEXT_t* titcontext) +{ + PVOID Buffer; + PCONTEXT Context; + DWORD ContextSize; + DWORD FeatureLength; + ULONG Index; + BOOL Success; + PM128A Ymm; + DWORD64 FeatureMask; + bool returnf = false; + + if(InitXState() == false) + return returnf; + + FeatureMask = pfnGetEnabledXStateFeatures(); + if((FeatureMask & XSTATE_MASK_AVX) == 0) + return returnf; + + ContextSize = 0; + Success = pfnInitializeContext(NULL, + CONTEXT_ALL | CONTEXT_XSTATE, + NULL, + &ContextSize); + + if((Success == TRUE) || (GetLastError() != ERROR_INSUFFICIENT_BUFFER)) + return returnf; + + Buffer = calloc(1, ContextSize); + if(Buffer == NULL) + return returnf; + + Success = pfnInitializeContext(Buffer, + CONTEXT_ALL | CONTEXT_XSTATE, + &Context, + &ContextSize); + + if(Success == FALSE) + goto Cleanup; + + Success = pfnSetXStateFeaturesMask(Context, XSTATE_MASK_AVX); + if(Success == FALSE) + goto Cleanup; + + Success = GetThreadContext(hActiveThread, Context); + if(Success == FALSE) + goto Cleanup; + + Success = pfnGetXStateFeaturesMask(Context, &FeatureMask); + if(Success == FALSE) + goto Cleanup; + + Ymm = (PM128A)pfnLocateXStateFeature(Context, XSTATE_AVX, &FeatureLength); + + for(Index = 0; Index < FeatureLength / sizeof(* Ymm); Index += 1) + { + memcpy + ( + (char*) & (titcontext->YmmRegisters[32 * Index]), + &titcontext->XmmRegisters[Index], + sizeof(titcontext->XmmRegisters[Index]) + ); + memcpy + ( + ((char*) & (titcontext->YmmRegisters[32 * Index])) + sizeof(titcontext->XmmRegisters[Index]), + &Ymm[Index], + sizeof(Ymm[Index]) + ); + } + + returnf = true; + +Cleanup: + free(Buffer); + + return returnf; +} + diff --git a/TitanEngine/definitions.h b/TitanEngine/definitions.h index 7c2d1c9..65d2790 100644 --- a/TitanEngine/definitions.h +++ b/TitanEngine/definitions.h @@ -184,6 +184,7 @@ __declspec(dllexport) void TITCALL Getx87FPURegisters(x87FPURegister_t x87FPUReg __declspec(dllexport) void TITCALL GetMMXRegisters(uint64_t mmx[8], TITAN_ENGINE_CONTEXT_t* titcontext); __declspec(dllexport) ULONG_PTR TITCALL GetContextDataEx(HANDLE hActiveThread, DWORD IndexOfRegister); __declspec(dllexport) ULONG_PTR TITCALL GetContextData(DWORD IndexOfRegister); +__declspec(dllexport) bool TITCALL GetAVXContext(HANDLE hActiveThread, TITAN_ENGINE_CONTEXT_t* titcontext); __declspec(dllexport) bool TITCALL SetContextFPUDataEx(HANDLE hActiveThread, void* FPUSaveArea); __declspec(dllexport) bool TITCALL SetContextDataEx(HANDLE hActiveThread, DWORD IndexOfRegister, ULONG_PTR NewRegisterValue); __declspec(dllexport) bool TITCALL SetContextData(DWORD IndexOfRegister, ULONG_PTR NewRegisterValue); diff --git a/TitanEngine/stdafx.h b/TitanEngine/stdafx.h index 2c2cceb..ddb238f 100644 --- a/TitanEngine/stdafx.h +++ b/TitanEngine/stdafx.h @@ -148,8 +148,10 @@ typedef struct DWORD MxCsr; #ifdef _WIN64 M128A XmmRegisters[16]; + BYTE YmmRegisters[32 * 16]; #else // x86 M128A XmmRegisters[8]; + BYTE YmmRegisters[32 * 8]; #endif } TITAN_ENGINE_CONTEXT_t; @@ -663,6 +665,22 @@ typedef struct #define UE_x87_ST5 84 #define UE_x87_ST6 85 #define UE_x87_ST7 86 +#define UE_YMM0 87 +#define UE_YMM1 88 +#define UE_YMM2 89 +#define UE_YMM3 90 +#define UE_YMM4 91 +#define UE_YMM5 92 +#define UE_YMM6 93 +#define UE_YMM7 94 +#define UE_YMM8 95 +#define UE_YMM9 96 +#define UE_YMM10 97 +#define UE_YMM11 98 +#define UE_YMM12 99 +#define UE_YMM13 100 +#define UE_YMM14 101 +#define UE_YMM15 102 typedef struct { From 4956d16b65557c9fb4aed6ed70f505b1c872cf6e Mon Sep 17 00:00:00 2001 From: dreg_fr33project Date: Thu, 13 Nov 2014 02:33:47 +0100 Subject: [PATCH 2/2] finish basic AVX support --- SDK/C/TitanEngine.h | 1 + TitanEngine/TitanEngine.Debugger.Context.cpp | 188 ++++++++++++++++--- TitanEngine/definitions.h | 1 + 3 files changed, 167 insertions(+), 23 deletions(-) diff --git a/SDK/C/TitanEngine.h b/SDK/C/TitanEngine.h index 974439a..74ddb99 100644 --- a/SDK/C/TitanEngine.h +++ b/SDK/C/TitanEngine.h @@ -835,6 +835,7 @@ __declspec(dllexport) bool TITCALL SetContextFPUDataEx(HANDLE hActiveThread, voi __declspec(dllexport) bool TITCALL SetContextDataEx(HANDLE hActiveThread, DWORD IndexOfRegister, ULONG_PTR NewRegisterValue); __declspec(dllexport) bool TITCALL SetContextData(DWORD IndexOfRegister, ULONG_PTR NewRegisterValue); __declspec(dllexport) bool TITCALL GetAVXContext(HANDLE hActiveThread, TITAN_ENGINE_CONTEXT_t* titcontext); +__declspec(dllexport) bool TITCALL SetAVXContext(HANDLE hActiveThread, TITAN_ENGINE_CONTEXT_t* titcontext); __declspec(dllexport) void TITCALL ClearExceptionNumber(); __declspec(dllexport) long TITCALL CurrentExceptionNumber(); __declspec(dllexport) bool TITCALL MatchPatternEx(HANDLE hProcess, void* MemoryToCheck, int SizeOfMemoryToCheck, void* PatternToMatch, int SizeOfPatternToMatch, PBYTE WildCard); diff --git a/TitanEngine/TitanEngine.Debugger.Context.cpp b/TitanEngine/TitanEngine.Debugger.Context.cpp index 92aa296..eacf897 100644 --- a/TitanEngine/TitanEngine.Debugger.Context.cpp +++ b/TitanEngine/TitanEngine.Debugger.Context.cpp @@ -66,10 +66,11 @@ __declspec(dllexport) bool TITCALL GetContextFPUDataEx(HANDLE hActiveThread, voi } -__declspec(dllexport) bool TITCALL _SetFullContextDataEx(HANDLE hActiveThread, TITAN_ENGINE_CONTEXT_t* titcontext) +__declspec(dllexport) bool TITCALL _SetFullContextDataEx(HANDLE hActiveThread, TITAN_ENGINE_CONTEXT_t* titcontext, bool AVX_PRIORITY) { CONTEXT DBGContext; int i; + bool returnf; memset(&DBGContext, 0, sizeof(DBGContext)); @@ -165,7 +166,13 @@ __declspec(dllexport) bool TITCALL _SetFullContextDataEx(HANDLE hActiveThread, T memcpy(& DBGContext.ExtendedRegisters[(10 + i) * 16], &(titcontext->XmmRegisters[i]), 16); #endif - return SetThreadContext(hActiveThread, & DBGContext) ? true : false; + returnf = SetThreadContext(hActiveThread, & DBGContext) ? true : false; + + if(AVX_PRIORITY) + SetAVXContext(hActiveThread, titcontext); + + return returnf; + } __declspec(dllexport) bool TITCALL SetFullContextDataEx(HANDLE hActiveThread, TITAN_ENGINE_CONTEXT_t* titcontext) @@ -175,7 +182,7 @@ __declspec(dllexport) bool TITCALL SetFullContextDataEx(HANDLE hActiveThread, TI if(SuspendThread(hActiveThread) == (DWORD) - 1) return false; - returnf = _SetFullContextDataEx(hActiveThread, titcontext); + returnf = _SetFullContextDataEx(hActiveThread, titcontext, false); ResumeThread(hActiveThread); @@ -590,6 +597,7 @@ __declspec(dllexport) bool TITCALL SetContextDataEx(HANDLE hActiveThread, DWORD { TITAN_ENGINE_CONTEXT_t titcontext; bool returnf; + bool avx_priority = false; if(SuspendThread(hActiveThread) == (DWORD) - 1) return false; @@ -764,6 +772,46 @@ __declspec(dllexport) bool TITCALL SetContextDataEx(HANDLE hActiveThread, DWORD { memcpy(& (titcontext.XmmRegisters[15]), (void*) NewRegisterValue, 16); } + else if(IndexOfRegister == UE_YMM8) + { + avx_priority = true; + memcpy(& (titcontext.YmmRegisters[32 * 8]), (void*) NewRegisterValue, 32); + } + else if(IndexOfRegister == UE_YMM9) + { + avx_priority = true; + memcpy(& (titcontext.YmmRegisters[32 * 9]), (void*) NewRegisterValue, 32); + } + else if(IndexOfRegister == UE_YMM10) + { + avx_priority = true; + memcpy(& (titcontext.YmmRegisters[32 * 10]), (void*) NewRegisterValue, 32); + } + else if(IndexOfRegister == UE_YMM11) + { + avx_priority = true; + memcpy(& (titcontext.YmmRegisters[32 * 11]), (void*) NewRegisterValue, 32); + } + else if(IndexOfRegister == UE_YMM12) + { + avx_priority = true; + memcpy(& (titcontext.YmmRegisters[32 * 12]), (void*) NewRegisterValue, 32); + } + else if(IndexOfRegister == UE_YMM13) + { + avx_priority = true; + memcpy(& (titcontext.YmmRegisters[32 * 13]), (void*) NewRegisterValue, 32); + } + else if(IndexOfRegister == UE_YMM14) + { + avx_priority = true; + memcpy(& (titcontext.YmmRegisters[32 * 14]), (void*) NewRegisterValue, 32); + } + else if(IndexOfRegister == UE_YMM15) + { + avx_priority = true; + memcpy(& (titcontext.YmmRegisters[32 * 15]), (void*) NewRegisterValue, 32); + } #else //x86 if(IndexOfRegister == UE_EAX) { @@ -1023,44 +1071,52 @@ __declspec(dllexport) bool TITCALL SetContextDataEx(HANDLE hActiveThread, DWORD memcpy(((uint64_t*) GetRegisterAreaOf87register(titcontext.RegisterArea, x87r0_position, 7)), (char*) NewRegisterValue, 10); } else if(IndexOfRegister == UE_YMM0) + { + avx_priority = true; memcpy(& (titcontext.YmmRegisters[32 * 0]), (void*) NewRegisterValue, 32); + } else if(IndexOfRegister == UE_YMM1) + { + avx_priority = true; memcpy(& (titcontext.YmmRegisters[32 * 1]), (void*) NewRegisterValue, 32); + } else if(IndexOfRegister == UE_YMM2) + { + avx_priority = true; memcpy(& (titcontext.YmmRegisters[32 * 2]), (void*) NewRegisterValue, 32); + } else if(IndexOfRegister == UE_YMM3) + { + avx_priority = true; memcpy(& (titcontext.YmmRegisters[32 * 3]), (void*) NewRegisterValue, 32); + } else if(IndexOfRegister == UE_YMM4) + { + avx_priority = true; memcpy(& (titcontext.YmmRegisters[32 * 4]), (void*) NewRegisterValue, 32); + } else if(IndexOfRegister == UE_YMM5) + { + avx_priority = true; memcpy(& (titcontext.YmmRegisters[32 * 5]), (void*) NewRegisterValue, 32); + } else if(IndexOfRegister == UE_YMM6) + { + avx_priority = true; memcpy(& (titcontext.YmmRegisters[32 * 6]), (void*) NewRegisterValue, 32); + } else if(IndexOfRegister == UE_YMM7) + { + avx_priority = true; memcpy(& (titcontext.YmmRegisters[32 * 7]), (void*) NewRegisterValue, 32); - else if(IndexOfRegister == UE_YMM8) - memcpy(& (titcontext.YmmRegisters[32 * 8]), (void*) NewRegisterValue, 32); - else if(IndexOfRegister == UE_YMM9) - memcpy(& (titcontext.YmmRegisters[32 * 9]), (void*) NewRegisterValue, 32); - else if(IndexOfRegister == UE_YMM10) - memcpy(& (titcontext.YmmRegisters[32 * 10]), (void*) NewRegisterValue, 32); - else if(IndexOfRegister == UE_YMM11) - memcpy(& (titcontext.YmmRegisters[32 * 11]), (void*) NewRegisterValue, 32); - else if(IndexOfRegister == UE_YMM12) - memcpy(& (titcontext.YmmRegisters[32 * 12]), (void*) NewRegisterValue, 32); - else if(IndexOfRegister == UE_YMM13) - memcpy(& (titcontext.YmmRegisters[32 * 13]), (void*) NewRegisterValue, 32); - else if(IndexOfRegister == UE_YMM14) - memcpy(& (titcontext.YmmRegisters[32 * 14]), (void*) NewRegisterValue, 32); - else if(IndexOfRegister == UE_YMM15) - memcpy(& (titcontext.YmmRegisters[32 * 15]), (void*) NewRegisterValue, 32); + } else { ResumeThread(hActiveThread); return false; } - returnf = _SetFullContextDataEx(hActiveThread, &titcontext); + returnf = _SetFullContextDataEx(hActiveThread, &titcontext, avx_priority); ResumeThread(hActiveThread); @@ -1137,6 +1193,90 @@ bool InitXState(void) return true; } + +__declspec(dllexport) bool TITCALL SetAVXContext(HANDLE hActiveThread, TITAN_ENGINE_CONTEXT_t* titcontext) +{ + PVOID Buffer; + PCONTEXT Context; + DWORD ContextSize; + DWORD FeatureLength; + ULONG Index; + BOOL Success; + PM128A Ymm; + PM128A Xmm; + DWORD64 FeatureMask; + bool returnf = false; + + if(InitXState() == false) + return returnf; + + FeatureMask = pfnGetEnabledXStateFeatures(); + if((FeatureMask & XSTATE_MASK_AVX) == 0) + return returnf; + + ContextSize = 0; + Success = pfnInitializeContext(NULL, + CONTEXT_ALL | CONTEXT_XSTATE, + NULL, + &ContextSize); + + if((Success == TRUE) || (GetLastError() != ERROR_INSUFFICIENT_BUFFER)) + return returnf; + + Buffer = calloc(1, ContextSize); + if(Buffer == NULL) + return returnf; + + Success = pfnInitializeContext(Buffer, + CONTEXT_ALL | CONTEXT_XSTATE, + &Context, + &ContextSize); + + if(Success == FALSE) + goto Cleanup; + + Success = pfnSetXStateFeaturesMask(Context, XSTATE_MASK_AVX); + if(Success == FALSE) + goto Cleanup; + + Success = pfnGetXStateFeaturesMask(Context, &FeatureMask); + if(Success == FALSE) + goto Cleanup; + + Xmm = (PM128A)pfnLocateXStateFeature(Context, XSTATE_LEGACY_SSE, &FeatureLength); + Ymm = (PM128A)pfnLocateXStateFeature(Context, XSTATE_AVX, NULL); + + for(Index = 0; Index < FeatureLength / sizeof(* Ymm); Index += 1) + { + memcpy + ( + Xmm++, + ((char*) & (titcontext->YmmRegisters[32 * Index])), + sizeof(Xmm[Index]) + ); + + memcpy + ( + Ymm++, + ((char*) & (titcontext->YmmRegisters[32 * Index])) + sizeof(titcontext->XmmRegisters[Index]), + sizeof(Ymm[Index]) + ); + } + + Success = SetThreadContext(hActiveThread, Context); + if(Success == FALSE) + goto Cleanup; + + returnf = true; + +Cleanup: + free(Buffer); + + return returnf; +} + + + __declspec(dllexport) bool TITCALL GetAVXContext(HANDLE hActiveThread, TITAN_ENGINE_CONTEXT_t* titcontext) { PVOID Buffer; @@ -1146,6 +1286,7 @@ __declspec(dllexport) bool TITCALL GetAVXContext(HANDLE hActiveThread, TITAN_ENG ULONG Index; BOOL Success; PM128A Ymm; + PM128A Xmm; DWORD64 FeatureMask; bool returnf = false; @@ -1190,19 +1331,20 @@ __declspec(dllexport) bool TITCALL GetAVXContext(HANDLE hActiveThread, TITAN_ENG goto Cleanup; Ymm = (PM128A)pfnLocateXStateFeature(Context, XSTATE_AVX, &FeatureLength); + Xmm = (PM128A)pfnLocateXStateFeature(Context, XSTATE_LEGACY_SSE, &FeatureLength); for(Index = 0; Index < FeatureLength / sizeof(* Ymm); Index += 1) { memcpy ( (char*) & (titcontext->YmmRegisters[32 * Index]), - &titcontext->XmmRegisters[Index], - sizeof(titcontext->XmmRegisters[Index]) + Xmm++, + sizeof(Xmm[Index]) ); memcpy ( ((char*) & (titcontext->YmmRegisters[32 * Index])) + sizeof(titcontext->XmmRegisters[Index]), - &Ymm[Index], + Ymm++, sizeof(Ymm[Index]) ); } diff --git a/TitanEngine/definitions.h b/TitanEngine/definitions.h index 65d2790..1fd133f 100644 --- a/TitanEngine/definitions.h +++ b/TitanEngine/definitions.h @@ -184,6 +184,7 @@ __declspec(dllexport) void TITCALL Getx87FPURegisters(x87FPURegister_t x87FPUReg __declspec(dllexport) void TITCALL GetMMXRegisters(uint64_t mmx[8], TITAN_ENGINE_CONTEXT_t* titcontext); __declspec(dllexport) ULONG_PTR TITCALL GetContextDataEx(HANDLE hActiveThread, DWORD IndexOfRegister); __declspec(dllexport) ULONG_PTR TITCALL GetContextData(DWORD IndexOfRegister); +__declspec(dllexport) bool TITCALL SetAVXContext(HANDLE hActiveThread, TITAN_ENGINE_CONTEXT_t* titcontext); __declspec(dllexport) bool TITCALL GetAVXContext(HANDLE hActiveThread, TITAN_ENGINE_CONTEXT_t* titcontext); __declspec(dllexport) bool TITCALL SetContextFPUDataEx(HANDLE hActiveThread, void* FPUSaveArea); __declspec(dllexport) bool TITCALL SetContextDataEx(HANDLE hActiveThread, DWORD IndexOfRegister, ULONG_PTR NewRegisterValue);