linux/samples/hw_breakpoint/data_breakpoint.c

// SPDX-License-Identifier: GPL-2.0-or-later
/*
 * data_breakpoint.c - Sample HW Breakpoint file to watch kernel data address
 *
 * usage: insmod data_breakpoint.ko ksym=<ksym_name>
 *
 * This file is a kernel module that places a breakpoint over ksym_name kernel
 * variable using Hardware Breakpoint register. The corresponding handler which
 * prints a backtrace is invoked every time a write operation is performed on
 * that variable.
 *
 * Copyright (C) IBM Corporation, 2009
 *
 * Author: K.Prasad <[email protected]>
 */
#include <linux/module.h>	/* Needed by all modules */
#include <linux/kernel.h>	/* Needed for KERN_INFO */
#include <linux/init.h>		/* Needed for the macros */
#include <linux/kallsyms.h>

#include <linux/perf_event.h>
#include <linux/hw_breakpoint.h>

static struct perf_event * __percpu *sample_hbp;

static char ksym_name[KSYM_NAME_LEN] =;
module_param_string();
MODULE_PARM_DESC();

static void sample_hbp_handler(struct perf_event *bp,
			       struct perf_sample_data *data,
			       struct pt_regs *regs)
{}

static int __init hw_break_module_init(void)
{}

static void __exit hw_break_module_exit(void)
{}

module_init(hw_break_module_init);
module_exit(hw_break_module_exit);

MODULE_LICENSE();
MODULE_AUTHOR();
MODULE_DESCRIPTION();