mirror of
https://github.com/hedge-dev/UnleashedRecomp.git
synced 2026-04-27 04:41:39 +00:00
Cross-platform TLS. (#34)
* Cross-platform TLS. * Fix front() to back(), use Mutex. * Fix global variable namings. --------- Co-authored-by: Skyth <19259897+blueskythlikesclouds@users.noreply.github.com>
This commit is contained in:
parent
fe15f154fe
commit
52b4f0ee5e
1 changed files with 30 additions and 4 deletions
|
|
@ -890,24 +890,50 @@ DWORD KeWaitForSingleObject(XDISPATCHER_HEADER* Object, DWORD WaitReason, DWORD
|
||||||
return WaitForSingleObjectEx(handle, timeout, Alertable);
|
return WaitForSingleObjectEx(handle, timeout, Alertable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static thread_local std::vector<uint32_t> g_tlsValues;
|
||||||
|
static std::vector<size_t> g_tlsFreeIndices;
|
||||||
|
static size_t g_tlsNextIndex = 0;
|
||||||
|
static Mutex g_tlsAllocationMutex;
|
||||||
|
|
||||||
|
static void KeTlsEnsureTlsCapacity(size_t index)
|
||||||
|
{
|
||||||
|
if (g_tlsValues.size() <= index)
|
||||||
|
{
|
||||||
|
g_tlsValues.resize(index + 1, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
uint32_t KeTlsGetValue(DWORD dwTlsIndex)
|
uint32_t KeTlsGetValue(DWORD dwTlsIndex)
|
||||||
{
|
{
|
||||||
return (uint32_t)TlsGetValue(dwTlsIndex);
|
KeTlsEnsureTlsCapacity(dwTlsIndex);
|
||||||
|
return g_tlsValues[dwTlsIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL KeTlsSetValue(DWORD dwTlsIndex, DWORD lpTlsValue)
|
BOOL KeTlsSetValue(DWORD dwTlsIndex, DWORD lpTlsValue)
|
||||||
{
|
{
|
||||||
return TlsSetValue(dwTlsIndex, (LPVOID)lpTlsValue);
|
KeTlsEnsureTlsCapacity(dwTlsIndex);
|
||||||
|
g_tlsValues[dwTlsIndex] = lpTlsValue;
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
DWORD KeTlsAlloc()
|
DWORD KeTlsAlloc()
|
||||||
{
|
{
|
||||||
return TlsAlloc();
|
std::lock_guard<Mutex> lock(g_tlsAllocationMutex);
|
||||||
|
if (!g_tlsFreeIndices.empty())
|
||||||
|
{
|
||||||
|
size_t index = g_tlsFreeIndices.back();
|
||||||
|
g_tlsFreeIndices.pop_back();
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
|
||||||
|
return g_tlsNextIndex++;
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL KeTlsFree(DWORD dwTlsIndex)
|
BOOL KeTlsFree(DWORD dwTlsIndex)
|
||||||
{
|
{
|
||||||
return TlsFree(dwTlsIndex);
|
std::lock_guard<Mutex> lock(g_tlsAllocationMutex);
|
||||||
|
g_tlsFreeIndices.push_back(dwTlsIndex);
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
DWORD XMsgInProcessCall(uint32_t app, uint32_t message, XDWORD* param1, XDWORD* param2)
|
DWORD XMsgInProcessCall(uint32_t app, uint32_t message, XDWORD* param1, XDWORD* param2)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue