mirror of
https://github.com/drasko/codezero.git
synced 2026-11-25 02:13:53 +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:
@@ -4,4 +4,19 @@
|
|||||||
#define min(x, y) (((x) < (y)) ? x : y)
|
#define min(x, y) (((x) < (y)) ? x : y)
|
||||||
#define max(x, y) (((x) > (y)) ? x : y)
|
#define max(x, y) (((x) > (y)) ? x : y)
|
||||||
|
|
||||||
|
/* Tests if ranges a-b intersect with range c-d */
|
||||||
|
static inline int set_intersection(unsigned long a, unsigned long b,
|
||||||
|
unsigned long c, unsigned long d)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* Below is the complement (') of the intersection
|
||||||
|
* of 2 ranges, much simpler ;-)
|
||||||
|
*/
|
||||||
|
if (b <= c || a >= d)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
/* The rest is always intersecting */
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* __LIB_MATH_H__ */
|
#endif /* __LIB_MATH_H__ */
|
||||||
|
|||||||
@@ -183,8 +183,6 @@ struct vm_area {
|
|||||||
unsigned long file_offset; /* File offset in pfns */
|
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.
|
* Finds the vma that has the given address.
|
||||||
* TODO: In the future a lot of use cases may need to traverse each vma
|
* TODO: In the future a lot of use cases may need to traverse each vma
|
||||||
|
|||||||
+6
-17
@@ -3,6 +3,7 @@
|
|||||||
*
|
*
|
||||||
* Copyright (C) 2007, 2008 Bahadir Balban
|
* Copyright (C) 2007, 2008 Bahadir Balban
|
||||||
*/
|
*/
|
||||||
|
#include <l4/lib/math.h>
|
||||||
#include <vm_area.h>
|
#include <vm_area.h>
|
||||||
#include <kmalloc/kmalloc.h>
|
#include <kmalloc/kmalloc.h>
|
||||||
#include INC_API(errno.h)
|
#include INC_API(errno.h)
|
||||||
@@ -37,20 +38,6 @@ struct vm_area *vma_new(unsigned long pfn_start, unsigned long npages,
|
|||||||
return vma;
|
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. */
|
/* Search an empty space in the task's mmapable address region. */
|
||||||
unsigned long find_unmapped_area(unsigned long npages, struct tcb *task)
|
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)) {
|
while (pfn_end <= __pfn(task->end)) {
|
||||||
|
|
||||||
/* If intersection, skip the vma and fast-forward to next */
|
/* 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 */
|
/* Update interval to next available space */
|
||||||
pfn_start = vma->pfn_end;
|
pfn_start = vma->pfn_end;
|
||||||
@@ -204,8 +192,9 @@ void *do_mmap(struct vm_file *mapfile, unsigned long file_offset,
|
|||||||
* splitting, shrink/grow etc.
|
* splitting, shrink/grow etc.
|
||||||
*/
|
*/
|
||||||
list_for_each_entry(mapped, &task->vm_area_head->list, list)
|
list_for_each_entry(mapped, &task->vm_area_head->list, list)
|
||||||
BUG_ON(vma_intersect(map_pfn, map_pfn + npages,
|
BUG_ON(set_intersection(map_pfn, map_pfn + npages,
|
||||||
mapped));
|
mapped->pfn_start,
|
||||||
|
mapped->pfn_end));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* For valid regions that aren't allocated by us, create the vma. */
|
/* For valid regions that aren't allocated by us, create the vma. */
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
#include <mmap.h>
|
#include <mmap.h>
|
||||||
#include <file.h>
|
#include <file.h>
|
||||||
#include <l4/api/errno.h>
|
#include <l4/api/errno.h>
|
||||||
|
#include <l4/lib/math.h>
|
||||||
#include <l4lib/arch/syslib.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) {
|
list_for_each_entry_safe(vma, n, &task->vm_area_head->list, list) {
|
||||||
/* Check for intersection */
|
/* 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,
|
* Flush pages if vma is writable,
|
||||||
* dirty and file-backed.
|
* dirty and file-backed.
|
||||||
|
|||||||
Reference in New Issue
Block a user