fix(libc): swap calloc and realloc slots of the malloc replacement table
SceLibcMallocReplace lists calloc before realloc (malloc, free, calloc, realloc, memalign, reallocalign, posix_memalign, ...), as the table in retail titles shows. realloc therefore called the application's calloc with the old pointer as the element count, and calloc called realloc. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
a4273c10dc
commit
998605fe4e
|
|
@ -142,7 +142,7 @@ void* ApplicationHeapReallocate_nid_no_patch(void* pointer, std::size_t bytes) {
|
|||
ApplicationHeapFree_nid_no_patch(pointer);
|
||||
return nullptr;
|
||||
}
|
||||
const auto reallocate = callback<Reallocate>(2);
|
||||
const auto reallocate = callback<Reallocate>(3);
|
||||
CallbackScope scope;
|
||||
return requireAllocation(reallocate(pointer, bytes));
|
||||
}
|
||||
|
|
@ -158,7 +158,7 @@ void* ApplicationHeapAlign_nid_no_patch(std::size_t alignment, std::size_t bytes
|
|||
|
||||
void* ApplicationHeapCalloc_nid_no_patch(std::size_t count, std::size_t bytes) {
|
||||
if (bytes != 0 && count > std::numeric_limits<std::size_t>::max() / bytes) throw std::length_error("application heap: calloc size overflow");
|
||||
const auto calloc = callback<Calloc>(3);
|
||||
const auto calloc = callback<Calloc>(2);
|
||||
CallbackScope scope;
|
||||
return requireAllocation(calloc(count, bytes));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -87,8 +87,8 @@ int main(int argc, char**) {
|
|||
write(replacement, 0x18, &finalize);
|
||||
write(replacement, 0x20, &allocate);
|
||||
write(replacement, 0x28, &release);
|
||||
write(replacement, 0x30, &reallocate);
|
||||
write(replacement, 0x38, &allocateZeroed);
|
||||
write(replacement, 0x30, &allocateZeroed);
|
||||
write(replacement, 0x38, &reallocate);
|
||||
write(replacement, 0x40, &align);
|
||||
write(replacement, 0x48, &reallocate);
|
||||
write(replacement, 0x50, &posixAlign);
|
||||
|
|
|
|||
Loading…
Reference in New Issue