Exemplo n.º 1
0
int
android_charmap_setup(const char* kcm_file_path) {
    // android_charmap_count being non-zero is used here as a flag,
    //  indicating that charmap has been initialized for the running
    // executable.
    if (android_charmap_count != 0) {
        return 0;
    }

    if (NULL != kcm_file_path) {
        if (!parse_kcm_file(kcm_file_path, &android_custom_charmap)) {
            // Here we have two default charmaps and the custom one.
            android_charmap_count = 3;
            android_charmaps = qemu_malloc(sizeof(AKeyCharmap*) *
                                           android_charmap_count);
            android_charmaps[0] = &android_custom_charmap;
            android_charmaps[1] = &_qwerty_charmap;
            android_charmaps[2] = &_qwerty2_charmap;
        } else {
            derror("Unable to parse kcm file.");
            return -1;
        }
    } else {
        // Here we have only two default charmaps.
        android_charmap_count = 2;
        android_charmaps = qemu_malloc(sizeof(AKeyCharmap*) *
                           android_charmap_count);
        android_charmaps[0] = &_qwerty_charmap;
        android_charmaps[1] = &_qwerty2_charmap;
    }

    return 0;
}
Exemplo n.º 2
0
int
android_charmap_setup(const char* kcm_file_path) {
    if (NULL != kcm_file_path) {
        if (!parse_kcm_file(kcm_file_path, &android_custom_charmap)) {
            // Here we have two default charmaps and the custom one.
            android_charmap_count = 3;
            android_charmaps = qemu_malloc(sizeof(AKeyCharmap*) *
                                           android_charmap_count);
            android_charmaps[0] = &android_custom_charmap;
            android_charmaps[1] = &_qwerty_charmap;
            android_charmaps[2] = &_qwerty2_charmap;
        } else {
            derror("Unable to parse kcm file.");
            return -1;
        }
    } else {
        // Here we have only two default charmaps.
        android_charmap_count = 2;
        android_charmaps = qemu_malloc(sizeof(AKeyCharmap*) *
                           android_charmap_count);
        android_charmaps[0] = &_qwerty_charmap;
        android_charmaps[1] = &_qwerty2_charmap;
    }

    return 0;
}
Exemplo n.º 3
0
int qcow2_read_snapshots(BlockDriverState *bs)
{
    BDRVQcowState *s = bs->opaque;
    QCowSnapshotHeader h;
    QCowSnapshot *sn;
    int i, id_str_size, name_size;
    int64_t offset;
    uint32_t extra_data_size;

    if (!s->nb_snapshots) {
        s->snapshots = NULL;
        s->snapshots_size = 0;
        return 0;
    }

    offset = s->snapshots_offset;
    s->snapshots = qemu_mallocz(s->nb_snapshots * sizeof(QCowSnapshot));
    for(i = 0; i < s->nb_snapshots; i++) {
        offset = align_offset(offset, 8);
        if (bdrv_pread(s->hd, offset, &h, sizeof(h)) != sizeof(h))
            goto fail;
        offset += sizeof(h);
        sn = s->snapshots + i;
        sn->l1_table_offset = be64_to_cpu(h.l1_table_offset);
        sn->l1_size = be32_to_cpu(h.l1_size);
        sn->vm_state_size = be32_to_cpu(h.vm_state_size);
        sn->date_sec = be32_to_cpu(h.date_sec);
        sn->date_nsec = be32_to_cpu(h.date_nsec);
        sn->vm_clock_nsec = be64_to_cpu(h.vm_clock_nsec);
        extra_data_size = be32_to_cpu(h.extra_data_size);

        id_str_size = be16_to_cpu(h.id_str_size);
        name_size = be16_to_cpu(h.name_size);

        offset += extra_data_size;

        sn->id_str = qemu_malloc(id_str_size + 1);
        if (bdrv_pread(s->hd, offset, sn->id_str, id_str_size) != id_str_size)
            goto fail;
        offset += id_str_size;
        sn->id_str[id_str_size] = '\0';

        sn->name = qemu_malloc(name_size + 1);
        if (bdrv_pread(s->hd, offset, sn->name, name_size) != name_size)
            goto fail;
        offset += name_size;
        sn->name[name_size] = '\0';
    }
    s->snapshots_size = offset - s->snapshots_offset;
    return 0;
 fail:
    qcow2_free_snapshots(bs);
    return -1;
}
Exemplo n.º 4
0
/*
 * allocate the set of arrays for certs, cert_len, key
 */
static PRBool
vcard_emul_alloc_arrays(unsigned char ***certsp, int **cert_lenp,
                        VCardKey ***keysp, int cert_count)
{
    *certsp = NULL;
    *cert_lenp = NULL;
    *keysp = NULL;
    *certsp = (unsigned char **)qemu_malloc(sizeof(unsigned char *)*cert_count);
    *cert_lenp = (int *)qemu_malloc(sizeof(int)*cert_count);
    *keysp = (VCardKey **)qemu_malloc(sizeof(VCardKey *)*cert_count);
    return PR_TRUE;
}
Exemplo n.º 5
0
void *qemu_realloc(void *ptr, size_t size)
{
    size_t old_size, copy;
    void *new_ptr;

    if (!ptr)
        return qemu_malloc(size);
    old_size = *(size_t *)((char *)ptr - 16);
    copy = old_size < size ? old_size : size;
    new_ptr = qemu_malloc(size);
    memcpy(new_ptr, ptr, copy);
    qemu_free(ptr);
    return new_ptr;
}
Exemplo n.º 6
0
static int cloop_open(BlockDriverState *bs, const char *filename, int flags)
{
    BDRVCloopState *s = bs->opaque;
    uint32_t offsets_size,max_compressed_block_size=1,i;

    s->fd = open(filename, O_RDONLY | O_BINARY);
    if (s->fd < 0)
        return -errno;
    bs->read_only = 1;

    /* read header */
    if(lseek(s->fd,128,SEEK_SET)<0) {
cloop_close:
        close(s->fd);
        return -1;
    }
    if(qemu_read_ok(s->fd,&s->block_size,4)<0)
        goto cloop_close;
    s->block_size=be32_to_cpu(s->block_size);
    if(qemu_read_ok(s->fd,&s->n_blocks,4)<0)
        goto cloop_close;
    s->n_blocks=be32_to_cpu(s->n_blocks);

    /* read offsets */
    offsets_size=s->n_blocks*sizeof(uint64_t);
    if(!(s->offsets=(uint64_t*)malloc(offsets_size)))
        goto cloop_close;
    if(read(s->fd,s->offsets,offsets_size)<offsets_size)
        goto cloop_close;
    for(i=0; i<s->n_blocks; i++) {
        s->offsets[i]=be64_to_cpu(s->offsets[i]);
        if(i>0) {
            uint32_t size=s->offsets[i]-s->offsets[i-1];
            if(size>max_compressed_block_size)
                max_compressed_block_size=size;
        }
    }

    /* initialize zlib engine */
    s->compressed_block = qemu_malloc(max_compressed_block_size+1);
    s->uncompressed_block = qemu_malloc(s->block_size);
    if(inflateInit(&s->zstream) != Z_OK)
        goto cloop_close;
    s->current_block=s->n_blocks;

    s->sectors_per_block = s->block_size/512;
    bs->total_sectors = s->n_blocks*s->sectors_per_block;
    return 0;
}
Exemplo n.º 7
0
static int cloop_open(BlockDriverState *bs, int flags)
{
    BDRVCloopState *s = bs->opaque;
    uint32_t offsets_size,max_compressed_block_size=1,i;

    bs->read_only = 1;

    
    if (bdrv_pread(bs->file, 128, &s->block_size, 4) < 4) {
        goto cloop_close;
    }
    s->block_size = be32_to_cpu(s->block_size);

    if (bdrv_pread(bs->file, 128 + 4, &s->n_blocks, 4) < 4) {
        goto cloop_close;
    }
    s->n_blocks = be32_to_cpu(s->n_blocks);

    
    offsets_size = s->n_blocks * sizeof(uint64_t);
    s->offsets = qemu_malloc(offsets_size);
    if (bdrv_pread(bs->file, 128 + 4 + 4, s->offsets, offsets_size) <
            offsets_size) {
	goto cloop_close;
    }
    for(i=0;i<s->n_blocks;i++) {
	s->offsets[i]=be64_to_cpu(s->offsets[i]);
	if(i>0) {
	    uint32_t size=s->offsets[i]-s->offsets[i-1];
	    if(size>max_compressed_block_size)
		max_compressed_block_size=size;
	}
    }

    
    s->compressed_block = qemu_malloc(max_compressed_block_size+1);
    s->uncompressed_block = qemu_malloc(s->block_size);
    if(inflateInit(&s->zstream) != Z_OK)
	goto cloop_close;
    s->current_block=s->n_blocks;

    s->sectors_per_block = s->block_size/512;
    bs->total_sectors = s->n_blocks*s->sectors_per_block;
    return 0;

cloop_close:
    return -1;
}
Exemplo n.º 8
0
void preLinuxRead(CPUX86State *env, void* user_data)
{
	uint32_t FileDescriptor, ReadBuffer, ReadSize;
	target_ulong ret_addr;
	PLinuxReadWriteData pReadData;

	// get file handle, buffer & buffer size from stack
    qebek_read_ulong(env, env->regs[R_ESP] + 4, &FileDescriptor); //WASIF:Q what does this do?
    qebek_read_ulong(env, env->regs[R_ESP] + 8, &ReadBuffer);
    qebek_read_ulong(env, env->regs[R_ESP] + 12, &ReadSize);

	//fprintf(stderr, "preLinuxRead: FileDescriptor %08x, Buffer %08x, Size %08x\n", FileDescriptor, ReadBuffer, ReadSize);

	if(FileDescriptor == 0x00){
		pReadData = (PLinuxReadWriteData)qemu_malloc(sizeof(LinuxReadWriteData));
		if(pReadData != NULL)
		{
			pReadData->FileDescriptor = FileDescriptor;
			pReadData->BufferAddr = ReadBuffer;
			pReadData->BufferSize = ReadSize;
		}

		// set return address, so the VM will break when returned
		qebek_read_ulong(env, env->regs[R_ESP], &ret_addr);
		if(!qebek_bp_add(ret_addr, env->cr[3], env->regs[R_EBP], postLinuxRead, pReadData))
		{
			fprintf(stderr, "preNtReadFile: failed to add postcall interception.\n");
		}
	}
}
Exemplo n.º 9
0
static int parallels_open(BlockDriverState *bs, int flags)
{
    BDRVParallelsState *s = bs->opaque;
    int i;
    struct parallels_header ph;

    bs->read_only = 1; 

    if (bdrv_pread(bs->file, 0, &ph, sizeof(ph)) != sizeof(ph))
        goto fail;

    if (memcmp(ph.magic, HEADER_MAGIC, 16) ||
	(le32_to_cpu(ph.version) != HEADER_VERSION)) {
        goto fail;
    }

    bs->total_sectors = le32_to_cpu(ph.nb_sectors);

    s->tracks = le32_to_cpu(ph.tracks);

    s->catalog_size = le32_to_cpu(ph.catalog_entries);
    s->catalog_bitmap = qemu_malloc(s->catalog_size * 4);
    if (bdrv_pread(bs->file, 64, s->catalog_bitmap, s->catalog_size * 4) !=
	s->catalog_size * 4)
	goto fail;
    for (i = 0; i < s->catalog_size; i++)
	le32_to_cpus(&s->catalog_bitmap[i]);

    return 0;
fail:
    if (s->catalog_bitmap)
	qemu_free(s->catalog_bitmap);
    return -1;
}
Exemplo n.º 10
0
/* XXX this needs to be emulated on non-FreeBSD hosts... */
static abi_long do_freebsd_sysctl(abi_ulong namep, int32_t namelen, abi_ulong oldp,
                          abi_ulong oldlenp, abi_ulong newp, abi_ulong newlen)
{
    abi_long ret;
    void *hnamep, *holdp, *hnewp = NULL;
    size_t holdlen;
    abi_ulong oldlen = 0;
    int32_t *snamep = qemu_malloc(sizeof(int32_t) * namelen), *p, *q, i;
    uint32_t kind = 0;

    if (oldlenp)
        get_user_ual(oldlen, oldlenp);
    if (!(hnamep = lock_user(VERIFY_READ, namep, namelen, 1)))
        return -TARGET_EFAULT;
    if (newp && !(hnewp = lock_user(VERIFY_READ, newp, newlen, 1)))
        return -TARGET_EFAULT;
    if (!(holdp = lock_user(VERIFY_WRITE, oldp, oldlen, 0)))
        return -TARGET_EFAULT;
    holdlen = oldlen;
    for (p = hnamep, q = snamep, i = 0; i < namelen; p++, i++)
       *q++ = tswap32(*p);
    oidfmt(snamep, namelen, NULL, &kind);
    /* XXX swap hnewp */
    ret = get_errno(sysctl(snamep, namelen, holdp, &holdlen, hnewp, newlen));
    if (!ret)
        sysctl_oldcvt(holdp, holdlen, kind);
    put_user_ual(holdlen, oldlenp);
    unlock_user(hnamep, namep, 0);
    unlock_user(holdp, oldp, holdlen);
    if (hnewp)
        unlock_user(hnewp, newp, 0);
    qemu_free(snamep);
    return ret;
}
Exemplo n.º 11
0
PSOCKET_ENTRY
InsertSocketHandle(
   IN ULONG ProcessId,
   IN HANDLE SocketHandle
   )
{
	PSOCKET_ENTRY Entry;

	if (!s_SocketListInitialized)
		return NULL;

	Entry = (PSOCKET_ENTRY)qemu_malloc(sizeof(SOCKET_ENTRY));

	if(Entry)
	{
		//fprintf(stderr, "InsertSocketHandle(PID:%d; SocketHandle:%x)\n", ProcessId, SocketHandle);

		memset(Entry, 0, sizeof(SOCKET_ENTRY));
		Entry->SocketHandle = SocketHandle;
		Entry->ProcessId = ProcessId;
		
		Entry->protocol = IPPROTO_IP;

		InsertHeadList(&s_SocketList, &Entry->ListEntry);
	}

	return Entry;
}
Exemplo n.º 12
0
/* compatibility wrapper */
int unix_listen(const char *str, char *ostr, int olen)
{
    QemuOpts *opts;
    char *path, *optstr;
    int sock, len;

    opts = qemu_opts_create(&dummy_opts, NULL, 0);

    optstr = strchr(str, ',');
    if (optstr) {
        len = optstr - str;
        if (len) {
            path = qemu_malloc(len+1);
            snprintf(path, len+1, "%.*s", len, str);
            qemu_opt_set(opts, "path", path);
            qemu_free(path);
        }
    } else {
        qemu_opt_set(opts, "path", str);
    }

    sock = unix_listen_opts(opts);

    if (sock != -1 && ostr)
        snprintf(ostr, olen, "%s%s", qemu_opt_get(opts, "path"), optstr ? optstr : "");
    qemu_opts_del(opts);
    return sock;
}
Exemplo n.º 13
0
static int vnc_set_x509_credential(VncDisplay *vd,
                                   const char *certdir,
                                   const char *filename,
                                   char **cred,
                                   int ignoreMissing)
{
    struct stat sb;

    if (*cred) {
        qemu_free(*cred);
        *cred = NULL;
    }

    *cred = qemu_malloc(strlen(certdir) + strlen(filename) + 2);

    strcpy(*cred, certdir);
    strcat(*cred, "/");
    strcat(*cred, filename);

    VNC_DEBUG("Check %s\n", *cred);
    if (stat(*cred, &sb) < 0) {
        qemu_free(*cred);
        *cred = NULL;
        if (ignoreMissing && errno == ENOENT)
            return 0;
        return -1;
    }

    return 0;
}
Exemplo n.º 14
0
void qemu_iovec_init(QEMUIOVector *qiov, int alloc_hint)
{
    qiov->iov = qemu_malloc(alloc_hint * sizeof(struct iovec));
    qiov->niov = 0;
    qiov->nalloc = alloc_hint;
    qiov->size = 0;
}
Exemplo n.º 15
0
int kvmppc_read_host_property(const char *node_path, const char *prop,
                                     void *val, size_t len)
{
    char *path;
    FILE *f;
    int ret = 0;
    int pathlen;

    pathlen = snprintf(NULL, 0, "%s/%s/%s", PROC_DEVTREE_PATH, node_path, prop)
              + 1;
    path = qemu_malloc(pathlen);

    snprintf(path, pathlen, "%s/%s/%s", PROC_DEVTREE_PATH, node_path, prop);

    f = fopen(path, "rb");
    if (f == NULL) {
        ret = errno;
        goto free;
    }

    len = fread(val, len, 1, f);
    if (len != 1) {
        ret = ferror(f);
        goto close;
    }

close:
    fclose(f);
free:
    free(path);
out:
    return ret;
}
Exemplo n.º 16
0
void qemu_sglist_init(QEMUSGList *qsg, int alloc_hint)
{
    qsg->sg = qemu_malloc(alloc_hint * sizeof(ScatterGatherEntry));
    qsg->nsg = 0;
    qsg->nalloc = alloc_hint;
    qsg->size = 0;
}
Exemplo n.º 17
0
VOID
InsertCsrssPortHandle(
   IN ULONG ProcessId,
   IN HANDLE PortHandle,
   IN ULONG VirtualOffset
   )
{
   PCSRSS_PORT_HANDLE_ENTRY Entry;

   if (!s_PortDataInitialized)
      return;

   Entry = (PCSRSS_PORT_HANDLE_ENTRY)qemu_malloc(sizeof(CSRSS_PORT_HANDLE_ENTRY));

   if (!Entry)
      return;

   //fprintf(stderr, "InsertCsrssPortHandle(PID:%xh; PortHandle:%xh; Offset:0x%08x)\n", ProcessId, PortHandle, VirtualOffset);

   Entry->PortHandle = PortHandle;
   Entry->ProcessId = ProcessId;
   Entry->VirtualOffset = VirtualOffset;

   InsertHeadList(&s_PortHandleList, &Entry->ListEntry);
}
Exemplo n.º 18
0
static void spapr_finalize_fdt(sPAPREnvironment *spapr,
                               target_phys_addr_t fdt_addr,
                               target_phys_addr_t rtas_addr,
                               target_phys_addr_t rtas_size)
{
    int ret;
    void *fdt;

    fdt = qemu_malloc(FDT_MAX_SIZE);

    /* open out the base tree into a temp buffer for the final tweaks */
    _FDT((fdt_open_into(spapr->fdt_skel, fdt, FDT_MAX_SIZE)));

    ret = spapr_populate_vdevice(spapr->vio_bus, fdt);
    if (ret < 0) {
        fprintf(stderr, "couldn't setup vio devices in fdt\n");
        exit(1);
    }

    /* RTAS */
    ret = spapr_rtas_device_tree_setup(fdt, rtas_addr, rtas_size);
    if (ret < 0) {
        fprintf(stderr, "Couldn't set up RTAS device tree properties\n");
    }

    _FDT((fdt_pack(fdt)));

    cpu_physical_memory_write(fdt_addr, fdt, fdt_totalsize(fdt));

    qemu_free(fdt);
}
Exemplo n.º 19
0
struct vhost_net *vhost_net_init(VLANClientState *backend, int devfd)
{
    int r;
    struct vhost_net *net = qemu_malloc(sizeof *net);
    if (!backend) {
        fprintf(stderr, "vhost-net requires backend to be setup\n");
        goto fail;
    }
    r = vhost_net_get_fd(backend);
    if (r < 0) {
        goto fail;
    }
    net->vc = backend;
    net->dev.backend_features = tap_has_vnet_hdr(backend) ? 0 :
        (1 << VHOST_NET_F_VIRTIO_NET_HDR);
    net->backend = r;

    r = vhost_dev_init(&net->dev, devfd);
    if (r < 0) {
        goto fail;
    }
    if (~net->dev.features & net->dev.backend_features) {
        fprintf(stderr, "vhost lacks feature mask %" PRIu64 " for backend\n",
                (uint64_t)(~net->dev.features & net->dev.backend_features));
        vhost_dev_cleanup(&net->dev);
        goto fail;
    }

    /* Set sane init value. Override when guest acks. */
    vhost_net_ack_features(net, 0);
    return net;
fail:
    qemu_free(net);
    return NULL;
}
Exemplo n.º 20
0
int fw_cfg_add_i64(FWCfgState *s, uint16_t key, uint64_t value)
{
    uint64_t *copy;

    copy = qemu_malloc(sizeof(value));
    *copy = cpu_to_le64(value);
    return fw_cfg_add_bytes(s, key, (uint8_t *)copy, sizeof(value));
}
Exemplo n.º 21
0
/**
 * qstring_from_str(): Create a new QString from a regular C string
 *
 * Return strong reference.
 */
QString *qstring_from_str(const char *str)
{
    QString *qstring;

    qstring = qemu_malloc(sizeof(*qstring));

    qstring->length = strlen(str);
    qstring->capacity = qstring->length;

    qstring->string = qemu_malloc(qstring->capacity + 1);
    memcpy(qstring->string, str, qstring->length);
    qstring->string[qstring->length] = 0;

    QOBJECT_INIT(qstring, &qstring_type);

    return qstring;
}
Exemplo n.º 22
0
static VirtIOBlockReq *virtio_blk_alloc_request(VirtIOBlock *s)
{
    VirtIOBlockReq *req = qemu_malloc(sizeof(*req));
    req->dev = s;
    req->qiov.size = 0;
    req->next = NULL;
    return req;
}
char *qemu_strdup(const char *str)
{
    char *ptr;
    ptr = qemu_malloc(strlen(str) + 1);
    if (!ptr)
        return NULL;
    strcpy(ptr, str);
    return ptr;
}
void *qemu_mallocz(size_t size)
{
    void *ptr;
    ptr = qemu_malloc(size);
    if (!ptr)
        return NULL;
    memset(ptr, 0, size);
    return ptr;
}
Exemplo n.º 25
0
static void *bamboo_load_device_tree(target_phys_addr_t addr,
                                     uint32_t ramsize,
                                     target_phys_addr_t initrd_base,
                                     target_phys_addr_t initrd_size,
                                     const char *kernel_cmdline)
{
    void *fdt = NULL;
#ifdef HAVE_FDT
    uint32_t mem_reg_property[] = { 0, 0, ramsize };
    char *path;
    int fdt_size;
    int pathlen;
    int ret;

    pathlen = snprintf(NULL, 0, "%s/%s", bios_dir, BINARY_DEVICE_TREE_FILE) + 1;
    path = qemu_malloc(pathlen);

    snprintf(path, pathlen, "%s/%s", bios_dir, BINARY_DEVICE_TREE_FILE);

    fdt = load_device_tree(path, &fdt_size);
    free(path);
    if (fdt == NULL)
        goto out;

    /* Manipulate device tree in memory. */

    ret = qemu_devtree_setprop(fdt, "/memory", "reg", mem_reg_property,
                               sizeof(mem_reg_property));
    if (ret < 0)
        fprintf(stderr, "couldn't set /memory/reg\n");

    ret = qemu_devtree_setprop_cell(fdt, "/chosen", "linux,initrd-start",
                                    initrd_base);
    if (ret < 0)
        fprintf(stderr, "couldn't set /chosen/linux,initrd-start\n");

    ret = qemu_devtree_setprop_cell(fdt, "/chosen", "linux,initrd-end",
                                    (initrd_base + initrd_size));
    if (ret < 0)
        fprintf(stderr, "couldn't set /chosen/linux,initrd-end\n");

    ret = qemu_devtree_setprop_string(fdt, "/chosen", "bootargs",
                                      kernel_cmdline);
    if (ret < 0)
        fprintf(stderr, "couldn't set /chosen/bootargs\n");

    if (kvm_enabled())
        kvmppc_fdt_update(fdt);

    cpu_physical_memory_write (addr, (void *)fdt, fdt_size);

out:
#endif

    return fdt;
}
Exemplo n.º 26
0
QEMUBH *qemu_bh_new(QEMUBHFunc *cb, void *opaque)
{
    QEMUBH *bh;

    bh = qemu_malloc(sizeof(*bh));
    bh->cb = cb;
    bh->opaque = opaque;

    return bh;
}
Exemplo n.º 27
0
/*
 *  Silly little functions to help parsing our argument string
 */
static char *
copy_string(const char *str, int str_len)
{
    char *new_str;

    new_str = qemu_malloc(str_len+1);
    memcpy(new_str, str, str_len);
    new_str[str_len] = 0;
    return new_str;
}
Exemplo n.º 28
0
static void *zalloc(void *x, unsigned items, unsigned size)
{
    void *p;

    size *= items;
    size = (size + ZALLOC_ALIGNMENT - 1) & ~(ZALLOC_ALIGNMENT - 1);

    p = qemu_malloc(size);

    return (p);
}
Exemplo n.º 29
0
int setenv(const char *name, const char *value, int overwrite)
{
    int result = 0;
    if (overwrite || !getenv(name)) {
        size_t length = strlen(name) + strlen(value) + 2;
        char *string = qemu_malloc(length);
        snprintf(string, length, "%s=%s", name, value);
        result = putenv(string);
    }
    return result;
}
Exemplo n.º 30
0
int kvm_set_msrs(CPUState *env, struct kvm_msr_entry *msrs, int n)
{
    struct kvm_msrs *kmsrs = qemu_malloc(sizeof *kmsrs + n * sizeof *msrs);
    int r;

    kmsrs->nmsrs = n;
    memcpy(kmsrs->entries, msrs, n * sizeof *msrs);
    r = kvm_vcpu_ioctl(env, KVM_SET_MSRS, kmsrs);
    free(kmsrs);
    return r;
}