1 /* SPDX-License-Identifier: Apache-2.0
2  *
3  * Copyright (c) 2021 Lexmark International, Inc.
4  */
5 
6 #include <zephyr/kernel.h>
7 #include <zephyr/internal/syscall_handler.h>
8 #include <zephyr/ztest.h>
9 
10 ZTEST_BMEM char user_stack[256];
11 
12 /**
13  * @brief Test sys_call does not write to user stack
14  *
15  * @ingroup kernel_memprotect_tests
16  */
ZTEST_USER(arm_mem_protect,test_user_corrupt_stack_pointer)17 ZTEST_USER(arm_mem_protect, test_user_corrupt_stack_pointer)
18 {
19 	int ret = 0;
20 	uint32_t saved_sp;
21 	size_t i;
22 
23 	saved_sp = __get_SP();
24 	__set_SP((uint32_t)&user_stack[0] + (sizeof(user_stack) / 2));
25 
26 	arch_syscall_invoke0(K_SYSCALL_K_YIELD);
27 
28 	__set_SP(saved_sp);
29 
30 	for (i = 0; i < sizeof(user_stack); ++i) {
31 		if (user_stack[i] != 0U) {
32 			ret = -1;
33 			break;
34 		}
35 	}
36 
37 	zassert_equal(ret, 0, "svc exception wrote to user stack");
38 }
39 
40 ZTEST_SUITE(arm_mem_protect, NULL, NULL, NULL, NULL, NULL);
41