21#ifndef ZEPHYR_INCLUDE_KERNEL_THREAD_STACK_H
22#define ZEPHYR_INCLUDE_KERNEL_THREAD_STACK_H
24#if !defined(_ASMLANGUAGE)
47struct __packed z_thread_stack_element {
69static inline char *z_stack_ptr_align(
char *ptr)
73#define Z_STACK_PTR_ALIGN(ptr) ((uintptr_t)z_stack_ptr_align((char *)(ptr)))
88#define Z_STACK_PTR_TO_FRAME(type, ptr) \
89 (type *)((ptr) - sizeof(type))
91#ifdef ARCH_KERNEL_STACK_RESERVED
92#define K_KERNEL_STACK_RESERVED ((size_t)ARCH_KERNEL_STACK_RESERVED)
94#define K_KERNEL_STACK_RESERVED ((size_t)0)
97#define Z_KERNEL_STACK_SIZE_ADJUST(size) (ROUND_UP(size, \
98 ARCH_STACK_PTR_ALIGN) + \
99 K_KERNEL_STACK_RESERVED)
101#ifdef ARCH_KERNEL_STACK_OBJ_ALIGN
102#define Z_KERNEL_STACK_OBJ_ALIGN ARCH_KERNEL_STACK_OBJ_ALIGN
104#define Z_KERNEL_STACK_OBJ_ALIGN ARCH_STACK_PTR_ALIGN
107#define K_KERNEL_STACK_LEN(size) \
108 ROUND_UP(Z_KERNEL_STACK_SIZE_ADJUST(size), Z_KERNEL_STACK_OBJ_ALIGN)
124#define K_KERNEL_STACK_DECLARE(sym, size) \
125 extern struct z_thread_stack_element \
126 sym[K_KERNEL_STACK_LEN(size)]
138#define K_KERNEL_STACK_ARRAY_DECLARE(sym, nmemb, size) \
139 extern struct z_thread_stack_element \
140 sym[nmemb][K_KERNEL_STACK_LEN(size)]
152#define K_KERNEL_PINNED_STACK_ARRAY_DECLARE(sym, nmemb, size) \
153 extern struct z_thread_stack_element \
154 sym[nmemb][K_KERNEL_STACK_LEN(size)]
175#define Z_KERNEL_STACK_DEFINE_IN(sym, size, lsect) \
176 struct z_thread_stack_element lsect \
177 __aligned(Z_KERNEL_STACK_OBJ_ALIGN) \
178 sym[K_KERNEL_STACK_LEN(size)]
188#define Z_KERNEL_STACK_ARRAY_DEFINE_IN(sym, nmemb, size, lsect) \
189 struct z_thread_stack_element lsect \
190 __aligned(Z_KERNEL_STACK_OBJ_ALIGN) \
191 sym[nmemb][K_KERNEL_STACK_LEN(size)]
214#define K_KERNEL_STACK_DEFINE(sym, size) \
215 Z_KERNEL_STACK_DEFINE_IN(sym, size, __kstackmem)
229#if defined(CONFIG_LINKER_USE_PINNED_SECTION)
230#define K_KERNEL_PINNED_STACK_DEFINE(sym, size) \
231 Z_KERNEL_STACK_DEFINE_IN(sym, size, __pinned_noinit)
233#define K_KERNEL_PINNED_STACK_DEFINE(sym, size) \
234 Z_KERNEL_STACK_DEFINE_IN(sym, size, __kstackmem)
246#define K_KERNEL_STACK_ARRAY_DEFINE(sym, nmemb, size) \
247 Z_KERNEL_STACK_ARRAY_DEFINE_IN(sym, nmemb, size, __kstackmem)
262#if defined(CONFIG_LINKER_USE_PINNED_SECTION)
263#define K_KERNEL_PINNED_STACK_ARRAY_DEFINE(sym, nmemb, size) \
264 Z_KERNEL_STACK_ARRAY_DEFINE_IN(sym, nmemb, size, __pinned_noinit)
266#define K_KERNEL_PINNED_STACK_ARRAY_DEFINE(sym, nmemb, size) \
267 Z_KERNEL_STACK_ARRAY_DEFINE_IN(sym, nmemb, size, __kstackmem)
279#define K_KERNEL_STACK_MEMBER(sym, size) \
280 Z_KERNEL_STACK_DEFINE_IN(sym, size,)
282#define K_KERNEL_STACK_SIZEOF(sym) (sizeof(sym) - K_KERNEL_STACK_RESERVED)
290#ifndef CONFIG_USERSPACE
291#define K_THREAD_STACK_RESERVED K_KERNEL_STACK_RESERVED
292#define K_THREAD_STACK_SIZEOF K_KERNEL_STACK_SIZEOF
293#define K_THREAD_STACK_LEN K_KERNEL_STACK_LEN
294#define K_THREAD_STACK_DEFINE K_KERNEL_STACK_DEFINE
295#define K_THREAD_STACK_ARRAY_DEFINE K_KERNEL_STACK_ARRAY_DEFINE
296#define K_THREAD_STACK_BUFFER K_KERNEL_STACK_BUFFER
297#define K_THREAD_STACK_DECLARE K_KERNEL_STACK_DECLARE
298#define K_THREAD_STACK_ARRAY_DECLARE K_KERNEL_STACK_ARRAY_DECLARE
299#define K_THREAD_PINNED_STACK_DEFINE K_KERNEL_PINNED_STACK_DEFINE
300#define K_THREAD_PINNED_STACK_ARRAY_DEFINE \
301 K_KERNEL_PINNED_STACK_ARRAY_DEFINE
318#ifdef ARCH_THREAD_STACK_RESERVED
319#define K_THREAD_STACK_RESERVED ((size_t)(ARCH_THREAD_STACK_RESERVED))
321#define K_THREAD_STACK_RESERVED ((size_t)0U)
349#if defined(ARCH_THREAD_STACK_OBJ_ALIGN)
350#define Z_THREAD_STACK_OBJ_ALIGN(size) \
351 ARCH_THREAD_STACK_OBJ_ALIGN(Z_THREAD_STACK_SIZE_ADJUST(size))
353#define Z_THREAD_STACK_OBJ_ALIGN(size) ARCH_STACK_PTR_ALIGN
382#if defined(ARCH_THREAD_STACK_SIZE_ADJUST)
383#define Z_THREAD_STACK_SIZE_ADJUST(size) \
384 ARCH_THREAD_STACK_SIZE_ADJUST((size) + K_THREAD_STACK_RESERVED)
386#define Z_THREAD_STACK_SIZE_ADJUST(size) \
387 (ROUND_UP((size), ARCH_STACK_PTR_ALIGN) + K_THREAD_STACK_RESERVED)
404#define K_THREAD_STACK_DECLARE(sym, size) \
405 extern struct z_thread_stack_element \
406 sym[K_THREAD_STACK_LEN(size)]
418#define K_THREAD_STACK_ARRAY_DECLARE(sym, nmemb, size) \
419 extern struct z_thread_stack_element \
420 sym[nmemb][K_THREAD_STACK_LEN(size)]
436#define K_THREAD_STACK_SIZEOF(sym) (sizeof(sym) - K_THREAD_STACK_RESERVED)
466#define Z_THREAD_STACK_DEFINE_IN(sym, size, lsect) \
467 struct z_thread_stack_element lsect \
468 __aligned(Z_THREAD_STACK_OBJ_ALIGN(size)) \
469 sym[K_THREAD_STACK_LEN(size)]
485#define Z_THREAD_STACK_ARRAY_DEFINE_IN(sym, nmemb, size, lsect) \
486 struct z_thread_stack_element lsect \
487 __aligned(Z_THREAD_STACK_OBJ_ALIGN(size)) \
488 sym[nmemb][K_THREAD_STACK_LEN(size)]
516#define K_THREAD_STACK_DEFINE(sym, size) \
517 Z_THREAD_STACK_DEFINE_IN(sym, size, __stackmem)
549#if defined(CONFIG_LINKER_USE_PINNED_SECTION)
550#define K_THREAD_PINNED_STACK_DEFINE(sym, size) \
551 Z_THREAD_STACK_DEFINE_IN(sym, size, __pinned_noinit)
553#define K_THREAD_PINNED_STACK_DEFINE(sym, size) \
554 K_THREAD_STACK_DEFINE(sym, size)
570#define K_THREAD_STACK_LEN(size) \
571 ROUND_UP(Z_THREAD_STACK_SIZE_ADJUST(size), \
572 Z_THREAD_STACK_OBJ_ALIGN(size))
587#define K_THREAD_STACK_ARRAY_DEFINE(sym, nmemb, size) \
588 Z_THREAD_STACK_ARRAY_DEFINE_IN(sym, nmemb, size, __stackmem)
607#if defined(CONFIG_LINKER_USE_PINNED_SECTION)
608#define K_THREAD_PINNED_STACK_ARRAY_DEFINE(sym, nmemb, size) \
609 Z_THREAD_PINNED_STACK_DEFINE_IN(sym, nmemb, size, __pinned_noinit)
611#define K_THREAD_PINNED_STACK_ARRAY_DEFINE(sym, nmemb, size) \
612 K_THREAD_STACK_ARRAY_DEFINE(sym, nmemb, size)
#define ARCH_STACK_PTR_ALIGN
Definition arch.h:98
struct z_thread_stack_element k_thread_stack_t
Typedef of struct z_thread_stack_element.
Definition arch_interface.h:46
#define ROUND_DOWN(x, align)
Value of x rounded down to the previous multiple of align.
Definition util.h:329
#define K_THREAD_STACK_RESERVED
Indicate how much additional memory is reserved for stack objects.
Definition thread_stack.h:321
static char * K_THREAD_STACK_BUFFER(k_thread_stack_t *sym)
Get a pointer to the physical stack buffer.
Definition thread_stack.h:631
static char * K_KERNEL_STACK_BUFFER(k_thread_stack_t *sym)
Definition thread_stack.h:286
#define K_KERNEL_STACK_RESERVED
Definition thread_stack.h:94