Prevent crash when TLS is absent from Xbe

This commit is contained in:
PatrickvL 2017-02-16 01:30:46 +01:00
parent 7cad3cd879
commit b38382e209
1 changed files with 38 additions and 34 deletions

View File

@ -383,12 +383,15 @@ void EmuInitFS()
// generate fs segment selector
void EmuGenerateFS(Xbe::TLS *pTLS, void *pTLSData)
{
void *pNewTLS = nullptr;
// Be aware that TLS might be absent (for example in homebrew "Wolf3d-xbox")
if (pTLS != nullptr) {
// Make sure the TLS Start and End addresses are within Xbox Memory
if (pTLS->dwDataStartAddr >= EMU_MAX_MEMORY_SIZE || pTLS->dwDataEndAddr >= EMU_MAX_MEMORY_SIZE) {
return;
}
void *pNewTLS = nullptr;
// copy global TLS to the current thread
{
@ -433,6 +436,7 @@ void EmuGenerateFS(Xbe::TLS *pTLS, void *pTLSData)
if (pNewTLS != nullptr)
*(void**)pNewTLS = pNewTLS;
}
}
// Allocate the xbox KPCR structure
xboxkrnl::KPCR *NewPcr = (xboxkrnl::KPCR*)CxbxCalloc(1, sizeof(xboxkrnl::KPCR));