From 13b2f36d85756df7088be24acdcf847944b6b9ef Mon Sep 17 00:00:00 2001 From: Damien Zammit Date: Thu, 22 Feb 2024 08:24:32 +0000 Subject: vm_map_lookup: Add parameter for keeping map locked This adds a parameter called keep_map_locked to vm_map_lookup() that allows the function to return with the map locked. This is to prepare for fixing a bug with gsync where the map is locked twice by mistake. Co-Authored-By: Sergey Bugaev Message-ID: <20240222082410.422869-3-damien@zamaudio.com> --- vm/vm_map.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'vm/vm_map.c') diff --git a/vm/vm_map.c b/vm/vm_map.c index e454bb2a..c237afbe 100644 --- a/vm/vm_map.c +++ b/vm/vm_map.c @@ -4607,8 +4607,9 @@ vm_map_t vm_map_fork(vm_map_t old_map) * In order to later verify this lookup, a "version" * is returned. * - * The map should not be locked; it will not be - * locked on exit. In order to guarantee the + * The map should not be locked; it will be + * unlocked on exit unless keep_map_locked is set and + * the lookup succeeds. In order to guarantee the * existence of the returned object, it is returned * locked. * @@ -4621,6 +4622,7 @@ kern_return_t vm_map_lookup( vm_map_t *var_map, /* IN/OUT */ vm_offset_t vaddr, vm_prot_t fault_type, + boolean_t keep_map_locked, vm_map_version_t *out_version, /* OUT */ vm_object_t *object, /* OUT */ @@ -4642,7 +4644,8 @@ kern_return_t vm_map_lookup( #define RETURN(why) \ { \ - vm_map_unlock_read(map); \ + if (!(keep_map_locked && (why == KERN_SUCCESS))) \ + vm_map_unlock_read(map); \ return(why); \ } -- cgit v1.2.3