-
Notifications
You must be signed in to change notification settings - Fork 11.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[libc] Lazily initialize freelist malloc using symbols
This allows the user to customize the size of the heap provided by overriding the weak symbol __libc_heap_limit at link time. The heap begins at _end and ends __libc_heap_limit bytes afterwards. It also prevents a completely unused heap from requiring any space. (It's reasonably common to link in malloc/free to handle exceptional situations that can never actually be encountered.) I'd think this should eventually be replaced with an implemenation based on sbrk(), with sbrk() implemented generically in terms of brk(), which would be a system call on e.g. Linux and a bump pointer from _end up to __libc_heap_limit on baremetal. This would allow the allocator to be more flexible (e.g., an implementation could swap out brk() and do dynamic memory availability checks), to manage the heap better by keeping better track of "wilderness" and to work properly as a malloc on Linux. Incidentally, this sets the default heap limit to 128KiB, from 102400 bytes, which had been reported as "1GiB".
- Loading branch information
1 parent
5b82741
commit d643410
Showing
7 changed files
with
63 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ | |
}, | ||
"malloc": { | ||
"LIBC_CONF_FREELIST_MALLOC_BUFFER_SIZE": { | ||
"value": 102400 | ||
"value": 131072 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.weak __libc_heap_limit | ||
.set __libc_heap_limit, LIBC_FREELIST_MALLOC_SIZE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters