memory-mapping interface (userspace).
More...
Go to the source code of this file.
|
| void * | mmap (void *addr, size_t length, int prot, int flags, int fd, off_t offset) |
| | map memory into the calling process's address space.
|
| int | munmap (void *addr, size_t length) |
| | remove the mappings in [addr, addr + length).
|
| int | mprotect (void *addr, size_t length, int prot) |
| | change the protection of [addr, addr + length), which must be mapped.
|
| int | shm_create (size_t size, int fd_flags) |
| | make a shared memory object (a ginnOS call, like Linux's memfd_create): size bytes of zeroed memory, rounded up to whole pages.
|
memory-mapping interface (userspace).
the prot/flag values here are ABI and must match the kernel side in src/kernel/memory/mman.h exactly.
◆ PROT_NONE
◆ PROT_READ
◆ PROT_WRITE
◆ PROT_EXEC
◆ MAP_SHARED
◆ MAP_PRIVATE
◆ MAP_ANONYMOUS
| #define MAP_ANONYMOUS 0x04 |
◆ MAP_FIXED
◆ MAP_FAILED
| #define MAP_FAILED ((void *)-1) |
◆ mmap()
| void * mmap |
( |
void * | addr, |
|
|
size_t | length, |
|
|
int | prot, |
|
|
int | flags, |
|
|
int | fd, |
|
|
off_t | offset ) |
map memory into the calling process's address space.
two forms are supported:
- anonymous (flags has MAP_ANONYMOUS, fd < 0): zero-filled pages.
- device-backed (fd is an open device node such as "/dev/fb0"): maps the device's memory (e.g. the linear framebuffer). with MAP_FIXED the mapping goes exactly at
addr (page-aligned), replacing anything mapped there; otherwise addr is a hint the kernel uses if that range is free, else it picks a free range in its mmap region.
- Parameters
-
| addr | address (MAP_FIXED) or hint (may be NULL). |
| length | number of bytes to map (rounded up to a page). |
| prot | protection bits (PROT_*). |
| flags | mapping flags (MAP_*). |
| fd | device fd for a device-backed mapping, or -1 for anonymous. |
| offset | byte offset into the file or device (a multiple of the page size, else EINVAL). |
- Returns
- the mapped address on success, or MAP_FAILED on error (errno set).
◆ munmap()
| int munmap |
( |
void * | addr, |
|
|
size_t | length ) |
remove the mappings in [addr, addr + length).
- Parameters
-
| addr | page-aligned start. |
| length | number of bytes (rounded up to a page). |
- Returns
- 0 on success, -1 on error (errno set).
◆ mprotect()
| int mprotect |
( |
void * | addr, |
|
|
size_t | length, |
|
|
int | prot ) |
change the protection of [addr, addr + length), which must be mapped.
- Parameters
-
| addr | page-aligned start. |
| length | number of bytes (rounded up to a page). |
| prot | the new PROT_* bits. |
- Returns
- 0 on success, -1 on error (errno set; ENOMEM if part of the range is not mapped).
◆ shm_create()
| int shm_create |
( |
size_t | size, |
|
|
int | fd_flags ) |
make a shared memory object (a ginnOS call, like Linux's memfd_create): size bytes of zeroed memory, rounded up to whole pages.
every mmap of the returned fd (MAP_SHARED), in this process or another one that has the fd (through fork, or sent over a socket), maps the same memory.
- Parameters
-
| size | the size in bytes. |
| fd_flags | FD_CLOEXEC or 0. |
- Returns
- the fd (open read-write), or -1 with errno set.