int kvm_init_vcpu(CPUState *cpu)

{

    KVMState *s = kvm_state;

    long mmap_size;

    int ret;



    DPRINTF("kvm_init_vcpu\n");



    ret = kvm_vm_ioctl(s, KVM_CREATE_VCPU, (void *)kvm_arch_vcpu_id(cpu));

    if (ret < 0) {

        DPRINTF("kvm_create_vcpu failed\n");

        goto err;

    }



    cpu->kvm_fd = ret;

    cpu->kvm_state = s;

    cpu->kvm_vcpu_dirty = true;



    mmap_size = kvm_ioctl(s, KVM_GET_VCPU_MMAP_SIZE, 0);

    if (mmap_size < 0) {

        ret = mmap_size;

        DPRINTF("KVM_GET_VCPU_MMAP_SIZE failed\n");

        goto err;

    }



    cpu->kvm_run = mmap(NULL, mmap_size, PROT_READ | PROT_WRITE, MAP_SHARED,

                        cpu->kvm_fd, 0);

    if (cpu->kvm_run == MAP_FAILED) {

        ret = -errno;

        DPRINTF("mmap'ing vcpu state failed\n");

        goto err;

    }



    if (s->coalesced_mmio && !s->coalesced_mmio_ring) {

        s->coalesced_mmio_ring =

            (void *)cpu->kvm_run + s->coalesced_mmio * PAGE_SIZE;

    }



    ret = kvm_arch_init_vcpu(cpu);

err:

    return ret;

}

int kvm_init_vcpu(CPUState *cpu)

{

    KVMState *s = kvm_state;

    long mmap_size;

    int ret;



    DPRINTF("kvm_init_vcpu\n");



    ret = kvm_vm_ioctl(s, KVM_CREATE_VCPU, (void *)kvm_arch_vcpu_id(cpu));

    if (ret < 0) {

        DPRINTF("kvm_create_vcpu failed\n");

        goto err;

    }



    cpu->kvm_fd = ret;

    cpu->kvm_state = s;

    cpu->kvm_vcpu_dirty = true;



    mmap_size = kvm_ioctl(s, KVM_GET_VCPU_MMAP_SIZE, 0);

    if (mmap_size < 0) {

        ret = mmap_size;

        DPRINTF("KVM_GET_VCPU_MMAP_SIZE failed\n");

        goto err;

    }



    cpu->kvm_run = mmap(NULL, mmap_size, PROT_READ | PROT_WRITE, MAP_SHARED,

                        cpu->kvm_fd, 0);

    if (cpu->kvm_run == MAP_FAILED) {

        ret = -errno;

        DPRINTF("mmap'ing vcpu state failed\n");

        goto err;

    }



    if (s->coalesced_mmio && !s->coalesced_mmio_ring) {

        s->coalesced_mmio_ring =

            (void *)cpu->kvm_run + s->coalesced_mmio * PAGE_SIZE;

    }



    ret = kvm_arch_init_vcpu(cpu);

err:

    return ret;

}

int FUNC_0(CPUState *VAR_0)

{

    KVMState *s = kvm_state;

    long VAR_1;

    int VAR_2;



    DPRINTF("FUNC_0\n");



    VAR_2 = kvm_vm_ioctl(s, KVM_CREATE_VCPU, (void *)kvm_arch_vcpu_id(VAR_0));

    if (VAR_2 < 0) {

        DPRINTF("kvm_create_vcpu failed\n");

        goto err;

    }



    VAR_0->kvm_fd = VAR_2;

    VAR_0->kvm_state = s;

    VAR_0->kvm_vcpu_dirty = true;



    VAR_1 = kvm_ioctl(s, KVM_GET_VCPU_MMAP_SIZE, 0);

    if (VAR_1 < 0) {

        VAR_2 = VAR_1;

        DPRINTF("KVM_GET_VCPU_MMAP_SIZE failed\n");

        goto err;

    }



    VAR_0->kvm_run = mmap(NULL, VAR_1, PROT_READ | PROT_WRITE, MAP_SHARED,

                        VAR_0->kvm_fd, 0);

    if (VAR_0->kvm_run == MAP_FAILED) {

        VAR_2 = -errno;

        DPRINTF("mmap'ing vcpu state failed\n");

        goto err;

    }



    if (s->coalesced_mmio && !s->coalesced_mmio_ring) {

        s->coalesced_mmio_ring =

            (void *)VAR_0->kvm_run + s->coalesced_mmio * PAGE_SIZE;

    }



    VAR_2 = kvm_arch_init_vcpu(VAR_0);

err:

    return VAR_2;

}

int FUNC_0(CPUState *VAR_0)
{ KVMState *s = kvm_state; long VAR_1; int VAR_2; DPRINTF("FUNC_0\n"); VAR_2 = kvm_vm_ioctl(s, KVM_CREATE_VCPU, (void *)kvm_arch_vcpu_id(VAR_0)); if (VAR_2 < 0) { DPRINTF("kvm_create_vcpu failed\n"); goto err; } VAR_0->kvm_fd = VAR_2; VAR_0->kvm_state = s; VAR_0->kvm_vcpu_dirty = true; VAR_1 = kvm_ioctl(s, KVM_GET_VCPU_MMAP_SIZE, 0); if (VAR_1 < 0) { VAR_2 = VAR_1; DPRINTF("KVM_GET_VCPU_MMAP_SIZE failed\n"); goto err; } VAR_0->kvm_run = mmap(NULL, VAR_1, PROT_READ | PROT_WRITE, MAP_SHARED,
VAR_0->kvm_fd, 0); if (VAR_0->kvm_run == MAP_FAILED) { VAR_2 = -errno; DPRINTF("mmap'ing vcpu state failed\n"); goto err; } if (s->coalesced_mmio && !s->coalesced_mmio_ring) { s->coalesced_mmio_ring =
(void *)VAR_0->kvm_run + s->coalesced_mmio * PAGE_SIZE; } VAR_2 = kvm_arch_init_vcpu(VAR_0); err:
return VAR_2; }