freemyipod r625 - Code Review

Jump to: navigation, search
Repository:freemyipod
Revision:r624‎ | r625 | r626 >
Date:17:09, 18 February 2011
Author:theseven
Status:new
Tags:
Comment:
emCORE: Add realign function, which is an alignment-aware realloc
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/libc/tlsf/tlsf.h (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
@@ -901,7 +901,7 @@
902902 ** - an extended buffer size will leave the newly-allocated area with
903903 ** contents undefined
904904 */
905 -void* tlsf_realloc(tlsf_pool tlsf, void* ptr, size_t size)
 905+void* tlsf_realign(tlsf_pool tlsf, void* ptr, size_t align, size_t size)
906906 {
907907 pool_t* pool = tlsf_cast(pool_t*, tlsf);
908908 void* p = 0;
@@ -931,7 +931,8 @@
932932 */
933933 if (adjust > cursize && (!block_is_free(next) || adjust > combined))
934934 {
935 - p = tlsf_malloc(tlsf, size);
 935+ if (align > 4) p = tlsf_memalign(tlsf, align, size);
 936+ else p = tlsf_malloc(tlsf, size);
936937 if (p)
937938 {
938939 const size_t minsize = tlsf_min(cursize, size);
@@ -956,3 +957,8 @@
957958
958959 return p;
959960 }
 961+
 962+void* tlsf_realloc(tlsf_pool tlsf, void* ptr, size_t size)
 963+{
 964+ return tlsf_realign(tlsf, ptr, 4, size);
 965+}
Index: emcore/trunk/libc/tlsf/tlsf.h
@@ -31,6 +31,7 @@
3232 /* malloc/memalign/realloc/free replacements. */
3333 void* tlsf_malloc(tlsf_pool pool, size_t bytes) ICODE_ATTR;
3434 void* tlsf_memalign(tlsf_pool pool, size_t align, size_t bytes) ICODE_ATTR;
 35+void* tlsf_realign(tlsf_pool pool, void* ptr, size_t align, size_t size) ICODE_ATTR;
3536 void* tlsf_realloc(tlsf_pool pool, void* ptr, size_t size) ICODE_ATTR;
3637 void tlsf_free(tlsf_pool pool, void* ptr) ICODE_ATTR;
3738
Index: emcore/trunk/export/syscallwrappers.h
@@ -220,6 +220,8 @@
221221 #define read_battery_mw __emcore_syscall->read_battery_mw
222222 #define read_input_mw __emcore_syscall->read_input_mw
223223 #define read_battery_state __emcore_syscall->read_battery_state
 224+#define tlsf_realign __emcore_syscall->tlsf_realign
 225+#define realign __emcore_syscall->realign
224226
225227
226228 #endif
Index: emcore/trunk/export/syscallapi.h
@@ -278,6 +278,8 @@
279279 typeof(read_battery_mw) *read_battery_mw;
280280 typeof(read_input_mw) *read_input_mw;
281281 typeof(read_battery_state) *read_battery_state;
 282+ typeof(tlsf_realign) *tlsf_realign;
 283+ typeof(realign) *realign;
282284 };
283285
284286
Index: emcore/trunk/malloc.c
@@ -53,12 +53,12 @@
5454 return ptr;
5555 }
5656
57 -void* realloc(void* ptr, size_t size)
 57+void* realign(void* ptr, size_t align, size_t size)
5858 {
5959 mutex_lock(&malloc_mutex, TIMEOUT_BLOCK);
6060 size_t oldsize = tlsf_block_size(ptr);
6161 struct scheduler_thread* owner = *((struct scheduler_thread**)(ptr + oldsize - 4));
62 - ptr = tlsf_realloc(global_mallocpool, ptr, size + 4);
 62+ ptr = tlsf_realign(global_mallocpool, ptr, align, size + 4);
6363 if (ptr)
6464 {
6565 size = tlsf_block_size(ptr);
@@ -68,6 +68,11 @@
6969 return ptr;
7070 }
7171
 72+void* realloc(void* ptr, size_t size)
 73+{
 74+ return realign(ptr, 4, size);
 75+}
 76+
7277 void reownalloc(void* ptr, struct scheduler_thread* owner)
7378 {
7479 mutex_lock(&malloc_mutex, TIMEOUT_BLOCK);
Index: emcore/trunk/malloc.h
@@ -31,6 +31,7 @@
3232
3333 void* malloc(size_t size) ICODE_ATTR;
3434 void* memalign(size_t align, size_t size) ICODE_ATTR;
 35+void* realign(void* ptr, size_t align, size_t size) ICODE_ATTR;
3536 void* realloc(void* ptr, size_t size) ICODE_ATTR;
3637 void reownalloc(void* ptr, struct scheduler_thread* owner);
3738 void free(void* ptr) ICODE_ATTR;
Index: emcore/trunk/syscallapi.c
@@ -242,5 +242,7 @@
243243 .read_battery_mwh_current = read_battery_mwh_current,
244244 .read_battery_mw = read_battery_mw,
245245 .read_input_mw = read_input_mw,
246 - .read_battery_state = read_battery_state
 246+ .read_battery_state = read_battery_state,
 247+ .tlsf_realign = tlsf_realign,
 248+ .realign = realign
247249 };