diff --git a/tests/kernel/mem_protect/userspace/src/main.c b/tests/kernel/mem_protect/userspace/src/main.c index 4eb34e04078b..71f8862ddc00 100644 --- a/tests/kernel/mem_protect/userspace/src/main.c +++ b/tests/kernel/mem_protect/userspace/src/main.c @@ -1131,6 +1131,43 @@ void test_object_recycle(void) zassert_true(perms_count == 1, "invalid number of thread permissions"); } +#define TLS_SIZE 4096 +struct k_thread tls_thread; +K_THREAD_STACK_DEFINE(tls_stack, TLS_SIZE); + +void tls_entry(void *p1, void *p2, void *p3) +{ + printk("tls_entry\n"); +} + +void test_tls_pointer(void) +{ + k_thread_create(&tls_thread, tls_stack, TLS_SIZE, tls_entry, + NULL, NULL, NULL, 1, K_USER, K_FOREVER); + + printk("tls pointer for thread %p: %p\n", + &tls_thread, (void *)tls_thread.userspace_local_data); + + printk("stack buffer reported bounds: [%p, %p)\n", + (void *)tls_thread.stack_info.start, + (void *)(tls_thread.stack_info.start + + tls_thread.stack_info.size)); + + printk("stack object bounds: [%p, %p)\n", + tls_stack, tls_stack + sizeof(tls_stack)); + + uintptr_t tls_start = (uintptr_t)tls_thread.userspace_local_data; + uintptr_t tls_end = tls_start + + sizeof(struct _thread_userspace_local_data); + + if ((tls_start < (uintptr_t)tls_stack) || + (tls_end > (uintptr_t)tls_stack + sizeof(tls_stack))) { + printk("tls area out of bounds\n"); + ztest_test_fail(); + } +} + + void test_main(void) { struct k_mem_partition *parts[] = {&part0, &part1, @@ -1184,7 +1221,8 @@ void test_main(void) ztest_unit_test(test_stack_buffer), ztest_user_unit_test(test_unimplemented_syscall), ztest_user_unit_test(test_bad_syscall), - ztest_unit_test(test_object_recycle) + ztest_unit_test(test_object_recycle), + ztest_unit_test(test_tls_pointer) ); ztest_run_test_suite(userspace); }