Howto: Adding a new kernel module
Windows Research Kernel @ HPIThe Windows Research Kernel contains multiple kernel modules,
e.g. for memory management or for the executive layer. Each module
has its own subdirectory in base/ntos
. If you want to
extend the WRK it might be useful to collect all your new files in a
new kernel module. This post explains the necessary steps for adding
a new kernel module. Basically, all it takes is tweaking a few
makefiles.
First step: creating the kernel module
subdirectory: base/ntos/foo
. The WRK build
process expects the kernel module makefile and directories for
binary files in another subdirectory BUILD
. So, you
have to create this sub-subdirectory as well. The directories for
binary files are obji386
and objamd64
.
Finally, your directory structure should be as follows:
The directories base/ntos/foo/amd64/
and
base/ntos/foo/i386/
are required if you have platform
specific source code.
Second step: creating the kernel module
makefile: base/ntos/foo/BUILD/makefile
. This
makefile is used to build the new kernel module. The following
listing shows a basic stub for a kernel module makefile.
library = $(module) !if "$(targ)" == "i386" # i386 specific asobjs= \ $(OBJ)\x86asmfoo.obj ccarchobjs= \ $(OBJ)\x86cfoo.obj !else # amd64 specific # ... !endif ccobjs= \ $(OBJ)\foo.obj \ $(OBJ)\bar.obj !include $(ntos)\BUILD\makefile.build
The makefile contains three different kinds of object file
information: (1) Object files assigned to asobjs
are
built using assembler, the asm files are located in a platform
dependent subdirectory of the kernel module. E.g.
base/ntos/foo/i368/bar.asm
. (2) Further platform
dependent object files which are generated from regular C files are
assigned to ccarchobjs
. (3) All remaining (platform
independent) kernel module object files are assigned to
ccobjs
.
You have to add object file entries for the files your kernel module implementation contains at the appropriate makefile location.
Final step: integrating the module into the
regular WRK build process. The main WRK makefile is
base/ntos/makefile
. This file defines the available
kernel modules:
modules = rtl config ex ob se mm ke ps io\iomgr io cache
lpc dbgk raw fstub fsrtl wmi perf init
Just extend this line with the newly created kernel module.