Path: blob/master/samples/nitro_enclaves/ne_ioctl_sample.c
26278 views
// SPDX-License-Identifier: GPL-2.01/*2* Copyright 2020-2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.3*/45/**6* DOC: Sample flow of using the ioctl interface provided by the Nitro Enclaves (NE)7* kernel driver.8*9* Usage10* -----11*12* Load the nitro_enclaves module, setting also the enclave CPU pool. The13* enclave CPUs need to be full cores from the same NUMA node. CPU 0 and its14* siblings have to remain available for the primary / parent VM, so they15* cannot be included in the enclave CPU pool.16*17* See the cpu list section from the kernel documentation.18* https://www.kernel.org/doc/html/latest/admin-guide/kernel-parameters.html#cpu-lists19*20* insmod drivers/virt/nitro_enclaves/nitro_enclaves.ko21* lsmod22*23* The CPU pool can be set at runtime, after the kernel module is loaded.24*25* echo <cpu-list> > /sys/module/nitro_enclaves/parameters/ne_cpus26*27* NUMA and CPU siblings information can be found using:28*29* lscpu30* /proc/cpuinfo31*32* Check the online / offline CPU list. The CPUs from the pool should be33* offlined.34*35* lscpu36*37* Check dmesg for any warnings / errors through the NE driver lifetime / usage.38* The NE logs contain the "nitro_enclaves" or "pci 0000:00:02.0" pattern.39*40* dmesg41*42* Setup hugetlbfs huge pages. The memory needs to be from the same NUMA node as43* the enclave CPUs.44*45* https://www.kernel.org/doc/html/latest/admin-guide/mm/hugetlbpage.html46*47* By default, the allocation of hugetlb pages are distributed on all possible48* NUMA nodes. Use the following configuration files to set the number of huge49* pages from a NUMA node:50*51* /sys/devices/system/node/node<X>/hugepages/hugepages-2048kB/nr_hugepages52* /sys/devices/system/node/node<X>/hugepages/hugepages-1048576kB/nr_hugepages53*54* or, if not on a system with multiple NUMA nodes, can also set the number55* of 2 MiB / 1 GiB huge pages using56*57* /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages58* /sys/kernel/mm/hugepages/hugepages-1048576kB/nr_hugepages59*60* In this example 256 hugepages of 2 MiB are used.61*62* Build and run the NE sample.63*64* make -C samples/nitro_enclaves clean65* make -C samples/nitro_enclaves66* ./samples/nitro_enclaves/ne_ioctl_sample <path_to_enclave_image>67*68* Unload the nitro_enclaves module.69*70* rmmod nitro_enclaves71* lsmod72*/7374#include <stdio.h>75#include <stdlib.h>76#include <errno.h>77#include <fcntl.h>78#include <limits.h>79#include <poll.h>80#include <pthread.h>81#include <string.h>82#include <sys/eventfd.h>83#include <sys/ioctl.h>84#include <sys/mman.h>85#include <sys/socket.h>86#include <sys/stat.h>87#include <sys/types.h>88#include <unistd.h>8990#include <linux/mman.h>91#include <linux/nitro_enclaves.h>92#include <linux/vm_sockets.h>9394/**95* NE_DEV_NAME - Nitro Enclaves (NE) misc device that provides the ioctl interface.96*/97#define NE_DEV_NAME "/dev/nitro_enclaves"9899/**100* NE_POLL_WAIT_TIME - Timeout in seconds for each poll event.101*/102#define NE_POLL_WAIT_TIME (60)103/**104* NE_POLL_WAIT_TIME_MS - Timeout in milliseconds for each poll event.105*/106#define NE_POLL_WAIT_TIME_MS (NE_POLL_WAIT_TIME * 1000)107108/**109* NE_SLEEP_TIME - Amount of time in seconds for the process to keep the enclave alive.110*/111#define NE_SLEEP_TIME (300)112113/**114* NE_DEFAULT_NR_VCPUS - Default number of vCPUs set for an enclave.115*/116#define NE_DEFAULT_NR_VCPUS (2)117118/**119* NE_MIN_MEM_REGION_SIZE - Minimum size of a memory region - 2 MiB.120*/121#define NE_MIN_MEM_REGION_SIZE (2 * 1024 * 1024)122123/**124* NE_DEFAULT_NR_MEM_REGIONS - Default number of memory regions of 2 MiB set for125* an enclave.126*/127#define NE_DEFAULT_NR_MEM_REGIONS (256)128129/**130* NE_IMAGE_LOAD_HEARTBEAT_CID - Vsock CID for enclave image loading heartbeat logic.131*/132#define NE_IMAGE_LOAD_HEARTBEAT_CID (3)133/**134* NE_IMAGE_LOAD_HEARTBEAT_PORT - Vsock port for enclave image loading heartbeat logic.135*/136#define NE_IMAGE_LOAD_HEARTBEAT_PORT (9000)137/**138* NE_IMAGE_LOAD_HEARTBEAT_VALUE - Heartbeat value for enclave image loading.139*/140#define NE_IMAGE_LOAD_HEARTBEAT_VALUE (0xb7)141142/**143* struct ne_user_mem_region - User space memory region set for an enclave.144* @userspace_addr: Address of the user space memory region.145* @memory_size: Size of the user space memory region.146*/147struct ne_user_mem_region {148void *userspace_addr;149size_t memory_size;150};151152/**153* ne_create_vm() - Create a slot for the enclave VM.154* @ne_dev_fd: The file descriptor of the NE misc device.155* @slot_uid: The generated slot uid for the enclave.156* @enclave_fd : The generated file descriptor for the enclave.157*158* Context: Process context.159* Return:160* * 0 on success.161* * Negative return value on failure.162*/163static int ne_create_vm(int ne_dev_fd, unsigned long *slot_uid, int *enclave_fd)164{165int rc = -EINVAL;166*enclave_fd = ioctl(ne_dev_fd, NE_CREATE_VM, slot_uid);167168if (*enclave_fd < 0) {169rc = *enclave_fd;170switch (errno) {171case NE_ERR_NO_CPUS_AVAIL_IN_POOL: {172printf("Error in create VM, no CPUs available in the NE CPU pool\n");173174break;175}176177default:178printf("Error in create VM [%m]\n");179}180181return rc;182}183184return 0;185}186187/**188* ne_poll_enclave_fd() - Thread function for polling the enclave fd.189* @data: Argument provided for the polling function.190*191* Context: Process context.192* Return:193* * NULL on success / failure.194*/195void *ne_poll_enclave_fd(void *data)196{197int enclave_fd = *(int *)data;198struct pollfd fds[1] = {};199int i = 0;200int rc = -EINVAL;201202printf("Running from poll thread, enclave fd %d\n", enclave_fd);203204fds[0].fd = enclave_fd;205fds[0].events = POLLIN | POLLERR | POLLHUP;206207/* Keep on polling until the current process is terminated. */208while (1) {209printf("[iter %d] Polling ...\n", i);210211rc = poll(fds, 1, NE_POLL_WAIT_TIME_MS);212if (rc < 0) {213printf("Error in poll [%m]\n");214215return NULL;216}217218i++;219220if (!rc) {221printf("Poll: %d seconds elapsed\n",222i * NE_POLL_WAIT_TIME);223224continue;225}226227printf("Poll received value 0x%x\n", fds[0].revents);228229if (fds[0].revents & POLLHUP) {230printf("Received POLLHUP\n");231232return NULL;233}234235if (fds[0].revents & POLLNVAL) {236printf("Received POLLNVAL\n");237238return NULL;239}240}241242return NULL;243}244245/**246* ne_alloc_user_mem_region() - Allocate a user space memory region for an enclave.247* @ne_user_mem_region: User space memory region allocated using hugetlbfs.248*249* Context: Process context.250* Return:251* * 0 on success.252* * Negative return value on failure.253*/254static int ne_alloc_user_mem_region(struct ne_user_mem_region *ne_user_mem_region)255{256/**257* Check available hugetlb encodings for different huge page sizes in258* include/uapi/linux/mman.h.259*/260ne_user_mem_region->userspace_addr = mmap(NULL, ne_user_mem_region->memory_size,261PROT_READ | PROT_WRITE,262MAP_PRIVATE | MAP_ANONYMOUS |263MAP_HUGETLB | MAP_HUGE_2MB, -1, 0);264if (ne_user_mem_region->userspace_addr == MAP_FAILED) {265printf("Error in mmap memory [%m]\n");266267return -1;268}269270return 0;271}272273/**274* ne_load_enclave_image() - Place the enclave image in the enclave memory.275* @enclave_fd : The file descriptor associated with the enclave.276* @ne_user_mem_regions: User space memory regions allocated for the enclave.277* @enclave_image_path : The file path of the enclave image.278*279* Context: Process context.280* Return:281* * 0 on success.282* * Negative return value on failure.283*/284static int ne_load_enclave_image(int enclave_fd, struct ne_user_mem_region ne_user_mem_regions[],285char *enclave_image_path)286{287unsigned char *enclave_image = NULL;288int enclave_image_fd = -1;289size_t enclave_image_size = 0;290size_t enclave_memory_size = 0;291unsigned long i = 0;292size_t image_written_bytes = 0;293struct ne_image_load_info image_load_info = {294.flags = NE_EIF_IMAGE,295};296struct stat image_stat_buf = {};297int rc = -EINVAL;298size_t temp_image_offset = 0;299300for (i = 0; i < NE_DEFAULT_NR_MEM_REGIONS; i++)301enclave_memory_size += ne_user_mem_regions[i].memory_size;302303rc = stat(enclave_image_path, &image_stat_buf);304if (rc < 0) {305printf("Error in get image stat info [%m]\n");306307return rc;308}309310enclave_image_size = image_stat_buf.st_size;311312if (enclave_memory_size < enclave_image_size) {313printf("The enclave memory is smaller than the enclave image size\n");314315return -ENOMEM;316}317318rc = ioctl(enclave_fd, NE_GET_IMAGE_LOAD_INFO, &image_load_info);319if (rc < 0) {320switch (errno) {321case NE_ERR_NOT_IN_INIT_STATE: {322printf("Error in get image load info, enclave not in init state\n");323324break;325}326327case NE_ERR_INVALID_FLAG_VALUE: {328printf("Error in get image load info, provided invalid flag\n");329330break;331}332333default:334printf("Error in get image load info [%m]\n");335}336337return rc;338}339340printf("Enclave image offset in enclave memory is %lld\n",341image_load_info.memory_offset);342343enclave_image_fd = open(enclave_image_path, O_RDONLY);344if (enclave_image_fd < 0) {345printf("Error in open enclave image file [%m]\n");346347return enclave_image_fd;348}349350enclave_image = mmap(NULL, enclave_image_size, PROT_READ,351MAP_PRIVATE, enclave_image_fd, 0);352if (enclave_image == MAP_FAILED) {353printf("Error in mmap enclave image [%m]\n");354355return -1;356}357358temp_image_offset = image_load_info.memory_offset;359360for (i = 0; i < NE_DEFAULT_NR_MEM_REGIONS; i++) {361size_t bytes_to_write = 0;362size_t memory_offset = 0;363size_t memory_size = ne_user_mem_regions[i].memory_size;364size_t remaining_bytes = 0;365void *userspace_addr = ne_user_mem_regions[i].userspace_addr;366367if (temp_image_offset >= memory_size) {368temp_image_offset -= memory_size;369370continue;371} else if (temp_image_offset != 0) {372memory_offset = temp_image_offset;373memory_size -= temp_image_offset;374temp_image_offset = 0;375}376377remaining_bytes = enclave_image_size - image_written_bytes;378bytes_to_write = memory_size < remaining_bytes ?379memory_size : remaining_bytes;380381memcpy(userspace_addr + memory_offset,382enclave_image + image_written_bytes, bytes_to_write);383384image_written_bytes += bytes_to_write;385386if (image_written_bytes == enclave_image_size)387break;388}389390munmap(enclave_image, enclave_image_size);391392close(enclave_image_fd);393394return 0;395}396397/**398* ne_set_user_mem_region() - Set a user space memory region for the given enclave.399* @enclave_fd : The file descriptor associated with the enclave.400* @ne_user_mem_region : User space memory region to be set for the enclave.401*402* Context: Process context.403* Return:404* * 0 on success.405* * Negative return value on failure.406*/407static int ne_set_user_mem_region(int enclave_fd, struct ne_user_mem_region ne_user_mem_region)408{409struct ne_user_memory_region mem_region = {410.flags = NE_DEFAULT_MEMORY_REGION,411.memory_size = ne_user_mem_region.memory_size,412.userspace_addr = (__u64)ne_user_mem_region.userspace_addr,413};414int rc = -EINVAL;415416rc = ioctl(enclave_fd, NE_SET_USER_MEMORY_REGION, &mem_region);417if (rc < 0) {418switch (errno) {419case NE_ERR_NOT_IN_INIT_STATE: {420printf("Error in set user memory region, enclave not in init state\n");421422break;423}424425case NE_ERR_INVALID_MEM_REGION_SIZE: {426printf("Error in set user memory region, mem size not multiple of 2 MiB\n");427428break;429}430431case NE_ERR_INVALID_MEM_REGION_ADDR: {432printf("Error in set user memory region, invalid user space address\n");433434break;435}436437case NE_ERR_UNALIGNED_MEM_REGION_ADDR: {438printf("Error in set user memory region, unaligned user space address\n");439440break;441}442443case NE_ERR_MEM_REGION_ALREADY_USED: {444printf("Error in set user memory region, memory region already used\n");445446break;447}448449case NE_ERR_MEM_NOT_HUGE_PAGE: {450printf("Error in set user memory region, not backed by huge pages\n");451452break;453}454455case NE_ERR_MEM_DIFFERENT_NUMA_NODE: {456printf("Error in set user memory region, different NUMA node than CPUs\n");457458break;459}460461case NE_ERR_MEM_MAX_REGIONS: {462printf("Error in set user memory region, max memory regions reached\n");463464break;465}466467case NE_ERR_INVALID_PAGE_SIZE: {468printf("Error in set user memory region, has page not multiple of 2 MiB\n");469470break;471}472473case NE_ERR_INVALID_FLAG_VALUE: {474printf("Error in set user memory region, provided invalid flag\n");475476break;477}478479default:480printf("Error in set user memory region [%m]\n");481}482483return rc;484}485486return 0;487}488489/**490* ne_free_mem_regions() - Unmap all the user space memory regions that were set491* aside for the enclave.492* @ne_user_mem_regions: The user space memory regions associated with an enclave.493*494* Context: Process context.495*/496static void ne_free_mem_regions(struct ne_user_mem_region ne_user_mem_regions[])497{498unsigned int i = 0;499500for (i = 0; i < NE_DEFAULT_NR_MEM_REGIONS; i++)501munmap(ne_user_mem_regions[i].userspace_addr,502ne_user_mem_regions[i].memory_size);503}504505/**506* ne_add_vcpu() - Add a vCPU to the given enclave.507* @enclave_fd : The file descriptor associated with the enclave.508* @vcpu_id: vCPU id to be set for the enclave, either provided or509* auto-generated (if provided vCPU id is 0).510*511* Context: Process context.512* Return:513* * 0 on success.514* * Negative return value on failure.515*/516static int ne_add_vcpu(int enclave_fd, unsigned int *vcpu_id)517{518int rc = -EINVAL;519520rc = ioctl(enclave_fd, NE_ADD_VCPU, vcpu_id);521if (rc < 0) {522switch (errno) {523case NE_ERR_NO_CPUS_AVAIL_IN_POOL: {524printf("Error in add vcpu, no CPUs available in the NE CPU pool\n");525526break;527}528529case NE_ERR_VCPU_ALREADY_USED: {530printf("Error in add vcpu, the provided vCPU is already used\n");531532break;533}534535case NE_ERR_VCPU_NOT_IN_CPU_POOL: {536printf("Error in add vcpu, the provided vCPU is not in the NE CPU pool\n");537538break;539}540541case NE_ERR_VCPU_INVALID_CPU_CORE: {542printf("Error in add vcpu, the core id of the provided vCPU is invalid\n");543544break;545}546547case NE_ERR_NOT_IN_INIT_STATE: {548printf("Error in add vcpu, enclave not in init state\n");549550break;551}552553case NE_ERR_INVALID_VCPU: {554printf("Error in add vcpu, the provided vCPU is out of avail CPUs range\n");555556break;557}558559default:560printf("Error in add vcpu [%m]\n");561}562563return rc;564}565566return 0;567}568569/**570* ne_start_enclave() - Start the given enclave.571* @enclave_fd : The file descriptor associated with the enclave.572* @enclave_start_info : Enclave metadata used for starting e.g. vsock CID.573*574* Context: Process context.575* Return:576* * 0 on success.577* * Negative return value on failure.578*/579static int ne_start_enclave(int enclave_fd, struct ne_enclave_start_info *enclave_start_info)580{581int rc = -EINVAL;582583rc = ioctl(enclave_fd, NE_START_ENCLAVE, enclave_start_info);584if (rc < 0) {585switch (errno) {586case NE_ERR_NOT_IN_INIT_STATE: {587printf("Error in start enclave, enclave not in init state\n");588589break;590}591592case NE_ERR_NO_MEM_REGIONS_ADDED: {593printf("Error in start enclave, no memory regions have been added\n");594595break;596}597598case NE_ERR_NO_VCPUS_ADDED: {599printf("Error in start enclave, no vCPUs have been added\n");600601break;602}603604case NE_ERR_FULL_CORES_NOT_USED: {605printf("Error in start enclave, enclave has no full cores set\n");606607break;608}609610case NE_ERR_ENCLAVE_MEM_MIN_SIZE: {611printf("Error in start enclave, enclave memory is less than min size\n");612613break;614}615616case NE_ERR_INVALID_FLAG_VALUE: {617printf("Error in start enclave, provided invalid flag\n");618619break;620}621622case NE_ERR_INVALID_ENCLAVE_CID: {623printf("Error in start enclave, provided invalid enclave CID\n");624625break;626}627628default:629printf("Error in start enclave [%m]\n");630}631632return rc;633}634635return 0;636}637638/**639* ne_start_enclave_check_booted() - Start the enclave and wait for a heartbeat640* from it, on a newly created vsock channel,641* to check it has booted.642* @enclave_fd : The file descriptor associated with the enclave.643*644* Context: Process context.645* Return:646* * 0 on success.647* * Negative return value on failure.648*/649static int ne_start_enclave_check_booted(int enclave_fd)650{651struct sockaddr_vm client_vsock_addr = {};652int client_vsock_fd = -1;653socklen_t client_vsock_len = sizeof(client_vsock_addr);654struct ne_enclave_start_info enclave_start_info = {};655struct pollfd fds[1] = {};656int rc = -EINVAL;657unsigned char recv_buf = 0;658struct sockaddr_vm server_vsock_addr = {659.svm_family = AF_VSOCK,660.svm_cid = NE_IMAGE_LOAD_HEARTBEAT_CID,661.svm_port = NE_IMAGE_LOAD_HEARTBEAT_PORT,662};663int server_vsock_fd = -1;664665server_vsock_fd = socket(AF_VSOCK, SOCK_STREAM, 0);666if (server_vsock_fd < 0) {667rc = server_vsock_fd;668669printf("Error in socket [%m]\n");670671return rc;672}673674rc = bind(server_vsock_fd, (struct sockaddr *)&server_vsock_addr,675sizeof(server_vsock_addr));676if (rc < 0) {677printf("Error in bind [%m]\n");678679goto out;680}681682rc = listen(server_vsock_fd, 1);683if (rc < 0) {684printf("Error in listen [%m]\n");685686goto out;687}688689rc = ne_start_enclave(enclave_fd, &enclave_start_info);690if (rc < 0)691goto out;692693printf("Enclave started, CID %llu\n", enclave_start_info.enclave_cid);694695fds[0].fd = server_vsock_fd;696fds[0].events = POLLIN;697698rc = poll(fds, 1, NE_POLL_WAIT_TIME_MS);699if (rc < 0) {700printf("Error in poll [%m]\n");701702goto out;703}704705if (!rc) {706printf("Poll timeout, %d seconds elapsed\n", NE_POLL_WAIT_TIME);707708rc = -ETIMEDOUT;709710goto out;711}712713if ((fds[0].revents & POLLIN) == 0) {714printf("Poll received value %d\n", fds[0].revents);715716rc = -EINVAL;717718goto out;719}720721rc = accept(server_vsock_fd, (struct sockaddr *)&client_vsock_addr,722&client_vsock_len);723if (rc < 0) {724printf("Error in accept [%m]\n");725726goto out;727}728729client_vsock_fd = rc;730731/*732* Read the heartbeat value that the init process in the enclave sends733* after vsock connect.734*/735rc = read(client_vsock_fd, &recv_buf, sizeof(recv_buf));736if (rc < 0) {737printf("Error in read [%m]\n");738739goto out;740}741742if (rc != sizeof(recv_buf) || recv_buf != NE_IMAGE_LOAD_HEARTBEAT_VALUE) {743printf("Read %d instead of %d\n", recv_buf,744NE_IMAGE_LOAD_HEARTBEAT_VALUE);745746goto out;747}748749/* Write the heartbeat value back. */750rc = write(client_vsock_fd, &recv_buf, sizeof(recv_buf));751if (rc < 0) {752printf("Error in write [%m]\n");753754goto out;755}756757rc = 0;758759out:760close(server_vsock_fd);761762return rc;763}764765int main(int argc, char *argv[])766{767int enclave_fd = -1;768unsigned int i = 0;769int ne_dev_fd = -1;770struct ne_user_mem_region ne_user_mem_regions[NE_DEFAULT_NR_MEM_REGIONS] = {};771unsigned int ne_vcpus[NE_DEFAULT_NR_VCPUS] = {};772int rc = -EINVAL;773pthread_t thread_id = 0;774unsigned long slot_uid = 0;775776if (argc != 2) {777printf("Usage: %s <path_to_enclave_image>\n", argv[0]);778779exit(EXIT_FAILURE);780}781782if (strlen(argv[1]) >= PATH_MAX) {783printf("The size of the path to enclave image is higher than max path\n");784785exit(EXIT_FAILURE);786}787788ne_dev_fd = open(NE_DEV_NAME, O_RDWR | O_CLOEXEC);789if (ne_dev_fd < 0) {790printf("Error in open NE device [%m]\n");791792exit(EXIT_FAILURE);793}794795printf("Creating enclave slot ...\n");796797rc = ne_create_vm(ne_dev_fd, &slot_uid, &enclave_fd);798799close(ne_dev_fd);800801if (rc < 0)802exit(EXIT_FAILURE);803804printf("Enclave fd %d\n", enclave_fd);805806rc = pthread_create(&thread_id, NULL, ne_poll_enclave_fd, (void *)&enclave_fd);807if (rc < 0) {808printf("Error in thread create [%m]\n");809810close(enclave_fd);811812exit(EXIT_FAILURE);813}814815for (i = 0; i < NE_DEFAULT_NR_MEM_REGIONS; i++) {816ne_user_mem_regions[i].memory_size = NE_MIN_MEM_REGION_SIZE;817818rc = ne_alloc_user_mem_region(&ne_user_mem_regions[i]);819if (rc < 0) {820printf("Error in alloc userspace memory region, iter %d\n", i);821822goto release_enclave_fd;823}824}825826rc = ne_load_enclave_image(enclave_fd, ne_user_mem_regions, argv[1]);827if (rc < 0)828goto release_enclave_fd;829830for (i = 0; i < NE_DEFAULT_NR_MEM_REGIONS; i++) {831rc = ne_set_user_mem_region(enclave_fd, ne_user_mem_regions[i]);832if (rc < 0) {833printf("Error in set memory region, iter %d\n", i);834835goto release_enclave_fd;836}837}838839printf("Enclave memory regions were added\n");840841for (i = 0; i < NE_DEFAULT_NR_VCPUS; i++) {842/*843* The vCPU is chosen from the enclave vCPU pool, if the value844* of the vcpu_id is 0.845*/846ne_vcpus[i] = 0;847rc = ne_add_vcpu(enclave_fd, &ne_vcpus[i]);848if (rc < 0) {849printf("Error in add vcpu, iter %d\n", i);850851goto release_enclave_fd;852}853854printf("Added vCPU %d to the enclave\n", ne_vcpus[i]);855}856857printf("Enclave vCPUs were added\n");858859rc = ne_start_enclave_check_booted(enclave_fd);860if (rc < 0) {861printf("Error in the enclave start / image loading heartbeat logic [rc=%d]\n", rc);862863goto release_enclave_fd;864}865866printf("Entering sleep for %d seconds ...\n", NE_SLEEP_TIME);867868sleep(NE_SLEEP_TIME);869870close(enclave_fd);871872ne_free_mem_regions(ne_user_mem_regions);873874exit(EXIT_SUCCESS);875876release_enclave_fd:877close(enclave_fd);878ne_free_mem_regions(ne_user_mem_regions);879880exit(EXIT_FAILURE);881}882883884