mirror of
https://github.com/drasko/codezero.git
synced 2026-01-17 05:13:16 +01:00
vma_intersect() was erroneous, replaced by a nice and simple set_intersection() routine.
Still testing sys_munmap(). It now correctly spots and unmaps the overlapping vma. The issue now is that if a split occurs, we forgot to add same objects to new vma.
This commit is contained in:
@@ -183,8 +183,6 @@ struct vm_area {
|
||||
unsigned long file_offset; /* File offset in pfns */
|
||||
};
|
||||
|
||||
int vma_intersect(unsigned long pfn_start, unsigned long pfn_end,
|
||||
struct vm_area *vma);
|
||||
/*
|
||||
* Finds the vma that has the given address.
|
||||
* TODO: In the future a lot of use cases may need to traverse each vma
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
*
|
||||
* Copyright (C) 2007, 2008 Bahadir Balban
|
||||
*/
|
||||
#include <l4/lib/math.h>
|
||||
#include <vm_area.h>
|
||||
#include <kmalloc/kmalloc.h>
|
||||
#include INC_API(errno.h)
|
||||
@@ -37,20 +38,6 @@ struct vm_area *vma_new(unsigned long pfn_start, unsigned long npages,
|
||||
return vma;
|
||||
}
|
||||
|
||||
int vma_intersect(unsigned long pfn_start, unsigned long pfn_end,
|
||||
struct vm_area *vma)
|
||||
{
|
||||
if ((pfn_start <= vma->pfn_start) && (pfn_end > vma->pfn_start)) {
|
||||
printf("%s: VMAs overlap.\n", __FUNCTION__);
|
||||
return 1;
|
||||
}
|
||||
if ((pfn_end >= vma->pfn_end) && (pfn_start < vma->pfn_end)) {
|
||||
printf("%s: VMAs overlap.\n", __FUNCTION__);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Search an empty space in the task's mmapable address region. */
|
||||
unsigned long find_unmapped_area(unsigned long npages, struct tcb *task)
|
||||
{
|
||||
@@ -72,7 +59,8 @@ unsigned long find_unmapped_area(unsigned long npages, struct tcb *task)
|
||||
while (pfn_end <= __pfn(task->end)) {
|
||||
|
||||
/* If intersection, skip the vma and fast-forward to next */
|
||||
if (vma_intersect(pfn_start, pfn_end, vma)) {
|
||||
if (set_intersection(pfn_start, pfn_end,
|
||||
vma->pfn_start, vma->pfn_end)) {
|
||||
|
||||
/* Update interval to next available space */
|
||||
pfn_start = vma->pfn_end;
|
||||
@@ -204,8 +192,9 @@ void *do_mmap(struct vm_file *mapfile, unsigned long file_offset,
|
||||
* splitting, shrink/grow etc.
|
||||
*/
|
||||
list_for_each_entry(mapped, &task->vm_area_head->list, list)
|
||||
BUG_ON(vma_intersect(map_pfn, map_pfn + npages,
|
||||
mapped));
|
||||
BUG_ON(set_intersection(map_pfn, map_pfn + npages,
|
||||
mapped->pfn_start,
|
||||
mapped->pfn_end));
|
||||
}
|
||||
|
||||
/* For valid regions that aren't allocated by us, create the vma. */
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <mmap.h>
|
||||
#include <file.h>
|
||||
#include <l4/api/errno.h>
|
||||
#include <l4/lib/math.h>
|
||||
#include <l4lib/arch/syslib.h>
|
||||
|
||||
|
||||
@@ -134,7 +135,8 @@ int do_munmap(struct tcb *task, void *vaddr, unsigned long npages)
|
||||
|
||||
list_for_each_entry_safe(vma, n, &task->vm_area_head->list, list) {
|
||||
/* Check for intersection */
|
||||
if (vma_intersect(munmap_start, munmap_end, vma)) {
|
||||
if (set_intersection(munmap_start, munmap_end,
|
||||
vma->pfn_start, vma->pfn_end)) {
|
||||
/*
|
||||
* Flush pages if vma is writable,
|
||||
* dirty and file-backed.
|
||||
|
||||
Reference in New Issue
Block a user