LoadEnclaveData function (enclaveapi.h)

Loads data into an uninitialized enclave that you created by calling CreateEnclave.

Syntax

BOOL LoadEnclaveData(
  [in]            HANDLE  hProcess,
  [in]            LPVOID  lpAddress,
  [in]            LPCVOID lpBuffer,
  [in]            SIZE_T  nSize,
  [in]            DWORD   flProtect,
  [in]            LPCVOID lpPageInformation,
  [in]            DWORD   dwInfoLength,
  [out]           PSIZE_T lpNumberOfBytesWritten,
  [out, optional] LPDWORD lpEnclaveError
);

Parameters

[in] hProcess

A handle to the process for which the enclave was created.

[in] lpAddress

The address in the enclave where you want to load the data.

[in] lpBuffer

A pointer to the data the you want to load into the enclave.

[in] nSize

The size of the data that you want to load into the enclave, in bytes. This value must be a whole-number multiple of the page size.

[in] flProtect

The memory protection to use for the pages that you want to add to the enclave. For a list of memory protection values, see memory protection constants. This value must not include the following constants:

  • PAGE_GUARD
  • PAGE_NOCACHE
  • PAGE_WRITECOMBINE
  • PAGE_NOACCESS

This value can include the enclave specific constants that the following table describes:

Constant Description
PAGE_ENCLAVE_THREAD_CONTROL The page contains a thread control structure (TCS).
PAGE_ENCLAVE_UNVALIDATED The page contents that you supply are excluded from measurement with the EEXTEND instruction of the Intel Software Guard Extensions programming model.

[in] lpPageInformation

A pointer to information that describes the pages that you want to add to the enclave. The lpPageInformation parameter is not used.

[in] dwInfoLength

The length of the structure that the lpPageInformation parameter points to, in bytes. This value must be 0.

[out] lpNumberOfBytesWritten

A pointer to a variable that receives the number of bytes that LoadEnclaveData copied into the enclave.

[out, optional] lpEnclaveError

An optional pointer to a variable that receives an enclave error code that is architecture-specific. The lpEnclaveError parameter is not used.

Return value

If all of the data is loaded into the enclave successfully, the return value is nonzero. Otherwise, the return value is zero. To get extended error information, call GetLastError.

For a list of common error codes, see System Error Codes. The following error codes also apply for this function.

Return code Description
ERROR_BAD_LENGTH The value of the dwInfoLength parameter did not match the value expected based on the value specified for the lpPageInformation parameter.

Remarks

To initialize the enclave after you load data into the enclave, call InitializeEnclave.

LoadEnclaveData is only supported enclaves that have the ENCLAVE_TYPE_SGX and ENCLAVE_TYPE_SGX2 enclave types.

Requirements

Requirement Value
Minimum supported client Windows 10 [desktop apps | UWP apps]
Minimum supported server Windows Server 2016 [desktop apps | UWP apps]
Target Platform Windows
Header enclaveapi.h (include Winbase.h)
Library onecore.lib
DLL Api-ms-win-core-enclave-l1-1-0.dll; kernel32.dll; KernelBase.dll

See also

Enclave functions

CreateEnclave

InitializeEnclave

Memory protection constants