Pageable Code Assert (Probably a basic question)

Hi (again),

Thanks for all the help so far from this novice.

I have encountered another problem which I am sure is very basic. I have
based my filter driver on the skeleton code produced by Walt Oney’s driver
wizard. The DispatchControl routine begins like this:

#pragma PAGEDCODE
NTSTATUS DispatchControl(…
{
PAGED_CODE();

When the driver is running and passing Irps down to the lower driver, after
a few seconds the ASSERT in this PAGED_CODE() macro fires with the message:
“EX: Pageable code called at IRQL 2”.

I assume that this has happened because after a few seconds this routine has
been “paged” out of memory, but surely that is what the PAGEDCODE pragma is
saying may happen.

The PAGEDCODE pragma looks like this:
code_seg(“PAGE”)

When I press “g” to continue the driver resumes until the next ASSERT. There
is no bugcheck.

What do I do here? Comment out the macro? I guess it is there for a reason.

Thanks

Alasdair (confused)

NOTICE AND DISCLAIMER:
This email (including attachments) is confidential. If you have received
this email in error please notify the sender immediately and delete this
email from your system without copying or disseminating it or placing any
reliance upon its contents. We cannot accept liability for any breaches of
confidence arising through use of email. Any opinions expressed in this
email (including attachments) are those of the author and do not necessarily
reflect our opinions. We will not accept responsibility for any commitments
made by our employees outside the scope of our business. We do not warrant
the accuracy or completeness of such information.

Hi Alasdair.

Paged code is fine, but in this case, the macro is checking that you’re not
calling the code in IRQL >= DISPATCH. The reason for this is that should
the code happen to be paged out, there’s no way the OS can page it back in,
as it’s running at an IRQL that prevents it from running the page-in code,
and thus, you’d blue-screen when this happens. Obviously, your test-machine
probably has enough memory and is excercising your driver enough to not
cause it to be paged out, but that doesn’t mean that it’s not a problem in
a different situation in a different system.

I’m pretty sure that you’d get a bug-check if you used Driver Verifier on
your driver, as it has a mechanism that “pages out” all pages that are
pageable, just to avoid you getting to debug the problem when you’ve got a
customer who has a tighter memory requirement than your test-system… :wink:
[I put “pages out” in quotes, because what DV really does is just to mark the page “not present”, whilst the page is actually still in memory, it’s just not available to code until the swapper process is available, and anything that accesses this page from high IRQL will automatically cause a BSOD!].


Mats
xxxxx@lists.osr.com wrote on 10/07/2004 11:22:50 AM:

Hi (again),
Thanks for all the help so far from this novice.

I have encountered another problem which I am sure is very basic. I
have based my filter driver on the skeleton code produced by Walt
Oney’s driver wizard. The DispatchControl routine begins like this:

#pragma PAGEDCODE
NTSTATUS DispatchControl(…
{
PAGED_CODE();

When the driver is running and passing Irps down to the lower
driver, after a few seconds the ASSERT in this PAGED_CODE() macro
fires with the message:
“EX: Pageable code called at IRQL 2”.
I assume that this has happened because after a few seconds this
routine has been “paged” out of memory, but surely that is what the
PAGEDCODE pragma is saying may happen.
The PAGEDCODE pragma looks like this:
code_seg(“PAGE”)
When I press “g” to continue the driver resumes until the next
ASSERT. There is no bugcheck.
What do I do here? Comment out the macro? I guess it is there for a
reason.
Thanks
Alasdair (confused)

NOTICE AND DISCLAIMER:
This email (including attachments) is confidential. If you have
received this email in error please notify the sender immediately
and delete this email from your system without copying or
disseminating it or placing any reliance upon its contents. We
cannot accept liability for any breaches of confidence arising
through use of email. Any opinions expressed in this email
(including attachments) are those of the author and do not
necessarily reflect our opinions. We will not accept responsibility
for any commitments made by our employees outside the scope of our
business. We do not warrant the accuracy or completeness of such
information.

Questions? First check the Kernel Driver FAQ at http://www.
osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: unknown lmsubst tag argument:
‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com
ForwardSourceID:NT00004CF6

Hi Mats,

Thanks for this very informative reply, I understand what the purpose of the
macro is now but I still don’t know why the ASSERT fires after a few
seconds. What is wrong with the way the routine is being called when this
happens?

The macro (in wdm.h) is:
if(KeGetCurrentIrql() > APC_LEVEL)
{
KdPrint(( “EX : Pageable code called at IRQL %d\n”.
KeGetCurrentIrql() ));
ASSERT(FALSE);
}

APC_LEVEL is 1, DISPATCH_LEVEL is 2 so this will fire whenever the routine
is called *AT* Dispatch level. Is it being called at the wrong level for
some reason?

I am running DV.

Thanks

Alasdair (still confused)

Hi Alasdair.

Paged code is fine, but in this case, the macro is checking
that you’re not calling the code in IRQL >= DISPATCH. The
reason for this is that should the code happen to be paged
out, there’s no way the OS can page it back in, as it’s
running at an IRQL that prevents it from running the page-in
code, and thus, you’d blue-screen when this happens.
Obviously, your test-machine probably has enough memory and
is excercising your driver enough to not cause it to be paged
out, but that doesn’t mean that it’s not a problem in a
different situation in a different system.

I’m pretty sure that you’d get a bug-check if you used Driver
Verifier on your driver, as it has a mechanism that “pages
out” all pages that are pageable, just to avoid you getting
to debug the problem when you’ve got a customer who has a
tighter memory requirement than your test-system… :wink: [I put “pages out” in quotes, because what DV really does is just to mark the page “not present”, whilst the page is actually still in memory, it’s just not available to code until the swapper process is available, and anything that accesses this page from high IRQL will automatically cause a BSOD!].


Mats
xxxxx@lists.osr.com wrote on 10/07/2004 11:22:50 AM:

> Hi (again),
> Thanks for all the help so far from this novice.
>
> I have encountered another problem which I am sure is very basic. I
> have based my filter driver on the skeleton code produced by Walt
> Oney’s driver wizard. The DispatchControl routine begins like this:
>
> #pragma PAGEDCODE
> NTSTATUS DispatchControl(…
> {
> PAGED_CODE();
> …
>
> When the driver is running and passing Irps down to the
lower driver,
> after a few seconds the ASSERT in this PAGED_CODE() macro
fires with
> the message:
> “EX: Pageable code called at IRQL 2”.
> I assume that this has happened because after a few seconds this
> routine has been “paged” out of memory, but surely that is what the
> PAGEDCODE pragma is saying may happen. The PAGEDCODE pragma
looks like
> this:
> code_seg(“PAGE”)
> When I press “g” to continue the driver resumes until the
next ASSERT.
> There is no bugcheck. What do I do here? Comment out the macro? I
> guess it is there for a
reason.
> Thanks
> Alasdair (confused)
>

> NOTICE AND DISCLAIMER:
> This email (including attachments) is confidential. If you have
> received this email in error please notify the sender
immediately and
> delete this email from your system without copying or
disseminating it
> or placing any reliance upon its contents. We cannot
accept liability
> for any breaches of confidence arising through use of email. Any
> opinions expressed in this email (including attachments)
are those of
> the author and do not necessarily reflect our opinions. We
will not
> accept responsibility for any commitments made by our employees
> outside the scope of our business. We do not warrant the
accuracy or
> completeness of such
information.
> —
> Questions? First check the Kernel Driver FAQ at http://www.
> osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: unknown lmsubst tag
> argument:
‘’
> To unsubscribe send a blank email to
xxxxx@lists.osr.com
> ForwardSourceID:NT00004CF6


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as:
xxxxx@t-mobile.co.uk To unsubscribe send a blank
email to xxxxx@lists.osr.com

NOTICE AND DISCLAIMER:
This email (including attachments) is confidential. If you have received
this email in error please notify the sender immediately and delete this
email from your system without copying or disseminating it or placing any
reliance upon its contents. We cannot accept liability for any breaches of
confidence arising through use of email. Any opinions expressed in this
email (including attachments) are those of the author and do not necessarily
reflect our opinions. We will not accept responsibility for any commitments
made by our employees outside the scope of our business. We do not warrant
the accuracy or completeness of such information.

xxxxx@lists.osr.com wrote on 10/07/2004 11:47:25 AM:

Hi Mats,
Thanks for this very informative reply, I understand what the
purpose of the macro is now but I still don’t know why the ASSERT
fires after a few seconds. What is wrong with the way the routine is
being called when this happens?
The macro (in wdm.h) is:
if(KeGetCurrentIrql() > APC_LEVEL)
{
KdPrint(( “EX : Pageable code called at IRQL %d\n”.
KeGetCurrentIrql() ));
ASSERT(FALSE);
}
APC_LEVEL is 1, DISPATCH_LEVEL is 2 so this will fire whenever the
routine is called *AT* Dispatch level. Is it being called at the
wrong level for some reason?

Simple answer: Yes, it’s called at DISPATCH or higher level, which is not
allowed for pageable code.

As to “What is wrogn with the wway the routine is being called”, you’ve got
to have a look at the stack for the call when it asserts. In most cases it
would become obvious from your own code why it’s happening, but it could of
course be more complicated (for instance, it’s not called by your own
driver, because it’s called through some function pointer or similar
mechanism).

You need to EITHER make sure that the code isn’t called from DISPATCH
level, or that the code is not pageable (i.e. it’s not in code_seg(PAGE)).
The right choice of those depends on what your code is actually doing, and
I’m not sure from the context you’re giving what IRQL it’s expected to be
called at. One possibility is that you have a leacky lock situation…
Simplified code:

somefunction(…)
{
KeAcquireSpinLock(…);

if (something)
return;

KeReleaseSpinLock(…);
}

someotherfunction(…)
{

somefunction(…);

DispatchControl(…);
}

The above code should release the spinlock when leaving the function. This
type of function is usually best designed so that you set a variable with
the return value, rather than just returning. I’ve seen several cases (in
my own and others code) where there is a return in the middle that causes
some lock or other operation to be left “dangling” when some special case
happens.

Or you’re DispatchControl is called by an interrupt? That would cause IRQL
to be > 1 for sure…

I am running DV.

Ok, so maybe it’s not paging out code in the driver. I thought it did. Or
maybe you haven’t got all the settings turned on… You should enable all
options EXCEPT the Low resource simulation (unless you think your driver is
almost ready to ship, in which case a LRS is a good final test for
reliability).

I hope this helps. If not, I’m not sure I can offer much more help, as I’ve
only run into this problem once, and that was caused by an interrupt
calling a paged function (and it did a BSOD, but the stack-trace was quite
easy to follow and fix was a one-line removal, so not too difficult to find
or fix).


Mats

Thanks
Alasdair (still confused)

> Hi Alasdair.
>
> Paged code is fine, but in this case, the macro is checking
> that you’re not calling the code in IRQL >= DISPATCH. The
> reason for this is that should the code happen to be paged
> out, there’s no way the OS can page it back in, as it’s
> running at an IRQL that prevents it from running the page-in
> code, and thus, you’d blue-screen when this happens.
> Obviously, your test-machine probably has enough memory and
> is excercising your driver enough to not cause it to be paged
> out, but that doesn’t mean that it’s not a problem in a
> different situation in a different system.
>
> I’m pretty sure that you’d get a bug-check if you used Driver
> Verifier on your driver, as it has a mechanism that “pages
> out” all pages that are pageable, just to avoid you getting
> to debug the problem when you’ve got a customer who has a
> tighter memory requirement than your test-system… :wink: [I \> put “pages out” in quotes, because what DV really does is \> just to mark the page “not present”, whilst the page is \> actually still in memory, it’s just not available to code \> until the swapper process is available, and anything that \> accesses this page from high IRQL will automatically cause a BSOD!].
>
> –
> Mats
> xxxxx@lists.osr.com wrote on 10/07/2004 11:22:50 AM:
>
> > Hi (again),
> > Thanks for all the help so far from this novice.
> >
> > I have encountered another problem which I am sure is very basic. I
> > have based my filter driver on the skeleton code produced by Walt
> > Oney’s driver wizard. The DispatchControl routine begins like this:
> >
> > #pragma PAGEDCODE
> > NTSTATUS DispatchControl(…
> > {
> > PAGED_CODE();
> > …
> >
> > When the driver is running and passing Irps down to the
> lower driver,
> > after a few seconds the ASSERT in this PAGED_CODE() macro
> fires with
> > the message:
> > “EX: Pageable code called at IRQL 2”.
> > I assume that this has happened because after a few seconds this
> > routine has been “paged” out of memory, but surely that is what the
> > PAGEDCODE pragma is saying may happen. The PAGEDCODE pragma
> looks like
> > this:
> > code_seg(“PAGE”)
> > When I press “g” to continue the driver resumes until the
> next ASSERT.
> > There is no bugcheck. What do I do here? Comment out the macro? I
> > guess it is there for a
> reason.
> > Thanks
> > Alasdair (confused)
> >
>
> > NOTICE AND DISCLAIMER:
> > This email (including attachments) is confidential. If you have
> > received this email in error please notify the sender
> immediately and
> > delete this email from your system without copying or
> disseminating it
> > or placing any reliance upon its contents. We cannot
> accept liability
> > for any breaches of confidence arising through use of email. Any
> > opinions expressed in this email (including attachments)
> are those of
> > the author and do not necessarily reflect our opinions. We
> will not
> > accept responsibility for any commitments made by our employees
> > outside the scope of our business. We do not warrant the
> accuracy or
> > completeness of such
> information.
> > —
> > Questions? First check the Kernel Driver FAQ at http://www.
> > osronline.com/article.cfm?id=256
> >
> > You are currently subscribed to ntdev as: unknown lmsubst tag
> > argument:
> ‘’
> > To unsubscribe send a blank email to
> xxxxx@lists.osr.com
> > ForwardSourceID:NT00004CF6
>
>
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as:
> xxxxx@t-mobile.co.uk To unsubscribe send a blank
> email to xxxxx@lists.osr.com
>

NOTICE AND DISCLAIMER:
This email (including attachments) is confidential. If you have
received this email in error please notify the sender immediately
and delete this email from your system without copying or
disseminating it or placing any reliance upon its contents. We
cannot accept liability for any breaches of confidence arising
through use of email. Any opinions expressed in this email
(including attachments) are those of the author and do not
necessarily reflect our opinions. We will not accept responsibility
for any commitments made by our employees outside the scope of our
business. We do not warrant the accuracy or completeness of such
information.

Questions? First check the Kernel Driver FAQ at http://www.
osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: unknown lmsubst tag argument:
‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com
ForwardSourceID:NT00004D02

Hi Mats,

Thanks for going into so much detail for me.

Firstly - DV is set as you said, I did have the LRS turned on but it caused
me some grief when I thought I had run out of memory trying to allocate a
handful of bytes!
“I/O Verficiation” is set to “Level 2” (whwtever that means).

This is an upper filter driver (which I sure should be very simple) for a
serial port so any application can connect to the serial port via this
driver and I should be able to see ioctls and data going through. So the
routine is being called from (in my test cases) either from “HyperTerminal”
or Windows Dial-Up_networking, (which establishes a connection to the
Internet via a GPRS mobile handset, but that is not relevant to the problem
I think). The 2nd case is the one that fails, presumably because it sends
more data more rapidly than I can typing manually in HyperTerminal. In other
words, I have no control over what IRQL is used when the routine is called.

I will look into the leaky lock situation you mentioned (sounds like a place
you might encounter on a canal boat holiday). I am not clear how this might
affect things but I will check it now as I remember there is some code
relating to an IoAcquireRemoveLock which I will check now.

Thanks

Alasdair

> Hi Mats,
> Thanks for this very informative reply, I understand what
the purpose
> of the macro is now but I still don’t know why the ASSERT
fires after
> a few seconds. What is wrong with the way the routine is
being called
> when this happens? The macro (in wdm.h) is:
> if(KeGetCurrentIrql() > APC_LEVEL)
> {
> KdPrint(( “EX : Pageable code called at IRQL %d\n”.
> KeGetCurrentIrql() ));
> ASSERT(FALSE);
> }
> APC_LEVEL is 1, DISPATCH_LEVEL is 2 so this will fire whenever the
> routine is called *AT* Dispatch level. Is it being called at the
> wrong level for some reason?

Simple answer: Yes, it’s called at DISPATCH or higher level,
which is not allowed for pageable code.

As to “What is wrogn with the wway the routine is being
called”, you’ve got to have a look at the stack for the call
when it asserts. In most cases it would become obvious from
your own code why it’s happening, but it could of course be
more complicated (for instance, it’s not called by your own
driver, because it’s called through some function pointer or
similar mechanism).

You need to EITHER make sure that the code isn’t called from
DISPATCH level, or that the code is not pageable (i.e. it’s
not in code_seg(PAGE)). The right choice of those depends on
what your code is actually doing, and I’m not sure from the
context you’re giving what IRQL it’s expected to be called
at. One possibility is that you have a leacky lock
situation… Simplified code:

somefunction(…)
{
KeAcquireSpinLock(…);

if (something)
return;

KeReleaseSpinLock(…);
}

someotherfunction(…)
{

somefunction(…);

DispatchControl(…);
}

The above code should release the spinlock when leaving the
function. This type of function is usually best designed so
that you set a variable with the return value, rather than
just returning. I’ve seen several cases (in my own and others
code) where there is a return in the middle that causes some
lock or other operation to be left “dangling” when some
special case happens.

Or you’re DispatchControl is called by an interrupt? That
would cause IRQL to be > 1 for sure…

> I am running DV.

Ok, so maybe it’s not paging out code in the driver. I
thought it did. Or maybe you haven’t got all the settings
turned on… You should enable all options EXCEPT the Low
resource simulation (unless you think your driver is almost
ready to ship, in which case a LRS is a good final test for
reliability).

I hope this helps. If not, I’m not sure I can offer much more
help, as I’ve only run into this problem once, and that was
caused by an interrupt calling a paged function (and it did a
BSOD, but the stack-trace was quite easy to follow and fix
was a one-line removal, so not too difficult to find or fix).


Mats

> Thanks
> Alasdair (still confused)
>
> > Hi Alasdair.
> >
> > Paged code is fine, but in this case, the macro is checking that
> > you’re not calling the code in IRQL >= DISPATCH. The
reason for this
> > is that should the code happen to be paged out, there’s
no way the
> > OS can page it back in, as it’s running at an IRQL that
prevents it
> > from running the page-in code, and thus, you’d
blue-screen when this
> > happens. Obviously, your test-machine probably has enough
memory and
> > is excercising your driver enough to not cause it to be paged
> > out, but that doesn’t mean that it’s not a problem in a
> > different situation in a different system.
> >
> > I’m pretty sure that you’d get a bug-check if you used Driver
> > Verifier on your driver, as it has a mechanism that
“pages out” all
> > pages that are pageable, just to avoid you getting to debug the
> > problem when you’ve got a customer who has a tighter memory
> > requirement than your test-system… :wink: [I put “pages out” in \> \> quotes, because what DV really does is just to mark the page “not \> \> present”, whilst the page is actually still in memory, it’s just not \> \> available to code until the swapper process is available, and \> \> anything that accesses this page from high IRQL will automatically \> \> cause a BSOD!].
> >
> > –
> > Mats
> > xxxxx@lists.osr.com wrote on 10/07/2004 11:22:50 AM:
> >
> > > Hi (again),
> > > Thanks for all the help so far from this novice.
> > >
> > > I have encountered another problem which I am sure is
very basic.
> > > I have based my filter driver on the skeleton code produced by
> > > Walt Oney’s driver wizard. The DispatchControl routine
begins like
> > > this:
> > >
> > > #pragma PAGEDCODE
> > > NTSTATUS DispatchControl(…
> > > {
> > > PAGED_CODE();
> > > …
> > >
> > > When the driver is running and passing Irps down to the
> > lower driver,
> > > after a few seconds the ASSERT in this PAGED_CODE() macro
> > fires with
> > > the message:
> > > “EX: Pageable code called at IRQL 2”.
> > > I assume that this has happened because after a few
seconds this
> > > routine has been “paged” out of memory, but surely that is what
> > > the PAGEDCODE pragma is saying may happen. The PAGEDCODE pragma
> > looks like
> > > this:
> > > code_seg(“PAGE”)
> > > When I press “g” to continue the driver resumes until the
> > next ASSERT.
> > > There is no bugcheck. What do I do here? Comment out
the macro? I
> > > guess it is there for a
> > reason.
> > > Thanks
> > > Alasdair (confused)
> > >
> >
> > > NOTICE AND DISCLAIMER:
> > > This email (including attachments) is confidential. If
you have
> > > received this email in error please notify the sender
> > immediately and
> > > delete this email from your system without copying or
> > disseminating it
> > > or placing any reliance upon its contents. We cannot
> > accept liability
> > > for any breaches of confidence arising through use of
email. Any
> > > opinions expressed in this email (including attachments)
> > are those of
> > > the author and do not necessarily reflect our opinions. We
> > will not
> > > accept responsibility for any commitments made by our employees
> > > outside the scope of our business. We do not warrant the
> > accuracy or
> > > completeness of such
> > information.
> > > —
> > > Questions? First check the Kernel Driver FAQ at http://www.
> > > osronline.com/article.cfm?id=256
> > >
> > > You are currently subscribed to ntdev as: unknown lmsubst tag
> > > argument:
> > ‘’
> > > To unsubscribe send a blank email to
> > xxxxx@lists.osr.com
> > > ForwardSourceID:NT00004CF6
> >
> >
> >
> > —
> > Questions? First check the Kernel Driver FAQ at
> > http://www.osronline.com/article.cfm?id=256
> >
> > You are currently subscribed to ntdev as:
> > xxxxx@t-mobile.co.uk To unsubscribe send a
blank email to
> > xxxxx@lists.osr.com
> >
>

> NOTICE AND DISCLAIMER:
> This email (including attachments) is confidential. If you have
> received this email in error please notify the sender
immediately and
> delete this email from your system without copying or
disseminating it
> or placing any reliance upon its contents. We cannot
accept liability
> for any breaches of confidence arising through use of email. Any
> opinions expressed in this email (including attachments)
are those of
> the author and do not necessarily reflect our opinions. We
will not
> accept responsibility for any commitments made by our employees
> outside the scope of our business. We do not warrant the
accuracy or
> completeness of such
information.
> —
> Questions? First check the Kernel Driver FAQ at http://www.
> osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: unknown lmsubst tag
> argument:
‘’
> To unsubscribe send a blank email to
xxxxx@lists.osr.com
> ForwardSourceID:NT00004D02


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as:
xxxxx@t-mobile.co.uk To unsubscribe send a blank
email to xxxxx@lists.osr.com

NOTICE AND DISCLAIMER:
This email (including attachments) is confidential. If you have received
this email in error please notify the sender immediately and delete this
email from your system without copying or disseminating it or placing any
reliance upon its contents. We cannot accept liability for any breaches of
confidence arising through use of email. Any opinions expressed in this
email (including attachments) are those of the author and do not necessarily
reflect our opinions. We will not accept responsibility for any commitments
made by our employees outside the scope of our business. We do not warrant
the accuracy or completeness of such information.

Unless you have some overwhelming reason to mark you code pageable I would
suggest never doing this. As far as I am concerned this practice is a relic
of a bygone time when memory was very expensive and computers did not have
much of it at all.

Pageable data is a different story.

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Mats PETERSSON
Sent: Thursday, October 07, 2004 7:07 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] Pageable Code Assert (Probably a basic question)

xxxxx@lists.osr.com wrote on 10/07/2004 11:47:25 AM:

> Hi Mats,
> Thanks for this very informative reply, I understand what
the purpose
> of the macro is now but I still don’t know why the ASSERT
fires after
> a few seconds. What is wrong with the way the routine is
being called
> when this happens?
> The macro (in wdm.h) is:
> if(KeGetCurrentIrql() > APC_LEVEL)
> {
> KdPrint(( “EX : Pageable code called at IRQL %d\n”.
> KeGetCurrentIrql() ));
> ASSERT(FALSE);
> }
> APC_LEVEL is 1, DISPATCH_LEVEL is 2 so this will fire whenever the
> routine is called *AT* Dispatch level. Is it being called
at the wrong
> level for some reason?

Simple answer: Yes, it’s called at DISPATCH or higher level,
which is not allowed for pageable code.

As to “What is wrogn with the wway the routine is being
called”, you’ve got to have a look at the stack for the call
when it asserts. In most cases it would become obvious from
your own code why it’s happening, but it could of course be
more complicated (for instance, it’s not called by your own
driver, because it’s called through some function pointer or
similar mechanism).

You need to EITHER make sure that the code isn’t called from
DISPATCH level, or that the code is not pageable (i.e. it’s
not in code_seg(PAGE)).
The right choice of those depends on what your code is
actually doing, and I’m not sure from the context you’re
giving what IRQL it’s expected to be called at. One
possibility is that you have a leacky lock situation…
Simplified code:

somefunction(…)
{
KeAcquireSpinLock(…);

if (something)
return;

KeReleaseSpinLock(…);
}

someotherfunction(…)
{

somefunction(…);

DispatchControl(…);
}

The above code should release the spinlock when leaving the
function. This type of function is usually best designed so
that you set a variable with the return value, rather than
just returning. I’ve seen several cases (in my own and others
code) where there is a return in the middle that causes some
lock or other operation to be left “dangling” when some
special case happens.

Or you’re DispatchControl is called by an interrupt? That
would cause IRQL to be > 1 for sure…

> I am running DV.

Ok, so maybe it’s not paging out code in the driver. I
thought it did. Or maybe you haven’t got all the settings
turned on… You should enable all options EXCEPT the Low
resource simulation (unless you think your driver is almost
ready to ship, in which case a LRS is a good final test for
reliability).

I hope this helps. If not, I’m not sure I can offer much more
help, as I’ve only run into this problem once, and that was
caused by an interrupt calling a paged function (and it did a
BSOD, but the stack-trace was quite easy to follow and fix
was a one-line removal, so not too difficult to find or fix).


Mats

> Thanks
> Alasdair (still confused)
>
> > Hi Alasdair.
> >
> > Paged code is fine, but in this case, the macro is checking that
> > you’re not calling the code in IRQL >= DISPATCH. The
reason for this
> > is that should the code happen to be paged out, there’s
no way the
> > OS can page it back in, as it’s running at an IRQL that
prevents it
> > from running the page-in code, and thus, you’d
blue-screen when this
> > happens.
> > Obviously, your test-machine probably has enough memory and is
> > excercising your driver enough to not cause it to be
paged out, but
> > that doesn’t mean that it’s not a problem in a different
situation
> > in a different system.
> >
> > I’m pretty sure that you’d get a bug-check if you used Driver
> > Verifier on your driver, as it has a mechanism that
“pages out” all
> > pages that are pageable, just to avoid you getting to debug the
> > problem when you’ve got a customer who has a tighter memory
> > requirement than your test-system… :wink: [I put “pages out” in \> \> quotes, because what DV really does is just to mark the page “not \> \> present”, whilst the page is actually still in memory, it’s just not \> \> available to code until the swapper process is available, and \> \> anything that accesses this page from high IRQL will automatically \> \> cause a BSOD!].
> >
> > –
> > Mats
> > xxxxx@lists.osr.com wrote on 10/07/2004 11:22:50 AM:
> >
> > > Hi (again),
> > > Thanks for all the help so far from this novice.
> > >
> > > I have encountered another problem which I am sure is
very basic.
> > > I have based my filter driver on the skeleton code produced by
> > > Walt Oney’s driver wizard. The DispatchControl routine
begins like this:
> > >
> > > #pragma PAGEDCODE
> > > NTSTATUS DispatchControl(…
> > > {
> > > PAGED_CODE();
> > > …
> > >
> > > When the driver is running and passing Irps down to the
> > lower driver,
> > > after a few seconds the ASSERT in this PAGED_CODE() macro
> > fires with
> > > the message:
> > > “EX: Pageable code called at IRQL 2”.
> > > I assume that this has happened because after a few
seconds this
> > > routine has been “paged” out of memory, but surely that is what
> > > the PAGEDCODE pragma is saying may happen. The PAGEDCODE pragma
> > looks like
> > > this:
> > > code_seg(“PAGE”)
> > > When I press “g” to continue the driver resumes until the
> > next ASSERT.
> > > There is no bugcheck. What do I do here? Comment out
the macro? I
> > > guess it is there for a
> > reason.
> > > Thanks
> > > Alasdair (confused)
> > >
> >
> > > NOTICE AND DISCLAIMER:
> > > This email (including attachments) is confidential. If
you have
> > > received this email in error please notify the sender
> > immediately and
> > > delete this email from your system without copying or
> > disseminating it
> > > or placing any reliance upon its contents. We cannot
> > accept liability
> > > for any breaches of confidence arising through use of
email. Any
> > > opinions expressed in this email (including attachments)
> > are those of
> > > the author and do not necessarily reflect our opinions. We
> > will not
> > > accept responsibility for any commitments made by our employees
> > > outside the scope of our business. We do not warrant the
> > accuracy or
> > > completeness of such
> > information.
> > > —
> > > Questions? First check the Kernel Driver FAQ at http://www.
> > > osronline.com/article.cfm?id=256
> > >
> > > You are currently subscribed to ntdev as: unknown lmsubst tag
> > > argument:
> > ‘’
> > > To unsubscribe send a blank email to
> > xxxxx@lists.osr.com
> > > ForwardSourceID:NT00004CF6
> >
> >
> >
> > —
> > Questions? First check the Kernel Driver FAQ at
> > http://www.osronline.com/article.cfm?id=256
> >
> > You are currently subscribed to ntdev as:
> > xxxxx@t-mobile.co.uk To unsubscribe send a
blank email to
> > xxxxx@lists.osr.com
> >
>

> NOTICE AND DISCLAIMER:
> This email (including attachments) is confidential. If you have
> received this email in error please notify the sender
immediately and
> delete this email from your system without copying or
disseminating it
> or placing any reliance upon its contents. We cannot
accept liability
> for any breaches of confidence arising through use of email. Any
> opinions expressed in this email (including attachments)
are those of
> the author and do not necessarily reflect our opinions. We
will not
> accept responsibility for any commitments made by our employees
> outside the scope of our business. We do not warrant the
accuracy or
> completeness of such
information.
> —
> Questions? First check the Kernel Driver FAQ at http://www.
> osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: unknown lmsubst
tag argument:
‘’
> To unsubscribe send a blank email to xxxxx@lists.osr.com
> ForwardSourceID:NT00004D02


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as:
xxxxx@hollistech.com To unsubscribe send a blank email to
xxxxx@lists.osr.com

Hi Mats,

The stack looks like this when the ASSERT fires:

STACK_TEXT:
ef823e40 80531f50 8330b910 b9bfeeb8 8160c910
NetMonSerW2kD!DispatchControl+0x4d [C:\Dev\NetMonSerW2k\Control.cpp @ 51]
ef823e8c ef9102fe 80531f50 8160cc30 b9bfeeb8 nt!IovSpecialIrpCallDriver+0xcd
ef823e90 80531f50 8160cc30 b9bfeeb8 815fbd80
RootMdm!RootModemPassThrough+0x1e
ef823edc ef7452ab b9bfeeb8 815fbd28 ef745197 nt!IovSpecialIrpCallDriver+0xcd
ef823ee8 ef745197 815fbd28 b9bfefd4 b9bfeeb8 Modem!UniSendOurWaitDown+0x6d
ef823f48 80531b7c 815fbc70 b9bfee02 00000000 Modem!UniSniffWaitComplete+0x5b
ef823f90 ef4f9983 816341c4 816340f8 ffdff000
nt!IovSpecialIrpCompleteRequest+0x18c
ef823fa4 ef4f2301 816340f8 00000000 ef4f2202
serial!SerialTryToCompleteCurrent+0x9c
ef823fe0 804650d4 816343a4 816340f8 00000000 serial!SerialCompleteWait+0x2d
ef823ff4 804041b6 ee349708 00000000 00000000 nt!KiRetireDpcList+0x30

The top one is my routine, I don’t have a clue what the others are!

Alasdair

NOTICE AND DISCLAIMER:
This email (including attachments) is confidential. If you have received
this email in error please notify the sender immediately and delete this
email from your system without copying or disseminating it or placing any
reliance upon its contents. We cannot accept liability for any breaches of
confidence arising through use of email. Any opinions expressed in this
email (including attachments) are those of the author and do not necessarily
reflect our opinions. We will not accept responsibility for any commitments
made by our employees outside the scope of our business. We do not warrant
the accuracy or completeness of such information.

xxxxx@lists.osr.com wrote on 10/07/2004 12:21:38 PM:

Hi Mats,
Thanks for going into so much detail for me.
Firstly - DV is set as you said, I did have the LRS turned on but it
caused me some grief when I thought I had run out of memory trying
to allocate a handful of bytes!

Yeah, that’s what it does. And in a real world scenario, you can’t really
know how many bytes you’ll be able to allocate or when, so it’s good for
testing those “real world” bad secnarios, but not when you’re trying to
debug general bugs in the driver, only as a final test before shipping it.

“I/O Verficiation” is set to “Level 2” (whwtever that means).

Not sure what that means of the top of my head, but I’m sure it’s fine…
:wink:

This is an upper filter driver (which I sure should be very simple)
for a serial port so any application can connect to the serial port
via this driver and I should be able to see ioctls and data going
through. So the routine is being called from (in my test cases)
either from “HyperTerminal” or Windows Dial-Up_networking, (which
establishes a connection to the Internet via a GPRS mobile handset,
but that is not relevant to the problem I think). The 2nd case is
the one that fails, presumably because it sends more data more
rapidly than I can typing manually in HyperTerminal. In other words,
I have no control over what IRQL is used when the routine is called.

Oh yeah, I remember you saying that…

So, the DispatchControl function is called by the lower layer (i.e.
Serial.sys or whatever driver is actually the COM port driver itself,
assuming no other filters in between0), is that what happens?

I will look into the leaky lock situation you mentioned (sounds like
a place you might encounter on a canal boat holiday). I am not clear
how this might affect things but I will check it now as I remember
there is some code relating to an IoAcquireRemoveLock which I will check
now.

Not been on a narrow boat, but my fiancee’s parents live right next to one
of the locks for one of the rivers you do those things on. Not sure if it’s
leaking or not… :wink:

I’d also check the stack, and particularly look for any code that does
“RaiseIRQL” in there.

Also, if I remember right, this is only an internal tool, so you may just
want to set the code as “non-pageable” all the way through the driver, and
ignore this type of problem (obviously also removing the Macro that checks
the IRQL!).

Of course, you need to be aware of the fact that some OS calls are only
available at lower IRQL, and all your memory needs to be non-paged too for
this to work. I’m not suggesting that this is a final solution, especially
not for a commercial driver, but if it’s just a test/verification/debug
tool on a limited set of machinery, it’s a different situation…


Mats

Thanks
Alasdair

> > Hi Mats,
> > Thanks for this very informative reply, I understand what
> the purpose
> > of the macro is now but I still don’t know why the ASSERT
> fires after
> > a few seconds. What is wrong with the way the routine is
> being called
> > when this happens? The macro (in wdm.h) is:
> > if(KeGetCurrentIrql() > APC_LEVEL)
> > {
> > KdPrint(( “EX : Pageable code called at IRQL %d\n”.
> > KeGetCurrentIrql() ));
> > ASSERT(FALSE);
> > }
> > APC_LEVEL is 1, DISPATCH_LEVEL is 2 so this will fire whenever the
> > routine is called *AT* Dispatch level. Is it being called at the
> > wrong level for some reason?
>
> Simple answer: Yes, it’s called at DISPATCH or higher level,
> which is not allowed for pageable code.
>
> As to “What is wrogn with the wway the routine is being
> called”, you’ve got to have a look at the stack for the call
> when it asserts. In most cases it would become obvious from
> your own code why it’s happening, but it could of course be
> more complicated (for instance, it’s not called by your own
> driver, because it’s called through some function pointer or
> similar mechanism).
>
> You need to EITHER make sure that the code isn’t called from
> DISPATCH level, or that the code is not pageable (i.e. it’s
> not in code_seg(PAGE)). The right choice of those depends on
> what your code is actually doing, and I’m not sure from the
> context you’re giving what IRQL it’s expected to be called
> at. One possibility is that you have a leacky lock
> situation… Simplified code:
>
> somefunction(…)
> {
> KeAcquireSpinLock(…);
>
> if (something)
> return;
>
> KeReleaseSpinLock(…);
> }
>
> someotherfunction(…)
> {
> …
>
> somefunction(…);
>
> DispatchControl(…);
> }
>
> The above code should release the spinlock when leaving the
> function. This type of function is usually best designed so
> that you set a variable with the return value, rather than
> just returning. I’ve seen several cases (in my own and others
> code) where there is a return in the middle that causes some
> lock or other operation to be left “dangling” when some
> special case happens.
>
> Or you’re DispatchControl is called by an interrupt? That
> would cause IRQL to be > 1 for sure…
>
> > I am running DV.
>
> Ok, so maybe it’s not paging out code in the driver. I
> thought it did. Or maybe you haven’t got all the settings
> turned on… You should enable all options EXCEPT the Low
> resource simulation (unless you think your driver is almost
> ready to ship, in which case a LRS is a good final test for
> reliability).
>
> I hope this helps. If not, I’m not sure I can offer much more
> help, as I’ve only run into this problem once, and that was
> caused by an interrupt calling a paged function (and it did a
> BSOD, but the stack-trace was quite easy to follow and fix
> was a one-line removal, so not too difficult to find or fix).
>
> –
> Mats
>
> > Thanks
> > Alasdair (still confused)
> >
> > > Hi Alasdair.
> > >
> > > Paged code is fine, but in this case, the macro is checking that
> > > you’re not calling the code in IRQL >= DISPATCH. The
> reason for this
> > > is that should the code happen to be paged out, there’s
> no way the
> > > OS can page it back in, as it’s running at an IRQL that
> prevents it
> > > from running the page-in code, and thus, you’d
> blue-screen when this
> > > happens. Obviously, your test-machine probably has enough
> memory and
> > > is excercising your driver enough to not cause it to be paged
> > > out, but that doesn’t mean that it’s not a problem in a
> > > different situation in a different system.
> > >
> > > I’m pretty sure that you’d get a bug-check if you used Driver
> > > Verifier on your driver, as it has a mechanism that
> “pages out” all
> > > pages that are pageable, just to avoid you getting to debug the
> > > problem when you’ve got a customer who has a tighter memory
> > > requirement than your test-system… :wink: [I put “pages out” in \> \> \> quotes, because what DV really does is just to mark the page “not \> \> \> present”, whilst the page is actually still in memory, \> it’s just not \> \> \> available to code until the swapper process is available, and \> \> \> anything that accesses this page from high IRQL will \> automatically \> \> \> cause a BSOD!].
> > >
> > > –
> > > Mats
> > > xxxxx@lists.osr.com wrote on 10/07/2004 11:22:50 AM:
> > >
> > > > Hi (again),
> > > > Thanks for all the help so far from this novice.
> > > >
> > > > I have encountered another problem which I am sure is
> very basic.
> > > > I have based my filter driver on the skeleton code produced by
> > > > Walt Oney’s driver wizard. The DispatchControl routine
> begins like
> > > > this:
> > > >
> > > > #pragma PAGEDCODE
> > > > NTSTATUS DispatchControl(…
> > > > {
> > > > PAGED_CODE();
> > > > …
> > > >
> > > > When the driver is running and passing Irps down to the
> > > lower driver,
> > > > after a few seconds the ASSERT in this PAGED_CODE() macro
> > > fires with
> > > > the message:
> > > > “EX: Pageable code called at IRQL 2”.
> > > > I assume that this has happened because after a few
> seconds this
> > > > routine has been “paged” out of memory, but surely that is what
> > > > the PAGEDCODE pragma is saying may happen. The PAGEDCODE pragma
> > > looks like
> > > > this:
> > > > code_seg(“PAGE”)
> > > > When I press “g” to continue the driver resumes until the
> > > next ASSERT.
> > > > There is no bugcheck. What do I do here? Comment out
> the macro? I
> > > > guess it is there for a
> > > reason.
> > > > Thanks
> > > > Alasdair (confused)
> > > >
> > >
> > > > NOTICE AND DISCLAIMER:
> > > > This email (including attachments) is confidential. If
> you have
> > > > received this email in error please notify the sender
> > > immediately and
> > > > delete this email from your system without copying or
> > > disseminating it
> > > > or placing any reliance upon its contents. We cannot
> > > accept liability
> > > > for any breaches of confidence arising through use of
> email. Any
> > > > opinions expressed in this email (including attachments)
> > > are those of
> > > > the author and do not necessarily reflect our opinions. We
> > > will not
> > > > accept responsibility for any commitments made by our employees
> > > > outside the scope of our business. We do not warrant the
> > > accuracy or
> > > > completeness of such
> > > information.
> > > > —
> > > > Questions? First check the Kernel Driver FAQ at http://www.
> > > > osronline.com/article.cfm?id=256
> > > >
> > > > You are currently subscribed to ntdev as: unknown lmsubst tag
> > > > argument:
> > > ‘’
> > > > To unsubscribe send a blank email to
> > > xxxxx@lists.osr.com
> > > > ForwardSourceID:NT00004CF6
> > >
> > >
> > >
> > > —
> > > Questions? First check the Kernel Driver FAQ at
> > > http://www.osronline.com/article.cfm?id=256
> > >
> > > You are currently subscribed to ntdev as:
> > > xxxxx@t-mobile.co.uk To unsubscribe send a
> blank email to
> > > xxxxx@lists.osr.com
> > >
> >
>
> > NOTICE AND DISCLAIMER:
> > This email (including attachments) is confidential. If you have
> > received this email in error please notify the sender
> immediately and
> > delete this email from your system without copying or
> disseminating it
> > or placing any reliance upon its contents. We cannot
> accept liability
> > for any breaches of confidence arising through use of email. Any
> > opinions expressed in this email (including attachments)
> are those of
> > the author and do not necessarily reflect our opinions. We
> will not
> > accept responsibility for any commitments made by our employees
> > outside the scope of our business. We do not warrant the
> accuracy or
> > completeness of such
> information.
> > —
> > Questions? First check the Kernel Driver FAQ at http://www.
> > osronline.com/article.cfm?id=256
> >
> > You are currently subscribed to ntdev as: unknown lmsubst tag
> > argument:
> ‘’
> > To unsubscribe send a blank email to
> xxxxx@lists.osr.com
> > ForwardSourceID:NT00004D02
>
>
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as:
> xxxxx@t-mobile.co.uk To unsubscribe send a blank
> email to xxxxx@lists.osr.com
>

NOTICE AND DISCLAIMER:
This email (including attachments) is confidential. If you have
received this email in error please notify the sender immediately
and delete this email from your system without copying or
disseminating it or placing any reliance upon its contents. We
cannot accept liability for any breaches of confidence arising
through use of email. Any opinions expressed in this email
(including attachments) are those of the author and do not
necessarily reflect our opinions. We will not accept responsibility
for any commitments made by our employees outside the scope of our
business. We do not warrant the accuracy or completeness of such
information.

Questions? First check the Kernel Driver FAQ at http://www.
osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: unknown lmsubst tag argument:
‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com
ForwardSourceID:NT00004D1A

Hi Mark,

Well this is what the skelton code Walt Oney’s driver wizard produced when I
started this project, I assumed it was a requirement. I can change all the
routines to non-paged but I don’t understand where the problem is with the
current setting.

Mats - I have checked for any “leaky” locks and I don’t have any.

Thanks

Alasdair

-----Original Message-----
From: Mark Roddy [mailto:xxxxx@hollistech.com]
Sent: 07 October 2004 12:25
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] Pageable Code Assert (Probably a basic question)

Unless you have some overwhelming reason to mark you code
pageable I would suggest never doing this. As far as I am
concerned this practice is a relic of a bygone time when
memory was very expensive and computers did not have much of
it at all.

Pageable data is a different story.

> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of Mats
PETERSSON
> Sent: Thursday, October 07, 2004 7:07 AM
> To: Windows System Software Devs Interest List
> Subject: RE: [ntdev] Pageable Code Assert (Probably a basic
question)
>
>
>
>
>
>
>
>
> xxxxx@lists.osr.com wrote on 10/07/2004 11:47:25 AM:
>
> > Hi Mats,
> > Thanks for this very informative reply, I understand what
> the purpose
> > of the macro is now but I still don’t know why the ASSERT
> fires after
> > a few seconds. What is wrong with the way the routine is
> being called
> > when this happens?
> > The macro (in wdm.h) is:
> > if(KeGetCurrentIrql() > APC_LEVEL)
> > {
> > KdPrint(( “EX : Pageable code called at
IRQL %d\n”.
> > KeGetCurrentIrql() ));
> > ASSERT(FALSE);
> > }
> > APC_LEVEL is 1, DISPATCH_LEVEL is 2 so this will fire whenever the
> > routine is called *AT* Dispatch level. Is it being called
> at the wrong
> > level for some reason?
>
> Simple answer: Yes, it’s called at DISPATCH or higher level,
> which is not allowed for pageable code.
>
> As to “What is wrogn with the wway the routine is being
> called”, you’ve got to have a look at the stack for the call
> when it asserts. In most cases it would become obvious from
> your own code why it’s happening, but it could of course be
> more complicated (for instance, it’s not called by your own
> driver, because it’s called through some function pointer or
> similar mechanism).
>
> You need to EITHER make sure that the code isn’t called from
> DISPATCH level, or that the code is not pageable (i.e. it’s
> not in code_seg(PAGE)).
> The right choice of those depends on what your code is
> actually doing, and I’m not sure from the context you’re
> giving what IRQL it’s expected to be called at. One
> possibility is that you have a leacky lock situation…
> Simplified code:
>
> somefunction(…)
> {
> KeAcquireSpinLock(…);
>
> if (something)
> return;
>
> KeReleaseSpinLock(…);
> }
>
> someotherfunction(…)
> {
> …
>
> somefunction(…);
>
> DispatchControl(…);
> }
>
> The above code should release the spinlock when leaving the
> function. This type of function is usually best designed so
> that you set a variable with the return value, rather than
> just returning. I’ve seen several cases (in my own and others
> code) where there is a return in the middle that causes some
> lock or other operation to be left “dangling” when some
> special case happens.
>
> Or you’re DispatchControl is called by an interrupt? That
> would cause IRQL to be > 1 for sure…
>
> > I am running DV.
>
> Ok, so maybe it’s not paging out code in the driver. I
> thought it did. Or maybe you haven’t got all the settings
> turned on… You should enable all options EXCEPT the Low
> resource simulation (unless you think your driver is almost
> ready to ship, in which case a LRS is a good final test for
> reliability).
>
> I hope this helps. If not, I’m not sure I can offer much more
> help, as I’ve only run into this problem once, and that was
> caused by an interrupt calling a paged function (and it did a
> BSOD, but the stack-trace was quite easy to follow and fix
> was a one-line removal, so not too difficult to find or fix).
>
> –
> Mats
>
> > Thanks
> > Alasdair (still confused)
> >
> > > Hi Alasdair.
> > >
> > > Paged code is fine, but in this case, the macro is checking that
> > > you’re not calling the code in IRQL >= DISPATCH. The
> reason for this
> > > is that should the code happen to be paged out, there’s
> no way the
> > > OS can page it back in, as it’s running at an IRQL that
> prevents it
> > > from running the page-in code, and thus, you’d
> blue-screen when this
> > > happens.
> > > Obviously, your test-machine probably has enough memory and is
> > > excercising your driver enough to not cause it to be
> paged out, but
> > > that doesn’t mean that it’s not a problem in a different
> situation
> > > in a different system.
> > >
> > > I’m pretty sure that you’d get a bug-check if you used Driver
> > > Verifier on your driver, as it has a mechanism that
> “pages out” all
> > > pages that are pageable, just to avoid you getting to debug the
> > > problem when you’ve got a customer who has a tighter memory
> > > requirement than your test-system… :wink: [I put “pages out” in \> \> \> quotes, because what DV really does is just to mark the page “not \> \> \> present”, whilst the page is actually still in memory, \> it’s just not \> \> \> available to code until the swapper process is available, and \> \> \> anything that accesses this page from high IRQL will \> automatically \> \> \> cause a BSOD!].
> > >
> > > –
> > > Mats
> > > xxxxx@lists.osr.com wrote on 10/07/2004
11:22:50 AM:
> > >
> > > > Hi (again),
> > > > Thanks for all the help so far from this novice.
> > > >
> > > > I have encountered another problem which I am sure is
> very basic.
> > > > I have based my filter driver on the skeleton code produced by
> > > > Walt Oney’s driver wizard. The DispatchControl routine
> begins like this:
> > > >
> > > > #pragma PAGEDCODE
> > > > NTSTATUS DispatchControl(…
> > > > {
> > > > PAGED_CODE();
> > > > …
> > > >
> > > > When the driver is running and passing Irps down to the
> > > lower driver,
> > > > after a few seconds the ASSERT in this PAGED_CODE() macro
> > > fires with
> > > > the message:
> > > > “EX: Pageable code called at IRQL 2”.
> > > > I assume that this has happened because after a few
> seconds this
> > > > routine has been “paged” out of memory, but surely
that is what
> > > > the PAGEDCODE pragma is saying may happen. The
PAGEDCODE pragma
> > > looks like
> > > > this:
> > > > code_seg(“PAGE”)
> > > > When I press “g” to continue the driver resumes until the
> > > next ASSERT.
> > > > There is no bugcheck. What do I do here? Comment out
> the macro? I
> > > > guess it is there for a
> > > reason.
> > > > Thanks
> > > > Alasdair (confused)
> > > >
> > >
> > > > NOTICE AND DISCLAIMER:
> > > > This email (including attachments) is confidential. If
> you have
> > > > received this email in error please notify the sender
> > > immediately and
> > > > delete this email from your system without copying or
> > > disseminating it
> > > > or placing any reliance upon its contents. We cannot
> > > accept liability
> > > > for any breaches of confidence arising through use of
> email. Any
> > > > opinions expressed in this email (including attachments)
> > > are those of
> > > > the author and do not necessarily reflect our opinions. We
> > > will not
> > > > accept responsibility for any commitments made by our
employees
> > > > outside the scope of our business. We do not warrant the
> > > accuracy or
> > > > completeness of such
> > > information.
> > > > —
> > > > Questions? First check the Kernel Driver FAQ at http://www.
> > > > osronline.com/article.cfm?id=256
> > > >
> > > > You are currently subscribed to ntdev as: unknown lmsubst tag
> > > > argument:
> > > ‘’
> > > > To unsubscribe send a blank email to
> > > xxxxx@lists.osr.com
> > > > ForwardSourceID:NT00004CF6
> > >
> > >
> > >
> > > —
> > > Questions? First check the Kernel Driver FAQ at
> > > http://www.osronline.com/article.cfm?id=256
> > >
> > > You are currently subscribed to ntdev as:
> > > xxxxx@t-mobile.co.uk To unsubscribe send a
> blank email to
> > > xxxxx@lists.osr.com
> > >
> >
>
> > NOTICE AND DISCLAIMER:
> > This email (including attachments) is confidential. If you have
> > received this email in error please notify the sender
> immediately and
> > delete this email from your system without copying or
> disseminating it
> > or placing any reliance upon its contents. We cannot
> accept liability
> > for any breaches of confidence arising through use of email. Any
> > opinions expressed in this email (including attachments)
> are those of
> > the author and do not necessarily reflect our opinions. We
> will not
> > accept responsibility for any commitments made by our employees
> > outside the scope of our business. We do not warrant the
> accuracy or
> > completeness of such
> information.
> > —
> > Questions? First check the Kernel Driver FAQ at http://www.
> > osronline.com/article.cfm?id=256
> >
> > You are currently subscribed to ntdev as: unknown lmsubst
> tag argument:
> ‘’
> > To unsubscribe send a blank email to
> > xxxxx@lists.osr.com ForwardSourceID:NT00004D02
>
>
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as:
> xxxxx@hollistech.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@t-mobile.co.uk
To unsubscribe send a blank email to xxxxx@lists.osr.com

NOTICE AND DISCLAIMER:
This email (including attachments) is confidential. If you have received
this email in error please notify the sender immediately and delete this
email from your system without copying or disseminating it or placing any
reliance upon its contents. We cannot accept liability for any breaches of
confidence arising through use of email. Any opinions expressed in this
email (including attachments) are those of the author and do not necessarily
reflect our opinions. We will not accept responsibility for any commitments
made by our employees outside the scope of our business. We do not warrant
the accuracy or completeness of such information.

Hi again Mats,

So, the DispatchControl function is called by the lower layer
(i.e. Serial.sys or whatever driver is actually the COM port
driver itself, assuming no other filters in between0), is
that what happens?

Yes,

> I will look into the leaky lock situation you mentioned
(sounds like a
> place you might encounter on a canal boat holiday). I am
not clear how
> this might affect things but I will check it now as I
remember there
> is some code relating to an IoAcquireRemoveLock which I will check
now.

Not been on a narrow boat, but my fiancee’s parents live
right next to one of the locks for one of the rivers you do
those things on. Not sure if it’s leaking or not… :wink:

I am sure it will be.

I’d also check the stack, and particularly look for any code
that does “RaiseIRQL” in there.

Also, if I remember right, this is only an internal tool, so
you may just want to set the code as “non-pageable” all the
way through the driver, and ignore this type of problem
(obviously also removing the Macro that checks the IRQL!).

Yes that’s right, although my bosses boss (no pressure!) has promised it to
some “marketing” chap for testing so anything could happen.
I’ll try setting all code to non-pageable. I did mark the offending routines
as non-pageable (there were actually three, DispatchControl, DispatchRead
and DispatchWrite) but I left the check in and it still fired at IRQL 2, I
will remove the check as well and see what happens.

Of course, you need to be aware of the fact that some OS
calls are only available at lower IRQL, and all your memory
needs to be non-paged too for this to work.

I am not sure how to set the memory non-pageable as well.

I’m not
suggesting that this is a final solution, especially not for
a commercial driver, but if it’s just a
test/verification/debug tool on a limited set of machinery,
it’s a different situation…

Yes - it means that we are able to say “don’t do this under these
circumstances” and get away with it.

Thanks again - going to lunch now.

Alasdair

NOTICE AND DISCLAIMER:
This email (including attachments) is confidential. If you have received
this email in error please notify the sender immediately and delete this
email from your system without copying or disseminating it or placing any
reliance upon its contents. We cannot accept liability for any breaches of
confidence arising through use of email. Any opinions expressed in this
email (including attachments) are those of the author and do not necessarily
reflect our opinions. We will not accept responsibility for any commitments
made by our employees outside the scope of our business. We do not warrant
the accuracy or completeness of such information.

xxxxx@lists.osr.com wrote on 10/07/2004 12:39:01 PM:

Hi Mark,
Well this is what the skelton code Walt Oney’s driver wizard
produced when I started this project, I assumed it was a
requirement. I can change all the routines to non-paged but I don’t
understand where the problem is with the current setting.

The problem is that if you ever get the code paged out and call it from an
IRQL higher than 1, it’s going to BSOD. If that’s not enough to cause harm,
I don’t know what… :wink:

Basicly, putting the code in the PAGE section means that the driver is
allowed to page out the code, which is fine if it’s called at passive or
APC level, but if it’s called from above that level, it’s going to hit a
page-fault because the page isn’t present. Page faults are handled by a
separate process, and IRQL >= 2 doesn’t allow the current process (or
thread) to be switched, so the page-in process will not be able to run
before we lower the IRQL, and you get a “IRQL_NOT_LESS_THAN” BSOD.

Mats - I have checked for any “leaky” locks and I don’t have any.

Ok.


Mats

Thanks
Alasdair

> -----Original Message-----
> From: Mark Roddy [mailto:xxxxx@hollistech.com]
> Sent: 07 October 2004 12:25
> To: Windows System Software Devs Interest List
> Subject: RE: [ntdev] Pageable Code Assert (Probably a basic question)
>
>
> Unless you have some overwhelming reason to mark you code
> pageable I would suggest never doing this. As far as I am
> concerned this practice is a relic of a bygone time when
> memory was very expensive and computers did not have much of
> it at all.
>
> Pageable data is a different story.
>
> > -----Original Message-----
> > From: xxxxx@lists.osr.com
> > [mailto:xxxxx@lists.osr.com] On Behalf Of Mats
> PETERSSON
> > Sent: Thursday, October 07, 2004 7:07 AM
> > To: Windows System Software Devs Interest List
> > Subject: RE: [ntdev] Pageable Code Assert (Probably a basic
> question)
> >
> >
> >
> >
> >
> >
> >
> >
> > xxxxx@lists.osr.com wrote on 10/07/2004 11:47:25 AM:
> >
> > > Hi Mats,
> > > Thanks for this very informative reply, I understand what
> > the purpose
> > > of the macro is now but I still don’t know why the ASSERT
> > fires after
> > > a few seconds. What is wrong with the way the routine is
> > being called
> > > when this happens?
> > > The macro (in wdm.h) is:
> > > if(KeGetCurrentIrql() > APC_LEVEL)
> > > {
> > > KdPrint(( “EX : Pageable code called at
> IRQL %d\n”.
> > > KeGetCurrentIrql() ));
> > > ASSERT(FALSE);
> > > }
> > > APC_LEVEL is 1, DISPATCH_LEVEL is 2 so this will fire whenever the
> > > routine is called *AT* Dispatch level. Is it being called
> > at the wrong
> > > level for some reason?
> >
> > Simple answer: Yes, it’s called at DISPATCH or higher level,
> > which is not allowed for pageable code.
> >
> > As to “What is wrogn with the wway the routine is being
> > called”, you’ve got to have a look at the stack for the call
> > when it asserts. In most cases it would become obvious from
> > your own code why it’s happening, but it could of course be
> > more complicated (for instance, it’s not called by your own
> > driver, because it’s called through some function pointer or
> > similar mechanism).
> >
> > You need to EITHER make sure that the code isn’t called from
> > DISPATCH level, or that the code is not pageable (i.e. it’s
> > not in code_seg(PAGE)).
> > The right choice of those depends on what your code is
> > actually doing, and I’m not sure from the context you’re
> > giving what IRQL it’s expected to be called at. One
> > possibility is that you have a leacky lock situation…
> > Simplified code:
> >
> > somefunction(…)
> > {
> > KeAcquireSpinLock(…);
> >
> > if (something)
> > return;
> >
> > KeReleaseSpinLock(…);
> > }
> >
> > someotherfunction(…)
> > {
> > …
> >
> > somefunction(…);
> >
> > DispatchControl(…);
> > }
> >
> > The above code should release the spinlock when leaving the
> > function. This type of function is usually best designed so
> > that you set a variable with the return value, rather than
> > just returning. I’ve seen several cases (in my own and others
> > code) where there is a return in the middle that causes some
> > lock or other operation to be left “dangling” when some
> > special case happens.
> >
> > Or you’re DispatchControl is called by an interrupt? That
> > would cause IRQL to be > 1 for sure…
> >
> > > I am running DV.
> >
> > Ok, so maybe it’s not paging out code in the driver. I
> > thought it did. Or maybe you haven’t got all the settings
> > turned on… You should enable all options EXCEPT the Low
> > resource simulation (unless you think your driver is almost
> > ready to ship, in which case a LRS is a good final test for
> > reliability).
> >
> > I hope this helps. If not, I’m not sure I can offer much more
> > help, as I’ve only run into this problem once, and that was
> > caused by an interrupt calling a paged function (and it did a
> > BSOD, but the stack-trace was quite easy to follow and fix
> > was a one-line removal, so not too difficult to find or fix).
> >
> > –
> > Mats
> >
> > > Thanks
> > > Alasdair (still confused)
> > >
> > > > Hi Alasdair.
> > > >
> > > > Paged code is fine, but in this case, the macro is checking that
> > > > you’re not calling the code in IRQL >= DISPATCH. The
> > reason for this
> > > > is that should the code happen to be paged out, there’s
> > no way the
> > > > OS can page it back in, as it’s running at an IRQL that
> > prevents it
> > > > from running the page-in code, and thus, you’d
> > blue-screen when this
> > > > happens.
> > > > Obviously, your test-machine probably has enough memory and is
> > > > excercising your driver enough to not cause it to be
> > paged out, but
> > > > that doesn’t mean that it’s not a problem in a different
> > situation
> > > > in a different system.
> > > >
> > > > I’m pretty sure that you’d get a bug-check if you used Driver
> > > > Verifier on your driver, as it has a mechanism that
> > “pages out” all
> > > > pages that are pageable, just to avoid you getting to debug the
> > > > problem when you’ve got a customer who has a tighter memory
> > > > requirement than your test-system… :wink: [I put “pages out” in \> \> \> \> quotes, because what DV really does is just to mark the \> page “not \> \> \> \> present”, whilst the page is actually still in memory, \> \> it’s just not \> \> \> \> available to code until the swapper process is available, and \> \> \> \> anything that accesses this page from high IRQL will \> \> automatically \> \> \> \> cause a BSOD!].
> > > >
> > > > –
> > > > Mats
> > > > xxxxx@lists.osr.com wrote on 10/07/2004
> 11:22:50 AM:
> > > >
> > > > > Hi (again),
> > > > > Thanks for all the help so far from this novice.
> > > > >
> > > > > I have encountered another problem which I am sure is
> > very basic.
> > > > > I have based my filter driver on the skeleton code produced by
> > > > > Walt Oney’s driver wizard. The DispatchControl routine
> > begins like this:
> > > > >
> > > > > #pragma PAGEDCODE
> > > > > NTSTATUS DispatchControl(…
> > > > > {
> > > > > PAGED_CODE();
> > > > > …
> > > > >
> > > > > When the driver is running and passing Irps down to the
> > > > lower driver,
> > > > > after a few seconds the ASSERT in this PAGED_CODE() macro
> > > > fires with
> > > > > the message:
> > > > > “EX: Pageable code called at IRQL 2”.
> > > > > I assume that this has happened because after a few
> > seconds this
> > > > > routine has been “paged” out of memory, but surely
> that is what
> > > > > the PAGEDCODE pragma is saying may happen. The
> PAGEDCODE pragma
> > > > looks like
> > > > > this:
> > > > > code_seg(“PAGE”)
> > > > > When I press “g” to continue the driver resumes until the
> > > > next ASSERT.
> > > > > There is no bugcheck. What do I do here? Comment out
> > the macro? I
> > > > > guess it is there for a
> > > > reason.
> > > > > Thanks
> > > > > Alasdair (confused)
> > > > >
> > > >
> > > > > NOTICE AND DISCLAIMER:
> > > > > This email (including attachments) is confidential. If
> > you have
> > > > > received this email in error please notify the sender
> > > > immediately and
> > > > > delete this email from your system without copying or
> > > > disseminating it
> > > > > or placing any reliance upon its contents. We cannot
> > > > accept liability
> > > > > for any breaches of confidence arising through use of
> > email. Any
> > > > > opinions expressed in this email (including attachments)
> > > > are those of
> > > > > the author and do not necessarily reflect our opinions. We
> > > > will not
> > > > > accept responsibility for any commitments made by our
> employees
> > > > > outside the scope of our business. We do not warrant the
> > > > accuracy or
> > > > > completeness of such
> > > > information.
> > > > > —
> > > > > Questions? First check the Kernel Driver FAQ at http://www.
> > > > > osronline.com/article.cfm?id=256
> > > > >
> > > > > You are currently subscribed to ntdev as: unknown lmsubst tag
> > > > > argument:
> > > > ‘’
> > > > > To unsubscribe send a blank email to
> > > > xxxxx@lists.osr.com
> > > > > ForwardSourceID:NT00004CF6
> > > >
> > > >
> > > >
> > > > —
> > > > Questions? First check the Kernel Driver FAQ at
> > > > http://www.osronline.com/article.cfm?id=256
> > > >
> > > > You are currently subscribed to ntdev as:
> > > > xxxxx@t-mobile.co.uk To unsubscribe send a
> > blank email to
> > > > xxxxx@lists.osr.com
> > > >
> > >
> >
> > > NOTICE AND DISCLAIMER:
> > > This email (including attachments) is confidential. If you have
> > > received this email in error please notify the sender
> > immediately and
> > > delete this email from your system without copying or
> > disseminating it
> > > or placing any reliance upon its contents. We cannot
> > accept liability
> > > for any breaches of confidence arising through use of email. Any
> > > opinions expressed in this email (including attachments)
> > are those of
> > > the author and do not necessarily reflect our opinions. We
> > will not
> > > accept responsibility for any commitments made by our employees
> > > outside the scope of our business. We do not warrant the
> > accuracy or
> > > completeness of such
> > information.
> > > —
> > > Questions? First check the Kernel Driver FAQ at http://www.
> > > osronline.com/article.cfm?id=256
> > >
> > > You are currently subscribed to ntdev as: unknown lmsubst
> > tag argument:
> > ‘’
> > > To unsubscribe send a blank email to
> > > xxxxx@lists.osr.com ForwardSourceID:NT00004D02
> >
> >
> >
> > —
> > Questions? First check the Kernel Driver FAQ at
> > http://www.osronline.com/article.cfm?id=256
> >
> > You are currently subscribed to ntdev as:
> > xxxxx@hollistech.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@t-mobile.co.uk
> To unsubscribe send a blank email to %%email.unsub%%
>

NOTICE AND DISCLAIMER:
This email (including attachments) is confidential. If you have
received this email in error please notify the sender immediately
and delete this email from your system without copying or
disseminating it or placing any reliance upon its contents. We
cannot accept liability for any breaches of confidence arising
through use of email. Any opinions expressed in this email
(including attachments) are those of the author and do not
necessarily reflect our opinions. We will not accept responsibility
for any commitments made by our employees outside the scope of our
business. We do not warrant the accuracy or completeness of such
information.

Questions? First check the Kernel Driver FAQ at http://www.
osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: unknown lmsubst tag argument:
‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com
ForwardSourceID:NT00004D32

While the DDK suggests that dispatch routines are called at PASSIVE_LEVEL,
the facts are that the level they are called at depends on the specific
device stack. In general if your dispatch routine is invoked at
DISPATCH_LEVEL that indicates that a driver above your driver has initiated
an IO request in its completion handler. This is common practice. The DDK
should make this clear rather than sort of indicating that this is unusual.
One of the nice features of the asynchronous IO model is in fact the
efficiency of initiating the next IO request in the context that completes
the current IO request, but it does complicate the programming model.

As Mats notes, pageable code cannot be invoked at DISPATCH_LEVEL. Avoid
marking your read/write and ioctl dispatch routine pageable unless you are
absolutely positive that they will always be invoked at less than
DISPATCH_LEVEL. Given the pervasiveness of filter drivers, I really don’t
know how you can ever be absolutely positive. As I said earlier, it is my
opinion that marking routines pageable is in general a waste of development
effort, and just begging for bugs.

If you insist on pageable code segments, consider making them internal
routines rather than externally callable interfaces, and test your IRQL
before invoking them. Use work items to redispatch the calls to PASSIVE
LEVEL threads. You can now guarantee correctness, but what exactly has your
driver gained with this effort?

=====================
Mark Roddy

-----Original Message-----
From: Mats PETERSSON [mailto:xxxxx@3dlabs.com]
Sent: Thursday, October 07, 2004 8:59 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] Pageable Code Assert (Probably a basic question)

xxxxx@lists.osr.com wrote on 10/07/2004 12:39:01 PM:

Hi Mark,
Well this is what the skelton code Walt Oney’s driver wizard produced
when I started this project, I assumed it was a requirement. I can
change all the routines to non-paged but I don’t understand where the
problem is with the current setting.

The problem is that if you ever get the code paged out and call it from an
IRQL higher than 1, it’s going to BSOD. If that’s not enough to cause harm,
I don’t know what… :wink:

Basicly, putting the code in the PAGE section means that the driver is
allowed to page out the code, which is fine if it’s called at passive or APC
level, but if it’s called from above that level, it’s going to hit a
page-fault because the page isn’t present. Page faults are handled by a
separate process, and IRQL >= 2 doesn’t allow the current process (or
thread) to be switched, so the page-in process will not be able to run
before we lower the IRQL, and you get a “IRQL_NOT_LESS_THAN” BSOD.

Mats - I have checked for any “leaky” locks and I don’t have any.

Ok.


Mats

Thanks
Alasdair

> -----Original Message-----
> From: Mark Roddy [mailto:xxxxx@hollistech.com]
> Sent: 07 October 2004 12:25
> To: Windows System Software Devs Interest List
> Subject: RE: [ntdev] Pageable Code Assert (Probably a basic
> question)
>
>
> Unless you have some overwhelming reason to mark you code pageable I
> would suggest never doing this. As far as I am concerned this
> practice is a relic of a bygone time when memory was very expensive
> and computers did not have much of it at all.
>
> Pageable data is a different story.
>
> > -----Original Message-----
> > From: xxxxx@lists.osr.com
> > [mailto:xxxxx@lists.osr.com] On Behalf Of Mats
> PETERSSON
> > Sent: Thursday, October 07, 2004 7:07 AM
> > To: Windows System Software Devs Interest List
> > Subject: RE: [ntdev] Pageable Code Assert (Probably a basic
> question)
> >
> >
> >
> >
> >
> >
> >
> >
> > xxxxx@lists.osr.com wrote on 10/07/2004 11:47:25 AM:
> >
> > > Hi Mats,
> > > Thanks for this very informative reply, I understand what
> > the purpose
> > > of the macro is now but I still don’t know why the ASSERT
> > fires after
> > > a few seconds. What is wrong with the way the routine is
> > being called
> > > when this happens?
> > > The macro (in wdm.h) is:
> > > if(KeGetCurrentIrql() > APC_LEVEL)
> > > {
> > > KdPrint(( “EX : Pageable code called at
> IRQL %d\n”.
> > > KeGetCurrentIrql() ));
> > > ASSERT(FALSE);
> > > }
> > > APC_LEVEL is 1, DISPATCH_LEVEL is 2 so this will fire whenever
> > > the routine is called *AT* Dispatch level. Is it being called
> > at the wrong
> > > level for some reason?
> >
> > Simple answer: Yes, it’s called at DISPATCH or higher level, which
> > is not allowed for pageable code.
> >
> > As to “What is wrogn with the wway the routine is being called”,
> > you’ve got to have a look at the stack for the call when it
> > asserts. In most cases it would become obvious from your own code
> > why it’s happening, but it could of course be more complicated
> > (for instance, it’s not called by your own driver, because it’s
> > called through some function pointer or similar mechanism).
> >
> > You need to EITHER make sure that the code isn’t called from
> > DISPATCH level, or that the code is not pageable (i.e. it’s not in
> > code_seg(PAGE)).
> > The right choice of those depends on what your code is actually
> > doing, and I’m not sure from the context you’re giving what IRQL
> > it’s expected to be called at. One possibility is that you have a
> > leacky lock situation…
> > Simplified code:
> >
> > somefunction(…)
> > {
> > KeAcquireSpinLock(…);
> >
> > if (something)
> > return;
> >
> > KeReleaseSpinLock(…);
> > }
> >
> > someotherfunction(…)
> > {
> > …
> >
> > somefunction(…);
> >
> > DispatchControl(…);
> > }
> >
> > The above code should release the spinlock when leaving the
> > function. This type of function is usually best designed so that
> > you set a variable with the return value, rather than just
> > returning. I’ve seen several cases (in my own and others
> > code) where there is a return in the middle that causes some lock
> > or other operation to be left “dangling” when some special case
> > happens.
> >
> > Or you’re DispatchControl is called by an interrupt? That would
> > cause IRQL to be > 1 for sure…
> >
> > > I am running DV.
> >
> > Ok, so maybe it’s not paging out code in the driver. I thought it
> > did. Or maybe you haven’t got all the settings turned on… You
> > should enable all options EXCEPT the Low resource simulation
> > (unless you think your driver is almost ready to ship, in which
> > case a LRS is a good final test for reliability).
> >
> > I hope this helps. If not, I’m not sure I can offer much more
> > help, as I’ve only run into this problem once, and that was caused
> > by an interrupt calling a paged function (and it did a BSOD, but
> > the stack-trace was quite easy to follow and fix was a one-line
> > removal, so not too difficult to find or fix).
> >
> > –
> > Mats
> >
> > > Thanks
> > > Alasdair (still confused)
> > >
> > > > Hi Alasdair.
> > > >
> > > > Paged code is fine, but in this case, the macro is checking
> > > > that you’re not calling the code in IRQL >= DISPATCH. The
> > reason for this
> > > > is that should the code happen to be paged out, there’s
> > no way the
> > > > OS can page it back in, as it’s running at an IRQL that
> > prevents it
> > > > from running the page-in code, and thus, you’d
> > blue-screen when this
> > > > happens.
> > > > Obviously, your test-machine probably has enough memory and is
> > > > excercising your driver enough to not cause it to be
> > paged out, but
> > > > that doesn’t mean that it’s not a problem in a different
> > situation
> > > > in a different system.
> > > >
> > > > I’m pretty sure that you’d get a bug-check if you used Driver
> > > > Verifier on your driver, as it has a mechanism that
> > “pages out” all
> > > > pages that are pageable, just to avoid you getting to debug
> > > > the problem when you’ve got a customer who has a tighter
> > > > memory requirement than your test-system… :wink: [I put “pages \> \> \> \> out” in quotes, because what DV really does is just to mark \> \> \> \> the \> page “not \> \> \> \> present”, whilst the page is actually still in memory, \> \> it’s just not \> \> \> \> available to code until the swapper process is available, and \> \> \> \> anything that accesses this page from high IRQL will \> \> automatically \> \> \> \> cause a BSOD!].
> > > >
> > > > –
> > > > Mats
> > > > xxxxx@lists.osr.com wrote on 10/07/2004
> 11:22:50 AM:
> > > >
> > > > > Hi (again),
> > > > > Thanks for all the help so far from this novice.
> > > > >
> > > > > I have encountered another problem which I am sure is
> > very basic.
> > > > > I have based my filter driver on the skeleton code produced
> > > > > by Walt Oney’s driver wizard. The DispatchControl routine
> > begins like this:
> > > > >
> > > > > #pragma PAGEDCODE
> > > > > NTSTATUS DispatchControl(…
> > > > > {
> > > > > PAGED_CODE();
> > > > > …
> > > > >
> > > > > When the driver is running and passing Irps down to the
> > > > lower driver,
> > > > > after a few seconds the ASSERT in this PAGED_CODE() macro
> > > > fires with
> > > > > the message:
> > > > > “EX: Pageable code called at IRQL 2”.
> > > > > I assume that this has happened because after a few
> > seconds this
> > > > > routine has been “paged” out of memory, but surely
> that is what
> > > > > the PAGEDCODE pragma is saying may happen. The
> PAGEDCODE pragma
> > > > looks like
> > > > > this:
> > > > > code_seg(“PAGE”)
> > > > > When I press “g” to continue the driver resumes until the
> > > > next ASSERT.
> > > > > There is no bugcheck. What do I do here? Comment out
> > the macro? I
> > > > > guess it is there for a
> > > > reason.
> > > > > Thanks
> > > > > Alasdair (confused)
> > > > >
> > > >
> > > > > NOTICE AND DISCLAIMER:
> > > > > This email (including attachments) is confidential. If
> > you have
> > > > > received this email in error please notify the sender
> > > > immediately and
> > > > > delete this email from your system without copying or
> > > > disseminating it
> > > > > or placing any reliance upon its contents. We cannot
> > > > accept liability
> > > > > for any breaches of confidence arising through use of
> > email. Any
> > > > > opinions expressed in this email (including attachments)
> > > > are those of
> > > > > the author and do not necessarily reflect our opinions. We
> > > > will not
> > > > > accept responsibility for any commitments made by our
> employees
> > > > > outside the scope of our business. We do not warrant the
> > > > accuracy or
> > > > > completeness of such
> > > > information.
> > > > > —
> > > > > Questions? First check the Kernel Driver FAQ at http://www.
> > > > > osronline.com/article.cfm?id=256
> > > > >
> > > > > You are currently subscribed to ntdev as: unknown lmsubst
> > > > > tag
> > > > > argument:
> > > > ‘’
> > > > > To unsubscribe send a blank email to
> > > > xxxxx@lists.osr.com
> > > > > ForwardSourceID:NT00004CF6
> > > >
> > > >
> > > >
> > > > —
> > > > Questions? First check the Kernel Driver FAQ at
> > > > http://www.osronline.com/article.cfm?id=256
> > > >
> > > > You are currently subscribed to ntdev as:
> > > > xxxxx@t-mobile.co.uk To unsubscribe send a
> > blank email to
> > > > xxxxx@lists.osr.com
> > > >
> > >
> >
> > > NOTICE AND DISCLAIMER:
> > > This email (including attachments) is confidential. If you have
> > > received this email in error please notify the sender
> > immediately and
> > > delete this email from your system without copying or
> > disseminating it
> > > or placing any reliance upon its contents. We cannot
> > accept liability
> > > for any breaches of confidence arising through use of email.
> > > Any opinions expressed in this email (including attachments)
> > are those of
> > > the author and do not necessarily reflect our opinions. We
> > will not
> > > accept responsibility for any commitments made by our employees
> > > outside the scope of our business. We do not warrant the
> > accuracy or
> > > completeness of such
> > information.
> > > —
> > > Questions? First check the Kernel Driver FAQ at http://www.
> > > osronline.com/article.cfm?id=256
> > >
> > > You are currently subscribed to ntdev as: unknown lmsubst
> > tag argument:
> > ‘’
> > > To unsubscribe send a blank email to
> > > xxxxx@lists.osr.com ForwardSourceID:NT00004D02
> >
> >
> >
> > —
> > Questions? First check the Kernel Driver FAQ at
> > http://www.osronline.com/article.cfm?id=256
> >
> > You are currently subscribed to ntdev as:
> > xxxxx@hollistech.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@t-mobile.co.uk
> To unsubscribe send a blank email to %%email.unsub%%
>

NOTICE AND DISCLAIMER:
This email (including attachments) is confidential. If you have
received this email in error please notify the sender immediately and
delete this email from your system without copying or disseminating it
or placing any reliance upon its contents. We cannot accept liability
for any breaches of confidence arising through use of email. Any
opinions expressed in this email (including attachments) are those of
the author and do not necessarily reflect our opinions. We will not
accept responsibility for any commitments made by our employees
outside the scope of our business. We do not warrant the accuracy or
completeness of such
information.

Questions? First check the Kernel Driver FAQ at http://www.
osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: unknown lmsubst tag argument:
‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com
ForwardSourceID:NT00004D32


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@stratus.com To
unsubscribe send a blank email to xxxxx@lists.osr.com

Hi Mats,

This is a good explanation which I now understand, I have marked the
routines as non-pageable and removed the check and that part now works fine.
(I say “that part” because I have another problem which you will no doubt
hear about soon!) So all in all it wasn’t a “bug” at all, just a
misunderstanding (a place I used to work would have called it “an
undocumented feature”).

Many thanks Mats - I wouldn’t have been able o do this without the help
provided on this list.

Alasdair

P.S. I think I DID have a leaky lock. It happened when there was an error
and I think this may have left the machine in some state which caused a
crash to happen later on. The mysterious crash I was suffering from
yesterday has not made an appearance today.

The problem is that if you ever get the code paged out and
call it from an IRQL higher than 1, it’s going to BSOD. If
that’s not enough to cause harm, I don’t know what… :wink:

Basicly, putting the code in the PAGE section means that the
driver is allowed to page out the code, which is fine if it’s
called at passive or APC level, but if it’s called from above
that level, it’s going to hit a page-fault because the page
isn’t present. Page faults are handled by a separate process,
and IRQL >= 2 doesn’t allow the current process (or
thread) to be switched, so the page-in process will not be
able to run before we lower the IRQL, and you get a
“IRQL_NOT_LESS_THAN” BSOD.

> Mats - I have checked for any “leaky” locks and I don’t have any.

Ok.


Mats
> Thanks
> Alasdair
>
> > -----Original Message-----
> > From: Mark Roddy [mailto:xxxxx@hollistech.com]
> > Sent: 07 October 2004 12:25
> > To: Windows System Software Devs Interest List
> > Subject: RE: [ntdev] Pageable Code Assert (Probably a basic
> > question)
> >
> >
> > Unless you have some overwhelming reason to mark you code
pageable I
> > would suggest never doing this. As far as I am concerned this
> > practice is a relic of a bygone time when memory was very
expensive
> > and computers did not have much of it at all.
> >
> > Pageable data is a different story.
> >
> > > -----Original Message-----
> > > From: xxxxx@lists.osr.com
> > > [mailto:xxxxx@lists.osr.com] On Behalf Of Mats
> > PETERSSON
> > > Sent: Thursday, October 07, 2004 7:07 AM
> > > To: Windows System Software Devs Interest List
> > > Subject: RE: [ntdev] Pageable Code Assert (Probably a basic
> > question)
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > > xxxxx@lists.osr.com wrote on 10/07/2004
11:47:25 AM:
> > >
> > > > Hi Mats,
> > > > Thanks for this very informative reply, I understand what
> > > the purpose
> > > > of the macro is now but I still don’t know why the ASSERT
> > > fires after
> > > > a few seconds. What is wrong with the way the routine is
> > > being called
> > > > when this happens?
> > > > The macro (in wdm.h) is:
> > > > if(KeGetCurrentIrql() > APC_LEVEL)
> > > > {
> > > > KdPrint(( “EX : Pageable code called at
> > IRQL %d\n”.
> > > > KeGetCurrentIrql() ));
> > > > ASSERT(FALSE);
> > > > }
> > > > APC_LEVEL is 1, DISPATCH_LEVEL is 2 so this will fire
whenever
> > > > the routine is called *AT* Dispatch level. Is it being called
> > > at the wrong
> > > > level for some reason?
> > >
> > > Simple answer: Yes, it’s called at DISPATCH or higher
level, which
> > > is not allowed for pageable code.
> > >
> > > As to “What is wrogn with the wway the routine is being
called”,
> > > you’ve got to have a look at the stack for the call when it
> > > asserts. In most cases it would become obvious from
your own code
> > > why it’s happening, but it could of course be more complicated
> > > (for instance, it’s not called by your own driver, because it’s
> > > called through some function pointer or similar mechanism).
> > >
> > > You need to EITHER make sure that the code isn’t called from
> > > DISPATCH level, or that the code is not pageable (i.e.
it’s not in
> > > code_seg(PAGE)). The right choice of those depends on what your
> > > code is actually doing, and I’m not sure from the context you’re
> > > giving what IRQL it’s expected to be called at. One
> > > possibility is that you have a leacky lock situation…
> > > Simplified code:
> > >
> > > somefunction(…)
> > > {
> > > KeAcquireSpinLock(…);
> > >
> > > if (something)
> > > return;
> > >
> > > KeReleaseSpinLock(…);
> > > }
> > >
> > > someotherfunction(…)
> > > {
> > > …
> > >
> > > somefunction(…);
> > >
> > > DispatchControl(…);
> > > }
> > >
> > > The above code should release the spinlock when leaving the
> > > function. This type of function is usually best
designed so that
> > > you set a variable with the return value, rather than just
> > > returning. I’ve seen several cases (in my own and others
> > > code) where there is a return in the middle that causes
some lock
> > > or other operation to be left “dangling” when some special case
> > > happens.
> > >
> > > Or you’re DispatchControl is called by an interrupt? That would
> > > cause IRQL to be > 1 for sure…
> > >
> > > > I am running DV.
> > >
> > > Ok, so maybe it’s not paging out code in the driver. I
thought it
> > > did. Or maybe you haven’t got all the settings turned on… You
> > > should enable all options EXCEPT the Low resource simulation
> > > (unless you think your driver is almost ready to ship, in which
> > > case a LRS is a good final test for reliability).
> > >
> > > I hope this helps. If not, I’m not sure I can offer much more
> > > help, as I’ve only run into this problem once, and that
was caused
> > > by an interrupt calling a paged function (and it did a
BSOD, but
> > > the stack-trace was quite easy to follow and fix was a one-line
> > > removal, so not too difficult to find or fix).
> > >
> > > –
> > > Mats
> > >
> > > > Thanks
> > > > Alasdair (still confused)
> > > >
> > > > > Hi Alasdair.
> > > > >
> > > > > Paged code is fine, but in this case, the macro is checking
> > > > > that you’re not calling the code in IRQL >= DISPATCH. The
> > > reason for this
> > > > > is that should the code happen to be paged out, there’s
> > > no way the
> > > > > OS can page it back in, as it’s running at an IRQL that
> > > prevents it
> > > > > from running the page-in code, and thus, you’d
> > > blue-screen when this
> > > > > happens.
> > > > > Obviously, your test-machine probably has enough
memory and is
> > > > > excercising your driver enough to not cause it to be
> > > paged out, but
> > > > > that doesn’t mean that it’s not a problem in a different
> > > situation
> > > > > in a different system.
> > > > >
> > > > > I’m pretty sure that you’d get a bug-check if you
used Driver
> > > > > Verifier on your driver, as it has a mechanism that
> > > “pages out” all
> > > > > pages that are pageable, just to avoid you getting to debug
> > > > > the problem when you’ve got a customer who has a tighter
> > > > > memory requirement than your test-system… :wink: [I put “pages \> \> \> \> \> out” in quotes, because what DV really does is just to mark \> \> \> \> \> the \> \> page “not \> \> \> \> \> present”, whilst the page is actually still in memory, \> \> \> it’s just not \> \> \> \> \> available to code until the swapper process is available, and \> \> \> \> \> anything that accesses this page from high IRQL will \> \> \> automatically \> \> \> \> \> cause a BSOD!].
> > > > >
> > > > > –
> > > > > Mats
> > > > > xxxxx@lists.osr.com wrote on 10/07/2004
> > 11:22:50 AM:
> > > > >
> > > > > > Hi (again),
> > > > > > Thanks for all the help so far from this novice.
> > > > > >
> > > > > > I have encountered another problem which I am sure is
> > > very basic.
> > > > > > I have based my filter driver on the skeleton
code produced
> > > > > > by Walt Oney’s driver wizard. The DispatchControl routine
> > > begins like this:
> > > > > >
> > > > > > #pragma PAGEDCODE
> > > > > > NTSTATUS DispatchControl(…
> > > > > > {
> > > > > > PAGED_CODE();
> > > > > > …
> > > > > >
> > > > > > When the driver is running and passing Irps down to the
> > > > > lower driver,
> > > > > > after a few seconds the ASSERT in this PAGED_CODE() macro
> > > > > fires with
> > > > > > the message:
> > > > > > “EX: Pageable code called at IRQL 2”.
> > > > > > I assume that this has happened because after a few
> > > seconds this
> > > > > > routine has been “paged” out of memory, but surely
> > that is what
> > > > > > the PAGEDCODE pragma is saying may happen. The
> > PAGEDCODE pragma
> > > > > looks like
> > > > > > this:
> > > > > > code_seg(“PAGE”)
> > > > > > When I press “g” to continue the driver resumes until the
> > > > > next ASSERT.
> > > > > > There is no bugcheck. What do I do here? Comment out
> > > the macro? I
> > > > > > guess it is there for a
> > > > > reason.
> > > > > > Thanks
> > > > > > Alasdair (confused)
> > > > > >
> > > > >
> > > > > > NOTICE AND DISCLAIMER:
> > > > > > This email (including attachments) is confidential. If
> > > you have
> > > > > > received this email in error please notify the sender
> > > > > immediately and
> > > > > > delete this email from your system without copying or
> > > > > disseminating it
> > > > > > or placing any reliance upon its contents. We cannot
> > > > > accept liability
> > > > > > for any breaches of confidence arising through use of
> > > email. Any
> > > > > > opinions expressed in this email (including attachments)
> > > > > are those of
> > > > > > the author and do not necessarily reflect our
opinions. We
> > > > > will not
> > > > > > accept responsibility for any commitments made by our
> > employees
> > > > > > outside the scope of our business. We do not warrant the
> > > > > accuracy or
> > > > > > completeness of such
> > > > > information.
> > > > > > —
> > > > > > Questions? First check the Kernel Driver FAQ at
http://www.
> > > > > > osronline.com/article.cfm?id=256
> > > > > >
> > > > > > You are currently subscribed to ntdev as: unknown lmsubst
> > > > > > tag
> > > > > > argument:
> > > > > ‘’
> > > > > > To unsubscribe send a blank email to
> > > > > xxxxx@lists.osr.com
> > > > > > ForwardSourceID:NT00004CF6
> > > > >
> > > > >
> > > > >
> > > > > —
> > > > > Questions? First check the Kernel Driver FAQ at
> > > > > http://www.osronline.com/article.cfm?id=256
> > > > >
> > > > > You are currently subscribed to ntdev as:
> > > > > xxxxx@t-mobile.co.uk To unsubscribe send a
> > > blank email to
> > > > > xxxxx@lists.osr.com
> > > > >
> > > >
> > >
> > > > NOTICE AND DISCLAIMER:
> > > > This email (including attachments) is confidential.
If you have
> > > > received this email in error please notify the sender
> > > immediately and
> > > > delete this email from your system without copying or
> > > disseminating it
> > > > or placing any reliance upon its contents. We cannot
> > > accept liability
> > > > for any breaches of confidence arising through use of email.
> > > > Any opinions expressed in this email (including attachments)
> > > are those of
> > > > the author and do not necessarily reflect our opinions. We
> > > will not
> > > > accept responsibility for any commitments made by our
employees
> > > > outside the scope of our business. We do not warrant the
> > > accuracy or
> > > > completeness of such
> > > information.
> > > > —
> > > > Questions? First check the Kernel Driver FAQ at http://www.
> > > > osronline.com/article.cfm?id=256
> > > >
> > > > You are currently subscribed to ntdev as: unknown lmsubst
> > > tag argument:
> > > ‘’
> > > > To unsubscribe send a blank email to
> > > > xxxxx@lists.osr.com ForwardSourceID:NT00004D02
> > >
> > >
> > >
> > > —
> > > Questions? First check the Kernel Driver FAQ at
> > > http://www.osronline.com/article.cfm?id=256
> > >
> > > You are currently subscribed to ntdev as:
xxxxx@hollistech.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@t-mobile.co.uk To unsubscribe send a
blank email to
> > %%email.unsub%%
> >
>

> NOTICE AND DISCLAIMER:
> This email (including attachments) is confidential. If you have
> received this email in error please notify the sender
immediately and
> delete this email from your system without copying or
disseminating it
> or placing any reliance upon its contents. We cannot
accept liability
> for any breaches of confidence arising through use of email. Any
> opinions expressed in this email (including attachments)
are those of
> the author and do not necessarily reflect our opinions. We
will not
> accept responsibility for any commitments made by our employees
> outside the scope of our business. We do not warrant the
accuracy or
> completeness of such
information.
> —
> Questions? First check the Kernel Driver FAQ at http://www.
> osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: unknown lmsubst tag
> argument:
‘’
> To unsubscribe send a blank email to
xxxxx@lists.osr.com
> ForwardSourceID:NT00004D32


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as:
xxxxx@t-mobile.co.uk To unsubscribe send a blank
email to xxxxx@lists.osr.com

NOTICE AND DISCLAIMER:
This email (including attachments) is confidential. If you have received
this email in error please notify the sender immediately and delete this
email from your system without copying or disseminating it or placing any
reliance upon its contents. We cannot accept liability for any breaches of
confidence arising through use of email. Any opinions expressed in this
email (including attachments) are those of the author and do not necessarily
reflect our opinions. We will not accept responsibility for any commitments
made by our employees outside the scope of our business. We do not warrant
the accuracy or completeness of such information.

Hi Mark,

Another brilliant explanation (is this list archived anywhere by the way? I
am sure these topics will be of use to future developers).

As I replied to Mats I have changed these routines now (Read, Write and
Dispatch) and that part is working fine.

Thanks

Alasdair (feeling more hopeful now)

-----Original Message-----
From: Roddy, Mark [mailto:xxxxx@stratus.com]
Sent: 07 October 2004 14:28
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] Pageable Code Assert (Probably a basic question)

While the DDK suggests that dispatch routines are called at
PASSIVE_LEVEL, the facts are that the level they are called
at depends on the specific device stack. In general if your
dispatch routine is invoked at DISPATCH_LEVEL that indicates
that a driver above your driver has initiated an IO request
in its completion handler. This is common practice. The DDK
should make this clear rather than sort of indicating that
this is unusual. One of the nice features of the asynchronous
IO model is in fact the efficiency of initiating the next IO
request in the context that completes the current IO request,
but it does complicate the programming model.

As Mats notes, pageable code cannot be invoked at
DISPATCH_LEVEL. Avoid marking your read/write and ioctl
dispatch routine pageable unless you are absolutely positive
that they will always be invoked at less than DISPATCH_LEVEL.
Given the pervasiveness of filter drivers, I really don’t
know how you can ever be absolutely positive. As I said
earlier, it is my opinion that marking routines pageable is
in general a waste of development effort, and just begging for bugs.

If you insist on pageable code segments, consider making them
internal routines rather than externally callable interfaces,
and test your IRQL before invoking them. Use work items to
redispatch the calls to PASSIVE LEVEL threads. You can now
guarantee correctness, but what exactly has your driver
gained with this effort?

=====================
Mark Roddy

-----Original Message-----
From: Mats PETERSSON [mailto:xxxxx@3dlabs.com]
Sent: Thursday, October 07, 2004 8:59 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] Pageable Code Assert (Probably a basic question)

NOTICE AND DISCLAIMER:
This email (including attachments) is confidential. If you have received
this email in error please notify the sender immediately and delete this
email from your system without copying or disseminating it or placing any
reliance upon its contents. We cannot accept liability for any breaches of
confidence arising through use of email. Any opinions expressed in this
email (including attachments) are those of the author and do not necessarily
reflect our opinions. We will not accept responsibility for any commitments
made by our employees outside the scope of our business. We do not warrant
the accuracy or completeness of such information.

Pageable Code Assert (Probably a basic question)>What do I do here? Comment out the macro? I guess it is there for a reason.

If you look at the macro definition, it just checks the IRQL that your code is called at and if it is anything > APC_LEVEL, it will assert unconditionally.

I guess the purpose of using this MACRO is that this way you are assuming that your routine will never be called at anything > APC_LEVEL. If based on this assumption, you are calling some routines or doing operations that can not be done at > APC_LEVEL, using this MACRO to catch violation of your assumption during debug build tests makes sense.

However, if in any case you don’t do any operation that conflict with IRQL restrictions (including marking the routine pageable), you don’t need the MACRO and can safely get rid of it.

HTH,
Bandeep

“Alasdair Tompson (external)” wrote in message news:xxxxx@ntdev…
Hi (again),

Thanks for all the help so far from this novice.

I have encountered another problem which I am sure is very basic. I have based my filter driver on the skeleton code produced by Walt Oney’s driver wizard. The DispatchControl routine begins like this:

#pragma PAGEDCODE
NTSTATUS DispatchControl(…
{
PAGED_CODE();


When the driver is running and passing Irps down to the lower driver, after a few seconds the ASSERT in this PAGED_CODE() macro fires with the message:

“EX: Pageable code called at IRQL 2”.

I assume that this has happened because after a few seconds this routine has been “paged” out of memory, but surely that is what the PAGEDCODE pragma is saying may happen.

The PAGEDCODE pragma looks like this:
code_seg(“PAGE”)

When I press “g” to continue the driver resumes until the next ASSERT. There is no bugcheck.

What do I do here? Comment out the macro? I guess it is there for a reason.

Thanks

Alasdair (confused)

NOTICE AND DISCLAIMER:
This email (including attachments) is confidential. If you have received this email in error please notify the sender immediately and delete this email from your system without copying or disseminating it or placing any reliance upon its contents. We cannot accept liability for any breaches of confidence arising through use of email. Any opinions expressed in this email (including attachments) are those of the author and do not necessarily reflect our opinions. We will not accept responsibility for any commitments made by our employees outside the scope of our business. We do not warrant the accuracy or completeness of such information.

Thanks Bandeep. I have done that now and the problem is fixed.
Alasdair

-----Original Message-----
From: Bandeep Singh [mailto:xxxxx@wipro.com]
Sent: 07 October 2004 16:01
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] Pageable Code Assert (Probably a basic question)

What do I do here? Comment out the macro? I guess it is there for a reason.

If you look at the macro definition, it just checks the IRQL that your code
is called at and if it is anything > APC_LEVEL, it will assert
unconditionally.

I guess the purpose of using this MACRO is that this way you are assuming
that your routine will never be called at anything > APC_LEVEL. If based on
this assumption, you are calling some routines or doing operations that can
not be done at > APC_LEVEL, using this MACRO to catch violation of your
assumption during debug build tests makes sense.

However, if in any case you don’t do any operation that conflict with IRQL
restrictions (including marking the routine pageable), you don’t need the
MACRO and can safely get rid of it.

HTH,
Bandeep

“Alasdair Tompson (external)” mailto:xxxxx > wrote in message news:xxxxx@ntdev
news:xxxxx

Hi (again),

Thanks for all the help so far from this novice.

I have encountered another problem which I am sure is very basic. I have
based my filter driver on the skeleton code produced by Walt Oney’s driver
wizard. The DispatchControl routine begins like this:

#pragma PAGEDCODE
NTSTATUS DispatchControl(…
{
PAGED_CODE();


When the driver is running and passing Irps down to the lower driver, after
a few seconds the ASSERT in this PAGED_CODE() macro fires with the message:

“EX: Pageable code called at IRQL 2”.

I assume that this has happened because after a few seconds this routine has
been “paged” out of memory, but surely that is what the PAGEDCODE pragma is
saying may happen.

The PAGEDCODE pragma looks like this:
code_seg(“PAGE”)

When I press “g” to continue the driver resumes until the next ASSERT. There
is no bugcheck.

What do I do here? Comment out the macro? I guess it is there for a reason.

Thanks

Alasdair (confused)

NOTICE AND DISCLAIMER:
This email (including attachments) is confidential. If you have received
this email in error please notify the sender immediately and delete this
email from your system without copying or disseminating it or placing any
reliance upon its contents. We cannot accept liability for any breaches of
confidence arising through use of email. Any opinions expressed in this
email (including attachments) are those of the author and do not necessarily
reflect our opinions. We will not accept responsibility for any commitments
made by our employees outside the scope of our business. We do not warrant
the accuracy or completeness of such information.


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: unknown lmsubst tag argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com

NOTICE AND DISCLAIMER:
This email (including attachments) is confidential. If you have received
this email in error please notify the sender immediately and delete this
email from your system without copying or disseminating it or placing any
reliance upon its contents. We cannot accept liability for any breaches of
confidence arising through use of email. Any opinions expressed in this
email (including attachments) are those of the author and do not necessarily
reflect our opinions. We will not accept responsibility for any commitments
made by our employees outside the scope of our business. We do not warrant
the accuracy or completeness of such information.</news:xxxxx></mailto:xxxxx>

I have to disagree with the assertion:

“I am concerned this practice is a relic of a bygone time when memory was
very expensive and computers did not have much of it at all”

This is the sort of thinking that has gotten us to where we are today; and
industry saturated with overly complex bloat-ware.

We have a driver that is somewhat complex and has a code size of about 50K.
The driver is used very little during day-to-day operations, but is required
occasionally to perform some task that may be in operation from several
minutes to several hours. In this driver, we mark all of the subroutines
used by the top level functions as pagable. When the IOCTLS are sent to the
driver asking the filters to engage, we lock these functions in memory. When
we are done, we unlock them so that they can be paged.

I am not sure what the performance penalty is on the rare IOCTLs that lock
and unlock the paged code, but it only took us a day or two to go through
the driver and set it all up to be pagable as I have described.

Please, let’s not get lazy about memory and resource constraints. We should
all strive to write the best possible code we can in the most resource
conservative way possible. It is a professional responsibility.

Jamey

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Mark Roddy
Sent: Thursday, October 07, 2004 4:25 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] Pageable Code Assert (Probably a basic question)

Unless you have some overwhelming reason to mark you code pageable I would
suggest never doing this. As far as I am concerned this practice is a relic
of a bygone time when memory was very expensive and computers did not have
much of it at all.

Pageable data is a different story.

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Mats PETERSSON
Sent: Thursday, October 07, 2004 7:07 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] Pageable Code Assert (Probably a basic question)

xxxxx@lists.osr.com wrote on 10/07/2004 11:47:25 AM:

> Hi Mats,
> Thanks for this very informative reply, I understand what
the purpose
> of the macro is now but I still don’t know why the ASSERT
fires after
> a few seconds. What is wrong with the way the routine is
being called
> when this happens?
> The macro (in wdm.h) is:
> if(KeGetCurrentIrql() > APC_LEVEL)
> {
> KdPrint(( “EX : Pageable code called at IRQL %d\n”.
> KeGetCurrentIrql() ));
> ASSERT(FALSE);
> }
> APC_LEVEL is 1, DISPATCH_LEVEL is 2 so this will fire whenever the
> routine is called *AT* Dispatch level. Is it being called
at the wrong
> level for some reason?

Simple answer: Yes, it’s called at DISPATCH or higher level,
which is not allowed for pageable code.

As to “What is wrogn with the wway the routine is being
called”, you’ve got to have a look at the stack for the call
when it asserts. In most cases it would become obvious from
your own code why it’s happening, but it could of course be
more complicated (for instance, it’s not called by your own
driver, because it’s called through some function pointer or
similar mechanism).

You need to EITHER make sure that the code isn’t called from
DISPATCH level, or that the code is not pageable (i.e. it’s
not in code_seg(PAGE)).
The right choice of those depends on what your code is
actually doing, and I’m not sure from the context you’re
giving what IRQL it’s expected to be called at. One
possibility is that you have a leacky lock situation…
Simplified code:

somefunction(…)
{
KeAcquireSpinLock(…);

if (something)
return;

KeReleaseSpinLock(…);
}

someotherfunction(…)
{

somefunction(…);

DispatchControl(…);
}

The above code should release the spinlock when leaving the
function. This type of function is usually best designed so
that you set a variable with the return value, rather than
just returning. I’ve seen several cases (in my own and others
code) where there is a return in the middle that causes some
lock or other operation to be left “dangling” when some
special case happens.

Or you’re DispatchControl is called by an interrupt? That
would cause IRQL to be > 1 for sure…

> I am running DV.

Ok, so maybe it’s not paging out code in the driver. I
thought it did. Or maybe you haven’t got all the settings
turned on… You should enable all options EXCEPT the Low
resource simulation (unless you think your driver is almost
ready to ship, in which case a LRS is a good final test for
reliability).

I hope this helps. If not, I’m not sure I can offer much more
help, as I’ve only run into this problem once, and that was
caused by an interrupt calling a paged function (and it did a
BSOD, but the stack-trace was quite easy to follow and fix
was a one-line removal, so not too difficult to find or fix).


Mats

> Thanks
> Alasdair (still confused)
>
> > Hi Alasdair.
> >
> > Paged code is fine, but in this case, the macro is checking that
> > you’re not calling the code in IRQL >= DISPATCH. The
reason for this
> > is that should the code happen to be paged out, there’s
no way the
> > OS can page it back in, as it’s running at an IRQL that
prevents it
> > from running the page-in code, and thus, you’d
blue-screen when this
> > happens.
> > Obviously, your test-machine probably has enough memory and is
> > excercising your driver enough to not cause it to be
paged out, but
> > that doesn’t mean that it’s not a problem in a different
situation
> > in a different system.
> >
> > I’m pretty sure that you’d get a bug-check if you used Driver
> > Verifier on your driver, as it has a mechanism that
“pages out” all
> > pages that are pageable, just to avoid you getting to debug the
> > problem when you’ve got a customer who has a tighter memory
> > requirement than your test-system… :wink: [I put “pages out” in \> \> quotes, because what DV really does is just to mark the page “not \> \> present”, whilst the page is actually still in memory, it’s just not \> \> available to code until the swapper process is available, and \> \> anything that accesses this page from high IRQL will automatically \> \> cause a BSOD!].
> >
> > –
> > Mats
> > xxxxx@lists.osr.com wrote on 10/07/2004 11:22:50 AM:
> >
> > > Hi (again),
> > > Thanks for all the help so far from this novice.
> > >
> > > I have encountered another problem which I am sure is
very basic.
> > > I have based my filter driver on the skeleton code produced by
> > > Walt Oney’s driver wizard. The DispatchControl routine
begins like this:
> > >
> > > #pragma PAGEDCODE
> > > NTSTATUS DispatchControl(…
> > > {
> > > PAGED_CODE();
> > > …
> > >
> > > When the driver is running and passing Irps down to the
> > lower driver,
> > > after a few seconds the ASSERT in this PAGED_CODE() macro
> > fires with
> > > the message:
> > > “EX: Pageable code called at IRQL 2”.
> > > I assume that this has happened because after a few
seconds this
> > > routine has been “paged” out of memory, but surely that is what
> > > the PAGEDCODE pragma is saying may happen. The PAGEDCODE pragma
> > looks like
> > > this:
> > > code_seg(“PAGE”)
> > > When I press “g” to continue the driver resumes until the
> > next ASSERT.
> > > There is no bugcheck. What do I do here? Comment out
the macro? I
> > > guess it is there for a
> > reason.
> > > Thanks
> > > Alasdair (confused)
> > >
> >
> > > NOTICE AND DISCLAIMER:
> > > This email (including attachments) is confidential. If
you have
> > > received this email in error please notify the sender
> > immediately and
> > > delete this email from your system without copying or
> > disseminating it
> > > or placing any reliance upon its contents. We cannot
> > accept liability
> > > for any breaches of confidence arising through use of
email. Any
> > > opinions expressed in this email (including attachments)
> > are those of
> > > the author and do not necessarily reflect our opinions. We
> > will not
> > > accept responsibility for any commitments made by our employees
> > > outside the scope of our business. We do not warrant the
> > accuracy or
> > > completeness of such
> > information.
> > > —
> > > Questions? First check the Kernel Driver FAQ at http://www.
> > > osronline.com/article.cfm?id=256
> > >
> > > You are currently subscribed to ntdev as: unknown lmsubst tag
> > > argument:
> > ‘’
> > > To unsubscribe send a blank email to
> > xxxxx@lists.osr.com
> > > ForwardSourceID:NT00004CF6
> >
> >
> >
> > —
> > Questions? First check the Kernel Driver FAQ at
> > http://www.osronline.com/article.cfm?id=256
> >
> > You are currently subscribed to ntdev as:
> > xxxxx@t-mobile.co.uk To unsubscribe send a
blank email to
> > xxxxx@lists.osr.com
> >
>

> NOTICE AND DISCLAIMER:
> This email (including attachments) is confidential. If you have
> received this email in error please notify the sender
immediately and
> delete this email from your system without copying or
disseminating it
> or placing any reliance upon its contents. We cannot
accept liability
> for any breaches of confidence arising through use of email. Any
> opinions expressed in this email (including attachments)
are those of
> the author and do not necessarily reflect our opinions. We
will not
> accept responsibility for any commitments made by our employees
> outside the scope of our business. We do not warrant the
accuracy or
> completeness of such
information.
> —
> Questions? First check the Kernel Driver FAQ at http://www.
> osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: unknown lmsubst
tag argument:
‘’
> To unsubscribe send a blank email to xxxxx@lists.osr.com
> ForwardSourceID:NT00004D02


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as:
xxxxx@hollistech.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@storagecraft.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

__________ NOD32 1.860 (20040903) Information __________

This message was checked by NOD32 antivirus system.
http://www.nod32.com

And I wonder why win32k.sys of xp is the way it is on xp, fly by over u/sec to pageable mode. If I am correct, on 2k lot of it was there as resident … Being lazy is okay, but first strive for it … It make lot of sense Jemmy !!

-pro

Jamey Kirby writes:
> I have to disagree with the assertion:
>
> “I am concerned this practice is a relic of a bygone time when memory was
> very expensive and computers did not have much of it at all”
>
> This is the sort of thinking that has gotten us to where we are today; and
> industry saturated with overly complex bloat-ware.

It is exactly things like pageable kernel code that lead to
complexities. When control flow hits paged-out code page, it has to be
brought back. This means:

  • current thread has to block. So one has to assure that at the entry
    to the pageable code section no (spin) locks are held, IRQ level allows
    dispatching, etc., but even worse:

  • to bring page P1 into memory some other page (P2) has to be thrown
    out. If P2 is dirty, is has to be written back to the storage first,
    this means calling some driver, which means deadlock possibility with
    driver trying to execute code in P1.

Very shortly this becomes quite involved, and depending in subtle ways
on internal logic of memory management subsystem.

> We have a driver that is somewhat complex and has a code size of about 50K.
> The driver is used very little during day-to-day operations, but is required
> occasionally to perform some task that may be in operation from several
> minutes to several hours. In this driver, we mark all of the subroutines
> used by the top level functions as pagable. When the IOCTLS are sent to the
> driver asking the filters to engage, we lock these functions in memory. When
> we are done, we unlock them so that they can be paged.
>
> I am not sure what the performance penalty is on the rare IOCTLs that lock
> and unlock the paged code, but it only took us a day or two to go through
> the driver and set it all up to be pagable as I have described.
>
> Please, let’s not get lazy about memory and resource constraints. We should
> all strive to write the best possible code we can in the most resource
> conservative way possible. It is a professional responsibility.

Correctness is the foremost professional responsibility of a software
developer.

> Jamey

Nikita.

It’s almost going to take the shape of a RANT or a discussion that would be bitten to death, so there is an imminent danger to answer to Nikita’s idea.

I’ve always thought about that if I had the whole world , no sharing, no paging, nothing . For now, I will go for computing my favorite alogoritn permutation…

Sorry folks !

-pro