mremap(): don't remove existing vmap when returning an error
If mremap() returns error, it should keep the existing mapping as
is, so rangemap_remove_node() should be called only after checking
for all possible error conditions.
@@ -317,10 +317,6 @@ sysreturn mremap(void *old_address, u64 old_size, u64 new_size, int flags, void
/* remove old mapping, preserving attributes */
u64 vmflags = old_vm->flags;
- /* we're moving the vmap to a new address region, so we can safely remove
- * the old node entirely */
- rangemap_remove_node(p->vmaps, &old_vm->node);
-
/* new virtual allocation */
u64 maplen = pad(new_size, vh->pagesize);
u64 vnew = allocate_u64(vh, maplen);
@@ -349,6 +345,10 @@ sysreturn mremap(void *old_address, u64 old_size, u64 new_size, int flags, void
}
thread_log(current, " new physical pages at 0x%lx, size %ld", dphys, dlen);
+ /* we're moving the vmap to a new address region, so we can safely remove
+ * the old node entirely */
+ rangemap_remove_node(p->vmaps, &old_vm->node);
+
/*
* XXX : if we decide to handle MREMAP_FIXED, we'll need to be careful about
* making sure destination address ranges are unmapped before mapping over them
