skip to content
==> include/mesh/shm.h <==
1/* @ajax/mesh-shm: the mailbox's memory on every backend (mesh-host shm.rs):
2 * one shared-memory file of MAILBOX_BYTES, mapped MAP_SHARED, page aligned
3 * and zero filled, that other processes map too -- native workers, and the
4 * --isolation mps workers.  The GPU backends wrap the same pages (CUDA
5 * registers them with cuMemHostRegister DEVICEMAP).
6 * - Linux: a memfd (close-on-exec); a child gets it as an inherited
7 *   descriptor, an MPS worker opens /proc/<pid>/fd/<fd>.
8 * - macOS: shm_open of a fresh name, unlinked at once.
9 * The mapping lives as long as the process (never unmapped). */
10#ifndef MESH_SHM_H
11#define MESH_SHM_H
12
13#include <stdbool.h>
14#include <stddef.h>
15#include <stdint.h>
16
17typedef struct {
18    uint8_t *base;
19    size_t len;
20    int fd; /* close-on-exec: a child gets it only through dup2 */
21} mesh_shm;
22
23/* A zeroed MAILBOX_BYTES mapping. False with *err ("mailbox: memfd_create: ..."). */
24bool mesh_shm_new(mesh_shm *out, char **err);
25bool mesh_shm_with_len(size_t len, mesh_shm *out, char **err);
26/* A path another process can open it by (Linux: /proc/<pid>/fd/<fd>), malloc'd. */
27char *mesh_shm_path(const mesh_shm *s);
28/* Unmaps and closes (tests only: meshd never does). */
29void mesh_shm_close(mesh_shm *s);
30
31#endif