Appendix S
Source plates.
The following excerpts show the system's organizing idea in source form: state changes become
typed events with enough structure to be replayed, traced, and federated.
Plate 01 include/causal.h
The event record
typedef struct {
uint32_t id;
uint32_t node_hash;
causal_time_t time;
causal_type_t type;
char subsystem[16];
char desc[CAUSAL_DESC_LEN];
uint8_t payload[CAUSAL_PAYLOAD_LEN];
uint32_t parents[CAUSAL_MAX_PARENTS];
uint8_t num_parents;
uint16_t child_count;
} causal_event_t;
Plate 02 kernel/graph/causal.c
The bounded ring
static causal_event_t events[CAUSAL_MAX_EVENTS];
static uint32_t event_count;
static uint32_t next_id = 1;
static uint64_t lamport_clock;
static inline uint32_t ring_index(uint32_t id)
{
return (id - 1) % CAUSAL_MAX_EVENTS;
}
Plate 03 kernel/core/syscall.c
Syscalls become context
if (num != SYS_YIELD && num != SYS_GETPID) {
sc_event = causal_event_fmt(CAUSAL_SYSCALL, "syscall",
"syscall %u pid=%d", num, cur ? cur->pid : 0);
if (sc_event)
causal_push_context(sc_event);
}
Plate 04 include/timeline.h
A named event chain
typedef struct {
char name[TIMELINE_NAME_LEN];
char app[16];
bool active;
uint32_t head_id;
uint32_t cursor_id;
uint32_t event_count;
uint32_t create_tick;
} timeline_t;
Plate 05 kernel/graph/actor.c
Actors announce themselves
int actor_register(const char *name, pid_t owner) {
if (!name || strlen(name) == 0)
return -1;
/* allocate an actor slot, then record it */
causal_event_fmt(CAUSAL_ACTOR, "actor",
"register name=%s id=%u", name, actors[i].id);
route_add_target(name, (int)actors[i].id);
return (int)actors[i].id;
}
Plate 06 kernel/apps/notes.c
Notes keep a durable snapshot
#define NOTES_SNAPSHOT_PATH "/notes.snapshot"
#define NOTES_SNAPSHOT_MAGIC 0x45544F4Eu
typedef struct {
uint32_t magic;
uint32_t version;
uint32_t note_state_size;
uint32_t count;
uint32_t saved_tick;
uint32_t checksum;
} __attribute__((packed)) notes_snapshot_header_t;
Reading note
The code is deliberately small.
SlOS favours fixed tables, explicit payloads, bounded buffers, and direct shell commands.
That economy makes the causal model visible. A reader can follow the path from a shell
command to a syscall, from a syscall to an event, and from an event to a replayed
application state.
Repository
Continue with the source tree.
The kernel source, manuals, smoke scripts, user programs, and video showcase live in the
main repository.
Open github.com/slepp/slos