Index: emcore/trunk/libc/tlsf/tlsf.c |
— | — | @@ -901,7 +901,7 @@ |
902 | 902 | ** - an extended buffer size will leave the newly-allocated area with
|
903 | 903 | ** contents undefined
|
904 | 904 | */
|
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)
|
906 | 906 | {
|
907 | 907 | pool_t* pool = tlsf_cast(pool_t*, tlsf);
|
908 | 908 | void* p = 0;
|
— | — | @@ -931,7 +931,8 @@ |
932 | 932 | */
|
933 | 933 | if (adjust > cursize && (!block_is_free(next) || adjust > combined))
|
934 | 934 | {
|
935 | | - p = tlsf_malloc(tlsf, size);
|
| 935 | + if (align > 4) p = tlsf_memalign(tlsf, align, size);
|
| 936 | + else p = tlsf_malloc(tlsf, size);
|
936 | 937 | if (p)
|
937 | 938 | {
|
938 | 939 | const size_t minsize = tlsf_min(cursize, size);
|
— | — | @@ -956,3 +957,8 @@ |
957 | 958 |
|
958 | 959 | return p;
|
959 | 960 | }
|
| 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 @@ |
32 | 32 | /* malloc/memalign/realloc/free replacements. */
|
33 | 33 | void* tlsf_malloc(tlsf_pool pool, size_t bytes) ICODE_ATTR;
|
34 | 34 | 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;
|
35 | 36 | void* tlsf_realloc(tlsf_pool pool, void* ptr, size_t size) ICODE_ATTR;
|
36 | 37 | void tlsf_free(tlsf_pool pool, void* ptr) ICODE_ATTR;
|
37 | 38 |
|
Index: emcore/trunk/export/syscallwrappers.h |
— | — | @@ -220,6 +220,8 @@ |
221 | 221 | #define read_battery_mw __emcore_syscall->read_battery_mw |
222 | 222 | #define read_input_mw __emcore_syscall->read_input_mw |
223 | 223 | #define read_battery_state __emcore_syscall->read_battery_state |
| 224 | +#define tlsf_realign __emcore_syscall->tlsf_realign |
| 225 | +#define realign __emcore_syscall->realign |
224 | 226 | |
225 | 227 | |
226 | 228 | #endif |
Index: emcore/trunk/export/syscallapi.h |
— | — | @@ -278,6 +278,8 @@ |
279 | 279 | typeof(read_battery_mw) *read_battery_mw; |
280 | 280 | typeof(read_input_mw) *read_input_mw; |
281 | 281 | typeof(read_battery_state) *read_battery_state; |
| 282 | + typeof(tlsf_realign) *tlsf_realign; |
| 283 | + typeof(realign) *realign; |
282 | 284 | }; |
283 | 285 | |
284 | 286 | |
Index: emcore/trunk/malloc.c |
— | — | @@ -53,12 +53,12 @@ |
54 | 54 | return ptr;
|
55 | 55 | }
|
56 | 56 |
|
57 | | -void* realloc(void* ptr, size_t size)
|
| 57 | +void* realign(void* ptr, size_t align, size_t size)
|
58 | 58 | {
|
59 | 59 | mutex_lock(&malloc_mutex, TIMEOUT_BLOCK);
|
60 | 60 | size_t oldsize = tlsf_block_size(ptr);
|
61 | 61 | 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);
|
63 | 63 | if (ptr)
|
64 | 64 | {
|
65 | 65 | size = tlsf_block_size(ptr);
|
— | — | @@ -68,6 +68,11 @@ |
69 | 69 | return ptr;
|
70 | 70 | }
|
71 | 71 |
|
| 72 | +void* realloc(void* ptr, size_t size)
|
| 73 | +{
|
| 74 | + return realign(ptr, 4, size);
|
| 75 | +}
|
| 76 | +
|
72 | 77 | void reownalloc(void* ptr, struct scheduler_thread* owner)
|
73 | 78 | {
|
74 | 79 | mutex_lock(&malloc_mutex, TIMEOUT_BLOCK);
|
Index: emcore/trunk/malloc.h |
— | — | @@ -31,6 +31,7 @@ |
32 | 32 |
|
33 | 33 | void* malloc(size_t size) ICODE_ATTR;
|
34 | 34 | void* memalign(size_t align, size_t size) ICODE_ATTR;
|
| 35 | +void* realign(void* ptr, size_t align, size_t size) ICODE_ATTR;
|
35 | 36 | void* realloc(void* ptr, size_t size) ICODE_ATTR;
|
36 | 37 | void reownalloc(void* ptr, struct scheduler_thread* owner);
|
37 | 38 | void free(void* ptr) ICODE_ATTR;
|
Index: emcore/trunk/syscallapi.c |
— | — | @@ -242,5 +242,7 @@ |
243 | 243 | .read_battery_mwh_current = read_battery_mwh_current, |
244 | 244 | .read_battery_mw = read_battery_mw, |
245 | 245 | .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 |
247 | 249 | }; |