freemyipod r626 - Code Review

Jump to: navigation, search
Repository:freemyipod
Revision:r625‎ | r626 | r627 >
Date:16:10, 18 February 2011
Author:theseven
Status:new
Tags:
Comment:
emCORE: Make sure that executed apps/libs are aligned at cacheline boundaries
Modified paths:
  • /emcore/trunk/execimage.c (modified) (history)

Diff [purge]

Index: emcore/trunk/execimage.c
@@ -63,7 +63,7 @@
6464 size_t tempsize = MAX(finalsize, datasize);
6565 if (compressed)
6666 {
67 - void* alloc = malloc(tempsize);
 67+ void* alloc = memalign(CACHEALIGN_SIZE, tempsize);
6868 if (!alloc)
6969 {
7070 cprintf(CONSOLE_BOOT, "execimage: Out of memory!\n");
@@ -81,21 +81,23 @@
8282 }
8383 image = alloc;
8484 }
85 - else if (copy)
 85+ else if (copy || (((uint32_t)image) & (CACHEALIGN_SIZE - 1)))
8686 {
87 - void* alloc = malloc(tempsize);
 87+ void* alloc = memalign(CACHEALIGN_SIZE, tempsize);
8888 if (!alloc)
8989 {
9090 cprintf(CONSOLE_BOOT, "execimage: Out of memory!\n");
 91+ if (!copy) free(image);
9192 return NULL;
9293 }
9394 memcpy(alloc, image + offset, datasize);
 95+ if (!copy) free(image);
9496 image = alloc;
9597 }
9698 else
9799 {
98100 memcpy(image, image + offset, datasize);
99 - void* newimage = realloc(image, tempsize);
 101+ void* newimage = realign(image, CACHEALIGN_SIZE, tempsize);
100102 if (!newimage)
101103 {
102104 free(image);