kernel/stack: Introduce K_THREAD_STACK_LEN macro
This is a public macro which calculates the size to be allocated for stacks inside a stack array. This is necessitated because of some internal padding (e.g. for MPU scenarios). This is particularly useful when a reference to K_THREAD_STACK_ARRAY_DEFINE needs to be made from within a struct. Signed-off-by: Rajavardhan Gundi <rajavardhan.gundi@intel.com>
This commit is contained in:
parent
9e97e5b5fd
commit
d4dd928eaa
4 changed files with 53 additions and 12 deletions
|
@ -153,6 +153,23 @@ extern "C" {
|
|||
sym[size+MPU_GUARD_ALIGN_AND_SIZE]
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Calculate size of stacks to be allocated in a stack array
|
||||
*
|
||||
* This macro calculates the size to be allocated for the stacks
|
||||
* inside a stack array. It accepts the indicated "size" as a parameter
|
||||
* and if required, pads some extra bytes (e.g. for MPU scenarios). Refer
|
||||
* K_THREAD_STACK_ARRAY_DEFINE definition to see how this is used.
|
||||
*
|
||||
* @param size Size of the stack memory region
|
||||
*/
|
||||
#if defined(CONFIG_USERSPACE) && \
|
||||
defined(CONFIG_MPU_REQUIRES_POWER_OF_TWO_ALIGNMENT)
|
||||
#define _ARCH_THREAD_STACK_LEN(size) (POW2_CEIL(size))
|
||||
#else
|
||||
#define _ARCH_THREAD_STACK_LEN(size) ((size)+MPU_GUARD_ALIGN_AND_SIZE)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Declare a toplevel array of thread stack memory regions
|
||||
*
|
||||
|
@ -171,12 +188,12 @@ extern "C" {
|
|||
#define _ARCH_THREAD_STACK_ARRAY_DEFINE(sym, nmemb, size) \
|
||||
struct _k_thread_stack_element __kernel_noinit \
|
||||
__aligned(POW2_CEIL(size)) \
|
||||
sym[nmemb][POW2_CEIL(size)]
|
||||
sym[nmemb][_ARCH_THREAD_STACK_LEN(size)]
|
||||
#else
|
||||
#define _ARCH_THREAD_STACK_ARRAY_DEFINE(sym, nmemb, size) \
|
||||
struct _k_thread_stack_element __kernel_noinit \
|
||||
__aligned(STACK_ALIGN) \
|
||||
sym[nmemb][size+MPU_GUARD_ALIGN_AND_SIZE]
|
||||
sym[nmemb][_ARCH_THREAD_STACK_LEN(size)]
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue