dep.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. Exports the lkmc_dep which dep2.ko uses.
  3. insmod /dep.ko
  4. # dmesg => 0
  5. # dmesg => 0
  6. # dmesg => ...
  7. insmod /dep2.ko
  8. # dmesg => 1
  9. # dmesg => 2
  10. # dmesg => ...
  11. rmmod dep
  12. # Fails because dep2 uses it.
  13. rmmod dep2
  14. # Dmesg stops incrementing.
  15. rmmod dep
  16. sys visibility:
  17. dmesg -n 1
  18. insmod /dep.ko
  19. insmod /dep2.ko
  20. ls -l /sys/module/dep/holders
  21. # => ../../dep2
  22. cat refcnt
  23. # => 1
  24. proc visibility:
  25. grep lkmc_dep /proc/kallsyms
  26. Requires "CONFIG_KALLSYMS_ALL=y".
  27. depmod:
  28. grep dep "/lib/module/"*"/depmod"
  29. # extra/dep2.ko: extra/dep.ko
  30. # extra/dep.ko:
  31. modprobe dep
  32. # lsmod
  33. # Both dep and dep2 were loaded.
  34. TODO: at what point does buildroot / busybox generate that file?
  35. */
  36. #include <linux/delay.h> /* usleep_range */
  37. #include <linux/kernel.h>
  38. #include <linux/kthread.h>
  39. #include <linux/module.h>
  40. int lkmc_dep = 0;
  41. EXPORT_SYMBOL(lkmc_dep);
  42. static struct task_struct *kthread;
  43. static int work_func(void *data)
  44. {
  45. while (!kthread_should_stop()) {
  46. pr_info("%d\n", lkmc_dep);
  47. usleep_range(1000000, 1000001);
  48. }
  49. return 0;
  50. }
  51. static int myinit(void)
  52. {
  53. kthread = kthread_create(work_func, NULL, "mykthread");
  54. wake_up_process(kthread);
  55. return 0;
  56. }
  57. static void myexit(void)
  58. {
  59. kthread_stop(kthread);
  60. }
  61. module_init(myinit)
  62. module_exit(myexit)
  63. MODULE_LICENSE("GPL");