Commit f101544c authored by Tyler Nichols's avatar Tyler Nichols

Committing basic loadable Linux kernel module with readme.

parents
Pipeline #15 skipped
A very basic skeleton of a loadable Linux kernel module and corresponding Makefile that can be cloned and used as a basis for building much more advanced modules.
This code was written on Ubuntu Server 16.04 LTS and tested on kernel version 4.4.0.
To build:
$ cd src/
$ make
To delete build artifacts:
$ make clean
To load the module:
$ sudo insmod module-skeleton.ko
To unload the module:
$ sudo rmmod module-skeleton
To view log entries:
$ tail -f /var/log/syslog
#
# NOTE! Don't add files that are generated in specific
# subdirectories here. Add them in the ".gitignore" file
# in that subdirectory instead.
#
# NOTE! Please use 'git ls-files -i --exclude-standard'
# command after changing this file, to see if there are
# any tracked files which get ignored after the change.
#
# Normal rules
#
.*
*.o
*.o.*
*.a
*.s
*.ko
*.so
*.so.dbg
*.mod.c
*.i
*.lst
*.symtypes
*.order
modules.builtin
*.elf
*.bin
*.gz
*.bz2
*.lzma
*.xz
*.lzo
*.patch
*.gcno
#
# Top-level generic files
#
/tags
/TAGS
/linux
/vmlinux
/vmlinuz
/System.map
/Module.markers
Module.symvers
#
# Debian directory (make deb-pkg)
#
/debian/
#
# git files that we don't want to ignore even it they are dot-files
#
!.gitignore
!.mailmap
#
# Generated include files
#
include/config
include/linux/version.h
include/generated
arch/*/include/generated
# stgit generated dirs
patches-*
# quilt's files
patches
series
# cscope files
cscope.*
ncscope.*
# gnu global files
GPATH
GRTAGS
GSYMS
GTAGS
*.orig
*~
\#*#
#
# Leavings from module signing
#
extra_certificates
signing_key.priv
signing_key.x509
x509.genkey
obj-m += module-skeleton.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
#include <linux/module.h> /* Needed by all kernel modules */
#include <linux/kernel.h> /* Needed for loglevels (KERN_WARNING, KERN_EMERG, KERN_INFO, etc.) */
#include <linux/init.h> /* Needed for __init and __exit macros. */
#include <linux/slab.h> /* kmalloc */
static int __init onload(void) {
printk(KERN_EMERG "Loadable module initialized\n");
return 0;
}
static void __exit onunload(void) {
printk(KERN_EMERG "Loadable module removed\n");
}
module_init(onload);
module_exit(onunload);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment