addrenv/kstack: Allocate the kernel stack before initializing tcb

This is preparation to use kernel stack for everything when the user
process enters the kernel. Now the user stack is in use when the user
process runs a system call, which might not be the safest option.
This commit is contained in:
Ville Juven
2023-05-31 14:39:09 +03:00
committed by archer
parent 7732791cd6
commit a636edcbe4
4 changed files with 37 additions and 23 deletions
+11 -11
View File
@@ -186,6 +186,17 @@ int exec_module(FAR struct binary_s *binp,
umm_initialize(vheap, up_addrenv_heapsize(addrenv));
#endif
#if defined(CONFIG_ARCH_ADDRENV) && defined(CONFIG_ARCH_KERNEL_STACK)
/* Allocate the kernel stack */
ret = up_addrenv_kstackalloc(&tcb->cmn);
if (ret < 0)
{
berr("ERROR: up_addrenv_kstackalloc() failed: %d\n", ret);
goto errout_with_addrenv;
}
#endif
/* Note that tcb->flags are not modified. 0=normal task */
/* tcb->flags |= TCB_FLAG_TTYPE_TASK; */
@@ -229,17 +240,6 @@ int exec_module(FAR struct binary_s *binp,
}
}
#if defined(CONFIG_ARCH_ADDRENV) && defined(CONFIG_ARCH_KERNEL_STACK)
/* Allocate the kernel stack */
ret = up_addrenv_kstackalloc(&tcb->cmn);
if (ret < 0)
{
berr("ERROR: up_addrenv_kstackalloc() failed: %d\n", ret);
goto errout_with_tcbinit;
}
#endif
#ifdef CONFIG_PIC
/* Add the D-Space address as the PIC base address. By convention, this
* must be the first allocated address space.