sys_mmap  [arch/i386/kernel/sys_i386.c]


Maps files or devices into memory. This system call can be used for dynamic memory allocation.

Arguments

eax 90
ebx Pointer to a properly initialized mmap_arg_struct structure:
struc mmap_arg_struct
{
.addr   rd 1
.len    rd 1
.prot   rd 1
.flags  rd 1
.fd     rd 1
.offset rd 1
}

mmap_arg_struct members:

addr

Address where pages will be mapped. If it's non-zero, it is used as a hint to the system. (As a convenience to the system, the actual address of the region may differ from the address supplied.) If it's zero, an address will be selected by the system.
len
Size of the mapped region.
prot
Protection flags:
PROT_EXEC Pages may be executed.
PROT_READ Pages may be read.
PROT_WRITE Pages may be written.
flags
Mode flags:
MAP_ANON Map anonymous memory not associated with any specific file. The file descriptor used for creating MAP_ANON regions is used only for naming, and may be specified as -1 if no name is associated with the region.
MAP_FILE Mapped from a regular file or character-special device memory. (This is the default mapping type, and need not be specified.)
MAP_FIXED Do not permit the system to select a different address than the one specified. If the specified address cannot be used, sys_mmap will fail. If MAP_FIXED is specified, ebx must be a multiple of the pagesize. Use of this option is discouraged.
MAP_HASSEMAPHORE Notify the kernel that the region may contain semaphores and that special handling may be necessary.
MAP_PRIVATE Modifications are private.
MAP_SHARED Modifications are shared.
fd
File descriptor. See mode flags descriptions for more info.
offset
Offset (within the file) of the data to be mapped. It's ignored if MAP_ANON is specified.

Return values

If the system call succeeds the return value is a pointer to the mapped region.
If the system call fails the return value is one of the following errno values:

-EACCES The flag PROT_READ was specified as part of the prot and file was not open for reading. The flags PROT_WRITE and MAP_SHARED were specified as part of the prot and flags arguments and file was not open for writing.
-EBADF fd is not a valid open file descriptor.
-EINVAL MAP_FIXED was specified and the parameter was not page aligned. fd did not reference a regular or character special file.
-ENOMEM MAP_FIXED was specified and the len wasn't available. MAP_ANON was specified and insufficient memory was available.
-EFAULT ebx points to an invalid address.

Remarks

To unmap pages sys_munmap should be used.

Compatibility

n/a