15
15
#include "memfault/ports/zephyr/version.h"
16
16
17
17
#if MEMFAULT_ZEPHYR_VERSION_GT (2 , 1 )
18
- #include <arch/arm/aarch32/cortex_m/cmsis.h>
18
+ #include <arch/arm/aarch32/cortex_m/cmsis.h>
19
19
#else
20
- #include <arch/arm/cortex_m/cmsis.h>
20
+ #include <arch/arm/cortex_m/cmsis.h>
21
21
#endif
22
22
23
23
#include "memfault/core/compiler.h"
24
24
#include "memfault/core/math.h"
25
25
#include "memfault/ports/zephyr/coredump.h"
26
26
27
- static sMfltCoredumpRegion s_coredump_regions [
28
- MEMFAULT_COREDUMP_MAX_TASK_REGIONS
29
- + 2 /* active stack(s) */
30
- + 1 /* _kernel variable */
31
- + 1 /* s_task_watermarks */
32
- + 1 /* s_task_tcbs */
33
- #if CONFIG_MEMFAULT_COREDUMP_COLLECT_DATA_REGIONS
34
- + 1
35
- #endif
36
- #if CONFIG_MEMFAULT_COREDUMP_COLLECT_BSS_REGIONS
37
- + 1
38
- #endif
39
- ];
40
-
41
- MEMFAULT_WEAK
42
- const sMfltCoredumpRegion * memfault_platform_coredump_get_regions (
43
- const sCoredumpCrashInfo * crash_info , size_t * num_regions ) {
27
+ size_t memfault_zephyr_coredump_get_regions (const sCoredumpCrashInfo * crash_info ,
28
+ sMfltCoredumpRegion * regions , size_t num_regions ) {
29
+ // Check that regions is valid and has enough space to store all required regions
30
+ if (regions == NULL || num_regions < MEMFAULT_ZEPHYR_COREDUMP_REGIONS ) {
31
+ return 0 ;
32
+ }
44
33
45
34
const bool msp_was_active = (crash_info -> exception_reg_state -> exc_return & (1 << 2 )) == 0 ;
46
- int region_idx = 0 ;
35
+ size_t region_idx = 0 ;
47
36
48
37
size_t stack_size_to_collect = memfault_platform_sanitize_address_range (
49
- crash_info -> stack_address , CONFIG_MEMFAULT_COREDUMP_STACK_SIZE_TO_COLLECT );
38
+ crash_info -> stack_address , CONFIG_MEMFAULT_COREDUMP_STACK_SIZE_TO_COLLECT );
50
39
51
- s_coredump_regions [region_idx ] = MEMFAULT_COREDUMP_MEMORY_REGION_INIT (
52
- crash_info -> stack_address , stack_size_to_collect );
40
+ regions [region_idx ] =
41
+ MEMFAULT_COREDUMP_MEMORY_REGION_INIT ( crash_info -> stack_address , stack_size_to_collect );
53
42
region_idx ++ ;
54
43
55
44
if (msp_was_active ) {
@@ -60,19 +49,15 @@ const sMfltCoredumpRegion *memfault_platform_coredump_get_regions(
60
49
// exception frame that will have been stacked on it as well
61
50
const uint32_t extra_stack_bytes = 128 ;
62
51
stack_size_to_collect = memfault_platform_sanitize_address_range (
63
- psp , CONFIG_MEMFAULT_COREDUMP_STACK_SIZE_TO_COLLECT + extra_stack_bytes );
64
- s_coredump_regions [region_idx ] = MEMFAULT_COREDUMP_MEMORY_REGION_INIT (
65
- psp , stack_size_to_collect );
52
+ psp , CONFIG_MEMFAULT_COREDUMP_STACK_SIZE_TO_COLLECT + extra_stack_bytes );
53
+ regions [region_idx ] = MEMFAULT_COREDUMP_MEMORY_REGION_INIT (psp , stack_size_to_collect );
66
54
region_idx ++ ;
67
55
}
68
56
69
- s_coredump_regions [region_idx ] = MEMFAULT_COREDUMP_MEMORY_REGION_INIT (
70
- & _kernel , sizeof (_kernel ));
57
+ regions [region_idx ] = MEMFAULT_COREDUMP_MEMORY_REGION_INIT (& _kernel , sizeof (_kernel ));
71
58
region_idx ++ ;
72
59
73
- region_idx += memfault_zephyr_get_task_regions (
74
- & s_coredump_regions [region_idx ],
75
- MEMFAULT_ARRAY_SIZE (s_coredump_regions ) - region_idx );
60
+ region_idx += memfault_zephyr_get_task_regions (& regions [region_idx ], num_regions - region_idx );
76
61
77
62
//
78
63
// Now that we have captured all the task state, we will
@@ -81,15 +66,22 @@ const sMfltCoredumpRegion *memfault_platform_coredump_get_regions(
81
66
//
82
67
83
68
#if CONFIG_MEMFAULT_COREDUMP_COLLECT_DATA_REGIONS
84
- region_idx += memfault_zephyr_get_data_regions (
85
- & s_coredump_regions [region_idx ], MEMFAULT_ARRAY_SIZE (s_coredump_regions ) - region_idx );
69
+ region_idx += memfault_zephyr_get_data_regions (& regions [region_idx ], num_regions - region_idx );
86
70
#endif
87
71
88
72
#if CONFIG_MEMFAULT_COREDUMP_COLLECT_BSS_REGIONS
89
- region_idx += memfault_zephyr_get_bss_regions (
90
- & s_coredump_regions [region_idx ], MEMFAULT_ARRAY_SIZE (s_coredump_regions ) - region_idx );
73
+ region_idx += memfault_zephyr_get_bss_regions (& regions [region_idx ], num_regions - region_idx );
91
74
#endif
92
75
93
- * num_regions = region_idx ;
76
+ return region_idx ;
77
+ }
78
+
79
+ MEMFAULT_WEAK
80
+ const sMfltCoredumpRegion * memfault_platform_coredump_get_regions (
81
+ const sCoredumpCrashInfo * crash_info , size_t * num_regions ) {
82
+ static sMfltCoredumpRegion s_coredump_regions [MEMFAULT_ZEPHYR_COREDUMP_REGIONS ];
83
+
84
+ * num_regions = memfault_zephyr_coredump_get_regions (crash_info , s_coredump_regions ,
85
+ MEMFAULT_ARRAY_SIZE (s_coredump_regions ));
94
86
return & s_coredump_regions [0 ];
95
87
}
0 commit comments