-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Changes from 5 commits
5353871
76d7056
5fc7931
37ad366
820993e
4c65133
d6d4569
021b386
0136346
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2301,3 +2301,96 @@ void Register_SysMemUserForUser() | |
{ | ||
RegisterModule("SysMemUserForUser", ARRAY_SIZE(SysMemUserForUser), SysMemUserForUser); | ||
} | ||
|
||
|
||
struct HeapInformation : public KernelObject { | ||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I take a search but no SCE_KERNEL_TMID_HEAP There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. partitionId, name,flags,name not used There was a problem hiding this comment. Choose a reason for hiding this commentThe 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] There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So this pull request is not ready for v1.1 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also yes,I copy most of code from sceHeap.cpp There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See also -[Unknown] |
||
}; | ||
|
||
std::map<u32, HeapInformation *> heapList; | ||
|
||
static HeapInformation *getHeap(u32 heapId) { | ||
auto found = heapList.find(heapId); | ||
if (found == heapList.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; | ||
heapList[uid] = heap; | ||
|
||
|
||
return hleLogError(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 hleLogError(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); | ||
heapList.erase(heapId); | ||
delete heap; | ||
return hleLogError(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); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should:
sceKernelHeap.cpp
.SysMemForKernel
here and export the functions insceKernelHeap.h
(kinda like sceKernelMutex.h, etc.)-[Unknown]