[PATCH] prevent NULL mmap in topdown model

From: Rik van Riel
Date: Wed May 18 2005 - 15:03:24 EST


This (trivial) patch prevents the topdown allocator from allocating
mmap areas all the way down to address zero. It's not the prettiest
patch, so suggestions for improvement are welcome ;)

Signed-off-by: Rik van Riel <riel@xxxxxxxxxx>

--- linux-2.6.11/mm/mmap.c.nullptr 2005-05-17 23:07:26.000000000 -0400
+++ linux-2.6.11/mm/mmap.c 2005-05-17 23:18:53.000000000 -0400
@@ -1251,7 +1251,7 @@
addr = mm->free_area_cache;

/* make sure it can fit in the remaining address space */
- if (addr >= len) {
+ if (addr >= (len + mm->brk)) {
vma = find_vma(mm, addr-len);
if (!vma || addr <= vma->vm_start)
/* remember the address as a hint for next time */
@@ -1267,13 +1267,13 @@
* return with success:
*/
vma = find_vma(mm, addr);
- if (!vma || addr+len <= vma->vm_start)
+ if ((!vma || addr+len <= vma->vm_start) && addr > mm->brk)
/* remember the address as a hint for next time */
return (mm->free_area_cache = addr);

/* try just below the current vma->vm_start */
addr = vma->vm_start-len;
- } while (len <= vma->vm_start);
+ } while (len <= vma->vm_start && addr > mm->brk);

/*
* A failed mmap() very likely causes application failure,
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/