Unable to set DPOOL_NX_OPTIN=1 macro in VS2015 for nonPagedPoolNx optin

Hi All,

I am trying to OPTIN NonPagedPoolNx pool type when bulding for Windows version >= 8.
So, as mentioned at https://msdn.microsoft.com/en-us/library/windows/hardware/hh920402(v=vs.85).aspx, I have added

C_DEFINES=$(C_DEFINES) -DPOOL_NX_OPTIN=1

in my driver .vcxproj file for Windows 10 Release configuration under C/C++ -> Preprocessor definitions and also called ExInitializeDriverRuntime(DrvRtPoolNxOptIn); in my driver entry.

But it seems, that my driver source code is not getting the DPOOL_NX_OPTIN macro because when I manually define this macro inside the source code, the Win10 code integrity test passes.

So please let me know if I am doing any mistake in assigning DPOOL_NX_OPTIN=1 macro in the property page.

Thanks in advance.

Execute a build on the command line and see what is being passed to cl.exe. Or put in something like this that will not compile to make sure it is being set

#if POOL_NX_OPTIN
Blah blah
#endif

If it is being properly set, move on to the next step in debugging why you are failing the test

Bent from my phone


From: xxxxx@lists.osr.com on behalf of xxxxx@gmx.com
Sent: Sunday, May 14, 2017 5:39:09 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] Unable to set DPOOL_NX_OPTIN=1 macro in VS2015 for nonPagedPoolNx optin

Hi All,

I am trying to OPTIN NonPagedPoolNx pool type when bulding for Windows version >= 8.
So, as mentioned at https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fmsdn.microsoft.com%2Fen-us%2Flibrary%2Fwindows%2Fhardware%2Fhh920402(v%3Dvs.85).aspx&data=02|01|Doron.Holan%40microsoft.com|65c649239d3440dad5b108d49ac64169|72f988bf86f141af91ab2d7cd011db47|1|0|636303623669124147&sdata=2OiyKxlyT71p5lVmwAXHY3jHSmF80s2h3p3CfMI34WI%3D&reserved=0, I have added

C_DEFINES=$(C_DEFINES) -DPOOL_NX_OPTIN=1

in my driver .vcxproj file for Windows 10 Release configuration under C/C++ -> Preprocessor definitions and also called ExInitializeDriverRuntime(DrvRtPoolNxOptIn); in my driver entry.

But it seems, that my driver source code is not getting the DPOOL_NX_OPTIN macro because when I manually define this macro inside the source code, the Win10 code integrity test passes.

So please let me know if I am doing any mistake in assigning DPOOL_NX_OPTIN=1 macro in the property page.

Thanks in advance.


NTDEV is sponsored by OSR

Visit the list online at: https:

MONTHLY seminars on crash dump analysis, WDF, Windows internals and software drivers!
Details at https:

To unsubscribe, visit the List Server section of OSR Online at https:</https:></https:></https:>

The test is failing only because of the use of NonPagedPool memory types instead of its no-execute type version NonPagedPoolNx.

When I set this macro in my source code as 

 

#define POOL_NX_OPTIN 1

 

it works. However, I want to set this MACRO in the VS2015 project property pages or *somewhere* to set this macro when I build for Windows 10 only.

 

Please let me know how can we introduce a new MACRO in an existing VS2015 solution so that it is recognized by the msbuild.exe during compilation.

 

 

Thanks, 

 

Sent:  Sunday, May 14, 2017 at 6:21 PM

From:  “Doron Holan”

To: “Windows System Software Devs Interest List”

Subject: Re: [ntdev] Unable to set DPOOL_NX_OPTIN=1 macro in VS2015 for nonPagedPoolNx optin

Execute a build on the command line and see what is being passed to cl.exe. Or put in something like this that will not compile to make sure it is being set

 

#if  POOL_NX_OPTIN

Blah blah

#endif

 

If it is being properly set, move on to the next step in debugging why you are failing the test

 

Bent from my phone


From: xxxxx@lists.osr.com on behalf of xxxxx@gmx.com

Sent: Sunday, May 14, 2017 5:39:09 AM

To: Windows System Software Devs Interest List

Subject: [ntdev] Unable to set DPOOL_NX_OPTIN=1 macro in VS2015 for nonPagedPoolNx optin

 

Hi All,





I am trying to OPTIN NonPagedPoolNx pool type when bulding for Windows version >= 8.

So, as mentioned at https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fmsdn.microsoft.com%2Fen-us%2Flibrary%2Fwindows%2Fhardware%2Fhh920402(v%3Dvs.85).aspx&data=02%7C01%7CDoron.Holan%40microsoft.com%7C65c649239d3440dad5b108d49ac64169%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636303623669124147&sdata=2OiyKxlyT71p5lVmwAXHY3jHSmF80s2h3p3CfMI34WI%3D&reserved=0, I have added



C_DEFINES=$(C_DEFINES) -DPOOL_NX_OPTIN=1



in my driver .vcxproj file for Windows 10 Release configuration under C/C++ -> Preprocessor definitions and also called ExInitializeDriverRuntime(DrvRtPoolNxOptIn); in my driver entry.





But it seems, that my driver source code is not getting the DPOOL_NX_OPTIN macro because when I manually define this macro inside the source code, the Win10 code integrity test passes.





So please let me know if I am doing any mistake in assigning DPOOL_NX_OPTIN=1 macro in the property page.





Thanks in advance.





NTDEV is sponsored by OSR



Visit the list online at: <https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.osronline.com%2Fshowlists.cfm%3Flist%3Dntdev&data=02%7C01%7CDoron.Holan%40microsoft.com%7C65c649239d3440dad5b108d49ac64169%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636303623669124147&sdata=pVWw%2FVVgvb%2F2V4Tl2mG8zDEh%2FxSabosA9xBe5PZhZgs%3D&reserved=0>



MONTHLY seminars on crash dump analysis, WDF, Windows internals and software drivers!

Details at <https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.osr.com%2Fseminars&data=02%7C01%7CDoron.Holan%40microsoft.com%7C65c649239d3440dad5b108d49ac64169%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636303623669124147&sdata=nVZhr8%2Fg7EMooUYekj6ILUANab2d5UpB9eYSj9sRg9I%3D&reserved=0>



To unsubscribe, visit the List Server section of OSR Online at <https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.osronline.com%2Fpage.cfm%3Fname%3DListServer&data=02%7C01%7CDoron.Holan%40microsoft.com%7C65c649239d3440dad5b108d49ac64169%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636303623669124147&sdata=zwkd%2F%2Fyq1ZaXd1VEPqw40UiJP6Kq8If1ZG1aZ4eP9XA%3D&reserved=0>


NTDEV is sponsored by OSR

Visit the list online at: <http://www.osronline.com/showlists.cfm?list=ntdev>

MONTHLY seminars on crash dump analysis, WDF, Windows internals and software drivers!

Details at <http://www.osr.com/seminars>

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

-D is just a compiler command line switch.

In C/C++ -> Preprocessor -> Preprocessor definitions, you should only add the following definition:

POOL_NX_OPTIN=1

Than, in C/C++ -> Command line, you should look for:

/D “POOL_NX_OPTIN=1”

J. S.

« Please let me know how can we introduce a new MACRO in an existing VS2015 solution so that it is recognized by the msbuild.exe during compilation. »

Modifications apply to the active configuration and platform unless you choose other ones in the project property window.

So if you run MSBUILD with the right configuration and platform, you changes should apply.

To add a macro, open the project property page, than in C/C++ > Preprocessor, select (click on) ‘Preprocessor definitions’. Click on the down arrow on the right and choose Edit or Modify. Just write your macro in the edit window and click the Ok button.

J. S.

It is working now. Seems like the problem was with the extra spaces between “DPOOL_NX_OPTIN” and “1”. However, there is a new problem. one of my drivers has multiple source files, and only one file has the DriverEntry defined. So even if I call “ExInitializeDriverRuntime(DrvRtPoolNxOptIn)” in this driver entry, it does not replace “NonPagedPool” with “NonPagedPoolNx” that are present in other source codes.

What should be the recommended way to address this scenario?

Where I have identical settings (of any kind) to apply to more than one VS project, I like to use Project Property Sheets (.props files). These establish properties that can be ‘inherited’ by any project they are associated with.

(VS Menus: View/Property Manager, right click on one or more projects in Property Manager tab, Add New (or Existing) Property Sheet, adjust its Properties, save and build.)

In this case, you would add POOL_NX_OPTIN=1 to the C/C++ Preprocessor property in the sheet.

It is working now. Seems like the problem was with the extra spaces
between “DPOOL_NX_OPTIN” and “1”. However, there is a new problem. one
of my drivers has multiple source files, and only one file has the
DriverEntry defined. So even if I call
“ExInitializeDriverRuntime(DrvRtPoolNxOptIn)” in this driver entry, it
does not replace “NonPagedPool” with “NonPagedPoolNx” that are present
in other source codes.

What should be the recommended way to address this scenario?

You have something wrong, this works properly even if you have multiple
source files (see wdm.h for how POOL_NX_OPTIN works).

-scott
OSR
@OSRDrivers

wrote in message news:xxxxx@ntdev…

It is working now. Seems like the problem was with the extra spaces between
“DPOOL_NX_OPTIN” and “1”. However, there is a new problem. one of my drivers
has multiple source files, and only one file has the DriverEntry defined. So
even if I call “ExInitializeDriverRuntime(DrvRtPoolNxOptIn)” in this driver
entry, it does not replace “NonPagedPool” with “NonPagedPoolNx” that are
present in other source codes.

What should be the recommended way to address this scenario?

I have defined the macro in project property sheet only. Also I haved
verified that the child source files also have this macro inherited.

My problem is with the ExInitializeRuntime() function call. I have checked
its definition in wdm.h. It’s an inline function. I have called it in the
driverentry routine. However, I still don’t get how it is obvious that this
inline function being in one source file will also be able to replace
nonpagedpool with nonpagedpoolnx in other source file of the same project ?

On 17-May-2017 7:57 PM, “Scott Noone” wrote:

> You have something wrong, this works properly even if you have multiple
> source files (see wdm.h for how POOL_NX_OPTIN works).
>
> -scott
> OSR
> @OSRDrivers
>
> wrote in message news:xxxxx@ntdev…
>
> It is working now. Seems like the problem was with the extra spaces
> between “DPOOL_NX_OPTIN” and “1”. However, there is a new problem. one of
> my drivers has multiple source files, and only one file has the DriverEntry
> defined. So even if I call “ExInitializeDriverRuntime(DrvRtPoolNxOptIn)”
> in this driver entry, it does not replace “NonPagedPool” with
> “NonPagedPoolNx” that are present in other source codes.
>
> What should be the recommended way to address this scenario?
>
> —
> NTDEV is sponsored by OSR
>
> Visit the list online at: http:> lists.cfm?list=ntdev>
>
> MONTHLY seminars on crash dump analysis, WDF, Windows internals and
> software drivers!
> Details at http:
>
> To unsubscribe, visit the List Server section of OSR Online at <
> http://www.osronline.com/page.cfm?name=ListServer&gt;
></http:></http:>

Utkal Sinha wrote:

My problem is with the ExInitializeRuntime() function call. I have
checked its definition in wdm.h. It’s an inline function. I have
called it in the driverentry routine. However, I still don’t get how
it is obvious that this inline function being in one source file will
also be able to replace nonpagedpool with nonpagedpoolnx in other
source file of the same project ?

For ExInitializeDriverRuntime to work, you still have to define
POOL_NX_OPTIN in every source file. When you use POOL_NX_OPTIN, it
redefines the constant “NonPagedPool” to be ExDefaultNonPagedPoolType,
which is a driver global. All that ExInitializeRuntime does is set the
global variable ExDefaultNonPagedPoolType to either NonPagedPool or
NonPagedPoolNx, depending on the operating system support.

The net effect is that POOL_NX_OPTIN turns this:
ExAllocatePool( NonPagedPool, 1234 );
into this:
ExAllocatePool( ExDefaultNonPagedPoolType, 1234 );

and the value of that variable is what gets redefined at runtime.


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

First, in wdm.h :

#define NonPagedPool ExDefaultNonPagedPoolType

And then in the inline function called in DriverEntry :

ExDefaultNonPagedPoolType = NonPagedPoolNx ;

W. N.