Kernel C++ Runtime Library

 

 

There is this endless debate in comp.os.ms-windows.programmers.nt.kernel-mode about the validity of using C++ code in the kernel. It is a religious war, akin to Emacs vs. Vi or C Indentation Styles or Runtime Assertions. There will never be a victor.

I'll let you know right now that I am on the side of truth, liberty, mom, apple-pie, the american way, and C++ in the kernel. I figure one way to end the debate is to make the use of C++ pervasive. As a step in that direction, here is at least part of the missing runtime infrastructure that is required for full C++ support, a C++ kernel runtime library.

What's missing in the kernel is support for global new and delete, initialization of global class objects, and C++ exception handling. (There is probably a lot of other stuff missing as well, but this is the basic list.) So a while back I concocted a simple C++ kernel runtime library. I even wrote an article about it in the NtInsider, which claimed that the described package could be downloaded from the OSR website. Funny thing is though, it never was downloadable.

The package is open source, freely redistributable (under the lesser GPL), and finally available here for downloading.  Comments, contributions, money, always gladly accepted.

 

Instructions.

Step 1.

Download the latest version here, this link will download the installation package to your system.

Step 2.

Install the library. The package is supplied as an msi file, just double click it to start the setup procedure.

Step 3.

Modify your Sources file to link with the library. Wherever you installed the package, that is where you must point your Sources file to link in the htscpp.lib binary. A sample sources file is illustrated below. (And the supplied TestDrv sample driver also provides an example.) This is a Windows2000 DDK solution only! You will have to modify the build files for windows NT 4.0 yourself.

MAJORCOMP=ntos

MINORCOMP=CPPRT

TARGETNAME=testDrv

TARGETPATH=obj

TARGETTYPE=DRIVER

!IF "$(DDKBUILDENV)" != "checked"
TARG_SUFFIX=fre

!ELSE
TARG_SUFFIX=chk

!ENDIF

LIBPATH=$(KCPPPATH)\lib$(TARG_SUFFIX)

INCLUDES=$(INCLUDES);..\inc

TARGETLIBS=\
$(LIBPATH)\*\htscpp.lib

SOURCES=\
testDrv.cpp

Step 4.

Include the kernel c++ header file htscpp.h in your source files and modify your DriverEntry routine, renaming your DriverEntry routine from DriverEntry to CPP_DRIVER_ENTRY. 

Step 5.

Build your driver.