From bdcafee412ab6eec58f6b315e16e57fe3dad002f Mon Sep 17 00:00:00 2001 From: Sergey Bugaev Date: Wed, 5 Jul 2023 17:16:37 +0300 Subject: vm: Make vm_object_coalesce return new object and offset vm_object_coalesce() callers used to rely on the fact that it always merged the next_object into prev_object, potentially destroying next_object and leaving prev_object the result of the whole operation. After ee65849bec5da261be90f565bee096abb4117bdd "vm: Allow coalescing null object with an internal object", this is no longer true, since in case of prev_object == VM_OBJECT_NULL and next_object != VM_OBJECT_NULL, the overall result is next_object, not prev_object. The current callers are prepared to deal with this since they handle this case seprately anyway, but the following commit will introduce another caller that handles both cases in the same code path. So, declare the way vm_object_coalesce() coalesces the two objects its implementation detail, and make it return the resulting object and the offset into it explicitly. This simplifies the callers, too. Message-Id: <20230705141639.85792-2-bugaevc@gmail.com> --- vm/vm_map.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'vm/vm_map.c') diff --git a/vm/vm_map.c b/vm/vm_map.c index 62fb87b9..55a822af 100644 --- a/vm/vm_map.c +++ b/vm/vm_map.c @@ -1064,7 +1064,9 @@ kern_return_t vm_map_enter( entry->offset, offset, (vm_size_t)(entry->vme_end - entry->vme_start), - size)) { + size, + &entry->object.vm_object, + &entry->offset)) { /* * Coalesced the two objects - can extend @@ -1074,7 +1076,6 @@ kern_return_t vm_map_enter( map->size += size; entry->vme_end = end; vm_map_gap_update(&map->hdr, entry); - vm_object_deallocate(object); RETURN(KERN_SUCCESS); } } @@ -1092,7 +1093,9 @@ kern_return_t vm_map_enter( offset, next_entry->offset, size, - (vm_size_t)(next_entry->vme_end - next_entry->vme_start))) { + (vm_size_t)(next_entry->vme_end - next_entry->vme_start), + &next_entry->object.vm_object, + &next_entry->offset)) { /* * Coalesced the two objects - can extend @@ -1101,9 +1104,7 @@ kern_return_t vm_map_enter( */ map->size += size; next_entry->vme_start = start; - next_entry->offset -= size; vm_map_gap_update(&map->hdr, entry); - vm_object_deallocate(object); RETURN(KERN_SUCCESS); } } -- cgit v1.2.3