Index: emcore/trunk/libc/tlsf/tlsf.c |
— | — | @@ -714,8 +714,9 @@ |
715 | 715 |
|
716 | 716 | static void default_walker(void* ptr, size_t size, int used, void* user)
|
717 | 717 | {
|
718 | | - (void)user;
|
719 | | - cprintf(CONSOLE_BOOT, "\t%p %s size: %x\n", ptr, used ? "used" : "free", size);
|
| 718 | + if (used) cprintf((int)user, "%08X: %08X+8 bytes owned by %08X\n", ptr,
|
| 719 | + size - 4, *((uint32_t*)(ptr + size - 4)));
|
| 720 | + else cprintf((int)user, "%08X: %08X bytes free\n", ptr, size + 4);
|
720 | 721 | }
|
721 | 722 |
|
722 | 723 | void tlsf_walk_heap(tlsf_pool pool, tlsf_walker walker, void* user)
|
Index: emcore/trunk/export/syscallwrappers.h |
— | — | @@ -203,6 +203,7 @@ |
204 | 204 | #define lcd_get_format __emcore_syscall->lcd_get_format
|
205 | 205 | #define crc32 __emcore_syscall->crc32
|
206 | 206 | #define clockgate_get_state __emcore_syscall->clockgate_get_state
|
| 207 | +#define malloc_walk __emcore_syscall->malloc_walk
|
207 | 208 |
|
208 | 209 |
|
209 | 210 | #endif
|
Index: emcore/trunk/export/syscallapi.h |
— | — | @@ -260,6 +260,7 @@ |
261 | 261 | typeof(lcd_get_format) *lcd_get_format;
|
262 | 262 | typeof(crc32) *crc32;
|
263 | 263 | typeof(clockgate_get_state) *clockgate_get_state;
|
| 264 | + typeof(malloc_walk) *malloc_walk;
|
264 | 265 | };
|
265 | 266 |
|
266 | 267 |
|
Index: emcore/trunk/malloc.c |
— | — | @@ -26,8 +26,8 @@ |
27 | 27 | #include "libc/tlsf/tlsf.h"
|
28 | 28 |
|
29 | 29 |
|
30 | | -extern int _poolstart; // These aren't ints at all, but gcc complains about void types being
|
31 | | -extern int _poolend; // used here, and we only need the address, so just make it happy...
|
| 30 | +extern char _poolstart; // These aren't ints at all, but gcc complains about void types being
|
| 31 | +extern char _poolend; // used here, and we only need the address, so just make it happy...
|
32 | 32 |
|
33 | 33 | struct mutex malloc_mutex;
|
34 | 34 | tlsf_pool global_mallocpool;
|
— | — | @@ -93,6 +93,13 @@ |
94 | 94 | mutex_unlock(&malloc_mutex);
|
95 | 95 | }
|
96 | 96 |
|
| 97 | +void malloc_walk(void (*walker), void* user)
|
| 98 | +{
|
| 99 | + mutex_lock(&malloc_mutex, TIMEOUT_BLOCK);
|
| 100 | + tlsf_walk_heap(global_mallocpool, walker, user);
|
| 101 | + mutex_unlock(&malloc_mutex);
|
| 102 | +}
|
| 103 | +
|
97 | 104 | void malloc_init()
|
98 | 105 | {
|
99 | 106 | mutex_init(&malloc_mutex);
|
Index: emcore/trunk/malloc.h |
— | — | @@ -35,6 +35,7 @@ |
36 | 36 | void reownalloc(void* ptr, struct scheduler_thread* owner);
|
37 | 37 | void free(void* ptr) ICODE_ATTR;
|
38 | 38 | void free_all_of_thread(struct scheduler_thread* owner);
|
| 39 | +void malloc_walk(void (*walker), void* user);
|
39 | 40 | void malloc_init() INITCODE_ATTR;
|
40 | 41 |
|
41 | 42 |
|
Index: emcore/trunk/syscallapi.c |
— | — | @@ -221,5 +221,6 @@ |
222 | 222 | #endif
|
223 | 223 | .lcd_get_format = lcd_get_format,
|
224 | 224 | .crc32 = crc32,
|
225 | | - .clockgate_get_state = clockgate_get_state
|
| 225 | + .clockgate_get_state = clockgate_get_state,
|
| 226 | + .malloc_walk = malloc_walk
|
226 | 227 | };
|