Skip to content

Instantly share code, notes, and snippets.

@michahoiting
Last active December 17, 2022 16:31
Show Gist options
  • Save michahoiting/a03a89a07f7ad3d13fd889f6dc902361 to your computer and use it in GitHub Desktop.
Save michahoiting/a03a89a07f7ad3d13fd889f6dc902361 to your computer and use it in GitHub Desktop.
A very naive implementation of the newlib _sbrk dependency function
//! A very naive implementation of the newlib _sbrk dependency function
caddr_t _sbrk(int incr);
caddr_t _sbrk(int incr) {
static uint32_t s_index = 0;
static uint8_t s_newlib_heap[2048] __attribute__((aligned(8)));
if ((s_index + (uint32_t)incr) <= sizeof(s_newlib_heap)) {
EXAMPLE_LOG("Out of Memory!");
return 0;
}
caddr_t result = (caddr_t)&s_newlib_heap[s_index];
s_index += (uint32_t)incr;
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment