Skip to content
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
10 changes: 10 additions & 0 deletions tools/labs/skels/Kbuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# autogenerated, do not edit
ccflags-y += -Wno-unused-function -Wno-unused-label -Wno-unused-variable
obj-m += ./kernel_modules/1-2-test-mod/
obj-m += ./kernel_modules/5-oops-mod/
obj-m += ./kernel_modules/9-dyndbg/
obj-m += ./kernel_modules/8-kdb/
obj-m += ./kernel_modules/4-multi-mod/
obj-m += ./kernel_modules/3-error-mod/
obj-m += ./kernel_modules/6-cmd-mod/
obj-m += ./kernel_modules/7-list-proc/
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
1 change: 1 addition & 0 deletions tools/labs/skels/kernel_modules/1-2-test-mod/ex1-2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
la 2 am dat comanda echo 5 > /proc/sys/kernel/printk pentru a modifica nivelul de log
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);
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/init.h>
#include <linux/kernel.h>
#include <linux/module.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);
5 changes: 5 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,5 @@
ccflags-y = -Wno-unused-function -Wno-unused-label -Wno-unused-variable

# TODO: add rules to create a multi object module
obj-m = multi-mod.o
multi-mod-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);
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;
}
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
ccflags-y = -g

obj-m = oops_mod.o
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);
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);
1 change: 1 addition & 0 deletions tools/labs/skels/kernel_modules/6-cmd-mod/ex6.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
insmod cmd_mod.ko str="Early bird gets tired."
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, name = %s\n", current->pid, current->comm);

/* TODO: print the pid and name of all processes */
for_each_process(p) {
pr_info("pid = %d, 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, name = %s\n", current->pid, current->comm);
}

module_init(my_proc_init);
module_exit(my_proc_exit);
3 changes: 3 additions & 0 deletions tools/labs/skels/kernel_modules/8-kdb/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 = hello_kdb.o
142 changes: 142 additions & 0 deletions tools/labs/skels/kernel_modules/8-kdb/hello_kdb.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
#include <linux/module.h>
#include <linux/proc_fs.h>
#include <linux/seq_file.h>

int kdb_write_address;
EXPORT_SYMBOL(kdb_write_address);

noinline void dummy_func18(void)
{
panic("Hello KDB has paniced!");
}
noinline void dummy_func17(void)
{
dummy_func18();
}
noinline void dummy_func16(void)
{
dummy_func17();
}
noinline void dummy_func15(void)
{
dummy_func16();
}
noinline void dummy_func14(void)
{
dummy_func15();
}
noinline void dummy_func13(void)
{
dummy_func14();
}
noinline void dummy_func12(void)
{
dummy_func13();
}
noinline void dummy_func11(void)
{
dummy_func12();
}
noinline void dummy_func10(void)
{
dummy_func11();
}
noinline void dummy_func9(void)
{
dummy_func10();
}
noinline void dummy_func8(void)
{
dummy_func9();
}
noinline void dummy_func7(void)
{
dummy_func8();
}
noinline void dummy_func6(void)
{
dummy_func7();
}
noinline void dummy_func5(void)
{
dummy_func6();
}
noinline void dummy_func4(void)
{
dummy_func5();
}
noinline void dummy_func3(void)
{
dummy_func4();
}
noinline void dummy_func2(void)
{
dummy_func3();
}
noinline void dummy_func1(void)
{
dummy_func2();
}

static int hello_proc_show(struct seq_file *m, void *v) {
seq_printf(m, "Hello proc!\n");
return 0;
}

static int hello_proc_open(struct inode *inode, struct file *file) {
return single_open(file, hello_proc_show, NULL);
}

static int edit_write(struct file *file, const char *buffer,
size_t count, loff_t *data)
{
kdb_write_address += 1;
return count;
}

static int bug_write(struct file *file, const char *buffer,
size_t count, loff_t *data)
{
dummy_func1();
return count;
}

static const struct proc_ops edit_proc_ops = {
.proc_open = hello_proc_open,
.proc_read = seq_read,
.proc_write = edit_write,
.proc_lseek = seq_lseek,
.proc_release = single_release,
};

static const struct proc_ops bug_proc_ops = {
.proc_open = hello_proc_open,
.proc_read = seq_read,
.proc_write = bug_write,
.proc_lseek = seq_lseek,
.proc_release = single_release,
};

static int __init hello_proc_init(void) {
struct proc_dir_entry *file;
file = proc_create("hello_kdb_bug", 0, NULL, &bug_proc_ops);
if (file == NULL) {
return -ENOMEM;
}

file = proc_create("hello_kdb_break", 0, NULL, &edit_proc_ops);
if (file == NULL) {
remove_proc_entry("hello_kdb_bug", NULL);
return -ENOMEM;
}
return 0;
}

static void __exit hello_proc_exit(void) {
remove_proc_entry("hello_kdb_bug", NULL);
remove_proc_entry("hello_kdb_break", NULL);
}

MODULE_LICENSE("GPL");
module_init(hello_proc_init);
module_exit(hello_proc_exit);
3 changes: 3 additions & 0 deletions tools/labs/skels/kernel_modules/9-dyndbg/Kbuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
EXTRA_CFLAGS = -Wall -g

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

MODULE_DESCRIPTION("Dyndbg kernel module");
MODULE_AUTHOR("Dyndbg");
MODULE_LICENSE("GPL");

void my_debug_func(void)
{
pr_debug("Important dyndbg debug message1\n");
pr_debug("Important dyndbg debug message2\n");
pr_debug("Verbose dyndbg debug message\n");
}
EXPORT_SYMBOL(my_debug_func);


static int dyndbg_init(void)
{
printk(KERN_INFO "Hi dyndbg!\n" );
my_debug_func();
return 0;
}

static void dyndbg_exit(void)
{
printk(KERN_INFO "Bye dyndbg!\n" );
my_debug_func();
}

module_init(dyndbg_init);
module_exit(dyndbg_exit);