Wrapper around memcpy that handles the STATUS_IN_PAGE_ERROR exception
Syntax
NTSTATUS NTAPI RtlCopyMappedMemory (
void* pDest,
const void* pSrc,
SIZE_T bytesToCopy
)
Parameters
- pDest
- Destination buffer of the memory copy
- PVOID pSrc
- Source buffer to copy from
- bytesToCopy
- Amount to copy from pSrc to pDest
Return Value
STATUS_SUCCESS if the copy was successful, or the IO error code if an exception was handled
Remarks
The exception handler is only interested in STATUS_IN_PAGE_ERROR, any other exceptions are left to bubble up to other relevant handlers.
The internal workhorse function called (RtlpCopyMappedMemoryEx) has additional functionality to return more exception information and accepts flags to control the exception handler's behaviour, but this function doesn't use them, making this function the equivalent of:
NTSTATUS NTAPI RtlCopyMappedMemory(void* pDst, const void* pSrc, SIZE_T bytes) { NTSTATUS ret = STATUS_SUCCESS; __try { memcpy(pDst, pSrc, bytes); } __except(HandleException(GetExceptionInformation(), &ret)) {} return ret; } LONG WINAPI HandleException(PEXCEPTION_POINTERS pEx, NTSTATUS* pStat) { // 1 = execute_handler, 0 == continue_search LONG ret = (pEx->ExceptionRecord->ExceptionCode == STATUS_IN_PAGE_ERROR); if(ret) { *pStat = (NTSTATUS)pEx->ExceptionRecord->ExceptionInformation[2]; } return ret; }