Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bulatov_i #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions tools/labs/skels/kernel_modules/1-2-test-mod/Kbuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ccflags-y = -Wno-unused-function -Wno-unused-label -Wno-unused-variable -DDEBUG

obj-m = hello_mod.o
21 changes: 21 additions & 0 deletions tools/labs/skels/kernel_modules/1-2-test-mod/hello_mod.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <linux/module.h>
#include <linux/init.h>
#include <linux/kernel.h>

MODULE_DESCRIPTION("Simple module");
MODULE_AUTHOR("Kernel Hacker");
MODULE_LICENSE("GPL");

static int my_hello_init(void)
{
pr_debug("Hello!\n");
return 0;
}

static void hello_exit(void)
{
pr_debug("Goodbye!\n");
}

module_init(my_hello_init);
module_exit(hello_exit);
Binary file not shown.
2 changes: 2 additions & 0 deletions tools/labs/skels/kernel_modules/1-2-test-mod/hello_mod.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/home/igor/linux/tools/labs/skels/./kernel_modules/1-2-test-mod/hello_mod.o

27 changes: 27 additions & 0 deletions tools/labs/skels/kernel_modules/1-2-test-mod/hello_mod.mod.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <linux/module.h>
#define INCLUDE_VERMAGIC
#include <linux/build-salt.h>
#include <linux/vermagic.h>
#include <linux/compiler.h>

BUILD_SALT;

MODULE_INFO(vermagic, VERMAGIC_STRING);
MODULE_INFO(name, KBUILD_MODNAME);

__visible struct module __this_module
__section(".gnu.linkonce.this_module") = {
.name = KBUILD_MODNAME,
.init = init_module,
#ifdef CONFIG_MODULE_UNLOAD
.exit = cleanup_module,
#endif
.arch = MODULE_ARCH_INIT,
};

#ifdef CONFIG_RETPOLINE
MODULE_INFO(retpoline, "Y");
#endif

MODULE_INFO(depends, "");

Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions tools/labs/skels/kernel_modules/1-2-test-mod/modules.order
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/home/igor/linux/tools/labs/skels/./kernel_modules/1-2-test-mod/hello_mod.ko
3 changes: 3 additions & 0 deletions tools/labs/skels/kernel_modules/3-error-mod/Kbuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ccflags-y = -Wno-unused-function -Wno-unused-label -Wno-unused-variable

obj-m = err_mod.o
26 changes: 26 additions & 0 deletions tools/labs/skels/kernel_modules/3-error-mod/err_mod.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <linux/module.h>
#include <linux/init.h>
#include <linux/kernel.h>
/* TODO: add missing kernel headers */

MODULE_DESCRIPTION("Error module");
MODULE_AUTHOR("Kernel Hacker");
MODULE_LICENSE("GPL");

static int n1, n2;

static int err_init(void)
{
n1 = 1; n2 = 2;
pr_info("n1 is %d, n2 is %d\n", n1, n2);

return 0;
}

static void err_exit(void)
{
pr_info("sum is %d\n", n1 + n2);
}

module_init(err_init);
module_exit(err_exit);
Binary file not shown.
2 changes: 2 additions & 0 deletions tools/labs/skels/kernel_modules/3-error-mod/err_mod.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/home/igor/linux/tools/labs/skels/./kernel_modules/3-error-mod/err_mod.o

27 changes: 27 additions & 0 deletions tools/labs/skels/kernel_modules/3-error-mod/err_mod.mod.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <linux/module.h>
#define INCLUDE_VERMAGIC
#include <linux/build-salt.h>
#include <linux/vermagic.h>
#include <linux/compiler.h>

BUILD_SALT;

MODULE_INFO(vermagic, VERMAGIC_STRING);
MODULE_INFO(name, KBUILD_MODNAME);

__visible struct module __this_module
__section(".gnu.linkonce.this_module") = {
.name = KBUILD_MODNAME,
.init = init_module,
#ifdef CONFIG_MODULE_UNLOAD
.exit = cleanup_module,
#endif
.arch = MODULE_ARCH_INIT,
};

#ifdef CONFIG_RETPOLINE
MODULE_INFO(retpoline, "Y");
#endif

MODULE_INFO(depends, "");

Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions tools/labs/skels/kernel_modules/3-error-mod/modules.order
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/home/igor/linux/tools/labs/skels/./kernel_modules/3-error-mod/err_mod.ko
8 changes: 8 additions & 0 deletions tools/labs/skels/kernel_modules/4-multi-mod/Kbuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
ccflags-y = -Wno-unused-function -Wno-unused-label -Wno-unused-variable

# TODO: add rules to create a multi object module

EXTRA_CFLAGS = -Wall -g

obj-m = supermodule.o
supermodule-y = mod1.o mod2.o
27 changes: 27 additions & 0 deletions tools/labs/skels/kernel_modules/4-multi-mod/mod1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <linux/module.h>
#include <linux/init.h>
#include <linux/kernel.h>

MODULE_DESCRIPTION("Multi-file module");
MODULE_AUTHOR("Kernel Hacker");
MODULE_LICENSE("GPL");

extern int add(int a, int b);

static int n1, n2;

static int my_hello_init(void)
{
n1 = 1; n2 = 2;
pr_info("n1 is %d, n2 is %d\n", n1, n2);

return 0;
}

static void hello_exit(void)
{
pr_info("sum is %d\n", add(n1, n2));
}

module_init(my_hello_init);
module_exit(hello_exit);
Binary file not shown.
4 changes: 4 additions & 0 deletions tools/labs/skels/kernel_modules/4-multi-mod/mod2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
int add(int a, int b)
{
return a + b;
}
Binary file not shown.
1 change: 1 addition & 0 deletions tools/labs/skels/kernel_modules/4-multi-mod/modules.order
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/home/igor/linux/tools/labs/skels/./kernel_modules/4-multi-mod/supermodule.ko
Binary file not shown.
2 changes: 2 additions & 0 deletions tools/labs/skels/kernel_modules/4-multi-mod/supermodule.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/home/igor/linux/tools/labs/skels/./kernel_modules/4-multi-mod/mod1.o /home/igor/linux/tools/labs/skels/./kernel_modules/4-multi-mod/mod2.o

27 changes: 27 additions & 0 deletions tools/labs/skels/kernel_modules/4-multi-mod/supermodule.mod.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <linux/module.h>
#define INCLUDE_VERMAGIC
#include <linux/build-salt.h>
#include <linux/vermagic.h>
#include <linux/compiler.h>

BUILD_SALT;

MODULE_INFO(vermagic, VERMAGIC_STRING);
MODULE_INFO(name, KBUILD_MODNAME);

__visible struct module __this_module
__section(".gnu.linkonce.this_module") = {
.name = KBUILD_MODNAME,
.init = init_module,
#ifdef CONFIG_MODULE_UNLOAD
.exit = cleanup_module,
#endif
.arch = MODULE_ARCH_INIT,
};

#ifdef CONFIG_RETPOLINE
MODULE_INFO(retpoline, "Y");
#endif

MODULE_INFO(depends, "");

Binary file not shown.
Binary file not shown.
4 changes: 4 additions & 0 deletions tools/labs/skels/kernel_modules/5-oops-mod/Kbuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# TODO: add flags to generate debug information
EXTRA_CFLAGS = -Wall -g

obj-m = oops_mod.o
1 change: 1 addition & 0 deletions tools/labs/skels/kernel_modules/5-oops-mod/modules.order
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/home/igor/linux/tools/labs/skels/./kernel_modules/5-oops-mod/oops_mod.ko
27 changes: 27 additions & 0 deletions tools/labs/skels/kernel_modules/5-oops-mod/oops_mod.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <linux/module.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/slab.h>

MODULE_DESCRIPTION("Oops generating module");
MODULE_AUTHOR("So2rul Esforever");
MODULE_LICENSE("GPL");

static int my_oops_init(void)
{
char *p = 0;

pr_info("before init\n");
*p = 'a';
pr_info("after init\n");

return 0;
}

static void my_oops_exit(void)
{
pr_info("module goes all out\n");
}

module_init(my_oops_init);
module_exit(my_oops_exit);
Binary file not shown.
2 changes: 2 additions & 0 deletions tools/labs/skels/kernel_modules/5-oops-mod/oops_mod.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/home/igor/linux/tools/labs/skels/./kernel_modules/5-oops-mod/oops_mod.o

27 changes: 27 additions & 0 deletions tools/labs/skels/kernel_modules/5-oops-mod/oops_mod.mod.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <linux/module.h>
#define INCLUDE_VERMAGIC
#include <linux/build-salt.h>
#include <linux/vermagic.h>
#include <linux/compiler.h>

BUILD_SALT;

MODULE_INFO(vermagic, VERMAGIC_STRING);
MODULE_INFO(name, KBUILD_MODNAME);

__visible struct module __this_module
__section(".gnu.linkonce.this_module") = {
.name = KBUILD_MODNAME,
.init = init_module,
#ifdef CONFIG_MODULE_UNLOAD
.exit = cleanup_module,
#endif
.arch = MODULE_ARCH_INIT,
};

#ifdef CONFIG_RETPOLINE
MODULE_INFO(retpoline, "Y");
#endif

MODULE_INFO(depends, "");

Binary file not shown.
Binary file not shown.
3 changes: 3 additions & 0 deletions tools/labs/skels/kernel_modules/6-cmd-mod/Kbuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ccflags-y = -Wno-unused-function -Wno-unused-label -Wno-unused-variable

obj-m = cmd_mod.o
26 changes: 26 additions & 0 deletions tools/labs/skels/kernel_modules/6-cmd-mod/cmd_mod.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <linux/module.h>
#include <linux/init.h>
#include <linux/kernel.h>

MODULE_DESCRIPTION("Command-line args module");
MODULE_AUTHOR("Kernel Hacker");
MODULE_LICENSE("GPL");

static char *str = "the worm";

module_param(str, charp, 0000);
MODULE_PARM_DESC(str, "A simple string");

static int __init cmd_init(void)
{
pr_info("Early bird gets %s\n", str);
return 0;
}

static void __exit cmd_exit(void)
{
pr_info("Exit, stage left\n");
}

module_init(cmd_init);
module_exit(cmd_exit);
Binary file not shown.
2 changes: 2 additions & 0 deletions tools/labs/skels/kernel_modules/6-cmd-mod/cmd_mod.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/home/igor/linux/tools/labs/skels/./kernel_modules/6-cmd-mod/cmd_mod.o

27 changes: 27 additions & 0 deletions tools/labs/skels/kernel_modules/6-cmd-mod/cmd_mod.mod.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <linux/module.h>
#define INCLUDE_VERMAGIC
#include <linux/build-salt.h>
#include <linux/vermagic.h>
#include <linux/compiler.h>

BUILD_SALT;

MODULE_INFO(vermagic, VERMAGIC_STRING);
MODULE_INFO(name, KBUILD_MODNAME);

__visible struct module __this_module
__section(".gnu.linkonce.this_module") = {
.name = KBUILD_MODNAME,
.init = init_module,
#ifdef CONFIG_MODULE_UNLOAD
.exit = cleanup_module,
#endif
.arch = MODULE_ARCH_INIT,
};

#ifdef CONFIG_RETPOLINE
MODULE_INFO(retpoline, "Y");
#endif

MODULE_INFO(depends, "");

Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions tools/labs/skels/kernel_modules/6-cmd-mod/modules.order
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/home/igor/linux/tools/labs/skels/./kernel_modules/6-cmd-mod/cmd_mod.ko
3 changes: 3 additions & 0 deletions tools/labs/skels/kernel_modules/7-list-proc/Kbuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ccflags-y = -Wno-unused-function -Wno-unused-label -Wno-unused-variable

obj-m = list_proc.o
35 changes: 35 additions & 0 deletions tools/labs/skels/kernel_modules/7-list-proc/list_proc.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
/* TODO: add missing headers */
#include <linux/sched/signal.h>

MODULE_DESCRIPTION("List current processes");
MODULE_AUTHOR("Kernel Hacker");
MODULE_LICENSE("GPL");

static int my_proc_init(void)
{
struct task_struct *p;

/* TODO: print current process pid and its name */
pr_info("Current process pid = %d; process name = %s\n",
current->pid, current->comm);

/* TODO: print the pid and name of all processes */
pr_info("Processes\n");
for_each_process(p)
pr_info("pid = %d; process name = %s\n", p->pid, p->comm);

return 0;
}

static void my_proc_exit(void)
{
/* TODO: print current process pid and name */
pr_info("Current process pid = %d; process name = %s\n",
current->pid, current->comm);
}

module_init(my_proc_init);
module_exit(my_proc_exit);
Binary file not shown.
2 changes: 2 additions & 0 deletions tools/labs/skels/kernel_modules/7-list-proc/list_proc.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/home/igor/linux/tools/labs/skels/./kernel_modules/7-list-proc/list_proc.o

27 changes: 27 additions & 0 deletions tools/labs/skels/kernel_modules/7-list-proc/list_proc.mod.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <linux/module.h>
#define INCLUDE_VERMAGIC
#include <linux/build-salt.h>
#include <linux/vermagic.h>
#include <linux/compiler.h>

BUILD_SALT;

MODULE_INFO(vermagic, VERMAGIC_STRING);
MODULE_INFO(name, KBUILD_MODNAME);

__visible struct module __this_module
__section(".gnu.linkonce.this_module") = {
.name = KBUILD_MODNAME,
.init = init_module,
#ifdef CONFIG_MODULE_UNLOAD
.exit = cleanup_module,
#endif
.arch = MODULE_ARCH_INIT,
};

#ifdef CONFIG_RETPOLINE
MODULE_INFO(retpoline, "Y");
#endif

MODULE_INFO(depends, "");

Binary file not shown.
Binary file not shown.
Loading