The manual
ginnOS
The reference: libc, the libraries and the kernel
Toggle main menu visibility
Loading...
Searching...
No Matches
mman.h
Go to the documentation of this file.
1
#pragma once
2
3
#include <
sys/types.h
>
4
5
/**
6
* @file sys/mman.h
7
* @brief memory-mapping interface (userspace).
8
*
9
* the prot/flag values here are ABI and must match the kernel side in
10
* src/kernel/memory/mman.h exactly.
11
*/
12
13
#define PROT_NONE 0x0
14
#define PROT_READ 0x1
15
#define PROT_WRITE 0x2
16
#define PROT_EXEC 0x4
17
18
// mapping flags (flags argument).
19
#define MAP_SHARED 0x01
20
#define MAP_PRIVATE 0x02
21
#define MAP_ANONYMOUS 0x04
22
#define MAP_FIXED 0x10
23
24
// mmap failure return value.
25
#define MAP_FAILED ((void *)-1)
26
27
/**
28
* map memory into the calling process's address space.
29
*
30
* two forms are supported:
31
* - anonymous (flags has MAP_ANONYMOUS, fd < 0): zero-filled pages.
32
* - device-backed (fd is an open device node such as "/dev/fb0"): maps the
33
* device's memory (e.g. the linear framebuffer).
34
* with MAP_FIXED the mapping goes exactly at @p addr (page-aligned),
35
* replacing anything mapped there; otherwise @p addr is a hint the kernel
36
* uses if that range is free, else it picks a free range in its mmap region.
37
*
38
* @param addr address (MAP_FIXED) or hint (may be NULL).
39
* @param length number of bytes to map (rounded up to a page).
40
* @param prot protection bits (PROT_*).
41
* @param flags mapping flags (MAP_*).
42
* @param fd device fd for a device-backed mapping, or -1 for anonymous.
43
* @param offset byte offset into the file or device (a multiple of the
44
* page size, else EINVAL).
45
* @return the mapped address on success, or MAP_FAILED on error (errno set).
46
*/
47
void
*
mmap
(
void
*addr,
size_t
length,
int
prot,
int
flags
,
int
fd,
off_t
offset);
48
49
/**
50
* remove the mappings in [addr, addr + length).
51
* @param addr page-aligned start.
52
* @param length number of bytes (rounded up to a page).
53
* @return 0 on success, -1 on error (errno set).
54
*/
55
int
munmap
(
void
*addr,
size_t
length);
56
57
/**
58
* change the protection of [addr, addr + length), which must be mapped.
59
* @param addr page-aligned start.
60
* @param length number of bytes (rounded up to a page).
61
* @param prot the new PROT_* bits.
62
* @return 0 on success, -1 on error (errno set; ENOMEM if part of the range
63
* is not mapped).
64
*/
65
int
mprotect
(
void
*addr,
size_t
length,
int
prot);
66
67
/**
68
* make a shared memory object (a ginnOS call, like Linux's memfd_create):
69
* size bytes of zeroed memory, rounded up to whole pages. every mmap of
70
* the returned fd (MAP_SHARED), in this process or another one that has
71
* the fd (through fork, or sent over a socket), maps the same memory.
72
* @param size the size in bytes.
73
* @param fd_flags FD_CLOEXEC or 0.
74
* @return the fd (open read-write), or -1 with errno set.
75
*/
76
int
shm_create
(
size_t
size,
int
fd_flags);
flags
uint8_t flags
Definition
idt.c:3
munmap
int munmap(void *addr, size_t length)
remove the mappings in [addr, addr + length).
mprotect
int mprotect(void *addr, size_t length, int prot)
change the protection of [addr, addr + length), which must be mapped.
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.
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,...
types.h
basic system types.
off_t
__INT64_TYPE__ off_t
Definition
types.h:20
src
libc
include
sys
mman.h
Generated by
1.18.0