Skip to content

Commit d736af8

Browse files
dcpleungnashif
authored andcommitted
x86: 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 fb0baba commit d736af8

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

arch/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ config X86
9595
&& !SOC_HAS_TIMING_FUNCTIONS
9696
select ARCH_HAS_STACK_CANARIES_TLS
9797
select ARCH_SUPPORTS_MEM_MAPPED_STACKS if X86_MMU && !DEMAND_PAGING
98+
select ARCH_HAS_THREAD_PRIV_STACK_SPACE_GET if USERSPACE
9899
help
99100
x86 architecture
100101

arch/x86/core/userspace.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7+
#include <errno.h>
8+
79
#include <zephyr/kernel.h>
810
#include <zephyr/sys/speculation.h>
911
#include <zephyr/internal/syscall_handler.h>
@@ -183,3 +185,19 @@ FUNC_NORETURN void arch_user_mode_enter(k_thread_entry_t user_entry,
183185
_current->stack_info.start);
184186
CODE_UNREACHABLE;
185187
}
188+
189+
int arch_thread_priv_stack_space_get(const struct k_thread *thread, size_t *stack_size,
190+
size_t *unused_ptr)
191+
{
192+
struct z_x86_thread_stack_header *hdr_stack_obj;
193+
194+
if ((thread->base.user_options & K_USER) != K_USER) {
195+
return -EINVAL;
196+
}
197+
198+
hdr_stack_obj = (struct z_x86_thread_stack_header *)thread->stack_obj;
199+
200+
return z_stack_space_get(&hdr_stack_obj->privilege_stack[0],
201+
sizeof(hdr_stack_obj->privilege_stack),
202+
unused_ptr);
203+
}

0 commit comments

Comments
 (0)