Pages

2010-09-08

Linux: Catching Die Notification in the Linux Kernel

A die notification (die_chain), is sent when a kernel function triggers a trap or a fault, caused by an oops, page fault, or a breakpoint hit. To catch such event we do:
#include <linux/notifier.h>
#include <asm/kdebug.h> 
static struct notifier_block my_die_notifier = 
{
  .notifier_call = my_die_event_handler,
};

int my_die_event_handler(struct notifier_block *self, unsigned long val, void *data)
{
  struct die_args *args = (struct die_args *) data;
  if (val == 1) /* oops */

  { 
    printk("my_die_event: OOPs! at EIP=%lx\n", args->regs->eip);
  } 
  return 0;
}
/* ... */ 
register_die_notifier(&my_die_notifier);

No comments:

Post a Comment