/* This routine is used to load the kernel or initrd. It tries mmap, but if that fails (Plan 9's kernel file isn't nicely aligned on page boundaries), it falls back to reading the memory in.  */
static void map_at(int fd, void *addr, unsigned long offset, unsigned long len)
/* This routine is used to load the kernel or initrd. It tries mmap, but if that fails (Plan 9's kernel file isn't nicely aligned on page boundaries), it falls back to reading the memory in.  */
static void map_at(int fd, void *addr, unsigned long offset, unsigned long len)
{
	ssize_t r;
	if (mmap(addr, len, PROT_READ|PROT_WRITE|PROT_EXEC,
		 MAP_FIXED|MAP_PRIVATE, fd, offset) != MAP_FAILED)
		return;
	r = pread(fd, addr, len, offset);
	if (r != len)
		err(1, "Reading offset %lu len %lu gave %zi", offset, len, r);
}