diff --git a/arch/arm/src/arm/arm_initialstate.c b/arch/arm/src/arm/arm_initialstate.c index d15d0b68c2..eff64ecdfe 100644 --- a/arch/arm/src/arm/arm_initialstate.c +++ b/arch/arm/src/arm/arm_initialstate.c @@ -62,8 +62,17 @@ void up_initial_state(struct tcb_s *tcb) { tcb->stack_alloc_ptr = (void *)(g_idle_topstack - CONFIG_IDLETHREAD_STACKSIZE); - tcb->stack_base_ptr = tcb->stack_alloc_ptr; + tcb->stack_base_ptr = tcb->stack_alloc_ptr; tcb->adj_stack_size = CONFIG_IDLETHREAD_STACKSIZE; + +#ifdef CONFIG_STACK_COLORATION + /* If stack debug is enabled, then fill the stack with a + * recognizable value that we can use later to test for high + * water marks. + */ + + arm_stack_color(tcb->stack_alloc_ptr, 0); +#endif /* CONFIG_STACK_COLORATION */ } /* Initialize the initial exception register context structure */ diff --git a/arch/arm/src/armv6-m/arm_initialstate.c b/arch/arm/src/armv6-m/arm_initialstate.c index 5df0fa071e..afa764a3e9 100644 --- a/arch/arm/src/armv6-m/arm_initialstate.c +++ b/arch/arm/src/armv6-m/arm_initialstate.c @@ -64,8 +64,17 @@ void up_initial_state(struct tcb_s *tcb) { tcb->stack_alloc_ptr = (void *)(g_idle_topstack - CONFIG_IDLETHREAD_STACKSIZE); - tcb->stack_base_ptr = tcb->stack_alloc_ptr; + tcb->stack_base_ptr = tcb->stack_alloc_ptr; tcb->adj_stack_size = CONFIG_IDLETHREAD_STACKSIZE; + +#ifdef CONFIG_STACK_COLORATION + /* If stack debug is enabled, then fill the stack with a + * recognizable value that we can use later to test for high + * water marks. + */ + + arm_stack_color(tcb->stack_alloc_ptr, 0); +#endif /* CONFIG_STACK_COLORATION */ } /* Initialize the initial exception register context structure */ diff --git a/arch/arm/src/armv7-a/arm_initialstate.c b/arch/arm/src/armv7-a/arm_initialstate.c index 521649b048..5cf5f92973 100644 --- a/arch/arm/src/armv7-a/arm_initialstate.c +++ b/arch/arm/src/armv7-a/arm_initialstate.c @@ -62,8 +62,17 @@ void up_initial_state(struct tcb_s *tcb) { tcb->stack_alloc_ptr = (void *)(g_idle_topstack - CONFIG_IDLETHREAD_STACKSIZE); - tcb->stack_base_ptr = tcb->stack_alloc_ptr; + tcb->stack_base_ptr = tcb->stack_alloc_ptr; tcb->adj_stack_size = CONFIG_IDLETHREAD_STACKSIZE; + +#ifdef CONFIG_STACK_COLORATION + /* If stack debug is enabled, then fill the stack with a + * recognizable value that we can use later to test for high + * water marks. + */ + + arm_stack_color(tcb->stack_alloc_ptr, 0); +#endif /* CONFIG_STACK_COLORATION */ } /* Initialize the initial exception register context structure */ diff --git a/arch/arm/src/armv7-m/arm_initialstate.c b/arch/arm/src/armv7-m/arm_initialstate.c index 90872ad143..8e95a5d548 100644 --- a/arch/arm/src/armv7-m/arm_initialstate.c +++ b/arch/arm/src/armv7-m/arm_initialstate.c @@ -65,8 +65,17 @@ void up_initial_state(struct tcb_s *tcb) { tcb->stack_alloc_ptr = (void *)(g_idle_topstack - CONFIG_IDLETHREAD_STACKSIZE); - tcb->stack_base_ptr = tcb->stack_alloc_ptr; + tcb->stack_base_ptr = tcb->stack_alloc_ptr; tcb->adj_stack_size = CONFIG_IDLETHREAD_STACKSIZE; + +#ifdef CONFIG_STACK_COLORATION + /* If stack debug is enabled, then fill the stack with a + * recognizable value that we can use later to test for high + * water marks. + */ + + arm_stack_color(tcb->stack_alloc_ptr, 0); +#endif /* CONFIG_STACK_COLORATION */ } /* Initialize the initial exception register context structure */ diff --git a/arch/arm/src/armv7-r/arm_initialstate.c b/arch/arm/src/armv7-r/arm_initialstate.c index 3656bb6764..1cf12adc80 100644 --- a/arch/arm/src/armv7-r/arm_initialstate.c +++ b/arch/arm/src/armv7-r/arm_initialstate.c @@ -62,8 +62,17 @@ void up_initial_state(struct tcb_s *tcb) { tcb->stack_alloc_ptr = (void *)(g_idle_topstack - CONFIG_IDLETHREAD_STACKSIZE); - tcb->stack_base_ptr = tcb->stack_alloc_ptr; + tcb->stack_base_ptr = tcb->stack_alloc_ptr; tcb->adj_stack_size = CONFIG_IDLETHREAD_STACKSIZE; + +#ifdef CONFIG_STACK_COLORATION + /* If stack debug is enabled, then fill the stack with a + * recognizable value that we can use later to test for high + * water marks. + */ + + arm_stack_color(tcb->stack_alloc_ptr, 0); +#endif /* CONFIG_STACK_COLORATION */ } /* Initialize the initial exception register context structure */ diff --git a/arch/arm/src/armv8-m/arm_initialstate.c b/arch/arm/src/armv8-m/arm_initialstate.c index b2bbf88596..99f19125c7 100644 --- a/arch/arm/src/armv8-m/arm_initialstate.c +++ b/arch/arm/src/armv8-m/arm_initialstate.c @@ -65,8 +65,17 @@ void up_initial_state(struct tcb_s *tcb) { tcb->stack_alloc_ptr = (void *)(g_idle_topstack - CONFIG_IDLETHREAD_STACKSIZE); - tcb->stack_base_ptr = tcb->stack_alloc_ptr; + tcb->stack_base_ptr = tcb->stack_alloc_ptr; tcb->adj_stack_size = CONFIG_IDLETHREAD_STACKSIZE; + +#ifdef CONFIG_STACK_COLORATION + /* If stack debug is enabled, then fill the stack with a + * recognizable value that we can use later to test for high + * water marks. + */ + + arm_stack_color(tcb->stack_alloc_ptr, 0); +#endif /* CONFIG_STACK_COLORATION */ } /* Initialize the initial exception register context structure */ diff --git a/arch/arm/src/common/arm_checkstack.c b/arch/arm/src/common/arm_checkstack.c index 5f9f41439f..b3b8f9b5ba 100644 --- a/arch/arm/src/common/arm_checkstack.c +++ b/arch/arm/src/common/arm_checkstack.c @@ -173,7 +173,8 @@ void arm_stack_color(FAR void *stackbase, size_t nbytes) /* Take extra care that we do not write outside the stack boundaries */ start = INT32_ALIGN_UP((uintptr_t)stackbase); - end = INT32_ALIGN_DOWN((uintptr_t)stackbase + nbytes); + end = nbytes ? INT32_ALIGN_DOWN((uintptr_t)stackbase + nbytes) : + up_getsp(); /* 0: colorize the running stack */ /* Get the adjusted size based on the top and bottom of the stack */ diff --git a/arch/avr/src/avr/up_initialstate.c b/arch/avr/src/avr/up_initialstate.c index 5135dc718e..19d14f6e90 100644 --- a/arch/avr/src/avr/up_initialstate.c +++ b/arch/avr/src/avr/up_initialstate.c @@ -61,9 +61,24 @@ void up_initial_state(struct tcb_s *tcb) if (tcb->pid == 0) { - tcb->stack_alloc_ptr = (void *)(g_idle_topstack - - CONFIG_IDLETHREAD_STACKSIZE); - tcb->stack_base_ptr = tcb->stack_alloc_ptr; + char *stack_ptr = (char *)(g_idle_topstack - + CONFIG_IDLETHREAD_STACKSIZE); +#ifdef CONFIG_STACK_COLORATION + char *stack_end = (char *)avr_getsp(); + + /* If stack debug is enabled, then fill the stack with a + * recognizable value that we can use later to test for high + * water marks. + */ + + while (stack_ptr < stack_end) + { + *--stack_end = STACK_COLOR; + } +#endif /* CONFIG_STACK_COLORATION */ + + tcb->stack_alloc_ptr = stack_ptr; + tcb->stack_base_ptr = stack_ptr; tcb->adj_stack_size = CONFIG_IDLETHREAD_STACKSIZE; } diff --git a/arch/avr/src/avr32/up_initialstate.c b/arch/avr/src/avr32/up_initialstate.c index eea5c8cca7..ee118ff2e0 100644 --- a/arch/avr/src/avr32/up_initialstate.c +++ b/arch/avr/src/avr32/up_initialstate.c @@ -58,9 +58,24 @@ void up_initial_state(struct tcb_s *tcb) if (tcb->pid == 0) { - tcb->stack_alloc_ptr = (void *)(g_idle_topstack - - CONFIG_IDLETHREAD_STACKSIZE); - tcb->stack_base_ptr = tcb->stack_alloc_ptr; + char *stack_ptr = (char *)(g_idle_topstack - + CONFIG_IDLETHREAD_STACKSIZE); +#ifdef CONFIG_STACK_COLORATION + char *stack_end = (char *)avr_getsp(); + + /* If stack debug is enabled, then fill the stack with a + * recognizable value that we can use later to test for high + * water marks. + */ + + while (stack_ptr < stack_end) + { + *--stack_end = STACK_COLOR; + } +#endif /* CONFIG_STACK_COLORATION */ + + tcb->stack_alloc_ptr = stack_ptr; + tcb->stack_base_ptr = stack_ptr; tcb->adj_stack_size = CONFIG_IDLETHREAD_STACKSIZE; } diff --git a/arch/hc/src/m9s12/m9s12_initialstate.c b/arch/hc/src/m9s12/m9s12_initialstate.c index 7cb6d69c45..d2ffa75d7f 100644 --- a/arch/hc/src/m9s12/m9s12_initialstate.c +++ b/arch/hc/src/m9s12/m9s12_initialstate.c @@ -58,9 +58,24 @@ void up_initial_state(struct tcb_s *tcb) if (tcb->pid == 0) { - tcb->stack_alloc_ptr = (void *)(g_idle_topstack - - CONFIG_IDLETHREAD_STACKSIZE); - tcb->stack_base_ptr = tcb->stack_alloc_ptr; + char *stack_ptr = (char *)(g_idle_topstack - + CONFIG_IDLETHREAD_STACKSIZE); +#ifdef CONFIG_STACK_COLORATION + char *stack_end = (char *)up_getsp(); + + /* If stack debug is enabled, then fill the stack with a + * recognizable value that we can use later to test for high + * water marks. + */ + + while (stack_ptr < stack_end) + { + *--stack_end = 0xaa; + } +#endif /* CONFIG_STACK_COLORATION */ + + tcb->stack_alloc_ptr = stack_ptr; + tcb->stack_base_ptr = stack_ptr; tcb->adj_stack_size = CONFIG_IDLETHREAD_STACKSIZE; } diff --git a/arch/mips/src/mips32/mips_initialstate.c b/arch/mips/src/mips32/mips_initialstate.c index 0a3d0c2cce..1c0d2f0812 100644 --- a/arch/mips/src/mips32/mips_initialstate.c +++ b/arch/mips/src/mips32/mips_initialstate.c @@ -62,9 +62,24 @@ void up_initial_state(struct tcb_s *tcb) if (tcb->pid == 0) { - tcb->stack_alloc_ptr = (void *)(g_idle_topstack - - CONFIG_IDLETHREAD_STACKSIZE); - tcb->stack_base_ptr = tcb->stack_alloc_ptr; + char *stack_ptr = (char *)(g_idle_topstack - + CONFIG_IDLETHREAD_STACKSIZE); +#ifdef CONFIG_STACK_COLORATION + char *stack_end = (char *)up_getsp(); + + /* If stack debug is enabled, then fill the stack with a + * recognizable value that we can use later to test for high + * water marks. + */ + + while (stack_ptr < stack_end) + { + *--stack_end = 0xaa; + } +#endif /* CONFIG_STACK_COLORATION */ + + tcb->stack_alloc_ptr = stack_ptr; + tcb->stack_base_ptr = stack_ptr; tcb->adj_stack_size = CONFIG_IDLETHREAD_STACKSIZE; } diff --git a/arch/misoc/src/lm32/lm32_initialstate.c b/arch/misoc/src/lm32/lm32_initialstate.c index cd79b6d9ba..da5a2281b3 100644 --- a/arch/misoc/src/lm32/lm32_initialstate.c +++ b/arch/misoc/src/lm32/lm32_initialstate.c @@ -59,9 +59,24 @@ void up_initial_state(struct tcb_s *tcb) if (tcb->pid == 0) { - tcb->stack_alloc_ptr = (void *)(g_idle_topstack - - CONFIG_IDLETHREAD_STACKSIZE); - tcb->stack_base_ptr = tcb->stack_alloc_ptr; + char *stack_ptr = (char *)(g_idle_topstack - + CONFIG_IDLETHREAD_STACKSIZE); +#ifdef CONFIG_STACK_COLORATION + char *stack_end = (char *)up_getsp(); + + /* If stack debug is enabled, then fill the stack with a + * recognizable value that we can use later to test for high + * water marks. + */ + + while (stack_ptr < stack_end) + { + *--stack_end = 0xaa; + } +#endif /* CONFIG_STACK_COLORATION */ + + tcb->stack_alloc_ptr = stack_ptr; + tcb->stack_base_ptr = stack_ptr; tcb->adj_stack_size = CONFIG_IDLETHREAD_STACKSIZE; } diff --git a/arch/misoc/src/minerva/minerva_initialstate.c b/arch/misoc/src/minerva/minerva_initialstate.c index a6ae5fa1d7..e0f5d974f2 100644 --- a/arch/misoc/src/minerva/minerva_initialstate.c +++ b/arch/misoc/src/minerva/minerva_initialstate.c @@ -63,9 +63,24 @@ void up_initial_state(struct tcb_s *tcb) if (tcb->pid == 0) { - tcb->stack_alloc_ptr = (void *)(g_idle_topstack - - CONFIG_IDLETHREAD_STACKSIZE); - tcb->stack_base_ptr = tcb->stack_alloc_ptr; + char *stack_ptr = (char *)(g_idle_topstack - + CONFIG_IDLETHREAD_STACKSIZE); +#ifdef CONFIG_STACK_COLORATION + char *stack_end = (char *)up_getsp(); + + /* If stack debug is enabled, then fill the stack with a + * recognizable value that we can use later to test for high + * water marks. + */ + + while (stack_ptr < stack_end) + { + *--stack_end = 0xaa; + } +#endif /* CONFIG_STACK_COLORATION */ + + tcb->stack_alloc_ptr = stack_ptr; + tcb->stack_base_ptr = stack_ptr; tcb->adj_stack_size = CONFIG_IDLETHREAD_STACKSIZE; } diff --git a/arch/or1k/src/common/up_createstack.c b/arch/or1k/src/common/up_createstack.c index 9a440ce6a4..8a921347a4 100644 --- a/arch/or1k/src/common/up_createstack.c +++ b/arch/or1k/src/common/up_createstack.c @@ -225,7 +225,8 @@ void up_stack_color(FAR void *stackbase, size_t nbytes) /* Take extra care that we do not write outsize the stack boundaries */ uint32_t *stkptr = (uint32_t *)(((uintptr_t)stackbase + 3) & ~3); - uintptr_t stkend = (((uintptr_t)stackbase + nbytes) & ~3); + uintptr_t stkend = nbytes ? (((uintptr_t)stackbase + nbytes) & ~3) : + up_getsp(); /* 0: colorize the running stack */ size_t nwords = (stkend - (uintptr_t)stackbase) >> 2; /* Set the entire stack to the coloration value */ diff --git a/arch/or1k/src/common/up_initialstate.c b/arch/or1k/src/common/up_initialstate.c index 28c9827d19..f45aeea1bf 100644 --- a/arch/or1k/src/common/up_initialstate.c +++ b/arch/or1k/src/common/up_initialstate.c @@ -79,8 +79,17 @@ void up_initial_state(struct tcb_s *tcb) { tcb->stack_alloc_ptr = (void *)(g_idle_topstack - CONFIG_IDLETHREAD_STACKSIZE); - tcb->stack_base_ptr = tcb->stack_alloc_ptr; + tcb->stack_base_ptr = tcb->stack_alloc_ptr; tcb->adj_stack_size = CONFIG_IDLETHREAD_STACKSIZE; + +#ifdef CONFIG_STACK_COLORATION + /* If stack debug is enabled, then fill the stack with a + * recognizable value that we can use later to test for high + * water marks. + */ + + up_stack_color(tcb->stack_alloc_ptr, 0); +#endif /* CONFIG_STACK_COLORATION */ } /* Initialize the initial exception register context structure */ diff --git a/arch/renesas/src/m16c/m16c_initialstate.c b/arch/renesas/src/m16c/m16c_initialstate.c index 5c88e0f91b..b3f172f460 100644 --- a/arch/renesas/src/m16c/m16c_initialstate.c +++ b/arch/renesas/src/m16c/m16c_initialstate.c @@ -60,9 +60,24 @@ void up_initial_state(FAR struct tcb_s *tcb) if (tcb->pid == 0) { - tcb->stack_alloc_ptr = (void *)(g_idle_topstack - - CONFIG_IDLETHREAD_STACKSIZE); - tcb->stack_base_ptr = tcb->stack_alloc_ptr; + char *stack_ptr = (char *)(g_idle_topstack - + CONFIG_IDLETHREAD_STACKSIZE); +#ifdef CONFIG_STACK_COLORATION + char *stack_end = (char *)up_getsp(); + + /* If stack debug is enabled, then fill the stack with a + * recognizable value that we can use later to test for high + * water marks. + */ + + while (stack_ptr < stack_end) + { + *--stack_end = 0xaa; + } +#endif /* CONFIG_STACK_COLORATION */ + + tcb->stack_alloc_ptr = stack_ptr; + tcb->stack_base_ptr = stack_ptr; tcb->adj_stack_size = CONFIG_IDLETHREAD_STACKSIZE; } diff --git a/arch/renesas/src/rx65n/rx65n_initialstate.c b/arch/renesas/src/rx65n/rx65n_initialstate.c index c6808b1fd1..62863f5de0 100644 --- a/arch/renesas/src/rx65n/rx65n_initialstate.c +++ b/arch/renesas/src/rx65n/rx65n_initialstate.c @@ -65,9 +65,24 @@ void up_initial_state(struct tcb_s *tcb) if (tcb->pid == 0) { - tcb->stack_alloc_ptr = (void *)(g_idle_topstack - - CONFIG_IDLETHREAD_STACKSIZE); - tcb->stack_base_ptr = tcb->stack_alloc_ptr; + char *stack_ptr = (char *)(g_idle_topstack - + CONFIG_IDLETHREAD_STACKSIZE); +#ifdef CONFIG_STACK_COLORATION + char *stack_end = (char *)up_getsp(); + + /* If stack debug is enabled, then fill the stack with a + * recognizable value that we can use later to test for high + * water marks. + */ + + while (stack_ptr < stack_end) + { + *--stack_end = 0xaa; + } +#endif /* CONFIG_STACK_COLORATION */ + + tcb->stack_alloc_ptr = stack_ptr; + tcb->stack_base_ptr = stack_ptr; tcb->adj_stack_size = CONFIG_IDLETHREAD_STACKSIZE; } diff --git a/arch/renesas/src/sh1/sh1_initialstate.c b/arch/renesas/src/sh1/sh1_initialstate.c index d52e09a71d..0e2444732f 100644 --- a/arch/renesas/src/sh1/sh1_initialstate.c +++ b/arch/renesas/src/sh1/sh1_initialstate.c @@ -77,9 +77,24 @@ void up_initial_state(struct tcb_s *tcb) if (tcb->pid == 0) { - tcb->stack_alloc_ptr = (void *)(g_idle_topstack - - CONFIG_IDLETHREAD_STACKSIZE); - tcb->stack_base_ptr = tcb->stack_alloc_ptr; + char *stack_ptr = (char *)(g_idle_topstack - + CONFIG_IDLETHREAD_STACKSIZE); +#ifdef CONFIG_STACK_COLORATION + char *stack_end = (char *)up_getsp(); + + /* If stack debug is enabled, then fill the stack with a + * recognizable value that we can use later to test for high + * water marks. + */ + + while (stack_ptr < stack_end) + { + *--stack_end = 0xaa; + } +#endif /* CONFIG_STACK_COLORATION */ + + tcb->stack_alloc_ptr = stack_ptr; + tcb->stack_base_ptr = stack_ptr; tcb->adj_stack_size = CONFIG_IDLETHREAD_STACKSIZE; } diff --git a/arch/risc-v/src/common/riscv_createstack.c b/arch/risc-v/src/common/riscv_createstack.c index 3e9858a338..51e5787a27 100644 --- a/arch/risc-v/src/common/riscv_createstack.c +++ b/arch/risc-v/src/common/riscv_createstack.c @@ -238,7 +238,8 @@ void riscv_stack_color(FAR void *stackbase, size_t nbytes) /* Take extra care that we do not write outsize the stack boundaries */ uint32_t *stkptr = (uint32_t *)(((uintptr_t)stackbase + 3) & ~3); - uintptr_t stkend = (((uintptr_t)stackbase + nbytes) & ~3); + uintptr_t stkend = nbytes ? (((uintptr_t)stackbase + nbytes) & ~3): + up_getsp(); /* 0: colorize the running stack */ size_t nwords = (stkend - (uintptr_t)stackbase) >> 2; /* Set the entire stack to the coloration value */ diff --git a/arch/risc-v/src/rv32im/riscv_initialstate.c b/arch/risc-v/src/rv32im/riscv_initialstate.c index 4106125070..55983a2474 100644 --- a/arch/risc-v/src/rv32im/riscv_initialstate.c +++ b/arch/risc-v/src/rv32im/riscv_initialstate.c @@ -63,8 +63,17 @@ void up_initial_state(struct tcb_s *tcb) { tcb->stack_alloc_ptr = (void *)(g_idle_topstack - CONFIG_IDLETHREAD_STACKSIZE); - tcb->stack_base_ptr = tcb->stack_alloc_ptr; + tcb->stack_base_ptr = tcb->stack_alloc_ptr; tcb->adj_stack_size = CONFIG_IDLETHREAD_STACKSIZE; + +#ifdef CONFIG_STACK_COLORATION + /* If stack debug is enabled, then fill the stack with a + * recognizable value that we can use later to test for high + * water marks. + */ + + riscv_stack_color(tcb->stack_alloc_ptr, 0); +#endif /* CONFIG_STACK_COLORATION */ } /* Initialize the initial exception register context structure */ diff --git a/arch/risc-v/src/rv64gc/riscv_initialstate.c b/arch/risc-v/src/rv64gc/riscv_initialstate.c index d20b187de8..6841300ffd 100644 --- a/arch/risc-v/src/rv64gc/riscv_initialstate.c +++ b/arch/risc-v/src/rv64gc/riscv_initialstate.c @@ -63,8 +63,17 @@ void up_initial_state(struct tcb_s *tcb) { tcb->stack_alloc_ptr = (void *)(g_idle_topstack - CONFIG_IDLETHREAD_STACKSIZE); - tcb->stack_base_ptr = tcb->stack_alloc_ptr; + tcb->stack_base_ptr = tcb->stack_alloc_ptr; tcb->adj_stack_size = CONFIG_IDLETHREAD_STACKSIZE; + +#ifdef CONFIG_STACK_COLORATION + /* If stack debug is enabled, then fill the stack with a + * recognizable value that we can use later to test for high + * water marks. + */ + + riscv_stack_color(tcb->stack_alloc_ptr, 0); +#endif /* CONFIG_STACK_COLORATION */ } /* Initialize the initial exception register context structure */ diff --git a/arch/sim/src/sim/up_createstack.c b/arch/sim/src/sim/up_createstack.c index a2e43df19f..b5f4ad6657 100644 --- a/arch/sim/src/sim/up_createstack.c +++ b/arch/sim/src/sim/up_createstack.c @@ -156,7 +156,8 @@ void up_stack_color(FAR void *stackbase, size_t nbytes) /* Take extra care that we do not write outsize the stack boundaries */ uint32_t *stkptr = (uint32_t *)(((uintptr_t)stackbase + 3) & ~3); - uintptr_t stkend = (((uintptr_t)stackbase + nbytes) & ~3); + uintptr_t stkend = nbytes ? (((uintptr_t)stackbase + nbytes) & ~3) : + up_getsp(); /* 0: colorize the running stack */ size_t nwords = (stkend - (uintptr_t)stackbase) >> 2; /* Set the entire stack to the coloration value */ diff --git a/arch/sim/src/sim/up_initialstate.c b/arch/sim/src/sim/up_initialstate.c index e1d7559ca3..1b11ebb050 100644 --- a/arch/sim/src/sim/up_initialstate.c +++ b/arch/sim/src/sim/up_initialstate.c @@ -55,8 +55,17 @@ void up_initial_state(struct tcb_s *tcb) { tcb->stack_alloc_ptr = (void *)(up_getsp() - CONFIG_IDLETHREAD_STACKSIZE); - tcb->stack_base_ptr = tcb->stack_alloc_ptr; + tcb->stack_base_ptr = tcb->stack_alloc_ptr; tcb->adj_stack_size = CONFIG_IDLETHREAD_STACKSIZE; + +#ifdef CONFIG_STACK_COLORATION + /* If stack debug is enabled, then fill the stack with a + * recognizable value that we can use later to test for high + * water marks. + */ + + up_stack_color(tcb->stack_alloc_ptr, 0); +#endif /* CONFIG_STACK_COLORATION */ } memset(&tcb->xcp, 0, sizeof(struct xcptcontext)); diff --git a/arch/x86/src/i486/up_initialstate.c b/arch/x86/src/i486/up_initialstate.c index fe40db4be6..407342b3a3 100644 --- a/arch/x86/src/i486/up_initialstate.c +++ b/arch/x86/src/i486/up_initialstate.c @@ -58,9 +58,24 @@ void up_initial_state(struct tcb_s *tcb) if (tcb->pid == 0) { - tcb->stack_alloc_ptr = (void *)(g_idle_topstack - - CONFIG_IDLETHREAD_STACKSIZE); - tcb->stack_base_ptr = tcb->stack_alloc_ptr; + char *stack_ptr = (char *)(g_idle_topstack - + CONFIG_IDLETHREAD_STACKSIZE); +#ifdef CONFIG_STACK_COLORATION + char *stack_end = (char *)up_getsp(); + + /* If stack debug is enabled, then fill the stack with a + * recognizable value that we can use later to test for high + * water marks. + */ + + while (stack_ptr < stack_end) + { + *--stack_end = 0xaa; + } +#endif /* CONFIG_STACK_COLORATION */ + + tcb->stack_alloc_ptr = stack_ptr; + tcb->stack_base_ptr = stack_ptr; tcb->adj_stack_size = CONFIG_IDLETHREAD_STACKSIZE; } diff --git a/arch/x86_64/src/intel64/up_initialstate.c b/arch/x86_64/src/intel64/up_initialstate.c index a517c04db1..ad66e54e57 100644 --- a/arch/x86_64/src/intel64/up_initialstate.c +++ b/arch/x86_64/src/intel64/up_initialstate.c @@ -59,9 +59,24 @@ void up_initial_state(struct tcb_s *tcb) if (tcb->pid == 0) { - tcb->stack_alloc_ptr = (void *)(g_idle_topstack - - CONFIG_IDLETHREAD_STACKSIZE); - tcb->stack_base_ptr = tcb->stack_alloc_ptr; + char *stack_ptr = (char *)(g_idle_topstack - + CONFIG_IDLETHREAD_STACKSIZE); +#ifdef CONFIG_STACK_COLORATION + char *stack_end = (char *)up_getsp(); + + /* If stack debug is enabled, then fill the stack with a + * recognizable value that we can use later to test for high + * water marks. + */ + + while (stack_ptr < stack_end) + { + *--stack_end = 0xaa; + } +#endif /* CONFIG_STACK_COLORATION */ + + tcb->stack_alloc_ptr = stack_ptr; + tcb->stack_base_ptr = stack_ptr; tcb->adj_stack_size = CONFIG_IDLETHREAD_STACKSIZE; } diff --git a/arch/xtensa/src/common/xtensa_createstack.c b/arch/xtensa/src/common/xtensa_createstack.c index 0a75b45e7e..95dd462c0e 100644 --- a/arch/xtensa/src/common/xtensa_createstack.c +++ b/arch/xtensa/src/common/xtensa_createstack.c @@ -280,7 +280,8 @@ void up_stack_color(FAR void *stackbase, size_t nbytes) /* Take extra care that we do not write outside the stack boundaries */ start = STACK_ALIGN_UP((uintptr_t)stackbase); - end = STACK_ALIGN_DOWN((uintptr_t)stackbase + nbytes); + end = nbytes ? STACK_ALIGN_DOWN((uintptr_t)stackbase + nbytes) : + up_getsp(); /* 0: colorize the running stack */ /* Get the adjusted size based on the top and bottom of the stack */ diff --git a/arch/xtensa/src/common/xtensa_initialstate.c b/arch/xtensa/src/common/xtensa_initialstate.c index 772ad0e9eb..f106a62823 100644 --- a/arch/xtensa/src/common/xtensa_initialstate.c +++ b/arch/xtensa/src/common/xtensa_initialstate.c @@ -63,8 +63,17 @@ void up_initial_state(struct tcb_s *tcb) if (tcb->pid == 0) { tcb->stack_alloc_ptr = g_idlestack; - tcb->stack_base_ptr = tcb->stack_alloc_ptr; + tcb->stack_base_ptr = tcb->stack_alloc_ptr; tcb->adj_stack_size = CONFIG_IDLETHREAD_STACKSIZE; + +#ifdef CONFIG_STACK_COLORATION + /* If stack debug is enabled, then fill the stack with a + * recognizable value that we can use later to test for high + * water marks. + */ + + up_stack_color(tcb->stack_alloc_ptr, 0); +#endif /* CONFIG_STACK_COLORATION */ } /* Initialize the initial exception register context structure */ diff --git a/arch/z80/src/z180/z180_initialstate.c b/arch/z80/src/z180/z180_initialstate.c index f05ce92d27..029286b0d8 100644 --- a/arch/z80/src/z180/z180_initialstate.c +++ b/arch/z80/src/z180/z180_initialstate.c @@ -57,8 +57,23 @@ void up_initial_state(struct tcb_s *tcb) if (tcb->pid == 0) { - tcb->stack_alloc_ptr = (void *)CONFIG_STACK_BASE; - tcb->stack_base_ptr = tcb->stack_alloc_ptr; + char *stack_ptr = (char *)CONFIG_STACK_BASE; +#ifdef CONFIG_STACK_COLORATION + char *stack_end = (char *)up_getsp(); + + /* If stack debug is enabled, then fill the stack with a + * recognizable value that we can use later to test for high + * water marks. + */ + + while (stack_ptr < stack_end) + { + *--stack_end = 0xaa; + } +#endif /* CONFIG_STACK_COLORATION */ + + tcb->stack_alloc_ptr = stack_ptr; + tcb->stack_base_ptr = stack_ptr; tcb->adj_stack_size = CONFIG_IDLETHREAD_STACKSIZE; } diff --git a/arch/z80/src/z80/z80_initialstate.c b/arch/z80/src/z80/z80_initialstate.c index 9b24a6524b..0d743eb430 100644 --- a/arch/z80/src/z80/z80_initialstate.c +++ b/arch/z80/src/z80/z80_initialstate.c @@ -57,8 +57,23 @@ void up_initial_state(struct tcb_s *tcb) if (tcb->pid == 0) { - tcb->stack_alloc_ptr = (void *)CONFIG_STACK_BASE; - tcb->stack_base_ptr = tcb->stack_alloc_ptr; + char *stack_ptr = (char *)CONFIG_STACK_BASE; +#ifdef CONFIG_STACK_COLORATION + char *stack_end = (char *)up_getsp(); + + /* If stack debug is enabled, then fill the stack with a + * recognizable value that we can use later to test for high + * water marks. + */ + + while (stack_ptr < stack_end) + { + *--stack_end = 0xaa; + } +#endif /* CONFIG_STACK_COLORATION */ + + tcb->stack_alloc_ptr = stack_ptr; + tcb->stack_base_ptr = stack_ptr; tcb->adj_stack_size = CONFIG_IDLETHREAD_STACKSIZE; }