diff --git a/debug/Makefile b/debug/Makefile index c0acdb3..accb7f2 100644 --- a/debug/Makefile +++ b/debug/Makefile @@ -1 +1,4 @@ -obj-m += myled.o +obj-y += myled.o +obj-m += mycpuinfo.o +obj-m += hello.o +obj-m += buildchain.o regchain.o notify.o diff --git a/debug/buildchain.c b/debug/buildchain.c new file mode 100644 index 0000000..ca70f80 --- /dev/null +++ b/debug/buildchain.c @@ -0,0 +1,37 @@ +#include +#include +#include +static RAW_NOTIFIER_HEAD(test_chain); + +int register_test_notifier(struct notifier_block *nb) +{ + return raw_notifier_chain_register(&test_chain, nb); +} +EXPORT_SYMBOL(register_test_notifier); + +int unregister_test_notifier(struct notifier_block *nb) +{ + return raw_notifier_chain_unregister(&test_chain,nb); +} +EXPORT_SYMBOL(unregister_test_notifier); + +int test_notifier_call_chain(unsigned long val, void *v) +{ + return raw_notifier_call_chain(&test_chain, val, v); +} +EXPORT_SYMBOL(test_notifier_call_chain); + +static int __init init_notifier(void) +{ + printk("init_notifier\n"); + return 0; +} + +static void __exit exit_notifier(void) +{ + printk("exit_notifier\n"); +} + +module_init(init_notifier); +module_exit(exit_notifier); +MODULE_LICENSE("GPL"); diff --git a/debug/notify.c b/debug/notify.c new file mode 100644 index 0000000..270ef65 --- /dev/null +++ b/debug/notify.c @@ -0,0 +1,27 @@ +#include +#include +#include +extern int test_notifier_call_chain(unsigned long val, void*v); + +static int __init call_notifier(void) +{ + int err; + printk("Begin to notify:\n"); + + + printk("==============================\n"); + err = test_notifier_call_chain(1, NULL); + printk("==============================\n"); + if (err) + printk("notifier_call_chain error\n"); + return err; +} + +static void __exit uncall_notifier(void) +{ + printk("Endnotify\n"); +} + +module_init(call_notifier); +module_exit(uncall_notifier); +MODULE_LICENSE("GPL"); diff --git a/debug/regchain.c b/debug/regchain.c new file mode 100644 index 0000000..503fac5 --- /dev/null +++ b/debug/regchain.c @@ -0,0 +1,83 @@ +#include +#include +#include +extern int unregister_test_notifier(struct notifier_block*); +extern int register_test_notifier(struct notifier_block *nb); + +static int test_event1(struct notifier_block *this, unsigned long event, void *ptr) +{ + printk("In Event 1: Event Number is %ld\n",event); + return 0; +} + +static int test_event2(struct notifier_block *this, unsigned long event, void *ptr) +{ + printk("In Event 2: Event Number is %ld\n",event); + return 0; +} + +static int test_event3(struct notifier_block *this, unsigned long event, void *ptr) +{ + printk("In Event 3: Event Number is %ld\n",event); + return 0; +} + +static struct notifier_block test_notifier1 = +{ + .notifier_call = test_event1, +}; + +static struct notifier_block test_notifier2 = +{ + .notifier_call = test_event2, +}; + +static struct notifier_block test_notifier3 = +{ + .notifier_call = test_event3, +}; + +static int __init reg_notifier(void) +{ + int err; + printk("Begin to register:\n"); + + err = register_test_notifier(&test_notifier1); + if (err) + { + printk("register test_notifier1 error\n"); + return-1; + } + printk("register test_notifier1 completed\n"); + + err = register_test_notifier(&test_notifier2); + if (err) + { + printk("register test_notifier2 error\n"); + return-1; + } + printk("register test_notifier2 completed\n"); + + err = register_test_notifier(&test_notifier3); + if (err) + { + printk("register test_notifier3 error\n"); + return-1; + } + printk("register test_notifier3 completed\n"); + + return err; +} + +static void __exit unreg_notifier(void) +{ + printk("Begin to unregister\n"); + unregister_test_notifier(&test_notifier1); + unregister_test_notifier(&test_notifier2); + unregister_test_notifier(&test_notifier3); + printk("Unregister finished\n"); +} + +module_init(reg_notifier); +module_exit(unreg_notifier); +MODULE_LICENSE("GPL");