Skip to content

Commit

Permalink
Restore VMA list assertions, at least for the debug build. (graminepr…
Browse files Browse the repository at this point in the history
  • Loading branch information
donporter authored and chiache committed Jul 6, 2018
1 parent 37c2aae commit 256f39c
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions LibOS/shim/src/bookkeep/shim_vma.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,15 @@ static inline void __assert_vma_list (void)
}
}

// In a debug build only, assert that the VMA list is
// sorted. This should be called with the vma_list_lock held.
static inline void assert_vma_list (void)
{
#ifdef DEBUG
__assert_vma_list();
#endif
}

/*
* __lookup_vma() returns the VMA that contains the address; otherwise,
* returns NULL. "pprev" returns the highest VMA below the address.
Expand Down Expand Up @@ -488,6 +497,7 @@ int bkeep_mmap (void * addr, uint64_t length, int prot, int flags,
__lookup_vma(addr, &prev);
int ret = __bkeep_mmap(prev, addr, addr + length, prot, flags, file, offset,
comment);
assert_vma_list();
__restore_reserved_vmas();
unlock(vma_list_lock);
return ret;
Expand Down Expand Up @@ -667,6 +677,7 @@ int bkeep_munmap (void * addr, uint64_t length, int flags)
struct shim_vma * prev = NULL;
__lookup_vma(addr, &prev);
int ret = __bkeep_munmap(&prev, addr, addr + length, flags);
assert_vma_list();
__restore_reserved_vmas();
unlock(vma_list_lock);
return ret;
Expand Down Expand Up @@ -777,6 +788,7 @@ int bkeep_mprotect (void * addr, uint64_t length, int prot, int flags)
struct shim_vma * prev = NULL;
__lookup_vma(addr, &prev);
int ret = __bkeep_mprotect(prev, addr, addr + length, prot, flags);
assert_vma_list();
__restore_reserved_vmas();
unlock(vma_list_lock);
return ret;
Expand Down Expand Up @@ -814,6 +826,7 @@ static void * __bkeep_unmapped (void * top_addr, void * bottom_addr,
/* create a new VMA at the top of the range */
__bkeep_mmap(prev, end - length, end, prot, flags,
file, offset, comment);
assert_vma_list();

debug("bkeep_unmapped: %p-%p%s%s\n", end - length, end,
comment ? " => " : "", comment ? : "");
Expand All @@ -838,6 +851,7 @@ void * bkeep_unmapped (void * top_addr, void * bottom_addr, uint64_t length,
lock(vma_list_lock);
void * addr = __bkeep_unmapped(top_addr, bottom_addr, length, prot, flags,
file, offset, comment);
assert_vma_list();
__restore_reserved_vmas();
unlock(vma_list_lock);
return addr;
Expand Down Expand Up @@ -878,6 +892,7 @@ void * bkeep_unmapped_heap (uint64_t length, int prot, int flags,
addr = __bkeep_unmapped(top_addr, bottom_addr,
length, prot, flags,
file, offset, comment);
assert_vma_list();

if (addr) {
/*
Expand All @@ -899,6 +914,7 @@ void * bkeep_unmapped_heap (uint64_t length, int prot, int flags,
addr = __bkeep_unmapped(heap_max, bottom_addr,
length, prot, flags,
file, offset, comment);
assert_vma_list();

out:
__restore_reserved_vmas();
Expand Down

0 comments on commit 256f39c

Please sign in to comment.