skip to content
==> include/mesh/loader.h <==
1/* @ajax/mesh-loader: everything about a load that happens outside the blink
2 * (mesh-host loader.rs): resolving a catalog name under --programs DIR
3 * (nothing else is readable), reading the manifest and PTX, an image's hash
4 * and identity, and the catalog listing.  The backend's compiler then checks
5 * and compiles on a worker thread. */
6#ifndef MESH_LOADER_H
7#define MESH_LOADER_H
8
9#include "mesh/manifest.h"
10
11#include <stdbool.h>
12#include <stddef.h>
13#include <stdint.h>
14
15/* A program's bytes as the catalog holds them (and F_LOAD carries them). */
16typedef struct {
17    char *dir;      /* the catalog dir name (under --programs) */
18    char *manifest; /* program.toml's text */
19    uint8_t *ptx;   /* may be NULL when ptx_len is 0 */
20    size_t ptx_len;
21} mesh_payload;
22
23void mesh_payload_copy(mesh_payload *dst, const mesh_payload *src);
24void mesh_payload_free(mesh_payload *p);
25
26/* A catalog name: [a-z0-9-]{1,64}, optionally followed by "/program.toml" (and
27 * trailing slashes).  The name (malloc'd), or NULL with *err:
28 * "manifest: \"../etc\": programs are named [a-z0-9-] under --programs (no paths)". */
29char *mesh_catalog_name(const char *spec, char **err);
30/* The program dir for spec, which must stay inside root (symlinks too): the
31 * canonical path (malloc'd), or NULL with *err. */
32char *mesh_loader_resolve(const char *root, const char *spec, char **err);
33/* The catalog dir spec's manifest text and PTX.  need_ptx: a missing PTX is
34 * an error (CUDA compiles it); otherwise it is read when present. */
35bool mesh_loader_read(const char *root, const char *spec, bool need_ptx, mesh_payload *out, char **err);
36/* An image's identity: fnv1a64 of its code, with `param` folded in when not 0. */
37uint64_t mesh_image_hash(const uint8_t *code, size_t n, uint32_t param);
38/* A native program's identity: the manifest and its source.hash (trimmed), and param. */
39uint64_t mesh_native_identity(const char *manifest, const char *source, uint32_t param);
40/* A catalog dir's payload, manifest and image identity as a member's executor
41 * computes it: the PTX's hash when the dir has one, else the first image the
42 * manifest's backends lists that the dir holds (native source.hash, .wasm, MSL). */
43bool mesh_loader_identity(const char *root, const char *spec, mesh_payload *p, mesh_manifest *m, uint64_t *hash, char **err);
44/* A peer's F_LOAD hash must be the bytes' (expect NULL: nothing announced). */
45bool mesh_check_hash(const char *name, const char *what, uint64_t hash, const uint64_t *expect, char **err);
46/* The program dirs under root (those with a program.toml), sorted. */
47bool mesh_catalog(const char *root, char ***names, size_t *n, char **err);
48
49#endif