Skip to content

Commit

Permalink
Correct some vpl allocation logic.
Browse files Browse the repository at this point in the history
Tricky.  This makes more tests pass, seems right.
  • Loading branch information
unknownbrackets committed Feb 2, 2014
1 parent 4cec228 commit ecdffab
Showing 1 changed file with 9 additions and 18 deletions.
27 changes: 9 additions & 18 deletions Core/HLE/sceKernelMemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,23 +204,24 @@ struct SceKernelVplHeader {

u32 Allocate(u32 size) {
u32 allocBlocks = ((size + 7) / 8) + 1;
auto prev = PSPPointer<SceKernelVplBlock>::Create(0);
auto b = nextFreeBlock_;
auto prev = nextFreeBlock_;
do {
auto b = prev->next;
if (b->sizeInBlocks > allocBlocks) {
if (nextFreeBlock_ == b) {
nextFreeBlock_ = prev;
}
prev = b;
b = SplitBlock(b, allocBlocks);
}

if (b->sizeInBlocks == allocBlocks) {
UnlinkFreeBlock(b, prev);
_dbg_assert_msg_(SCEKERNEL, b->sizeInBlocks == allocBlocks, "Returned block of improper size.");
return b.ptr + 8;
}

prev = b;
b = b->next;
} while (b.IsValid() && b != nextFreeBlock_);
} while (prev.IsValid() && prev != nextFreeBlock_);

return (u32)-1;
}
Expand Down Expand Up @@ -281,21 +282,11 @@ struct SceKernelVplHeader {
}

void UnlinkFreeBlock(PSPPointer<SceKernelVplBlock> b, PSPPointer<SceKernelVplBlock> prev) {
// If this was the first we tried, we have to search for prev.
if (!prev.IsValid()) {
prev = LastBlock();
while (prev->next != b) {
prev = prev->next;
if (prev == LastBlock()) {
_dbg_assert_msg_(SCEKERNEL, prev != LastBlock(), "Should have found a previous free block.");
break;
}
}
}

allocatedInBlocks_ += b->sizeInBlocks;
prev->next = b->next;
nextFreeBlock_ = b->next;
if (nextFreeBlock_ == b) {
nextFreeBlock_ = prev;
}
b->next = SentinelPtr();
}

Expand Down

0 comments on commit ecdffab

Please sign in to comment.