1
0
Fork 0

DBG: working on Windows XP again. But still guys, buy a new operating system...

This commit is contained in:
Mr. eXoDia 2015-07-14 12:13:24 +02:00
parent 09dc2a3d81
commit 1039f452b1
8 changed files with 118 additions and 41 deletions

View File

@ -35,22 +35,22 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<PlatformToolset>v120_xp</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<PlatformToolset>v120_xp</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<PlatformToolset>v120_xp</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<PlatformToolset>v120_xp</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">

View File

@ -208,7 +208,9 @@ DWORD ThreadGetId(HANDLE Thread)
}
// Wasn't found, check with Windows
return GetThreadId(Thread);
typedef DWORD (WINAPI * GETTHREADID)(HANDLE hThread);
static GETTHREADID _GetThreadId = (GETTHREADID)GetProcAddress(GetModuleHandleW(L"kernel32.dll"), "GetThreadId");
return _GetThreadId ? _GetThreadId(Thread) : 0;
}
int ThreadSuspendAll()

View File

@ -44,20 +44,51 @@ void waitdeinitialize()
}
bool SectionLockerGlobal::m_Initialized = false;
SRWLOCK SectionLockerGlobal::m_Locks[SectionLock::LockLast];
bool SectionLockerGlobal::m_SRWLocks = false;
SRWLOCK SectionLockerGlobal::m_srwLocks[SectionLock::LockLast];
CRITICAL_SECTION SectionLockerGlobal::m_crLocks[SectionLock::LockLast];
SectionLockerGlobal::SRWLOCKFUNCTION SectionLockerGlobal::m_InitializeSRWLock;
SectionLockerGlobal::SRWLOCKFUNCTION SectionLockerGlobal::m_AcquireSRWLockShared;
SectionLockerGlobal::SRWLOCKFUNCTION SectionLockerGlobal::m_AcquireSRWLockExclusive;
SectionLockerGlobal::SRWLOCKFUNCTION SectionLockerGlobal::m_ReleaseSRWLockShared;
SectionLockerGlobal::SRWLOCKFUNCTION SectionLockerGlobal::m_ReleaseSRWLockExclusive;
void SectionLockerGlobal::Initialize()
{
if(m_Initialized)
return;
// Destroy previous data if any existed
memset(m_Locks, 0, sizeof(m_Locks));
for(int i = 0; i < ARRAYSIZE(m_Locks); i++)
InitializeSRWLock(&m_Locks[i]);
m_Initialized = true;
// Attempt to read the SRWLock API
HMODULE hKernel32 = GetModuleHandleW(L"kernel32.dll");
m_InitializeSRWLock = (SRWLOCKFUNCTION)GetProcAddress(hKernel32, "InitializeSRWLock");
m_AcquireSRWLockShared = (SRWLOCKFUNCTION)GetProcAddress(hKernel32, "AcquireSRWLockShared");
m_AcquireSRWLockExclusive = (SRWLOCKFUNCTION)GetProcAddress(hKernel32, "AcquireSRWLockExclusive");
m_ReleaseSRWLockShared = (SRWLOCKFUNCTION)GetProcAddress(hKernel32, "ReleaseSRWLockShared");
m_ReleaseSRWLockExclusive = (SRWLOCKFUNCTION)GetProcAddress(hKernel32, "ReleaseSRWLockExclusive");
m_SRWLocks = m_InitializeSRWLock &&
m_AcquireSRWLockShared &&
m_AcquireSRWLockExclusive &&
m_ReleaseSRWLockShared &&
m_ReleaseSRWLockExclusive;
if(m_SRWLocks) // Prefer SRWLocks
{
// Destroy previous data if any existed
memset(m_srwLocks, 0, sizeof(m_srwLocks));
for(int i = 0; i < ARRAYSIZE(m_srwLocks); i++)
m_InitializeSRWLock(&m_srwLocks[i]);
}
else // Fall back to critical sections otherwise
{
// Destroy previous data if any existed
memset(m_crLocks, 0, sizeof(m_crLocks));
for(int i = 0; i < ARRAYSIZE(m_crLocks); i++)
InitializeCriticalSection(&m_crLocks[i]);
}
}
void SectionLockerGlobal::Deinitialize()
@ -65,14 +96,30 @@ void SectionLockerGlobal::Deinitialize()
if(!m_Initialized)
return;
for(int i = 0; i < ARRAYSIZE(m_Locks); i++)
if(m_SRWLocks)
{
// Wait for the lock's ownership to be released
AcquireSRWLockExclusive(&m_Locks[i]);
ReleaseSRWLockExclusive(&m_Locks[i]);
for(int i = 0; i < ARRAYSIZE(m_srwLocks); i++)
{
// Wait for the lock's ownership to be released
m_AcquireSRWLockExclusive(&m_srwLocks[i]);
m_ReleaseSRWLockExclusive(&m_srwLocks[i]);
// Invalidate data
memset(&m_Locks[i], 0, sizeof(SRWLOCK));
// Invalidate data
memset(&m_srwLocks[i], 0, sizeof(SRWLOCK));
}
}
else
{
for(int i = 0; i < ARRAYSIZE(m_crLocks); i++)
{
// Wait for the lock's ownership to be released
EnterCriticalSection(&m_crLocks[i]);
LeaveCriticalSection(&m_crLocks[i]);
// Delete critial section
DeleteCriticalSection(&m_crLocks[i]);
memset(&m_crLocks[i], 0, sizeof(CRITICAL_SECTION));
}
}
m_Initialized = false;

View File

@ -69,9 +69,45 @@ public:
static void Initialize();
static void Deinitialize();
static inline void AcquireLock(SectionLock LockIndex, bool Shared)
{
Initialize(); // Locks can be accessed before we know when to initialize
if(m_SRWLocks)
{
if(Shared)
m_AcquireSRWLockShared(&m_srwLocks[LockIndex]);
else
m_AcquireSRWLockExclusive(&m_srwLocks[LockIndex]);
}
else
EnterCriticalSection(&m_crLocks[LockIndex]);
}
static inline void ReleaseLock(SectionLock LockIndex, bool Shared)
{
if(m_SRWLocks)
{
if(Shared)
m_ReleaseSRWLockShared(&m_srwLocks[LockIndex]);
else
m_ReleaseSRWLockExclusive(&m_srwLocks[LockIndex]);
}
else
LeaveCriticalSection(&m_crLocks[LockIndex]);
}
private:
static bool m_Initialized;
static SRWLOCK m_Locks[SectionLock::LockLast];
typedef void (WINAPI* SRWLOCKFUNCTION)(PSRWLOCK SWRLock);
static bool m_Initialized;
static bool m_SRWLocks;
static SRWLOCK m_srwLocks[SectionLock::LockLast];
static CRITICAL_SECTION m_crLocks[SectionLock::LockLast];
static SRWLOCKFUNCTION m_InitializeSRWLock;
static SRWLOCKFUNCTION m_AcquireSRWLockShared;
static SRWLOCKFUNCTION m_AcquireSRWLockExclusive;
static SRWLOCKFUNCTION m_ReleaseSRWLockShared;
static SRWLOCKFUNCTION m_ReleaseSRWLockExclusive;
};
template<SectionLock LockIndex, bool Shared>
@ -98,10 +134,7 @@ public:
inline void Lock()
{
if(Shared)
AcquireSRWLockShared(&Internal::m_Locks[LockIndex]);
else
AcquireSRWLockExclusive(&Internal::m_Locks[LockIndex]);
Internal::AcquireLock(LockIndex, Shared);
m_LockCount++;
}
@ -110,10 +143,7 @@ public:
{
m_LockCount--;
if(Shared)
ReleaseSRWLockShared(&Internal::m_Locks[LockIndex]);
else
ReleaseSRWLockExclusive(&Internal::m_Locks[LockIndex]);
Internal::ReleaseLock(LockIndex, Shared);
}
private:

View File

@ -244,8 +244,6 @@ extern "C" DLL_EXPORT const char* _dbg_dbginit()
return "Invalid TITAN_ENGINE_CONTEXT_t alignment!";
if(sizeof(TITAN_ENGINE_CONTEXT_t) != sizeof(REGISTERCONTEXT))
return "Invalid REGISTERCONTEXT alignment!";
dputs("Initializing locks...");
SectionLockerGlobal::Initialize();
dputs("Initializing wait objects...");
waitinitialize();
dputs("Initializing debugger...");

View File

@ -214,22 +214,22 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<PlatformToolset>v120_xp</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<PlatformToolset>v120_xp</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<PlatformToolset>v120_xp</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<PlatformToolset>v120_xp</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">

View File

@ -44,22 +44,22 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<PlatformToolset>v120_xp</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<PlatformToolset>v120_xp</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<PlatformToolset>v120_xp</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<PlatformToolset>v120_xp</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">

View File

@ -27,12 +27,12 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<PlatformToolset>v120_xp</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<PlatformToolset>v120_xp</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">