powerpc: Add simple memory allocator to bootwrapper
PATCH 3/4 powerpc: Add simple memory allocator to bootwrapper
Provide primitive malloc, free, and realloc functions for bootwrapper.
---
Makefile | 2 simple_alloc.c | 131 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 132 insertions(+), 1 deletion(-)
---
arch/powerpc/boot/Makefile +1 -1
@@ -41,7 +41,7 @@ zliblinuxheader := zlib.h zconf.h zutil. $(addprefix $(obj)/,$(zlibheader)) src-wlib := string.S stdio.c main.c flatdevtree.c flatdevtree_misc.c ns16550.c \ - serial.c div64.S util.S $(zlib) + serial.c simple_alloc.c div64.S util.S $(zlib) src-plat := of.c src-boot := crt0.S $(src-wlib) $(src-plat) empty.c
arch/powerpc/boot/simple_alloc.c new file +131 -0
131 lines not on this page · raw message
Quoted 1 line · Mark A. Greer
Provide primitive malloc, free, and realloc functions for bootwrapper.
[snip]
Quoted 8 lines
arch/powerpc/boot/simple_alloc.c new file +8
-0+/* +* Change size of area pointed to by 'ptr' to 'size'. +* If 'ptr' is NULL, then its a malloc(). If 'size' is 0, then its a free(). +* 'ptr' must be NULL or a value previously returned by simple_realloc(). +*/ +static void *simple_realloc (void *ptr,unsigned long size) +{ +if (size ==0 ) {
arch/powerpc/boot/simple_alloc.c line 101
Quoted 10 lines
arch/powerpc/boot/simple_alloc.c new file +10
-0+simple_free (ptr); +return NULL ; + } +else if (ptr ==NULL ) +return simple_malloc (size); +else { +simple_free (ptr); +return simple_malloc (size); + } +}
Um.. the above is clearly broken, it will throw away the data in a realloc()ed block.
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Quoted 17 lines · David Gibson
Quoted 1 line · Mark A. Greer
Provide primitive malloc, free, and realloc functions for bootwrapper.
[snip]
Quoted 13 lines
arch/powerpc/boot/simple_alloc.c new file +13
-0+/* +* Change size of area pointed to by 'ptr' to 'size'. +* If 'ptr' is NULL, then its a malloc(). If 'size' is 0, then its a free(). +* 'ptr' must be NULL or a value previously returned by simple_realloc(). +*/ +static void *simple_realloc (void *ptr,unsigned long size) +{ +if (size ==0 ) { +simple_free (ptr); +return NULL ; + } +else if (ptr ==NULL ) +return simple_malloc (size);
Quoted 8 lines
arch/powerpc/boot/simple_alloc.c line 101
Quoted 5 lines
arch/powerpc/boot/simple_alloc.c new file +5
-0+else { +simple_free (ptr); +return simple_malloc (size); + } +}Um.. the above is clearly broken, it will throw away the data in a realloc()ed block.
Yes, too much of a hurry, I guess. I'll fix.
Mark
Quoted 1 line · Mark A. Greer
Provide primitive malloc, free, and realloc functions for bootwrapper.
The order is a bit off here. This should be patch 4/4, as the Makefile needs the ns16550.c changes introduced by "[PATCH 4/4] powerpc: Add non-OF serial console support", which should be patch 3/4.
josh
Quoted 6 lines · Josh Boyer
Quoted 1 line · Mark A. Greer
Provide primitive malloc, free, and realloc functions for bootwrapper.
The order is a bit off here. This should be patch 4/4, as the
Makefileneeds thens16550.cchanges introduced by "[PATCH 4/4] powerpc: Add non-OF serial console support", which should be patch 3/4.
Oops, I switched the order at the last minute. I'll switch back.
Mark