From 47de55da04390dc6519374dbd6cd9d3f2a9400c6 Mon Sep 17 00:00:00 2001 From: kib Date: Tue, 24 Feb 2009 20:43:29 +0000 Subject: Add the assertion macros for the map locks. Use them in several map manipulation functions. Tested by: pho Reviewed by: alc --- sys/vm/vm_map.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'sys/vm') diff --git a/sys/vm/vm_map.c b/sys/vm/vm_map.c index ea90a70..6e6918f 100644 --- a/sys/vm/vm_map.c +++ b/sys/vm/vm_map.c @@ -573,6 +573,38 @@ vm_map_locked(vm_map_t map) return (sx_xlocked(&map->lock)); } +#ifdef INVARIANTS +static void +_vm_map_assert_locked(vm_map_t map, const char *file, int line) +{ + + if (map->system_map) + _mtx_assert(&map->system_mtx, MA_OWNED, file, line); + else + _sx_assert(&map->lock, SA_XLOCKED, file, line); +} + +#if 0 +static void +_vm_map_assert_locked_read(vm_map_t map, const char *file, int line) +{ + + if (map->system_map) + _mtx_assert(&map->system_mtx, MA_OWNED, file, line); + else + _sx_assert(&map->lock, SA_SLOCKED, file, line); +} +#endif + +#define VM_MAP_ASSERT_LOCKED(map) \ + _vm_map_assert_locked(map, LOCK_FILE, LOCK_LINE) +#define VM_MAP_ASSERT_LOCKED_READ(map) \ + _vm_map_assert_locked_read(map, LOCK_FILE, LOCK_LINE) +#else +#define VM_MAP_ASSERT_LOCKED(map) +#define VM_MAP_ASSERT_LOCKED_READ(map) +#endif + /* * vm_map_unlock_and_wait: */ @@ -846,6 +878,7 @@ vm_map_entry_link(vm_map_t map, CTR4(KTR_VM, "vm_map_entry_link: map %p, nentries %d, entry %p, after %p", map, map->nentries, entry, after_where); + VM_MAP_ASSERT_LOCKED(map); map->nentries++; entry->prev = after_where; entry->next = after_where->next; @@ -876,6 +909,7 @@ vm_map_entry_unlink(vm_map_t map, { vm_map_entry_t next, prev, root; + VM_MAP_ASSERT_LOCKED(map); if (entry != map->root) vm_map_entry_splay(entry->start, map->root); if (entry->left == NULL) @@ -1025,6 +1059,8 @@ vm_map_insert(vm_map_t map, vm_object_t object, vm_ooffset_t offset, vm_map_entry_t temp_entry; vm_eflags_t protoeflags; + VM_MAP_ASSERT_LOCKED(map); + /* * Check that the start and end points are not bogus. */ @@ -1416,6 +1452,8 @@ _vm_map_clip_start(vm_map_t map, vm_map_entry_t entry, vm_offset_t start) { vm_map_entry_t new_entry; + VM_MAP_ASSERT_LOCKED(map); + /* * Split off the front portion -- note that we must insert the new * entry BEFORE this one, so that this entry has the specified @@ -1474,6 +1512,8 @@ _vm_map_clip_end(vm_map_t map, vm_map_entry_t entry, vm_offset_t end) { vm_map_entry_t new_entry; + VM_MAP_ASSERT_LOCKED(map); + /* * If there is no object backing this entry, we might as well create * one now. If we defer it, an object can get created after the map @@ -2461,6 +2501,8 @@ vm_map_delete(vm_map_t map, vm_offset_t start, vm_offset_t end, vm_map_entry_t entry; vm_map_entry_t first_entry; + VM_MAP_ASSERT_LOCKED(map); + /* * Find the start of the region, and clip it */ @@ -2621,6 +2663,8 @@ vm_map_copy_entry( { vm_object_t src_object; + VM_MAP_ASSERT_LOCKED(dst_map); + if ((dst_entry->eflags|src_entry->eflags) & MAP_ENTRY_IS_SUB_MAP) return; -- cgit v1.1