Skip to content

Commit 0962114

Browse files
dcpleungnashif
authored andcommitted
riscv: implements arch_thread_priv_stack_space_get
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]>
1 parent bb31335 commit 0962114

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

arch/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ config RISCV
121121
select SCHED_IPI_SUPPORTED if SMP
122122
select ARCH_HAS_DIRECTED_IPIS
123123
select BARRIER_OPERATIONS_BUILTIN
124+
select ARCH_HAS_THREAD_PRIV_STACK_SPACE_GET if USERSPACE
124125
imply XIP
125126
help
126127
RISCV architecture

arch/riscv/core/thread.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,18 @@ FUNC_NORETURN void arch_user_mode_enter(k_thread_entry_t user_entry,
195195
CODE_UNREACHABLE;
196196
}
197197

198+
int arch_thread_priv_stack_space_get(const struct k_thread *thread, size_t *stack_size,
199+
size_t *unused_ptr)
200+
{
201+
if ((thread->base.user_options & K_USER) != K_USER) {
202+
return -EINVAL;
203+
}
204+
205+
*stack_size = Z_STACK_PTR_ALIGN(K_KERNEL_STACK_RESERVED + CONFIG_PRIVILEGED_STACK_SIZE);
206+
207+
return z_stack_space_get((void *)thread->arch.priv_stack_start, *stack_size, unused_ptr);
208+
}
209+
198210
#endif /* CONFIG_USERSPACE */
199211

200212
#ifndef CONFIG_MULTITHREADING

0 commit comments

Comments
 (0)