Fixes VMR creating off-by-one
authorBarret Rhoden <brho@cs.berkeley.edu>
Thu, 2 Apr 2015 14:15:44 +0000 (10:15 -0400)
committerBarret Rhoden <brho@cs.berkeley.edu>
Tue, 7 Apr 2015 19:06:59 +0000 (15:06 -0400)
If a VMR would just barely fit before the first VMR, we would fail to
use that slot.

Practically, this only happens if you decide to do a MAP_FIXED at a low
address, which will unmap a chunk of ld.so - not recommended!

kern/arch/x86/ros/mmu64.h
kern/src/mm.c

index be2058e..9e692be 100644 (file)
@@ -118,6 +118,13 @@ typedef struct x86_pgdir {
  *                     |     Program Data & Heap      |
  *                     |                              |
  *                     +------------------------------+ 0x0000000000400000
+ *                     .                              .
+ *                     .                              .
+ *                     |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
+ *                     |                              |
+ *                     |       ld.so (Dynamic)        |
+ *                     |                              |
+ * MMAP_LOWEST_VA      +------------------------------+ 0x0000000000100000
  *                     |                              |
  *                     |       Empty Memory (*)       |
  *                     |                              |
index 2b10536..bf93513 100644 (file)
@@ -58,7 +58,7 @@ struct vm_region *create_vmr(struct proc *p, uintptr_t va, size_t len)
        vm_i = TAILQ_FIRST(&p->vm_regions);
        /* This works for now, but if all we have is BRK_END ones, we'll start
         * growing backwards (TODO) */
-       if (!vm_i || (va + len < vm_i->vm_base)) {
+       if (!vm_i || (va + len <= vm_i->vm_base)) {
                vmr = kmem_cache_alloc(vmr_kcache, 0);
                if (!vmr)
                        panic("EOM!");