static void *framebuffer_grant_test(uint32_t domid, uint32_t num_pages) { xc_gnttab *xcg; int i = 0; uint32_t refs[2560]; void *p; memset(refs, 0, 2560*sizeof(uint32_t)); xcg = xc_gnttab_open(NULL, 0); if ( !xcg ) { printf("Failed to open grant device, dying.\n"); return; } for (i = 0; i < num_pages; i++) { refs[i] = i; } p = xc_gnttab_map_domain_grant_refs(xcg, num_pages, domid, refs, PROT_READ); if ( p ) { printf("Mapped %d refs, ptr: %p\n", i, p); } else { printf("Failed to map at ref: %d\n", 0); abort(); } xc_gnttab_close(xcg); return p; }
CAMLprim value stub_gnttab_interface_open(void) { CAMLparam0(); xc_gnttab *xgh; xgh = xc_gnttab_open(NULL, 0); if (xgh == NULL) caml_failwith("Failed to open interface"); CAMLreturn((value)xgh); }
int main(int argc, char **argv) { struct event xs_event, xs_back_event; int xs_fd, xs_back_fd; if (argc != 1) return 1; /* Globals init */ xcg_handle = NULL; /* Initialize XenStore */ xs_fd = superxenstore_init(); if (xs_fd < 0) return 1; /* Initialize gnttab */ if (xcg_handle == NULL) { xcg_handle = xc_gnttab_open(NULL, 0); } if (xcg_handle == NULL) { superlog(LOG_ERR, "Failed to connect to xc"); return 1; } /* Initialize SuperHID */ superhid_init(); /* Initialize the backend */ xs_back_fd = superbackend_init(); input_grabber = -1; event_init(); event_set(&xs_event, xs_fd, EV_READ | EV_PERSIST, xenstore_handler, NULL); event_add(&xs_event, NULL); event_set(&xs_back_event, xs_back_fd, EV_READ | EV_PERSIST, xenstore_back_handler, NULL); event_add(&xs_back_event, NULL); event_dispatch(); /* Cleanup */ superxenstore_close(); xc_gnttab_close(xcg_handle); return 0; }
libIVC_t *openIVCLibrary() { libIVC_t *retval; assert( retval = calloc(1, sizeof(struct libIVC_interface)) ); assert( retval->xc = xc_interface_open(NULL, NULL, 0) ); assert( retval->xs = xs_open(0) ); assert( retval->ec = xc_evtchn_open(NULL, 0) ); assert( retval->gt = xc_gnttab_open(NULL, 0) ); #ifdef HAVE_XENSTORE_H retval->gs = xc_gntshr_open(NULL, 0); /* may not be available on all plats */ #endif return retval; }
struct libxenvchan *libxenvchan_client_init(xentoollog_logger *logger, int domain, const char* xs_path) { struct libxenvchan *ctrl = malloc(sizeof(struct libxenvchan)); struct xs_handle *xs = NULL; char buf[64]; char *ref; int ring_ref; unsigned int len; if (!ctrl) return 0; ctrl->ring = NULL; ctrl->event = NULL; ctrl->gnttab = NULL; ctrl->write.order = ctrl->read.order = 0; ctrl->is_server = 0; xs = xs_daemon_open(); if (!xs) xs = xs_domain_open(); if (!xs) goto fail; // find xenstore entry snprintf(buf, sizeof buf, "%s/ring-ref", xs_path); ref = xs_read(xs, 0, buf, &len); if (!ref) goto fail; ring_ref = atoi(ref); free(ref); if (!ring_ref) goto fail; snprintf(buf, sizeof buf, "%s/event-channel", xs_path); ref = xs_read(xs, 0, buf, &len); if (!ref) goto fail; ctrl->event_port = atoi(ref); free(ref); if (!ctrl->event_port) goto fail; ctrl->gnttab = xc_gnttab_open(logger, 0); if (!ctrl->gnttab) goto fail; // set up event channel if (init_evt_cli(ctrl, domain, logger)) goto fail; // set up shared page(s) if (init_gnt_cli(ctrl, domain, ring_ref)) goto fail; ctrl->ring->cli_live = 1; ctrl->ring->srv_notify = VCHAN_NOTIFY_WRITE; out: if (xs) xs_daemon_close(xs); return ctrl; fail: libxenvchan_close(ctrl); ctrl = NULL; goto out; }
/* Open an interface to gntshr or gnttab each time it is needed. */ int test_open_multiple() { xc_gntshr *gntshr_if; xc_gnttab *gnttab_if; uint32_t refs[PAGE_COUNT]; uint32_t domids[PAGE_COUNT]; void* local_share; void* remote_share; int i; int err; gntshr_if = xc_gntshr_open(NULL, 0); if(!gntshr_if) { printf("Failed to open gntshr interface.\n"); return 1; } gnttab_if = xc_gnttab_open(NULL, 0); if(!gnttab_if) { printf("Failed to open gnttab interface.\n"); return 1; } local_share = xc_gntshr_share_pages(gntshr_if, DOMID, PAGE_COUNT, refs, 0); if(!local_share) { printf("Failed to share memory.\n"); return 1; } for(i = 0; i < PAGE_COUNT; i++) { printf("Sharing page with ref %d.\n", refs[i]); } for(i = 0; i < PAGE_COUNT; i++) { domids[i] = DOMID; } remote_share = xc_gnttab_map_grant_refs( gnttab_if, PAGE_COUNT, domids, refs, PROT_READ); if(!remote_share) { printf("Failed to map memory.\n"); return 1; } if(xc_gntshr_close(gntshr_if)) { printf("Failed to close gntshr interface.\n"); return 1; } if(xc_gnttab_close(gnttab_if)) { printf("Failed to close gnttab interface.\n"); return 1; } gntshr_if = xc_gntshr_open(NULL, 0); if(!gntshr_if) { printf("Failed to open gntshr interface.\n"); return 1; } gnttab_if = xc_gnttab_open(NULL, 0); if(!gnttab_if) { printf("Failed to open gnttab interface.\n"); return 1; } err = xc_gnttab_munmap(gnttab_if, remote_share, 1); if(err) { printf("Failed to unmap memory - got error code %d.\n", err); return 1; } err = xc_gntshr_munmap(gntshr_if, local_share, 1); if(err) { printf("Failed to unshare memory - got error code %d.\n", err); return 1; } if(xc_gntshr_close(gntshr_if)) { printf("Failed to close gntshr interface.\n"); return 1; } if(xc_gnttab_close(gnttab_if)) { printf("Failed to close gnttab interface.\n"); return 1; } return 0; }