vm_reallocate
Function - Reallocate a region of virtual memory.
SYNOPSIS
kern_return_t vm_reallocate
(vm_task_t target_task,
vm_address_t src,
vm_size_t src_size,
vm_address_t *dst,
vm_size_t dst_size,
vm_offset_t align_mask,
int options,
int flags);
PARAMETERS
- target_task
-
[in task send right]
The port for the task whose address space the region is to be reallocated in.
- src
-
[in scalar]
The starting address for the source region.
- src_size
-
[in scalar]
The size of the source region in bytes.
- dst
-
[pointer to in/out scalar]
The starting address for the destination region, or a minimum address hint,
depending on flags.
- dst_size
-
[in scalar]
The size of the destination region in bytes; must be at least src_size.
- align_mask
-
[in scalar]
Alignment bitmask for destination address. Must be of the form (2^n - 1). The
result of align_mask | page_mask will be used for
alignment.
- options
-
[in scalar]
Reallocation options.
- VM_REALLOCATE_DEALLOCATE_SOURCE
-
The kernel deallocates the source.
- VM_REALLOCATE_ZERO_FILL_SOURCE
-
The kernel zero-fills the source.
- flags
-
[in scalar]
Flags that determine how the destination address is interpreted. The user tag
is passed in the high order byte.
- VM_FLAGS_ANYWHERE
-
The kernel will find an address, starting from *dst, to place the
reallocated region.
- VM_FLAGS_FIXED
-
The kernel will attempt to place the reallocated region directly at
*dst, and will fail if the address range is already mapped.
- VM_FLAGS_OVERWRITE
-
The kernel will overwrite any existing allocations when
VM_FLAGS_FIXED is specified. All dst_size bytes of
the destination must already be mapped without holes. On failure, the contents
of the destination are undefined, and should not be relied upon.
DESCRIPTION
The vm_reallocate function causes the src_size bytes
starting at address src to be reallocated as dst_size
bytes, and writes the new address to *dst.
If KERN_SUCCESS is returned, the data will only be accessible
through *dst. This restriction allows reallocation without making any
copies of the source data. Using vm_reallocate is therefore
more efficient than creating a new allocation and using memcpy
or vm_copy to "reallocate" memory.
The expanded region will be zero-filled.
vm_reallocate affects only target_task. Other tasks
that have access to the deallocated memory can continue to reference it.
NOTES
vm_deallocate can be used to deallocate memory passed
as out-of-line data in a
message.
RETURN VALUES
- KERN_INVALID_ARGUMENT
-
Unsupported Mach VM flags are specified in flags.
- KERN_INVALID_ARGUMENT
-
An unsupported reallocation option is specified in options.
KERN_INVALID_ARGUMENT
dst_size or src_size is not a multiple of
PAGE_SIZE.
KERN_INVALID_ARGUMENT
dst_size is smaller than src_size.
KERN_INVALID_ADDRESS
src is not page-aligned.
KERN_INVALID_ADDRESS
VM_FLAGS_FIXED is specified, and *dst is not
page/align_mask-aligned.
KERN_INVALID_ADDRESS
Any portion of [src, src + src_size) is not
mapped, is permanent, or is a sub-map.
KERN_INVALID_ADDRESS
VM_FLAGS_FIXED | VM_FLAGS_OVERWRITE specified,
and [dst, dst + dst_size) overlaps
[src, src + src_size).
KERN_NO_SPACE
VM_FLAGS_ANYWHERE is specified, and no contiguous range of
dst_size bytes could be found at or after *dst.
KERN_NO_SPACE
VM_FLAGS_FIXED is specified without
VM_FLAGS_OVERWRITE and any portion of [*dst,
*dst + dst_size) is already mapped.
KERN_NOT_SUPPORTED
The process is running with non-native page size (e.g., Rosetta).
KERN_NOT_SUPPORTED
Otherwise, vm_reallocate cannot perform the reallocation.
RELATED INFORMATION
Functions:
mach_msg,
vm_allocate,
vm_deallocate,
host_page_size.