Permalink
Browse files

Merge pull request #1511 from LukeUsher/debugging-hangs

Debugging hangs
  • Loading branch information...
RadWolfie committed Dec 1, 2018
2 parents 0eab84d + f3aa312 commit dc484998782cc6b5176fa75b86e794e0ad981b45
Showing with 27 additions and 34 deletions.
  1. +20 −32 src/CxbxKrnl/EmuKrnlPs.cpp
  2. +1 −1 src/CxbxKrnl/EmuX86.cpp
  3. +6 −1 src/core/HLE/DSOUND/DirectSound/DirectSound.cpp
@@ -130,7 +130,7 @@ static unsigned int WINAPI PCSTProxy
HANDLE hStartedEvent = iPCSTProxyParam->hStartedEvent;

// Once deleted, unable to directly access iPCSTProxyParam in remainder of function.
delete iPCSTProxyParam;
free(iPCSTProxyParam);

LOG_PCSTProxy(
StartRoutine,
@@ -145,38 +145,22 @@ static unsigned int WINAPI PCSTProxy

SetEvent(hStartedEvent);

if (StartSuspended == TRUE)
// Suspend right before calling the thread notification routines
SuspendThread(GetCurrentThread());
if (StartSuspended == TRUE) {
SuspendThread(GetCurrentThread());
}

// use the special calling convention
__try
{
// Given the non-standard calling convention (requiring
// the first argument in ebp+4) we need the below __asm.
//
// Otherwise, this call would have looked something like this :
// ((xboxkrnl::PKSYSTEM_ROUTINE)SystemRoutine)(
// (xboxkrnl::PKSTART_ROUTINE)StartRoutine,
// StartContext);
__asm
{
mov esi, SystemRoutine
push StartContext
push StartRoutine
push offset callComplete
lea ebp, [esp - 4]
jmp near esi
}
{
auto routine = (xboxkrnl::PKSYSTEM_ROUTINE)SystemRoutine;
routine(xboxkrnl::PKSTART_ROUTINE(StartRoutine), StartContext);
}
__except (EmuException(GetExceptionInformation()))
{
EmuLog(LOG_LEVEL::WARNING, "Problem with ExceptionFilter!");
}

callComplete:

// This will also handle thread notification :
// This will also handle thread notification :
LOG_TEST_CASE("Thread returned from SystemRoutine");
xboxkrnl::PsTerminateSystemThread(STATUS_SUCCESS);

return 0; // will never be reached
@@ -278,31 +262,32 @@ XBSYSAPI EXPORTNUM(255) xboxkrnl::NTSTATUS NTAPI xboxkrnl::PsCreateSystemThreadE

// use default kernel stack size if lesser specified
if (KernelStackSize < KERNEL_STACK_SIZE)
KernelStackSize = KERNEL_STACK_SIZE;
KernelStackSize = KERNEL_STACK_SIZE;

// Double the stack size, this is to account for the overhead HLE patching adds to the stack
KernelStackSize *= 2;

// round up to the next page boundary if un-aligned
KernelStackSize = RoundUp(KernelStackSize, PAGE_SIZE);

static bool bFirstTime = false;

// create thread, using our special proxy technique
{
DWORD dwThreadId = 0, dwThreadWait;
bool bWait = true;
HANDLE hStartedEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
HANDLE hStartedEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
if (hStartedEvent == NULL) {
std::string errorMessage = CxbxGetLastErrorString("PsCreateSystemThreadEx could not create PCSTProxyEvent");
CxbxKrnlCleanup(errorMessage.c_str());
}

// PCSTProxy is responsible for cleaning up this pointer
::PCSTProxyParam *iPCSTProxyParam = new ::PCSTProxyParam();
PCSTProxyParam *iPCSTProxyParam = (PCSTProxyParam*)malloc(sizeof(PCSTProxyParam));

iPCSTProxyParam->StartRoutine = StartRoutine;
iPCSTProxyParam->StartContext = StartContext;
iPCSTProxyParam->SystemRoutine = SystemRoutine; // NULL, XapiThreadStartup or unknown?
iPCSTProxyParam->StartSuspended = CreateSuspended;
iPCSTProxyParam->hStartedEvent = hStartedEvent;
iPCSTProxyParam->hStartedEvent = hStartedEvent;

/*
// call thread notification routine(s)
@@ -367,7 +352,10 @@ XBSYSAPI EXPORTNUM(255) xboxkrnl::NTSTATUS NTAPI xboxkrnl::PsCreateSystemThreadE

if (ThreadId != NULL)
*ThreadId = (xboxkrnl::HANDLE)dwThreadId;
}
}

SwitchToThread();
Sleep(10);

RETURN(STATUS_SUCCESS);
}
@@ -3297,7 +3297,7 @@ bool EmuX86_DecodeException(LPEXCEPTION_POINTERS e)
if (EmuX86_Opcode_XOR(e, info)) break;
goto opcode_error;
default:
EmuLog(LOG_LEVEL::WARNING, "Unhandled instruction : %s (%u)", Distorm_OpcodeString(info.opcode), info.opcode);
EmuLog(LOG_LEVEL::DEBUG, "Unhandled instruction : %s (%u)", Distorm_OpcodeString(info.opcode), info.opcode);
// HACK: If we hit an unhandled instruction, log and skip it
e->ContextRecord->Eip += info.size;
return true;
@@ -2262,7 +2262,12 @@ HRESULT WINAPI XTL::EMUPATCH(CDirectSoundStream_Pause)
LOG_FUNC_BEGIN
LOG_FUNC_ARG(pThis)
LOG_FUNC_ARG(dwPause)
LOG_FUNC_END;
LOG_FUNC_END;

if (!pThis) {
LOG_TEST_CASE("CDirectSoundStream_Pause called with pThis = nullptr");
return STATUS_SUCCESS;
}

return HybridDirectSoundBuffer_Pause(pThis->EmuDirectSoundBuffer8, dwPause, pThis->EmuFlags, pThis->EmuPlayFlags,
pThis->Host_isProcessing, 0LL, pThis->Xb_rtPauseEx);

0 comments on commit dc48499

Please sign in to comment.