Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 // Copyright (C) 2018 Joe Lawrence <joe.lawrence@redhat.com>
0003 
0004 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
0005 
0006 #include <linux/module.h>
0007 #include <linux/kernel.h>
0008 #include <linux/livepatch.h>
0009 
0010 static int replace;
0011 module_param(replace, int, 0644);
0012 MODULE_PARM_DESC(replace, "replace (default=0)");
0013 
0014 #include <linux/seq_file.h>
0015 static int livepatch_meminfo_proc_show(struct seq_file *m, void *v)
0016 {
0017     seq_printf(m, "%s: %s\n", THIS_MODULE->name,
0018            "this has been live patched");
0019     return 0;
0020 }
0021 
0022 static struct klp_func funcs[] = {
0023     {
0024         .old_name = "meminfo_proc_show",
0025         .new_func = livepatch_meminfo_proc_show,
0026     }, {}
0027 };
0028 
0029 static struct klp_object objs[] = {
0030     {
0031         /* name being NULL means vmlinux */
0032         .funcs = funcs,
0033     }, {}
0034 };
0035 
0036 static struct klp_patch patch = {
0037     .mod = THIS_MODULE,
0038     .objs = objs,
0039     /* set .replace in the init function below for demo purposes */
0040 };
0041 
0042 static int test_klp_atomic_replace_init(void)
0043 {
0044     patch.replace = replace;
0045     return klp_enable_patch(&patch);
0046 }
0047 
0048 static void test_klp_atomic_replace_exit(void)
0049 {
0050 }
0051 
0052 module_init(test_klp_atomic_replace_init);
0053 module_exit(test_klp_atomic_replace_exit);
0054 MODULE_LICENSE("GPL");
0055 MODULE_INFO(livepatch, "Y");
0056 MODULE_AUTHOR("Joe Lawrence <joe.lawrence@redhat.com>");
0057 MODULE_DESCRIPTION("Livepatch test: atomic replace");