A blog describing computer internals and electronics, from a student's viewpoint

"Paperbacks"

Sunday, March 14, 2010

Kernel-mode Applications under Windows XP

Recently, I have been making a dynamic-link library consisting of two main types of code: one that I actively learn through both trainings and algorithm books, and the other that are rewrites of old code I found in my data archives dating ~3 years back. For performance reasons, I decided to rewrite the code for operation as a device driver (which kernel-mode software are more commonly called by.) In the course of porting to kernel space, I came across this scenario: The well-beloved C runtime library of Windows, MSVCRT.DLL, has an almost non-existent equivalent for applications written to operate in kernel-mode. Of course, things like localization are not important for kernel-mode software, for their purpose is interfacing the operating system kernel to various hardware peripherals like CD-ROMs and USB host controllers. But C functions such as malloc(), free(), rand() and the str* series of functions, are very commonly used. The question is why Microsoft did not implement a kernel-mode equivalent of MSVCRT.DLL that contains even the most basic of C functions.

Because of this, I was forced to re-implement some C functions such as sin(), cos(), sqrt(), memcpy() and memset() . Being just a hobbyist, do not expect me to make a kernel-mode dynamic-link library without causing dreaded blue screens, in a short span of time; expect years. Some of the C functions now have a good-enough implementation, but many others are just "do nothing" stubs. I'll post a copy soon.

Upcoming hobby project for kernel-mode programming : an audio filter that is chained to a hardware driver to have dancing lights. :P

P.S. Do not ever expect me to make drivers for Vista and 7. The digital signatures required are way beyond my reach.

Thursday, January 14, 2010

Kernel-mode software: Part I

First of all, sorry for keeping this blog dormant for too long. :(

As of now, I am writing a compilation of algorithms whose implementation is designed in kernel-mode to make them faster. My goal: make a standard c/c++ library that can operate correctly under kernel-mode the same way as they do in user-mode - minus standard I/O (device drivers are designed to do I/O directly to their hardware, right? xD). And port common libraries to kernel-mode.

P.S. I'm currently doing my work under Windows XP. Will do for Linux afterwards.

As programmers know, kernel-mode software development is much, much harder than normal, user-mode programming. For one, while an application bug will just crash your application with familiar message boxes, in kernel-mode the same thing causes the entire system to issue a bugcheck (a.k.a. BSOD in Windows). For another, you'd have to do everything that the runtime would have done for you by hand; for example, the familiar C++ exception handling is absent in kernel-mode (C++ does not work properly under kernel-mode in the first place!) There are more issues than what I've written here, but these two are some of the most important, aside from security issues (kernel-mode software, from their name, are capable of fully controlling your system. So... don't, don't, DON'T INSTALL DEVICE DRIVERS FROM UNKNOWN PEOPLE!)

I think that the only advantage of normal applications ported to kernel-mode comes in terms of speed.

--- I shall add to this page. This is all for now... ---