freemyipod r565 - Code Review

Jump to: navigation, search
Repository:freemyipod
Revision:r564‎ | r565 | r566 >
Date:22:35, 7 February 2011
Author:theseven
Status:new
Tags:
Comment:
emCORE: Detect malloc heap size correctly, improve the default heap walker, and expose a function for walking the global malloc heap
Modified paths:
  • /emcore/trunk/export/syscallapi.h (modified) (history)
  • /emcore/trunk/export/syscallwrappers.h (modified) (history)
  • /emcore/trunk/libc/tlsf/tlsf.c (modified) (history)
  • /emcore/trunk/malloc.c (modified) (history)
  • /emcore/trunk/malloc.h (modified) (history)
  • /emcore/trunk/syscallapi.c (modified) (history)

Diff [purge]

Index: emcore/trunk/libc/tlsf/tlsf.c
@@ -714,8 +714,9 @@
715715
716716 static void default_walker(void* ptr, size_t size, int used, void* user)
717717 {
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);
720721 }
721722
722723 void tlsf_walk_heap(tlsf_pool pool, tlsf_walker walker, void* user)
Index: emcore/trunk/export/syscallwrappers.h
@@ -203,6 +203,7 @@
204204 #define lcd_get_format __emcore_syscall->lcd_get_format
205205 #define crc32 __emcore_syscall->crc32
206206 #define clockgate_get_state __emcore_syscall->clockgate_get_state
 207+#define malloc_walk __emcore_syscall->malloc_walk
207208
208209
209210 #endif
Index: emcore/trunk/export/syscallapi.h
@@ -260,6 +260,7 @@
261261 typeof(lcd_get_format) *lcd_get_format;
262262 typeof(crc32) *crc32;
263263 typeof(clockgate_get_state) *clockgate_get_state;
 264+ typeof(malloc_walk) *malloc_walk;
264265 };
265266
266267
Index: emcore/trunk/malloc.c
@@ -26,8 +26,8 @@
2727 #include "libc/tlsf/tlsf.h"
2828
2929
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...
3232
3333 struct mutex malloc_mutex;
3434 tlsf_pool global_mallocpool;
@@ -93,6 +93,13 @@
9494 mutex_unlock(&malloc_mutex);
9595 }
9696
 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+
97104 void malloc_init()
98105 {
99106 mutex_init(&malloc_mutex);
Index: emcore/trunk/malloc.h
@@ -35,6 +35,7 @@
3636 void reownalloc(void* ptr, struct scheduler_thread* owner);
3737 void free(void* ptr) ICODE_ATTR;
3838 void free_all_of_thread(struct scheduler_thread* owner);
 39+void malloc_walk(void (*walker), void* user);
3940 void malloc_init() INITCODE_ATTR;
4041
4142
Index: emcore/trunk/syscallapi.c
@@ -221,5 +221,6 @@
222222 #endif
223223 .lcd_get_format = lcd_get_format,
224224 .crc32 = crc32,
225 - .clockgate_get_state = clockgate_get_state
 225+ .clockgate_get_state = clockgate_get_state,
 226+ .malloc_walk = malloc_walk
226227 };