The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
shm.h File Reference

shared memory objects: pages that several processes map. More...

#include "common/error.h"
#include "common/stdint.h"

Go to the source code of this file.

Macros

#define SHM_MAX_SIZE   (64u * 1024 * 1024)

Functions

kerr_t shm_create (size_t size, struct file **out)
 make a shared memory object of size bytes (rounded up to whole pages).
bool shm_is_file (const struct file *file)
 true if the open file is a shared memory object (its mappings are VMA_SHARED areas).

Detailed Description

shared memory objects: pages that several processes map.

shm_create makes an object of zeroed pages and an open file for it. a process maps it with mmap(fd); every mapping of the object, in any process, uses the same frames, so a write in one is seen in all. this is how a window's pixels go from an app to the compositor.

the object lives while its open file does (the file can be shared by fork and dup, and later sent over a socket). each mapping holds its own reference to the frames, so a mapping stays valid after the file is closed, and the frames are freed when the last file and the last mapping are gone.

Macro Definition Documentation

◆ SHM_MAX_SIZE

#define SHM_MAX_SIZE   (64u * 1024 * 1024)

Function Documentation

◆ shm_create()

kerr_t shm_create ( size_t size,
struct file ** out )

make a shared memory object of size bytes (rounded up to whole pages).

Parameters
outreceives the open file (one reference), opened read-write.
Returns
KERR_OK, KERR_INVAL (size 0 or too big) or KERR_NOMEM.

◆ shm_is_file()

bool shm_is_file ( const struct file * file)

true if the open file is a shared memory object (its mappings are VMA_SHARED areas).