LockPages (Compact 2013)

3/28/2014

This function locks into memory the specified region of the virtual address space of the process, ensuring that subsequent access to the region does not incur a page fault. This function can be called only in kernel mode.

Syntax

BOOL LockPages(
  LPVOID lpvAddress,
  DWORD cbSize,
  PDWORD pPFNs,
  int fOptions
);

Parameters

  • lpvAddress
    [in] Starting address of a region of committed pages; that is, to be locked.
  • cbSize
    [in] Number of bytes to lock.
  • pPFNs
    [out] Array of page physical frame numbers representing the CPU-dependent physical addresses of the pages.

    This parameter can be set to NULL if the associated physical pages of the locked region does not matter to the caller.

  • fOptions
    [in] Option flag.

    The following table shows possible values for this parameter.

    Value

    Description

    LOCKFLAG_QUERY_ONLY

    Query the physical to virtual mapping of a memory allocation. No pages are locked, and no reference counters are incremented.

    LOCKFLAG_READ

    Read access is required, as opposed to page present but PAGE_NOACCESS.

    LOCKFLAG_WRITE

    Write access is required. This means that locking excludes other writers.

Return Value

TRUE indicates success. FALSE indicates failure. To get extended error information, call GetLastError.

Remarks

To determine the actual physical address, the value returned in pPFNs must be shifted to the left by a number of bits. The shift count can be found in UserKInfo[KINX_PFN_SHIFT]. Shift the returned values to the left by this value to get the actual physical address.

The physical pages are stored in increasing order, but are not guaranteed to be contiguous.

LockPages has a reference count, so if the same thread calls LockPages twice, the second call to UnlockPages unlocks the pages.

If LockPages is called with the LOCKFLAG_QUERY_ONLY flag in the fOptions parameter, no reference counters are incremented, and UnlockPages need not be called. If UnlockPages is called on pages for which LockPages has been called only with the LOCKFLAG_QUERY_ONLY flag, UnlockPages will return ERROR_INVALID_PARAMETER.

Requirements

Header

pkfuncs.h

Library

coredll.lib

See Also

Reference

Kernel Functions
UnlockPages
LoadDriver