Skip to content

Commit b4c455c

Browse files
dcpleungnashif
authored andcommitted
arch: add interface to get stack space of privileged stack
This adds a new arch_thread_priv_stack_space_get() interface for each architecture to report privileged stack space usage. Each architecture will need to implement this function as each arch has their own way of defining privileged stacks. Signed-off-by: Daniel Leung <[email protected]>
1 parent 2b9ce2e commit b4c455c

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

arch/Kconfig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,11 @@ config ARCH_SUPPORTS_MEM_MAPPED_STACKS
700700
help
701701
Select when the architecture supports memory mapped stacks.
702702

703+
config ARCH_HAS_THREAD_PRIV_STACK_SPACE_GET
704+
bool
705+
help
706+
Select when the architecture implements arch_thread_priv_stack_space_get().
707+
703708
#
704709
# Other architecture related options
705710
#

kernel/include/kernel_arch_interface.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,34 @@ int arch_float_disable(struct k_thread *thread);
208208
int arch_float_enable(struct k_thread *thread, unsigned int options);
209209
#endif /* CONFIG_FPU && CONFIG_FPU_SHARING */
210210

211+
#if defined(CONFIG_USERSPACE) && defined(CONFIG_ARCH_HAS_THREAD_PRIV_STACK_SPACE_GET)
212+
/**
213+
* @brief Obtain privileged stack usage information for the specified thread
214+
*
215+
* Must be called under supervisor mode.
216+
*
217+
* Some hardware may prevent inspection of a stack buffer currently in use.
218+
* If this API is called from supervisor mode, on the currently running thread,
219+
* on a platform which selects @kconfig{CONFIG_NO_UNUSED_STACK_INSPECTION}, an
220+
* error will be generated.
221+
*
222+
* @param[in] thread Thread to inspect stack information
223+
* @param[out] stack_size Filled in with the size of the stack space of
224+
* the target thread in bytes.
225+
* @param[out] unused_ptr Filled in with the unused stack space of
226+
* the target thread in bytes.
227+
*
228+
* @return 0 on success
229+
* @return -EBADF Bad thread object
230+
* @return -EPERM No permissions on thread object
231+
* #return -ENOTSUP Forbidden by hardware policy
232+
* @return -EINVAL Thread is uninitialized or exited or not a user thread
233+
* @return -EFAULT Bad memory address for unused_ptr
234+
*/
235+
int arch_thread_priv_stack_space_get(const struct k_thread *thread, size_t *stack_size,
236+
size_t *unused_ptr);
237+
#endif /* CONFIG_USERSPACE && CONFIG_ARCH_HAS_THREAD_PRIV_STACK_SPACE_GET */
238+
211239
/** @} */
212240

213241
/**

0 commit comments

Comments
 (0)