Exemplo n.º 1
0
/*
 * The eip contains the *virtual* address of the Guest's instruction:
 * we copy the instruction here so the Launcher doesn't have to walk
 * the page tables to decode it.  We handle the case (eg. in a kernel
 * module) where the instruction is over two pages, and the pages are
 * virtually but not physically contiguous.
 *
 * The longest possible x86 instruction is 15 bytes, but we don't handle
 * anything that strange.
 */
static void copy_from_guest(struct lg_cpu *cpu,
			    void *dst, unsigned long vaddr, size_t len)
{
	size_t to_page_end = PAGE_SIZE - (vaddr % PAGE_SIZE);
	unsigned long paddr;

	BUG_ON(len > PAGE_SIZE);

	/* If it goes over a page, copy in two parts. */
	if (len > to_page_end) {
		/* But make sure the next page is mapped! */
		if (__guest_pa(cpu, vaddr + to_page_end, &paddr))
			copy_from_guest(cpu, dst + to_page_end,
					vaddr + to_page_end,
					len - to_page_end);
		else
			/* Otherwise fill with zeroes. */
			memset(dst + to_page_end, 0, len - to_page_end);
		len = to_page_end;
	}

	/* This will kill the guest if it isn't mapped, but that
	 * shouldn't happen. */
	__lgread(cpu, dst, guest_pa(cpu, vaddr), len);
}
Exemplo n.º 2
0
/*
 * This is the version we normally use: kills the Guest if it uses a
 * bad address
 */
unsigned long guest_pa(struct lg_cpu *cpu, unsigned long vaddr)
{
	unsigned long paddr;

	if (!__guest_pa(cpu, vaddr, &paddr))
		kill_guest(cpu, "Bad address %#lx", vaddr);
	return paddr;
}