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

Kernel: Respect partition param in heap funcs #16413

Merged
merged 2 commits into from
Nov 22, 2022
Merged
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
40 changes: 25 additions & 15 deletions Core/HLE/sceKernelHeap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,16 @@ struct KernelHeap : public KernelObject {
static int sceKernelCreateHeap(int partitionId, int size, int flags, const char *Name) {
u32 allocSize = (size + 3) & ~3;

// TODO: partitionId should probably decide if we allocate from userMemory or kernel or whatever...
u32 addr = userMemory.Alloc(allocSize, g_fromBottom, "SysMemForKernel-Heap");
BlockAllocator *allocator = BlockAllocatorFromAddr(partitionId);
// TODO: Validate error code.
if (!allocator)
return hleLogError(SCEKERNEL, SCE_KERNEL_ERROR_ILLEGAL_ARGUMENT, "invalid partition");

// TODO: This should probably actually use flags? Name?
u32 addr = allocator->Alloc(allocSize, g_fromBottom, "SysMemForKernel-Heap");
if (addr == (u32)-1) {
ERROR_LOG(HLE, "sceKernelCreateHeap(partitionId=%d): Failed to allocate %d bytes memory", partitionId, size);
return SCE_KERNEL_ERROR_NO_MEMORY; // Blind guess
// TODO: Validate error code.
return hleLogError(SCEKERNEL, SCE_KERNEL_ERROR_NO_MEMORY, "fFailed to allocate %d bytes of memory", size);
}

KernelHeap *heap = new KernelHeap();
Expand All @@ -74,34 +79,39 @@ static int sceKernelAllocHeapMemory(int heapId, int size) {
u32 addr = heap->alloc.Alloc(memSize, true);
return hleLogSuccessInfoX(SCEKERNEL, addr);
} else {
return hleLogError(SCEKERNEL, error, "sceKernelAllocHeapMemory(%d): invalid heapId", heapId);
return hleLogError(SCEKERNEL, error, "invalid heapId");
}
}

static int sceKernelDeleteHeap(int heapId) {
u32 error;
KernelHeap *heap = kernelObjects.Get<KernelHeap>(heapId, error);
if (heap) {
userMemory.Free(heap->address);
// Not using heap->partitionId here for backwards compatibility with old save states.
BlockAllocator *allocator = BlockAllocatorFromAddr(heap->address);
if (allocator)
allocator->Free(heap->address);
kernelObjects.Destroy<KernelHeap>(heap->uid);
return hleLogSuccessInfoX(SCEKERNEL, 0);
} else {
return hleLogError(SCEKERNEL, error, "sceKernelDeleteHeap(%d): invalid heapId", heapId);
return hleLogError(SCEKERNEL, error, "invalid heapId");
}
}

static u32 sceKernelPartitionTotalFreeMemSize(int partitionId) {
ERROR_LOG(SCEKERNEL, "UNIMP sceKernelPartitionTotalFreeMemSize(%d)", partitionId);
//Need more work #13021
///We ignore partitionId for now
return userMemory.GetTotalFreeBytes();
BlockAllocator *allocator = BlockAllocatorFromID(partitionId);
// TODO: Validate error code.
if (!allocator)
return hleLogError(SCEKERNEL, SCE_KERNEL_ERROR_ILLEGAL_ARGUMENT, "invalid partition");
return hleLogWarning(SCEKERNEL, allocator->GetTotalFreeBytes());
}

static u32 sceKernelPartitionMaxFreeMemSize(int partitionId) {
ERROR_LOG(SCEKERNEL, "UNIMP sceKernelPartitionMaxFreeMemSize(%d)", partitionId);
//Need more work #13021
///We ignore partitionId for now
return userMemory.GetLargestFreeBlockSize();
BlockAllocator *allocator = BlockAllocatorFromID(partitionId);
// TODO: Validate error code.
if (!allocator)
return hleLogError(SCEKERNEL, SCE_KERNEL_ERROR_ILLEGAL_ARGUMENT, "invalid partition");
return hleLogWarning(SCEKERNEL, allocator->GetLargestFreeBlockSize());
}

static u32 SysMemForKernel_536AD5E1()
Expand Down
5 changes: 0 additions & 5 deletions GPU/D3D11/GPU_D3D11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,6 @@ u32 GPU_D3D11::CheckGPUFeatures() const {
features |= GPU_USE_16BIT_FORMATS;
}

// The Phantasy Star hack :(
if (PSP_CoreParameter().compat.flags().DepthRangeHack && (features & GPU_USE_ACCURATE_DEPTH) == 0) {
features |= GPU_USE_DEPTH_RANGE_HACK;
}

return CheckGPUFeaturesLate(features);
}

Expand Down