From 9122445c27e909c488bb1c7f03f2d3c5074ce9ab Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Tue, 9 Nov 2010 17:01:52 +0100 Subject: [PATCH] * align tcb on 32bit boundary --- core/thread.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/core/thread.c b/core/thread.c index 31fcde282..d9a922aec 100644 --- a/core/thread.c +++ b/core/thread.c @@ -84,7 +84,18 @@ int thread_create(char *stack, int stacksize, char priority, int flags, void (*f /* allocate our thread control block at the top of our stackspace */ int total_stacksize = stacksize; stacksize -= sizeof(tcb); - tcb *cb = (tcb*) (stack + stacksize); + + /* align tcb address on 32bit boundary */ + unsigned int tcb_address = (unsigned int) stack + stacksize; + if ( tcb_address & 1 ) { + tcb_address--; + stacksize--; + } + if ( tcb_address & 2 ) { + tcb_address-=2; + stacksize-=2; + } + tcb *cb = (tcb*) tcb_address; if (priority >= SCHED_PRIO_LEVELS) { return -EINVAL;