From a “least surprise” perspective, though, you should really avoid
dependending on static initializers/destructors, aside from normal C
variable initialization. Developers of NT device drivers really expect
all significant initialization work to occur in DriverEntry, and NOT
before. The cleanest way to maintain global data is usually to use an
overloaded operator new, or directly call your favorite kernel-mode pool
allocator, from DriverEntry. (And of course, free it during
DriverUnload.)
I say this mostly from the point of view of code base maintenance. If
someone needs to debug or work on your driver, and they are familiar
with NT device drivers, they will ordinarily assume
DriverEntry/DriverUnload handles all real init/shutdown. Anything else
will come as a surprise. The degree of the surprise may range from
curiosity to blue screen.
– arlie
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Bill McKenzie
Sent: Tuesday, August 26, 2003 2:12 PM
To: Windows System Software Developers Interest List
Subject: [ntdev] Re: C++ static construction on AMD 64?
Has anyone run into this, and if so, what was the workaround?
Yep, we have. For x86 you would do something like this, right?
#pragma data_seg(“.CRT$XCA”)
void (*_StartInitCalls[1])(void)={0};
For IA64/AMD64 you need something like this to accomplish the same:
#pragma section(“.CRT$XCA”,long,read)
__declspec(allocate(“.CRT$XCA”)) void
(*_StartInitCalls[1])(void)={0};
–
Bill McKenzie
Compuware Corporation
Watch your IRPs/IRBs/URBs/SRBs/NDIS pkts with our free WDMSniffer tool:
http://frontline.compuware.com/nashua/patches/utility.htm
“Ray Trent” wrote in message news:xxxxx@ntdev…
>
> We use C++ for our driver (no flamewars, please :-). Anyway, to do
> this, one thing you need to do is come up with some way to call the
> constructors for your global/static objects.
>
> There’s a pretty standard way to do this, described in
> http://msdn.microsoft.com/msdnmag/issues/01/01/hood/, that involves
> calling the functions pointed to in a specially named data segment
> called .CRT$XCU. The compiler puts all the static objects’
> constructors in this named segment so that they all get linked
> together in one place. This is normally bracketed by a couple of data
> segments called .CRT$XCA and .CRT$XCZ (which contain some globally
> accessible specially named variables so you can find them). That way
> there’s some way for the runtime initialization code to know what the
> boundaries of the constructor pointer list are. This still is all
> generated by the compiler and linker automatically.
>
> However, we just tried compiling our driver for the AMD64 processor in
> preparation for XP AMD64 notebooks coming out soon, and it appears
> that that compiler puts the XCA and XCZ segments in an area unrelated
> .CRT$XCU. Therefore I don’t know how to find them from our
> initialization code any more.
>
> Has anyone run into this, and if so, what was the workaround?
>
> Of course, our next step will be to reverse engineering the CRTL for
> this compiler… I was just hoping not to needlessly replicate that
> effort…
> –
> …/ray..
>
>
>
—
Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
You are currently subscribed to ntdev as: xxxxx@sublinear.org To
unsubscribe send a blank email to xxxxx@lists.osr.com