Windows Vista Tips

Windows Vista Tips > Newsgroups > Windows Vista Drivers > KMDF and class

Reply
Thread Tools Display Modes

KMDF and class

 
 
Harald
Guest
Posts: n/a

 
      06-23-2009

Hi

I using the Kernel Mode Framework(KMDF) for developing my driver. I have an
function which is called from 4 threads at the same time and it has local
variables which are different for all calls. So i want to implement this as
an class (c++) to make 4 instances of the class and the function. But when i
write class "name"{}; i got an error from the compiler that he didn't know
the command class. What must i change that he compile?!

Harald
 
Reply With Quote
 
 
 
 
Don Burn
Guest
Posts: n/a

 
      06-23-2009

By default drivers are C not C++. This is a complex issue that raises lots
of strong opinions. Take a look at
http://www.microsoft.com/whdc/driver/kernel/KMcode.mspx for some basic
information on the problems. Consider looking at the archives of NTDEV at
http://www.osronline.com for a lot of discussions. If you still want to use
C++ go to
http://www.hollistech.com/ and under resources get the C++ Kernel Runtime
Environment.


--
Don Burn (MVP, Windows DDK)
Windows Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr
Remove StopSpam to reply




"Harald" <> wrote in message
news:711340ED-51B5-43BA-8C2F-...
> Hi
>
> I using the Kernel Mode Framework(KMDF) for developing my driver. I have
> an
> function which is called from 4 threads at the same time and it has local
> variables which are different for all calls. So i want to implement this
> as
> an class (c++) to make 4 instances of the class and the function. But when
> i
> write class "name"{}; i got an error from the compiler that he didn't know
> the command class. What must i change that he compile?!
>
> Harald
>
> __________ Information from ESET NOD32 Antivirus, version of virus
> signature database 4179 (20090622) __________
>
> The message was checked by ESET NOD32 Antivirus.
>
> http://www.eset.com
>
>
>




__________ Information from ESET NOD32 Antivirus, version of virus signature database 4179 (20090622) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com




 
Reply With Quote
 
Harald
Guest
Posts: n/a

 
      06-23-2009

Hi

Thanks for your fast answer. I dont want to use c++ but i think i need to. I
have 4 Thread which all call the same function 250 times at the same time. Is
it possible that when the threads call the function at the same time they all
use the same local function of the function or get every function there own
local variables?!

Harald

 
Reply With Quote
 
Don Burn
Guest
Posts: n/a

 
      06-23-2009

Each thread has its own stack where the local variables reside. So there is
no problem with concurrent calls to the functions from local variables.


--
Don Burn (MVP, Windows DDK)
Windows Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr
Remove StopSpam to reply



"Harald" <> wrote in message
news:EFED1E3F-CEC3-411B-861E-...
> Hi
>
> Thanks for your fast answer. I dont want to use c++ but i think i need to.
> I
> have 4 Thread which all call the same function 250 times at the same time.
> Is
> it possible that when the threads call the function at the same time they
> all
> use the same local function of the function or get every function there
> own
> local variables?!
>
> Harald
>
>
> __________ Information from ESET NOD32 Antivirus, version of virus
> signature database 4179 (20090622) __________
>
> The message was checked by ESET NOD32 Antivirus.
>
> http://www.eset.com
>
>
>




__________ Information from ESET NOD32 Antivirus, version of virus signature database 4179 (20090622) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com




 
Reply With Quote
 
Harald
Guest
Posts: n/a

 
      06-23-2009

Hi

Its not the problem with the local variables of the thread but the function
has also some local variables and they are for all calls the same or? For
example i have an variable for an for iteration named i. When now the four
threads all call the function at the same time the all have the same variable
or is the variable for every call new?!

Harald

 
Reply With Quote
 
Don Burn
Guest
Posts: n/a

 
      06-23-2009

There are no thread local variables only function, each invocation of a
function allocates its local variables on the stack of the running thread.


--
Don Burn (MVP, Windows DDK)
Windows Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr
Remove StopSpam to reply



"Harald" <> wrote in message
news:C4413F56-858D-4155-A1AB-...
> Hi
>
> Its not the problem with the local variables of the thread but the
> function
> has also some local variables and they are for all calls the same or? For
> example i have an variable for an for iteration named i. When now the four
> threads all call the function at the same time the all have the same
> variable
> or is the variable for every call new?!
>
> Harald
>
>
> __________ Information from ESET NOD32 Antivirus, version of virus
> signature database 4180 (20090623) __________
>
> The message was checked by ESET NOD32 Antivirus.
>
> http://www.eset.com
>
>
>




__________ Information from ESET NOD32 Antivirus, version of virus signature database 4180 (20090623) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com




 
Reply With Quote
 
m
Guest
Posts: n/a

 
      06-24-2009

This is basic C! You probably should not be programming in KM if you do not
understand the binary behaviour of your compiler since the next question
will undoubtedly be something to the effect ‘when my driver is installed,
sometimes Windows goes BSOD. How can I fix this problem?’

I suggest that you gain experience with the C language in UM first, and then
try to tackle a KM project.



"Harald" <> wrote in message
news:C4413F56-858D-4155-A1AB-...
> Hi
>
> Its not the problem with the local variables of the thread but the
> function
> has also some local variables and they are for all calls the same or? For
> example i have an variable for an for iteration named i. When now the four
> threads all call the function at the same time the all have the same
> variable
> or is the variable for every call new?!
>
> Harald
>


 
Reply With Quote
 
Volodymyr Shcherbyna
Guest
Posts: n/a

 
      06-24-2009

As others replied in this thread, each thread has it's own stack frame, so
you are safe in your case. However, you should remember that intensivly
using stack in kernel is a bad idea, as it is limited to 3 pages, which is
12 KB in x32. You have to follow the following guides from here:
http://msdn.microsoft.com/en-us/library/ms796278.aspx

Moreover, if you will be allocating local variables on stack like this:

char szMyDummyArray[2048];

You definitly would not pass staticdrv test which is a part of DTM
submission package .

--
Volodymyr M. Shcherbyna, blog: http://www.shcherbyna.com/
(This posting is provided "AS IS" with no warranties, and confers no
rights)
"Harald" <> wrote in message
news:C4413F56-858D-4155-A1AB-...
> Hi
>
> Its not the problem with the local variables of the thread but the
> function
> has also some local variables and they are for all calls the same or? For
> example i have an variable for an for iteration named i. When now the four
> threads all call the function at the same time the all have the same
> variable
> or is the variable for every call new?!
>
> Harald
>



 
Reply With Quote
 
EMP
Guest
Posts: n/a

 
      06-24-2009

"Harald" wrote:
>
> Its not the problem with the local variables of the thread but the function
> has also some local variables and they are for all calls the same or? For
> example i have an variable for an for iteration named i. When now the four
> threads all call the function at the same time the all have the same variable
> or is the variable for every call new?!
>


As others have said, on each invocation of the function its local variables
are allocated on the stack of the calling thread. If all threads call the
function at the same time then each thread has its own set of local
variables, independent of all other threads.
However, if variable "i" is global (ex. to count all iterations for all
threads - which means there is only one copy of "i") then you have to
serialize access to that variable, either with a lock or by using available
atomic update APIs. Think about what would happen if all threads attempted to
update "i" at the same time.

EMP.
 
Reply With Quote
 
Scott Noone
Guest
Posts: n/a

 
      06-24-2009

> You definitly would not pass staticdrv test which is a part of DTM
> submission package .


Prefast has a /StackHogThreshold switch that can also find these. It
defaults to 1024 bytes, though I like to go much further down than that
(lots of people like to stick filters in the FS stack so we're constantly
hammered by this).

-scott

--
Scott Noone
Consulting Associate
OSR Open Systems Resources, Inc.
http://www.osronline.com



"Volodymyr Shcherbyna" <> wrote in message
news:...
> As others replied in this thread, each thread has it's own stack frame, so
> you are safe in your case. However, you should remember that intensivly
> using stack in kernel is a bad idea, as it is limited to 3 pages, which is
> 12 KB in x32. You have to follow the following guides from here:
> http://msdn.microsoft.com/en-us/library/ms796278.aspx
>
> Moreover, if you will be allocating local variables on stack like this:
>
> char szMyDummyArray[2048];
>
> You definitly would not pass staticdrv test which is a part of DTM
> submission package .
>
> --
> Volodymyr M. Shcherbyna, blog: http://www.shcherbyna.com/
> (This posting is provided "AS IS" with no warranties, and confers no
> rights)
> "Harald" <> wrote in message
> news:C4413F56-858D-4155-A1AB-...
>> Hi
>>
>> Its not the problem with the local variables of the thread but the
>> function
>> has also some local variables and they are for all calls the same or? For
>> example i have an variable for an for iteration named i. When now the
>> four
>> threads all call the function at the same time the all have the same
>> variable
>> or is the variable for every call new?!
>>
>> Harald
>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
KMDF Class Filter Driver Installs on Vista/XP.. Fails on 2K Gabe Windows Vista Drivers 3 10-20-2006 10:15 PM
KMDF Class Filter Drive INITSTARTFAILED gabenbecca@gmail.com Windows Vista Drivers 4 10-10-2006 08:59 PM
[KMDF USB] I/O to bulk endpoints on CDC ACM data class interface chris.aseltine@gmail.com Windows Vista Drivers 4 09-08-2006 01:13 PM
Does windows vista supports AVstream Class & Stream class drivers? darshan.tapdia@gmail.com Windows Vista Drivers 1 06-29-2006 10:54 AM
KMDF Interface : is it possible to use a c++ class ? b.lu Windows Vista Drivers 4 04-30-2006 08:11 PM



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59