[libc] Create debug version of malloc, fix near->far malloc conversion bug #2129
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.
Fixes bug in malloc that returned non-zero DS:0 on failure, rather than 0:0 (NULL) in large model. Discussed in rafael2k/8086-toolchain#19.
Adds debugging display to malloc and fmemalloc. When 'debug=1` is set in /bootopts, the sizes in bytes of malloc and fmemalloc will be displayed along with the process id, for easier tracking of near and far memory allocations used by the under-development 8086-toolchain. When malloc or fmemalloc fails, that will also be displayed to let the developer know the application is out of memory.
For instance, when running LD86, the following is displayed.
The MALLOC value is the requested allocation (+2 for internal tracking), and the SBRK value is the data segment heap expansion value (+ another 2 for heap tracking).
This allows for much better visibility on which tools ask for near vs far memory and how much is requested. Currently, no attempt is made to determine remaining free space or summing the allocations and frees to determine working set storage requirements.
@rafael2k: I haven't tested this on your last couple of days enhancements, as I'm in the middle of some C86 enhancements. Thus, my versions don't have the bug fixes you've run into regarding memrealloc and others. However, this PR does fix the problem of malloc returning DS:0 rather than NULL (0:), so the NULLPTR defines should not be necessary anymore, although it won't hurt to leave them in.
When you have time, please test this with your latest build (requires OWC libc rebuild and updated kernel, of course). I'm interested to hear what you think with regards to the memory allocations being used with the latest toolchain fixes.