Commit 4460dbc
committed
Let malloc leave some extra space for the stack
The _sbrk() implementation added previously refuses to overwrite the
stack, but will still happily allocate all other memory, leaving none to
expand the stack into. Since the stack can expand over the heap
undetected, this changes sbrk() to leave a safety margin between the
heap and the stack (at the time of the malloc/_sbrk call). The size of
this margin can be configured (by the sketch) by changing the
`__malloc_margin` global variable, it defaults to 64 bytes.
This approach (both having a margin and making it configurable with the
`__malloc_margin`) is copied from the avr-libc malloc implementation,
see:
https://onlinedocs.microchip.com/pr/GUID-317042D4-BCCE-4065-BB05-AC4312DBC2C4-en-US-2/index.html?GUID-27757112-8BE1-49C2-B023-CD94AD06C5E2
avr-libc uses a default margin of 32 bytes, but given the bigger integer
and pointer size on ARM, this is doubled for this core.1 parent d232b59 commit 4460dbc
1 file changed
+5
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
5 | 9 | | |
6 | 10 | | |
7 | 11 | | |
8 | 12 | | |
9 | 13 | | |
10 | 14 | | |
11 | | - | |
| 15 | + | |
12 | 16 | | |
13 | 17 | | |
14 | 18 | | |
| |||
0 commit comments