This commit is contained in:
Aaron Robinson 2003-04-27 23:08:42 +00:00
parent 7115722c27
commit a7ca72566b
4 changed files with 97 additions and 36 deletions

View File

@ -1,5 +1,5 @@
# Microsoft Developer Studio Project File - Name="Cxbx" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 60000
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Application" 0x0101
@ -43,7 +43,7 @@ RSC=rc.exe
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /MT /W3 /O2 /I "Include" /I "Include/Core/" /I "Include/Win32/" /I "Include/Win32/Cxbxkrnl" /I "Include/Win32/Cxbx" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /FR /YX /FD /c
# ADD CPP /nologo /MT /W3 /Zi /O2 /I "Include" /I "Include/Core/" /I "Include/Win32/" /I "Include/Win32/Cxbxkrnl" /I "Include/Win32/Cxbx" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /FAcs /FR /YX /FD /c
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x409 /d "NDEBUG"
@ -53,7 +53,7 @@ BSC32=bscmake.exe
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386
# ADD LINK32 dinput8.lib dxguid.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386 /nodefaultlib:"libc"
# ADD LINK32 dinput8.lib dxguid.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /map /debug /machine:I386 /nodefaultlib:"libc"
# Begin Special Build Tool
SOURCE="$(InputPath)"
PostBuild_Cmds=cd PostBuild upxCxbx.bat

View File

@ -1,5 +1,5 @@
# Microsoft Developer Studio Project File - Name="CxbxKrnl" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 60000
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
@ -43,7 +43,7 @@ RSC=rc.exe
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "CXBXKRNL_EXPORTS" /YX /FD /c
# ADD CPP /nologo /MT /W3 /O2 /I "Include" /I "Include/Core/" /I "Include/Win32/" /I "Include/Win32/Cxbxkrnl" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "CXBXKRNL_EXPORTS" /YX /FD /c
# ADD CPP /nologo /MT /W3 /Zi /O2 /I "Include" /I "Include/Core/" /I "Include/Win32/" /I "Include/Win32/Cxbxkrnl" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "CXBXKRNL_EXPORTS" /FAcs /YX /FD /c
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x409 /d "NDEBUG"
@ -53,7 +53,7 @@ BSC32=bscmake.exe
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
# ADD LINK32 d3d8.lib dinput8.lib dxguid.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /nodefaultlib:"lbc" /out:"Bin/Cxbx.dll" /libpath:"Lib"
# ADD LINK32 d3d8.lib dinput8.lib dxguid.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /pdb:"Bin/CxbxKrnl.pdb" /map:"Bin/CxbxKrnl.map" /debug /machine:I386 /nodefaultlib:"lbc" /out:"Bin/Cxbx.dll" /libpath:"Lib"
!ELSEIF "$(CFG)" == "CxbxKrnl - Win32 Debug"

View File

@ -58,6 +58,7 @@ extern DWORD g_dwTlsAdjust = 0;
// * static
// ******************************************************************
static void EmuInstallWrappers(OOVPATable *OovpaTable, uint32 OovpaTableSize, void (*Entry)(), Xbe::Header *XbeHeader);
static int ExitException(LPEXCEPTION_POINTERS e);
// ******************************************************************
// * func: DllMain
@ -299,24 +300,23 @@ extern "C" CXBXKRNL_API void NTAPI EmuCleanup(const char *szErrorMessage)
}
// ******************************************************************
// * Suspend all Threads
// * Suspend and Redirect all Threads
// ******************************************************************
while(true)
{
ThreadList *tl = ThreadList::pFirst;
ThreadList *tl = 0;
if(tl == NULL)
break;
// ignore current thread
DWORD cur = GetCurrentThreadId();
DWORD cmp = tl->dwThreadId;
if(cmp == 0)
break;
if(cmp != cur)
for(tl = ThreadList::pFirst;tl != NULL;tl = tl->pNext)
{
// ignore current thread
DWORD cur = GetCurrentThreadId();
DWORD cmp = tl->dwThreadId;
if(cmp == 0)
break;
if(cmp == cur)
continue;
SuspendThread(tl->hThread);
CONTEXT Context;
@ -324,28 +324,52 @@ extern "C" CXBXKRNL_API void NTAPI EmuCleanup(const char *szErrorMessage)
Context.ContextFlags = CONTEXT_CONTROL;
GetThreadContext(tl->hThread, &Context);
Context.Eip = (DWORD)EmuCleanThread;
Context.ContextFlags = CONTEXT_CONTROL;
SetThreadContext(tl->hThread, &Context);
}
}
ResumeThread(tl->hThread);
// ******************************************************************
// * Resume all Threads
// ******************************************************************
{
ThreadList *tl = ThreadList::pFirst;
DWORD dwTerm = 0;
GetExitCodeThread(tl->hThread, &dwTerm);
while(tl != NULL)
{
// ignore current thread
DWORD cur = GetCurrentThreadId();
DWORD cmp = tl->dwThreadId;
while(dwTerm == STILL_ACTIVE)
if(cmp == 0)
break;
if(cmp != cur)
{
Sleep(50);
ResumeThread(tl->hThread);
DWORD dwTerm = 0;
GetExitCodeThread(tl->hThread, &dwTerm);
while(dwTerm == STILL_ACTIVE)
{
Sleep(50);
GetExitCodeThread(tl->hThread, &dwTerm);
}
printf("Cxbx: Thread 0x%.08X Terminated\n", tl->hThread);
}
printf("Cxbx: Thread 0x%.08X Terminated\n", tl->hThread);
ThreadList *pTmpDel = tl;
tl = tl->pNext;
delete pTmpDel;
}
ThreadList::pFirst = tl->pNext;
delete tl;
}
printf("CxbxKrnl: Terminating Process\n");
@ -355,7 +379,14 @@ extern "C" CXBXKRNL_API void NTAPI EmuCleanup(const char *szErrorMessage)
EmuCleanupFS();
ExitThread(0);
__try
{
ExitProcess(0);
}
__except(ExitException(GetExceptionInformation()))
{
printf("Emu: WARNING!! Problem with ExitExceptionFilter\n");
}
return;
}
@ -562,3 +593,33 @@ int EmuException(LPEXCEPTION_POINTERS e)
return EXCEPTION_CONTINUE_SEARCH;
}
// ******************************************************************
// * func: ExitException
// ******************************************************************
int ExitException(LPEXCEPTION_POINTERS e)
{
static int count = 0;
// ******************************************************************
// * Debugging Information
// ******************************************************************
{
printf("\n");
printf("Recieved Exit Exception : 0x%.08X\n", e->ExceptionRecord->ExceptionCode);
printf("\n");
}
count++;
if(count > 1)
{
MessageBox(NULL, "Warning: Could not safely terminate process!", "Cxbx", MB_OK);
return EXCEPTION_CONTINUE_SEARCH;
}
ExitProcess(1);
return EXCEPTION_CONTINUE_SEARCH;
}

View File

@ -52,8 +52,8 @@ void Mutex::Lock()
while(true)
{
// Grab the lock, letting us look at the variables
// while(InterlockedCompareExchange((LPVOID*)&m_MutexLock, (LPVOID)1, (LPVOID)0))
while(InterlockedCompareExchange((LPLONG)&m_MutexLock, (LONG)1, (LONG)0))
while(InterlockedCompareExchange((LPVOID*)&m_MutexLock, (LPVOID)1, (LPVOID)0))
// while(InterlockedCompareExchange((LPLONG)&m_MutexLock, (LONG)1, (LONG)0))
Sleep(1);
// Are we the the new owner?
@ -99,8 +99,8 @@ void Mutex::Lock()
void Mutex::Unlock()
{
// Grab the lock, letting us look at the variables
// while(InterlockedCompareExchange((LPVOID*)&m_MutexLock, (LPVOID)1, (LPVOID)0))
while (InterlockedCompareExchange((LPLONG)&m_MutexLock, (LONG)1, (LONG)0))
while(InterlockedCompareExchange((LPVOID*)&m_MutexLock, (LPVOID)1, (LPVOID)0))
// while (InterlockedCompareExchange((LPLONG)&m_MutexLock, (LONG)1, (LONG)0))
Sleep(1);
// Decrement the lock count