mirror of
https://github.com/libretro/ppsspp.git
synced 2025-01-26 03:04:20 +00:00
Merge pull request #1251 from unknownbrackets/module-minor
Cleanup sceKernelGetModuleIdByAddress()
This commit is contained in:
commit
b5b13c6ab5
@ -200,7 +200,7 @@ bool ElfReader::LoadInto(u32 loadAddress)
|
||||
totalEnd = p->p_vaddr + p->p_memsz;
|
||||
}
|
||||
}
|
||||
u32 totalSize = totalEnd - totalStart;
|
||||
totalSize = totalEnd - totalStart;
|
||||
if (!bRelocate)
|
||||
{
|
||||
// Binary is prerelocated, load it where the first segment starts
|
||||
|
@ -111,6 +111,11 @@ public:
|
||||
return vaddr;
|
||||
}
|
||||
|
||||
u32 GetTotalSize()
|
||||
{
|
||||
return totalSize;
|
||||
}
|
||||
|
||||
// More indepth stuff:)
|
||||
bool LoadInto(u32 vaddr);
|
||||
bool LoadSymbols();
|
||||
@ -127,6 +132,7 @@ private:
|
||||
u32 *sectionAddrs;
|
||||
bool bRelocate;
|
||||
u32 entryPoint;
|
||||
u32 totalSize;
|
||||
u32 vaddr;
|
||||
u32 segmentVAddr[32];
|
||||
};
|
||||
|
@ -397,22 +397,20 @@ public:
|
||||
return static_cast<T *>(pool[realHandle]);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
T* GetByModuleByEntryAddr(u32 entryAddr)
|
||||
template <class T, typename ArgT>
|
||||
void Iterate(bool func(T *, ArgT), ArgT arg)
|
||||
{
|
||||
for (int i = 0; i < maxCount; ++i)
|
||||
for (int i = 0; i < maxCount; i++)
|
||||
{
|
||||
T* t = dynamic_cast<T*>(pool[i]);
|
||||
|
||||
if (!occupied[i])
|
||||
continue;
|
||||
T *t = dynamic_cast<T *>(pool[i]);
|
||||
if (t)
|
||||
{
|
||||
if (t->nm.entry_addr == entryAddr)
|
||||
{
|
||||
return t;
|
||||
}
|
||||
if (!func(t, arg))
|
||||
break;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static u32 GetMissingErrorCode() { return -1; } // TODO
|
||||
|
@ -165,12 +165,14 @@ public:
|
||||
{
|
||||
p.Do(nm);
|
||||
p.Do(memoryBlockAddr);
|
||||
p.Do(memoryBlockSize);
|
||||
p.DoMarker("Module");
|
||||
}
|
||||
|
||||
NativeModule nm;
|
||||
|
||||
u32 memoryBlockAddr;
|
||||
u32 memoryBlockSize;
|
||||
bool isFake;
|
||||
};
|
||||
|
||||
@ -232,7 +234,6 @@ struct SceKernelSMOption {
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// STATE BEGIN
|
||||
static int actionAfterModule;
|
||||
static SceUID mainModuleID; // hack
|
||||
// STATE END
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@ -243,7 +244,6 @@ void __KernelModuleInit()
|
||||
|
||||
void __KernelModuleDoState(PointerWrap &p)
|
||||
{
|
||||
p.Do(mainModuleID);
|
||||
p.Do(actionAfterModule);
|
||||
__KernelRestoreActionType(actionAfterModule, AfterModuleEntryCall::Create);
|
||||
p.DoMarker("sceKernelModule");
|
||||
@ -316,6 +316,7 @@ Module *__KernelLoadELFFromPtr(const u8 *ptr, u32 loadAddress, std::string *erro
|
||||
return 0;
|
||||
}
|
||||
module->memoryBlockAddr = reader.GetVaddr();
|
||||
module->memoryBlockSize = reader.GetTotalSize();
|
||||
|
||||
struct libent
|
||||
{
|
||||
@ -654,7 +655,6 @@ void __KernelStartModule(Module *m, int args, const char *argp, SceKernelSMOptio
|
||||
}
|
||||
|
||||
__KernelSetupRootThread(m->GetUID(), args, argp, options->priority, options->stacksize, options->attribute);
|
||||
mainModuleID = m->GetUID();
|
||||
//TODO: if current thread, put it in wait state, waiting for the new thread
|
||||
}
|
||||
|
||||
@ -722,7 +722,7 @@ bool __KernelLoadExec(const char *filename, SceKernelLoadExecParam *param, std::
|
||||
|
||||
__KernelStartModule(module, (u32)strlen(filename) + 1, filename, &option);
|
||||
|
||||
__KernelStartIdleThreads();
|
||||
__KernelStartIdleThreads(module->GetUID());
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -893,24 +893,36 @@ u32 sceKernelStopUnloadSelfModuleWithStatus(u32 moduleId, u32 argSize, u32 argp,
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct GetModuleIdByAddressArg
|
||||
{
|
||||
u32 addr;
|
||||
SceUID result;
|
||||
};
|
||||
|
||||
bool __GetModuleIdByAddressIterator(Module *module, GetModuleIdByAddressArg *state)
|
||||
{
|
||||
const u32 start = module->memoryBlockAddr, size = module->memoryBlockSize;
|
||||
printf("%08x - %08x ? %08x\n", start, start + size, state->addr);
|
||||
if (start <= state->addr && start + size > state->addr)
|
||||
{
|
||||
state->result = module->GetUID();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
u32 sceKernelGetModuleIdByAddress(u32 moduleAddr)
|
||||
{
|
||||
ERROR_LOG(HLE,"HACKIMPL sceKernelGetModuleIdByAddress(%08x)", moduleAddr);
|
||||
GetModuleIdByAddressArg state;
|
||||
state.addr = moduleAddr;
|
||||
state.result = SCE_KERNEL_ERROR_UNKNOWN_MODULE;
|
||||
|
||||
if ((moduleAddr & 0xFFFF0000) == 0x08800000)
|
||||
{
|
||||
return mainModuleID;
|
||||
}
|
||||
kernelObjects.Iterate(&__GetModuleIdByAddressIterator, &state);
|
||||
if (state.result == SCE_KERNEL_ERROR_UNKNOWN_MODULE)
|
||||
ERROR_LOG(HLE, "sceKernelGetModuleIdByAddress(%08x): module not found", moduleAddr)
|
||||
else
|
||||
{
|
||||
Module* foundMod= kernelObjects.GetByModuleByEntryAddr<Module>(moduleAddr);
|
||||
|
||||
if(foundMod)
|
||||
{
|
||||
return foundMod->GetUID();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
DEBUG_LOG(HLE, "%x=sceKernelGetModuleIdByAddress(%08x)", state.result, moduleAddr);
|
||||
return state.result;
|
||||
}
|
||||
|
||||
u32 sceKernelGetModuleId()
|
||||
|
@ -722,9 +722,6 @@ MipsCallManager mipsCalls;
|
||||
int actionAfterCallback;
|
||||
int actionAfterMipsCall;
|
||||
|
||||
// This seems nasty
|
||||
SceUID curModule;
|
||||
|
||||
// Doesn't need state saving.
|
||||
WaitTypeFuncs waitTypeFuncs[NUM_WAITTYPES];
|
||||
|
||||
@ -869,7 +866,6 @@ void __KernelThreadingDoState(PointerWrap &p)
|
||||
p.Do(threadqueue, dv);
|
||||
p.DoArray(threadIdleID, ARRAY_SIZE(threadIdleID));
|
||||
p.Do(dispatchEnabled);
|
||||
p.Do(curModule);
|
||||
|
||||
p.Do(threadReadyQueue);
|
||||
|
||||
@ -948,13 +944,13 @@ void __KernelChangeReadyState(SceUID threadID, bool ready)
|
||||
WARN_LOG(HLE, "Trying to change the ready state of an unknown thread?");
|
||||
}
|
||||
|
||||
void __KernelStartIdleThreads()
|
||||
void __KernelStartIdleThreads(SceUID moduleId)
|
||||
{
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
u32 error;
|
||||
Thread *t = kernelObjects.Get<Thread>(threadIdleID[i], error);
|
||||
t->nt.gpreg = __KernelGetModuleGP(curModule);
|
||||
t->nt.gpreg = __KernelGetModuleGP(moduleId);
|
||||
t->context.r[MIPS_REG_GP] = t->nt.gpreg;
|
||||
//t->context.pc += 4; // ADJUSTPC
|
||||
threadReadyQueue.prepare(t->nt.currentPriority);
|
||||
@ -1063,7 +1059,6 @@ void __KernelThreadingShutdown()
|
||||
cbReturnHackAddr = 0;
|
||||
currentThread = 0;
|
||||
intReturnHackAddr = 0;
|
||||
curModule = 0;
|
||||
hleCurrentThreadName = NULL;
|
||||
}
|
||||
|
||||
@ -1701,7 +1696,6 @@ Thread *__KernelCreateThread(SceUID &id, SceUID moduleId, const char *name, u32
|
||||
|
||||
void __KernelSetupRootThread(SceUID moduleID, int args, const char *argp, int prio, int stacksize, int attr)
|
||||
{
|
||||
curModule = moduleID;
|
||||
//grab mips regs
|
||||
SceUID id;
|
||||
Thread *thread = __KernelCreateThread(id, moduleID, "root", currentMIPS->pc, prio, stacksize, attr);
|
||||
@ -1758,10 +1752,7 @@ int __KernelCreateThread(const char *threadName, SceUID moduleID, u32 entry, u32
|
||||
|
||||
int sceKernelCreateThread(const char *threadName, u32 entry, u32 prio, int stacksize, u32 attr, u32 optionAddr)
|
||||
{
|
||||
SceUID moduleId = curModule;
|
||||
if (__GetCurrentThread())
|
||||
moduleId = __GetCurrentThread()->moduleId;
|
||||
return __KernelCreateThread(threadName, moduleId, entry, prio, stacksize, attr, optionAddr);
|
||||
return __KernelCreateThread(threadName, __KernelGetCurThreadModuleId(), entry, prio, stacksize, attr, optionAddr);
|
||||
}
|
||||
|
||||
|
||||
|
@ -185,7 +185,7 @@ u32 __KernelNotifyCallbackType(RegisteredCallbackType type, SceUID cbId, int not
|
||||
SceUID __KernelGetCurThread();
|
||||
SceUID __KernelGetCurThreadModuleId();
|
||||
void __KernelSetupRootThread(SceUID moduleId, int args, const char *argp, int prio, int stacksize, int attr); //represents the real PSP elf loader, run before execution
|
||||
void __KernelStartIdleThreads();
|
||||
void __KernelStartIdleThreads(SceUID moduleId);
|
||||
void __KernelReturnFromThread(); // Called as HLE function
|
||||
u32 __KernelGetThreadPrio(SceUID id);
|
||||
bool __KernelThreadSortPriority(SceUID thread1, SceUID thread2);
|
||||
|
Loading…
x
Reference in New Issue
Block a user