C30031

warning C30031: Calling a memory allocating function and passing a parameter that indicates executable memory

Code Analysis detected use of POOL_NX_OPTIN and ExInitializeDriverRuntime(DrvRtPoolNxOptIn) was called before the entry function (for example, DriverEntry() or DllInitialize()). It is possible that the entry function indirectly calls ExInitializeDriverRuntime(DrvRtPoolNxOptIn), in which case the error can be suppressed (see Pragma Prefast to Suppress Warning Messages).

BANNED_MEM_ALLOCATION_MAYBE_SAFE

Example

The following code in the sources file generates this warning:

C_DEFINES=$(C_DEFINES) -DPOOL_NX_OPTIN=1

In the code file

void MakeSafeInitialization()
{
    ExInitializeDriverRuntime(DrvRtPoolNxOptIn);
}

NTSTATUS
DriverEntry (
    _In_ PDRIVER_OBJECT DriverObject,
    _In_ PUNICODE_STRING RegistryPath
    )
{
    NTSTATUS status;

    MakeSafeInitialization ();
…
}

The following code avoids this warning:

NTSTATUS
DriverEntry (
    _In_ PDRIVER_OBJECT DriverObject,
    _In_ PUNICODE_STRING RegistryPath
    )
{
    NTSTATUS status;

    ExInitializeDriverRuntime(DrvRtPoolNxOptIn);
…
}