xtensa port: Clear the CP descriptor of new created thread.
This commit should fix the concern about uninitialized memory of main thread that was raised in https://gerrit.zephyrproject.org/r/#/c/12920/ The issue is more general, if it happens that the content of the CPENABLE flag of any thread is set then any other thread using the CP may cause a memory corruption. I'd prefer to avoid the issue by initializing the CP descriptor to 0. The descriptor itself is few words. We set them to 0 up to CP_ASA, which is set to a real value. As the dummy thread instantiated at the kernel startup does not use CP, there is no CP area in its thread memory buffer. However it is mandatory that it have the CP descriptor and that cpEnable in that descripot is set to null. This is ensured by adding XT_CP_DESCR_SIZE to _K_THREAD_NO_FLOAT_SIZEOF. Change-Id: I6a36b5b363600ea1e6d98ab679981182b2b5a236 Signed-off-by: Mazen NEIFER <mazen@nestwave.com>
This commit is contained in:
parent
59926490be
commit
01e9646638
|
@ -60,6 +60,6 @@ GEN_ABSOLUTE_SYM(__tPreempt_SIZEOF, sizeof(_caller_saved_t));
|
|||
/* size of the struct k_thread structure without save area for coproc regs */
|
||||
GEN_ABSOLUTE_SYM(_K_THREAD_NO_FLOAT_SIZEOF,
|
||||
sizeof(struct k_thread) - sizeof(tCoopCoprocReg) -
|
||||
sizeof(tPreempCoprocReg));
|
||||
sizeof(tPreempCoprocReg) + XT_CP_DESCR_SIZE);
|
||||
|
||||
GEN_ABS_SYM_END
|
||||
|
|
|
@ -89,6 +89,7 @@ void _new_thread(char *pStack, size_t stackSize,
|
|||
struct k_thread *thread = (struct k_thread *)(pStack);
|
||||
#if XCHAL_CP_NUM > 0
|
||||
uint32_t *cpSA;
|
||||
char *cpStack;
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_DEBUG
|
||||
|
@ -99,6 +100,9 @@ void _new_thread(char *pStack, size_t stackSize,
|
|||
memset(pStack, 0xaa, stackSize);
|
||||
#endif
|
||||
#if XCHAL_CP_NUM > 0
|
||||
/* Ensure CP state descriptor is correctly initialized */
|
||||
cpStack = thread->arch.preempCoprocReg.cpStack; /* short hand alias */
|
||||
memset(cpStack, 0, XT_CP_ASA); /* Set to zero to avoid bad surprises */
|
||||
/* Coprocessor's stack is allocated just after the k_thread */
|
||||
cpSA = (uint32_t *)(thread->arch.preempCoprocReg.cpStack + XT_CP_ASA);
|
||||
/* Coprocessor's save area alignment is at leat 16 bytes */
|
||||
|
|
|
@ -233,6 +233,8 @@ STRUCT_END(XtSolFrame)
|
|||
* that requires alignment greater than 16 bytes (ABI stack alignment).
|
||||
*/
|
||||
|
||||
#define XT_CP_DESCR_SIZE 12
|
||||
|
||||
#if XCHAL_CP_NUM > 0
|
||||
|
||||
/* Offsets of each coprocessor save area within the 'aligned save area': */
|
||||
|
@ -261,7 +263,8 @@ STRUCT_END(XtSolFrame)
|
|||
#define XT_CP_ASA 8
|
||||
|
||||
/* Overall size allows for dynamic alignment: */
|
||||
#define XT_CP_SIZE ALIGNUP(XCHAL_TOTAL_SA_ALIGN, 12 + XT_CP_SA_SIZE)
|
||||
#define XT_CP_SIZE ALIGNUP(XCHAL_TOTAL_SA_ALIGN, \
|
||||
XT_CP_DESCR_SIZE + XT_CP_SA_SIZE)
|
||||
#else
|
||||
#define XT_CP_SIZE 0
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue