> Windows Syscalls
ntoskrnl.exeT1620T1574T1106

NtLoadEnclaveData

Copies a page-aligned buffer (code or data) from VTL0 host memory into an enclave's VTL1 range before initialisation.

Prototype

NTSTATUS NtLoadEnclaveData(
  HANDLE  ProcessHandle,
  PVOID   BaseAddress,
  PVOID   Buffer,
  SIZE_T  BufferSize,
  ULONG   Protect,
  PVOID   PageInformation,
  ULONG   PageInformationLength,
  PSIZE_T NumberOfBytesWritten,
  PULONG  EnclaveError
);

Arguments

NameTypeDirDescription
ProcessHandleHANDLEinHandle to the host process owning the enclave. Typically NtCurrentProcess().
BaseAddressPVOIDinTarget VTL1 address inside the enclave where Buffer is copied. Must be page-aligned and inside the enclave's reserved range.
BufferPVOIDinSource VTL0 buffer (the mapped enclave image or a data page). Page-aligned.
BufferSizeSIZE_TinNumber of bytes to copy. Must be a multiple of the page size.
ProtectULONGinFinal page protection inside the enclave (PAGE_READONLY, PAGE_READWRITE, PAGE_EXECUTE_READ — never WRITE+EXECUTE on VBS).
PageInformationPVOIDinType-specific descriptor: ENCLAVE_LOAD_DATA_SGX (SECINFO + EADD flags) or ENCLAVE_LOAD_DATA_VBS (page type).
PageInformationLengthULONGinSize in bytes of the PageInformation descriptor.
NumberOfBytesWrittenPSIZE_ToutReceives the number of bytes actually written into the enclave (normally equal to BufferSize on success).
EnclaveErrorPULONGoutReceives the SGX EADD or securekernel-specific error code on STATUS_ENCLAVE_FAILURE.

Syscall IDs by Windows version

Windows versionSyscall IDBuild
Win10 16070xFAwin10-1607
Win10 17030xFDwin10-1703
Win10 17090xFEwin10-1709
Win10 18030xFFwin10-1803
Win10 18090x100win10-1809
Win10 19030x101win10-1903
Win10 19090x101win10-1909
Win10 20040x106win10-2004
Win10 20H20x106win10-20h2
Win10 21H10x106win10-21h1
Win10 21H20x107win10-21h2
Win10 22H20x107win10-22h2
Win11 21H20x10Cwin11-21h2
Win11 22H20x10Dwin11-22h2
Win11 23H20x10Dwin11-23h2
Win11 24H20x10Fwin11-24h2
Server 20160xFAwinserver-2016
Server 20190x100winserver-2019
Server 20220x10Bwinserver-2022
Server 20250x10Fwinserver-2025

Kernel module

ntoskrnl.exeNtLoadEnclaveData

Related APIs

LoadEnclaveDataLoadEnclaveImageWNtCreateEnclaveNtInitializeEnclaveNtCallEnclave

Syscall stub

4C 8B D1            mov r10, rcx
B8 0F 01 00 00      mov eax, 0x10F
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

`NtLoadEnclaveData` is the **page-by-page ingest** call that runs *between* `NtCreateEnclave` and `NtInitializeEnclave`. On SGX it lowers into an `EADD` for each source page; on VBS the Secure Kernel `IumLoadEnclaveData` copies the source buffer across the VTL boundary and stamps the destination page's measurement into the running enclave hash. The protection passed here is the *final* protection — the enclave cannot remap it later (no per-page `mprotect` exists in VTL1). For an enclave DLL, `vertdll.dll` makes one call per `IMAGE_SCN_*` section: one PAGE_READONLY for `.rdata`, one PAGE_EXECUTE_READ for `.text`, one PAGE_READWRITE for `.data`. All loads must happen before `NtInitializeEnclave`; afterwards the call returns `STATUS_ENCLAVE_NOT_TERMINATED`.

Common malware usage

From an offensive standpoint, this is the call that physically *places code into VTL1*. The barrier to abuse is that the loaded bytes will be measured into the enclave hash and that hash must match what `IMAGE_ENCLAVE_CONFIG` permits at init time. Two real-world levers: (1) **Microsoft-signed enclave with attacker-controlled data**: load benign data pages whose contents are interpreted as commands by the signed code — equivalent to ROP inside the enclave; (2) **research loader**: the Yuste / Soriano-Salvador work loads a signed *stub* enclave whose 'code' is actually a tiny dispatcher that accepts a shellcode pointer at `NtCallEnclave` time — the malicious payload is never measured into MRENCLAVE, only the dispatcher is. Defenders cannot inspect the loaded bytes after the fact — VTL1 memory is opaque to VTL0.

Detection opportunities

The pre-init load burst is highly characteristic: ten-to-hundreds of `NtLoadEnclaveData` calls in quick succession on the same enclave base address, followed by `NtInitializeEnclave`. The ETW provider `Microsoft-Windows-Kernel-Memory` emits an event per load. EDRs that hook on the host syscall pattern can flag the sequence trivially; the harder problem is attribution — which DLL is being loaded into the enclave. The defender's best lever is the *file source*: the host module performing the loads will have an `IMAGE_ENCLAVE_CONFIG` directory naming the enclave DLL by image hash. Sysmon Event ID 7 (ImageLoad) on the host will show the enclave DLL's PE mapping prior to the load syscalls — pair the two for retroactive identification.

Direct syscall examples

cVBS enclave bring-up (step 2/3 — load image)

// Walk the PE sections of a signed enclave DLL and copy them into the enclave.
// (Helper for the create -> load -> initialize -> call sequence.)
#include <windows.h>

BOOL LoadEnclaveImage(PVOID enclaveBase, PVOID peImage, SIZE_T peSize) {
    PIMAGE_DOS_HEADER dos = (PIMAGE_DOS_HEADER)peImage;
    PIMAGE_NT_HEADERS nt = (PIMAGE_NT_HEADERS)((BYTE*)peImage + dos->e_lfanew);
    PIMAGE_SECTION_HEADER sec = IMAGE_FIRST_SECTION(nt);

    for (WORD i = 0; i < nt->FileHeader.NumberOfSections; i++, sec++) {
        ULONG prot = PAGE_READONLY;
        if (sec->Characteristics & IMAGE_SCN_MEM_EXECUTE) prot = PAGE_EXECUTE_READ;
        else if (sec->Characteristics & IMAGE_SCN_MEM_WRITE) prot = PAGE_READWRITE;

        PVOID dst = (BYTE*)enclaveBase + sec->VirtualAddress;
        PVOID src = (BYTE*)peImage      + sec->PointerToRawData;
        SIZE_T size = ((sec->SizeOfRawData + 0xFFF) & ~0xFFFu);

        if (!LoadEnclaveData(
                GetCurrentProcess(),
                dst, src, size, prot,
                NULL, 0,           // page info (VBS-specific, may be NULL)
                NULL,              // bytes written
                NULL)) {           // enclave error
            return FALSE;
        }
    }
    return TRUE;
}

asmx64 direct stub (Win11 24H2)

; Direct syscall stub for NtLoadEnclaveData (SSN 0x10F on Win11 24H2 / Server 2025)
NtLoadEnclaveData PROC
    mov  r10, rcx          ; ProcessHandle
    mov  eax, 10Fh         ; SSN
    syscall
    ret
NtLoadEnclaveData ENDP

MITRE ATT&CK mappings

Last verified: 2026-05-20