Ejemplo n.º 1
0
int
xh_vm_setup_memory(size_t len, enum vm_mmap_style vms)
{
	void **addr;
	int error;

	/* XXX VM_MMAP_SPARSE not implemented yet */
	assert(vms == VM_MMAP_NONE || vms == VM_MMAP_ALL);

	mmap_style = vms;

	/*
	 * If 'len' cannot fit entirely in the 'lowmem' segment then
	 * create another 'highmem' segment above 4GB for the remainder.
	 */

	lowmem = (len > lowmem_limit) ? lowmem_limit : len;
	highmem = (len > lowmem_limit) ? (len - lowmem) : 0;

	if (lowmem > 0) {
		addr = (vms == VM_MMAP_ALL) ? &lowmem_addr : NULL;
		if ((error = setup_memory_segment(0, lowmem, addr))) {
			return (error);
		}
	}

	if (highmem > 0) {
		addr = (vms == VM_MMAP_ALL) ? &highmem_addr : NULL;
		if ((error = setup_memory_segment((4ull << 30), highmem, addr))) {
			return (error);
		}
	}

	return (0);
}
Ejemplo n.º 2
0
int
vm_setup_memory(struct vmctx *ctx, size_t memsize, enum vm_mmap_style vms)
{
	size_t objsize, len;
	vm_paddr_t gpa;
	char *baseaddr, *ptr;
	int error, flags;

	assert(vms == VM_MMAP_ALL);

	/*
	 * If 'memsize' cannot fit entirely in the 'lowmem' segment then
	 * create another 'highmem' segment above 4GB for the remainder.
	 */
	if (memsize > ctx->lowmem_limit) {
		ctx->lowmem = ctx->lowmem_limit;
		ctx->highmem = memsize - ctx->lowmem_limit;
		objsize = 4*GB + ctx->highmem;
	} else {
		ctx->lowmem = memsize;
		ctx->highmem = 0;
		objsize = ctx->lowmem;
	}

	error = vm_alloc_memseg(ctx, VM_SYSMEM, objsize, NULL);
	if (error)
		return (error);

	/*
	 * Stake out a contiguous region covering the guest physical memory
	 * and the adjoining guard regions.
	 */
	len = VM_MMAP_GUARD_SIZE + objsize + VM_MMAP_GUARD_SIZE;
	flags = MAP_PRIVATE | MAP_ANON | MAP_NOCORE | MAP_ALIGNED_SUPER;
	ptr = mmap(NULL, len, PROT_NONE, flags, -1, 0);
	if (ptr == MAP_FAILED)
		return (-1);

	baseaddr = ptr + VM_MMAP_GUARD_SIZE;
	if (ctx->highmem > 0) {
		gpa = 4*GB;
		len = ctx->highmem;
		error = setup_memory_segment(ctx, gpa, len, baseaddr);
		if (error)
			return (error);
	}

	if (ctx->lowmem > 0) {
		gpa = 0;
		len = ctx->lowmem;
		error = setup_memory_segment(ctx, gpa, len, baseaddr);
		if (error)
			return (error);
	}

	ctx->baseaddr = baseaddr;

	return (0);
}
Ejemplo n.º 3
0
int
vm_setup_memory(struct vmctx *ctx, size_t memsize, enum vm_mmap_style vms)
{
	char **addr;
	int error;

	/* XXX VM_MMAP_SPARSE not implemented yet */
	assert(vms == VM_MMAP_NONE || vms == VM_MMAP_ALL);
	ctx->vms = vms;

	/*
	 * If 'memsize' cannot fit entirely in the 'lowmem' segment then
	 * create another 'highmem' segment above 4GB for the remainder.
	 */
	if (memsize > ctx->lowmem_limit) {
		ctx->lowmem = ctx->lowmem_limit;
		ctx->highmem = memsize - ctx->lowmem;
	} else {
		ctx->lowmem = memsize;
		ctx->highmem = 0;
	}

	if (ctx->lowmem > 0) {
		addr = (vms == VM_MMAP_ALL) ? &ctx->lowmem_addr : NULL;
		error = setup_memory_segment(ctx, 0, ctx->lowmem, addr);
		if (error)
			return (error);
	}

	if (ctx->highmem > 0) {
		addr = (vms == VM_MMAP_ALL) ? &ctx->highmem_addr : NULL;
		error = setup_memory_segment(ctx, 4*GB, ctx->highmem, addr);
		if (error)
			return (error);
	}

	return (0);
}