Yes that’s right Doron,
I’m wrong on double count(s). Now I think, he was talking about local
stack variable(s) using class object(s), well then anyone can blow the
stack up ( longlong arrary[1024][12] ) or some such…
-prokash
-----Original Message-----
From: Doron Holan [mailto:xxxxx@windows.microsoft.com]
Sent: Wednesday, February 11, 2004 11:11 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] A giuide to writing device drivers in c++
Usually the this pointer is stuffed into ecx, not pushed onto the stack.
This has a sideaffect though that there is one less register to use in
the function so more stack space may be used later.
d
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Sinha, Prokash
Sent: Wednesday, February 11, 2004 10:59 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] A giuide to writing device drivers in c++
Mat
Not to pointificate, but IIRC the stack frame will have only one extra
4-byte *this* ptr where it is implicit !!!
-prokash
-----Original Message-----
From: xxxxx@3Dlabs.com [mailto:xxxxx@3Dlabs.com]
Sent: Wednesday, February 11, 2004 10:42 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] A giuide to writing device drivers in c++
Hi Robert,
I think this problem can be split into two pieces:
- Difficulties using C++ in an environment that doesn’t support C++
fully.
- Designing driver code using good C++.
I can be of some help with 1:
You need to do a fair bit of work to get C++ to run in a driver
environment. The major, and obvious points, are new and delete
functionality. You don’t have a standard C runtime library, so you can’t
just malloc/free to do memory allocation (which is essentially the way
new/delete works in a normal application).
You can replace new/delete with your own “overrides”, which should solve
this.
void * __cdecl::operator new( unsigned int size )
{
void *ptr;
ptr = allocatememory(size);
assert(ptr);
return ptr;
}
void __cdecl ::operator delete( void *ptr ) {
if( ptr )
freememory(ptr);
}
How you implement allocatememory and freememory is another story… 
You also can’t have static objects, because there is no “default
constructor”, so objects will not be constructed until you create them.
This means that this form won’t work:
class SomeClass x;
void func(…)
{
x.something = 7;
}
This is because x will not get constructed. You need to reconstruction
with a x as a pointer to SomeClass and then add
x = new SomeClass;
at “start of day”.
There’s a bunch of other support functions that are less obvious, like
“You’ve called a pure virtual function”.
int __cdecl _purecall( void )
{
assert( 0 );
}
I’m sure there are some other gotchas too, but these will certainly help
you.
You may also find that the stack space used is greater, due to the
“ease” with which you create objects and store more than you though on
the stack. The stack of a driver is only small.
I can’t really do much to explain #2 in the list above, simply because
what we use the C++ for is to simulate the next generation graphics
chip, and it’s linked into the driver as a chip simulator. We have
severe problems with for instance stack usage, but sidestep the issue by
breaking the rules and creating a second stack that we switch to before
calling the simulator with a “pretend to write this register” or
“pretend you read this memory”. (We also have our own multithreading in
the C++ code, which doesn’t use Windows threads, to simulate the
parallelism of different units working on the same clock-cycle in the
chip).
–
Mats
-----Original Message-----
From: Robert Fernando -ntlworld [mailto:xxxxx@ntlworld.com]
Sent: Wednesday, February 11, 2004 11:00 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] A giuide to writing device drivers in c++
Hi all,
Is there a good guide / samples which will outline how you use c++ to
develop a windows device driver. I know about developing windows
device drivers in c.
thanks
Robert Fernando
www.rowanclose.com
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.583 / Virus Database: 369 - Release Date: 10/02/2004
Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
You are currently subscribed to ntdev as: xxxxx@3dlabs.com To
unsubscribe send a blank email to xxxxx@lists.osr.com
Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
You are currently subscribed to ntdev as: xxxxx@maxtor.com To
unsubscribe send a blank email to xxxxx@lists.osr.com
Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
You are currently subscribed to ntdev as: xxxxx@windows.microsoft.com
To unsubscribe send a blank email to xxxxx@lists.osr.com
Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
You are currently subscribed to ntdev as: xxxxx@maxtor.com To
unsubscribe send a blank email to xxxxx@lists.osr.com