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_MEMBER K_KERNEL_STACK_MEMBER
297#define K_THREAD_STACK_BUFFER K_KERNEL_STACK_BUFFER
298#define K_THREAD_STACK_DECLARE K_KERNEL_STACK_DECLARE
299#define K_THREAD_STACK_ARRAY_DECLARE K_KERNEL_STACK_ARRAY_DECLARE
300#define K_THREAD_PINNED_STACK_DEFINE K_KERNEL_PINNED_STACK_DEFINE
301#define K_THREAD_PINNED_STACK_ARRAY_DEFINE \
302 K_KERNEL_PINNED_STACK_ARRAY_DEFINE
319#ifdef ARCH_THREAD_STACK_RESERVED
320#define K_THREAD_STACK_RESERVED ((size_t)(ARCH_THREAD_STACK_RESERVED))
322#define K_THREAD_STACK_RESERVED ((size_t)0U)
350#if defined(ARCH_THREAD_STACK_OBJ_ALIGN)
351#define Z_THREAD_STACK_OBJ_ALIGN(size) \
352 ARCH_THREAD_STACK_OBJ_ALIGN(Z_THREAD_STACK_SIZE_ADJUST(size))
354#define Z_THREAD_STACK_OBJ_ALIGN(size) ARCH_STACK_PTR_ALIGN
383#if defined(ARCH_THREAD_STACK_SIZE_ADJUST)
384#define Z_THREAD_STACK_SIZE_ADJUST(size) \
385 ARCH_THREAD_STACK_SIZE_ADJUST((size) + K_THREAD_STACK_RESERVED)
387#define Z_THREAD_STACK_SIZE_ADJUST(size) \
388 (ROUND_UP((size), ARCH_STACK_PTR_ALIGN) + K_THREAD_STACK_RESERVED)
405#define K_THREAD_STACK_DECLARE(sym, size) \
406 extern struct z_thread_stack_element \
407 sym[K_THREAD_STACK_LEN(size)]
419#define K_THREAD_STACK_ARRAY_DECLARE(sym, nmemb, size) \
420 extern struct z_thread_stack_element \
421 sym[nmemb][K_THREAD_STACK_LEN(size)]
437#define K_THREAD_STACK_SIZEOF(sym) (sizeof(sym) - K_THREAD_STACK_RESERVED)
467#define Z_THREAD_STACK_DEFINE_IN(sym, size, lsect) \
468 struct z_thread_stack_element lsect \
469 __aligned(Z_THREAD_STACK_OBJ_ALIGN(size)) \
470 sym[K_THREAD_STACK_LEN(size)]
486#define Z_THREAD_STACK_ARRAY_DEFINE_IN(sym, nmemb, size, lsect) \
487 struct z_thread_stack_element lsect \
488 __aligned(Z_THREAD_STACK_OBJ_ALIGN(size)) \
489 sym[nmemb][K_THREAD_STACK_LEN(size)]
517#define K_THREAD_STACK_DEFINE(sym, size) \
518 Z_THREAD_STACK_DEFINE_IN(sym, size, __stackmem)
550#if defined(CONFIG_LINKER_USE_PINNED_SECTION)
551#define K_THREAD_PINNED_STACK_DEFINE(sym, size) \
552 Z_THREAD_STACK_DEFINE_IN(sym, size, __pinned_noinit)
554#define K_THREAD_PINNED_STACK_DEFINE(sym, size) \
555 K_THREAD_STACK_DEFINE(sym, size)
571#define K_THREAD_STACK_LEN(size) \
572 ROUND_UP(Z_THREAD_STACK_SIZE_ADJUST(size), \
573 Z_THREAD_STACK_OBJ_ALIGN(size))
588#define K_THREAD_STACK_ARRAY_DEFINE(sym, nmemb, size) \
589 Z_THREAD_STACK_ARRAY_DEFINE_IN(sym, nmemb, size, __stackmem)
608#if defined(CONFIG_LINKER_USE_PINNED_SECTION)
609#define K_THREAD_PINNED_STACK_ARRAY_DEFINE(sym, nmemb, size) \
610 Z_THREAD_PINNED_STACK_DEFINE_IN(sym, nmemb, size, __pinned_noinit)
612#define K_THREAD_PINNED_STACK_ARRAY_DEFINE(sym, nmemb, size) \
613 K_THREAD_STACK_ARRAY_DEFINE(sym, nmemb, size)
634#define K_THREAD_STACK_MEMBER(sym, size) __DEPRECATED_MACRO \
635 Z_THREAD_STACK_DEFINE_IN(sym, 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:45
#define ROUND_DOWN(x, align)
Value of x rounded down to the previous multiple of align.
Definition: util.h:313
#define K_THREAD_STACK_RESERVED
Indicate how much additional memory is reserved for stack objects.
Definition: thread_stack.h:322
static char * K_THREAD_STACK_BUFFER(k_thread_stack_t *sym)
Get a pointer to the physical stack buffer.
Definition: thread_stack.h:653
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