Commit f82dc053 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent dfd6b518
...@@ -44,6 +44,7 @@ static void page_del(Page *page); ...@@ -44,6 +44,7 @@ static void page_del(Page *page);
static void *vma_page_addr(VMA *vma, Page *page); static void *vma_page_addr(VMA *vma, Page *page);
static pgoff_t vma_addr_fpgoffset(VMA *vma, uintptr_t addr); static pgoff_t vma_addr_fpgoffset(VMA *vma, uintptr_t addr);
static void vma_mmap_page(VMA *vma, Page *page); static void vma_mmap_page(VMA *vma, Page *page);
static int vma_page_infilerange(VMA *vma, Page *page);
static int vma_page_ismapped(VMA *vma, Page *page); static int vma_page_ismapped(VMA *vma, Page *page);
static void vma_page_ensure_unmapped(VMA *vma, Page *page); static void vma_page_ensure_unmapped(VMA *vma, Page *page);
static void vma_page_ensure_notmappedrw(VMA *vma, Page *page); static void vma_page_ensure_notmappedrw(VMA *vma, Page *page);
...@@ -283,7 +284,7 @@ int fileh_mmap(VMA *vma, BigFileH *fileh, pgoff_t pgoffset, pgoff_t pglen) ...@@ -283,7 +284,7 @@ int fileh_mmap(VMA *vma, BigFileH *fileh, pgoff_t pgoffset, pgoff_t pglen)
page = list_entry(hpage, typeof(*page), in_dirty); page = list_entry(hpage, typeof(*page), in_dirty);
BUG_ON(page->state != PAGE_DIRTY); BUG_ON(page->state != PAGE_DIRTY);
if (!(pgoffset <= page->f_pgoffset && page->f_pgoffset < pgoffset + pglen)) if (!vma_page_infilerange(vma, page))
continue; /* page is out of requested mmap coverage */ continue; /* page is out of requested mmap coverage */
// XXX notify watcher that we mmap RAM page in its range? -> no need // XXX notify watcher that we mmap RAM page in its range? -> no need
...@@ -889,8 +890,12 @@ VMFaultResult vma_on_pagefault(VMA *vma, uintptr_t addr, int write) ...@@ -889,8 +890,12 @@ VMFaultResult vma_on_pagefault(VMA *vma, uintptr_t addr, int write)
if (fileh->mmap_overlay) { if (fileh->mmap_overlay) {
list_for_each(hmmap, &fileh->mmaps) { list_for_each(hmmap, &fileh->mmaps) {
VMA *vma2 = list_entry(hmmap, typeof(*vma2), same_fileh); VMA *vma2 = list_entry(hmmap, typeof(*vma2), same_fileh);
if (vma2 != vma) if (vma2 == vma)
vma_mmap_page(vma2, page); continue;
if (!vma_page_infilerange(vma2, page))
continue; /* page is out of vma2 file-range coverage */
vma_mmap_page(vma2, page);
} }
} }
...@@ -1092,15 +1097,23 @@ static void vma_mmap_page(VMA *vma, Page *page) { ...@@ -1092,15 +1097,23 @@ static void vma_mmap_page(VMA *vma, Page *page) {
} }
} }
/* is `page` mapped to `vma` */ /* is `page->fpgoffset` belongs to file-range covered by `vma` */
static int vma_page_ismapped(VMA *vma, Page *page) static int vma_page_infilerange(VMA *vma, Page *page)
{ {
pgoff_t vma_fpgstop; pgoff_t vma_fpgstop;
ASSERT(vma->fileh == page->fileh); ASSERT(vma->fileh == page->fileh);
vma_fpgstop = vma_addr_fpgoffset(vma, vma->addr_stop); vma_fpgstop = vma_addr_fpgoffset(vma, vma->addr_stop);
if (!(vma->f_pgoffset <= page->f_pgoffset && return (vma->f_pgoffset <= page->f_pgoffset &&
page->f_pgoffset < vma_fpgstop)) page->f_pgoffset < vma_fpgstop);
}
/* is `page` mapped to `vma` */
static int vma_page_ismapped(VMA *vma, Page *page)
{
ASSERT(vma->fileh == page->fileh);
if (!vma_page_infilerange(vma, page))
return 0; return 0;
return bitmap_test_bit(vma->page_ismappedv, page->f_pgoffset - vma->f_pgoffset); return bitmap_test_bit(vma->page_ismappedv, page->f_pgoffset - vma->f_pgoffset);
......
...@@ -505,17 +505,10 @@ void _Mapping::unmap() { ...@@ -505,17 +505,10 @@ void _Mapping::unmap() {
FileH f = mmap->fileh; FileH f = mmap->fileh;
//f->_mmaps.remove(mmap); //f->_mmaps.remove(mmap);
printf("\nbefore remove %p:\n", mmap._ptr());
for (auto x : f->_mmaps)
printf("\t%p\n", x._ptr());
// FIXME keep mmaps sorted // FIXME keep mmaps sorted
f->_mmaps.erase( f->_mmaps.erase(
std::remove(f->_mmaps.begin(), f->_mmaps.end(), mmap), std::remove(f->_mmaps.begin(), f->_mmaps.end(), mmap),
f->_mmaps.end()); f->_mmaps.end());
printf("\nafter remove:\n");
for (auto x : f->_mmaps)
printf("\t%p\n", x._ptr());
} }
......
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