Lines Matching +full:stack +full:- +full:size

4  * SPDX-License-Identifier: Apache-2.0
27 k_thread_stack_t *stack; member
34 static k_thread_stack_t *z_thread_stack_alloc_pool(size_t size) in z_thread_stack_alloc_pool() argument
38 k_thread_stack_t *stack; in z_thread_stack_alloc_pool() local
40 if (size > CONFIG_DYNAMIC_THREAD_STACK_SIZE) { in z_thread_stack_alloc_pool()
41 LOG_DBG("stack size %zu is > pool stack size %d", size, in z_thread_stack_alloc_pool()
48 LOG_DBG("unable to allocate stack from pool"); in z_thread_stack_alloc_pool()
54 stack = (k_thread_stack_t *)&dynamic_stack[offset]; in z_thread_stack_alloc_pool()
56 return stack; in z_thread_stack_alloc_pool()
59 static k_thread_stack_t *z_thread_stack_alloc_dyn(size_t size, int flags) in z_thread_stack_alloc_dyn() argument
63 return k_object_alloc_size(K_OBJ_THREAD_STACK_ELEMENT, size); in z_thread_stack_alloc_dyn()
65 /* Dynamic user stack needs a kobject, so if this option is not in z_thread_stack_alloc_dyn()
72 return z_thread_aligned_alloc(Z_KERNEL_STACK_OBJ_ALIGN, K_KERNEL_STACK_LEN(size)); in z_thread_stack_alloc_dyn()
75 k_thread_stack_t *z_impl_k_thread_stack_alloc(size_t size, int flags) in z_impl_k_thread_stack_alloc() argument
77 k_thread_stack_t *stack = NULL; in z_impl_k_thread_stack_alloc() local
80 stack = z_thread_stack_alloc_dyn(size, flags); in z_impl_k_thread_stack_alloc()
81 if (stack == NULL && CONFIG_DYNAMIC_THREAD_POOL_SIZE > 0) { in z_impl_k_thread_stack_alloc()
82 stack = z_thread_stack_alloc_pool(size); in z_impl_k_thread_stack_alloc()
86 stack = z_thread_stack_alloc_pool(size); in z_impl_k_thread_stack_alloc()
89 if ((stack == NULL) && IS_ENABLED(CONFIG_DYNAMIC_THREAD_ALLOC)) { in z_impl_k_thread_stack_alloc()
90 stack = z_thread_stack_alloc_dyn(size, flags); in z_impl_k_thread_stack_alloc()
94 return stack; in z_impl_k_thread_stack_alloc()
98 static inline k_thread_stack_t *z_vrfy_k_thread_stack_alloc(size_t size, int flags) in z_vrfy_k_thread_stack_alloc() argument
100 return z_impl_k_thread_stack_alloc(size, flags); in z_vrfy_k_thread_stack_alloc()
109 if (data->stack == (k_thread_stack_t *)thread->stack_info.start) { in dyn_cb()
110 __ASSERT(data->tid == NULL, "stack %p is associated with more than one thread!", in dyn_cb()
111 (void *)thread->stack_info.start); in dyn_cb()
112 data->tid = (k_tid_t)thread; in dyn_cb()
116 int z_impl_k_thread_stack_free(k_thread_stack_t *stack) in z_impl_k_thread_stack_free() argument
118 struct dyn_cb_data data = {.stack = stack}; in z_impl_k_thread_stack_free()
120 /* Get a possible tid associated with stack */ in z_impl_k_thread_stack_free()
127 return -EBUSY; in z_impl_k_thread_stack_free()
132 if (IS_ARRAY_ELEMENT(dynamic_stack, stack)) { in z_impl_k_thread_stack_free()
133 if (sys_bitarray_free(&dynamic_ba, 1, ARRAY_INDEX(dynamic_stack, stack))) { in z_impl_k_thread_stack_free()
134 LOG_ERR("stack %p is not allocated!", stack); in z_impl_k_thread_stack_free()
135 return -EINVAL; in z_impl_k_thread_stack_free()
144 if (k_object_find(stack)) { in z_impl_k_thread_stack_free()
145 k_object_free(stack); in z_impl_k_thread_stack_free()
147 k_free(stack); in z_impl_k_thread_stack_free()
150 k_free(stack); in z_impl_k_thread_stack_free()
153 LOG_DBG("Invalid stack %p", stack); in z_impl_k_thread_stack_free()
154 return -EINVAL; in z_impl_k_thread_stack_free()
161 static inline int z_vrfy_k_thread_stack_free(k_thread_stack_t *stack) in z_vrfy_k_thread_stack_free() argument
163 /* The thread stack object must not be in initialized state. in z_vrfy_k_thread_stack_free()
165 * Thread stack objects are initialized when the thread is created in z_vrfy_k_thread_stack_free()
166 * and de-initialized when the thread is destroyed. Since we can't in z_vrfy_k_thread_stack_free()
167 * free a stack that is in use, we have to check that the caller in z_vrfy_k_thread_stack_free()
170 K_OOPS(K_SYSCALL_OBJ_NEVER_INIT(stack, K_OBJ_THREAD_STACK_ELEMENT)); in z_vrfy_k_thread_stack_free()
172 return z_impl_k_thread_stack_free(stack); in z_vrfy_k_thread_stack_free()