> Windows Syscalls
ntoskrnl.exeT1547T1027T1106

NtFlushVirtualMemory

Flushes dirty pages of a file-backed view to disk, similar to FlushViewOfFile.

Prototype

NTSTATUS NtFlushVirtualMemory(
  HANDLE           ProcessHandle,
  PVOID           *BaseAddress,
  PSIZE_T          RegionSize,
  PIO_STATUS_BLOCK IoStatus
);

Arguments

NameTypeDirDescription
ProcessHandleHANDLEinHandle to the process whose mapping should be flushed. NtCurrentProcess() for self.
BaseAddressPVOID*in/outPointer to the base of the region to flush. On return, set to the actual flushed base.
RegionSizePSIZE_Tin/outRegion size in bytes. Rounded up to a page boundary; actual size returned on output.
IoStatusPIO_STATUS_BLOCKoutReceives the I/O status (Status + Information bytes flushed).

Syscall IDs by Windows version

Windows versionSyscall IDBuild
Win10 15070xDCwin10-1507
Win10 16070xDFwin10-1607
Win10 17030xE2win10-1703
Win10 17090xE3win10-1709
Win10 18030xE4win10-1803
Win10 18090xE5win10-1809
Win10 19030xE6win10-1903
Win10 19090xE6win10-1909
Win10 20040xEBwin10-2004
Win10 20H20xEBwin10-20h2
Win10 21H10xEBwin10-21h1
Win10 21H20xECwin10-21h2
Win10 22H20xECwin10-22h2
Win11 21H20xF1win11-21h2
Win11 22H20xF2win11-22h2
Win11 23H20xF2win11-23h2
Win11 24H20xF4win11-24h2
Server 20160xDFwinserver-2016
Server 20190xE5winserver-2019
Server 20220xF0winserver-2022
Server 20250xF4winserver-2025

Kernel module

ntoskrnl.exeNtFlushVirtualMemory

Related APIs

FlushViewOfFileFlushFileBuffersNtCreateSectionNtMapViewOfSectionNtMapViewOfSectionExMapViewOfFile

Syscall stub

4C 8B D1            mov r10, rcx
B8 F4 00 00 00      mov eax, 0xF4      ; Win11 24H2 SSN
F6 04 25 08 03 FE 7F 01   test byte ptr [0x7FFE0308], 1
75 03               jne short +3
0F 05               syscall
C3                  ret
CD 2E               int 2Eh
C3                  ret

Undocumented notes

Counterpart to `FlushViewOfFile` for sections backed by a real on-disk file. The kernel walks the PTEs over the requested range, gathers any dirty pages, and issues paging-IO to the underlying file system — for a memory-mapped file this is equivalent to an `fsync` of just the dirty subset. For pagefile-backed or PAGE_NOACCESS regions the call is effectively a no-op. The `IoStatus.Information` field reports the number of bytes actually written.

Common malware usage

Used in persistence and ransomware chains that modify on-disk artifacts via a memory-mapped view rather than `WriteFile`: the attacker maps an executable, INI, scheduled-task XML or LSA Notification Package list with `PAGE_READWRITE`, patches the bytes, and calls `NtFlushVirtualMemory` to force the modification to disk *now* instead of waiting for the lazy writer — important when the next stage (a reboot, a service restart, or an immediate exec) must observe the on-disk change. Also seen in `MiniDumpWriteDump`-style credential-theft chains that map and edit the dump file in place. Some ransomware families touch this call to ensure the encrypted bytes hit the platters before they delete shadow copies and trigger a forced reboot.

Detection opportunities

Sysmon Event 11 (FileCreate) does not fire on a flush — the file already exists. The most reliable telemetry is the ETW `Microsoft-Windows-Kernel-FileIO` `FileIo/OperationEnd` event for `WRITE` operations whose `IrpFlags` indicate paging-IO, correlated to a process that recently obtained a writable section over a sensitive file (executable in `\System32`, scheduled-task XML, `\Registry\Machine\System\CurrentControlSet\Services\*\ImagePath`-backed binary). EDRs that hook `NtCreateSection` against high-value paths and then track subsequent `NtFlushVirtualMemory` against those views catch the in-place patch pattern.

Direct syscall examples

cPatch an on-disk binary via mapped view and force flush

// Persistence helper: patch C:\Windows\System32\target.exe in place.
HANDLE hFile = CreateFileW(L"C:\\Windows\\System32\\target.exe",
    GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ,
    NULL, OPEN_EXISTING, 0, NULL);

HANDLE hMap = CreateFileMappingW(hFile, NULL, PAGE_READWRITE, 0, 0, NULL);
PVOID  view = MapViewOfFile(hMap, FILE_MAP_WRITE, 0, 0, 0);

PatchEntryPoint(view);  // overwrite a few bytes

SIZE_T regionSize = /* SizeOfImage rounded up */ 0;
IO_STATUS_BLOCK iosb;
NTSTATUS s = NtFlushVirtualMemory(
    NtCurrentProcess(),
    &view,
    &regionSize,
    &iosb);
// iosb.Information now holds the number of bytes written back.

asmx64 direct stub (Win11 24H2)

; NtFlushVirtualMemory direct stub — SSN 0xF4 on Win11 24H2
NtFlushVirtualMemory PROC
    mov  r10, rcx
    mov  eax, 0F4h
    syscall
    ret
NtFlushVirtualMemory ENDP

rustFlush a mapped region

use ntapi::ntmmapi::NtFlushVirtualMemory;
use winapi::shared::ntdef::HANDLE;
use winapi::shared::ntdef::PVOID;
use winapi::um::winnt::IO_STATUS_BLOCK;
use std::{mem, ptr::null_mut};

unsafe fn flush(view: PVOID, mut size: usize) -> usize {
    let mut base = view;
    let mut iosb: IO_STATUS_BLOCK = mem::zeroed();
    let s = NtFlushVirtualMemory(
        -1isize as HANDLE,
        &mut base,
        &mut size,
        &mut iosb,
    );
    assert!(s >= 0);
    *iosb.Information() as usize
}

MITRE ATT&CK mappings

Last verified: 2026-05-20