From 0b3a4f35d010a1a1d3703e8bcd9dcd33264c59bb Mon Sep 17 00:00:00 2001 From: Daniel Leung Date: Wed, 13 Mar 2024 13:45:31 -0700 Subject: [PATCH] tests: mem_protect/userspace: extend tests for mapped stack This extends the test for memory mapped stack, as the address of memory mapped stack object would be different than the actual stack object. Signed-off-by: Daniel Leung --- tests/kernel/mem_protect/userspace/src/main.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/tests/kernel/mem_protect/userspace/src/main.c b/tests/kernel/mem_protect/userspace/src/main.c index edf5e8cd687..cd66c06ab7a 100644 --- a/tests/kernel/mem_protect/userspace/src/main.c +++ b/tests/kernel/mem_protect/userspace/src/main.c @@ -1060,6 +1060,9 @@ void tls_entry(void *p1, void *p2, void *p3) ZTEST(userspace, test_tls_pointer) { #ifdef CONFIG_THREAD_USERSPACE_LOCAL_DATA + char *stack_obj_ptr; + size_t stack_obj_sz; + k_thread_create(&test_thread, test_stack, STACKSIZE, tls_entry, NULL, NULL, NULL, 1, K_USER, K_FOREVER); @@ -1071,15 +1074,23 @@ ZTEST(userspace, test_tls_pointer) (void *)(test_thread.stack_info.start + test_thread.stack_info.size)); +#ifdef CONFIG_THREAD_STACK_MEM_MAPPED + stack_obj_ptr = (char *)test_thread.stack_obj_mapped; + stack_obj_sz = test_thread.stack_obj_size; +#else + stack_obj_ptr = (char *)test_stack; + stack_obj_sz = sizeof(test_stack); +#endif + printk("stack object bounds: [%p, %p)\n", - test_stack, test_stack + sizeof(test_stack)); + stack_obj_ptr, stack_obj_ptr + stack_obj_sz); uintptr_t tls_start = (uintptr_t)test_thread.userspace_local_data; uintptr_t tls_end = tls_start + sizeof(struct _thread_userspace_local_data); - if ((tls_start < (uintptr_t)test_stack) || - (tls_end > (uintptr_t)test_stack + sizeof(test_stack))) { + if ((tls_start < (uintptr_t)stack_obj_ptr) || + (tls_end > (uintptr_t)stack_obj_ptr + stack_obj_sz)) { printk("tls area out of bounds\n"); ztest_test_fail(); }