Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR addresses two problems:
__rpl_start
leading to an endless loop or crashMEMGetSizeForMBlockExpHeap
on pointers returned fromMEMAllocFromDefaultHeap
for realloc. But the underlying heap is not anExpHeap
anymore. Thus any realloc call causes havoc.I reworked wutmalloc to not assume any underlying heap implementation and instead add a header to each allocation to store the required information about size and alignment.
I also opted to add a canary value in the allocation header that is checked on each free/realloc operation. On corruption it will OSFatal(). I do believe that it's better to have controlled crashing with a message than to silently ignore it and crash further down the line. Even in release builds.
With these changes RPLs are functional. At least during my testing I have never encountered any problems.
On a side note, it may be wise to rename
wut_malloc
towut_rpl_malloc
in order to make it more clear that it's only used for RPLs. RPXs seem to use a custom sbrk based heap. If maintainers agree with this I can do a follow-up PR.