mmap: cosmetic changes

This commit is contained in:
NAKAMURA Gou
2016-03-15 14:48:31 +09:00
parent 832c0f9afd
commit 81690c5b5a
3 changed files with 28 additions and 24 deletions

View File

@ -34,8 +34,6 @@ void set_signal(int sig, void *regs0, siginfo_t *info);
void check_signal(unsigned long rc, void *regs0, int num); void check_signal(unsigned long rc, void *regs0, int num);
extern unsigned long do_fork(int, unsigned long, unsigned long, unsigned long, extern unsigned long do_fork(int, unsigned long, unsigned long, unsigned long,
unsigned long, unsigned long, unsigned long); unsigned long, unsigned long, unsigned long);
extern unsigned long do_mmap(const intptr_t, const size_t, const int, const int,
const int, const off_t);
//#define DEBUG_PRINT_SC //#define DEBUG_PRINT_SC
@ -1232,12 +1230,11 @@ SYSCALL_DECLARE(mmap)
const off_t off0 = ihk_mc_syscall_arg5(ctx); const off_t off0 = ihk_mc_syscall_arg5(ctx);
struct thread *thread = cpu_local_var(current); struct thread *thread = cpu_local_var(current);
struct vm_regions *region = &thread->vm->region; struct vm_regions *region = &thread->vm->region;
unsigned long error = 0; int error;
intptr_t addr; intptr_t addr;
size_t len; size_t len;
dkprintf("[%d]sys_mmap(%lx,%lx,%x,%x,%d,%lx)\n", dkprintf("sys_mmap(%lx,%lx,%x,%x,%d,%lx)\n",
ihk_mc_get_processor_id(),
addr0, len0, prot, flags, fd, off0); addr0, len0, prot, flags, fd, off0);
/* check constants for flags */ /* check constants for flags */
@ -1274,7 +1271,7 @@ SYSCALL_DECLARE(mmap)
ekprintf("sys_mmap(%lx,%lx,%x,%x,%x,%lx):EINVAL\n", ekprintf("sys_mmap(%lx,%lx,%x,%x,%x,%lx):EINVAL\n",
addr0, len0, prot, flags, fd, off0); addr0, len0, prot, flags, fd, off0);
error = -EINVAL; error = -EINVAL;
goto out2; goto out;
} }
/* check not supported requests */ /* check not supported requests */
@ -1284,13 +1281,16 @@ SYSCALL_DECLARE(mmap)
addr0, len0, prot, flags, fd, off0, addr0, len0, prot, flags, fd, off0,
(flags & ~(supported_flags | ignored_flags))); (flags & ~(supported_flags | ignored_flags)));
error = -EINVAL; error = -EINVAL;
goto out2; goto out;
} }
return do_mmap(addr, len, prot, flags, fd, off0); addr = do_mmap(addr, len, prot, flags, fd, off0);
out2: error = 0;
return error; out:
dkprintf("sys_mmap(%lx,%lx,%x,%x,%d,%lx): %ld %lx\n",
addr0, len0, prot, flags, fd, off0, error, addr);
return (!error)? addr: error;
} }
SYSCALL_DECLARE(clone) SYSCALL_DECLARE(clone)

View File

@ -362,5 +362,7 @@ extern struct tod_data_s tod_data; /* residing in arch-dependent file */
void reset_cputime(); void reset_cputime();
void set_cputime(int mode); void set_cputime(int mode);
intptr_t do_mmap(intptr_t addr0, size_t len0, int prot, int flags, int fd,
off_t off0);
#endif #endif

View File

@ -918,7 +918,7 @@ out:
return error; return error;
} }
unsigned long intptr_t
do_mmap(const intptr_t addr0, const size_t len0, const int prot, do_mmap(const intptr_t addr0, const size_t len0, const int prot,
const int flags, const int fd, const off_t off0) const int flags, const int fd, const off_t off0)
{ {
@ -942,6 +942,9 @@ do_mmap(const intptr_t addr0, const size_t len0, const int prot,
struct process *proc = thread->proc; struct process *proc = thread->proc;
struct mckfd *fdp = NULL; struct mckfd *fdp = NULL;
dkprintf("do_mmap(%lx,%lx,%x,%x,%d,%lx)\n",
addr0, len0, prot, flags, fd, off0);
if (!(flags & MAP_ANONYMOUS)) { if (!(flags & MAP_ANONYMOUS)) {
ihk_mc_spinlock_lock_noirq(&proc->mckfd_lock); ihk_mc_spinlock_lock_noirq(&proc->mckfd_lock);
for(fdp = proc->mckfd; fdp; fdp = fdp->next) for(fdp = proc->mckfd; fdp; fdp = fdp->next)
@ -973,7 +976,7 @@ do_mmap(const intptr_t addr0, const size_t len0, const int prot,
/* clear specified address range */ /* clear specified address range */
error = do_munmap((void *)addr, len); error = do_munmap((void *)addr, len);
if (error) { if (error) {
ekprintf("sys_mmap:do_munmap(%lx,%lx) failed. %d\n", ekprintf("do_mmap:do_munmap(%lx,%lx) failed. %d\n",
addr, len, error); addr, len, error);
goto out; goto out;
} }
@ -982,7 +985,7 @@ do_mmap(const intptr_t addr0, const size_t len0, const int prot,
/* choose mapping address */ /* choose mapping address */
error = search_free_space(len, region->map_end, &addr); error = search_free_space(len, region->map_end, &addr);
if (error) { if (error) {
ekprintf("sys_mmap:search_free_space(%lx,%lx) failed. %d\n", ekprintf("do_mmap:search_free_space(%lx,%lx) failed. %d\n",
len, region->map_end, error); len, region->map_end, error);
goto out; goto out;
} }
@ -1022,7 +1025,7 @@ do_mmap(const intptr_t addr0, const size_t len0, const int prot,
if (!(prot & PROT_WRITE)) { if (!(prot & PROT_WRITE)) {
error = set_host_vma(addr, len, PROT_READ); error = set_host_vma(addr, len, PROT_READ);
if (error) { if (error) {
kprintf("sys_mmap:set_host_vma failed. %d\n", error); kprintf("do_mmap:set_host_vma failed. %d\n", error);
goto out; goto out;
} }
@ -1048,7 +1051,7 @@ do_mmap(const intptr_t addr0, const size_t len0, const int prot,
} }
#endif #endif
if (error == -ESRCH) { if (error == -ESRCH) {
kprintf("sys_mmap:hit non VREG\n"); kprintf("do_mmap:hit non VREG\n");
/* /*
* XXX: temporary: * XXX: temporary:
* *
@ -1062,7 +1065,7 @@ do_mmap(const intptr_t addr0, const size_t len0, const int prot,
error = devobj_create(fd, len, off, &memobj, &maxprot); error = devobj_create(fd, len, off, &memobj, &maxprot);
} }
if (error) { if (error) {
ekprintf("sys_mmap:fileobj_create failed. %d\n", error); ekprintf("do_mmap:fileobj_create failed. %d\n", error);
goto out; goto out;
} }
} }
@ -1078,7 +1081,7 @@ do_mmap(const intptr_t addr0, const size_t len0, const int prot,
#endif /* USE_LARGE_PAGES */ #endif /* USE_LARGE_PAGES */
p = ihk_mc_alloc_aligned_pages(npages, p2align, IHK_MC_AP_NOWAIT); p = ihk_mc_alloc_aligned_pages(npages, p2align, IHK_MC_AP_NOWAIT);
if (p == NULL) { if (p == NULL) {
ekprintf("sys_mmap:allocate_pages(%d,%d) failed.\n", ekprintf("do_mmap:allocate_pages(%d,%d) failed.\n",
npages, p2align); npages, p2align);
error = -ENOMEM; error = -ENOMEM;
goto out; goto out;
@ -1091,14 +1094,14 @@ do_mmap(const intptr_t addr0, const size_t len0, const int prot,
ads.shm_perm.mode = SHM_DEST; ads.shm_perm.mode = SHM_DEST;
error = shmobj_create(&ads, &memobj); error = shmobj_create(&ads, &memobj);
if (error) { if (error) {
ekprintf("sys_mmap:shmobj_create failed. %d\n", error); ekprintf("do_mmap:shmobj_create failed. %d\n", error);
goto out; goto out;
} }
} }
else { else {
error = zeroobj_create(&memobj); error = zeroobj_create(&memobj);
if (error) { if (error) {
ekprintf("sys_mmap:zeroobj_create failed. %d\n", error); ekprintf("do_mmap:zeroobj_create failed. %d\n", error);
goto out; goto out;
} }
} }
@ -1108,7 +1111,7 @@ do_mmap(const intptr_t addr0, const size_t len0, const int prot,
} }
denied = prot & ~maxprot; denied = prot & ~maxprot;
if (denied) { if (denied) {
ekprintf("sys_mmap:denied %x. %x %x\n", denied, prot, maxprot); ekprintf("do_mmap:denied %x. %x %x\n", denied, prot, maxprot);
error = (denied == PROT_EXEC)? -EPERM: -EACCES; error = (denied == PROT_EXEC)? -EPERM: -EACCES;
goto out; goto out;
} }
@ -1116,7 +1119,7 @@ do_mmap(const intptr_t addr0, const size_t len0, const int prot,
error = add_process_memory_range(thread->vm, addr, addr+len, phys, vrflags, memobj, off); error = add_process_memory_range(thread->vm, addr, addr+len, phys, vrflags, memobj, off);
if (error) { if (error) {
ekprintf("sys_mmap:add_process_memory_range" ekprintf("do_mmap:add_process_memory_range"
"(%p,%lx,%lx,%lx,%lx) failed %d\n", "(%p,%lx,%lx,%lx,%lx) failed %d\n",
thread->vm, addr, addr+len, thread->vm, addr, addr+len,
virt_to_phys(p), vrflags, error); virt_to_phys(p), vrflags, error);
@ -1137,7 +1140,7 @@ out:
if (!error && populated_mapping) { if (!error && populated_mapping) {
error = populate_process_memory(thread->vm, (void *)addr, len); error = populate_process_memory(thread->vm, (void *)addr, len);
if (error) { if (error) {
ekprintf("sys_mmap:populate_process_memory" ekprintf("do_mmap:populate_process_memory"
"(%p,%p,%lx) failed %d\n", "(%p,%p,%lx) failed %d\n",
thread->vm, (void *)addr, len, error); thread->vm, (void *)addr, len, error);
/* /*
@ -1162,8 +1165,7 @@ out:
if (memobj) { if (memobj) {
memobj_release(memobj); memobj_release(memobj);
} }
dkprintf("[%d]sys_mmap(%lx,%lx,%x,%x,%d,%lx): %ld %lx\n", dkprintf("do_mmap(%lx,%lx,%x,%x,%d,%lx): %ld %lx\n",
ihk_mc_get_processor_id(),
addr0, len0, prot, flags, fd, off0, error, addr); addr0, len0, prot, flags, fd, off0, error, addr);
return (!error)? addr: error; return (!error)? addr: error;
} }