hopefully fixed a crash with getting/setting the AVX context on unsupported systems

This commit is contained in:
Mr. eXoDia 2014-12-08 02:08:46 +01:00
parent 60c7a748b4
commit e3107e6dd3
1 changed files with 48 additions and 32 deletions

View File

@ -82,7 +82,7 @@ __declspec(dllexport) bool TITCALL _SetFullContextDataEx(HANDLE hActiveThread, T
return false; return false;
} }
DBGContext.EFlags = titcontext->eflags; DBGContext.EFlags = (DWORD)titcontext->eflags;
DBGContext.Dr0 = titcontext->dr0; DBGContext.Dr0 = titcontext->dr0;
DBGContext.Dr1 = titcontext->dr1; DBGContext.Dr1 = titcontext->dr1;
DBGContext.Dr2 = titcontext->dr2; DBGContext.Dr2 = titcontext->dr2;
@ -1244,23 +1244,30 @@ __declspec(dllexport) bool TITCALL SetAVXContext(HANDLE hActiveThread, TITAN_ENG
goto Cleanup; goto Cleanup;
Xmm = (PM128A)pfnLocateXStateFeature(Context, XSTATE_LEGACY_SSE, &FeatureLength); Xmm = (PM128A)pfnLocateXStateFeature(Context, XSTATE_LEGACY_SSE, &FeatureLength);
Ymm = (PM128A)pfnLocateXStateFeature(Context, XSTATE_AVX, NULL); if(Xmm != NULL) //If the feature is unsupported by the processor it will return NULL
for(Index = 0; Index < FeatureLength / sizeof(* Ymm); Index += 1)
{ {
memcpy for(Index = 0; Index < FeatureLength / sizeof(* Ymm); Index += 1)
( {
Xmm++, memcpy
((char*) & (titcontext->YmmRegisters[32 * Index])), (
sizeof(Xmm[Index]) Xmm++,
); ((char*) & (titcontext->YmmRegisters[32 * Index])),
sizeof(Xmm[Index])
memcpy );
( }
Ymm++, }
((char*) & (titcontext->YmmRegisters[32 * Index])) + sizeof(titcontext->XmmRegisters[Index]), Ymm = (PM128A)pfnLocateXStateFeature(Context, XSTATE_AVX, NULL);
sizeof(Ymm[Index]) if(Ymm != NULL) //If the feature is unsupported by the processor it will return NULL
); {
for(Index = 0; Index < FeatureLength / sizeof(* Ymm); Index += 1)
{
memcpy
(
Ymm++,
((char*) & (titcontext->YmmRegisters[32 * Index])) + sizeof(titcontext->XmmRegisters[Index]),
sizeof(Ymm[Index])
);
}
} }
Success = SetThreadContext(hActiveThread, Context); Success = SetThreadContext(hActiveThread, Context);
@ -1330,23 +1337,32 @@ __declspec(dllexport) bool TITCALL GetAVXContext(HANDLE hActiveThread, TITAN_ENG
if(Success == FALSE) if(Success == FALSE)
goto Cleanup; goto Cleanup;
Ymm = (PM128A)pfnLocateXStateFeature(Context, XSTATE_AVX, &FeatureLength);
Xmm = (PM128A)pfnLocateXStateFeature(Context, XSTATE_LEGACY_SSE, &FeatureLength); Xmm = (PM128A)pfnLocateXStateFeature(Context, XSTATE_LEGACY_SSE, &FeatureLength);
if(Xmm != NULL) //If the feature is unsupported by the processor it will return NULL
for(Index = 0; Index < FeatureLength / sizeof(* Ymm); Index += 1)
{ {
memcpy for(Index = 0; Index < FeatureLength / sizeof(* Ymm); Index += 1)
( {
(char*) & (titcontext->YmmRegisters[32 * Index]), memcpy
Xmm++, (
sizeof(Xmm[Index]) (char*) & (titcontext->YmmRegisters[32 * Index]),
); Xmm++,
memcpy sizeof(Xmm[Index])
( );
((char*) & (titcontext->YmmRegisters[32 * Index])) + sizeof(titcontext->XmmRegisters[Index]), }
Ymm++, }
sizeof(Ymm[Index])
); Ymm = (PM128A)pfnLocateXStateFeature(Context, XSTATE_AVX, &FeatureLength);
if(Ymm != NULL) //If the feature is unsupported by the processor it will return NULL
{
for(Index = 0; Index < FeatureLength / sizeof(* Ymm); Index += 1)
{
memcpy
(
((char*) & (titcontext->YmmRegisters[32 * Index])) + sizeof(titcontext->XmmRegisters[Index]),
Ymm++,
sizeof(Ymm[Index])
);
}
} }
returnf = true; returnf = true;