From 4fe98a46f551a87230ae577579ab2b569929cbce Mon Sep 17 00:00:00 2001 From: Peter Mitsis Date: Mon, 25 May 2015 14:31:59 -0400 Subject: [PATCH] Initialize stack area in _NewContext() Instead of initializing the stack (when INIT_STACKS is enabled) in start_task() and _fiber_start(), do it in _NewContext(). This helps to both reduce code duplication AND ensure that all contexts get an initialized stack (previously the background/idle task's was missed). Change-Id: If2d50309d2be48fac937f5d0ae96b9de185c0fe2 Signed-off-by: Peter Mitsis --- arch/arc/core/context.c | 4 ++++ arch/arm/core/nanocontext.c | 4 ++++ arch/x86/core/nanocontext.c | 4 ++++ kernel/microkernel/k_task.c | 4 ---- kernel/nanokernel/nano_fiber.c | 4 ---- 5 files changed, 12 insertions(+), 8 deletions(-) diff --git a/arch/arc/core/context.c b/arch/arc/core/context.c index ef9d97cd210..59557ea2c30 100644 --- a/arch/arc/core/context.c +++ b/arch/arc/core/context.c @@ -124,6 +124,10 @@ void _NewContext( tCCS *pCcs = (tCCS *) pStackMem; +#ifdef CONFIG_INIT_STACKS + k_memset(pStackMem, 0xaa, stackSize); +#endif + /* carve the context entry struct from the "base" of the stack */ pInitCtx = (struct init_stack_frame *)(STACK_ROUND_DOWN(stackEnd) - diff --git a/arch/arm/core/nanocontext.c b/arch/arm/core/nanocontext.c index ec00f13d80f..5d01482826c 100644 --- a/arch/arm/core/nanocontext.c +++ b/arch/arm/core/nanocontext.c @@ -117,6 +117,10 @@ void _NewContext( struct __esf *pInitCtx; tCCS *pCcs = (tCCS *) pStackMem; +#ifdef CONFIG_INIT_STACKS + k_memset(pStackMem, 0xaa, stackSize); +#endif + /* carve the context entry struct from the "base" of the stack */ pInitCtx = (struct __esf *)(STACK_ROUND_DOWN(stackEnd) - diff --git a/arch/x86/core/nanocontext.c b/arch/x86/core/nanocontext.c index 86b32466dce..01c61a4d07b 100644 --- a/arch/x86/core/nanocontext.c +++ b/arch/x86/core/nanocontext.c @@ -301,6 +301,10 @@ void _NewContext( { unsigned long *pInitialContext; +#ifdef CONFIG_INIT_STACKS + k_memset(pStackMem, 0xaa, stackSize); +#endif + /* carve the context entry struct from the "base" of the stack */ pInitialContext = diff --git a/kernel/microkernel/k_task.c b/kernel/microkernel/k_task.c index 92ba6de3c27..f0a5462611a 100644 --- a/kernel/microkernel/k_task.c +++ b/kernel/microkernel/k_task.c @@ -208,10 +208,6 @@ void start_task(struct k_proc *X, /* ptr to task control block */ /* Note: the field X->worksize now represents the task size in bytes */ -#ifdef CONFIG_INIT_STACKS - memset(X->workspace, 0xaa, X->worksize); -#endif - contextOptions = 0; _START_TASK_ARCH(X, &contextOptions); diff --git a/kernel/nanokernel/nano_fiber.c b/kernel/nanokernel/nano_fiber.c index ad679fa3a30..c9d6c3f878e 100644 --- a/kernel/nanokernel/nano_fiber.c +++ b/kernel/nanokernel/nano_fiber.c @@ -79,10 +79,6 @@ void _fiber_start(char *pStack, tCCS *ccs; unsigned int imask; -#ifdef CONFIG_INIT_STACKS - memset((char *)pStack, 0xaa, stackSize); -#endif - ccs = (tCCS *) pStack; _NewContext(pStack, stackSize,