diff --git a/tasks/libl4/include/l4lib/ipcdefs.h b/tasks/libl4/include/l4lib/ipcdefs.h index 4fb33ac..4bb51fd 100644 --- a/tasks/libl4/include/l4lib/ipcdefs.h +++ b/tasks/libl4/include/l4lib/ipcdefs.h @@ -50,7 +50,6 @@ #define L4_IPC_TAG_EXIT 27 #define L4_IPC_TAG_WAIT 28 - /* Tags for ipc between fs0 and mm0 */ #define L4_IPC_TAG_TASKDATA 40 #define L4_IPC_TAG_PAGER_OPEN 41 /* vfs sends the pager open file data. */ diff --git a/tasks/mm0/include/syscalls.h b/tasks/mm0/include/syscalls.h index 6d17e06..7d210c2 100644 --- a/tasks/mm0/include/syscalls.h +++ b/tasks/mm0/include/syscalls.h @@ -27,6 +27,7 @@ void *sys_mmap(struct tcb *sender, void *start, size_t length, int prot, int flags, int fd, off_t offset); int sys_munmap(struct tcb *sender, void *vaddr, unsigned long size); +int sys_msync(struct tcb *task, void *start, unsigned long length, int flags); struct sys_shmat_args { l4id_t shmid; diff --git a/tasks/mm0/main.c b/tasks/mm0/main.c index 899d7eb..dd6a32d 100644 --- a/tasks/mm0/main.c +++ b/tasks/mm0/main.c @@ -121,6 +121,15 @@ void handle_requests(void) args->flags, args->fd, __pfn(args->offset)); break; } + case L4_IPC_TAG_MUNMAP: { + ret = sys_munmap(sender, (void *)mr[0], (unsigned long)mr[1]); + break; + } + case L4_IPC_TAG_MSYNC: { + ret = sys_msync(sender, (void *)mr[0], + (unsigned long)mr[1], (int)mr[2]); + break; + } case L4_IPC_TAG_FORK: { ret = sys_fork(sender); break; @@ -134,16 +143,6 @@ void handle_requests(void) // ret = sys_brk(sender, (void *)mr[0]); // break; } - - case L4_IPC_TAG_MUNMAP: { - ret = sys_munmap(sender, (void *)mr[0], (unsigned long)mr[1]); - break; - } - case L4_IPC_TAG_MSYNC: { - /* TODO: Use arg struct instead */ -// sys_msync(sender, (void *)mr[0], (int)mr[1], (int)mr[2]); - break; - } default: printf("%s: Unrecognised ipc tag (%d) " "received from (%d). Full mr reading: " diff --git a/tasks/mm0/src/munmap.c b/tasks/mm0/src/munmap.c index d3e84d0..7f44fa6 100644 --- a/tasks/mm0/src/munmap.c +++ b/tasks/mm0/src/munmap.c @@ -8,11 +8,6 @@ #include #include -/* TODO: This is to be implemented when fs0 is ready. */ -int do_msync(void *addr, unsigned long size, unsigned int flags, struct tcb *task) -{ - return 0; -} /* This splits a vma, splitter region must be in the *middle* of original vma */ int vma_split(struct vm_area *vma, struct tcb *task, @@ -142,7 +137,7 @@ int do_munmap(struct tcb *task, void *vaddr, unsigned long npages) if ((err = vma_flush_pages(vma)) < 0) return err; - /* Unmap the vma accordingly */ + /* Unmap the vma accordingly. Note, this may delete the vma */ if ((err = vma_unmap(vma, task, munmap_start, munmap_end)) < 0) return err; @@ -165,3 +160,35 @@ int sys_munmap(struct tcb *task, void *start, unsigned long length) } +/* Syncs mapped area. Currently just synchronously */ +int do_msync(struct tcb *task, void *vaddr, unsigned long npages, int flags) +{ + const unsigned long msync_start = __pfn(vaddr); + const unsigned long msync_end = msync_start + npages; + struct vm_area *vma; + int err; + + /* Find a vma that overlaps with this address range */ + while ((vma = find_vma_byrange(msync_start, msync_end, + &task->vm_area_head->list))) { + + /* Flush pages if vma is writable, dirty and file-backed. */ + if ((err = vma_flush_pages(vma)) < 0) + return err; + } + return 0; +} + +int sys_msync(struct tcb *task, void *start, unsigned long length, int flags) +{ + /* Must be aligned on a page boundary */ + if ((unsigned long)start & PAGE_MASK) + return -EINVAL; + + /* + * TODO: We need to pass sync'ed and non-sync'ed file flushes to vfs + * and support synced and non-synced io. + */ + return do_msync(task, start, __pfn(page_align_up(length)), flags); +} +