The opinions expressed in this blog are my own and do not represent those of my current employer

Recently i was looking for another approaches how to use c++ features in kernel mode drivers. I found some references, but no one will fullfill my needs & desires to use also boost & std (at least partially).

Some time ago my friend show me a way how to add mentioned libraries to kernel code, so i decided to do it from scratch, do some minimalistic approach with some kind of ‘manual’ and PoC, and maybe it can be for someone, except myself, usefull.

Part I. – force c++ to cooperate

Firstly, it is no big deal to use c++ in kernel mode. For example, some of references that i was able to found :

Ok, now it is good enough to use c++ in Kernel mode, and also usage of nice feature of std::unique_ptr. But when you attempt to use some boost::intrusive or std::shared_ptr you may encounter some probems! And this problemes are c++ E X C E P T I O N S , on code project resides very good article for reading about c++ exceptions vs kernel.

in libc.git project, i use $(DDK_LIB_PATH)\libcntpr.lib; for including some additional functions (_hypot and friends…). And in next version of vs can be needed also another functions, and for this you should firstly find in .lib in $(DDK_LIB_PATH) and try to link it to project, or after that if nothing was found implement it by yourself …

But important here, is to avoid linking usermode .dll into your kernel mode driver

I also pushed on github KernelProject PoC of usage of libc.git and new WDM driver for visual studio 2013 – (shared_ptr, unique_ptr, boost::intrusive::avltree). (i used also Common repo because of demonstrating on Vads, and usage of CCppDriver class as “main” of driver) – Windows 8.1 Release is setup-ed configuration – platform, so you can try to set-up Windows 7.1 release for sucessfully running also Vad test (because in undoc is setuped constans just for win7sp1 and win7, both x64)

1 Comments.

Well done, I tried doing this before. And wanted to implement a base library base on COM likes. Whant I recommend is how about all class inherit base class, which contain object reference. In future, we can implement ourself GC