int virtio_load(VirtIODevice *vdev, QEMUFile *f)

{

    int num, i, ret;

    uint32_t features;

    uint32_t supported_features =

        vdev->binding->get_features(vdev->binding_opaque);




    if (vdev->binding->load_config) {

        ret = vdev->binding->load_config(vdev->binding_opaque, f);

        if (ret)

            return ret;

    }



    qemu_get_8s(f, &vdev->status);

    qemu_get_8s(f, &vdev->isr);

    qemu_get_be16s(f, &vdev->queue_sel);

    qemu_get_be32s(f, &features);

    if (features & ~supported_features) {

        fprintf(stderr, "Features 0x%x unsupported. Allowed features: 0x%x\n",

                features, supported_features);

        return -1;

    }

    if (vdev->set_features)

        vdev->set_features(vdev, features);

    vdev->guest_features = features;

    vdev->config_len = qemu_get_be32(f);

    qemu_get_buffer(f, vdev->config, vdev->config_len);



    num = qemu_get_be32(f);



    for (i = 0; i < num; i++) {

        vdev->vq[i].vring.num = qemu_get_be32(f);

        vdev->vq[i].pa = qemu_get_be64(f);

        qemu_get_be16s(f, &vdev->vq[i].last_avail_idx);



        if (vdev->vq[i].pa) {

            virtqueue_init(&vdev->vq[i]);

        }

	num_heads = vring_avail_idx(&vdev->vq[i]) - vdev->vq[i].last_avail_idx;

	/* Check it isn't doing very strange things with descriptor numbers. */

	if (num_heads > vdev->vq[i].vring.num) {

		fprintf(stderr, "VQ %d size 0x%x Guest index 0x%x "

                        "inconsistent with Host index 0x%x: delta 0x%x\n",

			i, vdev->vq[i].vring.num,

                        vring_avail_idx(&vdev->vq[i]),

                        vdev->vq[i].last_avail_idx, num_heads);

		return -1;

	}

        if (vdev->binding->load_queue) {

            ret = vdev->binding->load_queue(vdev->binding_opaque, i, f);

            if (ret)

                return ret;

        }

    }



    virtio_notify_vector(vdev, VIRTIO_NO_VECTOR);

    return 0;

}
int virtio_load(VirtIODevice *vdev, QEMUFile *f)

{

    int num, i, ret;

    uint32_t features;

    uint32_t supported_features =

        vdev->binding->get_features(vdev->binding_opaque);




    if (vdev->binding->load_config) {

        ret = vdev->binding->load_config(vdev->binding_opaque, f);

        if (ret)

            return ret;

    }



    qemu_get_8s(f, &vdev->status);

    qemu_get_8s(f, &vdev->isr);

    qemu_get_be16s(f, &vdev->queue_sel);

    qemu_get_be32s(f, &features);

    if (features & ~supported_features) {

        fprintf(stderr, "Features 0x%x unsupported. Allowed features: 0x%x\n",

                features, supported_features);

        return -1;

    }

    if (vdev->set_features)

        vdev->set_features(vdev, features);

    vdev->guest_features = features;

    vdev->config_len = qemu_get_be32(f);

    qemu_get_buffer(f, vdev->config, vdev->config_len);



    num = qemu_get_be32(f);



    for (i = 0; i < num; i++) {

        vdev->vq[i].vring.num = qemu_get_be32(f);

        vdev->vq[i].pa = qemu_get_be64(f);

        qemu_get_be16s(f, &vdev->vq[i].last_avail_idx);



        if (vdev->vq[i].pa) {

            virtqueue_init(&vdev->vq[i]);

        }

	num_heads = vring_avail_idx(&vdev->vq[i]) - vdev->vq[i].last_avail_idx;

	

	if (num_heads > vdev->vq[i].vring.num) {

		fprintf(stderr, "VQ %d size 0x%x Guest index 0x%x "

                        "inconsistent with Host index 0x%x: delta 0x%x\n",

			i, vdev->vq[i].vring.num,

                        vring_avail_idx(&vdev->vq[i]),

                        vdev->vq[i].last_avail_idx, num_heads);

		return -1;

	}

        if (vdev->binding->load_queue) {

            ret = vdev->binding->load_queue(vdev->binding_opaque, i, f);

            if (ret)

                return ret;

        }

    }



    virtio_notify_vector(vdev, VIRTIO_NO_VECTOR);

    return 0;

}
int FUNC_0(VirtIODevice *VAR_0, QEMUFile *VAR_1)

{

    int VAR_2, VAR_3, VAR_4;

    uint32_t features;

    uint32_t supported_features =

        VAR_0->binding->get_features(VAR_0->binding_opaque);




    if (VAR_0->binding->load_config) {

        VAR_4 = VAR_0->binding->load_config(VAR_0->binding_opaque, VAR_1);

        if (VAR_4)

            return VAR_4;

    }



    qemu_get_8s(VAR_1, &VAR_0->status);

    qemu_get_8s(VAR_1, &VAR_0->isr);

    qemu_get_be16s(VAR_1, &VAR_0->queue_sel);

    qemu_get_be32s(VAR_1, &features);

    if (features & ~supported_features) {

        fprintf(stderr, "Features 0x%x unsupported. Allowed features: 0x%x\n",

                features, supported_features);

        return -1;

    }

    if (VAR_0->set_features)

        VAR_0->set_features(VAR_0, features);

    VAR_0->guest_features = features;

    VAR_0->config_len = qemu_get_be32(VAR_1);

    qemu_get_buffer(VAR_1, VAR_0->config, VAR_0->config_len);



    VAR_2 = qemu_get_be32(VAR_1);



    for (VAR_3 = 0; VAR_3 < VAR_2; VAR_3++) {

        VAR_0->vq[VAR_3].vring.VAR_2 = qemu_get_be32(VAR_1);

        VAR_0->vq[VAR_3].pa = qemu_get_be64(VAR_1);

        qemu_get_be16s(VAR_1, &VAR_0->vq[VAR_3].last_avail_idx);



        if (VAR_0->vq[VAR_3].pa) {

            virtqueue_init(&VAR_0->vq[VAR_3]);

        }

	num_heads = vring_avail_idx(&VAR_0->vq[VAR_3]) - VAR_0->vq[VAR_3].last_avail_idx;

	

	if (num_heads > VAR_0->vq[VAR_3].vring.VAR_2) {

		fprintf(stderr, "VQ %d size 0x%x Guest index 0x%x "

                        "inconsistent with Host index 0x%x: delta 0x%x\n",

			VAR_3, VAR_0->vq[VAR_3].vring.VAR_2,

                        vring_avail_idx(&VAR_0->vq[VAR_3]),

                        VAR_0->vq[VAR_3].last_avail_idx, num_heads);

		return -1;

	}

        if (VAR_0->binding->load_queue) {

            VAR_4 = VAR_0->binding->load_queue(VAR_0->binding_opaque, VAR_3, VAR_1);

            if (VAR_4)

                return VAR_4;

        }

    }



    virtio_notify_vector(VAR_0, VIRTIO_NO_VECTOR);

    return 0;

}
int FUNC_0(VirtIODevice *VAR_0, QEMUFile *VAR_1)
{ int VAR_2, VAR_3, VAR_4; uint32_t features; uint32_t supported_features =
VAR_0->binding->get_features(VAR_0->binding_opaque); if (VAR_0->binding->load_config) { VAR_4 = VAR_0->binding->load_config(VAR_0->binding_opaque, VAR_1); if (VAR_4)
return VAR_4; } qemu_get_8s(VAR_1, &VAR_0->status); qemu_get_8s(VAR_1, &VAR_0->isr); qemu_get_be16s(VAR_1, &VAR_0->queue_sel); qemu_get_be32s(VAR_1, &features); if (features & ~supported_features) { fprintf(stderr, "Features 0x%x unsupported. Allowed features: 0x%x\n",
features, supported_features); return -1; } if (VAR_0->set_features)
VAR_0->set_features(VAR_0, features); VAR_0->guest_features = features; VAR_0->config_len = qemu_get_be32(VAR_1); qemu_get_buffer(VAR_1, VAR_0->config, VAR_0->config_len); VAR_2 = qemu_get_be32(VAR_1); for (VAR_3 = 0; VAR_3 < VAR_2; VAR_3++) { VAR_0->vq[VAR_3].vring.VAR_2 = qemu_get_be32(VAR_1); VAR_0->vq[VAR_3].pa = qemu_get_be64(VAR_1); qemu_get_be16s(VAR_1, &VAR_0->vq[VAR_3].last_avail_idx); if (VAR_0->vq[VAR_3].pa) { virtqueue_init(&VAR_0->vq[VAR_3]); } num_heads = vring_avail_idx(&VAR_0->vq[VAR_3]) - VAR_0->vq[VAR_3].last_avail_idx; if (num_heads > VAR_0->vq[VAR_3].vring.VAR_2) { fprintf(stderr, "VQ %d size 0x%x Guest index 0x%x "
"inconsistent with Host index 0x%x: delta 0x%x\n",
VAR_3, VAR_0->vq[VAR_3].vring.VAR_2,
vring_avail_idx(&VAR_0->vq[VAR_3]),
VAR_0->vq[VAR_3].last_avail_idx, num_heads); return -1; } if (VAR_0->binding->load_queue) { VAR_4 = VAR_0->binding->load_queue(VAR_0->binding_opaque, VAR_3, VAR_1); if (VAR_4)
return VAR_4; } } virtio_notify_vector(VAR_0, VIRTIO_NO_VECTOR); return 0; }