From 787a6034170b59d55afe8d0a12cb0904f20cb74d Mon Sep 17 00:00:00 2001 From: Justus Winter <4winter@informatik.uni-hamburg.de> Date: Sun, 16 Aug 2015 02:18:47 +0200 Subject: codify locking contracts Conflicts: vm/vm_page.h --- vm/vm_object.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'vm/vm_object.c') diff --git a/vm/vm_object.c b/vm/vm_object.c index 4b31482..836f5ef 100644 --- a/vm/vm_object.c +++ b/vm/vm_object.c @@ -188,6 +188,8 @@ struct lock vm_object_cache_lock_data; lock_try_write(&vm_object_cache_lock_data) #define vm_object_cache_unlock() \ lock_write_done(&vm_object_cache_lock_data) +#define have_vm_object_cache_lock() \ + have_write_lock(&vm_object_cache_lock_data) /* * Number of physical pages referenced by cached objects. @@ -516,7 +518,6 @@ void vm_object_deallocate( * Destroy the object; the cache lock will * be released in the process. */ - vm_object_terminate(object); /* @@ -554,6 +555,9 @@ void vm_object_terminate( vm_external_t existence_info; #endif /* MACH_PAGEMAP */ + assert(have_vm_object_lock(object)); + assert(have_vm_object_cache_lock()); + /* * Make sure the object isn't already being terminated */ @@ -754,6 +758,8 @@ void vm_object_abort_activity( vm_page_t p; vm_page_t next; + assert(have_vm_object_lock(object)); + /* * Abort all activity that would be waiting * for a result on this memory object. @@ -791,6 +797,7 @@ void vm_object_abort_activity( object->pager_ready = TRUE; vm_object_wakeup(object, VM_OBJECT_EVENT_PAGER_READY); + assert(have_vm_object_lock(object)); } /* @@ -889,6 +896,7 @@ void vm_object_deactivate_pages( { vm_page_t p; + assert(have_vm_object_lock(object)); queue_iterate(&object->memq, p, vm_page_t, listq) { vm_page_lock_queues(); if (!p->busy) @@ -1348,6 +1356,8 @@ kern_return_t vm_object_copy_call( vm_object_t new_object; vm_page_t p; + assert(have_vm_object_lock(src_object)); + /* * Create a memory object port to be associated * with this new vm_object. @@ -2196,6 +2206,7 @@ restart: /* * [At this point, the object must be locked] */ + assert(have_vm_object_lock(object)); /* * Wait for the work above to be done by the first @@ -2325,6 +2336,8 @@ void vm_object_remove( { ipc_port_t port; + assert(have_vm_object_cache_lock()); + if ((port = object->pager) != IP_NULL) { if (ip_kotype(port) == IKOT_PAGER) ipc_kobject_set(port, IKO_NULL, @@ -2380,6 +2393,8 @@ void vm_object_collapse( vm_page_t p, pp; ipc_port_t old_name_port; + assert(have_vm_object_lock(object)); + if (!vm_object_collapse_allowed) return; @@ -2729,6 +2744,8 @@ void vm_object_page_remove( { vm_page_t p, next; + assert(have_vm_object_lock(object)); + /* * One and two page removals are most popular. * The factor of 16 here is somewhat arbitrary. -- cgit v1.2.3