arch: arm64: thread: Clean thread arch when creating thread

Clean the thread->arch during the arch_new_thread to avoid unexpected
behavior. If the thread struct is allocated from heap or in stack, the
data in thread->arch might be dirty.

Signed-off-by: Jaxson Han <jaxson.han@arm.com>
This commit is contained in:
Jaxson Han 2023-09-16 15:26:45 +08:00 committed by Carles Cufí
commit 1ac3d1cc5e

View file

@ -69,6 +69,12 @@ void arch_new_thread(struct k_thread *thread, k_thread_stack_t *stack,
extern void z_arm64_exit_exc(void); extern void z_arm64_exit_exc(void);
z_arch_esf_t *pInitCtx; z_arch_esf_t *pInitCtx;
/*
* Clean the thread->arch to avoid unexpected behavior because the
* thread->arch might be dirty
*/
memset(&thread->arch, 0, sizeof(thread->arch));
/* /*
* The ESF is now hosted at the top of the stack. For user threads this * The ESF is now hosted at the top of the stack. For user threads this
* is also fine because at this stage they are still running in EL1. * is also fine because at this stage they are still running in EL1.
@ -100,9 +106,6 @@ void arch_new_thread(struct k_thread *thread, k_thread_stack_t *stack,
pInitCtx->elr = (uint64_t)z_thread_entry; pInitCtx->elr = (uint64_t)z_thread_entry;
} }
#if defined(CONFIG_ARM_MPU)
atomic_clear(&thread->arch.flushing);
#endif
#else #else
pInitCtx->elr = (uint64_t)z_thread_entry; pInitCtx->elr = (uint64_t)z_thread_entry;
#endif #endif