Does the stack of driver locates on "non paged" or "paged" memory?

thanks!

Huh?

d

tiny phone keyboard + fat thumbs = you do the muth

-----Original Message-----
From: xxxxx@hotmail.com
Sent: Sunday, March 28, 2010 6:45 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Does the stack of driver locates on “non paged” or “paged” memory?

thanks!


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

Why does it matter?

The personal opinion of
Gary G. Little

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@hotmail.com
Sent: Sunday, March 28, 2010 8:46 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Does the stack of driver locates on “non paged” or “paged”
memory?

thanks!


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

__________ Information from ESET Smart Security, version of virus signature
database 4980 (20100328) __________

The message was checked by ESET Smart Security.

http://www.eset.com

__________ Information from ESET Smart Security, version of virus signature
database 4980 (20100328) __________

The message was checked by ESET Smart Security.

http://www.eset.com

>Huh?

when a kernel driver is running in memory, its stack is loaded to “non paged” or “paged” memory?
thanks!

>Why does it matter?

In my code, Some local variables, which are defined in a function, will be accessed in a “spin lock”. So, If these local variables are swap out to harddisk, driver will cause OS to crash.

Then, How can I prohibit these variables from being swapped out to harddisk?

Do not mark the function as PAGEable

d

tiny phone keyboard + fat thumbs = you do the muth

-----Original Message-----
From: xxxxx@hotmail.com
Sent: Sunday, March 28, 2010 7:24 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] Does the stack of driver locates on “non paged” or “paged” memory?

>Why does it matter?

In my code, Some local variables, which are defined in a function, will be accessed in a “spin lock”. So, If these local variables are swap out to harddisk, driver will cause OS to crash.

Then, How can I prohibit these variables from being swapped out to harddisk?


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

>Do not mark the function as PAGEable

thanks!!

It is my understanding that the code segment of a particular function has
nothing to do with whether or not the stack of a thread that calls that
function might be paged out or not. I thought it had only to do with
whether or not the thread blocks. If the thread blocks, the stack may be
paged out. If the thread does not block, the stack will not be paged out.
Or so I thought.

Regards,
Dave Cattley

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Doron Holan
Sent: Sunday, March 28, 2010 10:31 PM
To: Windows System Software Devs Interest List
Subject: RE: RE:[ntdev] Does the stack of driver locates on “non paged” or
“paged” memory?

Do not mark the function as PAGEable

d

tiny phone keyboard + fat thumbs = you do the muth

-----Original Message-----
From: xxxxx@hotmail.com
Sent: Sunday, March 28, 2010 7:24 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] Does the stack of driver locates on “non paged” or
“paged” memory?

>Why does it matter?

In my code, Some local variables, which are defined in a function, will be
accessed in a “spin lock”. So, If these local variables are swap out to
harddisk, driver will cause OS to crash.

Then, How can I prohibit these variables from being swapped out to harddisk?


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

You really need to study Windows memory management.

First of all, it really doesn’t make any sense to protect a local variable
with a spin lock. A stack-allocated variable exists only until the
allocating function exits. In addition, if the function was actually called
concurrently in the context of a different CPU or thread, then there would
be a separate instance of the local variable on a different stack. So, no
need to protect it with a spin lock.

One thing that you cannot do is pass a stack-allocated variable to an
asynchronous routine and then exit the function that contained the
stack-allocated variable. In this case the question of whether the
stack-allocated variable I paged or non-paged doesn’t really matter. What
does matter is as soon as you exit the function the function’s stack is
re-used. This is true in user-mode and kernel mode.

Study the basics and then ask a better question.

Thomas F. Divine


From:
Sent: Sunday, March 28, 2010 10:25 PM
To: “Windows System Software Devs Interest List”
Subject: RE:[ntdev] Does the stack of driver locates on “non paged” or
“paged” memory?

>>Why does it matter?
>
> In my code, Some local variables, which are defined in a function, will be
> accessed in a “spin lock”. So, If these local variables are swap out to
> harddisk, driver will cause OS to crash.
>
> Then, How can I prohibit these variables from being swapped out to
> harddisk?
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer

>You really need to study Windows memory management.

First of all, it really doesn’t make any sense to protect a local variable
with a spin lock. A stack-allocated variable exists only until the
allocating function exits. In addition, if the function was actually called
concurrently in the context of a different CPU or thread, then there would
be a separate instance of the local variable on a different stack. So, no
need to protect it with a spin lock.

One thing that you cannot do is pass a stack-allocated variable to an
asynchronous routine and then exit the function that contained the
stack-allocated variable. In this case the question of whether the
stack-allocated variable I paged or non-paged doesn’t really matter. What
does matter is as soon as you exit the function the function’s stack is
re-used. This is true in user-mode and kernel mode.

Study the basics and then ask a better question.

Thomas F. Divine

thanks

Hmm.

Your problems are more basic here. What you’re describing doesn’t make any sense for a few reasons.

I’d suggest that you take a look at this document about kernel memory management:

http://www.microsoft.com/whdc/driver/kernel/mem-mgmt.mspx

Also, if you happen to have a copy of Windows Internals, reading the chapter on memory management would provide a good introduction (read it before that paper, if you have it).

http://blogs.technet.com/markrussinovich/archive/2009/07/06/3261631.aspx

Good luck,

mm

>Hmm.

Your problems are more basic here. What you’re describing doesn’t make any
sense for a few reasons.

I’d suggest that you take a look at this document about kernel memory
management:

http://www.microsoft.com/whdc/driver/kernel/mem-mgmt.mspx

Also, if you happen to have a copy of Windows Internals, reading the chapter on
memory management would provide a good introduction (read it before that paper,
if you have it).

http://blogs.technet.com/markrussinovich/archive/2009/07/06/3261631.aspx

Good luck,

mm

thanks!!

While it does not make sense to protect a local var, you can stil use local vars while holding the lock. In that case, you better be sure that the var is not pageable. For instance, draining a list from the device extension to a local listhead, the list is protected by a spinlock.

d

tiny phone keyboard + fat thumbs = you do the muth

-----Original Message-----
From: Thomas F. Divine
Sent: Sunday, March 28, 2010 7:56 PM
To: Windows System Software Devs Interest List
Subject: Re: RE:[ntdev] Does the stack of driver locates on “non paged” or “paged” memory?

You really need to study Windows memory management.

First of all, it really doesn’t make any sense to protect a local variable
with a spin lock. A stack-allocated variable exists only until the
allocating function exits. In addition, if the function was actually called
concurrently in the context of a different CPU or thread, then there would
be a separate instance of the local variable on a different stack. So, no
need to protect it with a spin lock.

One thing that you cannot do is pass a stack-allocated variable to an
asynchronous routine and then exit the function that contained the
stack-allocated variable. In this case the question of whether the
stack-allocated variable I paged or non-paged doesn’t really matter. What
does matter is as soon as you exit the function the function’s stack is
re-used. This is true in user-mode and kernel mode.

Study the basics and then ask a better question.

Thomas F. Divine

--------------------------------------------------
From:
Sent: Sunday, March 28, 2010 10:25 PM
To: “Windows System Software Devs Interest List”
Subject: RE:[ntdev] Does the stack of driver locates on “non paged” or
“paged” memory?

>>Why does it matter?
>
> In my code, Some local variables, which are defined in a function, will be
> accessed in a “spin lock”. So, If these local variables are swap out to
> harddisk, driver will cause OS to crash.
>
> Then, How can I prohibit these variables from being swapped out to
> harddisk?
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

>If the thread blocks, the stack may be paged out.

Just to clarify, only if the thread waits with
KeWaitForSingleObject/KeWaitForMultipleObjects and specifies a WaitMode of
UserMode will the kernel stack be eligible for paging. This is important
since lots of code uses stack based events to wait for things such as I/O
completion and that would be broken if the kernel stack got paged out
(events need to be non-paged).

-scott


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

“David R. Cattley” wrote in message news:xxxxx@ntdev…
> It is my understanding that the code segment of a particular function has
> nothing to do with whether or not the stack of a thread that calls that
> function might be paged out or not. I thought it had only to do with
> whether or not the thread blocks. If the thread blocks, the stack may be
> paged out. If the thread does not block, the stack will not be paged out.
> Or so I thought.
>
> Regards,
> Dave Cattley
>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of Doron Holan
> Sent: Sunday, March 28, 2010 10:31 PM
> To: Windows System Software Devs Interest List
> Subject: RE: RE:[ntdev] Does the stack of driver locates on “non paged” or
> “paged” memory?
>
> Do not mark the function as PAGEable
>
> d
>
> tiny phone keyboard + fat thumbs = you do the muth
>
>
>
> -----Original Message-----
> From: xxxxx@hotmail.com
> Sent: Sunday, March 28, 2010 7:24 PM
> To: Windows System Software Devs Interest List
> Subject: RE:[ntdev] Does the stack of driver locates on “non paged” or
> “paged” memory?
>
>>Why does it matter?
>
> In my code, Some local variables, which are defined in a function, will be
> accessed in a “spin lock”. So, If these local variables are swap out to
> harddisk, driver will cause OS to crash.
>
> Then, How can I prohibit these variables from being swapped out to
> harddisk?
>
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>
>

Thanks Scott. A detail I had missplaced in my recollection.

Dave Cattley

From: xxxxx@osr.com
Subject: Re:[ntdev] RE:Does the stack of driver locates on “non paged” or “paged” memory?
Date: Mon, 29 Mar 2010 13:44:38 -0400
To: xxxxx@lists.osr.com

>If the thread blocks, the stack may be paged out.

Just to clarify, only if the thread waits with
KeWaitForSingleObject/KeWaitForMultipleObjects and specifies a WaitMode of
UserMode will the kernel stack be eligible for paging. This is important
since lots of code uses stack based events to wait for things such as I/O
completion and that would be broken if the kernel stack got paged out
(events need to be non-paged).

-scott


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

“David R. Cattley” wrote in message news:xxxxx@ntdev…
> > It is my understanding that the code segment of a particular function has
> > nothing to do with whether or not the stack of a thread that calls that
> > function might be paged out or not. I thought it had only to do with
> > whether or not the thread blocks. If the thread blocks, the stack may be
> > paged out. If the thread does not block, the stack will not be paged out.
> > Or so I thought.
> >
> > Regards,
> > Dave Cattley
> >
> > -----Original Message-----
> > From: xxxxx@lists.osr.com
> > [mailto:xxxxx@lists.osr.com] On Behalf Of Doron Holan
> > Sent: Sunday, March 28, 2010 10:31 PM
> > To: Windows System Software Devs Interest List
> > Subject: RE: RE:[ntdev] Does the stack of driver locates on “non paged” or
> > “paged” memory?
> >
> > Do not mark the function as PAGEable
> >
> > d
> >
> > tiny phone keyboard + fat thumbs = you do the muth
> >
> >
> >
> > -----Original Message-----
> > From: xxxxx@hotmail.com
> > Sent: Sunday, March 28, 2010 7:24 PM
> > To: Windows System Software Devs Interest List
> > Subject: RE:[ntdev] Does the stack of driver locates on “non paged” or
> > “paged” memory?
> >
> >>Why does it matter?
> >
> > In my code, Some local variables, which are defined in a function, will be
> > accessed in a “spin lock”. So, If these local variables are swap out to
> > harddisk, driver will cause OS to crash.
> >
> > Then, How can I prohibit these variables from being swapped out to
> > harddisk?
> >
> >
> > —
> > NTDEV is sponsored by OSR
> >
> > For our schedule of WDF, WDM, debugging and other seminars visit:
> > http://www.osr.com/seminars
> >
> > To unsubscribe, visit the List Server section of OSR Online at
> > http://www.osronline.com/page.cfm?name=ListServer
> >
> >
> > —
> > NTDEV is sponsored by OSR
> >
> > For our schedule of WDF, WDM, debugging and other seminars visit:
> > http://www.osr.com/seminars
> >
> > To unsubscribe, visit the List Server section of OSR Online at
> > http://www.osronline.com/page.cfm?name=ListServer
> >
> >
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer