arch/assert: flush the syslog before stack dump

flush the syslog before stack dump to avoid buffer overwrite

Signed-off-by: chao.an <anchao@xiaomi.com>
This commit is contained in:
chao.an 2021-12-15 19:40:52 +08:00 committed by Xiang Xiao
parent ed1e4ddfa7
commit b11833cbba
22 changed files with 107 additions and 8 deletions

View File

@ -77,6 +77,10 @@ static void up_stackdump(uint32_t sp, uint32_t stack_top)
{ {
uint32_t stack; uint32_t stack;
/* Flush any buffered SYSLOG data to avoid overwrite */
syslog_flush();
for (stack = sp & ~0x1f; stack < (stack_top & ~0x1f); stack += 32) for (stack = sp & ~0x1f; stack < (stack_top & ~0x1f); stack += 32)
{ {
uint32_t *ptr = (uint32_t *)stack; uint32_t *ptr = (uint32_t *)stack;

View File

@ -76,6 +76,10 @@ static void up_stackdump(uint32_t sp, uint32_t stack_top)
{ {
uint32_t stack; uint32_t stack;
/* Flush any buffered SYSLOG data to avoid overwrite */
syslog_flush();
for (stack = sp & ~0x1f; stack < (stack_top & ~0x1f); stack += 32) for (stack = sp & ~0x1f; stack < (stack_top & ~0x1f); stack += 32)
{ {
uint32_t *ptr = (uint32_t *)stack; uint32_t *ptr = (uint32_t *)stack;

View File

@ -79,6 +79,10 @@ static void up_stackdump(uint32_t sp, uint32_t stack_top)
{ {
uint32_t stack; uint32_t stack;
/* Flush any buffered SYSLOG data to avoid overwrite */
syslog_flush();
for (stack = sp & ~0x1f; stack < (stack_top & ~0x1f); stack += 32) for (stack = sp & ~0x1f; stack < (stack_top & ~0x1f); stack += 32)
{ {
uint32_t *ptr = (uint32_t *)stack; uint32_t *ptr = (uint32_t *)stack;

View File

@ -79,6 +79,10 @@ static void up_stackdump(uint32_t sp, uint32_t stack_top)
{ {
uint32_t stack; uint32_t stack;
/* Flush any buffered SYSLOG data to avoid overwrite */
syslog_flush();
for (stack = sp & ~0x1f; stack < (stack_top & ~0x1f); stack += 32) for (stack = sp & ~0x1f; stack < (stack_top & ~0x1f); stack += 32)
{ {
uint32_t *ptr = (uint32_t *)stack; uint32_t *ptr = (uint32_t *)stack;

View File

@ -76,6 +76,10 @@ static void up_stackdump(uint32_t sp, uint32_t stack_top)
{ {
uint32_t stack; uint32_t stack;
/* Flush any buffered SYSLOG data to avoid overwrite */
syslog_flush();
for (stack = sp & ~0x1f; stack < (stack_top & ~0x1f); stack += 32) for (stack = sp & ~0x1f; stack < (stack_top & ~0x1f); stack += 32)
{ {
uint32_t *ptr = (uint32_t *)stack; uint32_t *ptr = (uint32_t *)stack;

View File

@ -79,6 +79,10 @@ static void up_stackdump(uint32_t sp, uint32_t stack_top)
{ {
uint32_t stack; uint32_t stack;
/* Flush any buffered SYSLOG data to avoid overwrite */
syslog_flush();
for (stack = sp & ~0x1f; stack < (stack_top & ~0x1f); stack += 32) for (stack = sp & ~0x1f; stack < (stack_top & ~0x1f); stack += 32)
{ {
uint32_t *ptr = (uint32_t *)stack; uint32_t *ptr = (uint32_t *)stack;

View File

@ -31,6 +31,7 @@
#include <nuttx/irq.h> #include <nuttx/irq.h>
#include <nuttx/arch.h> #include <nuttx/arch.h>
#include <nuttx/syslog/syslog.h>
#include <arch/board/board.h> #include <arch/board/board.h>
#include "up_arch.h" #include "up_arch.h"
@ -51,7 +52,11 @@ static void up_stackdump(uint16_t sp, uint16_t stack_top)
{ {
uint16_t stack; uint16_t stack;
for (stack = sp & ~3; stack < (stack_top & ~0x1f); stack += 12) /* Flush any buffered SYSLOG data to avoid overwrite */
syslog_flush();
for (stack = sp & ~0x3; stack < (stack_top & ~0x3); stack += 12)
{ {
uint8_t *ptr = (uint8_t *)stack; uint8_t *ptr = (uint8_t *)stack;
_alert("%04x: %02x %02x %02x %02x %02x %02x %02x %02x" _alert("%04x: %02x %02x %02x %02x %02x %02x %02x %02x"

View File

@ -31,6 +31,7 @@
#include <nuttx/irq.h> #include <nuttx/irq.h>
#include <nuttx/arch.h> #include <nuttx/arch.h>
#include <nuttx/syslog/syslog.h>
#include <arch/board/board.h> #include <arch/board/board.h>
#include "up_arch.h" #include "up_arch.h"
@ -51,6 +52,10 @@ static void up_stackdump(uint32_t sp, uint32_t stack_top)
{ {
uint32_t stack; uint32_t stack;
/* Flush any buffered SYSLOG data to avoid overwrite */
syslog_flush();
for (stack = sp & ~0x1f; stack < (stack_top & ~0x1f); stack += 32) for (stack = sp & ~0x1f; stack < (stack_top & ~0x1f); stack += 32)
{ {
uint32_t *ptr = (uint32_t *)stack; uint32_t *ptr = (uint32_t *)stack;

View File

@ -76,7 +76,11 @@ static void up_stackdump(uint16_t sp, uint16_t stack_top)
{ {
uint16_t stack; uint16_t stack;
for (stack = sp; stack < (stack_top & ~0x1f); stack += 16) /* Flush any buffered SYSLOG data to avoid overwrite */
syslog_flush();
for (stack = sp & ~0x1f; stack < (stack_top & ~0x1f); stack += 16)
{ {
uint8_t *ptr = (uint8_t *)stack; uint8_t *ptr = (uint8_t *)stack;

View File

@ -32,6 +32,7 @@
#include <nuttx/irq.h> #include <nuttx/irq.h>
#include <nuttx/arch.h> #include <nuttx/arch.h>
#include <nuttx/syslog/syslog.h>
#include <arch/board/board.h> #include <arch/board/board.h>
#include "mips_arch.h" #include "mips_arch.h"
@ -52,6 +53,10 @@ static void up_stackdump(uint32_t sp, uint32_t stack_top)
{ {
uint32_t stack; uint32_t stack;
/* Flush any buffered SYSLOG data to avoid overwrite */
syslog_flush();
for (stack = sp & ~0x1f; stack < (stack_top & ~0x1f); stack += 32) for (stack = sp & ~0x1f; stack < (stack_top & ~0x1f); stack += 32)
{ {
uint32_t *ptr = (uint32_t *)stack; uint32_t *ptr = (uint32_t *)stack;

View File

@ -31,6 +31,7 @@
#include <nuttx/irq.h> #include <nuttx/irq.h>
#include <nuttx/arch.h> #include <nuttx/arch.h>
#include <nuttx/syslog/syslog.h>
#include <arch/board/board.h> #include <arch/board/board.h>
#include "sched/sched.h" #include "sched/sched.h"
@ -50,6 +51,10 @@ static void up_stackdump(uint32_t sp, uint32_t stack_top)
{ {
uint32_t stack; uint32_t stack;
/* Flush any buffered SYSLOG data to avoid overwrite */
syslog_flush();
for (stack = sp & ~0x1f; stack < (stack_top & ~0x1f); stack += 32) for (stack = sp & ~0x1f; stack < (stack_top & ~0x1f); stack += 32)
{ {
uint32_t *ptr = (uint32_t *)stack; uint32_t *ptr = (uint32_t *)stack;

View File

@ -31,6 +31,7 @@
#include <nuttx/irq.h> #include <nuttx/irq.h>
#include <nuttx/arch.h> #include <nuttx/arch.h>
#include <nuttx/syslog/syslog.h>
#include <arch/board/board.h> #include <arch/board/board.h>
#include "sched/sched.h" #include "sched/sched.h"
@ -50,6 +51,10 @@ static void up_stackdump(uint32_t sp, uint32_t stack_top)
{ {
uint32_t stack; uint32_t stack;
/* Flush any buffered SYSLOG data to avoid overwrite */
syslog_flush();
for (stack = sp & ~0x1f; stack < (stack_top & ~0x1f); stack += 32) for (stack = sp & ~0x1f; stack < (stack_top & ~0x1f); stack += 32)
{ {
uint32_t *ptr = (uint32_t *) stack; uint32_t *ptr = (uint32_t *) stack;

View File

@ -32,6 +32,7 @@
#include <nuttx/irq.h> #include <nuttx/irq.h>
#include <nuttx/arch.h> #include <nuttx/arch.h>
#include <nuttx/board.h> #include <nuttx/board.h>
#include <nuttx/syslog/syslog.h>
#include <nuttx/usb/usbdev_trace.h> #include <nuttx/usb/usbdev_trace.h>
#include <arch/board/board.h> #include <arch/board/board.h>
@ -75,6 +76,10 @@ static void up_stackdump(uint32_t sp, uint32_t stack_top)
{ {
uint32_t stack; uint32_t stack;
/* Flush any buffered SYSLOG data to avoid overwrite */
syslog_flush();
for (stack = sp & ~0x1f; stack < (stack_top & ~0x1f); stack += 32) for (stack = sp & ~0x1f; stack < (stack_top & ~0x1f); stack += 32)
{ {
uint32_t *ptr = (uint32_t *)stack; uint32_t *ptr = (uint32_t *)stack;

View File

@ -29,6 +29,7 @@
#include <nuttx/irq.h> #include <nuttx/irq.h>
#include <nuttx/arch.h> #include <nuttx/arch.h>
#include <nuttx/syslog/syslog.h>
#include "up_arch.h" #include "up_arch.h"
#include "up_internal.h" #include "up_internal.h"
@ -67,7 +68,11 @@ static void m16c_stackdump(uint16_t sp, uint16_t stack_top)
{ {
uint16_t stack; uint16_t stack;
for (stack = sp & ~7; stack < stack_top; stack += 8) /* Flush any buffered SYSLOG data to avoid overwrite */
syslog_flush();
for (stack = sp & ~7; stack < (stack_top & ~7); stack += 8)
{ {
uint8_t *ptr = (uint8_t *)stack; uint8_t *ptr = (uint8_t *)stack;
_alert("%04x: %02x %02x %02x %02x %02x %02x %02x %02x\n", _alert("%04x: %02x %02x %02x %02x %02x %02x %02x %02x\n",

View File

@ -30,6 +30,7 @@
#include <nuttx/irq.h> #include <nuttx/irq.h>
#include <nuttx/arch.h> #include <nuttx/arch.h>
#include <nuttx/syslog/syslog.h>
#include "up_arch.h" #include "up_arch.h"
#include "up_internal.h" #include "up_internal.h"
@ -69,7 +70,11 @@ static void rx65n_stackdump(uint16_t sp, uint16_t stack_top)
{ {
uint16_t stack; uint16_t stack;
for (stack = sp & ~7; stack < stack_top; stack += 8) /* check */ /* Flush any buffered SYSLOG data to avoid overwrite */
syslog_flush();
for (stack = sp & ~7; stack < (stack_top & ~7); stack += 8) /* check */
{ {
uint8_t *ptr = (uint8_t *)&stack; uint8_t *ptr = (uint8_t *)&stack;

View File

@ -29,6 +29,7 @@
#include <nuttx/irq.h> #include <nuttx/irq.h>
#include <nuttx/arch.h> #include <nuttx/arch.h>
#include <nuttx/syslog/syslog.h>
#include "up_arch.h" #include "up_arch.h"
#include "up_internal.h" #include "up_internal.h"
@ -54,7 +55,11 @@ static void sh1_stackdump(uint32_t sp, uint32_t stack_top)
{ {
uint32_t stack; uint32_t stack;
for (stack = sp & ~0x1f; stack < stack_top; stack += 32) /* Flush any buffered SYSLOG data to avoid overwrite */
syslog_flush();
for (stack = sp & ~0x1f; stack < (stack_top & ~0x1f); stack += 32)
{ {
uint32_t *ptr = (uint32_t *)stack; uint32_t *ptr = (uint32_t *)stack;
_alert("%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n", _alert("%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",

View File

@ -72,7 +72,11 @@ static void riscv_stackdump(uint32_t sp, uint32_t stack_top)
{ {
uint32_t stack; uint32_t stack;
for (stack = sp & ~0x1f; stack < stack_top; stack += 32) /* Flush any buffered SYSLOG data to avoid overwrite */
syslog_flush();
for (stack = sp & ~0x1f; stack < (stack_top & ~0x1f); stack += 32)
{ {
uint32_t *ptr = (uint32_t *)stack; uint32_t *ptr = (uint32_t *)stack;
_alert("%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n", _alert("%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",

View File

@ -75,6 +75,10 @@ static void up_stackdump(uint64_t sp, uintptr_t stack_top)
{ {
uintptr_t stack; uintptr_t stack;
/* Flush any buffered SYSLOG data to avoid overwrite */
syslog_flush();
for (stack = sp & ~0x1f; stack < (stack_top & ~0x1f); stack += 32) for (stack = sp & ~0x1f; stack < (stack_top & ~0x1f); stack += 32)
{ {
uint32_t *ptr = (uint32_t *)stack; uint32_t *ptr = (uint32_t *)stack;

View File

@ -77,6 +77,10 @@ static void up_stackdump(uint32_t sp, uint32_t stack_top)
{ {
uint32_t stack; uint32_t stack;
/* Flush any buffered SYSLOG data to avoid overwrite */
syslog_flush();
for (stack = sp & ~0x1f; stack < (stack_top & ~0x1f); stack += 32) for (stack = sp & ~0x1f; stack < (stack_top & ~0x1f); stack += 32)
{ {
uint32_t *ptr = (uint32_t *)stack; uint32_t *ptr = (uint32_t *)stack;

View File

@ -69,6 +69,10 @@ static void up_stackdump(uint64_t sp, uint64_t stack_top)
{ {
uint64_t stack; uint64_t stack;
/* Flush any buffered SYSLOG data to avoid overwrite */
syslog_flush();
for (stack = sp & ~0x1f; stack < (stack_top & ~0x1f); stack += 32) for (stack = sp & ~0x1f; stack < (stack_top & ~0x1f); stack += 32)
{ {
uint32_t *ptr = (uint32_t *)stack; uint32_t *ptr = (uint32_t *)stack;

View File

@ -31,6 +31,7 @@
#include <nuttx/irq.h> #include <nuttx/irq.h>
#include <nuttx/arch.h> #include <nuttx/arch.h>
#include <nuttx/syslog/syslog.h>
#include <arch/xtensa/xtensa_corebits.h> #include <arch/xtensa/xtensa_corebits.h>
#include <arch/board/board.h> #include <arch/board/board.h>
@ -102,7 +103,11 @@ static void xtensa_stackdump(uint32_t sp, uint32_t stack_top)
{ {
uint32_t stack; uint32_t stack;
for (stack = sp & ~0x1f; stack < stack_top; stack += 32) /* Flush any buffered SYSLOG data to avoid overwrite */
syslog_flush();
for (stack = sp & ~0x1f; stack < (stack_top & ~0x1f); stack += 32)
{ {
uint32_t *ptr = (uint32_t *)stack; uint32_t *ptr = (uint32_t *)stack;
_alert("%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n", _alert("%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",

View File

@ -23,6 +23,7 @@
****************************************************************************/ ****************************************************************************/
#include <nuttx/config.h> #include <nuttx/config.h>
#include <nuttx/syslog/syslog.h>
#include <debug.h> #include <debug.h>
@ -68,8 +69,12 @@ static void z16_stackdump(void)
stack = stack_base; stack = stack_base;
} }
/* Flush any buffered SYSLOG data to avoid overwrite */
syslog_flush();
for (stack = stack & ~0x0f; for (stack = stack & ~0x0f;
stack < stack_base + stack_size; stack < ((stack_base + stack_size) & ~0x0f);
stack += 8 * sizeof(chipreg_t)) stack += 8 * sizeof(chipreg_t))
{ {
chipreg_t *ptr = (chipreg_t *)stack; chipreg_t *ptr = (chipreg_t *)stack;