| 80 | ****************************************************************************/ |
| 81 | |
| 82 | int up_create_stack(struct tcb_s *tcb, size_t stack_size, uint8_t ttype) |
| 83 | { |
| 84 | stack_size += CONFIG_SIM_STACKSIZE_ADJUSTMENT; |
| 85 | |
| 86 | #ifdef CONFIG_TLS_ALIGNED |
| 87 | /* The allocated stack size must not exceed the maximum possible for the |
| 88 | * TLS feature. |
| 89 | */ |
| 90 | |
| 91 | DEBUGASSERT(stack_size <= TLS_MAXSTACK); |
| 92 | if (stack_size >= TLS_MAXSTACK) |
| 93 | { |
| 94 | stack_size = TLS_MAXSTACK; |
| 95 | } |
| 96 | #endif |
| 97 | |
| 98 | /* Is there already a stack allocated of a different size? Because of |
| 99 | * alignment issues, stack_size might erroneously appear to be of a |
| 100 | * different size. Fortunately, this is not a critical operation. |
| 101 | */ |
| 102 | |
| 103 | if (tcb->stack_alloc_ptr && tcb->adj_stack_size != stack_size) |
| 104 | { |
| 105 | /* Yes.. Release the old stack */ |
| 106 | |
| 107 | up_release_stack(tcb, ttype); |
| 108 | } |
| 109 | |
| 110 | /* Do we need to allocate a new stack? */ |
| 111 | |
| 112 | if (!tcb->stack_alloc_ptr) |
| 113 | { |
| 114 | /* Allocate the stack. If DEBUG is enabled (but not stack debug), |
| 115 | * then create a zeroed stack to make stack dumps easier to trace. |
| 116 | * If TLS is enabled, then we must allocate aligned stacks. |
| 117 | */ |
| 118 | |
| 119 | #ifdef CONFIG_TLS_ALIGNED |
| 120 | tcb->stack_alloc_ptr = kumm_memalign(TLS_STACK_ALIGN, stack_size); |
| 121 | #else |
| 122 | tcb->stack_alloc_ptr = kumm_malloc(stack_size); |
| 123 | #endif |
| 124 | } |
| 125 | |
| 126 | /* Did we successfully allocate a stack? */ |
| 127 | |
| 128 | if (tcb->stack_alloc_ptr) |
| 129 | { |
| 130 | uintptr_t top_of_stack; |
| 131 | size_t size_of_stack; |
| 132 | |
| 133 | top_of_stack = (uintptr_t)tcb->stack_alloc_ptr + stack_size; |
| 134 | top_of_stack = STACKFRAME_ALIGN_DOWN(top_of_stack); |
| 135 | size_of_stack = top_of_stack - (uintptr_t)tcb->stack_alloc_ptr; |
| 136 | |
| 137 | /* Save the values in the TCB */ |
| 138 | |
| 139 | tcb->stack_base_ptr = tcb->stack_alloc_ptr; |
no test coverage detected