static variables in kernel

Hello,

Assuming I have a static variable somewhere at the top of the C file, let’s say it’s in the driver main code where DriverEntry is.
Is this static memory pagable ?

The reason I ask is because I want to use a small piece of memory but it will be sent to the hardware so it can’t be paged out.

Thanks
Shay

xxxxx@emc.com wrote:

Hello,

Assuming I have a static variable somewhere at the top of the C file,
let’s say it’s in the driver main code where DriverEntry is.

Is this static memory pagable ?

The reason I ask is because I want to use a small piece of memory but
it will be sent to the hardware so it can’t be paged out.

Unless you use #pragma data_seg to override the data section name (and
almost no one does), then your static data will be non-pagable.

However, that’s a driver global, which is almost never a good idea. You
might consider whether it wouldn’t be better to put it in your device
context structure (which is non-paged), or allocate it from NonPagedPool
instead.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

Nonpaged, unless declared #pragma data_seg(“PAGE”)


Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com

wrote in message news:xxxxx@ntdev…
Hello,

Assuming I have a static variable somewhere at the top of the C file, let’s say it’s in the driver main code where DriverEntry is.
Is this static memory pagable ?

The reason I ask is because I want to use a small piece of memory but it will be sent to the hardware so it can’t be paged out.

Thanks
Shay

>

xxxxx@emc.com wrote:
>
> Hello,
>
> Assuming I have a static variable somewhere at the top of the C
file,
> let’s say it’s in the driver main code where DriverEntry is.
>
> Is this static memory pagable ?
>
> The reason I ask is because I want to use a small piece of memory
but
> it will be sent to the hardware so it can’t be paged out.
>

Unless you use #pragma data_seg to override the data section name (and
almost no one does), then your static data will be non-pagable.

However, that’s a driver global, which is almost never a good idea.
You
might consider whether it wouldn’t be better to put it in your device
context structure (which is non-paged), or allocate it from
NonPagedPool
instead.

If it’s a static (as opposed to global, even though they amount to the
same thing) declared in DriverEntry then I assume it can’t be put in the
driver context. It does seem a strange way to do things though.

James

James Harper wrote:

If it’s a static (as opposed to global, even though they amount to the
same thing) declared in DriverEntry then I assume it can’t be put in the
driver context.

Ah, yes – I didn’t read that closely enough. You’re right.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.