5

I am newbie in windows driver development. I just want to know , a global variable in a driver will use paged pool memory or non paged pool memory ?

Thanks and Regards

Navaneeth

Navaneeth
  • 607
  • 2
  • 9
  • 19

3 Answers3

8

Depends. The Non paged pool should be reserved for memory that must stay in RAM so if you are doing something critical that would affected by a memory page from disk operation then use non paged.

See here for more info.

Looking at this (though it discusses c++ as opposed to C) it would seem that by default the globals can be located in either by #pragma. Also on p22 of this we see how to do this. Finally this discuss here we see that the data segment should be non pagagable by default.

Preet Sangha
  • 64,563
  • 18
  • 145
  • 216
  • No.my question is somthing like if i declare a global variable in device driver,which memory will be used ,ie paged pool memory or non-paged pool memory?(Local variable will use non paged pool memory). – Navaneeth Apr 28 '09 at 10:07
  • 1
    it wont be depends. it will be either paged or non-paged pool. – Navaneeth Apr 28 '09 at 10:34
  • 3
    #pragma data_seg("PAGE") int foo; #pragma data_seg("NONPAGE") int bar; -- foo here is pageable, and bar is non-paged. The default is non-paged if you don't give it a pragma. – SecurityMatt Mar 11 '12 at 17:18
2

Global variables in a kernel mode driver are allocated from NonPagedPool.

You can also use the device extension (when you call IoCreateDevice), it is always allocated from NonPaged memory.

I hope this helps, Martin

Martin
  • 145
  • 1
  • 1
    This isn't true. Kernel drivers in Windows are PE files with multiple sections, and unlike normal user-mode programs, KM drivers normally have *two* data-sections - one that is paged and one that is non-paged (and occasionally a third which is discarded after the KM driver has initialized). In your code you can choose whether your variable (or indeed function) is paged or non-paged through the use of the alloc pragmas. – SecurityMatt Mar 11 '12 at 17:14
0

Another good answer that I find is: "Nonpaged pool is kernel memory which can't be paged out into the pagefile when Windows runs out of free physical memory. It is used by drivers to allocate memory which they need." from here

afshar
  • 523
  • 4
  • 16