Поделиться через


VirtualAllocCopyEx (Compact 2013)

3/28/2014

This function reserves or commits a region of pages in the virtual address space of the specified destination process, hDstProc, and then dynamically creates an alias to the virtual memory given by the source process, hSrcProc, and the source address pAddr. Terminate the mapping by calling VirtualFreeEx. This function is callable only in kernel mode.

Syntax

LPVOID VirtualAllocCopyEx (
    HANDLE hSrcProc,
    HANDLE hDstProc,
    LPVOID pAddr,
    DWORD cbSize,
    DWORD dwProtect
);

Parameters

  • hSrcProc
    [in] Handle to the source process.
  • hDstProc
    [in] Handle to the destination process.
  • pAddr
    [in] Long pointer to the specified starting address in the source process, hSrcProc. This cannot be NULL.
  • cbSize
    [in] Size in bytes of virtual allocation pointed to by pAddr in the hSrcProc process. This cannot be NULL.
  • dwProtect
    [in] Type of access protection. If the pages are being committed, any one of a number of flags can be specified, along with the PAGE_GUARD and PAGE_NOCACHE, protection modifier flags.

    For information about the possible flags for this parameter, see VirtualCopy.

Return Value

The base address of the allocated region of pages indicates success. NULL indicates failure. To get extended error information, call GetLastError.

Remarks

If you want to VirtualAllocCopy a physical or virtual buffer, if that buffer is not page-aligned then you will end up copying more data than you specified. If the start of the buffer is not page-aligned then you will also copy data before the start of the specified buffer, starting from the beginning of the page. If the end of the buffer is not page-aligned then you will also copy data after the end of the specified buffer, ending at the following page boundary.

This is a security issue if the copied buffer is ever passed to user mode. The user mode application will be able to access the surrounding data that is not part of the specified buffer. To protect the surrounding data, use a buffer that is page-aligned and an even multiple of pages in size. If that is not possible then passing the data to user mode puts it at risk.

For more information, see VirtualAllocEx and VirtualCopyEx.

Requirements

Header

pkfuncs.h

Library

coredll.lib

See Also

Reference

Memory Management Functions
GetSystemInfo
VirtualCopyEx
VirtualAllocEx
VirtualFreeEx