Skip to content

Commit 9962bc1

Browse files
wearyzennashif
authored andcommitted
arch: arm: fix start of the privileged stack
Make sure that arch.mode is set with appropriate flags before setting up the privileged stack start. Fixes #99895 Signed-off-by: Sudan Landge <[email protected]>
1 parent 78a3890 commit 9962bc1

File tree

2 files changed

+24
-22
lines changed

2 files changed

+24
-22
lines changed

arch/arm/core/cortex_a_r/thread.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,18 @@ void arch_new_thread(struct k_thread *thread, k_thread_stack_t *stack,
107107
#endif /* FP_GUARD_EXTRA_SIZE */
108108
#endif /* CONFIG_MPU_STACK_GUARD */
109109

110+
#if defined(CONFIG_ARM_STORE_EXC_RETURN) || defined(CONFIG_USERSPACE)
111+
thread->arch.mode = 0;
112+
#if defined(CONFIG_ARM_STORE_EXC_RETURN)
113+
thread->arch.mode_exc_return = DEFAULT_EXC_RETURN;
114+
#endif
115+
#if FP_GUARD_EXTRA_SIZE > 0
116+
if ((thread->base.user_options & K_FP_REGS) != 0) {
117+
thread->arch.mode |= Z_ARM_MODE_MPU_GUARD_FLOAT_Msk;
118+
}
119+
#endif
120+
#endif
121+
110122
iframe = Z_STACK_PTR_TO_FRAME(struct __basic_sf, stack_ptr);
111123
#if defined(CONFIG_USERSPACE)
112124
thread->arch.priv_stack_start = 0;
@@ -144,17 +156,6 @@ void arch_new_thread(struct k_thread *thread, k_thread_stack_t *stack,
144156
thread->callee_saved.psp = (uint32_t)iframe;
145157
thread->arch.basepri = 0;
146158

147-
#if defined(CONFIG_ARM_STORE_EXC_RETURN) || defined(CONFIG_USERSPACE)
148-
thread->arch.mode = 0;
149-
#if defined(CONFIG_ARM_STORE_EXC_RETURN)
150-
thread->arch.mode_exc_return = DEFAULT_EXC_RETURN;
151-
#endif
152-
#if FP_GUARD_EXTRA_SIZE > 0
153-
if ((thread->base.user_options & K_FP_REGS) != 0) {
154-
thread->arch.mode |= Z_ARM_MODE_MPU_GUARD_FLOAT_Msk;
155-
}
156-
#endif
157-
#endif
158159
/*
159160
* initial values in all other registers/thread entries are
160161
* irrelevant.

arch/arm/core/cortex_m/thread.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,18 @@ void arch_new_thread(struct k_thread *thread, k_thread_stack_t *stack, char *sta
115115
#endif /* FP_GUARD_EXTRA_SIZE */
116116
#endif /* CONFIG_MPU_STACK_GUARD */
117117

118+
#if defined(CONFIG_ARM_STORE_EXC_RETURN) || defined(CONFIG_USERSPACE)
119+
thread->arch.mode = 0;
120+
#if defined(CONFIG_ARM_STORE_EXC_RETURN)
121+
thread->arch.mode_exc_return = DEFAULT_EXC_RETURN;
122+
#endif
123+
#if FP_GUARD_EXTRA_SIZE > 0
124+
if ((thread->base.user_options & K_FP_REGS) != 0) {
125+
thread->arch.mode |= Z_ARM_MODE_MPU_GUARD_FLOAT_Msk;
126+
}
127+
#endif
128+
#endif
129+
118130
iframe = Z_STACK_PTR_TO_FRAME(struct __basic_sf, stack_ptr);
119131
#if defined(CONFIG_USERSPACE)
120132
thread->arch.priv_stack_start = 0;
@@ -141,17 +153,6 @@ void arch_new_thread(struct k_thread *thread, k_thread_stack_t *stack, char *sta
141153
thread->callee_saved.psp = (uint32_t)iframe;
142154
thread->arch.basepri = 0;
143155

144-
#if defined(CONFIG_ARM_STORE_EXC_RETURN) || defined(CONFIG_USERSPACE)
145-
thread->arch.mode = 0;
146-
#if defined(CONFIG_ARM_STORE_EXC_RETURN)
147-
thread->arch.mode_exc_return = DEFAULT_EXC_RETURN;
148-
#endif
149-
#if FP_GUARD_EXTRA_SIZE > 0
150-
if ((thread->base.user_options & K_FP_REGS) != 0) {
151-
thread->arch.mode |= Z_ARM_MODE_MPU_GUARD_FLOAT_Msk;
152-
}
153-
#endif
154-
#endif
155156
#ifdef CONFIG_ARM_PAC_PER_THREAD
156157
/* Generate PAC key and save it in thread context to be set later
157158
* when the thread is actually switched in

0 commit comments

Comments
 (0)