int virtio_gpu_create_mapping_iov(struct virtio_gpu_resource_attach_backing *ab,

                                  struct virtio_gpu_ctrl_command *cmd,

                                  struct iovec **iov)

{

    struct virtio_gpu_mem_entry *ents;

    size_t esize, s;

    int i;



    if (ab->nr_entries > 16384) {

        qemu_log_mask(LOG_GUEST_ERROR,

                      "%s: nr_entries is too big (%d > 16384)\n",

                      __func__, ab->nr_entries);

        return -1;

    }



    esize = sizeof(*ents) * ab->nr_entries;

    ents = g_malloc(esize);

    s = iov_to_buf(cmd->elem.out_sg, cmd->elem.out_num,

                   sizeof(*ab), ents, esize);

    if (s != esize) {

        qemu_log_mask(LOG_GUEST_ERROR,

                      "%s: command data size incorrect %zu vs %zu\n",

                      __func__, s, esize);

        g_free(ents);

        return -1;

    }



    *iov = g_malloc0(sizeof(struct iovec) * ab->nr_entries);

    for (i = 0; i < ab->nr_entries; i++) {

        hwaddr len = ents[i].length;

        (*iov)[i].iov_len = ents[i].length;

        (*iov)[i].iov_base = cpu_physical_memory_map(ents[i].addr, &len, 1);

        if (!(*iov)[i].iov_base || len != ents[i].length) {

            qemu_log_mask(LOG_GUEST_ERROR, "%s: failed to map MMIO memory for"

                          " resource %d element %d\n",

                          __func__, ab->resource_id, i);

            virtio_gpu_cleanup_mapping_iov(*iov, i);

            g_free(ents);

            g_free(*iov);

            *iov = NULL;

            return -1;

        }

    }

    g_free(ents);

    return 0;

}

int virtio_gpu_create_mapping_iov(struct virtio_gpu_resource_attach_backing *ab,

                                  struct virtio_gpu_ctrl_command *cmd,

                                  struct iovec **iov)

{

    struct virtio_gpu_mem_entry *ents;

    size_t esize, s;

    int i;



    if (ab->nr_entries > 16384) {

        qemu_log_mask(LOG_GUEST_ERROR,

                      "%s: nr_entries is too big (%d > 16384)\n",

                      __func__, ab->nr_entries);

        return -1;

    }



    esize = sizeof(*ents) * ab->nr_entries;

    ents = g_malloc(esize);

    s = iov_to_buf(cmd->elem.out_sg, cmd->elem.out_num,

                   sizeof(*ab), ents, esize);

    if (s != esize) {

        qemu_log_mask(LOG_GUEST_ERROR,

                      "%s: command data size incorrect %zu vs %zu\n",

                      __func__, s, esize);

        g_free(ents);

        return -1;

    }



    *iov = g_malloc0(sizeof(struct iovec) * ab->nr_entries);

    for (i = 0; i < ab->nr_entries; i++) {

        hwaddr len = ents[i].length;

        (*iov)[i].iov_len = ents[i].length;

        (*iov)[i].iov_base = cpu_physical_memory_map(ents[i].addr, &len, 1);

        if (!(*iov)[i].iov_base || len != ents[i].length) {

            qemu_log_mask(LOG_GUEST_ERROR, "%s: failed to map MMIO memory for"

                          " resource %d element %d\n",

                          __func__, ab->resource_id, i);

            virtio_gpu_cleanup_mapping_iov(*iov, i);

            g_free(ents);

            g_free(*iov);

            *iov = NULL;

            return -1;

        }

    }

    g_free(ents);

    return 0;

}

            g_free(*iov);
int FUNC_0(struct virtio_gpu_resource_attach_backing *VAR_0,

                                  struct virtio_gpu_ctrl_command *VAR_1,

                                  struct iovec **VAR_2)

{

    struct virtio_gpu_mem_entry *VAR_3;

    size_t esize, s;

    int VAR_4;



    if (VAR_0->nr_entries > 16384) {

        qemu_log_mask(LOG_GUEST_ERROR,

                      "%s: nr_entries is too big (%d > 16384)\n",

                      __func__, VAR_0->nr_entries);

        return -1;

    }



    esize = sizeof(*VAR_3) * VAR_0->nr_entries;

    VAR_3 = g_malloc(esize);

    s = iov_to_buf(VAR_1->elem.out_sg, VAR_1->elem.out_num,

                   sizeof(*VAR_0), VAR_3, esize);

    if (s != esize) {

        qemu_log_mask(LOG_GUEST_ERROR,

                      "%s: command data size incorrect %zu vs %zu\n",

                      __func__, s, esize);

        g_free(VAR_3);

        return -1;

    }



    *VAR_2 = g_malloc0(sizeof(struct iovec) * VAR_0->nr_entries);

    for (VAR_4 = 0; VAR_4 < VAR_0->nr_entries; VAR_4++) {

        hwaddr len = VAR_3[VAR_4].length;

        (*VAR_2)[VAR_4].iov_len = VAR_3[VAR_4].length;

        (*VAR_2)[VAR_4].iov_base = cpu_physical_memory_map(VAR_3[VAR_4].addr, &len, 1);

        if (!(*VAR_2)[VAR_4].iov_base || len != VAR_3[VAR_4].length) {

            qemu_log_mask(LOG_GUEST_ERROR, "%s: failed to map MMIO memory for"

                          " resource %d element %d\n",

                          __func__, VAR_0->resource_id, VAR_4);

            virtio_gpu_cleanup_mapping_iov(*VAR_2, VAR_4);

            g_free(VAR_3);

            g_free(*VAR_2);

            *VAR_2 = NULL;

            return -1;

        }

    }

    g_free(VAR_3);

    return 0;

}

int FUNC_0(struct virtio_gpu_resource_attach_backing *VAR_0,
struct virtio_gpu_ctrl_command *VAR_1,
struct iovec **VAR_2)
{ struct virtio_gpu_mem_entry *VAR_3; size_t esize, s; int VAR_4; if (VAR_0->nr_entries > 16384) { qemu_log_mask(LOG_GUEST_ERROR,
"%s: nr_entries is too big (%d > 16384)\n",
__func__, VAR_0->nr_entries); return -1; } esize = sizeof(*VAR_3) * VAR_0->nr_entries; VAR_3 = g_malloc(esize); s = iov_to_buf(VAR_1->elem.out_sg, VAR_1->elem.out_num,
sizeof(*VAR_0), VAR_3, esize); if (s != esize) { qemu_log_mask(LOG_GUEST_ERROR,
"%s: command data size incorrect %zu vs %zu\n",
__func__, s, esize); g_free(VAR_3); return -1; } *VAR_2 = g_malloc0(sizeof(struct iovec) * VAR_0->nr_entries); for (VAR_4 = 0; VAR_4 < VAR_0->nr_entries; VAR_4++) { hwaddr len = VAR_3[VAR_4].length; (*VAR_2)[VAR_4].iov_len = VAR_3[VAR_4].length; (*VAR_2)[VAR_4].iov_base = cpu_physical_memory_map(VAR_3[VAR_4].addr, &len, 1); if (!(*VAR_2)[VAR_4].iov_base || len != VAR_3[VAR_4].length) { qemu_log_mask(LOG_GUEST_ERROR, "%s: failed to map MMIO memory for"
" resource %d element %d\n",
__func__, VAR_0->resource_id, VAR_4); virtio_gpu_cleanup_mapping_iov(*VAR_2, VAR_4); g_free(VAR_3); g_free(*VAR_2); *VAR_2 = NULL; return -1; } } g_free(VAR_3); return 0; }