diff --git a/drivers/note/notesnap_driver.c b/drivers/note/notesnap_driver.c index aaa067fba4e..603013ff274 100644 --- a/drivers/note/notesnap_driver.c +++ b/drivers/note/notesnap_driver.c @@ -26,6 +26,7 @@ #include #include +#include #include #include @@ -51,6 +52,7 @@ struct notesnap_chunk_s struct notesnap_s { struct note_driver_s driver; + struct notifier_block nb; size_t index; bool dumping; struct notesnap_chunk_s buffer[CONFIG_DRIVERS_NOTESNAP_NBUFFERS]; @@ -192,7 +194,10 @@ static inline void notesnap_common(FAR struct note_driver_s *drv, FAR struct tcb_s *tcb, uint8_t type, uintptr_t args) { - struct notesnap_s *snap = (struct notesnap_s *)drv; + FAR struct notesnap_s *snap = (FAR struct notesnap_s *)drv; + FAR struct notesnap_chunk_s *note; + size_t index; + if (snap->dumping) { return; @@ -200,9 +205,8 @@ static inline void notesnap_common(FAR struct note_driver_s *drv, /* Atomic operation, equivalent to snap.index++; */ - size_t index = atomic_fetch_add(&snap->index, 1); - FAR struct notesnap_chunk_s *note = - &snap->buffer[index % CONFIG_DRIVERS_NOTESNAP_NBUFFERS]; + index = atomic_fetch_add(&snap->index, 1); + note = &snap->buffer[index % CONFIG_DRIVERS_NOTESNAP_NBUFFERS]; note->type = type; #ifdef CONFIG_SMP @@ -337,6 +341,17 @@ static void notesnap_syscall_leave(FAR struct note_driver_s *drv, int nr, } #endif +static int notesnap_notifier(FAR struct notifier_block *nb, + unsigned long action, FAR void *data) +{ + if (action == PANIC_KERNEL) + { + notesnap_dump(); + } + + return 0; +} + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -347,6 +362,8 @@ static void notesnap_syscall_leave(FAR struct note_driver_s *drv, int nr, int notesnap_register(void) { + g_notesnap.nb.notifier_call = notesnap_notifier; + panic_notifier_chain_register(&g_notesnap.nb); return note_driver_register(&g_notesnap.driver); }