From 6d12ee19e24c3d3f31cede92b06960d66bfd7685 Mon Sep 17 00:00:00 2001 From: Abdelatif Guettouche Date: Wed, 13 Apr 2022 13:34:42 +0200 Subject: [PATCH] arch: Move the DUMP_ON_EXIT logic after nxtask_exit. Otherwise we will try to dump the state of the current task, however the exit handler has already started doing some cleanup and invalidated its group. Accessing the group from dumponexit will crash. Signed-off-by: Abdelatif Guettouche --- arch/arm/src/common/arm_exit.c | 8 ++++---- arch/avr/src/common/up_exit.c | 8 ++++---- arch/hc/src/common/up_exit.c | 8 ++++---- arch/mips/src/common/mips_exit.c | 8 ++++---- arch/misoc/src/lm32/lm32_exit.c | 8 ++++---- arch/misoc/src/minerva/minerva_exit.c | 8 ++++---- arch/or1k/src/common/up_exit.c | 8 ++++---- arch/renesas/src/common/up_exit.c | 8 ++++---- arch/risc-v/src/common/riscv_exit.c | 8 ++++---- arch/sparc/src/common/up_exit.c | 10 +++++----- arch/x86/src/common/up_exit.c | 8 ++++---- arch/x86_64/src/common/up_exit.c | 8 ++++---- arch/xtensa/src/common/xtensa_exit.c | 10 +++++----- arch/z16/src/common/z16_exit.c | 8 ++++---- arch/z80/src/common/z80_exit.c | 8 ++++---- 15 files changed, 62 insertions(+), 62 deletions(-) diff --git a/arch/arm/src/common/arm_exit.c b/arch/arm/src/common/arm_exit.c index c44c4cf1041..a998a15851a 100644 --- a/arch/arm/src/common/arm_exit.c +++ b/arch/arm/src/common/arm_exit.c @@ -115,15 +115,15 @@ void up_exit(int status) sinfo("TCB=%p exiting\n", tcb); + /* Destroy the task at the head of the ready to run list. */ + + nxtask_exit(); + #ifdef CONFIG_DUMP_ON_EXIT sinfo("Other tasks:\n"); nxsched_foreach(_up_dumponexit, NULL); #endif - /* Destroy the task at the head of the ready to run list. */ - - nxtask_exit(); - /* Now, perform the context switch to the new ready-to-run task at the * head of the list. */ diff --git a/arch/avr/src/common/up_exit.c b/arch/avr/src/common/up_exit.c index 98ac5160d42..e0c9664e7a6 100644 --- a/arch/avr/src/common/up_exit.c +++ b/arch/avr/src/common/up_exit.c @@ -114,15 +114,15 @@ void up_exit(int status) sinfo("TCB=%p exiting\n", tcb); + /* Destroy the task at the head of the ready to run list. */ + + nxtask_exit(); + #ifdef CONFIG_DUMP_ON_EXIT sinfo("Other tasks:\n"); nxsched_foreach(_up_dumponexit, NULL); #endif - /* Destroy the task at the head of the ready to run list. */ - - nxtask_exit(); - /* Now, perform the context switch to the new ready-to-run task at the * head of the list. */ diff --git a/arch/hc/src/common/up_exit.c b/arch/hc/src/common/up_exit.c index 3ba7affd606..3e92f8936b3 100644 --- a/arch/hc/src/common/up_exit.c +++ b/arch/hc/src/common/up_exit.c @@ -114,15 +114,15 @@ void up_exit(int status) sinfo("TCB=%p exiting\n", tcb); + /* Destroy the task at the head of the ready to run list. */ + + nxtask_exit(); + #ifdef CONFIG_DUMP_ON_EXIT sinfo("Other tasks:\n"); nxsched_foreach(_up_dumponexit, NULL); #endif - /* Destroy the task at the head of the ready to run list. */ - - nxtask_exit(); - /* Now, perform the context switch to the new ready-to-run task at the * head of the list. */ diff --git a/arch/mips/src/common/mips_exit.c b/arch/mips/src/common/mips_exit.c index dd17b8d436e..b28dbd24c23 100644 --- a/arch/mips/src/common/mips_exit.c +++ b/arch/mips/src/common/mips_exit.c @@ -116,15 +116,15 @@ void up_exit(int status) sinfo("TCB=%p exiting\n", tcb); + /* Destroy the task at the head of the ready to run list. */ + + nxtask_exit(); + #ifdef CONFIG_DUMP_ON_EXIT sinfo("Other tasks:\n"); nxsched_foreach(_up_dumponexit, NULL); #endif - /* Destroy the task at the head of the ready to run list. */ - - nxtask_exit(); - /* Now, perform the context switch to the new ready-to-run task at the * head of the list. */ diff --git a/arch/misoc/src/lm32/lm32_exit.c b/arch/misoc/src/lm32/lm32_exit.c index 3474bafb350..fb75de94d3f 100644 --- a/arch/misoc/src/lm32/lm32_exit.c +++ b/arch/misoc/src/lm32/lm32_exit.c @@ -108,15 +108,15 @@ void up_exit(int status) sinfo("TCB=%p exiting\n", tcb); + /* Destroy the task at the head of the ready to run list. */ + + nxtask_exit(); + #ifdef CONFIG_DUMP_ON_EXIT sinfo("Other tasks:\n"); nxsched_foreach(_up_dumponexit, NULL); #endif - /* Destroy the task at the head of the ready to run list. */ - - nxtask_exit(); - /* Now, perform the context switch to the new ready-to-run task at the * head of the list. */ diff --git a/arch/misoc/src/minerva/minerva_exit.c b/arch/misoc/src/minerva/minerva_exit.c index 814eaaeafd2..0be779b84ba 100644 --- a/arch/misoc/src/minerva/minerva_exit.c +++ b/arch/misoc/src/minerva/minerva_exit.c @@ -108,15 +108,15 @@ void up_exit(int status) sinfo("TCB=%p exiting\n", tcb); + /* Destroy the task at the head of the ready to run list. */ + + nxtask_exit(); + #ifdef CONFIG_DUMP_ON_EXIT sinfo("Other tasks:\n"); nxsched_foreach(_up_dumponexit, NULL); #endif - /* Destroy the task at the head of the ready to run list. */ - - nxtask_exit(); - /* Now, perform the context switch to the new ready-to-run task at the head * of the list. */ diff --git a/arch/or1k/src/common/up_exit.c b/arch/or1k/src/common/up_exit.c index 017b19e9154..ff68918b04c 100644 --- a/arch/or1k/src/common/up_exit.c +++ b/arch/or1k/src/common/up_exit.c @@ -115,15 +115,15 @@ void up_exit(int status) sinfo("TCB=%p exiting\n", tcb); + /* Destroy the task at the head of the ready to run list. */ + + nxtask_exit(); + #ifdef CONFIG_DUMP_ON_EXIT sinfo("Other tasks:\n"); nxsched_foreach(_up_dumponexit, NULL); #endif - /* Destroy the task at the head of the ready to run list. */ - - nxtask_exit(); - /* Now, perform the context switch to the new ready-to-run task at the * head of the list. */ diff --git a/arch/renesas/src/common/up_exit.c b/arch/renesas/src/common/up_exit.c index 9ef5347b5bb..6d78ba4dccd 100644 --- a/arch/renesas/src/common/up_exit.c +++ b/arch/renesas/src/common/up_exit.c @@ -114,15 +114,15 @@ void up_exit(int status) sinfo("TCB=%p exiting\n", tcb); + /* Destroy the task at the head of the ready to run list. */ + + nxtask_exit(); + #ifdef CONFIG_DUMP_ON_EXIT sinfo("Other tasks:\n"); nxsched_foreach(_up_dumponexit, NULL); #endif - /* Destroy the task at the head of the ready to run list. */ - - nxtask_exit(); - /* Now, perform the context switch to the new ready-to-run task at the * head of the list. */ diff --git a/arch/risc-v/src/common/riscv_exit.c b/arch/risc-v/src/common/riscv_exit.c index 10036e9116b..c6177f29b7e 100644 --- a/arch/risc-v/src/common/riscv_exit.c +++ b/arch/risc-v/src/common/riscv_exit.c @@ -116,15 +116,15 @@ void up_exit(int status) sinfo("TCB=%p exiting\n", tcb); + /* Destroy the task at the head of the ready to run list. */ + + nxtask_exit(); + #ifdef CONFIG_DUMP_ON_EXIT sinfo("Other tasks:\n"); nxsched_foreach(_up_dumponexit, NULL); #endif - /* Destroy the task at the head of the ready to run list. */ - - nxtask_exit(); - /* Now, perform the context switch to the new ready-to-run task at the * head of the list. */ diff --git a/arch/sparc/src/common/up_exit.c b/arch/sparc/src/common/up_exit.c index 808b69ece09..8f6a7d4e406 100644 --- a/arch/sparc/src/common/up_exit.c +++ b/arch/sparc/src/common/up_exit.c @@ -137,11 +137,6 @@ void up_exit(int status) sinfo("TCB=%p exiting\n", tcb); -#ifdef CONFIG_DUMP_ON_EXIT - sinfo("Other tasks:\n"); - sched_foreach(_up_dumponexit, NULL); -#endif - /* Update scheduler parameters */ nxsched_suspend_scheduler(tcb); @@ -150,6 +145,11 @@ void up_exit(int status) (void)nxtask_exit(); +#ifdef CONFIG_DUMP_ON_EXIT + sinfo("Other tasks:\n"); + sched_foreach(_up_dumponexit, NULL); +#endif + /* Now, perform the context switch to the new ready-to-run task at the * head of the list. */ diff --git a/arch/x86/src/common/up_exit.c b/arch/x86/src/common/up_exit.c index 82463648bb9..46864f2d5b0 100644 --- a/arch/x86/src/common/up_exit.c +++ b/arch/x86/src/common/up_exit.c @@ -114,15 +114,15 @@ void up_exit(int status) sinfo("TCB=%p exiting\n", tcb); + /* Destroy the task at the head of the ready to run list. */ + + nxtask_exit(); + #ifdef CONFIG_DUMP_ON_EXIT sinfo("Other tasks:\n"); nxsched_foreach(_up_dumponexit, NULL); #endif - /* Destroy the task at the head of the ready to run list. */ - - nxtask_exit(); - /* Now, perform the context switch to the new ready-to-run task at the * head of the list. */ diff --git a/arch/x86_64/src/common/up_exit.c b/arch/x86_64/src/common/up_exit.c index 3d4fd39e504..8671fcba97c 100644 --- a/arch/x86_64/src/common/up_exit.c +++ b/arch/x86_64/src/common/up_exit.c @@ -114,15 +114,15 @@ void up_exit(int status) sinfo("TCB=%p exiting\n", this_task()); + /* Destroy the task at the head of the ready to run list. */ + + nxtask_exit(); + #ifdef CONFIG_DUMP_ON_EXIT sinfo("Other tasks:\n"); nxsched_foreach(_up_dumponexit, NULL); #endif - /* Destroy the task at the head of the ready to run list. */ - - nxtask_exit(); - /* Now, perform the context switch to the new ready-to-run task at the * head of the list. */ diff --git a/arch/xtensa/src/common/xtensa_exit.c b/arch/xtensa/src/common/xtensa_exit.c index edc6d170489..612862de418 100644 --- a/arch/xtensa/src/common/xtensa_exit.c +++ b/arch/xtensa/src/common/xtensa_exit.c @@ -116,11 +116,6 @@ void up_exit(int status) sinfo("TCB=%p exiting\n", tcb); -#ifdef CONFIG_DUMP_ON_EXIT - sinfo("Other tasks:\n"); - nxsched_foreach(_xtensa_dumponexit, NULL); -#endif - #if XCHAL_CP_NUM > 0 /* Disable co-processor support for the task that is exit-ing. */ @@ -131,6 +126,11 @@ void up_exit(int status) nxtask_exit(); +#ifdef CONFIG_DUMP_ON_EXIT + sinfo("Other tasks:\n"); + nxsched_foreach(_xtensa_dumponexit, NULL); +#endif + /* Now, perform the context switch to the new ready-to-run task at the * head of the list. */ diff --git a/arch/z16/src/common/z16_exit.c b/arch/z16/src/common/z16_exit.c index ed072a62417..c7fc4d38b59 100644 --- a/arch/z16/src/common/z16_exit.c +++ b/arch/z16/src/common/z16_exit.c @@ -114,15 +114,15 @@ void up_exit(int status) sinfo("TCB=%p exiting\n", tcb); + /* Destroy the task at the head of the ready to run list. */ + + nxtask_exit(); + #ifdef CONFIG_DUMP_ON_EXIT sinfo("Other tasks:\n"); nxsched_foreach(_z16_dumponexit, NULL); #endif - /* Destroy the task at the head of the ready to run list. */ - - nxtask_exit(); - /* Now, perform the context switch to the new ready-to-run task at the * head of the list. */ diff --git a/arch/z80/src/common/z80_exit.c b/arch/z80/src/common/z80_exit.c index f1dece39a98..6843ba0ae8d 100644 --- a/arch/z80/src/common/z80_exit.c +++ b/arch/z80/src/common/z80_exit.c @@ -116,15 +116,15 @@ void up_exit(int status) sinfo("TCB=%p exiting\n", tcb); + /* Destroy the task at the head of the ready to run list. */ + + nxtask_exit(); + #ifdef CONFIG_DUMP_ON_EXIT sinfo("Other tasks:\n"); nxsched_foreach(_up_dumponexit, NULL); #endif - /* Destroy the task at the head of the ready to run list. */ - - nxtask_exit(); - /* Now, perform the context switch to the new ready-to-run task at the * head of the list. */