mirror of
https://github.com/krislamo/kernmod.git
synced 2024-11-10 00:30:36 +00:00
A hello world Linux kernel module
This commit is contained in:
commit
00e921ec10
8
.gitignore
vendored
Normal file
8
.gitignore
vendored
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
*.cmd
|
||||||
|
*.ko
|
||||||
|
*.mod*
|
||||||
|
*.o
|
||||||
|
.helloworld.o.d
|
||||||
|
.vagrant
|
||||||
|
Module.symvers
|
||||||
|
modules.order
|
7
Makefile
Normal file
7
Makefile
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
obj-m += helloworld.o
|
||||||
|
|
||||||
|
all:
|
||||||
|
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
|
||||||
|
|
||||||
|
clean:
|
||||||
|
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
|
11
README.md
Normal file
11
README.md
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
## kernmod
|
||||||
|
|
||||||
|
A hello world Linux kernel module and build environment in Debian GNU/Linux.
|
||||||
|
|
||||||
|
|
||||||
|
### Public Domain Dedication
|
||||||
|
Copyright (C) 2021 Kris Lamoureux
|
||||||
|
|
||||||
|
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
6
Vagrantfile
vendored
Normal file
6
Vagrantfile
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
Vagrant.configure("2") do |config|
|
||||||
|
config.vm.box = "debian/bullseye64"
|
||||||
|
config.vm.synced_folder ".", "/vagrant"
|
||||||
|
config.vm.network "private_network", type: "dhcp"
|
||||||
|
config.vm.provision "shell", path: "build.sh"
|
||||||
|
end
|
13
build.sh
Normal file
13
build.sh
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
export DEBIAN_FRONTEND=noninteractive
|
||||||
|
apt-get update
|
||||||
|
apt-get install build-essential linux-headers-$(uname -r) -y
|
||||||
|
|
||||||
|
cd /vagrant
|
||||||
|
make
|
||||||
|
modinfo helloworld.ko
|
||||||
|
insmod helloworld.ko
|
||||||
|
cat /proc/modules | grep helloworld
|
||||||
|
rmmod helloworld
|
||||||
|
cat /var/log/messages | grep helloworld
|
21
helloworld.c
Normal file
21
helloworld.c
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
#include <linux/module.h>
|
||||||
|
#include <linux/kernel.h>
|
||||||
|
#include <linux/init.h>
|
||||||
|
|
||||||
|
#define DRIVER_AUTHOR "Kris Lamoureux"
|
||||||
|
#define DRIVER_DESC "Hello world kernel module"
|
||||||
|
|
||||||
|
int init_module(void)
|
||||||
|
{
|
||||||
|
printk(KERN_INFO "helloworld: hello, world\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void cleanup_module(void)
|
||||||
|
{
|
||||||
|
printk(KERN_INFO "helloworld: goodbye, world\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
MODULE_LICENSE("Dual BSD/GPL");
|
||||||
|
MODULE_AUTHOR(DRIVER_AUTHOR);
|
||||||
|
MODULE_DESCRIPTION(DRIVER_DESC);
|
Loading…
Reference in New Issue
Block a user