samples/nitro_enclaves/ne_ioctl_sample.c
Source file repositories/reference/linux-study-clean/samples/nitro_enclaves/ne_ioctl_sample.c
File Facts
- System
- Linux kernel
- Corpus path
samples/nitro_enclaves/ne_ioctl_sample.c- Extension
.c- Size
- 20900 bytes
- Lines
- 883
- Domain
- Support Tooling And Documentation
- Bucket
- samples
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
stdio.hstdlib.herrno.hfcntl.hlimits.hpoll.hpthread.hstring.hsys/eventfd.hsys/ioctl.hsys/mman.hsys/socket.hsys/stat.hsys/types.hunistd.hlinux/mman.hlinux/nitro_enclaves.hlinux/vm_sockets.h
Detected Declarations
struct ne_user_mem_regionfunction ne_create_vmfunction ne_poll_enclave_fdfunction ne_alloc_user_mem_regionfunction ne_load_enclave_imagefunction ne_set_user_mem_regionfunction ne_free_mem_regionsfunction ne_add_vcpufunction ne_start_enclavefunction ne_start_enclave_check_bootedfunction main
Annotated Snippet
struct ne_user_mem_region {
void *userspace_addr;
size_t memory_size;
};
/**
* ne_create_vm() - Create a slot for the enclave VM.
* @ne_dev_fd: The file descriptor of the NE misc device.
* @slot_uid: The generated slot uid for the enclave.
* @enclave_fd : The generated file descriptor for the enclave.
*
* Context: Process context.
* Return:
* * 0 on success.
* * Negative return value on failure.
*/
static int ne_create_vm(int ne_dev_fd, unsigned long *slot_uid, int *enclave_fd)
{
int rc = -EINVAL;
*enclave_fd = ioctl(ne_dev_fd, NE_CREATE_VM, slot_uid);
if (*enclave_fd < 0) {
rc = *enclave_fd;
switch (errno) {
case NE_ERR_NO_CPUS_AVAIL_IN_POOL: {
printf("Error in create VM, no CPUs available in the NE CPU pool\n");
break;
}
default:
printf("Error in create VM [%m]\n");
}
return rc;
}
return 0;
}
/**
* ne_poll_enclave_fd() - Thread function for polling the enclave fd.
* @data: Argument provided for the polling function.
*
* Context: Process context.
* Return:
* * NULL on success / failure.
*/
void *ne_poll_enclave_fd(void *data)
{
int enclave_fd = *(int *)data;
struct pollfd fds[1] = {};
int i = 0;
int rc = -EINVAL;
printf("Running from poll thread, enclave fd %d\n", enclave_fd);
fds[0].fd = enclave_fd;
fds[0].events = POLLIN | POLLERR | POLLHUP;
/* Keep on polling until the current process is terminated. */
while (1) {
printf("[iter %d] Polling ...\n", i);
rc = poll(fds, 1, NE_POLL_WAIT_TIME_MS);
if (rc < 0) {
printf("Error in poll [%m]\n");
return NULL;
}
i++;
if (!rc) {
printf("Poll: %d seconds elapsed\n",
i * NE_POLL_WAIT_TIME);
continue;
}
printf("Poll received value 0x%x\n", fds[0].revents);
if (fds[0].revents & POLLHUP) {
printf("Received POLLHUP\n");
return NULL;
}
if (fds[0].revents & POLLNVAL) {
printf("Received POLLNVAL\n");
Annotation
- Immediate include surface: `stdio.h`, `stdlib.h`, `errno.h`, `fcntl.h`, `limits.h`, `poll.h`, `pthread.h`, `string.h`.
- Detected declarations: `struct ne_user_mem_region`, `function ne_create_vm`, `function ne_poll_enclave_fd`, `function ne_alloc_user_mem_region`, `function ne_load_enclave_image`, `function ne_set_user_mem_region`, `function ne_free_mem_regions`, `function ne_add_vcpu`, `function ne_start_enclave`, `function ne_start_enclave_check_booted`.
- Atlas domain: Support Tooling And Documentation / samples.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.