diff options
Diffstat (limited to 'malloc.c')
-rw-r--r-- | malloc.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/malloc.c b/malloc.c new file mode 100644 index 0000000..3ab95ed --- /dev/null +++ b/malloc.c @@ -0,0 +1,21 @@ +#include <inttypes.h> +#include "string.h" + +extern uint8_t edata; +static uint8_t *fseg_base = &edata; + +extern uint8_t stext; +static uint8_t *malloc_top = &stext; + +void *malloc(int n) +{ + malloc_top -= (n + 15) & -16; + return malloc_top; +} + +void *malloc_fseg(int n) +{ + void *p = fseg_base; + fseg_base += (n + 15) & -16; + return p; +} |