Kernel: Rename conflicting kernel object names.
These are names that can often conflict with system headers in ports. Let's just simplify by prefixing with PSP. No actual functional/code changes, just syntax and names.
This commit is contained in:
parent
a540274435
commit
7d36b70a8e
11 changed files with 327 additions and 418 deletions
|
@ -21,7 +21,7 @@
|
||||||
|
|
||||||
class KernelThreadDebugInterface : public MIPSDebugInterface {
|
class KernelThreadDebugInterface : public MIPSDebugInterface {
|
||||||
public:
|
public:
|
||||||
KernelThreadDebugInterface(MIPSState *c, ThreadContext &t) : MIPSDebugInterface(c), ctx(t) {
|
KernelThreadDebugInterface(MIPSState *c, PSPThreadContext &t) : MIPSDebugInterface(c), ctx(t) {
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int getPC() override { return ctx.pc; }
|
unsigned int getPC() override { return ctx.pc; }
|
||||||
|
@ -86,5 +86,5 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
ThreadContext &ctx;
|
PSPThreadContext &ctx;
|
||||||
};
|
};
|
||||||
|
|
|
@ -764,10 +764,10 @@ typedef struct {
|
||||||
#pragma pack(pop)
|
#pragma pack(pop)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
class AfterMatchingMipsCall : public Action {
|
class AfterMatchingMipsCall : public PSPAction {
|
||||||
public:
|
public:
|
||||||
AfterMatchingMipsCall() {}
|
AfterMatchingMipsCall() {}
|
||||||
static Action *Create() { return new AfterMatchingMipsCall(); }
|
static PSPAction *Create() { return new AfterMatchingMipsCall(); }
|
||||||
void DoState(PointerWrap &p) override {
|
void DoState(PointerWrap &p) override {
|
||||||
auto s = p.Section("AfterMatchingMipsCall", 1, 2);
|
auto s = p.Section("AfterMatchingMipsCall", 1, 2);
|
||||||
if (!s)
|
if (!s)
|
||||||
|
|
|
@ -338,10 +338,10 @@ private:
|
||||||
DISALLOW_COPY_AND_ASSIGN(LoadedFont);
|
DISALLOW_COPY_AND_ASSIGN(LoadedFont);
|
||||||
};
|
};
|
||||||
|
|
||||||
class PostAllocCallback : public Action {
|
class PostAllocCallback : public PSPAction {
|
||||||
public:
|
public:
|
||||||
PostAllocCallback() {}
|
PostAllocCallback() {}
|
||||||
static Action *Create() { return new PostAllocCallback(); }
|
static PSPAction *Create() { return new PostAllocCallback(); }
|
||||||
void DoState(PointerWrap &p) override {
|
void DoState(PointerWrap &p) override {
|
||||||
auto s = p.Section("PostAllocCallback", 1, 2);
|
auto s = p.Section("PostAllocCallback", 1, 2);
|
||||||
if (!s)
|
if (!s)
|
||||||
|
@ -360,10 +360,10 @@ private:
|
||||||
u32 errorCodePtr_;
|
u32 errorCodePtr_;
|
||||||
};
|
};
|
||||||
|
|
||||||
class PostOpenCallback : public Action {
|
class PostOpenCallback : public PSPAction {
|
||||||
public:
|
public:
|
||||||
PostOpenCallback() {}
|
PostOpenCallback() {}
|
||||||
static Action *Create() { return new PostOpenCallback(); }
|
static PSPAction *Create() { return new PostOpenCallback(); }
|
||||||
void DoState(PointerWrap &p) override {
|
void DoState(PointerWrap &p) override {
|
||||||
auto s = p.Section("PostOpenCallback", 1);
|
auto s = p.Section("PostOpenCallback", 1);
|
||||||
if (!s)
|
if (!s)
|
||||||
|
|
|
@ -37,16 +37,14 @@ struct NativeAlarm
|
||||||
u32_le commonPtr;
|
u32_le commonPtr;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Alarm : public KernelObject
|
struct PSPAlarm : public KernelObject {
|
||||||
{
|
|
||||||
const char *GetName() override {return "[Alarm]";}
|
const char *GetName() override {return "[Alarm]";}
|
||||||
const char *GetTypeName() override {return "Alarm";}
|
const char *GetTypeName() override {return "Alarm";}
|
||||||
static u32 GetMissingErrorCode() { return SCE_KERNEL_ERROR_UNKNOWN_ALMID; }
|
static u32 GetMissingErrorCode() { return SCE_KERNEL_ERROR_UNKNOWN_ALMID; }
|
||||||
static int GetStaticIDType() { return SCE_KERNEL_TMID_Alarm; }
|
static int GetStaticIDType() { return SCE_KERNEL_TMID_Alarm; }
|
||||||
int GetIDType() const override { return SCE_KERNEL_TMID_Alarm; }
|
int GetIDType() const override { return SCE_KERNEL_TMID_Alarm; }
|
||||||
|
|
||||||
void DoState(PointerWrap &p) override
|
void DoState(PointerWrap &p) override {
|
||||||
{
|
|
||||||
auto s = p.Section("Alarm", 1);
|
auto s = p.Section("Alarm", 1);
|
||||||
if (!s)
|
if (!s)
|
||||||
return;
|
return;
|
||||||
|
@ -57,7 +55,7 @@ struct Alarm : public KernelObject
|
||||||
NativeAlarm alm;
|
NativeAlarm alm;
|
||||||
};
|
};
|
||||||
|
|
||||||
void __KernelScheduleAlarm(Alarm *alarm, u64 micro);
|
void __KernelScheduleAlarm(PSPAlarm *alarm, u64 micro);
|
||||||
|
|
||||||
class AlarmIntrHandler : public IntrHandler
|
class AlarmIntrHandler : public IntrHandler
|
||||||
{
|
{
|
||||||
|
@ -69,7 +67,7 @@ public:
|
||||||
u32 error;
|
u32 error;
|
||||||
int alarmID = triggeredAlarm.front();
|
int alarmID = triggeredAlarm.front();
|
||||||
|
|
||||||
Alarm *alarm = kernelObjects.Get<Alarm>(alarmID, error);
|
PSPAlarm *alarm = kernelObjects.Get<PSPAlarm>(alarmID, error);
|
||||||
if (error)
|
if (error)
|
||||||
{
|
{
|
||||||
WARN_LOG(SCEKERNEL, "Ignoring deleted alarm %08x", alarmID);
|
WARN_LOG(SCEKERNEL, "Ignoring deleted alarm %08x", alarmID);
|
||||||
|
@ -95,7 +93,7 @@ public:
|
||||||
{
|
{
|
||||||
DEBUG_LOG(SCEKERNEL, "Rescheduling alarm %08x for +%dms", alarmID, result);
|
DEBUG_LOG(SCEKERNEL, "Rescheduling alarm %08x for +%dms", alarmID, result);
|
||||||
u32 error;
|
u32 error;
|
||||||
Alarm *alarm = kernelObjects.Get<Alarm>(alarmID, error);
|
PSPAlarm *alarm = kernelObjects.Get<PSPAlarm>(alarmID, error);
|
||||||
__KernelScheduleAlarm(alarm, result);
|
__KernelScheduleAlarm(alarm, result);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -106,21 +104,19 @@ public:
|
||||||
DEBUG_LOG(SCEKERNEL, "Finished alarm %08x", alarmID);
|
DEBUG_LOG(SCEKERNEL, "Finished alarm %08x", alarmID);
|
||||||
|
|
||||||
// Delete the alarm if it's not rescheduled.
|
// Delete the alarm if it's not rescheduled.
|
||||||
kernelObjects.Destroy<Alarm>(alarmID);
|
kernelObjects.Destroy<PSPAlarm>(alarmID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
static int alarmTimer = -1;
|
static int alarmTimer = -1;
|
||||||
|
|
||||||
static void __KernelTriggerAlarm(u64 userdata, int cyclesLate)
|
static void __KernelTriggerAlarm(u64 userdata, int cyclesLate) {
|
||||||
{
|
|
||||||
int uid = (int) userdata;
|
int uid = (int) userdata;
|
||||||
|
|
||||||
u32 error;
|
u32 error;
|
||||||
Alarm *alarm = kernelObjects.Get<Alarm>(uid, error);
|
PSPAlarm *alarm = kernelObjects.Get<PSPAlarm>(uid, error);
|
||||||
if (alarm)
|
if (alarm) {
|
||||||
{
|
|
||||||
triggeredAlarm.push_back(uid);
|
triggeredAlarm.push_back(uid);
|
||||||
__TriggerInterrupt(PSP_INTR_IMMEDIATE, PSP_SYSTIMER0_INTR);
|
__TriggerInterrupt(PSP_INTR_IMMEDIATE, PSP_SYSTIMER0_INTR);
|
||||||
}
|
}
|
||||||
|
@ -144,14 +140,12 @@ void __KernelAlarmDoState(PointerWrap &p)
|
||||||
CoreTiming::RestoreRegisterEvent(alarmTimer, "Alarm", __KernelTriggerAlarm);
|
CoreTiming::RestoreRegisterEvent(alarmTimer, "Alarm", __KernelTriggerAlarm);
|
||||||
}
|
}
|
||||||
|
|
||||||
KernelObject *__KernelAlarmObject()
|
KernelObject *__KernelAlarmObject() {
|
||||||
{
|
|
||||||
// Default object to load from state.
|
// Default object to load from state.
|
||||||
return new Alarm;
|
return new PSPAlarm;
|
||||||
}
|
}
|
||||||
|
|
||||||
void __KernelScheduleAlarm(Alarm *alarm, u64 micro)
|
void __KernelScheduleAlarm(PSPAlarm *alarm, u64 micro) {
|
||||||
{
|
|
||||||
alarm->alm.schedule = CoreTiming::GetGlobalTimeUs() + micro;
|
alarm->alm.schedule = CoreTiming::GetGlobalTimeUs() + micro;
|
||||||
CoreTiming::ScheduleEvent(usToCycles(micro), alarmTimer, alarm->GetUID());
|
CoreTiming::ScheduleEvent(usToCycles(micro), alarmTimer, alarm->GetUID());
|
||||||
}
|
}
|
||||||
|
@ -161,7 +155,7 @@ static SceUID __KernelSetAlarm(u64 micro, u32 handlerPtr, u32 commonPtr)
|
||||||
if (!Memory::IsValidAddress(handlerPtr))
|
if (!Memory::IsValidAddress(handlerPtr))
|
||||||
return SCE_KERNEL_ERROR_ILLEGAL_ADDR;
|
return SCE_KERNEL_ERROR_ILLEGAL_ADDR;
|
||||||
|
|
||||||
Alarm *alarm = new Alarm;
|
PSPAlarm *alarm = new PSPAlarm();
|
||||||
SceUID uid = kernelObjects.Create(alarm);
|
SceUID uid = kernelObjects.Create(alarm);
|
||||||
|
|
||||||
alarm->alm.size = NATIVEALARM_SIZE;
|
alarm->alm.size = NATIVEALARM_SIZE;
|
||||||
|
@ -197,13 +191,13 @@ int sceKernelCancelAlarm(SceUID uid)
|
||||||
|
|
||||||
CoreTiming::UnscheduleEvent(alarmTimer, uid);
|
CoreTiming::UnscheduleEvent(alarmTimer, uid);
|
||||||
|
|
||||||
return kernelObjects.Destroy<Alarm>(uid);
|
return kernelObjects.Destroy<PSPAlarm>(uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
int sceKernelReferAlarmStatus(SceUID uid, u32 infoPtr)
|
int sceKernelReferAlarmStatus(SceUID uid, u32 infoPtr)
|
||||||
{
|
{
|
||||||
u32 error;
|
u32 error;
|
||||||
Alarm *alarm = kernelObjects.Get<Alarm>(uid, error);
|
PSPAlarm *alarm = kernelObjects.Get<PSPAlarm>(uid, error);
|
||||||
if (!alarm)
|
if (!alarm)
|
||||||
{
|
{
|
||||||
ERROR_LOG(SCEKERNEL, "sceKernelReferAlarmStatus(%08x, %08x): invalid alarm", uid, infoPtr);
|
ERROR_LOG(SCEKERNEL, "sceKernelReferAlarmStatus(%08x, %08x): invalid alarm", uid, infoPtr);
|
||||||
|
@ -228,4 +222,4 @@ int sceKernelReferAlarmStatus(SceUID uid, u32 infoPtr)
|
||||||
Memory::Write_U32(alarm->alm.commonPtr, infoPtr + 16);
|
Memory::Write_U32(alarm->alm.commonPtr, infoPtr + 16);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,15 +48,13 @@ static const u32 PSP_NUMBER_SUBINTERRUPTS = 32;
|
||||||
// INTERRUPT MANAGEMENT
|
// INTERRUPT MANAGEMENT
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
class InterruptState
|
class InterruptState {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
void save();
|
void save();
|
||||||
void restore();
|
void restore();
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
void DoState(PointerWrap &p)
|
void DoState(PointerWrap &p) {
|
||||||
{
|
|
||||||
auto s = p.Section("InterruptState", 1);
|
auto s = p.Section("InterruptState", 1);
|
||||||
if (!s)
|
if (!s)
|
||||||
return;
|
return;
|
||||||
|
@ -64,7 +62,7 @@ public:
|
||||||
p.Do(savedCpu);
|
p.Do(savedCpu);
|
||||||
}
|
}
|
||||||
|
|
||||||
ThreadContext savedCpu;
|
PSPThreadContext savedCpu;
|
||||||
};
|
};
|
||||||
|
|
||||||
// STATE
|
// STATE
|
||||||
|
|
|
@ -155,8 +155,8 @@ void ImportFuncSymbol(const FuncSymbolImport &func, bool reimporting);
|
||||||
void ExportFuncSymbol(const FuncSymbolExport &func);
|
void ExportFuncSymbol(const FuncSymbolExport &func);
|
||||||
void UnexportFuncSymbol(const FuncSymbolExport &func);
|
void UnexportFuncSymbol(const FuncSymbolExport &func);
|
||||||
|
|
||||||
class Module;
|
class PSPModule;
|
||||||
static bool KernelImportModuleFuncs(Module *module, u32 *firstImportStubAddr, bool reimporting = false);
|
static bool KernelImportModuleFuncs(PSPModule *module, u32 *firstImportStubAddr, bool reimporting = false);
|
||||||
|
|
||||||
struct NativeModule {
|
struct NativeModule {
|
||||||
u32_le next;
|
u32_le next;
|
||||||
|
@ -228,10 +228,10 @@ enum NativeModuleStatus {
|
||||||
MODULE_STATUS_UNLOADING = 8,
|
MODULE_STATUS_UNLOADING = 8,
|
||||||
};
|
};
|
||||||
|
|
||||||
class Module : public KernelObject {
|
class PSPModule : public KernelObject {
|
||||||
public:
|
public:
|
||||||
Module() : textStart(0), textEnd(0), libstub(0), libstubend(0), memoryBlockAddr(0), isFake(false) {}
|
PSPModule() : textStart(0), textEnd(0), libstub(0), libstubend(0), memoryBlockAddr(0), isFake(false) {}
|
||||||
~Module() {
|
~PSPModule() {
|
||||||
if (memoryBlockAddr) {
|
if (memoryBlockAddr) {
|
||||||
// If it's either below user memory, or using a high kernel bit, it's in kernel.
|
// If it's either below user memory, or using a high kernel bit, it's in kernel.
|
||||||
if (memoryBlockAddr < PSP_GetUserMemoryBase() || memoryBlockAddr > PSP_GetUserMemoryEnd()) {
|
if (memoryBlockAddr < PSP_GetUserMemoryBase() || memoryBlockAddr > PSP_GetUserMemoryEnd()) {
|
||||||
|
@ -421,10 +421,10 @@ public:
|
||||||
|
|
||||||
KernelObject *__KernelModuleObject()
|
KernelObject *__KernelModuleObject()
|
||||||
{
|
{
|
||||||
return new Module;
|
return new PSPModule;
|
||||||
}
|
}
|
||||||
|
|
||||||
class AfterModuleEntryCall : public Action {
|
class AfterModuleEntryCall : public PSPAction {
|
||||||
public:
|
public:
|
||||||
AfterModuleEntryCall() {}
|
AfterModuleEntryCall() {}
|
||||||
SceUID moduleID_;
|
SceUID moduleID_;
|
||||||
|
@ -438,7 +438,7 @@ public:
|
||||||
p.Do(moduleID_);
|
p.Do(moduleID_);
|
||||||
p.Do(retValAddr);
|
p.Do(retValAddr);
|
||||||
}
|
}
|
||||||
static Action *Create() {
|
static PSPAction *Create() {
|
||||||
return new AfterModuleEntryCall;
|
return new AfterModuleEntryCall;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -507,7 +507,7 @@ void __KernelModuleDoState(PointerWrap &p)
|
||||||
u32 error;
|
u32 error;
|
||||||
// We process these late, since they depend on loadedModules for interlinking.
|
// We process these late, since they depend on loadedModules for interlinking.
|
||||||
for (SceUID moduleId : loadedModules) {
|
for (SceUID moduleId : loadedModules) {
|
||||||
Module *module = kernelObjects.Get<Module>(moduleId, error);
|
PSPModule *module = kernelObjects.Get<PSPModule>(moduleId, error);
|
||||||
if (module && module->libstub != 0) {
|
if (module && module->libstub != 0) {
|
||||||
if (!KernelImportModuleFuncs(module, nullptr, true)) {
|
if (!KernelImportModuleFuncs(module, nullptr, true)) {
|
||||||
ERROR_LOG(LOADER, "Something went wrong loading imports on load state");
|
ERROR_LOG(LOADER, "Something went wrong loading imports on load state");
|
||||||
|
@ -655,7 +655,7 @@ void ImportVarSymbol(const VarSymbolImport &var) {
|
||||||
|
|
||||||
u32 error;
|
u32 error;
|
||||||
for (SceUID moduleId : loadedModules) {
|
for (SceUID moduleId : loadedModules) {
|
||||||
Module *module = kernelObjects.Get<Module>(moduleId, error);
|
PSPModule *module = kernelObjects.Get<PSPModule>(moduleId, error);
|
||||||
if (!module || !module->ImportsOrExportsModuleName(var.moduleName)) {
|
if (!module || !module->ImportsOrExportsModuleName(var.moduleName)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -676,7 +676,7 @@ void ImportVarSymbol(const VarSymbolImport &var) {
|
||||||
void ExportVarSymbol(const VarSymbolExport &var) {
|
void ExportVarSymbol(const VarSymbolExport &var) {
|
||||||
u32 error;
|
u32 error;
|
||||||
for (SceUID moduleId : loadedModules) {
|
for (SceUID moduleId : loadedModules) {
|
||||||
Module *module = kernelObjects.Get<Module>(moduleId, error);
|
PSPModule *module = kernelObjects.Get<PSPModule>(moduleId, error);
|
||||||
if (!module || !module->ImportsOrExportsModuleName(var.moduleName)) {
|
if (!module || !module->ImportsOrExportsModuleName(var.moduleName)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -694,7 +694,7 @@ void ExportVarSymbol(const VarSymbolExport &var) {
|
||||||
void UnexportVarSymbol(const VarSymbolExport &var) {
|
void UnexportVarSymbol(const VarSymbolExport &var) {
|
||||||
u32 error;
|
u32 error;
|
||||||
for (SceUID moduleId : loadedModules) {
|
for (SceUID moduleId : loadedModules) {
|
||||||
Module *module = kernelObjects.Get<Module>(moduleId, error);
|
PSPModule *module = kernelObjects.Get<PSPModule>(moduleId, error);
|
||||||
if (!module || !module->ImportsOrExportsModuleName(var.moduleName)) {
|
if (!module || !module->ImportsOrExportsModuleName(var.moduleName)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -724,7 +724,7 @@ void ImportFuncSymbol(const FuncSymbolImport &func, bool reimporting) {
|
||||||
|
|
||||||
u32 error;
|
u32 error;
|
||||||
for (SceUID moduleId : loadedModules) {
|
for (SceUID moduleId : loadedModules) {
|
||||||
Module *module = kernelObjects.Get<Module>(moduleId, error);
|
PSPModule *module = kernelObjects.Get<PSPModule>(moduleId, error);
|
||||||
if (!module || !module->ImportsOrExportsModuleName(func.moduleName)) {
|
if (!module || !module->ImportsOrExportsModuleName(func.moduleName)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -765,7 +765,7 @@ void ExportFuncSymbol(const FuncSymbolExport &func) {
|
||||||
|
|
||||||
u32 error;
|
u32 error;
|
||||||
for (SceUID moduleId : loadedModules) {
|
for (SceUID moduleId : loadedModules) {
|
||||||
Module *module = kernelObjects.Get<Module>(moduleId, error);
|
PSPModule *module = kernelObjects.Get<PSPModule>(moduleId, error);
|
||||||
if (!module || !module->ImportsOrExportsModuleName(func.moduleName)) {
|
if (!module || !module->ImportsOrExportsModuleName(func.moduleName)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -790,7 +790,7 @@ void UnexportFuncSymbol(const FuncSymbolExport &func) {
|
||||||
|
|
||||||
u32 error;
|
u32 error;
|
||||||
for (SceUID moduleId : loadedModules) {
|
for (SceUID moduleId : loadedModules) {
|
||||||
Module *module = kernelObjects.Get<Module>(moduleId, error);
|
PSPModule *module = kernelObjects.Get<PSPModule>(moduleId, error);
|
||||||
if (!module || !module->ImportsOrExportsModuleName(func.moduleName)) {
|
if (!module || !module->ImportsOrExportsModuleName(func.moduleName)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -806,7 +806,7 @@ void UnexportFuncSymbol(const FuncSymbolExport &func) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Module::Cleanup() {
|
void PSPModule::Cleanup() {
|
||||||
MIPSAnalyst::ForgetFunctions(textStart, textEnd);
|
MIPSAnalyst::ForgetFunctions(textStart, textEnd);
|
||||||
|
|
||||||
loadedModules.erase(GetUID());
|
loadedModules.erase(GetUID());
|
||||||
|
@ -909,7 +909,7 @@ static bool IsHLEVersionedModule(const char *name) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool KernelImportModuleFuncs(Module *module, u32 *firstImportStubAddr, bool reimporting) {
|
static bool KernelImportModuleFuncs(PSPModule *module, u32 *firstImportStubAddr, bool reimporting) {
|
||||||
struct PspLibStubEntry {
|
struct PspLibStubEntry {
|
||||||
u32_le name;
|
u32_le name;
|
||||||
u16_le version;
|
u16_le version;
|
||||||
|
@ -1090,8 +1090,8 @@ static int gzipDecompress(u8 *OutBuffer, int OutBufferLength, u8 *InBuffer) {
|
||||||
return stream.total_out;
|
return stream.total_out;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Module *__KernelLoadELFFromPtr(const u8 *ptr, size_t elfSize, u32 loadAddress, bool fromTop, std::string *error_string, u32 *magic, u32 &error) {
|
static PSPModule *__KernelLoadELFFromPtr(const u8 *ptr, size_t elfSize, u32 loadAddress, bool fromTop, std::string *error_string, u32 *magic, u32 &error) {
|
||||||
Module *module = new Module;
|
PSPModule *module = new PSPModule();
|
||||||
kernelObjects.Create(module);
|
kernelObjects.Create(module);
|
||||||
loadedModules.insert(module->GetUID());
|
loadedModules.insert(module->GetUID());
|
||||||
memset(&module->nm, 0, sizeof(module->nm));
|
memset(&module->nm, 0, sizeof(module->nm));
|
||||||
|
@ -1133,7 +1133,7 @@ static Module *__KernelLoadELFFromPtr(const u8 *ptr, size_t elfSize, u32 loadAdd
|
||||||
if (size > elfSize) {
|
if (size > elfSize) {
|
||||||
*error_string = StringFromFormat("ELF/PRX truncated: %d > %d", (int)size, (int)elfSize);
|
*error_string = StringFromFormat("ELF/PRX truncated: %d > %d", (int)size, (int)elfSize);
|
||||||
module->Cleanup();
|
module->Cleanup();
|
||||||
kernelObjects.Destroy<Module>(module->GetUID());
|
kernelObjects.Destroy<PSPModule>(module->GetUID());
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
const auto maxElfSize = std::max(head->elf_size, head->psp_size);
|
const auto maxElfSize = std::max(head->elf_size, head->psp_size);
|
||||||
|
@ -1166,7 +1166,7 @@ static Module *__KernelLoadELFFromPtr(const u8 *ptr, size_t elfSize, u32 loadAdd
|
||||||
if (addr == (u32)-1) {
|
if (addr == (u32)-1) {
|
||||||
error = SCE_KERNEL_ERROR_MEMBLOCK_ALLOC_FAILED;
|
error = SCE_KERNEL_ERROR_MEMBLOCK_ALLOC_FAILED;
|
||||||
module->Cleanup();
|
module->Cleanup();
|
||||||
kernelObjects.Destroy<Module>(module->GetUID());
|
kernelObjects.Destroy<PSPModule>(module->GetUID());
|
||||||
} else {
|
} else {
|
||||||
error = 0;
|
error = 0;
|
||||||
module->memoryBlockAddr = addr;
|
module->memoryBlockAddr = addr;
|
||||||
|
@ -1207,7 +1207,7 @@ static Module *__KernelLoadELFFromPtr(const u8 *ptr, size_t elfSize, u32 loadAdd
|
||||||
if (newptr)
|
if (newptr)
|
||||||
delete [] newptr;
|
delete [] newptr;
|
||||||
module->Cleanup();
|
module->Cleanup();
|
||||||
kernelObjects.Destroy<Module>(module->GetUID());
|
kernelObjects.Destroy<PSPModule>(module->GetUID());
|
||||||
error = SCE_KERNEL_ERROR_UNSUPPORTED_PRX_TYPE;
|
error = SCE_KERNEL_ERROR_UNSUPPORTED_PRX_TYPE;
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
@ -1221,7 +1221,7 @@ static Module *__KernelLoadELFFromPtr(const u8 *ptr, size_t elfSize, u32 loadAdd
|
||||||
if (newptr)
|
if (newptr)
|
||||||
delete [] newptr;
|
delete [] newptr;
|
||||||
module->Cleanup();
|
module->Cleanup();
|
||||||
kernelObjects.Destroy<Module>(module->GetUID());
|
kernelObjects.Destroy<PSPModule>(module->GetUID());
|
||||||
error = result;
|
error = result;
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
@ -1536,8 +1536,8 @@ static Module *__KernelLoadELFFromPtr(const u8 *ptr, size_t elfSize, u32 loadAdd
|
||||||
return module;
|
return module;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Module *__KernelLoadModule(u8 *fileptr, size_t fileSize, SceKernelLMOption *options, std::string *error_string) {
|
static PSPModule *__KernelLoadModule(u8 *fileptr, size_t fileSize, SceKernelLMOption *options, std::string *error_string) {
|
||||||
Module *module = 0;
|
PSPModule *module = nullptr;
|
||||||
// Check for PBP
|
// Check for PBP
|
||||||
if (memcmp(fileptr, "\0PBP", 4) == 0) {
|
if (memcmp(fileptr, "\0PBP", 4) == 0) {
|
||||||
// PBP!
|
// PBP!
|
||||||
|
@ -1583,8 +1583,7 @@ static Module *__KernelLoadModule(u8 *fileptr, size_t fileSize, SceKernelLMOptio
|
||||||
return module;
|
return module;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void __KernelStartModule(Module *m, int args, const char *argp, SceKernelSMOption *options)
|
static void __KernelStartModule(PSPModule *m, int args, const char *argp, SceKernelSMOption *options) {
|
||||||
{
|
|
||||||
m->nm.status = MODULE_STATUS_STARTED;
|
m->nm.status = MODULE_STATUS_STARTED;
|
||||||
if (m->nm.module_start_func != 0 && m->nm.module_start_func != (u32)-1)
|
if (m->nm.module_start_func != 0 && m->nm.module_start_func != (u32)-1)
|
||||||
{
|
{
|
||||||
|
@ -1599,16 +1598,12 @@ static void __KernelStartModule(Module *m, int args, const char *argp, SceKernel
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
u32 __KernelGetModuleGP(SceUID uid)
|
u32 __KernelGetModuleGP(SceUID uid) {
|
||||||
{
|
|
||||||
u32 error;
|
u32 error;
|
||||||
Module *module = kernelObjects.Get<Module>(uid, error);
|
PSPModule *module = kernelObjects.Get<PSPModule>(uid, error);
|
||||||
if (module)
|
if (module) {
|
||||||
{
|
|
||||||
return module->nm.gp_value;
|
return module->nm.gp_value;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1619,7 +1614,7 @@ void __KernelLoadReset() {
|
||||||
u32 error;
|
u32 error;
|
||||||
while (!loadedModules.empty()) {
|
while (!loadedModules.empty()) {
|
||||||
SceUID moduleID = *loadedModules.begin();
|
SceUID moduleID = *loadedModules.begin();
|
||||||
Module *module = kernelObjects.Get<Module>(moduleID, error);
|
PSPModule *module = kernelObjects.Get<PSPModule>(moduleID, error);
|
||||||
if (module) {
|
if (module) {
|
||||||
module->Cleanup();
|
module->Cleanup();
|
||||||
} else {
|
} else {
|
||||||
|
@ -1686,12 +1681,12 @@ bool __KernelLoadExec(const char *filename, u32 paramPtr, std::string *error_str
|
||||||
pspFileSystem.ReadFile(handle, temp, (size_t)info.size);
|
pspFileSystem.ReadFile(handle, temp, (size_t)info.size);
|
||||||
|
|
||||||
PSP_SetLoading("Loading modules...");
|
PSP_SetLoading("Loading modules...");
|
||||||
Module *module = __KernelLoadModule(temp, (size_t)info.size, 0, error_string);
|
PSPModule *module = __KernelLoadModule(temp, (size_t)info.size, 0, error_string);
|
||||||
|
|
||||||
if (!module || module->isFake) {
|
if (!module || module->isFake) {
|
||||||
if (module) {
|
if (module) {
|
||||||
module->Cleanup();
|
module->Cleanup();
|
||||||
kernelObjects.Destroy<Module>(module->GetUID());
|
kernelObjects.Destroy<PSPModule>(module->GetUID());
|
||||||
}
|
}
|
||||||
ERROR_LOG(LOADER, "Failed to load module %s", filename);
|
ERROR_LOG(LOADER, "Failed to load module %s", filename);
|
||||||
*error_string = "Failed to load executable: " + *error_string;
|
*error_string = "Failed to load executable: " + *error_string;
|
||||||
|
@ -1770,7 +1765,7 @@ bool __KernelLoadGEDump(const std::string &base_filename, std::string *error_str
|
||||||
Memory::WriteUnchecked_U32(runDumpCode[i], mipsr4k.pc + (int)i * sizeof(u32_le));
|
Memory::WriteUnchecked_U32(runDumpCode[i], mipsr4k.pc + (int)i * sizeof(u32_le));
|
||||||
}
|
}
|
||||||
|
|
||||||
Module *module = new Module;
|
PSPModule *module = new PSPModule();
|
||||||
kernelObjects.Create(module);
|
kernelObjects.Create(module);
|
||||||
loadedModules.insert(module->GetUID());
|
loadedModules.insert(module->GetUID());
|
||||||
memset(&module->nm, 0, sizeof(module->nm));
|
memset(&module->nm, 0, sizeof(module->nm));
|
||||||
|
@ -1847,7 +1842,7 @@ u32 sceKernelLoadModule(const char *name, u32 flags, u32 optionAddr) {
|
||||||
|
|
||||||
for (size_t i = 0; i < ARRAY_SIZE(lieAboutSuccessModules); i++) {
|
for (size_t i = 0; i < ARRAY_SIZE(lieAboutSuccessModules); i++) {
|
||||||
if (!strcmp(name, lieAboutSuccessModules[i])) {
|
if (!strcmp(name, lieAboutSuccessModules[i])) {
|
||||||
Module *module = new Module;
|
PSPModule *module = new PSPModule();
|
||||||
kernelObjects.Create(module);
|
kernelObjects.Create(module);
|
||||||
loadedModules.insert(module->GetUID());
|
loadedModules.insert(module->GetUID());
|
||||||
memset(&module->nm, 0, sizeof(module->nm));
|
memset(&module->nm, 0, sizeof(module->nm));
|
||||||
|
@ -1898,7 +1893,7 @@ u32 sceKernelLoadModule(const char *name, u32 flags, u32 optionAddr) {
|
||||||
WARN_LOG_REPORT(LOADER, "sceKernelLoadModule: unsupported options size=%08x, flags=%08x, pos=%d, access=%d, data=%d, text=%d", lmoption->size, lmoption->flags, lmoption->position, lmoption->access, lmoption->mpiddata, lmoption->mpidtext);
|
WARN_LOG_REPORT(LOADER, "sceKernelLoadModule: unsupported options size=%08x, flags=%08x, pos=%d, access=%d, data=%d, text=%d", lmoption->size, lmoption->flags, lmoption->position, lmoption->access, lmoption->mpiddata, lmoption->mpidtext);
|
||||||
}
|
}
|
||||||
|
|
||||||
Module *module = 0;
|
PSPModule *module = nullptr;
|
||||||
u8 *temp = new u8[(int)size];
|
u8 *temp = new u8[(int)size];
|
||||||
u32 handle = pspFileSystem.OpenFile(name, FILEACCESS_READ);
|
u32 handle = pspFileSystem.OpenFile(name, FILEACCESS_READ);
|
||||||
pspFileSystem.ReadFile(handle, temp, (size_t)size);
|
pspFileSystem.ReadFile(handle, temp, (size_t)size);
|
||||||
|
@ -1961,7 +1956,7 @@ static void sceKernelStartModule(u32 moduleId, u32 argsize, u32 argAddr, u32 ret
|
||||||
Memory::ReadStruct(optionAddr, &smoption);
|
Memory::ReadStruct(optionAddr, &smoption);
|
||||||
}
|
}
|
||||||
u32 error;
|
u32 error;
|
||||||
Module *module = kernelObjects.Get<Module>(moduleId, error);
|
PSPModule *module = kernelObjects.Get<PSPModule>(moduleId, error);
|
||||||
if (!module) {
|
if (!module) {
|
||||||
INFO_LOG(SCEMODULE, "sceKernelStartModule(%d,asize=%08x,aptr=%08x,retptr=%08x,%08x): error %08x", moduleId, argsize, argAddr, returnValueAddr, optionAddr, error);
|
INFO_LOG(SCEMODULE, "sceKernelStartModule(%d,asize=%08x,aptr=%08x,retptr=%08x,%08x): error %08x", moduleId, argsize, argAddr, returnValueAddr, optionAddr, error);
|
||||||
RETURN(error);
|
RETURN(error);
|
||||||
|
@ -2060,7 +2055,7 @@ static u32 sceKernelStopModule(u32 moduleId, u32 argSize, u32 argAddr, u32 retur
|
||||||
// TODO: In a lot of cases (even for errors), this should resched. Needs testing.
|
// TODO: In a lot of cases (even for errors), this should resched. Needs testing.
|
||||||
|
|
||||||
u32 error;
|
u32 error;
|
||||||
Module *module = kernelObjects.Get<Module>(moduleId, error);
|
PSPModule *module = kernelObjects.Get<PSPModule>(moduleId, error);
|
||||||
if (!module)
|
if (!module)
|
||||||
{
|
{
|
||||||
ERROR_LOG(SCEMODULE, "sceKernelStopModule(%08x, %08x, %08x, %08x, %08x): invalid module id", moduleId, argSize, argAddr, returnValueAddr, optionAddr);
|
ERROR_LOG(SCEMODULE, "sceKernelStopModule(%08x, %08x, %08x, %08x, %08x): invalid module id", moduleId, argSize, argAddr, returnValueAddr, optionAddr);
|
||||||
|
@ -2133,12 +2128,12 @@ static u32 sceKernelUnloadModule(u32 moduleId)
|
||||||
{
|
{
|
||||||
INFO_LOG(SCEMODULE,"sceKernelUnloadModule(%i)", moduleId);
|
INFO_LOG(SCEMODULE,"sceKernelUnloadModule(%i)", moduleId);
|
||||||
u32 error;
|
u32 error;
|
||||||
Module *module = kernelObjects.Get<Module>(moduleId, error);
|
PSPModule *module = kernelObjects.Get<PSPModule>(moduleId, error);
|
||||||
if (!module)
|
if (!module)
|
||||||
return hleDelayResult(error, "module unloaded", 150);
|
return hleDelayResult(error, "module unloaded", 150);
|
||||||
|
|
||||||
module->Cleanup();
|
module->Cleanup();
|
||||||
kernelObjects.Destroy<Module>(moduleId);
|
kernelObjects.Destroy<PSPModule>(moduleId);
|
||||||
return hleDelayResult(moduleId, "module unloaded", 500);
|
return hleDelayResult(moduleId, "module unloaded", 500);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2155,7 +2150,7 @@ u32 hleKernelStopUnloadSelfModuleWithOrWithoutStatus(u32 exitCode, u32 argSize,
|
||||||
// TODO: In a lot of cases (even for errors), this should resched. Needs testing.
|
// TODO: In a lot of cases (even for errors), this should resched. Needs testing.
|
||||||
|
|
||||||
u32 error;
|
u32 error;
|
||||||
Module *module = kernelObjects.Get<Module>(moduleID, error);
|
PSPModule *module = kernelObjects.Get<PSPModule>(moduleID, error);
|
||||||
if (!module) {
|
if (!module) {
|
||||||
if (WithStatus)
|
if (WithStatus)
|
||||||
ERROR_LOG(SCEMODULE, "sceKernelStopUnloadSelfModuleWithStatus(%08x, %08x, %08x, %08x, %08x): invalid module id", exitCode, argSize, argp, statusAddr, optionAddr);
|
ERROR_LOG(SCEMODULE, "sceKernelStopUnloadSelfModuleWithStatus(%08x, %08x, %08x, %08x, %08x): invalid module id", exitCode, argSize, argp, statusAddr, optionAddr);
|
||||||
|
@ -2204,7 +2199,7 @@ u32 hleKernelStopUnloadSelfModuleWithOrWithoutStatus(u32 exitCode, u32 argSize,
|
||||||
INFO_LOG(SCEMODULE, "sceKernelSelfStopUnloadModule(%08x, %08x, %08x): no stop func", exitCode, argSize, argp);
|
INFO_LOG(SCEMODULE, "sceKernelSelfStopUnloadModule(%08x, %08x, %08x): no stop func", exitCode, argSize, argp);
|
||||||
sceKernelExitDeleteThread(exitCode);
|
sceKernelExitDeleteThread(exitCode);
|
||||||
module->Cleanup();
|
module->Cleanup();
|
||||||
kernelObjects.Destroy<Module>(moduleID);
|
kernelObjects.Destroy<PSPModule>(moduleID);
|
||||||
} else {
|
} else {
|
||||||
if (WithStatus)
|
if (WithStatus)
|
||||||
ERROR_LOG_REPORT(SCEMODULE, "sceKernelStopUnloadSelfModuleWithStatus(%08x, %08x, %08x, %08x, %08x): bad stop func address", exitCode, argSize, argp, statusAddr, optionAddr);
|
ERROR_LOG_REPORT(SCEMODULE, "sceKernelStopUnloadSelfModuleWithStatus(%08x, %08x, %08x, %08x, %08x): bad stop func address", exitCode, argSize, argp, statusAddr, optionAddr);
|
||||||
|
@ -2212,7 +2207,7 @@ u32 hleKernelStopUnloadSelfModuleWithOrWithoutStatus(u32 exitCode, u32 argSize,
|
||||||
ERROR_LOG_REPORT(SCEMODULE, "sceKernelSelfStopUnloadModule(%08x, %08x, %08x): bad stop func address", exitCode, argSize, argp);
|
ERROR_LOG_REPORT(SCEMODULE, "sceKernelSelfStopUnloadModule(%08x, %08x, %08x): bad stop func address", exitCode, argSize, argp);
|
||||||
sceKernelExitDeleteThread(exitCode);
|
sceKernelExitDeleteThread(exitCode);
|
||||||
module->Cleanup();
|
module->Cleanup();
|
||||||
kernelObjects.Destroy<Module>(moduleID);
|
kernelObjects.Destroy<PSPModule>(moduleID);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (WithStatus)
|
if (WithStatus)
|
||||||
|
@ -2248,7 +2243,7 @@ void __KernelReturnFromModuleFunc()
|
||||||
sceKernelDeleteThread(leftThreadID);
|
sceKernelDeleteThread(leftThreadID);
|
||||||
|
|
||||||
u32 error;
|
u32 error;
|
||||||
Module *module = kernelObjects.Get<Module>(leftModuleID, error);
|
PSPModule *module = kernelObjects.Get<PSPModule>(leftModuleID, error);
|
||||||
if (!module) {
|
if (!module) {
|
||||||
ERROR_LOG_REPORT(SCEMODULE, "Returned from deleted module start/stop func");
|
ERROR_LOG_REPORT(SCEMODULE, "Returned from deleted module start/stop func");
|
||||||
return;
|
return;
|
||||||
|
@ -2278,7 +2273,7 @@ void __KernelReturnFromModuleFunc()
|
||||||
if (module->nm.status == MODULE_STATUS_UNLOADING) {
|
if (module->nm.status == MODULE_STATUS_UNLOADING) {
|
||||||
// TODO: Delete the waiting thread?
|
// TODO: Delete the waiting thread?
|
||||||
module->Cleanup();
|
module->Cleanup();
|
||||||
kernelObjects.Destroy<Module>(leftModuleID);
|
kernelObjects.Destroy<PSPModule>(leftModuleID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2288,11 +2283,9 @@ struct GetModuleIdByAddressArg
|
||||||
SceUID result;
|
SceUID result;
|
||||||
};
|
};
|
||||||
|
|
||||||
static bool __GetModuleIdByAddressIterator(Module *module, GetModuleIdByAddressArg *state)
|
static bool __GetModuleIdByAddressIterator(PSPModule *module, GetModuleIdByAddressArg *state) {
|
||||||
{
|
|
||||||
const u32 start = module->memoryBlockAddr, size = module->memoryBlockSize;
|
const u32 start = module->memoryBlockAddr, size = module->memoryBlockSize;
|
||||||
if (start != 0 && start <= state->addr && start + size > state->addr)
|
if (start != 0 && start <= state->addr && start + size > state->addr) {
|
||||||
{
|
|
||||||
state->result = module->GetUID();
|
state->result = module->GetUID();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -2351,7 +2344,7 @@ static u32 sceKernelLoadModuleByID(u32 id, u32 flags, u32 lmoptionPtr)
|
||||||
size_t size = pspFileSystem.SeekFile(handle, 0, FILEMOVE_END);
|
size_t size = pspFileSystem.SeekFile(handle, 0, FILEMOVE_END);
|
||||||
std::string error_string;
|
std::string error_string;
|
||||||
pspFileSystem.SeekFile(handle, pos, FILEMOVE_BEGIN);
|
pspFileSystem.SeekFile(handle, pos, FILEMOVE_BEGIN);
|
||||||
Module *module = 0;
|
PSPModule *module = nullptr;
|
||||||
u8 *temp = new u8[size - pos];
|
u8 *temp = new u8[size - pos];
|
||||||
pspFileSystem.ReadFile(handle, temp, size - pos);
|
pspFileSystem.ReadFile(handle, temp, size - pos);
|
||||||
u32 magic;
|
u32 magic;
|
||||||
|
@ -2409,7 +2402,7 @@ static SceUID sceKernelLoadModuleBufferUsbWlan(u32 size, u32 bufPtr, u32 flags,
|
||||||
WARN_LOG_REPORT(LOADER, "sceKernelLoadModuleBufferUsbWlan: unsupported options size=%08x, flags=%08x, pos=%d, access=%d, data=%d, text=%d", lmoption->size, lmoption->flags, lmoption->position, lmoption->access, lmoption->mpiddata, lmoption->mpidtext);
|
WARN_LOG_REPORT(LOADER, "sceKernelLoadModuleBufferUsbWlan: unsupported options size=%08x, flags=%08x, pos=%d, access=%d, data=%d, text=%d", lmoption->size, lmoption->flags, lmoption->position, lmoption->access, lmoption->mpiddata, lmoption->mpidtext);
|
||||||
}
|
}
|
||||||
std::string error_string;
|
std::string error_string;
|
||||||
Module *module = 0;
|
PSPModule *module = nullptr;
|
||||||
u32 magic;
|
u32 magic;
|
||||||
u32 error;
|
u32 error;
|
||||||
module = __KernelLoadELFFromPtr(Memory::GetPointer(bufPtr), size, 0, lmoption ? lmoption->position == PSP_SMEM_High : false, &error_string, &magic, error);
|
module = __KernelLoadELFFromPtr(Memory::GetPointer(bufPtr), size, 0, lmoption ? lmoption->position == PSP_SMEM_High : false, &error_string, &magic, error);
|
||||||
|
@ -2451,7 +2444,7 @@ static u32 sceKernelQueryModuleInfo(u32 uid, u32 infoAddr)
|
||||||
{
|
{
|
||||||
INFO_LOG(SCEMODULE, "sceKernelQueryModuleInfo(%i, %08x)", uid, infoAddr);
|
INFO_LOG(SCEMODULE, "sceKernelQueryModuleInfo(%i, %08x)", uid, infoAddr);
|
||||||
u32 error;
|
u32 error;
|
||||||
Module *module = kernelObjects.Get<Module>(uid, error);
|
PSPModule *module = kernelObjects.Get<PSPModule>(uid, error);
|
||||||
if (!module)
|
if (!module)
|
||||||
return error;
|
return error;
|
||||||
if (!Memory::IsValidAddress(infoAddr)) {
|
if (!Memory::IsValidAddress(infoAddr)) {
|
||||||
|
@ -2492,7 +2485,7 @@ static u32 sceKernelGetModuleIdList(u32 resultBuffer, u32 resultBufferSize, u32
|
||||||
|
|
||||||
u32 error;
|
u32 error;
|
||||||
for (SceUID moduleId : loadedModules) {
|
for (SceUID moduleId : loadedModules) {
|
||||||
Module *module = kernelObjects.Get<Module>(moduleId, error);
|
PSPModule *module = kernelObjects.Get<PSPModule>(moduleId, error);
|
||||||
if (!module->isFake) {
|
if (!module->isFake) {
|
||||||
if (resultBufferOffset < resultBufferSize) {
|
if (resultBufferOffset < resultBufferSize) {
|
||||||
Memory::Write_U32(module->GetUID(), resultBuffer + resultBufferOffset);
|
Memory::Write_U32(module->GetUID(), resultBuffer + resultBufferOffset);
|
||||||
|
|
|
@ -62,7 +62,7 @@ struct NativeMutex
|
||||||
s32_le numWaitThreads;
|
s32_le numWaitThreads;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Mutex : public KernelObject
|
struct PSPMutex : public KernelObject
|
||||||
{
|
{
|
||||||
const char *GetName() override { return nm.name; }
|
const char *GetName() override { return nm.name; }
|
||||||
const char *GetTypeName() override { return "Mutex"; }
|
const char *GetTypeName() override { return "Mutex"; }
|
||||||
|
@ -189,7 +189,7 @@ void __KernelMutexDoState(PointerWrap &p)
|
||||||
|
|
||||||
KernelObject *__KernelMutexObject()
|
KernelObject *__KernelMutexObject()
|
||||||
{
|
{
|
||||||
return new Mutex;
|
return new PSPMutex;
|
||||||
}
|
}
|
||||||
|
|
||||||
KernelObject *__KernelLwMutexObject()
|
KernelObject *__KernelLwMutexObject()
|
||||||
|
@ -202,8 +202,7 @@ void __KernelMutexShutdown()
|
||||||
mutexHeldLocks.clear();
|
mutexHeldLocks.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void __KernelMutexAcquireLock(Mutex *mutex, int count, SceUID thread)
|
static void __KernelMutexAcquireLock(PSPMutex *mutex, int count, SceUID thread) {
|
||||||
{
|
|
||||||
#if defined(_DEBUG)
|
#if defined(_DEBUG)
|
||||||
auto locked = mutexHeldLocks.equal_range(thread);
|
auto locked = mutexHeldLocks.equal_range(thread);
|
||||||
for (MutexMap::iterator iter = locked.first; iter != locked.second; ++iter)
|
for (MutexMap::iterator iter = locked.first; iter != locked.second; ++iter)
|
||||||
|
@ -216,13 +215,11 @@ static void __KernelMutexAcquireLock(Mutex *mutex, int count, SceUID thread)
|
||||||
mutex->nm.lockThread = thread;
|
mutex->nm.lockThread = thread;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void __KernelMutexAcquireLock(Mutex *mutex, int count)
|
static void __KernelMutexAcquireLock(PSPMutex *mutex, int count) {
|
||||||
{
|
|
||||||
__KernelMutexAcquireLock(mutex, count, __KernelGetCurThread());
|
__KernelMutexAcquireLock(mutex, count, __KernelGetCurThread());
|
||||||
}
|
}
|
||||||
|
|
||||||
static void __KernelMutexEraseLock(Mutex *mutex)
|
static void __KernelMutexEraseLock(PSPMutex *mutex) {
|
||||||
{
|
|
||||||
if (mutex->nm.lockThread != -1)
|
if (mutex->nm.lockThread != -1)
|
||||||
{
|
{
|
||||||
SceUID id = mutex->GetUID();
|
SceUID id = mutex->GetUID();
|
||||||
|
@ -259,8 +256,7 @@ static std::vector<SceUID>::iterator __KernelMutexFindPriority(std::vector<SceUI
|
||||||
return best;
|
return best;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool __KernelUnlockMutexForThread(Mutex *mutex, SceUID threadID, u32 &error, int result)
|
static bool __KernelUnlockMutexForThread(PSPMutex *mutex, SceUID threadID, u32 &error, int result) {
|
||||||
{
|
|
||||||
if (!HLEKernel::VerifyWait(threadID, WAITTYPE_MUTEX, mutex->GetUID()))
|
if (!HLEKernel::VerifyWait(threadID, WAITTYPE_MUTEX, mutex->GetUID()))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -283,8 +279,7 @@ static bool __KernelUnlockMutexForThread(Mutex *mutex, SceUID threadID, u32 &err
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool __KernelUnlockMutexForThreadCheck(Mutex *mutex, SceUID threadID, u32 &error, int result, bool &wokeThreads)
|
static bool __KernelUnlockMutexForThreadCheck(PSPMutex *mutex, SceUID threadID, u32 &error, int result, bool &wokeThreads) {
|
||||||
{
|
|
||||||
if (mutex->nm.lockThread == -1 && __KernelUnlockMutexForThread(mutex, threadID, error, 0))
|
if (mutex->nm.lockThread == -1 && __KernelUnlockMutexForThread(mutex, threadID, error, 0))
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
|
@ -292,7 +287,7 @@ static bool __KernelUnlockMutexForThreadCheck(Mutex *mutex, SceUID threadID, u32
|
||||||
|
|
||||||
void __KernelMutexBeginCallback(SceUID threadID, SceUID prevCallbackId)
|
void __KernelMutexBeginCallback(SceUID threadID, SceUID prevCallbackId)
|
||||||
{
|
{
|
||||||
auto result = HLEKernel::WaitBeginCallback<Mutex, WAITTYPE_MUTEX, SceUID>(threadID, prevCallbackId, mutexWaitTimer);
|
auto result = HLEKernel::WaitBeginCallback<PSPMutex, WAITTYPE_MUTEX, SceUID>(threadID, prevCallbackId, mutexWaitTimer);
|
||||||
if (result == HLEKernel::WAIT_CB_SUCCESS)
|
if (result == HLEKernel::WAIT_CB_SUCCESS)
|
||||||
DEBUG_LOG(SCEKERNEL, "sceKernelLockMutexCB: Suspending lock wait for callback");
|
DEBUG_LOG(SCEKERNEL, "sceKernelLockMutexCB: Suspending lock wait for callback");
|
||||||
else
|
else
|
||||||
|
@ -301,7 +296,7 @@ void __KernelMutexBeginCallback(SceUID threadID, SceUID prevCallbackId)
|
||||||
|
|
||||||
void __KernelMutexEndCallback(SceUID threadID, SceUID prevCallbackId)
|
void __KernelMutexEndCallback(SceUID threadID, SceUID prevCallbackId)
|
||||||
{
|
{
|
||||||
auto result = HLEKernel::WaitEndCallback<Mutex, WAITTYPE_MUTEX, SceUID>(threadID, prevCallbackId, mutexWaitTimer, __KernelUnlockMutexForThreadCheck);
|
auto result = HLEKernel::WaitEndCallback<PSPMutex, WAITTYPE_MUTEX, SceUID>(threadID, prevCallbackId, mutexWaitTimer, __KernelUnlockMutexForThreadCheck);
|
||||||
if (result == HLEKernel::WAIT_CB_RESUMED_WAIT)
|
if (result == HLEKernel::WAIT_CB_RESUMED_WAIT)
|
||||||
DEBUG_LOG(SCEKERNEL, "sceKernelLockMutexCB: Resuming lock wait for callback");
|
DEBUG_LOG(SCEKERNEL, "sceKernelLockMutexCB: Resuming lock wait for callback");
|
||||||
}
|
}
|
||||||
|
@ -324,7 +319,7 @@ int sceKernelCreateMutex(const char *name, u32 attr, int initialCount, u32 optio
|
||||||
if ((attr & PSP_MUTEX_ATTR_ALLOW_RECURSIVE) == 0 && initialCount > 1)
|
if ((attr & PSP_MUTEX_ATTR_ALLOW_RECURSIVE) == 0 && initialCount > 1)
|
||||||
return SCE_KERNEL_ERROR_ILLEGAL_COUNT;
|
return SCE_KERNEL_ERROR_ILLEGAL_COUNT;
|
||||||
|
|
||||||
Mutex *mutex = new Mutex();
|
PSPMutex *mutex = new PSPMutex();
|
||||||
SceUID id = kernelObjects.Create(mutex);
|
SceUID id = kernelObjects.Create(mutex);
|
||||||
|
|
||||||
mutex->nm.size = sizeof(mutex->nm);
|
mutex->nm.size = sizeof(mutex->nm);
|
||||||
|
@ -357,7 +352,7 @@ int sceKernelCreateMutex(const char *name, u32 attr, int initialCount, u32 optio
|
||||||
int sceKernelDeleteMutex(SceUID id)
|
int sceKernelDeleteMutex(SceUID id)
|
||||||
{
|
{
|
||||||
u32 error;
|
u32 error;
|
||||||
Mutex *mutex = kernelObjects.Get<Mutex>(id, error);
|
PSPMutex *mutex = kernelObjects.Get<PSPMutex>(id, error);
|
||||||
if (mutex)
|
if (mutex)
|
||||||
{
|
{
|
||||||
DEBUG_LOG(SCEKERNEL, "sceKernelDeleteMutex(%i)", id);
|
DEBUG_LOG(SCEKERNEL, "sceKernelDeleteMutex(%i)", id);
|
||||||
|
@ -373,7 +368,7 @@ int sceKernelDeleteMutex(SceUID id)
|
||||||
if (wokeThreads)
|
if (wokeThreads)
|
||||||
hleReSchedule("mutex deleted");
|
hleReSchedule("mutex deleted");
|
||||||
|
|
||||||
return kernelObjects.Destroy<Mutex>(id);
|
return kernelObjects.Destroy<PSPMutex>(id);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -382,8 +377,7 @@ int sceKernelDeleteMutex(SceUID id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool __KernelLockMutexCheck(Mutex *mutex, int count, u32 &error)
|
static bool __KernelLockMutexCheck(PSPMutex *mutex, int count, u32 &error) {
|
||||||
{
|
|
||||||
if (error)
|
if (error)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -411,8 +405,7 @@ static bool __KernelLockMutexCheck(Mutex *mutex, int count, u32 &error)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool __KernelLockMutex(Mutex *mutex, int count, u32 &error)
|
static bool __KernelLockMutex(PSPMutex *mutex, int count, u32 &error) {
|
||||||
{
|
|
||||||
if (!__KernelLockMutexCheck(mutex, count, error))
|
if (!__KernelLockMutexCheck(mutex, count, error))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -433,8 +426,7 @@ static bool __KernelLockMutex(Mutex *mutex, int count, u32 &error)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool __KernelUnlockMutex(Mutex *mutex, u32 &error)
|
static bool __KernelUnlockMutex(PSPMutex *mutex, u32 &error) {
|
||||||
{
|
|
||||||
__KernelMutexEraseLock(mutex);
|
__KernelMutexEraseLock(mutex);
|
||||||
|
|
||||||
bool wokeThreads = false;
|
bool wokeThreads = false;
|
||||||
|
@ -459,7 +451,7 @@ static bool __KernelUnlockMutex(Mutex *mutex, u32 &error)
|
||||||
void __KernelMutexTimeout(u64 userdata, int cyclesLate)
|
void __KernelMutexTimeout(u64 userdata, int cyclesLate)
|
||||||
{
|
{
|
||||||
SceUID threadID = (SceUID)userdata;
|
SceUID threadID = (SceUID)userdata;
|
||||||
HLEKernel::WaitExecTimeout<Mutex, WAITTYPE_MUTEX>(threadID);
|
HLEKernel::WaitExecTimeout<PSPMutex, WAITTYPE_MUTEX>(threadID);
|
||||||
}
|
}
|
||||||
|
|
||||||
void __KernelMutexThreadEnd(SceUID threadID)
|
void __KernelMutexThreadEnd(SceUID threadID)
|
||||||
|
@ -470,7 +462,7 @@ void __KernelMutexThreadEnd(SceUID threadID)
|
||||||
SceUID waitingMutexID = __KernelGetWaitID(threadID, WAITTYPE_MUTEX, error);
|
SceUID waitingMutexID = __KernelGetWaitID(threadID, WAITTYPE_MUTEX, error);
|
||||||
if (waitingMutexID)
|
if (waitingMutexID)
|
||||||
{
|
{
|
||||||
Mutex *mutex = kernelObjects.Get<Mutex>(waitingMutexID, error);
|
PSPMutex *mutex = kernelObjects.Get<PSPMutex>(waitingMutexID, error);
|
||||||
if (mutex)
|
if (mutex)
|
||||||
HLEKernel::RemoveWaitingThread(mutex->waitingThreads, threadID);
|
HLEKernel::RemoveWaitingThread(mutex->waitingThreads, threadID);
|
||||||
}
|
}
|
||||||
|
@ -481,7 +473,7 @@ void __KernelMutexThreadEnd(SceUID threadID)
|
||||||
{
|
{
|
||||||
// Need to increment early so erase() doesn't invalidate.
|
// Need to increment early so erase() doesn't invalidate.
|
||||||
SceUID mutexID = (*iter++).second;
|
SceUID mutexID = (*iter++).second;
|
||||||
Mutex *mutex = kernelObjects.Get<Mutex>(mutexID, error);
|
PSPMutex *mutex = kernelObjects.Get<PSPMutex>(mutexID, error);
|
||||||
|
|
||||||
if (mutex)
|
if (mutex)
|
||||||
{
|
{
|
||||||
|
@ -491,8 +483,7 @@ void __KernelMutexThreadEnd(SceUID threadID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void __KernelWaitMutex(Mutex *mutex, u32 timeoutPtr)
|
static void __KernelWaitMutex(PSPMutex *mutex, u32 timeoutPtr) {
|
||||||
{
|
|
||||||
if (timeoutPtr == 0 || mutexWaitTimer == -1)
|
if (timeoutPtr == 0 || mutexWaitTimer == -1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -511,7 +502,7 @@ static void __KernelWaitMutex(Mutex *mutex, u32 timeoutPtr)
|
||||||
int sceKernelCancelMutex(SceUID uid, int count, u32 numWaitThreadsPtr)
|
int sceKernelCancelMutex(SceUID uid, int count, u32 numWaitThreadsPtr)
|
||||||
{
|
{
|
||||||
u32 error;
|
u32 error;
|
||||||
Mutex *mutex = kernelObjects.Get<Mutex>(uid, error);
|
PSPMutex *mutex = kernelObjects.Get<PSPMutex>(uid, error);
|
||||||
if (mutex)
|
if (mutex)
|
||||||
{
|
{
|
||||||
bool lockable = count <= 0 || __KernelLockMutexCheck(mutex, count, error);
|
bool lockable = count <= 0 || __KernelLockMutexCheck(mutex, count, error);
|
||||||
|
@ -566,7 +557,7 @@ int sceKernelLockMutex(SceUID id, int count, u32 timeoutPtr)
|
||||||
{
|
{
|
||||||
DEBUG_LOG(SCEKERNEL, "sceKernelLockMutex(%i, %i, %08x)", id, count, timeoutPtr);
|
DEBUG_LOG(SCEKERNEL, "sceKernelLockMutex(%i, %i, %08x)", id, count, timeoutPtr);
|
||||||
u32 error;
|
u32 error;
|
||||||
Mutex *mutex = kernelObjects.Get<Mutex>(id, error);
|
PSPMutex *mutex = kernelObjects.Get<PSPMutex>(id, error);
|
||||||
|
|
||||||
if (__KernelLockMutex(mutex, count, error))
|
if (__KernelLockMutex(mutex, count, error))
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -591,7 +582,7 @@ int sceKernelLockMutexCB(SceUID id, int count, u32 timeoutPtr)
|
||||||
{
|
{
|
||||||
DEBUG_LOG(SCEKERNEL, "sceKernelLockMutexCB(%i, %i, %08x)", id, count, timeoutPtr);
|
DEBUG_LOG(SCEKERNEL, "sceKernelLockMutexCB(%i, %i, %08x)", id, count, timeoutPtr);
|
||||||
u32 error;
|
u32 error;
|
||||||
Mutex *mutex = kernelObjects.Get<Mutex>(id, error);
|
PSPMutex *mutex = kernelObjects.Get<PSPMutex>(id, error);
|
||||||
|
|
||||||
if (!__KernelLockMutexCheck(mutex, count, error))
|
if (!__KernelLockMutexCheck(mutex, count, error))
|
||||||
{
|
{
|
||||||
|
@ -630,7 +621,7 @@ int sceKernelTryLockMutex(SceUID id, int count)
|
||||||
{
|
{
|
||||||
DEBUG_LOG(SCEKERNEL, "sceKernelTryLockMutex(%i, %i)", id, count);
|
DEBUG_LOG(SCEKERNEL, "sceKernelTryLockMutex(%i, %i)", id, count);
|
||||||
u32 error;
|
u32 error;
|
||||||
Mutex *mutex = kernelObjects.Get<Mutex>(id, error);
|
PSPMutex *mutex = kernelObjects.Get<PSPMutex>(id, error);
|
||||||
|
|
||||||
if (__KernelLockMutex(mutex, count, error))
|
if (__KernelLockMutex(mutex, count, error))
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -645,7 +636,7 @@ int sceKernelUnlockMutex(SceUID id, int count)
|
||||||
{
|
{
|
||||||
DEBUG_LOG(SCEKERNEL, "sceKernelUnlockMutex(%i, %i)", id, count);
|
DEBUG_LOG(SCEKERNEL, "sceKernelUnlockMutex(%i, %i)", id, count);
|
||||||
u32 error;
|
u32 error;
|
||||||
Mutex *mutex = kernelObjects.Get<Mutex>(id, error);
|
PSPMutex *mutex = kernelObjects.Get<PSPMutex>(id, error);
|
||||||
|
|
||||||
if (error)
|
if (error)
|
||||||
return error;
|
return error;
|
||||||
|
@ -672,7 +663,7 @@ int sceKernelUnlockMutex(SceUID id, int count)
|
||||||
int sceKernelReferMutexStatus(SceUID id, u32 infoAddr)
|
int sceKernelReferMutexStatus(SceUID id, u32 infoAddr)
|
||||||
{
|
{
|
||||||
u32 error;
|
u32 error;
|
||||||
Mutex *m = kernelObjects.Get<Mutex>(id, error);
|
PSPMutex *m = kernelObjects.Get<PSPMutex>(id, error);
|
||||||
if (!m)
|
if (!m)
|
||||||
{
|
{
|
||||||
ERROR_LOG(SCEKERNEL, "sceKernelReferMutexStatus(%i, %08x): invalid mutex id", id, infoAddr);
|
ERROR_LOG(SCEKERNEL, "sceKernelReferMutexStatus(%i, %08x): invalid mutex id", id, infoAddr);
|
||||||
|
@ -1136,4 +1127,4 @@ int sceKernelReferLwMutexStatus(u32 workareaPtr, u32 infoPtr)
|
||||||
ERROR_LOG(SCEKERNEL, "%08x=sceKernelReferLwMutexStatus(%08x, %08x)", error, workareaPtr, infoPtr);
|
ERROR_LOG(SCEKERNEL, "%08x=sceKernelReferLwMutexStatus(%08x, %08x)", error, workareaPtr, infoPtr);
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,8 +53,7 @@ struct NativeSemaphore
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
struct Semaphore : public KernelObject
|
struct PSPSemaphore : public KernelObject {
|
||||||
{
|
|
||||||
const char *GetName() override { return ns.name; }
|
const char *GetName() override { return ns.name; }
|
||||||
const char *GetTypeName() override { return "Semaphore"; }
|
const char *GetTypeName() override { return "Semaphore"; }
|
||||||
|
|
||||||
|
@ -103,12 +102,11 @@ void __KernelSemaDoState(PointerWrap &p)
|
||||||
|
|
||||||
KernelObject *__KernelSemaphoreObject()
|
KernelObject *__KernelSemaphoreObject()
|
||||||
{
|
{
|
||||||
return new Semaphore;
|
return new PSPSemaphore;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns whether the thread should be removed.
|
// Returns whether the thread should be removed.
|
||||||
static bool __KernelUnlockSemaForThread(Semaphore *s, SceUID threadID, u32 &error, int result, bool &wokeThreads)
|
static bool __KernelUnlockSemaForThread(PSPSemaphore *s, SceUID threadID, u32 &error, int result, bool &wokeThreads) {
|
||||||
{
|
|
||||||
if (!HLEKernel::VerifyWait(threadID, WAITTYPE_SEMA, s->GetUID()))
|
if (!HLEKernel::VerifyWait(threadID, WAITTYPE_SEMA, s->GetUID()))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
@ -139,7 +137,7 @@ static bool __KernelUnlockSemaForThread(Semaphore *s, SceUID threadID, u32 &erro
|
||||||
|
|
||||||
void __KernelSemaBeginCallback(SceUID threadID, SceUID prevCallbackId)
|
void __KernelSemaBeginCallback(SceUID threadID, SceUID prevCallbackId)
|
||||||
{
|
{
|
||||||
auto result = HLEKernel::WaitBeginCallback<Semaphore, WAITTYPE_SEMA, SceUID>(threadID, prevCallbackId, semaWaitTimer);
|
auto result = HLEKernel::WaitBeginCallback<PSPSemaphore, WAITTYPE_SEMA, SceUID>(threadID, prevCallbackId, semaWaitTimer);
|
||||||
if (result == HLEKernel::WAIT_CB_SUCCESS)
|
if (result == HLEKernel::WAIT_CB_SUCCESS)
|
||||||
DEBUG_LOG(SCEKERNEL, "sceKernelWaitSemaCB: Suspending sema wait for callback");
|
DEBUG_LOG(SCEKERNEL, "sceKernelWaitSemaCB: Suspending sema wait for callback");
|
||||||
else
|
else
|
||||||
|
@ -148,15 +146,14 @@ void __KernelSemaBeginCallback(SceUID threadID, SceUID prevCallbackId)
|
||||||
|
|
||||||
void __KernelSemaEndCallback(SceUID threadID, SceUID prevCallbackId)
|
void __KernelSemaEndCallback(SceUID threadID, SceUID prevCallbackId)
|
||||||
{
|
{
|
||||||
auto result = HLEKernel::WaitEndCallback<Semaphore, WAITTYPE_SEMA, SceUID>(threadID, prevCallbackId, semaWaitTimer, __KernelUnlockSemaForThread);
|
auto result = HLEKernel::WaitEndCallback<PSPSemaphore, WAITTYPE_SEMA, SceUID>(threadID, prevCallbackId, semaWaitTimer, __KernelUnlockSemaForThread);
|
||||||
if (result == HLEKernel::WAIT_CB_RESUMED_WAIT)
|
if (result == HLEKernel::WAIT_CB_RESUMED_WAIT)
|
||||||
DEBUG_LOG(SCEKERNEL, "sceKernelWaitSemaCB: Resuming sema wait for callback");
|
DEBUG_LOG(SCEKERNEL, "sceKernelWaitSemaCB: Resuming sema wait for callback");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Resume all waiting threads (for delete / cancel.)
|
// Resume all waiting threads (for delete / cancel.)
|
||||||
// Returns true if it woke any threads.
|
// Returns true if it woke any threads.
|
||||||
static bool __KernelClearSemaThreads(Semaphore *s, int reason)
|
static bool __KernelClearSemaThreads(PSPSemaphore *s, int reason) {
|
||||||
{
|
|
||||||
u32 error;
|
u32 error;
|
||||||
bool wokeThreads = false;
|
bool wokeThreads = false;
|
||||||
std::vector<SceUID>::iterator iter, end;
|
std::vector<SceUID>::iterator iter, end;
|
||||||
|
@ -170,7 +167,7 @@ static bool __KernelClearSemaThreads(Semaphore *s, int reason)
|
||||||
int sceKernelCancelSema(SceUID id, int newCount, u32 numWaitThreadsPtr)
|
int sceKernelCancelSema(SceUID id, int newCount, u32 numWaitThreadsPtr)
|
||||||
{
|
{
|
||||||
u32 error;
|
u32 error;
|
||||||
Semaphore *s = kernelObjects.Get<Semaphore>(id, error);
|
PSPSemaphore *s = kernelObjects.Get<PSPSemaphore>(id, error);
|
||||||
if (s)
|
if (s)
|
||||||
{
|
{
|
||||||
if (newCount > s->ns.maxCount)
|
if (newCount > s->ns.maxCount)
|
||||||
|
@ -215,7 +212,7 @@ int sceKernelCreateSema(const char* name, u32 attr, int initVal, int maxVal, u32
|
||||||
return SCE_KERNEL_ERROR_ILLEGAL_ATTR;
|
return SCE_KERNEL_ERROR_ILLEGAL_ATTR;
|
||||||
}
|
}
|
||||||
|
|
||||||
Semaphore *s = new Semaphore;
|
PSPSemaphore *s = new PSPSemaphore();
|
||||||
SceUID id = kernelObjects.Create(s);
|
SceUID id = kernelObjects.Create(s);
|
||||||
|
|
||||||
s->ns.size = sizeof(NativeSemaphore);
|
s->ns.size = sizeof(NativeSemaphore);
|
||||||
|
@ -244,7 +241,7 @@ int sceKernelCreateSema(const char* name, u32 attr, int initVal, int maxVal, u32
|
||||||
int sceKernelDeleteSema(SceUID id)
|
int sceKernelDeleteSema(SceUID id)
|
||||||
{
|
{
|
||||||
u32 error;
|
u32 error;
|
||||||
Semaphore *s = kernelObjects.Get<Semaphore>(id, error);
|
PSPSemaphore *s = kernelObjects.Get<PSPSemaphore>(id, error);
|
||||||
if (s)
|
if (s)
|
||||||
{
|
{
|
||||||
DEBUG_LOG(SCEKERNEL, "sceKernelDeleteSema(%i)", id);
|
DEBUG_LOG(SCEKERNEL, "sceKernelDeleteSema(%i)", id);
|
||||||
|
@ -253,7 +250,7 @@ int sceKernelDeleteSema(SceUID id)
|
||||||
if (wokeThreads)
|
if (wokeThreads)
|
||||||
hleReSchedule("semaphore deleted");
|
hleReSchedule("semaphore deleted");
|
||||||
|
|
||||||
return kernelObjects.Destroy<Semaphore>(id);
|
return kernelObjects.Destroy<PSPSemaphore>(id);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -265,7 +262,7 @@ int sceKernelDeleteSema(SceUID id)
|
||||||
int sceKernelReferSemaStatus(SceUID id, u32 infoPtr)
|
int sceKernelReferSemaStatus(SceUID id, u32 infoPtr)
|
||||||
{
|
{
|
||||||
u32 error;
|
u32 error;
|
||||||
Semaphore *s = kernelObjects.Get<Semaphore>(id, error);
|
PSPSemaphore *s = kernelObjects.Get<PSPSemaphore>(id, error);
|
||||||
if (s)
|
if (s)
|
||||||
{
|
{
|
||||||
DEBUG_LOG(SCEKERNEL, "sceKernelReferSemaStatus(%i, %08x)", id, infoPtr);
|
DEBUG_LOG(SCEKERNEL, "sceKernelReferSemaStatus(%i, %08x)", id, infoPtr);
|
||||||
|
@ -290,7 +287,7 @@ int sceKernelReferSemaStatus(SceUID id, u32 infoPtr)
|
||||||
int sceKernelSignalSema(SceUID id, int signal)
|
int sceKernelSignalSema(SceUID id, int signal)
|
||||||
{
|
{
|
||||||
u32 error;
|
u32 error;
|
||||||
Semaphore *s = kernelObjects.Get<Semaphore>(id, error);
|
PSPSemaphore *s = kernelObjects.Get<PSPSemaphore>(id, error);
|
||||||
if (s)
|
if (s)
|
||||||
{
|
{
|
||||||
if (s->ns.currentCount + signal - (int) s->waitingThreads.size() > s->ns.maxCount)
|
if (s->ns.currentCount + signal - (int) s->waitingThreads.size() > s->ns.maxCount)
|
||||||
|
@ -336,10 +333,10 @@ void __KernelSemaTimeout(u64 userdata, int cycleslate)
|
||||||
u32 error;
|
u32 error;
|
||||||
SceUID uid = __KernelGetWaitID(threadID, WAITTYPE_SEMA, error);
|
SceUID uid = __KernelGetWaitID(threadID, WAITTYPE_SEMA, error);
|
||||||
|
|
||||||
HLEKernel::WaitExecTimeout<Semaphore, WAITTYPE_SEMA>(threadID);
|
HLEKernel::WaitExecTimeout<PSPSemaphore, WAITTYPE_SEMA>(threadID);
|
||||||
|
|
||||||
// If in FIFO mode, that may have cleared another thread to wake up.
|
// If in FIFO mode, that may have cleared another thread to wake up.
|
||||||
Semaphore *s = kernelObjects.Get<Semaphore>(uid, error);
|
PSPSemaphore *s = kernelObjects.Get<PSPSemaphore>(uid, error);
|
||||||
if (s && (s->ns.attr & PSP_SEMA_ATTR_PRIORITY) == PSP_SEMA_ATTR_FIFO) {
|
if (s && (s->ns.attr & PSP_SEMA_ATTR_PRIORITY) == PSP_SEMA_ATTR_FIFO) {
|
||||||
bool wokeThreads;
|
bool wokeThreads;
|
||||||
std::vector<SceUID>::iterator iter = s->waitingThreads.begin();
|
std::vector<SceUID>::iterator iter = s->waitingThreads.begin();
|
||||||
|
@ -351,8 +348,7 @@ void __KernelSemaTimeout(u64 userdata, int cycleslate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void __KernelSetSemaTimeout(Semaphore *s, u32 timeoutPtr)
|
static void __KernelSetSemaTimeout(PSPSemaphore *s, u32 timeoutPtr) {
|
||||||
{
|
|
||||||
if (timeoutPtr == 0 || semaWaitTimer == -1)
|
if (timeoutPtr == 0 || semaWaitTimer == -1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -378,7 +374,7 @@ static int __KernelWaitSema(SceUID id, int wantedCount, u32 timeoutPtr, bool pro
|
||||||
hleEatCycles(500);
|
hleEatCycles(500);
|
||||||
|
|
||||||
u32 error;
|
u32 error;
|
||||||
Semaphore *s = kernelObjects.Get<Semaphore>(id, error);
|
PSPSemaphore *s = kernelObjects.Get<PSPSemaphore>(id, error);
|
||||||
if (s)
|
if (s)
|
||||||
{
|
{
|
||||||
if (wantedCount > s->ns.maxCount)
|
if (wantedCount > s->ns.maxCount)
|
||||||
|
@ -438,7 +434,7 @@ int sceKernelPollSema(SceUID id, int wantedCount)
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 error;
|
u32 error;
|
||||||
Semaphore *s = kernelObjects.Get<Semaphore>(id, error);
|
PSPSemaphore *s = kernelObjects.Get<PSPSemaphore>(id, error);
|
||||||
if (s)
|
if (s)
|
||||||
{
|
{
|
||||||
if (s->ns.currentCount >= wantedCount && s->waitingThreads.size() == 0)
|
if (s->ns.currentCount >= wantedCount && s->waitingThreads.size() == 0)
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -26,7 +26,7 @@
|
||||||
// There's a good description of the thread scheduling rules in:
|
// There's a good description of the thread scheduling rules in:
|
||||||
// http://code.google.com/p/jpcsp/source/browse/trunk/src/jpcsp/HLE/modules150/ThreadManForUser.java
|
// http://code.google.com/p/jpcsp/source/browse/trunk/src/jpcsp/HLE/modules150/ThreadManForUser.java
|
||||||
|
|
||||||
class Thread;
|
class PSPThread;
|
||||||
class DebugInterface;
|
class DebugInterface;
|
||||||
|
|
||||||
int sceKernelChangeThreadPriority(SceUID threadID, int priority);
|
int sceKernelChangeThreadPriority(SceUID threadID, int priority);
|
||||||
|
@ -119,8 +119,7 @@ typedef void (* WaitEndCallbackFunc)(SceUID threadID, SceUID prevCallbackId);
|
||||||
|
|
||||||
void __KernelRegisterWaitTypeFuncs(WaitType type, WaitBeginCallbackFunc beginFunc, WaitEndCallbackFunc endFunc);
|
void __KernelRegisterWaitTypeFuncs(WaitType type, WaitBeginCallbackFunc beginFunc, WaitEndCallbackFunc endFunc);
|
||||||
|
|
||||||
struct ThreadContext
|
struct PSPThreadContext {
|
||||||
{
|
|
||||||
void reset();
|
void reset();
|
||||||
|
|
||||||
// r must be followed by f.
|
// r must be followed by f.
|
||||||
|
@ -168,8 +167,8 @@ u32 __KernelGetCurThreadStackStart();
|
||||||
const char *__KernelGetThreadName(SceUID threadID);
|
const char *__KernelGetThreadName(SceUID threadID);
|
||||||
bool KernelIsThreadDormant(SceUID threadID);
|
bool KernelIsThreadDormant(SceUID threadID);
|
||||||
|
|
||||||
void __KernelSaveContext(ThreadContext *ctx, bool vfpuEnabled);
|
void __KernelSaveContext(PSPThreadContext *ctx, bool vfpuEnabled);
|
||||||
void __KernelLoadContext(ThreadContext *ctx, bool vfpuEnabled);
|
void __KernelLoadContext(PSPThreadContext *ctx, bool vfpuEnabled);
|
||||||
|
|
||||||
u32 __KernelResumeThreadFromWait(SceUID threadID, u32 retval); // can return an error value
|
u32 __KernelResumeThreadFromWait(SceUID threadID, u32 retval); // can return an error value
|
||||||
u32 __KernelResumeThreadFromWait(SceUID threadID, u64 retval);
|
u32 __KernelResumeThreadFromWait(SceUID threadID, u64 retval);
|
||||||
|
@ -216,10 +215,10 @@ int sceKernelGetCallbackCount(SceUID cbId);
|
||||||
void sceKernelCheckCallback();
|
void sceKernelCheckCallback();
|
||||||
int sceKernelReferCallbackStatus(SceUID cbId, u32 statusAddr);
|
int sceKernelReferCallbackStatus(SceUID cbId, u32 statusAddr);
|
||||||
|
|
||||||
class Action;
|
class PSPAction;
|
||||||
|
|
||||||
// Not an official Callback object, just calls a mips function on the current thread.
|
// Not an official Callback object, just calls a mips function on the current thread.
|
||||||
void __KernelDirectMipsCall(u32 entryPoint, Action *afterAction, u32 args[], int numargs, bool reschedAfter);
|
void __KernelDirectMipsCall(u32 entryPoint, PSPAction *afterAction, u32 args[], int numargs, bool reschedAfter);
|
||||||
|
|
||||||
void __KernelReturnFromMipsCall(); // Called as HLE function
|
void __KernelReturnFromMipsCall(); // Called as HLE function
|
||||||
bool __KernelInCallback();
|
bool __KernelInCallback();
|
||||||
|
@ -228,8 +227,8 @@ bool __KernelInCallback();
|
||||||
bool __KernelCheckCallbacks();
|
bool __KernelCheckCallbacks();
|
||||||
bool __KernelForceCallbacks();
|
bool __KernelForceCallbacks();
|
||||||
bool __KernelCurHasReadyCallbacks();
|
bool __KernelCurHasReadyCallbacks();
|
||||||
void __KernelSwitchContext(Thread *target, const char *reason);
|
void __KernelSwitchContext(PSPThread *target, const char *reason);
|
||||||
bool __KernelExecutePendingMipsCalls(Thread *currentThread, bool reschedAfter);
|
bool __KernelExecutePendingMipsCalls(PSPThread *currentThread, bool reschedAfter);
|
||||||
void __KernelNotifyCallback(SceUID cbId, int notifyArg);
|
void __KernelNotifyCallback(SceUID cbId, int notifyArg);
|
||||||
|
|
||||||
// Switch to an idle / non-user thread, if not already on one.
|
// Switch to an idle / non-user thread, if not already on one.
|
||||||
|
@ -243,8 +242,8 @@ u32 __KernelSetThreadRA(SceUID threadID, u32 nid);
|
||||||
|
|
||||||
// A call into game code. These can be pending on a thread.
|
// A call into game code. These can be pending on a thread.
|
||||||
// Similar to Callback-s (NOT CallbackInfos) in JPCSP.
|
// Similar to Callback-s (NOT CallbackInfos) in JPCSP.
|
||||||
typedef Action *(*ActionCreator)();
|
typedef PSPAction *(*ActionCreator)();
|
||||||
Action *__KernelCreateAction(int actionType);
|
PSPAction *__KernelCreateAction(int actionType);
|
||||||
int __KernelRegisterActionType(ActionCreator creator);
|
int __KernelRegisterActionType(ActionCreator creator);
|
||||||
void __KernelRestoreActionType(int actionType, ActionCreator creator);
|
void __KernelRestoreActionType(int actionType, ActionCreator creator);
|
||||||
|
|
||||||
|
@ -258,7 +257,7 @@ struct MipsCall {
|
||||||
u32 cbId;
|
u32 cbId;
|
||||||
u32 args[6];
|
u32 args[6];
|
||||||
int numArgs;
|
int numArgs;
|
||||||
Action *doAfter;
|
PSPAction *doAfter;
|
||||||
u32 savedPc;
|
u32 savedPc;
|
||||||
u32 savedV0;
|
u32 savedV0;
|
||||||
u32 savedV1;
|
u32 savedV1;
|
||||||
|
@ -279,10 +278,10 @@ struct MipsCall {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class Action
|
class PSPAction
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual ~Action() {}
|
virtual ~PSPAction() {}
|
||||||
virtual void run(MipsCall &call) = 0;
|
virtual void run(MipsCall &call) = 0;
|
||||||
virtual void DoState(PointerWrap &p) = 0;
|
virtual void DoState(PointerWrap &p) = 0;
|
||||||
int actionTypeID;
|
int actionTypeID;
|
||||||
|
@ -300,7 +299,7 @@ enum ThreadStatus
|
||||||
THREADSTATUS_WAITSUSPEND = THREADSTATUS_WAIT | THREADSTATUS_SUSPEND
|
THREADSTATUS_WAITSUSPEND = THREADSTATUS_WAIT | THREADSTATUS_SUSPEND
|
||||||
};
|
};
|
||||||
|
|
||||||
void __KernelChangeThreadState(Thread *thread, ThreadStatus newStatus);
|
void __KernelChangeThreadState(PSPThread *thread, ThreadStatus newStatus);
|
||||||
|
|
||||||
typedef void (*ThreadCallback)(SceUID threadID);
|
typedef void (*ThreadCallback)(SceUID threadID);
|
||||||
void __KernelListenThreadEnd(ThreadCallback callback);
|
void __KernelListenThreadEnd(ThreadCallback callback);
|
||||||
|
|
|
@ -355,11 +355,11 @@ static void AnalyzeMpeg(u8 *buffer, u32 validSize, MpegContext *ctx) {
|
||||||
INFO_LOG(ME, "First timestamp: %lld, Last timestamp: %lld", ctx->mpegFirstTimestamp, ctx->mpegLastTimestamp);
|
INFO_LOG(ME, "First timestamp: %lld, Last timestamp: %lld", ctx->mpegFirstTimestamp, ctx->mpegLastTimestamp);
|
||||||
}
|
}
|
||||||
|
|
||||||
class PostPutAction : public Action {
|
class PostPutAction : public PSPAction {
|
||||||
public:
|
public:
|
||||||
PostPutAction() {}
|
PostPutAction() {}
|
||||||
void setRingAddr(u32 ringAddr) { ringAddr_ = ringAddr; }
|
void setRingAddr(u32 ringAddr) { ringAddr_ = ringAddr; }
|
||||||
static Action *Create() { return new PostPutAction; }
|
static PSPAction *Create() { return new PostPutAction; }
|
||||||
void DoState(PointerWrap &p) override {
|
void DoState(PointerWrap &p) override {
|
||||||
auto s = p.Section("PostPutAction", 1);
|
auto s = p.Section("PostPutAction", 1);
|
||||||
if (!s)
|
if (!s)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue