Thursday, August 28, 2008

Finally fixed the driver

The only thing worth going through the painful process of fixing a complicated problem, the kind of problem which keeps you up at night and makes you dream of code and unfathomable journeys through memory space filled with pointers and addresses, is that when you finally solve it you feel that much better.

In "One of those weeks" I told you about a problem that I was facing where a particular memset call was producing access violations, even though the memory was mapped and should have been accessible. I stayed in my office yesterday until 9pm and banged my head against the screen a few times before I figured out the problem. I started the driver and while booting I saw in my debugger window in Visual Studio something that caught my attention. I saw that instead of the driver been loaded at an address which I expected it to, it had been shifted a little (I almost couldn't help say a 'bit'). This shift caused the whole loading process to shift and so our memset address got shifted and ran out of bounds.

I set the expected address to the address where the driver was actually loaded, and lo and behold it worked. This is a problem that I was able to solve but just as well might not have since it was so difficult to identify. This brings me to an important point. Sometimes especially when things do not seem to work and we try every possible solution, just like I had tried--I changed the address, re-mapped the address, checked the buffer size, every test that I made suggested that the driver should work--then the best way to proceed is to throw all of your knowledge, your instincts, your results, and most importantly your assumptions out the window and question your initial assumption which might have shifted your whole problem astray. Sometimes the solution to the problem does not lie within the intricacies of itself, but rather within the context in which we are trying to solve it. In my case, the driver itself was correct just like my tests were showing, and the mapping was done perfectly. To keep investing time in debugging the inner works and magic of the driver would have been to waste it. Instead, taking back a look at how the driver itself is loaded into memory and question whether this process was correct, yielded the right answer.

The other thing I like about solving difficult problems aside from the feeling of confidence it gives balancing the sessions of self esteem bashing, is that it has a humbling factor. Difficult problems serve to show us that no matter how much we think we know, there is always more for us to learn, by researching and from others.

And no, I did not scream I am king of the world.

No comments: