From f6b9a8f5777d07f094bc6a4977657173291e9428 Mon Sep 17 00:00:00 2001 From: wanggang26 Date: Fri, 20 Sep 2024 19:02:37 +0800 Subject: [PATCH] coredump: fix issue that nvic region overlapped by board memory region Firstly call arm_coredump_add_region in up_initialize to add nvic region, then call coredump_set_memory_region to add board mem region, at this moment, an overlap occurs. Signed-off-by: wanggang26 --- include/nuttx/coredump.h | 10 ---------- sched/misc/coredump.c | 31 ++++++++++++++++++++++--------- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/include/nuttx/coredump.h b/include/nuttx/coredump.h index dadfff66134..2cd687d7860 100644 --- a/include/nuttx/coredump.h +++ b/include/nuttx/coredump.h @@ -59,16 +59,6 @@ struct coredump_info_s * Public Function Prototypes ****************************************************************************/ -/**************************************************************************** - * Name: coredump_set_memory_region - * - * Description: - * Set do coredump memory region. - * - ****************************************************************************/ - -int coredump_set_memory_region(FAR const struct memory_region_s *region); - /**************************************************************************** * Name: coredump_add_memory_region * diff --git a/sched/misc/coredump.c b/sched/misc/coredump.c index 368346bb3a4..fc5a83e1ff7 100644 --- a/sched/misc/coredump.c +++ b/sched/misc/coredump.c @@ -765,19 +765,23 @@ static void coredump_dump_dev(pid_t pid) #endif /**************************************************************************** - * Name: coredump_set_memory_region + * Name: coredump_initialize_memory_region * * Description: - * Set do coredump memory region. + * initialize the memory region with board memory range specified in config * ****************************************************************************/ -int coredump_set_memory_region(FAR const struct memory_region_s *region) +static int coredump_initialize_memory_region(void) { - /* Not free g_regions, because allow call this fun when crash */ +#ifdef CONFIG_BOARD_MEMORY_RANGE + if (g_regions == NULL) + { + g_regions = g_memory_region; + } +#endif - g_regions = region; - return 0; + return OK; } /**************************************************************************** @@ -793,6 +797,13 @@ int coredump_add_memory_region(FAR const void *ptr, size_t size, { FAR struct memory_region_s *region; size_t count = 1; /* 1 for end flag */ + int ret; + + ret = coredump_initialize_memory_region(); + if (ret < 0) + { + return ret; + } if (g_regions != NULL) { @@ -881,9 +892,11 @@ int coredump_initialize(void) { int ret = 0; -#ifdef CONFIG_BOARD_MEMORY_RANGE - g_regions = g_memory_region; -#endif + ret = coredump_initialize_memory_region(); + if (ret < 0) + { + return ret; + } #ifdef CONFIG_BOARD_COREDUMP_BLKDEV ret = lib_blkoutstream_open(&g_devstream,