Export (0) Print
Expand All

C28170

warning C28170: The function has been declared to be in a paged segment, but neither PAGED_CODE nor PAGED_CODE_LOCKED was found

The Code Analysis tool reports this error when #pragma alloc_text or #pragma code_seg is used to move a function that does not contain a PAGED_CODE or PAGED_CODE_LOCKED macro into a pageable code section. This error is reported at the line number that corresponds to the first brace ({) in the function.

The Code Analysis tool infers that a section is pageable when the section name begins with PAGE. The functions in pageable code must contain a PAGED_CODE or PAGED_CODE_LOCKED macro at the beginning of the function between the first brace ({ ) and the first conditional statement.

These macros allow the Code Analysis tool and a run-time checker to determine whether pageable code might be run at an elevated IRQL. If a page fault occurs while the system is running at an elevated level, the system will crash.

If the functions in a paged segment are subsequently locked into memory, use PAGED_CODE_LOCKED instead of PAGED_CODE. The PAGE_CODE_LOCKED macro permits the driver to make calls that raise the IRQL without encountering a PREfast for Drivers warning.

This condition is often very difficult to find while testing (unless the PAGED_CODE macro is used to cause the Driver Verifier to check for the error), because the code must actually be paged out for the page fault to occur.

Example

The following code example elicits this warning.


void func();
#pragma alloc_text("PAGED_CODE", func);

void func1()
{
   // paged, no PAGED_CODE: error
}

The following code example avoids this warning.


void func();
#pragma alloc_text("PAGED_CODE", func);

void func2()
{
   PAGED_CODE(); // includes PAGED_CODE macro
}

 

 

Send comments about this topic to Microsoft

Show:
© 2014 Microsoft