summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien Zammit <damien@zamaudio.com>2024-02-23 08:15:11 +0000
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2024-02-23 14:14:52 +0100
commite5872f2d6a0129dfc4a564b8af8a0f45dcdce86c (patch)
tree54df87f9773f4293d5ccd06750f601db72674759
parent082831b9a62c7582635c564791d329e2477e2de4 (diff)
vm_map: Add comment and assert for vm_map_deletemaster
This will prevent calling vm_map_delete without the map locked unless ref_count is zero. Message-ID: <20240223081505.458240-1-damien@zamaudio.com>
-rw-r--r--vm/vm_map.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/vm/vm_map.c b/vm/vm_map.c
index c237afbe..7db76b7b 100644
--- a/vm/vm_map.c
+++ b/vm/vm_map.c
@@ -551,10 +551,12 @@ void vm_map_deallocate(vm_map_t map)
c = --map->ref_count;
simple_unlock(&map->ref_lock);
+ /* Check the refcount */
if (c > 0) {
return;
}
+ /* If no more references, call vm_map_delete without locking the map */
projected_buffer_collect(map);
(void) vm_map_delete(map, map->min_offset, map->max_offset);
@@ -2029,6 +2031,11 @@ kern_return_t vm_map_delete(
panic("vm_map_delete(%lx-%lx) falls in physical memory area!\n", (unsigned long) start, (unsigned long) end);
/*
+ * Must be called with map lock taken unless refcount is zero
+ */
+ assert((map->ref_count > 0 && have_lock(map->lock)) || (map->ref_count == 0));
+
+ /*
* Find the start of the region, and clip it
*/