Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrap some SysMemForKernel's nids, fixing #7960 #7965

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Core/HLE/FunctionWrappers.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ template<int func(const char *, int, int, int, int, int, int)> void WrapI_CIIIII
RETURN(retval);
}

template<int func(int, int, int, const char *)> void WrapI_IIIC() {
u32 retval = func(PARAM(0), PARAM(1), PARAM(2), Memory::GetCharPointer(PARAM(3)));
RETURN(retval);
}

// Hm, do so many params get passed in registers?
template<int func(int, int, int, int, int, int, u32)> void WrapI_IIIIIIU() {
u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4), PARAM(5), PARAM(6));
Expand Down
22 changes: 5 additions & 17 deletions Core/HLE/sceKernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -940,18 +940,6 @@ const HLEFunction LoadExecForKernel[] =
{0X4AC57943, &WrapI_I<LoadExecForKernel_4AC57943>, "LoadExecForKernel_4AC57943", 'i', "i" },
{0XA3D5E142, nullptr, "LoadExecForKernel_a3d5e142", '?', "" },
};

void Register_LoadExecForKernel()
{
RegisterModule("LoadExecForKernel", ARRAY_SIZE(LoadExecForKernel), LoadExecForKernel);
}

const HLEFunction SysMemForKernel[] =
{
{0X636C953B, nullptr, "SysMemForKernel_636c953b", '?', "" },
{0XC9805775, nullptr, "SysMemForKernel_c9805775", '?', "" },
{0X1C1FBFE7, nullptr, "SysMemForKernel_1c1fbfe7", '?', "" },
};

const HLEFunction ExceptionManagerForKernel[] =
{
Expand All @@ -965,11 +953,6 @@ const HLEFunction ExceptionManagerForKernel[] =
{0XB15357C9, nullptr, "sceKernelReleaseNmiHandler", '?', "" },
};

void Register_SysMemForKernel()
{
RegisterModule("SysMemForKernel", ARRAY_SIZE(SysMemForKernel), SysMemForKernel);
}

void Register_ExceptionManagerForKernel()
{
RegisterModule("ExceptionManagerForKernel", ARRAY_SIZE(ExceptionManagerForKernel), ExceptionManagerForKernel);
Expand Down Expand Up @@ -1008,3 +991,8 @@ void Register_ThreadManForKernel()
{
RegisterModule("ThreadManForKernel", ARRAY_SIZE(ThreadManForKernel), ThreadManForKernel);
}

void Register_LoadExecForKernel()
{
RegisterModule("LoadExecForKernel", ARRAY_SIZE(LoadExecForKernel), LoadExecForKernel);
}
1 change: 0 additions & 1 deletion Core/HLE/sceKernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -578,5 +578,4 @@ void Register_ThreadManForUser();
void Register_ThreadManForKernel();
void Register_LoadExecForUser();
void Register_LoadExecForKernel();
void Register_SysMemForKernel();
void Register_UtilsForKernel();
112 changes: 112 additions & 0 deletions Core/HLE/sceKernelMemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2301,3 +2301,115 @@ void Register_SysMemUserForUser()
{
RegisterModule("SysMemUserForUser", ARRAY_SIZE(SysMemUserForUser), SysMemUserForUser);
}


struct HeapInformation : public KernelObject {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should:

  1. Put these functions and structs in sceKernelHeap.cpp.
  2. Keep SysMemForKernel here and export the functions in sceKernelHeap.h (kinda like sceKernelMutex.h, etc.)

-[Unknown]

HeapInformation() {}
int uid;
int partitionId;
u32 size;
int flags;
u32 address;
std::string name;
BlockAllocator alloc;
static int GetStaticIDType() { return SCE_KERNEL_TMID_Fpl; }// wrong
int GetIDType() const override { return SCE_KERNEL_TMID_Fpl; }// wrong
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I take a search but no SCE_KERNEL_TMID_HEAP

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

partitionId, name,flags,name not used
Not sure really need save status these variable

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't use the "XyzInformation" convention in PPSSPP, even if JPCSP does. I really think we should have testing to understand how this differs from sceHeap. Also, testing can identify which TMID is uses - there's a syscall that gives you the type id for a uid, iirc.

I can't remember for sure, but I thought we used the TMID for savestates, though. I don't think it's good if they're wrong.

-[Unknown]

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this pull request is not ready for v1.1

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also yes,I copy most of code from sceHeap.cpp

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, it won't make it. we can start adding some kernel stuff after 1.1 but for now I want to keep things the way they are to be safe.

1.1 will be soon though, I'm planning to release next weekend.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See also PPSSPP_KERNEL_TMID_Module and similar for using fake TMID values. For savestates to work correctly, we need unique values right now.

-[Unknown]


void DoState(PointerWrap &p) {
p.Do(uid);
p.Do(partitionId);
p.Do(size);
p.Do(flags);
p.Do(address);
p.Do(name);
p.Do(alloc);
}
};

std::map<u32, HeapInformation *> heapInformationList;

void __HeapInformationDoState(PointerWrap &p) {
auto s = p.Section("kernelHeap", 1);
if (!s)
return;

if (s >= 1) {
p.Do(heapInformationList);
}
}

static HeapInformation *getHeap(u32 heapId) {
auto found = heapInformationList.find(heapId);
if (found == heapInformationList.end()) {
return NULL;
}
return found->second;
}

const u32 HEAP_BLOCK_HEADER_SIZE = 8;
const bool frombottom = false;

static int sceKernelCreateHeap(int partitionId, int size, int flags, const char *Name)
{
HeapInformation *heap = new HeapInformation;
heap->partitionId = partitionId;
heap->flags = flags;
heap->name = *Name;
int allocSize = (size + 3) & ~3;
heap->size = allocSize;
u32 addr = userMemory.Alloc(heap->size, frombottom, "SysMemForKernel-Heap");
if (addr == (u32)-1) {
ERROR_LOG(HLE, "sceKernelCreateHeap(): Failed to allocate %i bytes memory", size);
heap->uid = -1;
delete heap;
}
heap->address = addr;
heap->alloc.Init(heap->address + 128, heap->size - 128);
SceUID uid = kernelObjects.Create(heap);
heap->uid = uid;
heapInformationList[uid] = heap;


return hleLogSuccessInfoX(SCEKERNEL, uid, "");
}


static int sceKernelAllocHeapMemory(int heapId, int size)
{
HeapInformation *heap = getHeap(heapId);
if (!heap) {
ERROR_LOG(HLE, "sceKernelAllocHeapMemory cannot find heapId", heapId);
return 0;
}

// There's 8 bytes at the end of every block, reserved.
u32 memSize = HEAP_BLOCK_HEADER_SIZE + size;
u32 addr = heap->alloc.Alloc(memSize, true);
return hleLogSuccessInfoX(SCEKERNEL, addr, "");
}

static int sceKernelDeleteHeap(int heapId)
{
HeapInformation *heap = getHeap(heapId);
if (!heap) {
ERROR_LOG(HLE, "sceKernelDeleteHeap(%i): invalid heapId", heapId);
return -1;
}
userMemory.Free(heap->address);
kernelObjects.Destroy<FPL>(heap->uid);
heapInformationList.erase(heapId);
return hleLogSuccessInfoX(SCEKERNEL, 0, "");
}

const HLEFunction SysMemForKernel[] =
{
{ 0X636C953B, &WrapI_II<sceKernelAllocHeapMemory>, "sceKernelAllocHeapMemory", 'I', "ii" },
{ 0XC9805775, &WrapI_I<sceKernelDeleteHeap>, "sceKernelDeleteHeap", 'I', "i" },
{ 0X1C1FBFE7, &WrapI_IIIC<sceKernelCreateHeap>, "sceKernelCreateHeap", 'I', "iiis" },
};

void Register_SysMemForKernel()
{
RegisterModule("SysMemForKernel", ARRAY_SIZE(SysMemForKernel), SysMemForKernel);
}

2 changes: 2 additions & 0 deletions Core/HLE/sceKernelMemory.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,5 @@ int sceKernelFreeTlspl(SceUID uid);
int sceKernelReferTlsplStatus(SceUID uid, u32 infoPtr);

void Register_SysMemUserForUser();
void Register_SysMemForKernel();