sgx_ioc_enclave_add_pages(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… sgx_ioc_enclave_add_pages(9) β€” like, the kernel API manual, bestie ✨

okay so picture this: it's a page from the Kernel API Manual and it's all about sgx_ioc_enclave_add_pages and honestly? she's lowkey iconic. let's get into it 🫢


🌸 NAME 🌸

sgx_ioc_enclave_add_pages β€” the handler for %SGX_IOC_ENCLAVE_ADD_PAGES πŸ’–


✨ SYNOPSIS ✨

long sgx_ioc_enclave_add_pages (struct sgx_encl *encl , void __user *arg
);

πŸŽ€ ARGUMENTS πŸŽ€

  • encl β€” an enclave pointer, bestie. that's the whole vibe.
  • arg β€” a user pointer to a struct sgx_enclave_add_pages instance πŸ¦‹

πŸ‘‘ DESCRIPTION πŸ‘‘

So what she does: she adds one or more pages to an uninitialized enclave, and optionally extends the measurement with the contents of the page. and the SECINFO + the measurement mask? those get applied to all the pages. periodt. πŸ’…

Now, a SECINFO for a TCS is required to always contain zero permissions, because the CPU silently zeros them 😭. Allowing anything else would cause a mismatch in the measurement β€” so like, don't.

mmap's protection bits are capped by the page permissions. For each page address, the maximum protection bits are computed with the following heuristics:

  1. A regular page: PROT_R, PROT_W and PROT_X match the SECINFO permissions.
  2. A TCS page: PROT_R | PROT_W.

mmap is not allowed to surpass the minimum of the maximum protection bits within the given address range. no cap, fr fr πŸ™ˆ

⚠️ The function deinitializes kernel data structures for enclave and returns -EIO in any of the following conditions:
  • Enclave Page Cache (EPC), the physical memory holding enclaves, has been invalidated. This will cause EADD and EEXTEND to fail. πŸ’€
  • If the source address is corrupted somehow when executing EADD.

πŸ”₯ RETURN πŸ”₯

  • 0: Success. slay πŸ’–
  • -EACCES: The source page is located in a noexec partition.
  • -ENOMEM: Out of EPC pages. 😭
  • -EINTR: The call was interrupted before data was processed.
  • -EIO: Either EADD or EEXTEND failed because invalid source address or power cycle.
  • -errno: POSIX error.

🌈 SEE ALSO 🌈

Kernel file ./arch/x86/kernel/cpu/sgx/ioctl.c πŸ’«


and that's the whole page, bestie 🧚 ngl she lives at ./arch/x86/kernel/cpu/sgx, stamped October 2026 β€” go off, king πŸ‘‘πŸ’œ

πŸ“¦ where this page comes from