linux/drivers/tty/sysrq.c

// SPDX-License-Identifier: GPL-2.0
/*
 *	Linux Magic System Request Key Hacks
 *
 *	(c) 1997 Martin Mares <[email protected]>
 *	based on ideas by Pavel Machek <[email protected]>
 *
 *	(c) 2000 Crutcher Dunnavant <[email protected]>
 *	overhauled to use key registration
 *	based upon discusions in irc://irc.openprojects.net/#kernelnewbies
 *
 *	Copyright (c) 2010 Dmitry Torokhov
 *	Input handler conversion
 */

#define pr_fmt(fmt)

#include <linux/sched/signal.h>
#include <linux/sched/rt.h>
#include <linux/sched/debug.h>
#include <linux/sched/task.h>
#include <linux/ctype.h>
#include <linux/interrupt.h>
#include <linux/mm.h>
#include <linux/fs.h>
#include <linux/mount.h>
#include <linux/kdev_t.h>
#include <linux/major.h>
#include <linux/reboot.h>
#include <linux/sysrq.h>
#include <linux/kbd_kern.h>
#include <linux/proc_fs.h>
#include <linux/nmi.h>
#include <linux/quotaops.h>
#include <linux/perf_event.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/suspend.h>
#include <linux/writeback.h>
#include <linux/swap.h>
#include <linux/spinlock.h>
#include <linux/vt_kern.h>
#include <linux/workqueue.h>
#include <linux/hrtimer.h>
#include <linux/oom.h>
#include <linux/slab.h>
#include <linux/input.h>
#include <linux/uaccess.h>
#include <linux/moduleparam.h>
#include <linux/jiffies.h>
#include <linux/syscalls.h>
#include <linux/of.h>
#include <linux/rcupdate.h>

#include <asm/ptrace.h>
#include <asm/irq_regs.h>

/* Whether we react on sysrq keys or just ignore them */
static int __read_mostly sysrq_enabled =;
static bool __read_mostly sysrq_always_enabled;

static bool sysrq_on(void)
{}

/**
 * sysrq_mask - Getter for sysrq_enabled mask.
 *
 * Return: 1 if sysrq is always enabled, enabled sysrq_key_op mask otherwise.
 */
int sysrq_mask(void)
{}
EXPORT_SYMBOL_GPL();

/*
 * A value of 1 means 'all', other nonzero values are an op mask:
 */
static bool sysrq_on_mask(int mask)
{}

static int __init sysrq_always_enabled_setup(char *str)
{}

__setup();


static void sysrq_handle_loglevel(u8 key)
{}
static const struct sysrq_key_op sysrq_loglevel_op =;

#ifdef CONFIG_VT
static void sysrq_handle_SAK(u8 key)
{}
static const struct sysrq_key_op sysrq_SAK_op =;
#else
#define sysrq_SAK_op
#endif

#ifdef CONFIG_VT
static void sysrq_handle_unraw(u8 key)
{}

static const struct sysrq_key_op sysrq_unraw_op =;
#else
#define sysrq_unraw_op
#endif /* CONFIG_VT */

static void sysrq_handle_crash(u8 key)
{}
static const struct sysrq_key_op sysrq_crash_op =;

static void sysrq_handle_reboot(u8 key)
{}
static const struct sysrq_key_op sysrq_reboot_op =;

const struct sysrq_key_op *__sysrq_reboot_op =;

static void sysrq_handle_sync(u8 key)
{}
static const struct sysrq_key_op sysrq_sync_op =;

static void sysrq_handle_show_timers(u8 key)
{}

static const struct sysrq_key_op sysrq_show_timers_op =;

static void sysrq_handle_mountro(u8 key)
{}
static const struct sysrq_key_op sysrq_mountro_op =;

#ifdef CONFIG_LOCKDEP
static void sysrq_handle_showlocks(u8 key)
{}

static const struct sysrq_key_op sysrq_showlocks_op =;
#else
#define sysrq_showlocks_op
#endif

#ifdef CONFIG_SMP
static DEFINE_RAW_SPINLOCK(show_lock);

static void showacpu(void *dummy)
{}

static void sysrq_showregs_othercpus(struct work_struct *dummy)
{}

static DECLARE_WORK(sysrq_showallcpus, sysrq_showregs_othercpus);

static void sysrq_handle_showallcpus(u8 key)
{}

static const struct sysrq_key_op sysrq_showallcpus_op =;
#else
#define sysrq_showallcpus_op
#endif

static void sysrq_handle_showregs(u8 key)
{}
static const struct sysrq_key_op sysrq_showregs_op =;

static void sysrq_handle_showstate(u8 key)
{}
static const struct sysrq_key_op sysrq_showstate_op =;

static void sysrq_handle_showstate_blocked(u8 key)
{}
static const struct sysrq_key_op sysrq_showstate_blocked_op =;

#ifdef CONFIG_TRACING
#include <linux/ftrace.h>

static void sysrq_ftrace_dump(u8 key)
{}
static const struct sysrq_key_op sysrq_ftrace_dump_op =;
#else
#define sysrq_ftrace_dump_op
#endif

static void sysrq_handle_showmem(u8 key)
{}
static const struct sysrq_key_op sysrq_showmem_op =;

/*
 * Signal sysrq helper function.  Sends a signal to all user processes.
 */
static void send_sig_all(int sig)
{}

static void sysrq_handle_term(u8 key)
{}
static const struct sysrq_key_op sysrq_term_op =;

static void moom_callback(struct work_struct *ignored)
{}

static DECLARE_WORK(moom_work, moom_callback);

static void sysrq_handle_moom(u8 key)
{}
static const struct sysrq_key_op sysrq_moom_op =;

#ifdef CONFIG_BLOCK
static void sysrq_handle_thaw(u8 key)
{}
static const struct sysrq_key_op sysrq_thaw_op =;
#else
#define sysrq_thaw_op
#endif

static void sysrq_handle_kill(u8 key)
{}
static const struct sysrq_key_op sysrq_kill_op =;

static void sysrq_handle_unrt(u8 key)
{}
static const struct sysrq_key_op sysrq_unrt_op =;

static void sysrq_handle_replay_logs(u8 key)
{}
static struct sysrq_key_op sysrq_replay_logs_op =;

/* Key Operations table and lock */
static DEFINE_SPINLOCK(sysrq_key_table_lock);

static const struct sysrq_key_op *sysrq_key_table[62] =;

/* key2index calculation, -1 on invalid index */
static int sysrq_key_table_key2index(u8 key)
{}

/*
 * get and put functions for the table, exposed to modules.
 */
static const struct sysrq_key_op *__sysrq_get_key_op(u8 key)
{}

static void __sysrq_put_key_op(u8 key, const struct sysrq_key_op *op_p)
{}

void __handle_sysrq(u8 key, bool check_mask)
{}

void handle_sysrq(u8 key)
{}
EXPORT_SYMBOL();

#ifdef CONFIG_INPUT
static int sysrq_reset_downtime_ms;

/* Simple translation table for the SysRq keys */
static const unsigned char sysrq_xlate[KEY_CNT] =;                                      /* 0x60 - 0x6f */

struct sysrq_state {};

#define SYSRQ_KEY_RESET_MAX
static unsigned short sysrq_reset_seq[SYSRQ_KEY_RESET_MAX];
static unsigned int sysrq_reset_seq_len;
static unsigned int sysrq_reset_seq_version =;

static void sysrq_parse_reset_sequence(struct sysrq_state *state)
{}

static void sysrq_do_reset(struct timer_list *t)
{}

static void sysrq_handle_reset_request(struct sysrq_state *state)
{}

static void sysrq_detect_reset_sequence(struct sysrq_state *state,
					unsigned int code, int value)
{}

#ifdef CONFIG_OF
static void sysrq_of_get_keyreset_config(void)
{}
#else
static void sysrq_of_get_keyreset_config(void)
{
}
#endif

static void sysrq_reinject_alt_sysrq(struct work_struct *work)
{}

static bool sysrq_handle_keypress(struct sysrq_state *sysrq,
				  unsigned int code, int value)
{}

static bool sysrq_filter(struct input_handle *handle,
			 unsigned int type, unsigned int code, int value)
{}

static int sysrq_connect(struct input_handler *handler,
			 struct input_dev *dev,
			 const struct input_device_id *id)
{}

static void sysrq_disconnect(struct input_handle *handle)
{}

/*
 * We are matching on KEY_LEFTALT instead of KEY_SYSRQ because not all
 * keyboards have SysRq key predefined and so user may add it to keymap
 * later, but we expect all such keyboards to have left alt.
 */
static const struct input_device_id sysrq_ids[] =;

static struct input_handler sysrq_handler =;

static inline void sysrq_register_handler(void)
{}

static inline void sysrq_unregister_handler(void)
{}

static int sysrq_reset_seq_param_set(const char *buffer,
				     const struct kernel_param *kp)
{}

static const struct kernel_param_ops param_ops_sysrq_reset_seq =;

#define param_check_sysrq_reset_seq(name, p)

/*
 * not really modular, but the easiest way to keep compat with existing
 * bootargs behaviour is to continue using module_param here.
 */
module_param_array_named();

module_param_named(sysrq_downtime_ms, sysrq_reset_downtime_ms, int, 0644);

#else

static inline void sysrq_register_handler(void)
{
}

static inline void sysrq_unregister_handler(void)
{
}

#endif /* CONFIG_INPUT */

int sysrq_toggle_support(int enable_mask)
{}
EXPORT_SYMBOL_GPL();

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 register_sysrq_key(u8 key, const struct sysrq_key_op *op_p)
{}
EXPORT_SYMBOL();

int unregister_sysrq_key(u8 key, const struct sysrq_key_op *op_p)
{}
EXPORT_SYMBOL();

#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)
{}

static const struct proc_ops sysrq_trigger_proc_ops =;

static void sysrq_init_procfs(void)
{}

#else

static inline void sysrq_init_procfs(void)
{
}

#endif /* CONFIG_PROC_FS */

static int __init sysrq_init(void)
{}
device_initcall(sysrq_init);