struct xc_interface_core *xc_interface_open(xentoollog_logger *logger, xentoollog_logger *dombuild_logger, unsigned open_flags) { struct xc_interface_core xch_buf = { 0 }, *xch = &xch_buf; xch->flags = open_flags; xch->dombuild_logger_file = 0; xc_clear_last_error(xch); xch->error_handler = logger; xch->error_handler_tofree = 0; xch->dombuild_logger = dombuild_logger; xch->dombuild_logger_tofree = 0; if (!xch->error_handler) { xch->error_handler = xch->error_handler_tofree = (xentoollog_logger*) xtl_createlogger_stdiostream(stderr, XTL_PROGRESS, 0); if (!xch->error_handler) goto err; } xch = malloc(sizeof(*xch)); if (!xch) { xch = &xch_buf; PERROR("Could not allocate new xc_interface struct"); goto err; } *xch = xch_buf; if (open_flags & XC_OPENFLAG_DUMMY) return xch; /* We are done */ xch->xcall = xencall_open(xch->error_handler, open_flags & XC_OPENFLAG_NON_REENTRANT ? XENCALL_OPENFLAG_NON_REENTRANT : 0U); if ( xch->xcall == NULL ) goto err; xch->fmem = xenforeignmemory_open(xch->error_handler, 0); if ( xch->fmem == NULL ) goto err; xch->dmod = xendevicemodel_open(xch->error_handler, 0); if ( xch->dmod == NULL ) goto err; return xch; err: xenforeignmemory_close(xch->fmem); xencall_close(xch->xcall); xtl_logger_destroy(xch->error_handler_tofree); if (xch != &xch_buf) free(xch); return NULL; }
int xendevicemodel_close(xendevicemodel_handle *dmod) { int rc; if (!dmod) return 0; rc = osdep_xendevicemodel_close(dmod); xencall_close(dmod->xcall); xtl_logger_destroy(dmod->logger_tofree); free(dmod); return rc; }
int xc_interface_close(xc_interface *xch) { int rc = 0; if (!xch) return 0; rc = xencall_close(xch->xcall); if (rc) PERROR("Could not close xencall interface"); rc = xenforeignmemory_close(xch->fmem); if (rc) PERROR("Could not close foreign memory interface"); rc = xendevicemodel_close(xch->dmod); if (rc) PERROR("Could not close device model interface"); xtl_logger_destroy(xch->dombuild_logger_tofree); xtl_logger_destroy(xch->error_handler_tofree); free(xch); return rc; }
xendevicemodel_handle *xendevicemodel_open(xentoollog_logger *logger, unsigned open_flags) { xendevicemodel_handle *dmod = calloc(1, sizeof(*dmod)); int rc; if (!dmod) return NULL; dmod->flags = open_flags; dmod->logger = logger; dmod->logger_tofree = NULL; if (!dmod->logger) { dmod->logger = dmod->logger_tofree = (xentoollog_logger*) xtl_createlogger_stdiostream(stderr, XTL_PROGRESS, 0); if (!dmod->logger) goto err; } dmod->xcall = xencall_open(dmod->logger, 0); if (!dmod->xcall) goto err; rc = osdep_xendevicemodel_open(dmod); if (rc) goto err; return dmod; err: xtl_logger_destroy(dmod->logger_tofree); xencall_close(dmod->xcall); free(dmod); return NULL; }