sys_mremap [mm/mremap.c]
Expands (or shrinks) an existing memory mapping, potentially moving it at the same time. In Linux the memory is divided into pages. A user process has (one or) several linear virtual memory segments. Each virtual memory segment has one or more mappings to real memory pages (in the page table). Each virtual memory segment has its own protection (access rights), which may cause a segmentation violation if the memory is accessed incorrectly (e.g., writing to a read-only segment). Accessing virtual memory outside of the segments will also cause a segmentation violation. Arguments
eax | 163
ebx | Old address of the virtual memory block that you want to expand (or shrink). It has to be page aligned.
ecx | Old size of the virtual memory block
edx | Requested size of the virtual memory block after the resize.
esi | Flags:
`MREMAP_MAYMOVE` | `By default, if there is not sufficient space to expand a mapping at its current location, then sys_mremap fails. If this flag is specified, then the kernel is permitted to relocate the mapping to a new virtual address, if necessary. If the mapping is relocated, then absolute pointers into the old mapping location become invalid (offsets relative to the starting address of the mapping should be employed).`
`MREMAP_FIXED` | `This flag serves a similar purpose to the MAP_FIXED flag of sys_mmap. If this flag is specified, then sys_mremap accepts a fifth argument, edi, which specifies a page-aligned address to which the mapping must be moved. Any previous mapping at the address range specified by edi and edx is unmapped. If MREMAP_FIXED is specified, then MREMAP_MAYMOVE must also be specified.`
edi | New address. This argument is valid only if MREMAP_FIXED is specified.
Return values If the system call succeeds the return value is a pointer to the new virtual memory area. If the system call fails the return value is one of the following errno values:
`-EAGAIN` | `The caller tried to expand a memory segment that is locked, but this was not possible without exceeding the RLIMIT_MEMLOCK resource limit.`
`-EFAULT` | `"Segmentation fault." Some address in the range ebx to ebx+ecx is an invalid virtual memory address for this process. You can also get EFAULT even if there exist mappings that cover the whole address space requested, but those mappings are of different types.`
`-EINVAL` | `An invalid argument was given. Possible causes are: ebx was not page aligned; a value other than MREMAP_MAYMOVE or MREMAP_FIXED was specified in esi; edx was zero; edx or edi was invalid; or the new address range specified by edi and edx overlapped the old address range specified by ebx and ecx; or MREMAP_FIXED was specified without also specifying MREMAP_MAYMOVE.`
`-ENOMEM` | `The memory area cannot be expanded at the current virtual address, and the MREMAP_MAYMOVE flag is not set in esi. Or, there is not enough (virtual) memory available.`
Remarks If the memory segment specified by ebx and ecx is locked (using sys_mlock or similar), then this lock is maintained when the segment is resized and/or relocated. As a consequence, the amount of memory locked by the process may change. Compatibility n/a