diff options
Diffstat (limited to 'common/misc.c')
-rw-r--r-- | common/misc.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/common/misc.c b/common/misc.c new file mode 100644 index 0000000000..b3c47ef62d --- /dev/null +++ b/common/misc.c @@ -0,0 +1,32 @@ + +#include <mem_malloc.h> + +/* + * Begin and End of memory area for malloc(), and current "brk" + */ +static ulong mem_malloc_start = 0; +static ulong mem_malloc_end = 0; +static ulong mem_malloc_brk = 0; + +void mem_malloc_init (ulong start, ulong end) +{ + mem_malloc_start = start; + mem_malloc_end = end; + mem_malloc_brk = mem_malloc_start; + + memset ((void *) mem_malloc_start, 0, + mem_malloc_end - mem_malloc_start); +} + +void *sbrk (ptrdiff_t increment) +{ + ulong old = mem_malloc_brk; + ulong new = old + increment; + + if ((new < mem_malloc_start) || (new > mem_malloc_end)) { + return (NULL); + } + mem_malloc_brk = new; + + return ((void *) old); +} |