Artifact a5e2494c7bfb3db60f58c2514ac5e0be12d5a7d79f2a1d7ddb90cfaa6f7a9ff4:
- File
src/platform.h
— part of check-in
[9542357f2e]
at
2026-11-19 18:07:00
on branch seams
— Platform and executor seams (ticket d131051152)
pic's OS dependencies now sit behind two interfaces, with the host as the only implementation and no change in behaviour. pic_platform (src/platform.h) holds the wall and monotonic clocks, entropy, the journal lock, input reading and the SQLite VFS name, which the journal and pic.sqlite now open with. pic_executor (src/pic.h) holds the file operations the tools use (stat, read, write, remove, mkdir, list) and running a command; it mirrors libfossil's checkout filesystem so a database-backed workspace can drop in later. test_files covers the host file operations. (user: dmestas, size: 1942) [annotate] [blame] [check-ins using] [more...]
/* What pic asks of the machine it runs on, apart from files a tool touches * and commands it runs (pic_executor, in pic.h): clocks, entropy, the * journal's single-writer lock, file inputs, and the SQLite VFS for pic's * databases. The host's is the only one today; a build where pic is the * whole guest of a microVM supplies its own with pic_platform_set(). */ #ifndef PIC_PLATFORM_H #define PIC_PLATFORM_H #include <stddef.h> #include <stdint.h> typedef struct pic_platform { /* Wall-clock time in ns since the Unix epoch, or -1 when unknown. */ int64_t (*wall_ns)(void); /* A clock that never steps back, in ns from an arbitrary origin. */ uint64_t (*mono_ns)(void); /* Fills buf with n (at most 256) random bytes: 0, or -1 with errno. */ int (*entropy)(void *buf, size_t n); /* Takes the exclusive lock named by path without waiting. A handle * (>= 0) on success; -1 with errno when the lock cannot be opened; -2 * with errno (EWOULDBLOCK: someone else holds it) when it is not taken. * The lock lasts until unlock() or until this process and the children * it forks have all exited. */ int (*lock)(const char *path); void (*unlock)(int handle); /* pic_input_read (input.h) dispatches here. */ char *(*input_read)(const char *path, size_t max, int flags, size_t *len, int *truncated); /* The VFS pic's journal and ~/.pic/pic.sqlite are opened with; NULL is * SQLite's default. */ const char *vfs; } pic_platform; /* This machine's: POSIX clocks, getentropy, flock, the filesystem. */ const pic_platform *pic_platform_host(void); /* The one in use, the host's unless another was set. */ const pic_platform *pic_platform_get(void); void pic_platform_set(const pic_platform *p); /* input.c's reader of host files, the host platform's input_read. */ char *pic_input_read_host(const char *path, size_t max, int flags, size_t *len, int *truncated); #endif