| 68 | ****************************************************************************/ |
| 69 | |
| 70 | void *up_stack_frame(struct tcb_s *tcb, size_t frame_size) |
| 71 | { |
| 72 | void *ret; |
| 73 | |
| 74 | /* Align the frame_size */ |
| 75 | |
| 76 | frame_size = STACKFRAME_ALIGN_UP(frame_size); |
| 77 | |
| 78 | /* Is there already a stack allocated? Is it big enough? */ |
| 79 | |
| 80 | if (!tcb->stack_alloc_ptr || tcb->adj_stack_size < frame_size) |
| 81 | { |
| 82 | return NULL; |
| 83 | } |
| 84 | |
| 85 | /* Save the adjusted stack values in the struct tcb_s */ |
| 86 | |
| 87 | ret = tcb->stack_base_ptr; |
| 88 | memset(ret, 0, frame_size); |
| 89 | |
| 90 | /* Save the adjusted stack values in the struct tcb_s */ |
| 91 | |
| 92 | tcb->stack_base_ptr = (uint8_t *)tcb->stack_base_ptr + frame_size; |
| 93 | tcb->adj_stack_size -= frame_size; |
| 94 | |
| 95 | /* And return the pointer to the allocated region */ |
| 96 | |
| 97 | return ret; |
| 98 | } |