AcpHal Stubs

This commit is contained in:
Serenity
2025-04-20 02:21:41 -04:00
parent 177e8a069f
commit 1ee11e5d77
5 changed files with 198 additions and 435 deletions
+94 -135
View File
@@ -1,4 +1,4 @@
// AcpHal.cpp
// AcpHal.cpp
#include "pch.h"
#include "AcpHal.h"
@@ -8,10 +8,15 @@
#include "../common/debug.h"
#include "contexts.h"
#include <intsafe.h>
#include <new>
_RTL_CRITICAL_SECTION* criticalSection = nullptr;
static APU_HEAP g_ApuHeap = { 0 };
HRESULT AcpHalAllocateShapeContexts_X(SHAPE_CONTEXTS* ctx) {
if (!ctx)
return E_INVALIDARG;
memset(ctx, 0, sizeof(SHAPE_CONTEXTS));
if (ctx->numSrcContexts > 0)
ctx->srcContextArray = static_cast<SHAPE_SRC_CONTEXT*>(malloc(sizeof(SHAPE_SRC_CONTEXT) * ctx->numSrcContexts));
@@ -30,45 +35,81 @@ HRESULT AcpHalAllocateShapeContexts_X(SHAPE_CONTEXTS* ctx) {
if (ctx->numPcmContexts > 0)
ctx->pcmContextArray = static_cast<SHAPE_PCM_CONTEXT*>(malloc(sizeof(SHAPE_PCM_CONTEXT) * ctx->numPcmContexts));
printf("[AcpHal] allocated shape contexts\n");
printf("[AcpHalAllocateShapeContexts_X] Allocated shape context arrays.");
return S_OK;
}
HRESULT AcpHalReleaseShapeContexts_X() {
HRESULT AcpHalReleaseShapeContexts_X( ) {
DEBUG_PRINT( );
// Free any previously allocated context arrays
if (g_ApuHeap.NonCached) {
free(g_ApuHeap.NonCached);
g_ApuHeap.NonCached = NULL;
g_ApuHeap.NonCachedSize = 0;
}
if (g_ApuHeap.Cached) {
free(g_ApuHeap.Cached);
g_ApuHeap.Cached = NULL;
g_ApuHeap.CachedSize = 0;
}
printf("[AcpHal] released shape context memory and reset heap");
return S_OK;
}
HRESULT __stdcall AcpHalCreate_X(IAcpHal** acpInterface)
{
EnterCriticalSection((LPCRITICAL_SECTION) &criticalSection->LockSemaphore);
if (!acpInterface)
{
LeaveCriticalSection((LPCRITICAL_SECTION) &criticalSection->LockSemaphore);
return E_INVALIDARG;
}
return E_POINTER;
*acpInterface = new IAcpHal( );
AcpHal* instance = new (std::nothrow) AcpHal( );
if (!instance)
return E_OUTOFMEMORY;
LeaveCriticalSection((LPCRITICAL_SECTION) &criticalSection->LockSemaphore);
return *acpInterface ? S_OK : E_OUTOFMEMORY;
*acpInterface = instance;
printf("[AcpHalCreate_X] IAcpHal interface created successfully.\n");
return S_OK;
}
HRESULT ApuAlloc_X(
void** virtualAddress,
APU_ADDRESS* physicalAddress,
UINT32 sizeInBytes,
UINT32 alignmentInBytes,
UINT32 flags
void** virtualAddress,
APU_ADDRESS* physicalAddress,
UINT32 sizeInBytes,
UINT32 alignmentInBytes,
UINT32 flags
)
{
alignmentInBytes = 4;
DEBUG_PRINT( );
return 0;
if (!virtualAddress || sizeInBytes == 0 || alignmentInBytes == 0)
return E_INVALIDARG;
if ((alignmentInBytes & (alignmentInBytes - 1)) != 0 || alignmentInBytes < 4)
return E_INVALIDARG;
if ((flags != APU_ALLOC_CACHED) && (flags != APU_ALLOC_NONCACHED))
return E_INVALIDARG;
// Use aligned malloc for safe CPU-side simulation
void* alignedPtr = _aligned_malloc(sizeInBytes, alignmentInBytes);
if (!alignedPtr)
return E_OUTOFMEMORY;
*virtualAddress = alignedPtr;
// Simulate physical address (if needed)
if (physicalAddress)
*physicalAddress = reinterpret_cast<APU_ADDRESS>(alignedPtr);
printf("[ApuAlloc_X] Allocated %u bytes at 0x%p (aligned to %u bytes), flags=0x%X, phys=0x%llX\n",
sizeInBytes, alignedPtr, alignmentInBytes, flags,
physicalAddress ? *physicalAddress : 0);
return S_OK;
}
static APU_HEAP g_ApuHeap = { 0 };
HRESULT __stdcall ApuCreateHeap_X(UINT32 cachedSizeInBytes, UINT32 nonCachedSizeInBytes)
{
if (g_ApuHeap.Cached || g_ApuHeap.NonCached) {
@@ -92,48 +133,21 @@ HRESULT __stdcall ApuCreateHeap_X(UINT32 cachedSizeInBytes, UINT32 nonCachedSize
g_ApuHeap.NonCachedSize = nonCachedSizeInBytes;
return S_OK;
}
void ReleaseResourceEntry(_RTL_CRITICAL_SECTION* DebugInfo, void* virtualAddress) {
// Implementation of the function
// Assuming it releases some resources associated with the virtualAddress
// This is a placeholder implementation
if (DebugInfo && virtualAddress) {
// Perform resource release logic here
}
}
HRESULT __stdcall ApuHeapGetState_X(ApuHeapState* apuHeapState, UINT32 flags)
{
_RTL_CRITICAL_SECTION* p_LockSemaphore; // rbx
PRTL_CRITICAL_SECTION_DEBUG DebugInfo; // rax
DEBUG_PRINT( );
p_LockSemaphore = (_RTL_CRITICAL_SECTION*)&criticalSection->LockSemaphore;
EnterCriticalSection((LPCRITICAL_SECTION)& criticalSection->LockSemaphore);
if (!apuHeapState)
goto LABEL_9;
if (flags == 1)
{
DebugInfo = criticalSection[ 2 ].DebugInfo;
goto LABEL_4;
}
if (flags != 2)
{
LABEL_9:
LeaveCriticalSection(p_LockSemaphore);
return E_INVALIDARG;
}
DebugInfo = (PRTL_CRITICAL_SECTION_DEBUG)*&criticalSection[ 2 ].LockCount;
LABEL_4:
if (DebugInfo)
{
apuHeapState->allocationCount = (uint32_t)*&DebugInfo[ 1 ].ProcessLocksList.Blink;
LeaveCriticalSection(p_LockSemaphore);
}
else
{
LeaveCriticalSection(p_LockSemaphore);
return E_CRITICAL_SECTION_DEBUG_INFO_NOT_FOUND;
}
return 0;
return E_POINTER;
apuHeapState->bytesFree = 0; // Not tracked
apuHeapState->bytesAllocated = g_ApuHeap.CachedSize + g_ApuHeap.NonCachedSize;
apuHeapState->bytesLost = 0; // Not tracked
apuHeapState->maximumBlockSizeAvailable = 0; // Not tracked
apuHeapState->allocationCount = 0; // Not tracked
return S_OK;
}
bool ApuIsVirtualAddressValid_X(
@@ -142,75 +156,28 @@ bool ApuIsVirtualAddressValid_X(
)
{
DEBUG_PRINT( );
return 0;
if (!virtualAddress || physicalAlignmentInBytes == 0)
return false;
uintptr_t addr = reinterpret_cast<uintptr_t>(virtualAddress);
bool isAligned = (addr % physicalAlignmentInBytes) == 0;
return isAligned;
}
bool EnsureInitialized(_RTL_CRITICAL_SECTION* criticalSection) {
// Placeholder implementation for EnsureInitialized
// Assuming it checks if the critical section is initialized
return criticalSection && criticalSection->DebugInfo != nullptr;
}
HRESULT ApuFree_X(void* virtualAddress) {
_RTL_CRITICAL_SECTION* DebugInfo; // rcx
EnterCriticalSection((LPCRITICAL_SECTION)&criticalSection->LockSemaphore);
if (EnsureInitialized(criticalSection)) {
DebugInfo = (_RTL_CRITICAL_SECTION*)criticalSection[2].DebugInfo;
if (virtualAddress < DebugInfo->OwningThread || virtualAddress >= (void*)((char*)DebugInfo->OwningThread + DebugInfo->LockCount))
DebugInfo = (_RTL_CRITICAL_SECTION*)*&criticalSection[2].LockCount;
ReleaseResourceEntry(DebugInfo, virtualAddress);
}
LeaveCriticalSection((LPCRITICAL_SECTION)&criticalSection->LockSemaphore);
return E_FAIL;
}
APU_ADDRESS __stdcall ApuMapVirtualAddress_X(const void *virtualAddress) {
_RTL_CRITICAL_SECTION *p_LockSemaphore; // rbx
PRTL_CRITICAL_SECTION_DEBUG DebugInfo; // rcx
char v6; // al
p_LockSemaphore = (_RTL_CRITICAL_SECTION*)&criticalSection->LockSemaphore;
EnterCriticalSection((LPCRITICAL_SECTION) & criticalSection->LockSemaphore);
if (EnsureInitialized(criticalSection)) {
DebugInfo = criticalSection[2].DebugInfo;
if (virtualAddress < DebugInfo->ProcessLocksList.Flink
|| (v6 = 1, virtualAddress >= DebugInfo->ProcessLocksList.Flink + LODWORD(DebugInfo->CriticalSection))) {
v6 = 0;
}
if (!v6)
DebugInfo = (PRTL_CRITICAL_SECTION_DEBUG)*&criticalSection[2].LockCount;
return TranslateMemoryAddress(DebugInfo, virtualAddress);
}
LeaveCriticalSection(p_LockSemaphore);
return 0;
}
APU_ADDRESS __stdcall TranslateMemoryAddress(PRTL_CRITICAL_SECTION_DEBUG SECTION_DEBUG, const void* address)
HRESULT ApuFree_X(void* virtualAddress)
{
APU_ADDRESS Result; // rdi
PRTL_CRITICAL_SECTION_DEBUG DebugInfo; // rcx
if (!virtualAddress)
return E_INVALIDARG;
EnterCriticalSection((LPCRITICAL_SECTION)& SECTION_DEBUG->EntryCount);
if (address >= SECTION_DEBUG->ProcessLocksList.Flink
&& address < SECTION_DEBUG->ProcessLocksList.Flink + LODWORD(SECTION_DEBUG->CriticalSection))
{
for (DebugInfo = (PRTL_CRITICAL_SECTION_DEBUG)*&SECTION_DEBUG->Type;
DebugInfo && address >= DebugInfo->ProcessLocksList.Flink;
DebugInfo = (PRTL_CRITICAL_SECTION_DEBUG)*&DebugInfo->EntryCount)
{
if (LOBYTE(DebugInfo->Flags) && address < DebugInfo->ProcessLocksList.Flink + *&DebugInfo->Type)
{
Result = (APU_ADDRESS)((uintptr_t)address
+ (uintptr_t)DebugInfo->ProcessLocksList.Blink >> 32
- (uintptr_t)DebugInfo->ProcessLocksList.Flink);
break;
}
}
}
LeaveCriticalSection((LPCRITICAL_SECTION)&SECTION_DEBUG->EntryCount);
return Result;
_aligned_free(virtualAddress);
printf("[ApuFree_X] Freed memory at 0x%p\n", virtualAddress);
return S_OK;
}
APU_ADDRESS __stdcall ApuMapVirtualAddress_X(const void* virtualAddress) {
DEBUG_PRINT( );
return reinterpret_cast<APU_ADDRESS>(virtualAddress);
}
void* ApuMapApuAddress_X(
@@ -218,13 +185,5 @@ void* ApuMapApuAddress_X(
)
{
DEBUG_PRINT( );
return 0;
}
IAcpHal::IAcpHal( )
{
}
IAcpHal::~IAcpHal( )
{
return reinterpret_cast<void*>(apuPhysicalAddress);
}
+101 -36
View File
@@ -1,6 +1,10 @@
#pragma once
#include <inttypes.h>
#include "contexts.h"
#include "messages.h"
#include <cstdio>
#pragma once
typedef uint64_t APU_ADDRESS;
struct ApuHeapState {
/* 0x0000 */ public: uint32_t bytesFree;
@@ -15,18 +19,9 @@ typedef struct APU_HEAP {
UINT32 CachedSize;
UINT32 NonCachedSize;
} APU_HEAP;
#define APU_ALLOC_CACHED 0x1;
typedef uint64_t APU_ADDRESS;
HRESULT InitializeCriticalSectionWrapper( );
APU_ADDRESS __stdcall TranslateMemoryAddress(PRTL_CRITICAL_SECTION_DEBUG SECTION_DEBUG, const void* address);
BOOL __stdcall ManageThreadLocalStorage(HINSTANCE hModule, DWORD ul_reason_for_call, LPVOID lpReserved);
#pragma once
extern _RTL_CRITICAL_SECTION* criticalSection;
#define E_CRITICAL_SECTION_DEBUG_INFO_NOT_NULL 0x8ACA0001
#define E_CRITICAL_SECTION_DEBUG_INFO_NOT_FOUND 0x8ACA0002
static const UINT32 APU_ALLOC_CACHED = 0x00000001;
static const UINT32 APU_ALLOC_NONCACHED = 0x00000002;
#define ACPE_E_NOT_INITIALIZED HRESULT(0x8AC80002)
#define ACPE_E_RESOURCE_IN_USE HRESULT(0x8AC80010)
@@ -278,36 +273,106 @@ typedef struct AcpHal_SHAPE_CONTEXTS {
APU_ADDRESS apuPcmContextArray;
} AcpHal_SHAPE_CONTEXTS;
#pragma once
#include <windows.h>
enum ACP_COMMAND_TYPE
{
ACP_COMMAND_TYPE_LOAD_SHAPE_FLOWGRAPH = 1,
ACP_COMMAND_TYPE_REGISTER_MESSAGE,
ACP_COMMAND_TYPE_UNREGISTER_MESSAGE,
ACP_COMMAND_TYPE_START_FLOWGRAPH,
ACP_COMMAND_TYPE_ENABLE_XMA_CONTEXT,
ACP_COMMAND_TYPE_ENABLE_XMA_CONTEXTS,
ACP_COMMAND_TYPE_DISABLE_XMA_CONTEXT,
ACP_COMMAND_TYPE_DISABLE_XMA_CONTEXTS,
ACP_COMMAND_TYPE_UPDATE_SRC_CONTEXT,
ACP_COMMAND_TYPE_UPDATE_EQCOMP_CONTEXT,
ACP_COMMAND_TYPE_UPDATE_FILTVOL_CONTEXT,
ACP_COMMAND_TYPE_UPDATE_DMA_CONTEXT,
ACP_COMMAND_TYPE_UPDATE_PCM_CONTEXT,
ACP_COMMAND_TYPE_UPDATE_XMA_CONTEXT,
ACP_COMMAND_TYPE_INCREMENT_DMA_WRITE_POINTER,
ACP_COMMAND_TYPE_INCREMENT_DMA_READ_POINTER,
ACP_COMMAND_TYPE_INCREMENT_PCM_WRITE_POINTER,
ACP_COMMAND_TYPE_INCREMENT_XMA_WRITE_BUFFER_OFFSET_READ,
ACP_COMMAND_TYPE_UPDATE_XMA_READ_BUFFER,
ACP_COMMAND_TYPE_UPDATE_ALL_CONTEXTS,
ACP_COMMAND_TYPE_UPDATE_SRC_CONTEXTS,
ACP_COMMAND_TYPE_UPDATE_EQCOMP_CONTEXTS,
ACP_COMMAND_TYPE_UPDATE_FILTVOL_CONTEXTS,
ACP_COMMAND_TYPE_UPDATE_DMA_READ_CONTEXTS,
ACP_COMMAND_TYPE_UPDATE_DMA_WRITE_CONTEXTS,
ACP_COMMAND_TYPE_UPDATE_PCM_CONTEXTS,
ACP_COMMAND_TYPE_UPDATE_XMA_CONTEXTS,
ACP_COMMAND_TYPE_COUNT = ACP_COMMAND_TYPE_UPDATE_XMA_CONTEXTS
};
struct ACP_MESSAGE
{
UINT32 type; // Message type
UINT32 droppedMessageCount; // Count of dropped messages prior to this message
UINT32 usec; // time when this message is constructed
union // Message data
{
ACP_MESSAGE_AUDIO_FRAME_START audioFrameStart;
ACP_MESSAGE_FLOWGRAPH_COMPLETED flowgraphCompleted;
ACP_MESSAGE_SHAPE_COMMAND_BLOCKED shapeCommandBlocked;
ACP_MESSAGE_COMMAND_COMPLETED commandCompleted;
ACP_MESSAGE_FLOWGRAPH_TERMINATED flowgraphTerminated;
ACP_MESSAGE_ERROR error;
};
};
class IAcpHal
{
public:
IAcpHal( );
~IAcpHal( );
IAcpHal( ) { printf("[IAcpHal] Constructed\n"); }
virtual ~IAcpHal( ) { printf("[IAcpHal] Destructed\n"); }
// Possibly public API methods would go here later
// Add virtual destructor to allow safe deletion
virtual HRESULT __stdcall Connect(UINT32, UINT32) = 0;
virtual HRESULT __stdcall Disconnect( ) = 0;
virtual HRESULT __stdcall SubmitCommand(ACP_COMMAND_TYPE, UINT64, UINT32, const void*, APU_ADDRESS) = 0;
virtual bool __stdcall PopMessage(ACP_MESSAGE* msg) = 0;
virtual UINT32 __stdcall GetNumMessages( ) = 0;
virtual void __stdcall Release( ) = 0;
};
private:
void* m_initFunction; // Likely a function pointer or vtable
CRITICAL_SECTION m_critical1; // Offset +0x08
CRITICAL_SECTION m_critical2; // Offset +0x20
LPCRITICAL_SECTION m_sharedCritical;// From global criticalSection
int m_lockCount; // lockCount = sharedCritical->LockCount + 1
char m_someFlag; // LOBYTE set to 0
class AcpHal : public IAcpHal {
ULONG m_refCount = 1;
public:
AcpHal( ) { printf("[AcpHal] Constructed\n"); }
~AcpHal( ) { printf("[AcpHal] Destructed\n"); }
// COM reference tracking
ULONG AddRef( ) { return ++m_refCount; }
ULONG ReleaseRef( ) {
ULONG ref = --m_refCount;
if (ref == 0) {
delete this;
return 0;
}
return ref;
}
// IAcpHal methods
HRESULT __stdcall Connect(UINT32, UINT32) override { printf("Connect()\n"); return S_OK; }
HRESULT __stdcall Disconnect( ) override { printf("Disconnect()\n"); return S_OK; }
HRESULT __stdcall SubmitCommand(ACP_COMMAND_TYPE, UINT64, UINT32, const void*, APU_ADDRESS) override {
printf("SubmitCommand()\n");
return S_OK;
}
bool __stdcall PopMessage(ACP_MESSAGE* msg) override {
printf("PopMessage()\n");
if (msg) ZeroMemory(msg, sizeof(*msg));
return false;
}
UINT32 __stdcall GetNumMessages( ) override {
printf("GetNumMessages()\n");
return 0;
}
void __stdcall Release( ) override {
printf("Release() called\n");
ReleaseRef( ); // Properly manages reference count
}
// Remaining zeroed memory — treated as reserved/internal state
int m_padding;
int m_lockCount2;
int64_t m_dummy2;
int64_t m_threadPtr;
int64_t m_lockSem;
int64_t m_spinCount;
int64_t m_debug1;
int64_t m_lockSem2;
int64_t m_spinCount2;
int64_t m_debug2;
int m_lockCount3;
int m_lockCount4;
};
+1 -1
View File
@@ -1,5 +1,5 @@
#pragma once
#include "AcpHal.h"
struct SHAPE_EQCOMP_CONTEXT {
UINT32 timestamp : 21;
UINT32 reserved0 : 2;
+1 -261
View File
@@ -6,11 +6,6 @@
#include <corecrt_startup.h>
#include <cstdint>
#include "AcpHal.h"
BOOL(__stdcall* CustomDllEntryPoint)(HMODULE, DWORD, LPVOID);
void* Block;
uintptr_t _security_cookie;
uint64_t _security_cookie_complement = 0xFFFFD466D2205DCDULL;
BOOL APIENTRY DllMain(HMODULE hModule,
DWORD ul_reason_for_call,
@@ -23,55 +18,9 @@ BOOL APIENTRY DllMain(HMODULE hModule,
{
case DLL_PROCESS_ATTACH:
if (CustomDllEntryPoint)
{
dll_custom_init_success = 1;
success = CustomDllEntryPoint(hModule, DLL_PROCESS_ATTACH, lpReserved);
}
if (success)
success = ManageThreadLocalStorage(hModule, DLL_PROCESS_ATTACH, lpReserved);
if (success)
if (InitializeCriticalSectionWrapper( ) < 0)
return FALSE;
if (!success)
{
if (criticalSection)
{
//CleanupCriticalSectionResources(criticalSection);
operator delete(criticalSection);
}
criticalSection = 0;
ManageThreadLocalStorage(hModule, DLL_PROCESS_DETACH, nullptr);
if (CustomDllEntryPoint)
CustomDllEntryPoint(hModule, DLL_PROCESS_DETACH, nullptr);
}
break;
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
if (dll_custom_init_success && CustomDllEntryPoint)
success = CustomDllEntryPoint(hModule, ul_reason_for_call, lpReserved);
if (success)
success = ManageThreadLocalStorage(hModule, ul_reason_for_call, lpReserved);
break;
case DLL_PROCESS_DETACH:
if (dll_custom_init_success && CustomDllEntryPoint)
success = CustomDllEntryPoint(hModule, DLL_PROCESS_DETACH, lpReserved);
ManageThreadLocalStorage(hModule, DLL_PROCESS_DETACH, lpReserved);
if (criticalSection)
{
//CleanupCriticalSectionResources(criticalSection);
operator delete(criticalSection);
}
criticalSection = 0;
break;
default:
@@ -80,213 +29,4 @@ BOOL APIENTRY DllMain(HMODULE hModule,
}
return success;
}
void amsg_exit(int exit_code)
{
char message[ 64 ];
sprintf_s(message, sizeof(message), "Critical Error: Exit Code %d", exit_code);
MessageBoxA(NULL, message, "Critical Error", MB_ICONERROR | MB_OK);
ExitProcess(exit_code);
}
void initterm(const _PVFV* first, const _PVFV* last)
{
while (first < last)
{
if (*first)
(*first)();
++first;
}
}
const _PVFV First = NULL;
const _PVFV Last = NULL;
void* TlsCallbackListEnd;
uintptr_t InitializeSecurityCookie( )
{
if (_security_cookie == 0x2B992DDFA232ULL)
{
FILETIME systemTimeAsFileTime = { 0 };
LARGE_INTEGER performanceCount;
DWORD cookie;
GetSystemTimeAsFileTime(&systemTimeAsFileTime);
cookie = systemTimeAsFileTime.dwLowDateTime;
cookie |= systemTimeAsFileTime.dwHighDateTime << 32;
cookie ^= GetCurrentProcessId( );
cookie ^= GetCurrentThreadId( );
cookie ^= (GetTickCount( ) << 24);
cookie ^= GetTickCount( );
QueryPerformanceCounter(&performanceCount);
cookie ^= performanceCount.QuadPart;
cookie ^= (performanceCount.LowPart << 32);
cookie &= 0xFFFFFFFFFFFFULL;
if (cookie == 0x2B992DDFA232ULL)
cookie = 0x2B992DDFA233ULL;
_security_cookie = cookie;
}
_security_cookie_complement = ~_security_cookie;
return _security_cookie_complement;
}
BOOL __stdcall ManageThreadLocalStorage(HINSTANCE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
static volatile LONG64 tlsSynchronizationLock = 0;
static int dll_pending_operations = 0;
static int tlsInitializationState = 0; // 0: uninitialized, 1: initializing, 2: initialized
LONG64 currentStackBase = reinterpret_cast<LONG64>(reinterpret_cast<PNT_TIB>(NtCurrentTeb( ))->StackBase);
// Acquire synchronization lock
while (_InterlockedCompareExchange64(&tlsSynchronizationLock, currentStackBase, 0) != 0)
Sleep(10);
BOOL result = TRUE;
if (ul_reason_for_call == DLL_PROCESS_ATTACH)
{
if (tlsInitializationState != 0)
{
amsg_exit(31);
result = FALSE;
goto cleanup;
}
tlsInitializationState = 1;
// TLS initialization
initterm(&First, &Last);
tlsInitializationState = 2;
++dll_pending_operations;
}
else if (ul_reason_for_call == DLL_PROCESS_DETACH)
{
if (dll_pending_operations <= 0 || tlsInitializationState != 2)
{
amsg_exit(31);
result = FALSE;
goto cleanup;
}
--dll_pending_operations;
// TLS cleanup
if (Block)
{
for (void (**callback)(void) = reinterpret_cast<void (**)(void)>(Block);
callback < reinterpret_cast<void (**)(void)>(TlsCallbackListEnd);
++callback)
{
if (*callback)
(*callback)();
}
free(Block);
Block = nullptr;
TlsCallbackListEnd = nullptr;
}
tlsInitializationState = 0;
}
cleanup:
_InterlockedExchange64(&tlsSynchronizationLock, 0);
return result;
}
HRESULT InitializeCriticalSectionWrapper( )
{
if (criticalSection)
return E_UNEXPECTED; // Already initialized.
LPCRITICAL_SECTION css = (LPCRITICAL_SECTION)operator new(0xB8);
if (!css)
return E_OUTOFMEMORY;
InitializeCriticalSection((LPCRITICAL_SECTION) &css->LockSemaphore);
css->DebugInfo = nullptr;
css->LockCount = 0;
css->OwningThread = nullptr;
css[ 3 ].DebugInfo = nullptr;
*reinterpret_cast<__int64*>(&css[ 3 ].LockCount) = 0;
css[ 3 ].OwningThread = nullptr;
css[ 2 ].DebugInfo = nullptr;
*reinterpret_cast<__int64*>(&css[ 2 ].LockCount) = 0;
css[ 2 ].OwningThread = nullptr;
css[ 2 ].LockSemaphore = nullptr;
css[ 2 ].SpinCount = 0;
reinterpret_cast<DWORD&>(css[ 1 ].LockSemaphore) = 0;
reinterpret_cast<BYTE*>(&css[ 1 ].LockSemaphore)[ 4 ] = 0;
css[ 3 ].LockSemaphore = nullptr;
reinterpret_cast<DWORD*>(&css[ 1 ].SpinCount)[ 0 ] = 0x4000000;
reinterpret_cast<DWORD*>(&css[ 1 ].SpinCount)[ 1 ] = 1130496;
memset(&css[ 3 ].SpinCount, 0, 0x20);
criticalSection = css;
return S_OK;
}
HRESULT __stdcall QueueEventRequest(LPCRITICAL_SECTION criticalSection, HRESULT requestType, __int64 requestData)
{
HRESULT result = S_OK;
EnterCriticalSection(criticalSection);
if (requestData || requestType == 0x80000006)
{
PRTL_CRITICAL_SECTION_DEBUG debugInfo = reinterpret_cast<PRTL_CRITICAL_SECTION_DEBUG>(criticalSection[3].DebugInfo);
if (debugInfo->Type)
{
result = 0x8AC80003;
}
else
{
*(reinterpret_cast<int*>(&debugInfo->CreatorBackTraceIndex) + 1) = 0;
*reinterpret_cast<__int64*>(reinterpret_cast<char*>(debugInfo) + 8) = 0;
*reinterpret_cast<HRESULT*>(reinterpret_cast<char*>(debugInfo) + 16) = requestType;
switch (requestType)
{
case 0x80000000:
break;
case 0x80000001:
break;
case 0x80000002:
break;
}
++reinterpret_cast<int*>(criticalSection[3].LockSemaphore)[1];
debugInfo->Type = 1;
debugInfo = reinterpret_cast<PRTL_CRITICAL_SECTION_DEBUG>(reinterpret_cast<char*>(debugInfo) + 256);
if (reinterpret_cast<__int64>(debugInfo) >= reinterpret_cast<__int64>(criticalSection[3].OwningThread))
debugInfo = reinterpret_cast<PRTL_CRITICAL_SECTION_DEBUG>(criticalSection[3].DebugInfo);
criticalSection[3].LockCount = reinterpret_cast<LONG>(debugInfo);
}
}
else
{
result = E_INVALIDARG; // E_INVALIDARG
}
LeaveCriticalSection(criticalSection);
return result;
}
}
+1 -2
View File
@@ -1,6 +1,5 @@
#pragma once
typedef UINT32 APU_ADDRESS;
typedef uint64_t APU_ADDRESS;
struct ACP_MESSAGE_AUDIO_FRAME_START
{
UINT32 audioFrame; // Audio frame index