drivers/tty/sysrq.c
Source file repositories/reference/linux-study-clean/drivers/tty/sysrq.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/tty/sysrq.c- Extension
.c- Size
- 29557 bytes
- Lines
- 1260
- Domain
- Driver Families
- Bucket
- drivers/tty
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/sched/signal.hlinux/sched/rt.hlinux/sched/debug.hlinux/sched/task.hlinux/ctype.hlinux/interrupt.hlinux/mm.hlinux/fs.hlinux/mount.hlinux/kdev_t.hlinux/major.hlinux/reboot.hlinux/sysrq.hlinux/kbd_kern.hlinux/proc_fs.hlinux/nmi.hlinux/quotaops.hlinux/perf_event.hlinux/kernel.hlinux/module.hlinux/suspend.hlinux/writeback.hlinux/swap.hlinux/spinlock.hlinux/vt_kern.hlinux/workqueue.hlinux/hrtimer.hlinux/oom.hlinux/slab.hlinux/input.hlinux/uaccess.hlinux/moduleparam.h
Detected Declarations
struct sysrq_statefunction sysrq_onfunction sysrq_maskfunction sysrq_on_maskfunction sysrq_always_enabled_setupfunction sysrq_handle_loglevelfunction sysrq_handle_SAKfunction sysrq_handle_unrawfunction sysrq_handle_crashfunction sysrq_handle_rebootfunction sysrq_handle_syncfunction sysrq_handle_show_timersfunction sysrq_handle_mountrofunction sysrq_handle_showlocksfunction showacpufunction sysrq_showregs_othercpusfunction sysrq_handle_showallcpusfunction sysrq_handle_showregsfunction sysrq_handle_showstatefunction sysrq_handle_showstate_blockedfunction sysrq_ftrace_dumpfunction sysrq_handle_showmemfunction send_sig_allfunction sysrq_handle_termfunction moom_callbackfunction sysrq_handle_moomfunction sysrq_handle_thawfunction sysrq_handle_killfunction sysrq_handle_unrtfunction sysrq_handle_replay_logsfunction sysrq_key_table_key2indexfunction __sysrq_put_key_opfunction __handle_sysrqfunction operationsfunction handle_sysrqfunction sysrq_parse_reset_sequencefunction sysrq_do_resetfunction sysrq_handle_reset_requestfunction sysrq_detect_reset_sequencefunction sysrq_of_get_keyreset_configfunction of_property_for_each_u32function sysrq_of_get_keyreset_configfunction sysrq_handle_keypressfunction sysrq_filterfunction sysrq_connectfunction sysrq_disconnectfunction sysrq_register_handlerfunction sysrq_unregister_handler
Annotated Snippet
subsys_initcall(init_sysrq_sysctl);
static int __sysrq_swap_key_ops(u8 key, const struct sysrq_key_op *insert_op_p,
const struct sysrq_key_op *remove_op_p)
{
int retval;
spin_lock(&sysrq_key_table_lock);
if (__sysrq_get_key_op(key) == remove_op_p) {
__sysrq_put_key_op(key, insert_op_p);
retval = 0;
} else {
retval = -1;
}
spin_unlock(&sysrq_key_table_lock);
/*
* A concurrent __handle_sysrq either got the old op or the new op.
* Wait for it to go away before returning, so the code for an old
* op is not freed (eg. on module unload) while it is in use.
*/
synchronize_rcu();
return retval;
}
int register_sysrq_key(u8 key, const struct sysrq_key_op *op_p)
{
return __sysrq_swap_key_ops(key, op_p, NULL);
}
EXPORT_SYMBOL(register_sysrq_key);
int unregister_sysrq_key(u8 key, const struct sysrq_key_op *op_p)
{
return __sysrq_swap_key_ops(key, NULL, op_p);
}
EXPORT_SYMBOL(unregister_sysrq_key);
#ifdef CONFIG_PROC_FS
/*
* writing 'C' to /proc/sysrq-trigger is like sysrq-C
* Normally, only the first character written is processed.
* However, if the first character is an underscore,
* all characters are processed.
*/
static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
size_t count, loff_t *ppos)
{
bool bulk = false;
size_t i;
for (i = 0; i < count; i++) {
char c;
if (get_user(c, buf + i))
return -EFAULT;
if (c == '_')
bulk = true;
else
__handle_sysrq(c, false);
if (!bulk)
break;
}
return count;
}
static const struct proc_ops sysrq_trigger_proc_ops = {
.proc_write = write_sysrq_trigger,
.proc_lseek = noop_llseek,
};
static void sysrq_init_procfs(void)
{
if (!proc_create("sysrq-trigger", S_IWUSR, NULL,
&sysrq_trigger_proc_ops))
pr_err("Failed to register proc interface\n");
}
#else
static inline void sysrq_init_procfs(void)
{
}
#endif /* CONFIG_PROC_FS */
static int __init sysrq_init(void)
Annotation
- Immediate include surface: `linux/sched/signal.h`, `linux/sched/rt.h`, `linux/sched/debug.h`, `linux/sched/task.h`, `linux/ctype.h`, `linux/interrupt.h`, `linux/mm.h`, `linux/fs.h`.
- Detected declarations: `struct sysrq_state`, `function sysrq_on`, `function sysrq_mask`, `function sysrq_on_mask`, `function sysrq_always_enabled_setup`, `function sysrq_handle_loglevel`, `function sysrq_handle_SAK`, `function sysrq_handle_unraw`, `function sysrq_handle_crash`, `function sysrq_handle_reboot`.
- Atlas domain: Driver Families / drivers/tty.
- Implementation status: integration implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.