[Sound-open-firmware] [PATCH] panic: fix panic_dump_stack()

Liam Girdwood liam.r.girdwood at linux.intel.com
Thu Dec 21 18:18:59 CET 2017


Fix so that dump stack does not overwrite any debug data and does not
read past the end of the stack.

Signed-off-by: Liam Girdwood <liam.r.girdwood at linux.intel.com>
---
 src/include/reef/debug.h | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/src/include/reef/debug.h b/src/include/reef/debug.h
index 7551fc5..85f91d4 100644
--- a/src/include/reef/debug.h
+++ b/src/include/reef/debug.h
@@ -46,6 +46,7 @@
 #define PANIC_TASK	5
 #define PANIC_EXCEPTION	6
 #define PANIC_DEADLOCK	7
+#define PANIC_STACK	8
 
 #define DEBUG
 
@@ -144,26 +145,26 @@
 	} while (0);
 
 /* dump stack as part of panic */
-/* TODO: rework to make this generic - the stack top can be moved to arch code */
 #define panic_dump_stack(_p) \
 	do { \
 		extern uint32_t __stack; \
 		extern uint32_t _stack_sentry; \
 		uint32_t _stack_bottom = (uint32_t)&__stack; \
 		uint32_t _stack_limit = (uint32_t)&_stack_sentry; \
-		uint32_t _stack_top; \
-		\
-		__asm__ __volatile__ ("mov %0, a1" : "=a" (_stack_top) : : "memory"); \
+		uint32_t _stack_top = arch_get_stack_ptr(); \
+		uint32_t _size = _stack_bottom - _stack_top; \
+		uint32_t _panic = _p; \
 		dbg_val(0xdead0000 | _p) \
-		platform_panic(_p); \
-		dbg_val(_stack_top) \
-		dbg_val(_stack_bottom) \
-		\
+		dbg_val_at(_stack_top, 1) \
+		dbg_val_at(_stack_bottom, 2) \
+		/* is stack smashed ? */\
 		if (_stack_bottom <= _stack_limit) { \
-			dbg_val(0x51ac0000 | _p) \
+			dbg_val_at(0x51ac0000 | _p, 3); \
 			_stack_bottom = _stack_limit; \
+			_panic = PANIC_STACK; \
 		} \
-		dump(_stack_top, _stack_bottom - _stack_top) \
+		platform_panic(_panic); \
+		dump_at(_stack_top, (_size - sizeof(uint32_t)) >> 2, 4) \
 		\
 		while(1) {}; \
 	} while (0);
-- 
2.14.1



More information about the Sound-open-firmware mailing list