Exemplo n.º 1
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;
}
Exemplo n.º 2
0
Arquivo: init.c Projeto: Fantu/Xen
struct libxenvchan *libxenvchan_server_init(xentoollog_logger *logger, int domain, const char* xs_path, size_t left_min, size_t right_min)
{
	struct libxenvchan *ctrl;
	int ring_ref;
	if (left_min > MAX_RING_SIZE || right_min > MAX_RING_SIZE)
		return 0;

	ctrl = malloc(sizeof(*ctrl));
	if (!ctrl)
		return 0;

	ctrl->ring = NULL;
	ctrl->event = NULL;
	ctrl->is_server = 1;
	ctrl->server_persist = 0;

	ctrl->read.order = min_order(left_min);
	ctrl->write.order = min_order(right_min);

	// if we can avoid allocating extra pages by using in-page rings, do so
	if (left_min <= MAX_SMALL_RING && right_min <= MAX_LARGE_RING) {
		ctrl->read.order = SMALL_RING_SHIFT;
		ctrl->write.order = LARGE_RING_SHIFT;
	} else if (left_min <= MAX_LARGE_RING && right_min <= MAX_SMALL_RING) {
		ctrl->read.order = LARGE_RING_SHIFT;
		ctrl->write.order = SMALL_RING_SHIFT;
	} else if (left_min <= MAX_LARGE_RING) {
		ctrl->read.order = LARGE_RING_SHIFT;
	} else if (right_min <= MAX_LARGE_RING) {
		ctrl->write.order = LARGE_RING_SHIFT;
	}

	ctrl->gntshr = xc_gntshr_open(logger, 0);
	if (!ctrl->gntshr)
		goto out;

	if (init_evt_srv(ctrl, domain, logger))
		goto out;
	ring_ref = init_gnt_srv(ctrl, domain);
	if (ring_ref < 0)
		goto out;
	if (init_xs_srv(ctrl, domain, xs_path, ring_ref))
		goto out;
	return ctrl;
out:
	libxenvchan_close(ctrl);
	return 0;
}
CAMLprim value stub_xc_gntshr_open(void)
{
	CAMLparam0();
	CAMLlocal1(result);
#ifdef HAVE_GNTSHR
	xc_gntshr *xgh;

	xgh = xc_gntshr_open(NULL, 0);
	if (NULL == xgh)
		failwith_xc(NULL);
	result = (value)xgh;
#else
	gntshr_missing();
#endif
	CAMLreturn(result);
}
Exemplo n.º 4
0
CAMLprim value stub_gntshr_open(value unit)
{
	CAMLparam1(unit);
	CAMLlocal1(result);
#ifdef HAVE_GNTSHR
	xc_gntshr *xgh;

	xgh = xc_gntshr_open(NULL, 0);
	if (NULL == xgh)
		caml_failwith("Failed to open interface");
	result = (value)xgh;
#else
	gntshr_missing();
#endif
	CAMLreturn(result);
}
Exemplo n.º 5
0
/* 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;
}