Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

An example of writing an external, simple Linux kernel module, in V.

License

NotificationsYou must be signed in to change notification settings

spytheman/simple_kernel_module_in_v

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

The purpose of this repo, is to show how to write and testa very simple Linux kernel module,usingthe V programming language .

NB: this isvery experimental and may break in the future.It works as of 2021/10/23, withgcc 10.3.0 andV 0.2.4 008d15d .Update: it also works as of 2022/08/16, withgcc 10.3.0 andV 0.3.0 3bc01d6 too.

The-no-builtin -no-preludes options produce C code, that may noteven compile, if it depends on some of V'sbuiltin module features, likedynamic arrays, maps, array/string methods, string interpolation etc.

Prerequisites:

A C compiler, and a V compiler.

On a Debian system, you can install them with:

apt-get install gccgit clone https://github.com/vlang/v&&cd v&& make&& ./v symlink

Once you have them installed, you can keep them up to date with:

apt-get upgradev up

Building the kernel module:

make

See alsohttps://www.kernel.org/doc/html/latest/kbuild/modules.html .

Loading the module in your kernel:

sudo insmod vhellokernel.ko

Verifying that the module was loaded in the kernel:

cat /proc/modules |grep vhellokernel

If everything is ok, you should see something like this:

vhellokernel 16384 0 - Live 0x0000000000000000 (OE)

Usedmesg | tail to see the messages that the module wrote.

Removing the module from your kernel:

sudo rmmod vhellokernel.ko

make clean test

0[12:47:53] /v/misc/2021_10_22__02/simple_kernel_module_in_v LINUX $ make clean testmake -C /lib/modules/`uname -r`/build M=$PWD cleanmake[1]: Entering directory '/usr/src/linux-headers-5.11.0-38-generic'  CLEAN   /v/misc/2021_10_22__02/simple_kernel_module_in_v/Module.symversmake[1]: Leaving directory '/usr/src/linux-headers-5.11.0-38-generic'rm -rf vhellokernel.o vhellokernel.cv -no-builtin -no-preludes -o vhellokernel.c vhellokernel.vmake -C /lib/modules/`uname -r`/build M=$PWD modulesmake[1]: Entering directory '/usr/src/linux-headers-5.11.0-38-generic'  CC [M]  /v/misc/2021_10_22__02/simple_kernel_module_in_v/vhellokernel.o  MODPOST /v/misc/2021_10_22__02/simple_kernel_module_in_v/Module.symvers  CC [M]  /v/misc/2021_10_22__02/simple_kernel_module_in_v/vhellokernel.mod.o  LD [M]  /v/misc/2021_10_22__02/simple_kernel_module_in_v/vhellokernel.komake[1]: Leaving directory '/usr/src/linux-headers-5.11.0-38-generic'make loadmake[1]: Entering directory '/v/misc/2021_10_22__02/simple_kernel_module_in_v'sudo insmod vhellokernel.komake[1]: Leaving directory '/v/misc/2021_10_22__02/simple_kernel_module_in_v'cat /proc/modules |grep vhellokernelvhellokernel 16384 0 - Live 0x0000000000000000 (OE)make unloadmake[1]: Entering directory '/v/misc/2021_10_22__02/simple_kernel_module_in_v'sudo rmmod vhellokernel.komake[1]: Leaving directory '/v/misc/2021_10_22__02/simple_kernel_module_in_v'0[12:47:56] /v/misc/2021_10_22__02/simple_kernel_module_in_v LINUX $

Further reading:

  1. https://tldp.org/LDP/lkmpg/2.6/lkmpg.pdf

  2. https://www.kernel.org/doc/html/latest/kbuild/modules.html

  3. https://github.com/vlang/v/blob/master/doc/docs.md

About

An example of writing an external, simple Linux kernel module, in V.

Topics

Resources

License

Stars

Watchers

Forks


[8]ページ先頭

©2009-2025 Movatter.jp