freemyipod r842 - Code Review

Jump to: navigation, search
Repository:freemyipod
Revision:r841‎ | r842 | r843 >
Date:22:22, 26 December 2011
Author:theseven
Status:new
Tags:
Comment:
emCORE: Fix stack alignment if execimage() command line argument size is not a multiple of 4
Modified paths:
  • /emcore/trunk/execimage.c (modified) (history)
  • /emcore/trunk/execimage.h (modified) (history)
  • /emcore/trunk/init.c (modified) (history)

Diff [purge]

Index: emcore/trunk/init.c
@@ -133,7 +133,7 @@
134134 #endif
135135
136136 void initthread(void* arg0, void* arg1, void* arg2, void* arg3) INITCODE_ATTR;
137 -void initthread(void* arg0, void* bootalloc, void* arg2, void* arg3)
 137+void initthread(void* arg0, void* arg1, void* arg2, void* arg3)
138138 {
139139 struct initbss* ib = (struct initbss*)arg0;
140140 #ifdef HAVE_I2C
@@ -244,7 +244,6 @@
245245 else option = option->fail_next;
246246 }
247247 if (!success) cputs(CONSOLE_BOOT, nobootoptionsstr);
248 - free(bootalloc);
249248 }
250249
251250 void init() INITCODE_ATTR;
@@ -271,7 +270,7 @@
272271 reownalloc(ib, OWNER_TYPE(OWNER_THREAD, &(ib->initthread)));
273272 reownalloc(bootalloc, OWNER_TYPE(OWNER_THREAD, &(ib->initthread)));
274273 thread_create(&(ib->initthread), initthreadname, initthread, ib->initstack,
275 - sizeof(ib->initstack), OS_THREAD, 127, true, ib, bootalloc, NULL, NULL);
 274+ sizeof(ib->initstack), OS_THREAD, 127, true, ib, NULL, NULL, NULL);
276275 timer_init();
277276 interrupt_init();
278277 }
Index: emcore/trunk/execimage.c
@@ -28,7 +28,7 @@
2929 #include "malloc.h"
3030
3131
32 -struct scheduler_thread* execimage(void* image, bool copy, int argc, const char** argv)
 32+struct scheduler_thread* execimage(void* image, bool copy, int argc, const char* const* argv)
3333 {
3434 int i;
3535 struct emcoreapp_header* header = (struct emcoreapp_header*)image;
@@ -62,6 +62,7 @@
6363 for (i = 0; i < argc; i++)
6464 argsize += 5 + strlen(argv[i]);
6565 else argc = 0;
 66+ argsize = (argsize + 3) & ~3;
6667 size_t finalsize;
6768 if (lib) finalsize = textsize + bsssize;
6869 else finalsize = textsize + bsssize + argsize + stacksize;
@@ -122,6 +123,7 @@
123124 void* ptr = image + textsize;
124125 memset(ptr, 0, bsssize);
125126 ptr += bsssize;
 127+ void* argv_copy = ptr;
126128 if (argv)
127129 {
128130 memcpy(image + textsize + bsssize, argv, argc * 4);
@@ -133,6 +135,7 @@
134136 ptr += len;
135137 }
136138 }
 139+ ptr = (void*)(((int)ptr + 3) & ~3);
137140 clean_dcache();
138141 invalidate_icache();
139142 struct scheduler_thread* thread;
@@ -141,7 +144,7 @@
142145 else
143146 {
144147 thread = thread_create(NULL, NULL, image + entrypoint, ptr, stacksize,
145 - USER_THREAD, 127, false, (void*)argc, argv, NULL, NULL);
 148+ USER_THREAD, 127, false, (void*)argc, argv_copy, NULL, NULL);
146149 if (thread)
147150 {
148151 reownalloc(image, OWNER_TYPE(OWNER_THREAD, thread));
Index: emcore/trunk/execimage.h
@@ -54,7 +54,7 @@
5555
5656
5757 #ifndef _TOOL
58 -struct scheduler_thread* execimage(void* image, bool copy, int argc, const char** argv);
 58+struct scheduler_thread* execimage(void* image, bool copy, int argc, const char* const* argv);
5959 #endif
6060
6161