Skip to content

Commit

Permalink
riscv: implements arch_thread_priv_stack_space_get
Browse files Browse the repository at this point in the history
This implements arch_thread_priv_stack_space_get() so this can
be used to figure out how much privileged stack space is used.

Signed-off-by: Daniel Leung <[email protected]>
  • Loading branch information
dcpleung authored and nashif committed Aug 28, 2024
1 parent bb31335 commit 0962114
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions arch/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ config RISCV
select SCHED_IPI_SUPPORTED if SMP
select ARCH_HAS_DIRECTED_IPIS
select BARRIER_OPERATIONS_BUILTIN
select ARCH_HAS_THREAD_PRIV_STACK_SPACE_GET if USERSPACE
imply XIP
help
RISCV architecture
Expand Down
12 changes: 12 additions & 0 deletions arch/riscv/core/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,18 @@ FUNC_NORETURN void arch_user_mode_enter(k_thread_entry_t user_entry,
CODE_UNREACHABLE;
}

int arch_thread_priv_stack_space_get(const struct k_thread *thread, size_t *stack_size,
size_t *unused_ptr)
{
if ((thread->base.user_options & K_USER) != K_USER) {
return -EINVAL;
}

*stack_size = Z_STACK_PTR_ALIGN(K_KERNEL_STACK_RESERVED + CONFIG_PRIVILEGED_STACK_SIZE);

return z_stack_space_get((void *)thread->arch.priv_stack_start, *stack_size, unused_ptr);
}

#endif /* CONFIG_USERSPACE */

#ifndef CONFIG_MULTITHREADING
Expand Down

0 comments on commit 0962114

Please sign in to comment.