Repository navigation
feat(libc): implement malloc_usable_size - #1656
NahuelGenchi wants to merge 1 commit into
Conversation
|
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
|
|
Windows run, since the description says the Windows job would be the first run there: Windows 11 Pro (26200), MinGW-w64 GCC 15.2.0 (WinLibs r7, the CI build), Release, configured like CI, Ryzen 9 5900X. This commit merged onto
The Windows guest heap commits through AI-assisted: yes (Claude Code). |
|
First Windows run, since the description says it wasn't tested on Windows. Setup: Windows 10 (19045), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release. Merged onto
🤖 Addressed by Claude Code |
|
Closing: no title is shown stopping at |
|
@NahuelGenchi OpenRCT2 Native Port (PPSA99728) now stops at |
What
malloc_usable_sizeis imported from libSceLibcInternal by PPSA99005 and PPSA99001 (the ps5-opengl and ProsperoRadio homebrew in #1578) and wasn't exported. It returns the number of bytes a block can hold, which is at least what was requested. A null pointer gives 0, as on FreeBSD.With the default heap it comes from the block header every allocation already carries: the space from the user pointer to the end of the raw block. That covers the extra room of the 16 byte header rounding and the padding added for aligned allocations, and the whole range is writable. A pointer the heap didn't hand out still fails the allocation lookup and throws, the same way
freedoes.When a title installs its own allocator, the call goes to its
malloc_usable_sizeentry. The replacement table already carries it (slot 9 after malloc, free, calloc, realloc, memalign, reallocalign, posix_memalign, malloc_stats and malloc_stats_fast, in the order ofMallocReplaceinSceTypes.hpp). If a title leaves that entry empty the call throws like the other unregistered allocator entries, since there's no way to know the size without it.The progress tool counts two functions here because it also counts the
defaultUsableSizecallback, like it counts the otherdefault*callbacks in that file. The export itself is one.PR #1611 also appends to the end of
ApplicationHeap.cppand its test, so those two will conflict as text. They add different functions, and whichever merges second needs a small rebase.Tested
Ubuntu 26.04, GCC 15.2.
application_heap_testscovers the title allocator path (the callback is called with the right pointer, null never reaches it), a table without the entry (throws, null still returns 0), and the default heap for 1, 37, 4096 and 100000 bytes plus aligned blocks: the result covers the request and every reported byte can be written. A stack address is rejected. The whole non-GPU suite passes (239 tests). Not run on Windows locally, so the Windows job is the first run there.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)