Skip to content

Tighten GCC 2-region _sbrk #11572

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 3, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions platform/source/mbed_retarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1268,27 +1268,26 @@ extern "C" WEAK void __cxa_pure_virtual(void)
extern uint32_t __mbed_sbrk_start;
extern uint32_t __mbed_krbs_start;
/* Additional RAM memory used for heap - please note this
* address should be lower address then the previous default address
* address must be lower address then the previous default address
*/
extern uint32_t __mbed_sbrk_start_0;
extern uint32_t __mbed_krbs_start_0;

extern "C" WEAK caddr_t _sbrk(int incr)
{
static uint32_t heap = (uint32_t) &__mbed_sbrk_start_0;
static bool once = true;
uint32_t prev_heap = heap;
uint32_t new_heap = heap + incr;

/**
* If the new address is outside the first region, start allocating from the second region.
* Jump to second region is done just once, and `static bool once` is used to keep track of that.
* If we exceed the first region, start allocating from the second region.
*/
if (once && (new_heap > (uint32_t) &__mbed_krbs_start_0)) {
once = false;
if (prev_heap <= (uint32_t) &__mbed_krbs_start_0 && new_heap > (uint32_t) &__mbed_krbs_start_0) {
prev_heap = (uint32_t) &__mbed_sbrk_start;
new_heap = prev_heap + incr;
} else if (new_heap > (uint32_t) &__mbed_krbs_start) {
}

if (new_heap > (uint32_t) &__mbed_krbs_start) {
/**
* If the new address is outside the second region, return out-of-memory.
*/
Expand Down