-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
bkleiner
committed
Oct 15, 2023
1 parent
f7c664e
commit 1a95c5a
Showing
4 changed files
with
27 additions
and
6 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
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,22 @@ | ||
#include <sys/types.h> | ||
|
||
register char *stack_ptr asm("sp"); | ||
uint __heap_limit = 0xcafedead; | ||
|
||
__attribute__((__used__)) void *_sbrk(ptrdiff_t incr) { | ||
extern char end asm("end"); /* Defined by the linker. */ | ||
static char *heap_end; | ||
|
||
if (heap_end == NULL) | ||
heap_end = &end; | ||
|
||
const char *prev_heap_end = heap_end; | ||
|
||
if ((heap_end + incr > stack_ptr) || | ||
(__heap_limit != 0xcafedead && heap_end + incr > (char *)__heap_limit)) { | ||
return (void *)-1; | ||
} | ||
|
||
heap_end += incr; | ||
return (void *)prev_heap_end; | ||
} |