The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
shm.h
Go to the documentation of this file.
1#pragma once
2
3/**
4 * @file shm.h
5 * @brief shared memory objects: pages that several processes map.
6 *
7 * shm_create makes an object of zeroed pages and an open file for it. a
8 * process maps it with mmap(fd); every mapping of the object, in any
9 * process, uses the same frames, so a write in one is seen in all. this
10 * is how a window's pixels go from an app to the compositor.
11 *
12 * the object lives while its open file does (the file can be shared by
13 * fork and dup, and later sent over a socket). each mapping holds its own
14 * reference to the frames, so a mapping stays valid after the file is
15 * closed, and the frames are freed when the last file and the last
16 * mapping are gone.
17 */
18
19#include "common/error.h"
20#include "common/stdint.h"
21
22struct file;
23
24// the largest object
25#define SHM_MAX_SIZE (64u * 1024 * 1024)
26
27/**
28 * make a shared memory object of size bytes (rounded up to whole pages).
29 * @param out receives the open file (one reference), opened read-write.
30 * @return KERR_OK, KERR_INVAL (size 0 or too big) or KERR_NOMEM.
31 */
32kerr_t shm_create(size_t size, struct file **out);
33
34/**
35 * true if the open file is a shared memory object (its mappings are
36 * VMA_SHARED areas).
37 */
38bool shm_is_file(const struct file *file);
kerr_t
unified kernel error codes.
Definition error.h:14
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,...
bool shm_is_file(const file_t *file)
Definition shm.c:141
an open-file description.
Definition file.h:64