Commit fbd5b279 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 1dcbe2a4
...@@ -230,9 +230,12 @@ int fileh_mmap(VMA *vma, BigFileH *fileh, pgoff_t pgoffset, pgoff_t pglen) ...@@ -230,9 +230,12 @@ int fileh_mmap(VMA *vma, BigFileH *fileh, pgoff_t pgoffset, pgoff_t pglen)
sigsegv_block(&save_sigset); sigsegv_block(&save_sigset);
virt_lock(); virt_lock();
/* alloc vma->page_ismappedv[] */ /* start preparing vma */
bzero(vma, sizeof(*vma)); bzero(vma, sizeof(*vma));
vma->fileh = fileh;
vma->f_pgoffset = pgoffset;
/* alloc vma->page_ismappedv[] */
vma->page_ismappedv = bitmap_alloc0(pglen); vma->page_ismappedv = bitmap_alloc0(pglen);
if (!vma->page_ismappedv) if (!vma->page_ismappedv)
goto fail; goto fail;
...@@ -241,26 +244,41 @@ int fileh_mmap(VMA *vma, BigFileH *fileh, pgoff_t pgoffset, pgoff_t pglen) ...@@ -241,26 +244,41 @@ int fileh_mmap(VMA *vma, BigFileH *fileh, pgoff_t pgoffset, pgoff_t pglen)
vma->mmap_overlay = (fops->mmap_setup_read != NULL); vma->mmap_overlay = (fops->mmap_setup_read != NULL);
if (vma->mmap_overlay) { if (vma->mmap_overlay) {
/* wcfs: mmap(base, READ) + mmap(fileh->dirty_pages) over it */ /* wcfs: mmap(base, READ) */
TODO (file->blksize != fileh->ramh->ram->pagesize); TODO (file->blksize != fileh->ramh->ram->pagesize);
addr = fops->mmap_setup_read(file, pgoffset, pglen, vma); addr = fops->mmap_setup_read(file, pgoffset, pglen, vma);
if (!addr)
goto fail;
// XXX + mmap(fileh->dirty_pages)
} else { } else {
/* !wcfs: allocate address space somewhere */ /* !wcfs: allocate address space somewhere */
addr = mem_valloc(NULL, len); addr = mem_valloc(NULL, len);
if (!addr)
goto fail;
} }
if (!addr)
goto fail;
/* vma address range known */
/* everything allocated - link it up */
vma->addr_start = (uintptr_t)addr; vma->addr_start = (uintptr_t)addr;
vma->addr_stop = vma->addr_start + len; vma->addr_stop = vma->addr_start + len;
vma->fileh = fileh; /* wcfs: mmap(fileh->dirty_pages) over base */
vma->f_pgoffset = pgoffset; if (vma->mmap_overlay) {
Page* page;
struct list_head *hpage;
list_for_each(hpage, &fileh->dirty_pages) {
page = list_entry(hpage, typeof(*page), in_dirty);
BUG_ON(page->state != PAGE_DIRTY);
if (!(pgoffset <= page->f_pgoffset && page->f_pgoffset < pgoffset + pglen))
continue; /* page is out of requested mmap coverage */
// XXX err
// XXX notify watcher that we mmaped RAM page in its range?
page_mmap(page, vma_page_addr(vma, page), PROT_READ | PROT_WRITE);
bitmap_set_bit(vma->page_ismappedv, page->f_pgoffset - vma->f_pgoffset);
page_incref(page);
}
}
/* everything allocated - link it up */
// XXX need to init vma->virt_list first? // XXX need to init vma->virt_list first?
/* hook vma to fileh->mmaps */ /* hook vma to fileh->mmaps */
...@@ -276,7 +294,7 @@ out: ...@@ -276,7 +294,7 @@ out:
fail: fail:
free(vma->page_ismappedv); free(vma->page_ismappedv);
vma->page_ismappedv = NULL; bzero(vma, sizeof(*vma));
err = -1; err = -1;
goto out; goto out;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment