コード例 #1
0
ファイル: VM.cpp プロジェクト: Nukem9/Haxm
bool VM_HaxEnabled()
{
	// This function only creates a temporary state for the driver handle
	hax_state hax;
	memset(&hax, 0, sizeof(hax_state));

	hax.fd = hax_mod_open();

	// Is the returned handle valid?
	if (hax_invalid_fd(hax.fd))
		return false;

	// Determine the capabilities from the driver
	if (!HaxIsAvailable(&hax))
	{
		hax_mod_close(&hax);
		return false;
	}

	// Check if the version is supported
	if (!HaxIsSupported(&hax))
	{
		printf("Incompatible HAX version\n");
		hax_mod_close(&hax);
		return false;
	}

	hax_mod_close(&hax);
	return true;
}
コード例 #2
0
ファイル: hax-all.c プロジェクト: CTU-IIG/qemu
static int hax_init(ram_addr_t ram_size)
{
    struct hax_state *hax = NULL;
    struct hax_qemu_version qversion;
    int ret;

    hax = &hax_global;

    memset(hax, 0, sizeof(struct hax_state));
    hax->mem_quota = ram_size;

    hax->fd = hax_mod_open();
    if (hax_invalid_fd(hax->fd)) {
        hax->fd = 0;
        ret = -ENODEV;
        goto error;
    }

    ret = hax_get_capability(hax);

    if (ret) {
        if (ret != -ENOSPC) {
            ret = -EINVAL;
        }
        goto error;
    }

    if (!hax_version_support(hax)) {
        ret = -EINVAL;
        goto error;
    }

    hax->vm = hax_vm_create(hax);
    if (!hax->vm) {
        fprintf(stderr, "Failed to create HAX VM\n");
        ret = -EINVAL;
        goto error;
    }

    hax_memory_init();

    qversion.cur_version = hax_cur_version;
    qversion.min_version = hax_min_version;
    hax_notify_qemu_version(hax->vm->fd, &qversion);
    cpu_interrupt_handler = hax_handle_interrupt;

    return ret;
  error:
    if (hax->vm) {
        hax_vm_destroy(hax->vm);
    }
    if (hax->fd) {
        hax_mod_close(hax);
    }

    return ret;
}