Merge pull request #16413 from unknownbrackets/heap-partition

Kernel: Respect partition param in heap funcs
This commit is contained in:
Henrik Rydgård 2022-11-22 10:18:47 +01:00 committed by GitHub
commit 5c2663e37c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 20 deletions

View File

@ -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();
@ -74,7 +79,7 @@ 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");
}
}
@ -82,26 +87,31 @@ 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()

View File

@ -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);
}