Added msync(), added handling of munmap/msync to pager main.c

This commit is contained in:
Bahadir Balban
2008-10-29 19:22:01 +02:00
parent 51af9968c2
commit 4046ad9e3f
4 changed files with 43 additions and 17 deletions

View File

@@ -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. */

View File

@@ -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;

View File

@@ -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: "

View File

@@ -8,11 +8,6 @@
#include <l4/api/errno.h>
#include <l4lib/arch/syslib.h>
/* 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);
}