sched:use tcb_s inside of task_tcb_s , remove all cast

Simplify the code and remove different tcb

Signed-off-by: anjiahao <anjiahao@xiaomi.com>
This commit is contained in:
anjiahao
2025-02-13 12:12:32 +08:00
committed by GUIDINGLI
parent cd8ba3377c
commit 0a2b01950c
24 changed files with 248 additions and 271 deletions
@@ -31,7 +31,7 @@ Here is the body of some function. It expects to have the following inputs:
* used to that all fields of the new TCB will be zeroed.
*/
tcb = (FAR struct task_tcb_s *)kmm_zalloc(sizeof(struct task_tcb_s));
tcb = kmm_zalloc(sizeof(struct tcb_s) + sizeof(struct task_group_s));
if (tcb == NULL)
{
return -ENOMEM;
@@ -131,4 +131,4 @@ option is to include it in all cases where you do not expect the custom stack
to be de-allocated.
You must not free the custom stack after ``nxtask_activate()`` returns
successfully and until the kernel thread is terminated.
successfully and until the kernel thread is terminated.
+20 -20
View File
@@ -92,7 +92,7 @@
pid_t arm_fork(const struct fork_s *context)
{
struct tcb_s *parent = this_task();
struct task_tcb_s *child;
struct tcb_s *child;
uint32_t newsp;
uint32_t newfp;
uint32_t newtop;
@@ -144,17 +144,17 @@ pid_t arm_fork(const struct fork_s *context)
* effort is overkill.
*/
newtop = (uint32_t)child->cmn.stack_base_ptr +
child->cmn.adj_stack_size;
newtop = (uint32_t)child->stack_base_ptr +
child->adj_stack_size;
newsp = newtop - stackutil;
/* Move the register context to newtop. */
memcpy((void *)(newsp - XCPTCONTEXT_SIZE),
child->cmn.xcp.regs, XCPTCONTEXT_SIZE);
child->xcp.regs, XCPTCONTEXT_SIZE);
child->cmn.xcp.regs = (void *)(newsp - XCPTCONTEXT_SIZE);
child->xcp.regs = (void *)(newsp - XCPTCONTEXT_SIZE);
memcpy((void *)newsp, (const void *)oldsp, stackutil);
@@ -182,16 +182,16 @@ pid_t arm_fork(const struct fork_s *context)
* child thread.
*/
child->cmn.xcp.regs[REG_R4] = context->r4; /* Volatile register r4 */
child->cmn.xcp.regs[REG_R5] = context->r5; /* Volatile register r5 */
child->cmn.xcp.regs[REG_R6] = context->r6; /* Volatile register r6 */
child->cmn.xcp.regs[REG_R7] = context->r7; /* Volatile register r7 */
child->cmn.xcp.regs[REG_R8] = context->r8; /* Volatile register r8 */
child->cmn.xcp.regs[REG_R9] = context->r9; /* Volatile register r9 */
child->cmn.xcp.regs[REG_R10] = context->r10; /* Volatile register r10 */
child->cmn.xcp.regs[REG_R11] = context->r11; /* Volatile register r11 */
child->cmn.xcp.regs[REG_FP] = newfp; /* Frame pointer */
child->cmn.xcp.regs[REG_SP] = newsp; /* Stack pointer */
child->xcp.regs[REG_R4] = context->r4; /* Volatile register r4 */
child->xcp.regs[REG_R5] = context->r5; /* Volatile register r5 */
child->xcp.regs[REG_R6] = context->r6; /* Volatile register r6 */
child->xcp.regs[REG_R7] = context->r7; /* Volatile register r7 */
child->xcp.regs[REG_R8] = context->r8; /* Volatile register r8 */
child->xcp.regs[REG_R9] = context->r9; /* Volatile register r9 */
child->xcp.regs[REG_R10] = context->r10; /* Volatile register r10 */
child->xcp.regs[REG_R11] = context->r11; /* Volatile register r11 */
child->xcp.regs[REG_FP] = newfp; /* Frame pointer */
child->xcp.regs[REG_SP] = newsp; /* Stack pointer */
#ifdef CONFIG_LIB_SYSCALL
/* If we got here via a syscall, then we are going to have to setup some
@@ -203,7 +203,7 @@ pid_t arm_fork(const struct fork_s *context)
int index;
for (index = 0; index < parent->xcp.nsyscalls; index++)
{
child->cmn.xcp.syscall[index].sysreturn =
child->xcp.syscall[index].sysreturn =
parent->xcp.syscall[index].sysreturn;
/* REVISIT: This logic is *not* common. */
@@ -211,7 +211,7 @@ pid_t arm_fork(const struct fork_s *context)
#if defined(CONFIG_ARCH_ARMV7A)
# ifdef CONFIG_BUILD_KERNEL
child->cmn.xcp.syscall[index].cpsr =
child->xcp.syscall[index].cpsr =
parent->xcp.syscall[index].cpsr;
# endif
@@ -219,21 +219,21 @@ pid_t arm_fork(const struct fork_s *context)
#elif defined(CONFIG_ARCH_ARMV7R)
# ifdef CONFIG_BUILD_PROTECTED
child->cmn.xcp.syscall[index].cpsr =
child->xcp.syscall[index].cpsr =
parent->xcp.syscall[index].cpsr;
# endif
#elif defined(CONFIG_ARCH_ARMV6M) || defined(CONFIG_ARCH_ARMV7M) || \
defined(CONFIG_ARCH_ARMV8M)
child->cmn.xcp.syscall[index].excreturn =
child->xcp.syscall[index].excreturn =
parent->xcp.syscall[index].excreturn;
#else
# error Missing logic
#endif
}
child->cmn.xcp.nsyscalls = parent->xcp.nsyscalls;
child->xcp.nsyscalls = parent->xcp.nsyscalls;
}
#endif
+39 -39
View File
@@ -122,7 +122,7 @@ void arm64_fork_fpureg_save(struct fork_s *context)
pid_t arm64_fork(const struct fork_s *context)
{
struct tcb_s *parent = this_task();
struct task_tcb_s *child;
struct tcb_s *child;
uint64_t newsp;
uint64_t newfp;
uint64_t newtop;
@@ -156,8 +156,8 @@ pid_t arm64_fork(const struct fork_s *context)
* effort is overkill.
*/
newtop = (uint64_t)child->cmn.stack_base_ptr +
child->cmn.adj_stack_size;
newtop = (uint64_t)child->stack_base_ptr +
child->adj_stack_size;
newsp = newtop - stackutil;
memcpy((void *)newsp, (const void *)context->sp, stackutil);
@@ -183,59 +183,59 @@ pid_t arm64_fork(const struct fork_s *context)
/* make the fork stack frame */
#ifdef CONFIG_ARCH_FPU
child->cmn.xcp.fpu_regs = (void *)(newsp - FPU_CONTEXT_SIZE);
memcpy(child->cmn.xcp.fpu_regs, context->fpu, FPU_CONTEXT_SIZE);
child->xcp.fpu_regs = (void *)(newsp - FPU_CONTEXT_SIZE);
memcpy(child->xcp.fpu_regs, context->fpu, FPU_CONTEXT_SIZE);
#endif
child->cmn.xcp.regs = (void *)(newsp - XCPTCONTEXT_SIZE);
child->xcp.regs = (void *)(newsp - XCPTCONTEXT_SIZE);
child->cmn.xcp.regs[REG_X0] = 0;
child->cmn.xcp.regs[REG_X8] = context->regs[FORK_REG_X8];
child->cmn.xcp.regs[REG_X9] = context->regs[FORK_REG_X9];
child->cmn.xcp.regs[REG_X10] = context->regs[FORK_REG_X10];
child->cmn.xcp.regs[REG_X11] = context->regs[FORK_REG_X11];
child->cmn.xcp.regs[REG_X12] = context->regs[FORK_REG_X12];
child->cmn.xcp.regs[REG_X13] = context->regs[FORK_REG_X13];
child->cmn.xcp.regs[REG_X14] = context->regs[FORK_REG_X14];
child->cmn.xcp.regs[REG_X15] = context->regs[FORK_REG_X15];
child->cmn.xcp.regs[REG_X16] = context->regs[FORK_REG_X16];
child->cmn.xcp.regs[REG_X17] = context->regs[FORK_REG_X17];
child->cmn.xcp.regs[REG_X18] = context->regs[FORK_REG_X18];
child->cmn.xcp.regs[REG_X19] = context->regs[FORK_REG_X19];
child->cmn.xcp.regs[REG_X20] = context->regs[FORK_REG_X20];
child->cmn.xcp.regs[REG_X21] = context->regs[FORK_REG_X21];
child->cmn.xcp.regs[REG_X22] = context->regs[FORK_REG_X22];
child->cmn.xcp.regs[REG_X23] = context->regs[FORK_REG_X23];
child->cmn.xcp.regs[REG_X24] = context->regs[FORK_REG_X24];
child->cmn.xcp.regs[REG_X25] = context->regs[FORK_REG_X25];
child->cmn.xcp.regs[REG_X26] = context->regs[FORK_REG_X26];
child->cmn.xcp.regs[REG_X27] = context->regs[FORK_REG_X27];
child->cmn.xcp.regs[REG_X28] = context->regs[FORK_REG_X28];
child->cmn.xcp.regs[REG_FP] = newfp;
child->xcp.regs[REG_X0] = 0;
child->xcp.regs[REG_X8] = context->regs[FORK_REG_X8];
child->xcp.regs[REG_X9] = context->regs[FORK_REG_X9];
child->xcp.regs[REG_X10] = context->regs[FORK_REG_X10];
child->xcp.regs[REG_X11] = context->regs[FORK_REG_X11];
child->xcp.regs[REG_X12] = context->regs[FORK_REG_X12];
child->xcp.regs[REG_X13] = context->regs[FORK_REG_X13];
child->xcp.regs[REG_X14] = context->regs[FORK_REG_X14];
child->xcp.regs[REG_X15] = context->regs[FORK_REG_X15];
child->xcp.regs[REG_X16] = context->regs[FORK_REG_X16];
child->xcp.regs[REG_X17] = context->regs[FORK_REG_X17];
child->xcp.regs[REG_X18] = context->regs[FORK_REG_X18];
child->xcp.regs[REG_X19] = context->regs[FORK_REG_X19];
child->xcp.regs[REG_X20] = context->regs[FORK_REG_X20];
child->xcp.regs[REG_X21] = context->regs[FORK_REG_X21];
child->xcp.regs[REG_X22] = context->regs[FORK_REG_X22];
child->xcp.regs[REG_X23] = context->regs[FORK_REG_X23];
child->xcp.regs[REG_X24] = context->regs[FORK_REG_X24];
child->xcp.regs[REG_X25] = context->regs[FORK_REG_X25];
child->xcp.regs[REG_X26] = context->regs[FORK_REG_X26];
child->xcp.regs[REG_X27] = context->regs[FORK_REG_X27];
child->xcp.regs[REG_X28] = context->regs[FORK_REG_X28];
child->xcp.regs[REG_FP] = newfp;
#if CONFIG_ARCH_ARM64_EXCEPTION_LEVEL == 3
child->cmn.xcp.regs[REG_SPSR] = SPSR_MODE_EL3H;
child->xcp.regs[REG_SPSR] = SPSR_MODE_EL3H;
#else
child->cmn.xcp.regs[REG_SPSR] = SPSR_MODE_EL1H;
child->xcp.regs[REG_SPSR] = SPSR_MODE_EL1H;
#endif
#ifdef CONFIG_SUPPRESS_INTERRUPTS
child->cmn.xcp.regs[REG_SPSR] |= (DAIF_IRQ_BIT | DAIF_FIQ_BIT);
child->xcp.regs[REG_SPSR] |= (DAIF_IRQ_BIT | DAIF_FIQ_BIT);
#endif /* CONFIG_SUPPRESS_INTERRUPTS */
child->cmn.xcp.regs[REG_ELR] = (uint64_t)context->lr;
child->xcp.regs[REG_ELR] = (uint64_t)context->lr;
child->cmn.xcp.regs[REG_SCTLR_EL1] = read_sysreg(sctlr_el1);
child->xcp.regs[REG_SCTLR_EL1] = read_sysreg(sctlr_el1);
#ifdef CONFIG_ARM64_MTE
child->cmn.xcp.regs[REG_SCTLR_EL1] |= SCTLR_TCF1_BIT;
child->xcp.regs[REG_SCTLR_EL1] |= SCTLR_TCF1_BIT;
#endif
child->cmn.xcp.regs[REG_EXE_DEPTH] = 0;
child->cmn.xcp.regs[REG_SP_ELX] = newsp - XCPTCONTEXT_SIZE;
child->xcp.regs[REG_EXE_DEPTH] = 0;
child->xcp.regs[REG_SP_ELX] = newsp - XCPTCONTEXT_SIZE;
#ifdef CONFIG_ARCH_KERNEL_STACK
child->cmn.xcp.regs[REG_SP_EL0] = (uint64_t)child->cmn.xcp.ustkptr;
child->xcp.regs[REG_SP_EL0] = (uint64_t)child->xcp.ustkptr;
#else
child->cmn.xcp.regs[REG_SP_EL0] = newsp - XCPTCONTEXT_SIZE;
child->xcp.regs[REG_SP_EL0] = newsp - XCPTCONTEXT_SIZE;
#endif
/* And, finally, start the child task. On a failure, nxtask_start_fork()
+11 -11
View File
@@ -87,7 +87,7 @@ pid_t ceva_fork(const uint32_t *regs)
{
#ifdef CONFIG_SCHED_WAITPID
struct tcb_s *parent = this_task();
struct task_tcb_s *child;
struct tcb_s *child;
size_t stacksize;
const void *sp = regs + XCPTCONTEXT_REGS;
void *newsp;
@@ -146,14 +146,14 @@ pid_t ceva_fork(const uint32_t *regs)
* effort is overkill.
*/
newsp = child->cmn.stack_base_ptr - stackutil;
newsp = child->stack_base_ptr - stackutil;
memcpy(newsp, sp, stackutil);
/* Allocate the context and copy the parent snapshot */
newsp -= XCPTCONTEXT_SIZE;
memcpy(newsp, regs, XCPTCONTEXT_SIZE);
child->cmn.xcp.regs = newsp;
child->xcp.regs = newsp;
/* Was there a frame pointer in place before? */
@@ -161,7 +161,7 @@ pid_t ceva_fork(const uint32_t *regs)
regs[REG_FP] >= (uint32_t)parent->stack_base_ptr - stacksize)
{
uint32_t frameutil = (uint32_t)parent->stack_base_ptr - regs[REG_FP];
newfp = (uint32_t)child->cmn.stack_base_ptr - frameutil;
newfp = (uint32_t)child->stack_base_ptr - frameutil;
}
else
{
@@ -171,17 +171,17 @@ pid_t ceva_fork(const uint32_t *regs)
sinfo("Parent: stack base:%08x SP:%08x FP:%08x\n",
parent->stack_base_ptr, sp, regs[REG_FP]);
sinfo("Child: stack base:%08x SP:%08x FP:%08x\n",
child->cmn.stack_base_ptr, newsp, newfp);
child->stack_base_ptr, newsp, newfp);
/* Update the stack pointer, frame pointer, and the return value in A0
* should be cleared to zero, providing the indication to the newly started
* child thread.
*/
child->cmn.xcp.regs[REG_A0] = 0; /* Return value */
child->cmn.xcp.regs[REG_FP] = newfp; /* Frame pointer */
child->cmn.xcp.regs[REG_PC] = regs[REG_LR]; /* Program counter */
child->cmn.xcp.regs[REG_SP] = (uint32_t)newsp; /* Stack pointer */
child->xcp.regs[REG_A0] = 0; /* Return value */
child->xcp.regs[REG_FP] = newfp; /* Frame pointer */
child->xcp.regs[REG_PC] = regs[REG_LR]; /* Program counter */
child->xcp.regs[REG_SP] = (uint32_t)newsp; /* Stack pointer */
#ifdef CONFIG_LIB_SYSCALL
/* If we got here via a syscall, then we are going to have to setup some
@@ -193,10 +193,10 @@ pid_t ceva_fork(const uint32_t *regs)
int index;
for (index = 0; index < parent->xcp.nsyscalls; index++)
{
child->cmn.xcp.syscall[index] = parent->xcp.syscall[index];
child->xcp.syscall[index] = parent->xcp.syscall[index];
}
child->cmn.xcp.nsyscalls = parent->xcp.nsyscalls;
child->xcp.nsyscalls = parent->xcp.nsyscalls;
}
#endif
+15 -15
View File
@@ -92,7 +92,7 @@
pid_t mips_fork(const struct fork_s *context)
{
struct tcb_s *parent = this_task();
struct task_tcb_s *child;
struct tcb_s *child;
uint32_t newsp;
#ifdef CONFIG_MIPS32_FRAMEPOINTER
uint32_t newfp;
@@ -159,8 +159,8 @@ pid_t mips_fork(const struct fork_s *context)
* effort is overkill.
*/
newtop = (uintptr_t)child->cmn.stack_base_ptr +
child->cmn.adj_stack_size;
newtop = (uintptr_t)child->stack_base_ptr +
child->adj_stack_size;
newsp = newtop - stackutil;
memcpy((void *)newsp, (const void *)context->sp, stackutil);
@@ -195,22 +195,22 @@ pid_t mips_fork(const struct fork_s *context)
* indication to the newly started child thread.
*/
child->cmn.xcp.regs[REG_S0] = context->s0; /* Saved register s0 */
child->cmn.xcp.regs[REG_S1] = context->s1; /* Saved register s1 */
child->cmn.xcp.regs[REG_S2] = context->s2; /* Saved register s2 */
child->cmn.xcp.regs[REG_S3] = context->s3; /* Volatile register s3 */
child->cmn.xcp.regs[REG_S4] = context->s4; /* Volatile register s4 */
child->cmn.xcp.regs[REG_S5] = context->s5; /* Volatile register s5 */
child->cmn.xcp.regs[REG_S6] = context->s6; /* Volatile register s6 */
child->cmn.xcp.regs[REG_S7] = context->s7; /* Volatile register s7 */
child->xcp.regs[REG_S0] = context->s0; /* Saved register s0 */
child->xcp.regs[REG_S1] = context->s1; /* Saved register s1 */
child->xcp.regs[REG_S2] = context->s2; /* Saved register s2 */
child->xcp.regs[REG_S3] = context->s3; /* Volatile register s3 */
child->xcp.regs[REG_S4] = context->s4; /* Volatile register s4 */
child->xcp.regs[REG_S5] = context->s5; /* Volatile register s5 */
child->xcp.regs[REG_S6] = context->s6; /* Volatile register s6 */
child->xcp.regs[REG_S7] = context->s7; /* Volatile register s7 */
#ifdef CONFIG_MIPS32_FRAMEPOINTER
child->cmn.xcp.regs[REG_FP] = newfp; /* Frame pointer */
child->xcp.regs[REG_FP] = newfp; /* Frame pointer */
#else
child->cmn.xcp.regs[REG_S8] = context->s8; /* Volatile register s8 */
child->xcp.regs[REG_S8] = context->s8; /* Volatile register s8 */
#endif
child->cmn.xcp.regs[REG_SP] = newsp; /* Stack pointer */
child->xcp.regs[REG_SP] = newsp; /* Stack pointer */
#ifdef MIPS32_SAVE_GP
child->cmn.xcp.regs[REG_GP] = context->gp; /* Global pointer */
child->xcp.regs[REG_GP] = context->gp; /* Global pointer */
#endif
/* And, finally, start the child task. On a failure, nxtask_start_fork()
@@ -552,7 +552,7 @@ static int spiflash_init_spi_flash_op_block_task(int cpu)
/* Initialize the task */
ret = nxtask_init((FAR struct task_tcb_s *)tcb, "spiflash_op",
ret = nxtask_init(tcb, "spiflash_op",
SCHED_PRIORITY_MAX,
NULL, SPIFLASH_OP_TASK_STACKSIZE,
spi_flash_op_block_task, argv, environ, NULL);
+43 -43
View File
@@ -105,7 +105,7 @@
pid_t riscv_fork(const struct fork_s *context)
{
struct tcb_s *parent = this_task();
struct task_tcb_s *child;
struct tcb_s *child;
uintptr_t newsp;
uintptr_t newtop;
uintptr_t stacktop;
@@ -132,7 +132,7 @@ pid_t riscv_fork(const struct fork_s *context)
/* Copy goes to child's user stack top */
newtop = (uintptr_t)child->cmn.stack_base_ptr + child->cmn.adj_stack_size;
newtop = (uintptr_t)child->stack_base_ptr + child->adj_stack_size;
newsp = newtop - stackutil;
memcpy((void *)newsp, (const void *)parent->xcp.sregs[REG_SP], stackutil);
@@ -140,17 +140,17 @@ pid_t riscv_fork(const struct fork_s *context)
#ifdef CONFIG_SCHED_THREAD_LOCAL
/* Save child's thread pointer */
tp = child->cmn.xcp.regs[REG_TP];
tp = child->xcp.regs[REG_TP];
#endif
/* Determine the integer context save area */
#ifdef CONFIG_ARCH_KERNEL_STACK
if (child->cmn.xcp.kstack)
if (child->xcp.kstack)
{
/* Set context to kernel stack */
stacktop = (uintptr_t)child->cmn.xcp.ktopstk;
stacktop = (uintptr_t)child->xcp.ktopstk;
}
else
#endif
@@ -162,22 +162,22 @@ pid_t riscv_fork(const struct fork_s *context)
/* Set the new register restore area to the new stack top */
child->cmn.xcp.regs = (void *)(stacktop - XCPTCONTEXT_SIZE);
child->xcp.regs = (void *)(stacktop - XCPTCONTEXT_SIZE);
/* Copy the parent integer context (overwrites child's SP and TP) */
memcpy(child->cmn.xcp.regs, parent->xcp.sregs, XCPTCONTEXT_SIZE);
memcpy(child->xcp.regs, parent->xcp.sregs, XCPTCONTEXT_SIZE);
/* Save FPU */
riscv_savefpu(child->cmn.xcp.regs, riscv_fpuregs(&child->cmn));
riscv_savefpu(child->xcp.regs, riscv_fpuregs(child));
/* Return 0 to child */
child->cmn.xcp.regs[REG_A0] = 0;
child->cmn.xcp.regs[REG_SP] = newsp;
child->xcp.regs[REG_A0] = 0;
child->xcp.regs[REG_SP] = newsp;
#ifdef CONFIG_SCHED_THREAD_LOCAL
child->cmn.xcp.regs[REG_TP] = tp;
child->xcp.regs[REG_TP] = tp;
#endif
/* And, finally, start the child task. On a failure, nxtask_start_fork()
@@ -192,7 +192,7 @@ pid_t riscv_fork(const struct fork_s *context)
pid_t riscv_fork(const struct fork_s *context)
{
struct tcb_s *parent = this_task();
struct task_tcb_s *child;
struct tcb_s *child;
uintptr_t newsp;
#ifdef CONFIG_RISCV_FRAMEPOINTER
uintptr_t newfp;
@@ -259,13 +259,13 @@ pid_t riscv_fork(const struct fork_s *context)
* effort is overkill.
*/
newtop = (uintptr_t)child->cmn.stack_base_ptr + child->cmn.adj_stack_size;
newtop = (uintptr_t)child->stack_base_ptr + child->adj_stack_size;
newsp = newtop - stackutil;
/* Set up frame for context and copy the initial context there */
memcpy((void *)(newsp - XCPTCONTEXT_SIZE),
child->cmn.xcp.regs, XCPTCONTEXT_SIZE);
child->xcp.regs, XCPTCONTEXT_SIZE);
/* Copy the parent stack contents (overwrites child's SP and TP) */
@@ -273,7 +273,7 @@ pid_t riscv_fork(const struct fork_s *context)
/* Set the new register restore area to the new stack top */
child->cmn.xcp.regs = (void *)(newsp - XCPTCONTEXT_SIZE);
child->xcp.regs = (void *)(newsp - XCPTCONTEXT_SIZE);
/* Was there a frame pointer in place before? */
@@ -306,40 +306,40 @@ pid_t riscv_fork(const struct fork_s *context)
* indication to the newly started child thread.
*/
child->cmn.xcp.regs[REG_S1] = context->s1; /* Saved register s1 */
child->cmn.xcp.regs[REG_S2] = context->s2; /* Saved register s2 */
child->cmn.xcp.regs[REG_S3] = context->s3; /* Saved register s3 */
child->cmn.xcp.regs[REG_S4] = context->s4; /* Saved register s4 */
child->cmn.xcp.regs[REG_S5] = context->s5; /* Saved register s5 */
child->cmn.xcp.regs[REG_S6] = context->s6; /* Saved register s6 */
child->cmn.xcp.regs[REG_S7] = context->s7; /* Saved register s7 */
child->cmn.xcp.regs[REG_S8] = context->s8; /* Saved register s8 */
child->cmn.xcp.regs[REG_S9] = context->s9; /* Saved register s9 */
child->cmn.xcp.regs[REG_S10] = context->s10; /* Saved register s10 */
child->cmn.xcp.regs[REG_S11] = context->s11; /* Saved register s11 */
child->xcp.regs[REG_S1] = context->s1; /* Saved register s1 */
child->xcp.regs[REG_S2] = context->s2; /* Saved register s2 */
child->xcp.regs[REG_S3] = context->s3; /* Saved register s3 */
child->xcp.regs[REG_S4] = context->s4; /* Saved register s4 */
child->xcp.regs[REG_S5] = context->s5; /* Saved register s5 */
child->xcp.regs[REG_S6] = context->s6; /* Saved register s6 */
child->xcp.regs[REG_S7] = context->s7; /* Saved register s7 */
child->xcp.regs[REG_S8] = context->s8; /* Saved register s8 */
child->xcp.regs[REG_S9] = context->s9; /* Saved register s9 */
child->xcp.regs[REG_S10] = context->s10; /* Saved register s10 */
child->xcp.regs[REG_S11] = context->s11; /* Saved register s11 */
#ifdef CONFIG_RISCV_FRAMEPOINTER
child->cmn.xcp.regs[REG_FP] = newfp; /* Frame pointer */
child->xcp.regs[REG_FP] = newfp; /* Frame pointer */
#else
child->cmn.xcp.regs[REG_S0] = context->s0; /* Saved register s0 */
child->xcp.regs[REG_S0] = context->s0; /* Saved register s0 */
#endif
child->cmn.xcp.regs[REG_SP] = newsp; /* Stack pointer */
child->xcp.regs[REG_SP] = newsp; /* Stack pointer */
#ifdef RISCV_SAVE_GP
child->cmn.xcp.regs[REG_GP] = context->gp; /* Global pointer */
child->xcp.regs[REG_GP] = context->gp; /* Global pointer */
#endif
#ifdef CONFIG_ARCH_FPU
fregs = riscv_fpuregs(&child->cmn);
fregs[REG_FS0] = context->fs0; /* Saved register fs1 */
fregs[REG_FS1] = context->fs1; /* Saved register fs1 */
fregs[REG_FS2] = context->fs2; /* Saved register fs2 */
fregs[REG_FS3] = context->fs3; /* Saved register fs3 */
fregs[REG_FS4] = context->fs4; /* Saved register fs4 */
fregs[REG_FS5] = context->fs5; /* Saved register fs5 */
fregs[REG_FS6] = context->fs6; /* Saved register fs6 */
fregs[REG_FS7] = context->fs7; /* Saved register fs7 */
fregs[REG_FS8] = context->fs8; /* Saved register fs8 */
fregs[REG_FS9] = context->fs9; /* Saved register fs9 */
fregs[REG_FS10] = context->fs10; /* Saved register fs10 */
fregs[REG_FS11] = context->fs11; /* Saved register fs11 */
fregs = riscv_fpuregs(child);
fregs[REG_FS0] = context->fs0; /* Saved register fs1 */
fregs[REG_FS1] = context->fs1; /* Saved register fs1 */
fregs[REG_FS2] = context->fs2; /* Saved register fs2 */
fregs[REG_FS3] = context->fs3; /* Saved register fs3 */
fregs[REG_FS4] = context->fs4; /* Saved register fs4 */
fregs[REG_FS5] = context->fs5; /* Saved register fs5 */
fregs[REG_FS6] = context->fs6; /* Saved register fs6 */
fregs[REG_FS7] = context->fs7; /* Saved register fs7 */
fregs[REG_FS8] = context->fs8; /* Saved register fs8 */
fregs[REG_FS9] = context->fs9; /* Saved register fs9 */
fregs[REG_FS10] = context->fs10; /* Saved register fs10 */
fregs[REG_FS11] = context->fs11; /* Saved register fs11 */
#endif
/* And, finally, start the child task. On a failure, nxtask_start_fork()
+6 -6
View File
@@ -91,7 +91,7 @@ nosanitize_address
pid_t sim_fork(const xcpt_reg_t *context)
{
struct tcb_s *parent = this_task();
struct task_tcb_s *child;
struct tcb_s *child;
unsigned char *pout;
unsigned char *pin;
xcpt_reg_t newsp;
@@ -135,8 +135,8 @@ pid_t sim_fork(const xcpt_reg_t *context)
* effort is overkill.
*/
newtop = (xcpt_reg_t)child->cmn.stack_base_ptr +
child->cmn.adj_stack_size;
newtop = (xcpt_reg_t)child->stack_base_ptr +
child->adj_stack_size;
newsp = newtop - stackutil;
pout = (unsigned char *)newsp;
pin = (unsigned char *)context[JB_SP];
@@ -166,10 +166,10 @@ pid_t sim_fork(const xcpt_reg_t *context)
* child thread.
*/
memcpy(child->cmn.xcp.regs, context,
memcpy(child->xcp.regs, context,
sizeof(xcpt_reg_t) * XCPTCONTEXT_REGS);
child->cmn.xcp.regs[JB_FP] = newfp; /* Frame pointer */
child->cmn.xcp.regs[JB_SP] = newsp; /* Stack pointer */
child->xcp.regs[JB_FP] = newfp; /* Frame pointer */
child->xcp.regs[JB_SP] = newsp; /* Stack pointer */
/* And, finally, start the child task. On a failure, nxtask_start_fork()
* will discard the TCB by calling nxtask_abort_fork().
+16 -16
View File
@@ -92,7 +92,7 @@
pid_t x86_64_fork(const struct fork_s *context)
{
struct tcb_s *parent = this_task();
struct task_tcb_s *child;
struct tcb_s *child;
uint64_t newsp;
uint64_t newfp;
uint64_t newtop;
@@ -140,15 +140,15 @@ pid_t x86_64_fork(const struct fork_s *context)
* effort is overkill.
*/
newtop = (uint64_t)XCP_ALIGN_DOWN((uintptr_t)child->cmn.stack_base_ptr +
child->cmn.adj_stack_size -
newtop = (uint64_t)XCP_ALIGN_DOWN((uintptr_t)child->stack_base_ptr +
child->adj_stack_size -
XCPTCONTEXT_SIZE);
newsp = newtop - stackutil;
/* Move the register context (from parent) to newtop. */
memcpy(child->cmn.xcp.regs, parent->xcp.regs, XCPTCONTEXT_SIZE);
memcpy(child->xcp.regs, parent->xcp.regs, XCPTCONTEXT_SIZE);
memcpy((void *)newsp, (const void *)context->rsp, stackutil);
@@ -178,18 +178,18 @@ pid_t x86_64_fork(const struct fork_s *context)
* child thread.
*/
child->cmn.xcp.regs[REG_RAX] = 0; /* Parent proc return 0 */
child->cmn.xcp.regs[REG_R12] = context->r12; /* Non-volatile register r12 */
child->cmn.xcp.regs[REG_R13] = context->r13; /* Non-volatile register r13 */
child->cmn.xcp.regs[REG_R14] = context->r14; /* Non-volatile register r14 */
child->cmn.xcp.regs[REG_R15] = context->r15; /* Non-volatile register r15 */
child->cmn.xcp.regs[REG_RBX] = context->rbx; /* Non-volatile register rbx */
child->cmn.xcp.regs[REG_SS] = context->ss; /* SS */
child->cmn.xcp.regs[REG_CS] = context->cs; /* CS */
child->cmn.xcp.regs[REG_RFLAGS] = context->rflags;
child->cmn.xcp.regs[REG_RIP] = context->rip;
child->cmn.xcp.regs[REG_RSP] = newsp; /* Stack pointer */
child->cmn.xcp.regs[REG_RBP] = newfp; /* Like registers */
child->xcp.regs[REG_RAX] = 0; /* Parent proc return 0 */
child->xcp.regs[REG_R12] = context->r12; /* Non-volatile register r12 */
child->xcp.regs[REG_R13] = context->r13; /* Non-volatile register r13 */
child->xcp.regs[REG_R14] = context->r14; /* Non-volatile register r14 */
child->xcp.regs[REG_R15] = context->r15; /* Non-volatile register r15 */
child->xcp.regs[REG_RBX] = context->rbx; /* Non-volatile register rbx */
child->xcp.regs[REG_SS] = context->ss; /* SS */
child->xcp.regs[REG_CS] = context->cs; /* CS */
child->xcp.regs[REG_RFLAGS] = context->rflags;
child->xcp.regs[REG_RIP] = context->rip;
child->xcp.regs[REG_RSP] = newsp; /* Stack pointer */
child->xcp.regs[REG_RBP] = newfp; /* Like registers */
/* And, finally, start the child task. On a failure, nxtask_start_fork()
* will discard the TCB by calling nxtask_abort_fork().
@@ -589,7 +589,7 @@ static int spiflash_init_spi_flash_op_block_task(int cpu)
/* Initialize the task */
ret = nxtask_init((FAR struct task_tcb_s *)tcb, "spiflash_op",
ret = nxtask_init(tcb, "spiflash_op",
SCHED_PRIORITY_MAX,
NULL, SPIFLASH_OP_TASK_STACKSIZE,
spi_flash_op_block_task, argv, environ, NULL);
+1 -1
View File
@@ -2585,7 +2585,7 @@ int spiflash_init_spi_flash_op_block_task(int cpu)
/* Initialize the task */
ret = nxtask_init((FAR struct task_tcb_s *)tcb, "spiflash_op",
ret = nxtask_init(tcb, "spiflash_op",
SCHED_PRIORITY_MAX,
NULL, CONFIG_ESP32_SPIFLASH_OP_TASK_STACKSIZE,
spi_flash_op_block_task, argv, environ, NULL);
+1 -1
View File
@@ -1024,7 +1024,7 @@ static int spiflash_init_spi_flash_op_block_task(int cpu)
/* Initialize the task */
ret = nxtask_init((FAR struct task_tcb_s *)tcb, "spiflash_op",
ret = nxtask_init(tcb, "spiflash_op",
SCHED_PRIORITY_MAX,
NULL, CONFIG_ESP32S3_SPIFLASH_OP_TASK_STACKSIZE,
spi_flash_op_block_task, argv, environ, NULL);
+15 -15
View File
@@ -156,7 +156,7 @@ int exec_module(FAR struct binary_s *binp,
FAR const posix_spawnattr_t *attr,
bool spawn)
{
FAR struct task_tcb_s *tcb;
FAR struct tcb_s *tcb;
#if defined(CONFIG_ARCH_ADDRENV) && defined(CONFIG_BUILD_KERNEL)
FAR struct arch_addrenv_s *addrenv = &binp->addrenv->addrenv;
FAR void *vheap;
@@ -179,7 +179,7 @@ int exec_module(FAR struct binary_s *binp,
/* Allocate a TCB for the new task. */
tcb = kmm_zalloc(sizeof(struct task_tcb_s));
tcb = kmm_zalloc(sizeof(struct tcb_s));
if (!tcb)
{
return -ENOMEM;
@@ -243,7 +243,7 @@ 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);
ret = up_addrenv_kstackalloc(tcb);
if (ret < 0)
{
berr("ERROR: up_addrenv_kstackalloc() failed: %d\n", ret);
@@ -251,11 +251,11 @@ int exec_module(FAR struct binary_s *binp,
}
#endif
/* Note that tcb->cmn.flags are not modified. 0=normal task */
/* Note that tcb->flags are not modified. 0=normal task */
/* tcb->cmn.flags |= TCB_FLAG_TTYPE_TASK; */
/* tcb->flags |= TCB_FLAG_TTYPE_TASK; */
tcb->cmn.flags |= TCB_FLAG_FREE_TCB;
tcb->flags |= TCB_FLAG_FREE_TCB;
/* Initialize the task */
@@ -293,17 +293,17 @@ int exec_module(FAR struct binary_s *binp,
* must be the first allocated address space.
*/
tcb->cmn.dspace = binp->picbase;
tcb->dspace = binp->picbase;
/* Re-initialize the task's initial state to account for the new PIC base */
up_initial_state(&tcb->cmn);
up_initial_state(tcb);
#endif
#ifdef CONFIG_ARCH_ADDRENV
/* Attach the address environment to the new task */
ret = addrenv_attach((FAR struct tcb_s *)tcb, binp->addrenv);
ret = addrenv_attach(tcb, binp->addrenv);
if (ret < 0)
{
berr("ERROR: addrenv_attach() failed: %d\n", ret);
@@ -314,23 +314,23 @@ int exec_module(FAR struct binary_s *binp,
#ifdef CONFIG_SCHED_USER_IDENTITY
if (binp->mode & S_ISUID)
{
tcb->cmn.group->tg_euid = binp->uid;
tcb->group->tg_euid = binp->uid;
}
if (binp->mode & S_ISGID)
{
tcb->cmn.group->tg_egid = binp->gid;
tcb->group->tg_egid = binp->gid;
}
#endif
if (!spawn)
{
exec_swap(this_task(), (FAR struct tcb_s *)tcb);
exec_swap(this_task(), tcb);
}
/* Get the assigned pid before we start the task */
pid = tcb->cmn.pid;
pid = tcb->pid;
#if defined(CONFIG_ARCH_ADDRENV) && defined(CONFIG_BUILD_KERNEL)
/* Restore the address environment of the caller */
@@ -356,7 +356,7 @@ int exec_module(FAR struct binary_s *binp,
/* Then activate the task at the provided priority */
nxtask_activate((FAR struct tcb_s *)tcb);
nxtask_activate(tcb);
return pid;
@@ -364,7 +364,7 @@ errout_with_tcbinit:
#ifndef CONFIG_BUILD_KERNEL
if (binp->stackaddr != NULL)
{
tcb->cmn.stack_alloc_ptr = NULL;
tcb->stack_alloc_ptr = NULL;
}
#endif
+5 -24
View File
@@ -729,25 +729,6 @@ struct tcb_s
#endif
};
/* struct task_tcb_s ********************************************************/
/* This is the particular form of the task control block (TCB) structure used
* by tasks (and kernel threads). There are two TCB forms: one for pthreads
* and one for tasks.
* Both share the common TCB fields (which must appear at the top of the
* structure) plus additional fields unique to tasks and threads.
* Having separate structures for tasks and pthreads adds some complexity,
* but saves memory in that it prevents pthreads from being burdened with the
* overhead required for tasks (and vice versa).
*/
struct task_tcb_s
{
/* Common TCB fields ******************************************************/
struct tcb_s cmn; /* Common TCB fields */
};
/* struct pthread_tcb_s *****************************************************/
/* This is the particular form of the task control block (TCB) structure used
@@ -1009,7 +990,7 @@ FAR struct fdlist *nxsched_get_fdlist(void);
*
****************************************************************************/
int nxtask_init(FAR struct task_tcb_s *tcb, const char *name, int priority,
int nxtask_init(FAR struct tcb_s *tcb, const char *name, int priority,
FAR void *stack, uint32_t stack_size, main_t entry,
FAR char * const argv[], FAR char * const envp[],
FAR const posix_spawn_file_actions_t *actions);
@@ -1033,7 +1014,7 @@ int nxtask_init(FAR struct task_tcb_s *tcb, const char *name, int priority,
*
****************************************************************************/
void nxtask_uninit(FAR struct task_tcb_s *tcb);
void nxtask_uninit(FAR struct tcb_s *tcb);
/****************************************************************************
* Name: nxtask_create
@@ -1169,9 +1150,9 @@ void nxtask_startup(main_t entrypt, int argc, FAR char *argv[]);
*
****************************************************************************/
FAR struct task_tcb_s *nxtask_setup_fork(start_t retaddr);
pid_t nxtask_start_fork(FAR struct task_tcb_s *child);
void nxtask_abort_fork(FAR struct task_tcb_s *child, int errcode);
FAR struct tcb_s *nxtask_setup_fork(start_t retaddr);
pid_t nxtask_start_fork(FAR struct tcb_s *child);
void nxtask_abort_fork(FAR struct tcb_s *child, int errcode);
/****************************************************************************
* Name: nxtask_argvstr
+3 -3
View File
@@ -58,8 +58,8 @@ void task_initialize(void);
/* Task group data structure management */
int group_allocate(FAR struct task_tcb_s *tcb, uint8_t ttype);
void group_initialize(FAR struct task_tcb_s *tcb);
int group_allocate(FAR struct tcb_s *tcb, uint8_t ttype);
void group_initialize(FAR struct tcb_s *tcb);
#ifndef CONFIG_DISABLE_PTHREAD
void group_bind(FAR struct pthread_tcb_s *tcb);
void group_join(FAR struct pthread_tcb_s *tcb);
@@ -112,7 +112,7 @@ void group_remove_children(FAR struct task_group_s *group);
/* Group data resource configuration */
int group_setupidlefiles(void);
int group_setuptaskfiles(FAR struct task_tcb_s *tcb,
int group_setuptaskfiles(FAR struct tcb_s *tcb,
FAR const posix_spawn_file_actions_t *actions,
bool cloexec);
+10 -10
View File
@@ -116,12 +116,12 @@ static inline void group_inherit_identity(FAR struct task_group_s *group)
*
****************************************************************************/
int group_allocate(FAR struct task_tcb_s *tcb, uint8_t ttype)
int group_allocate(FAR struct tcb_s *tcb, uint8_t ttype)
{
FAR struct task_group_s *group;
int ret;
DEBUGASSERT(tcb && !tcb->cmn.group);
DEBUGASSERT(tcb && !tcb->group);
ttype &= TCB_FLAG_TTYPE_MASK;
@@ -130,7 +130,7 @@ int group_allocate(FAR struct task_tcb_s *tcb, uint8_t ttype)
if (ttype == TCB_FLAG_TTYPE_KERNEL)
{
group = &g_kthread_group;
tcb->cmn.group = group;
tcb->group = group;
if (group->tg_info)
{
return OK;
@@ -165,7 +165,7 @@ int group_allocate(FAR struct task_tcb_s *tcb, uint8_t ttype)
/* Attach the group to the TCB */
tcb->cmn.group = group;
tcb->group = group;
/* Inherit the user identity from the parent task group */
@@ -225,23 +225,23 @@ errout_with_group:
*
****************************************************************************/
void group_initialize(FAR struct task_tcb_s *tcb)
void group_initialize(FAR struct tcb_s *tcb)
{
FAR struct task_group_s *group;
DEBUGASSERT(tcb && tcb->cmn.group);
group = tcb->cmn.group;
DEBUGASSERT(tcb && tcb->group);
group = tcb->group;
spin_lock_init(&group->tg_lock);
/* Allocate mm_map list if required */
mm_map_initialize(&group->tg_mm_map,
(tcb->cmn.flags & TCB_FLAG_TTYPE_KERNEL) != 0);
(tcb->flags & TCB_FLAG_TTYPE_KERNEL) != 0);
#ifdef HAVE_GROUP_MEMBERS
/* Assign the PID of this new task as a member of the group. */
sq_addlast(&tcb->cmn.member, &group->tg_members);
sq_addlast(&tcb->member, &group->tg_members);
#endif
/* Save the ID of the main task within the group of threads. This needed
@@ -252,6 +252,6 @@ void group_initialize(FAR struct task_tcb_s *tcb)
if (group != &g_kthread_group)
{
group->tg_pid = tcb->cmn.pid;
group->tg_pid = tcb->pid;
}
}
+6 -6
View File
@@ -59,11 +59,11 @@
*
****************************************************************************/
int group_setuptaskfiles(FAR struct task_tcb_s *tcb,
int group_setuptaskfiles(FAR struct tcb_s *tcb,
FAR const posix_spawn_file_actions_t *actions,
bool cloexec)
{
FAR struct task_group_s *group = tcb->cmn.group;
FAR struct task_group_s *group = tcb->group;
int ret = OK;
#ifndef CONFIG_FDCLONE_DISABLE
FAR struct tcb_s *rtcb = this_task();
@@ -72,7 +72,7 @@ int group_setuptaskfiles(FAR struct task_tcb_s *tcb,
sched_trace_begin();
DEBUGASSERT(group);
#ifndef CONFIG_DISABLE_PTHREAD
DEBUGASSERT((tcb->cmn.flags & TCB_FLAG_TTYPE_MASK) !=
DEBUGASSERT((tcb->flags & TCB_FLAG_TTYPE_MASK) !=
TCB_FLAG_TTYPE_PTHREAD);
#endif
@@ -84,16 +84,16 @@ int group_setuptaskfiles(FAR struct task_tcb_s *tcb,
*/
if (group != rtcb->group &&
(tcb->cmn.flags & TCB_FLAG_TTYPE_MASK) != TCB_FLAG_TTYPE_KERNEL)
(tcb->flags & TCB_FLAG_TTYPE_MASK) != TCB_FLAG_TTYPE_KERNEL)
{
ret = fdlist_copy(&rtcb->group->tg_fdlist,
&group->tg_fdlist, actions, cloexec);
}
if (ret >= 0 && actions != NULL &&
(tcb->cmn.flags & TCB_FLAG_TTYPE_MASK) != TCB_FLAG_TTYPE_KERNEL)
(tcb->flags & TCB_FLAG_TTYPE_MASK) != TCB_FLAG_TTYPE_KERNEL)
{
ret = spawn_file_actions(&tcb->cmn, actions);
ret = spawn_file_actions(tcb, actions);
}
#endif
+3 -4
View File
@@ -445,7 +445,7 @@ static void idle_group_initialize(void)
/* Allocate the IDLE group */
DEBUGVERIFY(
group_allocate((FAR struct task_tcb_s *)tcb, tcb->flags));
group_allocate(tcb, tcb->flags));
/* Initialize the task join */
@@ -478,7 +478,7 @@ static void idle_group_initialize(void)
* of child status in the IDLE group.
*/
group_initialize((FAR struct task_tcb_s *)tcb);
group_initialize(tcb);
tcb->group->tg_flags = GROUP_FLAG_NOCLDWAIT | GROUP_FLAG_PRIVILEGED;
}
}
@@ -705,8 +705,7 @@ void nx_start(void)
{
/* Clone stdout, stderr, stdin from the CPU0 IDLE task. */
DEBUGVERIFY(group_setuptaskfiles(
(FAR struct task_tcb_s *)&g_idletcb[i], NULL, true));
DEBUGVERIFY(group_setuptaskfiles(&g_idletcb[i], NULL, true));
}
else
{
+3 -3
View File
@@ -44,13 +44,13 @@ struct tcb_s; /* Forward reference */
/* Task start-up */
void nxtask_start(void);
int nxtask_setup_stackargs(FAR struct task_tcb_s *tcb,
int nxtask_setup_stackargs(FAR struct tcb_s *tcb,
FAR const char *name,
FAR char * const argv[]);
int nxtask_setup_scheduler(FAR struct task_tcb_s *tcb, int priority,
int nxtask_setup_scheduler(FAR struct tcb_s *tcb, int priority,
start_t start, main_t main, uint8_t ttype);
#if CONFIG_TASK_NAME_SIZE > 0
void nxtask_setup_name(FAR struct task_tcb_s *tcb, FAR const char *name);
void nxtask_setup_name(FAR struct tcb_s *tcb, FAR const char *name);
#else
# define nxtask_setup_name(tcb, name)
#endif
+2 -3
View File
@@ -84,8 +84,7 @@ int nxthread_create(FAR const char *name, uint8_t ttype, int priority,
/* Allocate a TCB for the new task. */
tcb = kmm_zalloc(ttype == TCB_FLAG_TTYPE_KERNEL ?
sizeof(struct tcb_s) : sizeof(struct task_tcb_s));
tcb = kmm_zalloc(sizeof(struct tcb_s));
if (!tcb)
{
serr("ERROR: Failed to allocate TCB\n");
@@ -98,7 +97,7 @@ int nxthread_create(FAR const char *name, uint8_t ttype, int priority,
/* Initialize the task */
ret = nxtask_init((FAR struct task_tcb_s *)tcb, name, priority,
ret = nxtask_init(tcb, name, priority,
stack_addr, stack_size, entry, argv, envp, NULL);
if (ret < OK)
{
+17 -18
View File
@@ -93,11 +93,11 @@
*
****************************************************************************/
FAR struct task_tcb_s *nxtask_setup_fork(start_t retaddr)
FAR struct tcb_s *nxtask_setup_fork(start_t retaddr)
{
FAR struct tcb_s *ptcb = this_task();
FAR struct tcb_s *parent;
FAR struct task_tcb_s *child;
FAR struct tcb_s *child;
FAR char **argv;
size_t stack_size;
uint8_t ttype;
@@ -137,7 +137,7 @@ FAR struct task_tcb_s *nxtask_setup_fork(start_t retaddr)
/* Allocate a TCB for the child task. */
child = kmm_zalloc(sizeof(struct task_tcb_s));
child = kmm_zalloc(sizeof(struct tcb_s) + sizeof(struct task_group_s));
if (!child)
{
serr("ERROR: Failed to allocate TCB\n");
@@ -145,14 +145,14 @@ FAR struct task_tcb_s *nxtask_setup_fork(start_t retaddr)
goto errout;
}
child->cmn.flags |= TCB_FLAG_FREE_TCB;
child->flags |= TCB_FLAG_FREE_TCB;
#if defined(CONFIG_ARCH_ADDRENV)
/* Join the parent address environment (REVISIT: vfork() only) */
if (ttype != TCB_FLAG_TTYPE_KERNEL)
{
ret = addrenv_join(parent, &child->cmn);
ret = addrenv_join(parent, child);
if (ret < 0)
{
goto errout_with_tcb;
@@ -162,10 +162,10 @@ FAR struct task_tcb_s *nxtask_setup_fork(start_t retaddr)
/* Initialize the task join */
nxtask_joininit(&child->cmn);
nxtask_joininit(child);
#if !defined(CONFIG_DISABLE_PTHREAD) && !defined(CONFIG_PTHREAD_MUTEX_UNSAFE)
spin_lock_init(&child->cmn.mhead_lock);
spin_lock_init(&child->mhead_lock);
#endif
/* Allocate a new task group with the same privileges as the parent */
@@ -178,7 +178,7 @@ FAR struct task_tcb_s *nxtask_setup_fork(start_t retaddr)
/* Duplicate the parent tasks environment */
ret = env_dup(child->cmn.group, environ);
ret = env_dup(child->group, environ);
if (ret < 0)
{
goto errout_with_tcb;
@@ -202,7 +202,7 @@ FAR struct task_tcb_s *nxtask_setup_fork(start_t retaddr)
stack_size = (uintptr_t)ptcb->stack_base_ptr -
(uintptr_t)ptcb->stack_alloc_ptr + ptcb->adj_stack_size;
ret = up_create_stack(&child->cmn, stack_size, ttype);
ret = up_create_stack(child, stack_size, ttype);
if (ret < OK)
{
goto errout_with_tcb;
@@ -213,7 +213,7 @@ FAR struct task_tcb_s *nxtask_setup_fork(start_t retaddr)
if (ttype != TCB_FLAG_TTYPE_KERNEL)
{
ret = up_addrenv_kstackalloc(&child->cmn);
ret = up_addrenv_kstackalloc(child);
if (ret < 0)
{
goto errout_with_tcb;
@@ -223,7 +223,7 @@ FAR struct task_tcb_s *nxtask_setup_fork(start_t retaddr)
/* Setup thread local storage */
ret = tls_dup_info(&child->cmn, parent);
ret = tls_dup_info(child, parent);
if (ret < OK)
{
goto errout_with_tcb;
@@ -301,7 +301,7 @@ errout:
* 6) nxtask_start_fork() then executes the child thread.
*
* Input Parameters:
* child - The task_tcb_s struct instance that created by
* child - The tcb_s struct instance that created by
* nxtask_setup_fork() method
* wait_child - whether need to wait until the child is running finished
*
@@ -313,7 +313,7 @@ errout:
*
****************************************************************************/
pid_t nxtask_start_fork(FAR struct task_tcb_s *child)
pid_t nxtask_start_fork(FAR struct tcb_s *child)
{
pid_t pid;
@@ -322,11 +322,11 @@ pid_t nxtask_start_fork(FAR struct task_tcb_s *child)
/* Get the assigned pid before we start the task */
pid = child->cmn.pid;
pid = child->pid;
/* Activate the task */
nxtask_activate((FAR struct tcb_s *)child);
nxtask_activate(child);
return pid;
}
@@ -342,7 +342,7 @@ pid_t nxtask_start_fork(FAR struct task_tcb_s *child)
*
****************************************************************************/
void nxtask_abort_fork(FAR struct task_tcb_s *child, int errcode)
void nxtask_abort_fork(FAR struct tcb_s *child, int errcode)
{
/* The TCB was added to the active task list by nxtask_setup_scheduler() */
@@ -350,8 +350,7 @@ void nxtask_abort_fork(FAR struct task_tcb_s *child, int errcode)
/* Release the TCB */
nxsched_release_tcb((FAR struct tcb_s *)child,
child->cmn.flags & TCB_FLAG_TTYPE_MASK);
nxsched_release_tcb(child, child->flags & TCB_FLAG_TTYPE_MASK);
set_errno(errcode);
}
+16 -17
View File
@@ -85,13 +85,13 @@
*
****************************************************************************/
int nxtask_init(FAR struct task_tcb_s *tcb, const char *name, int priority,
int nxtask_init(FAR struct tcb_s *tcb, const char *name, int priority,
FAR void *stack, uint32_t stack_size,
main_t entry, FAR char * const argv[],
FAR char * const envp[],
FAR const posix_spawn_file_actions_t *actions)
{
uint8_t ttype = tcb->cmn.flags & TCB_FLAG_TTYPE_MASK;
uint8_t ttype = tcb->flags & TCB_FLAG_TTYPE_MASK;
int ret;
sched_trace_begin();
@@ -107,13 +107,13 @@ int nxtask_init(FAR struct task_tcb_s *tcb, const char *name, int priority,
if (ttype == TCB_FLAG_TTYPE_KERNEL)
{
tcb->cmn.addrenv_own = NULL;
tcb->addrenv_own = NULL;
}
#endif
/* Create a new task group */
ret = group_allocate(tcb, tcb->cmn.flags);
ret = group_allocate(tcb, tcb->flags);
if (ret < 0)
{
sched_trace_end();
@@ -123,16 +123,16 @@ int nxtask_init(FAR struct task_tcb_s *tcb, const char *name, int priority,
#ifndef CONFIG_DISABLE_PTHREAD
/* Initialize the task join */
nxtask_joininit(&tcb->cmn);
nxtask_joininit(tcb);
#endif
#if !defined(CONFIG_DISABLE_PTHREAD) && !defined(CONFIG_PTHREAD_MUTEX_UNSAFE)
spin_lock_init(&tcb->cmn.mhead_lock);
spin_lock_init(&tcb->mhead_lock);
#endif
/* Duplicate the parent tasks environment */
ret = env_dup(tcb->cmn.group, envp);
ret = env_dup(tcb->group, envp);
if (ret < 0)
{
goto errout_with_group;
@@ -154,13 +154,13 @@ int nxtask_init(FAR struct task_tcb_s *tcb, const char *name, int priority,
{
/* Use pre-allocated stack */
ret = up_use_stack(&tcb->cmn, stack, stack_size);
ret = up_use_stack(tcb, stack, stack_size);
}
else
{
/* Allocate the stack for the TCB */
ret = up_create_stack(&tcb->cmn, stack_size, ttype);
ret = up_create_stack(tcb, stack_size, ttype);
}
if (ret < OK)
@@ -179,7 +179,7 @@ int nxtask_init(FAR struct task_tcb_s *tcb, const char *name, int priority,
/* Initialize thread local storage */
ret = tls_init_info(&tcb->cmn);
ret = tls_init_info(tcb);
if (ret < OK)
{
goto errout_with_group;
@@ -200,7 +200,7 @@ int nxtask_init(FAR struct task_tcb_s *tcb, const char *name, int priority,
return ret;
errout_with_group:
if (!stack && tcb->cmn.stack_alloc_ptr)
if (!stack && tcb->stack_alloc_ptr)
{
#ifdef CONFIG_BUILD_KERNEL
/* If the exiting thread is not a kernel thread, then it has an
@@ -216,13 +216,13 @@ errout_with_group:
if (ttype == TCB_FLAG_TTYPE_KERNEL)
#endif
{
up_release_stack(&tcb->cmn, ttype);
up_release_stack(tcb, ttype);
}
}
nxtask_joindestroy(&tcb->cmn);
nxtask_joindestroy(tcb);
group_leave(&tcb->cmn);
group_leave(tcb);
sched_trace_end();
return ret;
@@ -247,7 +247,7 @@ errout_with_group:
*
****************************************************************************/
void nxtask_uninit(FAR struct task_tcb_s *tcb)
void nxtask_uninit(FAR struct tcb_s *tcb)
{
/* The TCB was added to the inactive task list by
* nxtask_setup_scheduler().
@@ -259,6 +259,5 @@ void nxtask_uninit(FAR struct task_tcb_s *tcb)
* itself.
*/
nxsched_release_tcb((FAR struct tcb_s *)tcb,
tcb->cmn.flags & TCB_FLAG_TTYPE_MASK);
nxsched_release_tcb(tcb, tcb->flags & TCB_FLAG_TTYPE_MASK);
}
+7 -7
View File
@@ -516,7 +516,7 @@ static int nxthread_setup_scheduler(FAR struct tcb_s *tcb, int priority,
*
****************************************************************************/
int nxtask_setup_stackargs(FAR struct task_tcb_s *tcb,
int nxtask_setup_stackargs(FAR struct tcb_s *tcb,
FAR const char *name,
FAR char * const argv[])
{
@@ -557,8 +557,8 @@ int nxtask_setup_stackargs(FAR struct task_tcb_s *tcb,
*/
strtablen += (strlen(argv[argc]) + 1);
DEBUGASSERT(strtablen < tcb->cmn.adj_stack_size);
if (strtablen >= tcb->cmn.adj_stack_size)
DEBUGASSERT(strtablen < tcb->adj_stack_size);
if (strtablen >= tcb->adj_stack_size)
{
return -ENAMETOOLONG;
}
@@ -583,7 +583,7 @@ int nxtask_setup_stackargs(FAR struct task_tcb_s *tcb,
*/
argvlen = (argc + 2) * sizeof(FAR char *);
stackargv = (FAR char **)up_stack_frame(&tcb->cmn, argvlen + strtablen);
stackargv = (FAR char **)up_stack_frame(tcb, argvlen + strtablen);
DEBUGASSERT(stackargv != NULL);
if (stackargv == NULL)
@@ -658,7 +658,7 @@ int nxtask_setup_stackargs(FAR struct task_tcb_s *tcb,
*
****************************************************************************/
int nxtask_setup_scheduler(FAR struct task_tcb_s *tcb, int priority,
int nxtask_setup_scheduler(FAR struct tcb_s *tcb, int priority,
start_t start, main_t main, uint8_t ttype)
{
/* Perform common thread setup */
@@ -719,9 +719,9 @@ int pthread_setup_scheduler(FAR struct pthread_tcb_s *tcb, int priority,
****************************************************************************/
#if CONFIG_TASK_NAME_SIZE > 0
void nxtask_setup_name(FAR struct task_tcb_s *tcb, FAR const char *name)
void nxtask_setup_name(FAR struct tcb_s *tcb, FAR const char *name)
{
FAR char *dst = tcb->cmn.name;
FAR char *dst = tcb->name;
int i;
/* Give a name to the unnamed tasks */
+5 -5
View File
@@ -86,13 +86,13 @@ static int nxtask_spawn_create(FAR const char *name, int priority,
FAR const posix_spawn_file_actions_t *actions,
FAR const posix_spawnattr_t *attr)
{
FAR struct task_tcb_s *tcb;
FAR struct tcb_s *tcb;
pid_t pid;
int ret;
/* Allocate a TCB for the new task. */
tcb = kmm_zalloc(sizeof(struct task_tcb_s));
tcb = kmm_zalloc(sizeof(struct tcb_s));
if (tcb == NULL)
{
serr("ERROR: Failed to allocate TCB\n");
@@ -101,7 +101,7 @@ static int nxtask_spawn_create(FAR const char *name, int priority,
/* Setup the task type */
tcb->cmn.flags = TCB_FLAG_TTYPE_TASK | TCB_FLAG_FREE_TCB;
tcb->flags = TCB_FLAG_TTYPE_TASK | TCB_FLAG_FREE_TCB;
/* Initialize the task */
@@ -115,7 +115,7 @@ static int nxtask_spawn_create(FAR const char *name, int priority,
/* Get the assigned pid before we start the task */
pid = tcb->cmn.pid;
pid = tcb->pid;
/* Set the attributes */
@@ -130,7 +130,7 @@ static int nxtask_spawn_create(FAR const char *name, int priority,
/* Activate the task */
nxtask_activate(&tcb->cmn);
nxtask_activate(tcb);
return pid;