Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 1 | #include <stdlib.h> |
| 2 | #include <console/console.h> |
| 3 | |
| 4 | #if 0 |
| 5 | #define MALLOCDBG(x) |
| 6 | #else |
Stefan Reinauer | 054c723 | 2009-03-06 17:22:35 +0000 | [diff] [blame] | 7 | #define MALLOCDBG(x...) printk_spew(x) |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 8 | #endif |
| 9 | extern unsigned char _heap, _eheap; |
Stefan Reinauer | 054c723 | 2009-03-06 17:22:35 +0000 | [diff] [blame] | 10 | static void *free_mem_ptr = &_heap; /* Start of heap */ |
| 11 | static void *free_mem_end_ptr = &_eheap; /* End of heap */ |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 12 | |
| 13 | |
| 14 | void malloc_mark(malloc_mark_t *place) |
| 15 | { |
Stefan Reinauer | 054c723 | 2009-03-06 17:22:35 +0000 | [diff] [blame] | 16 | *place = (malloc_mark_t)free_mem_ptr; |
| 17 | printk_spew("malloc_mark %p\n", free_mem_ptr); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 18 | } |
| 19 | |
| 20 | void malloc_release(malloc_mark_t *ptr) |
| 21 | { |
Stefan Reinauer | 054c723 | 2009-03-06 17:22:35 +0000 | [diff] [blame] | 22 | free_mem_ptr = (void *)*ptr; |
| 23 | printk_spew("malloc_release %p\n", free_mem_ptr); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 24 | } |
| 25 | |
| 26 | void *malloc(size_t size) |
| 27 | { |
| 28 | void *p; |
| 29 | |
Stefan Reinauer | 054c723 | 2009-03-06 17:22:35 +0000 | [diff] [blame] | 30 | MALLOCDBG("%s Enter, size %ld, free_mem_ptr %p\n", __func__, size, free_mem_ptr); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 31 | if (size < 0) |
| 32 | die("Error! malloc: Size < 0"); |
| 33 | if (free_mem_ptr <= 0) |
| 34 | die("Error! malloc: Free_mem_ptr <= 0"); |
| 35 | |
Stefan Reinauer | 054c723 | 2009-03-06 17:22:35 +0000 | [diff] [blame] | 36 | free_mem_ptr = (void *)(((unsigned long)free_mem_ptr + 3) & ~3); /* Align */ |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 37 | |
| 38 | p = (void *) free_mem_ptr; |
| 39 | free_mem_ptr += size; |
| 40 | |
| 41 | if (free_mem_ptr >= free_mem_end_ptr) |
arch import user (historical) | ef03afa | 2005-07-06 17:15:30 +0000 | [diff] [blame] | 42 | die("Error! malloc: free_mem_ptr >= free_mem_end_ptr"); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 43 | |
Stefan Reinauer | 054c723 | 2009-03-06 17:22:35 +0000 | [diff] [blame] | 44 | MALLOCDBG("malloc %p\n", p); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 45 | |
| 46 | return p; |
| 47 | } |
| 48 | |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 49 | void free(void *where) |
| 50 | { |
| 51 | /* Don't care */ |
| 52 | } |