Archive for April, 2006

AHA!

Saturday, April 29th, 2006

See, I told you so. It was all my fault.

After tons more code spelunking and debugging, it became obvious that NDIS was simply failing to set up the miniport block for my driver correctly. It even lacked the special miniport block magic number (which is ‘NDMP’ in big-endian). I spent hours tracing through the internals and finally gave up and went to bed, hoping for inspiration the next day.

I found several samples that called NdisReadConfiguration() in the DDK, and noticed in particular that Elyias Yakub’s netvmini sample was passing a variable called ‘WrapperConfigurationContext’ to NdisOpenConfiguration. I’d read the docs about 100 times, but for some reason, that variable stuck out this time. So I went back to the NdisOpenConfiguration() docs to see what that parameter should be. The documentation reads: Specifies the handle input to MiniportInitialize. So I looked at the MiniportInitialize documentation, and Lo And Behold, there are two handles input to MiniportInitialize(). Sure enough this code was passing the wrong one in.

It would have helped if I had named that variable precisely WrapperConfigurationContext the first time, instead of something slightly and confusingly different, because then I wouldn’t have had to make the tacit translation of variable names from the docs to my code, and the error would have been (more) obvious. Reason #143,532 to have coding standards.

So, back to testing. What a pain. I discovered several interesting NDIS-related bugs along the way, though, so it wasn’t a total loss. NdisInitializeString() is just weird, and to add to that, there are a couple of minor type bugs in NdisInitializeString() (again!) and NdisMEthIndicateReceive(), where things that are documented as taking VOID are actually prototyped as taking PUCHAR.

Who’s wrong?

Friday, April 28th, 2006

I hate it when this happens. I’m debugging a Very Weird Problem with an NDIS driver, wherein calling NdisReadConfiguration() even once, with a variety of different test inputs, causes NDIS to break (oddly) every single time, but only on Windows XP SP0. So I searched Google looking for NdisReadConfiguration() docs having to do with Windows XP and found nothing that looks related. Nada on the newsgroups.

The real kicker is that it works fine on the only other platform I’ve tested on so far, Win2k3 sp1. When I trace in with a debugger, NDIS calls RtlQueryRegistryValues(). The args NDIS passes to it are totally, monumentally broken at the point of the call. Yet the original args I am passing to NDIS are fine.

So the question is: whose bug is it? The call looks fine to me, and works on other versions of Windows. It’s not a commonly called API in the grand scheme of things, and this is on an unpatched XP system, so could it really be an OS bug? On the other hand, there are absolutely no reports of anything like this on the Internet. That’s not a good sign.

In the end, I’m sure this will wind up being my bug, but as I sit here working on it on a Friday night, I don’t see how yet. There is, of course, more than one way to skin the cat, but I’m annoyed by this enough at the moment to forge ahead blindly.

Just so I can say I asked: has anyone ever successfully used NdisReadConfiguration() on XP gold?

FWA Symposium

Monday, April 24th, 2006

I just got a note from the organizer of the Financial Women’s Association Symposium, to which I’m heading tomorrow to participate in a remote workforce panel. I didn’t think this would be how I would finally get my name into Forbes, though!

NDIS API breakage

Thursday, April 20th, 2006

I have been spending some time polishing up a driver I’m working on, and today I got to the point in my testing that it was time for Driver Verifier’s Low Resources Simulation. Everything was moving along nicely, when all of a sudden I glanced up and noticed a kd> prompt staring at me. I always hate finding bugchecks that late in the test process.

It was broken into an area of code that I didn’t write, so I wasn’t immediately familiar with how it worked. The top of the stack was inside a call to NdisReadConfiguration(). Looking at the code, it seemed like an impossible bugcheck - I had already validated all of my buffers prior to that point. The call immediately above was to NdisInitializeString() - that can’t fail, right? After all, it return VOID… Hmmm…

Then I noticed a missing L before the string literal I was trying to initialize. That couldn’t work… but why wasn’t the compiler complaining? I was compiling on /W3 after all. No, in fact, for historical reasons going back before Windows NT, NdisInitializeString takes a regular 8-bit character pointer. But the docs clearly say that NDIS_STRING is UNICODE_STRING in Windows 2000+. Unicode is bigger than ANSI by double; where does it get the extra memory from for the conversion? Yep, that’s right, it’s calling ExAllocatePoolWithTag(). Can that fail? Yes. :-)

So I cracked the function open in WinDbg and sure enough, it tries to allocate memory (under the tag NDst). After setting string.Buffer to the returned pointer, it checks for failure and just returns if the allocation failed. That means that Buffer is NULL, so at least there’s a way of testing for this condition - as long as Microsoft doesn’t change the code!

On further inspection of the documentation, it turns out that you’re supposed to pass in a “null” NDIS_STRING for initialization by NdisInitializeString(). I wasn’t sure what that meant at the time, but on further review, it looks like it would be a good idea to zero-fill the NDIS_STRING before passing it to this API, just in case the internal implementation changes (e.g. if they test the return from ExAllocatePoolWithTag() before assigning it to .Buffer).

And the icing on the cake is that NdisFreeString is just a macro for NdisFreeMemory, which frees to the null tag.

Now I just have to figure out why the thing Just Doesn’t Work™ on Windows XP gold. I love NDIS!

Downtown Mandolin Orchestra debut

Thursday, April 20th, 2006

If you’re around the Kansas City metro area and are looking for a good way to pass an evening on April 29, come out to Lawrence, KS and check out the debut performance of the Downtown Mandolin Orchestra.

I’ll be playing mandolin in the orchestra, which also includes mandolas, mandocellos, guitars, a base, and percussion. All told, there are about 18 of us - a little smaller than the Mandofest orchestra I’ve played in the last couple of year. But, the small size means a tighter sound.

We’re playing quite a bit of music - my guess is we’ll have over an hour of playing time. Styles range from a classical suite to a number of Brazilian tunes, a couple of Spanish tunes, a couple of Irish numbers by Turlogh O’Carolan (always fun), and more. We have a very special finale prepared as well.

Scott Tichenor, the man behind Mandolin Cafe, will be the featured artist of the night. He’s a really fantastic player and plays an equally fantastic mandolin.

More information is available at the Cafe. Tickets are $5 at the door. I hope to see you there!

Mild outage…

Thursday, April 20th, 2006

My otherwise-excellent virtual server at linode.com apparently died as a result of a buggy host kernel earlier today. They’ve upgraded the host and my box is back online. Aah, technology…

Get perpendicular

Wednesday, April 19th, 2006

Thanks to David Justis, a colleague at Positive Networks, for passing along this hilarious video from Hitachi about perpendicular storage: http://www.hitachigst.com/hdd/research/recording_head/pr/PerpendicularAnimation.html.

An interesting take on software patents

Wednesday, April 12th, 2006

It’s been a while since I’ve posted on patents. I ran across this post today from Brad Feld today, though, and it started to get the gears turning again: Abolish Software Patents. It’s a interesting (and simple) idea, and something I’ve always been very sympathetic with. Interesting reading.

Working at Tech*Ed

Tuesday, April 11th, 2006

It looks like I’ll be working at Tech*Ed in Boston this year. I haven’t firmed up my travel plans yet, but I should be there the whole week, hanging out with the client support people and maybe attending a few sessions. I’m really looking forward to it - I love Boston, and summer is about the perfect time to be there, as far as I’m concerned.

Drop me a line if you’re going to be there.

A couple more x64 articles

Tuesday, April 11th, 2006

Matt Pietrek has a new article published on msdn, called Everything You Need To Know To Start Programming 64-Bit Windows Systems. It’s a pretty good overview if you haven’t come up to speed on this yet, but it is annoyingly light on some of the driver-centric issues.

I can personally attest to the WOW64 registry redirection thing, though - I just spent an embarrassingly long time fighting with WinDbg, trying to get it to post-mortem debug some 32-bit usermode code I am working on. It turns out, obviously, that windbg -I only installs it in one place - i.e. 32-bit windbg installs itself only for 32-bit post-mortem debugging. I had installed only the 64-bit debugger on that box, and it took me forever (and eventually a justly condescending reminder from Ken) before I figured out what was up.

The Pietrek article also links to another that looks interesting at a glance, but I thought I’d pass it along too: X64 Unwind Information. Enjoy!