root/lib/livepatch/test_klp_atomic_replace.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. livepatch_meminfo_proc_show
  2. test_klp_atomic_replace_init
  3. test_klp_atomic_replace_exit

   1 // SPDX-License-Identifier: GPL-2.0
   2 // Copyright (C) 2018 Joe Lawrence <joe.lawrence@redhat.com>
   3 
   4 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
   5 
   6 #include <linux/module.h>
   7 #include <linux/kernel.h>
   8 #include <linux/livepatch.h>
   9 
  10 static int replace;
  11 module_param(replace, int, 0644);
  12 MODULE_PARM_DESC(replace, "replace (default=0)");
  13 
  14 #include <linux/seq_file.h>
  15 static int livepatch_meminfo_proc_show(struct seq_file *m, void *v)
  16 {
  17         seq_printf(m, "%s: %s\n", THIS_MODULE->name,
  18                    "this has been live patched");
  19         return 0;
  20 }
  21 
  22 static struct klp_func funcs[] = {
  23         {
  24                 .old_name = "meminfo_proc_show",
  25                 .new_func = livepatch_meminfo_proc_show,
  26         }, {}
  27 };
  28 
  29 static struct klp_object objs[] = {
  30         {
  31                 /* name being NULL means vmlinux */
  32                 .funcs = funcs,
  33         }, {}
  34 };
  35 
  36 static struct klp_patch patch = {
  37         .mod = THIS_MODULE,
  38         .objs = objs,
  39         /* set .replace in the init function below for demo purposes */
  40 };
  41 
  42 static int test_klp_atomic_replace_init(void)
  43 {
  44         patch.replace = replace;
  45         return klp_enable_patch(&patch);
  46 }
  47 
  48 static void test_klp_atomic_replace_exit(void)
  49 {
  50 }
  51 
  52 module_init(test_klp_atomic_replace_init);
  53 module_exit(test_klp_atomic_replace_exit);
  54 MODULE_LICENSE("GPL");
  55 MODULE_INFO(livepatch, "Y");
  56 MODULE_AUTHOR("Joe Lawrence <joe.lawrence@redhat.com>");
  57 MODULE_DESCRIPTION("Livepatch test: atomic replace");

/* [<][>][^][v][top][bottom][index][help] */