Bug: Fix bugs in allocation with function map

This commit is contained in:
zilmar 2013-01-05 09:47:28 +11:00
parent 23cc5f0a67
commit 14bd317e40
1 changed files with 11 additions and 14 deletions

View File

@ -23,23 +23,21 @@ CFunctionMap::~CFunctionMap()
bool CFunctionMap::AllocateMemory() bool CFunctionMap::AllocateMemory()
{ {
if (g_System->LookUpMode() == FuncFind_VirtualLookup) if (g_System->LookUpMode() == FuncFind_VirtualLookup && m_FunctionTable == NULL)
{ {
if (m_FunctionTable == NULL) m_FunctionTable = (PCCompiledFunc_TABLE *)VirtualAlloc(NULL,0xFFFFF * sizeof(CCompiledFunc *),MEM_RESERVE|MEM_COMMIT,PAGE_READWRITE);
{ if (m_FunctionTable == NULL) {
m_FunctionTable = (PCCompiledFunc_TABLE *)VirtualAlloc(NULL,0xFFFFF * sizeof(CCompiledFunc *),MEM_RESERVE|MEM_COMMIT,PAGE_READWRITE); WriteTrace(TraceError,__FUNCTION__ ": failed to allocate function table");
if (m_FunctionTable == NULL) { g_Notify->FatalError(MSG_MEM_ALLOC_ERROR);
WriteTrace(TraceError,__FUNCTION__ ": failed to allocate function table"); return false;
g_Notify->FatalError(MSG_MEM_ALLOC_ERROR);
return false;
}
memset(m_FunctionTable,0,0xFFFFF * sizeof(CCompiledFunc *));
} }
memset(m_FunctionTable,0,0xFFFFF * sizeof(CCompiledFunc *));
} }
if (g_System->LookUpMode() == FuncFind_PhysicalLookup) if (g_System->LookUpMode() == FuncFind_PhysicalLookup && m_JumpTable == NULL)
{ {
m_JumpTable = new PCCompiledFunc[g_MMU->RdramSize() >> 2]; m_JumpTable = new PCCompiledFunc[g_MMU->RdramSize() >> 2];
if (m_JumpTable == NULL) { if (m_JumpTable == NULL)
{
WriteTrace(TraceError,__FUNCTION__ ": failed to allocate jump table"); WriteTrace(TraceError,__FUNCTION__ ": failed to allocate jump table");
g_Notify->FatalError(MSG_MEM_ALLOC_ERROR); g_Notify->FatalError(MSG_MEM_ALLOC_ERROR);
return false; return false;
@ -73,8 +71,7 @@ void CFunctionMap::CleanBuffers ( void )
void CFunctionMap::Reset ( bool bAllocate ) void CFunctionMap::Reset ( bool bAllocate )
{ {
CleanBuffers(); CleanBuffers();
if (bAllocate && (g_System->LookUpMode() == FuncFind_VirtualLookup && m_FunctionTable != NULL) || if (bAllocate && (g_System->LookUpMode() == FuncFind_VirtualLookup || g_System->LookUpMode() == FuncFind_PhysicalLookup))
(g_System->LookUpMode() == FuncFind_PhysicalLookup && m_JumpTable != NULL))
{ {
AllocateMemory(); AllocateMemory();
} }