Example #1
0
File: VM.cpp Project: 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;
}
Example #2
0
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;
}
Example #3
0
File: VM.cpp Project: Nukem9/Haxm
hax_state *VM_CreateInstance(UINT RAMSize)
{
	// Allocate a state structure and zero it
	auto instance = (hax_state *)malloc(sizeof(hax_state));

	if (!instance)
		return nullptr;

	memset(instance, 0, sizeof(hax_state));

	// Set device handle and RAM size
	instance->fd = hax_mod_open();
	instance->mem_quota = RAMSize;

	// Link a VM handle to the state
	if (!HaxVmCreate(instance))
	{
		free(instance);
		return nullptr;
	}

	return instance;
}