static int add_mmap(unsigned long virt, unsigned long phys, unsigned long len, unsigned int prot, struct host_vm_change *hvc) { __u64 offset; struct host_vm_op *last; int fd, ret = 0; fd = phys_mapping(phys, &offset); if (hvc->index != 0) { last = &hvc->ops[hvc->index - 1]; if ((last->type == MMAP) && (last->u.mmap.addr + last->u.mmap.len == virt) && (last->u.mmap.prot == prot) && (last->u.mmap.fd == fd) && (last->u.mmap.offset + last->u.mmap.len == offset)) { last->u.mmap.len += len; return 0; } } if (hvc->index == ARRAY_SIZE(hvc->ops)) { ret = do_ops(hvc, ARRAY_SIZE(hvc->ops), 0); hvc->index = 0; } hvc->ops[hvc->index++] = ((struct host_vm_op) { .type = MMAP, .u = { .mmap = { .addr = virt, .len = len, .prot = prot, .fd = fd, .offset = offset } } });
void map_memory(unsigned long virt, unsigned long phys, unsigned long len, int r, int w, int x) { __u64 offset; int fd, err; fd = phys_mapping(phys, &offset); err = os_map_memory((void *) virt, fd, offset, len, r, w, x); if (err) { if (err == -ENOMEM) printk(KERN_ERR "try increasing the host's " "/proc/sys/vm/max_map_count to <physical " "memory size>/4096\n"); panic("map_memory(0x%lx, %d, 0x%llx, %ld, %d, %d, %d) failed, " "err = %d\n", virt, fd, offset, len, r, w, x, err); } }