* I want to add SysRQ key events to a module, how does it work? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In order to register a basic function with the table, you must first include the header 'include/linux/sysrq.h', this will define everything else you need. Next, you must create a sysrq_key_op struct, and populate it with A) the key handler function you will use, B) a help_msg string, that will print when SysRQ prints help, and C) an action_msg string, that will print right before your handler is called. Your handler must conform to the prototype in 'sysrq.h'. After the sysrq_key_op is created, you can call the macro register_sysrq_key(int key, struct sysrq_key_op *op_p) that is defined in sysrq.h, this will register the operation pointed to by 'op_p' at table key 'key', if that slot in the table is blank. At module unload time, you must call the macro unregister_sysrq_key(int key, struct sysrq_key_op *op_p), which will remove the key op pointed to by 'op_p' from the key 'key', if and only if it is currently registered in that slot. This is in case the slot has been overwritten since you registered it. The Magic SysRQ system works by registering key operations against a key op lookup table, which is defined in 'drivers/char/sysrq.c'. This key table has a number of operations registered into it at compile time, but is mutable, and 4 functions are exported for interface to it: __sysrq_lock_table, __sysrq_unlock_table, __sysrq_get_key_op, and __sysrq_put_key_op. The functions __sysrq_swap_key_ops and __sysrq_swap_key_ops_nolock are defined in the header itself, and the REGISTER and UNREGISTER macros are built from these. More complex (and dangerous!) manipulations of the table are possible using these functions, but you must be careful to always lock the table before you read or write from it, and to unlock it again when you are done. (And of course, to never ever leave an invalid pointer in the table). Null pointers in the table are always safe :) If for some reason you feel the need to call the handle_sysrq function from within a function called by handle_sysrq, you must be aware that you are in a lock (you are also in an interrupt handler, which means don't sleep!), so you must call __handle_sysrq_nolock instead.