Skip to content

Commit ba5865e

Browse files
committed
0.6.3: a core runner for an implementation without files, processes or threads
One interface (include/okrun.h, run/src/runner.h, the bindings) has two runners, selected in run/mcpp.toml by the interfaces the implementation provides (cfg(interface = ...), mcpp 2026.11.13.1). With openkal.fs, openkal.process, openkal.task, openkal.random and openkal.map it is the full runner (run/src/full), unchanged. Without any of them it is the core runner (run/src/core), which runs what the program carries from memory --- an image, a group, or an archive --- with the same admission and loader, and without cache, snapshot or profiler; okrun_run_file refuses with the reason. A callback of an absent interface is absent, as its other names are. openkal-run requires only abort, env, exec, memory, stream and time.
1 parent 7fa8684 commit ba5865e

14 files changed

Lines changed: 527 additions & 85 deletions

File tree

‎README.md‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,23 @@ The runner now folds a relative name against the first directory's name ---
8484
name beneath it, which is matched against the supplied directories as an
8585
absolute one is. No other change.
8686

87+
Version 0.6.3 builds a core runner where the implementation beneath it has no
88+
files, processes or threads --- a firmware's, such as openkal-uefi. One interface
89+
(`include/okrun.h`, `run/src/runner.h`, the bindings) has two runners, and
90+
`run/mcpp.toml` selects one by the interfaces the implementation provides
91+
(`cfg(interface = "openkal.fs")`, mcpp 2026.11.13.1): with `openkal.fs`,
92+
`openkal.process`, `openkal.task`, `openkal.random` and `openkal.map` the full
93+
runner (`run/src/full`), unchanged; without any of them the core runner
94+
(`run/src/core`). The core runner runs what the program carries, from memory:
95+
an image, a group of images, or an archive of them (`okrun_run_bytes`,
96+
`okrun_run_images`, `okrun_run_okb_bytes`), with the same admission --- the
97+
requirements note, the architecture, the signature --- and the same loader. It
98+
has no cache, no snapshot and no profiler, and `okrun_run_file` refuses with the
99+
reason. A name of an interface the implementation does not provide is absent to
100+
the image, so an image that imports it weakly runs (SPEC 12.4). openkal-run
101+
itself requires only `openkal.abort`, `openkal.env`, `openkal.exec`,
102+
`openkal.memory`, `openkal.stream` and `openkal.time`, and mcpp 2026.11.13.1.
103+
87104
## An image
88105

89106
```sh

‎ld/mcpp.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
namespace = "mcpplibs"
33
name = "openkal-ld"
4-
version = "0.6.2"
4+
version = "0.6.3"
55
description = "libokld: the ok format (openkal image format) --- its definition, a reader of bytes, a checker, a signer, and a loader. Freestanding: no C library, no exceptions."
66
license = "Apache-2.0"
77
authors = ["mcpplibs"]

‎run/build.mcpp‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,11 @@ int main() {
8282
// of the calls an image makes (okprof, 0.2) keeps its counts.
8383
for (std::size_t i = 0; i < names.size(); ++i) {
8484
const auto& n = names[i];
85-
o << (own.contains(n) ? "OKRUN_OWN(" : callbacks.contains(n) ? "OKRUN_CALLBACK(" :
86-
provided.contains(group_of[n]) ? "OKRUN_BIND(" : "OKRUN_ABSENT(")
85+
// A callback of an interface the implementation does not provide is absent, as
86+
// its other names are (0.6.3: a context cannot be started where there are none).
87+
o << (own.contains(n) ? "OKRUN_OWN(" :
88+
!provided.contains(group_of[n]) ? "OKRUN_ABSENT(" :
89+
callbacks.contains(n) ? "OKRUN_CALLBACK(" : "OKRUN_BIND(")
8790
<< n << ", " << i << ")\n";
8891
}
8992
};

‎run/mcpp.toml‎

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
[package]
22
namespace = "mcpplibs"
33
name = "openkal-run"
4-
version = "0.6.2"
4+
version = "0.6.3"
55
description = "libokrun: the runner's core --- an ok image's names bound to this process's one openkal implementation, in the image's calling convention, and its entry entered."
66
license = "Apache-2.0"
77
authors = ["mcpplibs"]
88
repo = "https://github.com/mcpplibs/openkal-image"
99
# `[defaults]' (mcpp 2026.11.9.1, SPEC-002 §3.7); the implementation's
10-
# interfaces read by build.mcpp (MCPP_KERNEL_ABI_INTERFACES, 2026.11.10.1).
11-
mcpp = ">=2026.11.10.1"
10+
# interfaces read by build.mcpp (MCPP_KERNEL_ABI_INTERFACES, 2026.11.10.1); the
11+
# runner's sources selected by them (`cfg(interface = ...)', 2026.11.13.1).
12+
mcpp = ">=2026.11.13.1"
1213
# The runner binds an image's names to this process's one implementation of
1314
# openkal: whichever the graph has --- the consumer's, or the one its
1415
# platform adds --- else the default of the system below.
@@ -27,22 +28,32 @@ macos = "openkal-macos@^0.23.0"
2728
windows = "openkal-windows@^0.21.0"
2829
'cfg(os = "freebsd")' = "openkal-freebsd@^0.1.0"
2930

30-
# THE INTERFACES THE RUNNER ITSELF CALLS (0.6): an implementation that does not
31-
# provide one of them is refused when the graph is resolved. Every other
32-
# interface is bound where the implementation provides it (build.mcpp reads
33-
# its `provides-interfaces'), and an image that requires one it does not is
34-
# refused at load, naming it (SPEC 12.4). An implementation that states no list
35-
# is taken to provide every interface.
31+
# THE INTERFACES THE RUNNER ITSELF CALLS (0.6; 0.6.3 the core runner): an implementation that does
32+
# not provide one of them is refused when the graph is resolved. Every other interface is bound
33+
# where the implementation provides it (build.mcpp reads its `provides-interfaces'), and an image
34+
# that requires one it does not is refused at load, naming it (SPEC 12.4). An implementation that
35+
# states no list is taken to provide every interface.
3636
[kernel-abi]
3737
requires-interfaces = [
38-
"openkal.abort", "openkal.stream", "openkal.memory", "openkal.env", "openkal.time",
39-
"openkal.random", "openkal.fs", "openkal.process", "openkal.task", "openkal.exec",
40-
"openkal.map",
38+
"openkal.abort", "openkal.stream", "openkal.memory", "openkal.env", "openkal.time", "openkal.exec",
4139
]
4240

4341
[build]
44-
sources = ["src/okrun.cppm", "src/run.cpp", "src/bindings.cpp", "src/seal.cpp", "src/prof.cpp"]
42+
sources = ["src/okrun.cppm", "src/bindings.cpp", "src/adapters.cpp"]
4543
include_dirs = ["include"]
4644
flags = [
4745
{ glob = "src/*.cpp", cxxflags = ["-fno-exceptions", "-fno-rtti"] },
46+
{ glob = "src/full/*.cpp", cxxflags = ["-fno-exceptions", "-fno-rtti"] },
47+
{ glob = "src/core/*.cpp", cxxflags = ["-fno-exceptions", "-fno-rtti"] },
4848
]
49+
50+
# ONE INTERFACE, TWO RUNNERS (0.6.3), chosen by what the implementation provides. The full runner
51+
# reads images from files, keeps a cache and snapshots, starts itself again and digests in
52+
# parallel; the core runner runs what the program carries, from memory --- on firmware, or any
53+
# implementation without files, processes or threads. Both answer the same C interface
54+
# (include/okrun.h).
55+
[target.'cfg(all(interface = "openkal.fs", interface = "openkal.process", interface = "openkal.task", interface = "openkal.random", interface = "openkal.map"))'.build]
56+
sources = ["src/full/*.cpp"]
57+
58+
[target.'cfg(not(all(interface = "openkal.fs", interface = "openkal.process", interface = "openkal.task", interface = "openkal.random", interface = "openkal.map")))'.build]
59+
sources = ["src/core/*.cpp"]

‎run/src/adapters.cpp‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// The implementation's measurement and names (openkal.prof, openkal.debug), for both runners.
2+
#include <openkal.h>
3+
#include "runner.h"
4+
5+
namespace okrun {
6+
7+
// THE IMPLEMENTATION'S MEASUREMENT AND NAMES (openkal.prof, openkal.debug),
8+
// referred to only where it provides them (0.6): an implementation without
9+
// them is not asked to define a name it does not have (SPEC 6.1).
10+
#if OKRUN_HAS_PROF
11+
kal_uintptr impl_prof_props() { return kal_prof_props(); }
12+
int impl_prof_sample_begin(kal_u32 per_second) { return kal_prof_sample_begin(per_second); }
13+
kal_intptr impl_prof_sample_take(kal_prof_sample* out, kal_uintptr count) { return kal_prof_sample_take(out, count); }
14+
int impl_prof_sample_end() { return kal_prof_sample_end(); }
15+
int impl_prof_touch_begin(const void* at, kal_uintptr size) { return kal_prof_touch_begin(at, size); }
16+
kal_intptr impl_prof_touch_take(kal_uintptr* out, kal_uintptr count) { return kal_prof_touch_take(out, count); }
17+
int impl_prof_touch_end() { return kal_prof_touch_end(); }
18+
#else
19+
kal_uintptr impl_prof_props() { return 0; }
20+
int impl_prof_sample_begin(kal_u32) { return kal_err_not_supported; }
21+
kal_intptr impl_prof_sample_take(kal_prof_sample*, kal_uintptr) { return 0; }
22+
int impl_prof_sample_end() { return kal_err_invalid; }
23+
int impl_prof_touch_begin(const void*, kal_uintptr) { return kal_err_not_supported; }
24+
kal_intptr impl_prof_touch_take(kal_uintptr*, kal_uintptr) { return 0; }
25+
int impl_prof_touch_end() { return kal_err_invalid; }
26+
#endif
27+
#if OKRUN_HAS_DEBUG
28+
kal_uintptr impl_debug_props() { return kal_debug_props(); }
29+
kal_intptr impl_debug_symbolize(kal_uintptr address, char* out, kal_uintptr cap, kal_uintptr* start) {
30+
return kal_debug_symbolize(address, out, cap, start);
31+
}
32+
#else
33+
kal_uintptr impl_debug_props() { return 0; }
34+
kal_intptr impl_debug_symbolize(kal_uintptr, char*, kal_uintptr, kal_uintptr*) { return -kal_err_not_found; }
35+
#endif
36+
37+
} // namespace okrun

‎run/src/bindings.cpp‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ void enter_image(void* p) {
5252
b.fn(b.arg);
5353
}
5454

55+
#if OKRUN_HAS_TASK
5556
OKRUN_IMAGE_ABI int callback_kal_task_start(image_entry fn, void* arg, struct kal_task* out) {
5657
auto* b = static_cast<box*>(kal_alloc(sizeof(box), alignof(box)));
5758
if (!b) return kal_err_no_memory;
@@ -69,6 +70,7 @@ OKRUN_IMAGE_ABI int callback_kal_task_start_sized(image_entry fn, void* arg, kal
6970
if (rc != kal_ok) kal_free(b, sizeof(box), alignof(box));
7071
return rc;
7172
}
73+
#endif // OKRUN_HAS_TASK
7274

7375
// The image's own arguments and name (SPEC 12.3), answered by the runner.
7476
kal_intptr give(const char* v, kal_uintptr n, char* out, kal_uintptr cap) {
@@ -224,3 +226,42 @@ void* space_props_binding() { return nullptr; }
224226
#endif
225227

226228
} // namespace okrun
229+
230+
// --- the names a runner binds, and a call's floating-point state: both runners' (0.6.3) ----
231+
232+
using namespace okrun;
233+
234+
extern "C" const char* const* okrun_names(unsigned long* count) {
235+
static const char* names[256];
236+
static unsigned long n = 0;
237+
if (n == 0) {
238+
unsigned long k = 0;
239+
const binding* t = bindings(k);
240+
for (unsigned long i = 0; i < k && n < 256; ++i) names[n++] = t[i].name;
241+
t = space_bindings(k);
242+
for (unsigned long i = 0; t && i < k && n < 256; ++i) names[n++] = t[i].name;
243+
}
244+
if (count) *count = n;
245+
return names;
246+
}
247+
248+
// A NAME'S SLOT, from a hash under which no two of the surface's names share
249+
// one (build.mcpp, 0.4): one name compared, where every name was.
250+
#include "surface_hash.inc"
251+
252+
extern "C" void* okrun_resolve(const char* name) {
253+
if (!name) return nullptr;
254+
unsigned h = 2166136261u ^ kResolveSeed;
255+
for (const char* c = name; *c; ++c) { h ^= static_cast<unsigned char>(*c); h *= 16777619u; }
256+
const unsigned short slot = kResolveSlot[h % kResolveSlots];
257+
if (slot == 0) return nullptr;
258+
unsigned long n = 0;
259+
const unsigned long i = slot - 1u;
260+
const binding* t = i < kResolveMain ? bindings(n) : space_bindings(n);
261+
const unsigned long k = i < kResolveMain ? i : i - kResolveMain;
262+
if (!t || k >= n || !same(t[k].name, name)) return nullptr;
263+
return t[k].address;
264+
}
265+
266+
extern "C" unsigned long long okrun_call_enter(void) { return okrun_fp_enter(); }
267+
extern "C" void okrun_call_leave(unsigned long long state) { okrun_fp_leave(state); }

‎run/src/core/prof.cpp‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// The core runner measures nothing (openkal-image 0.6.3). A measurement writes files and names
2+
// processes, which an implementation without openkal.fs and openkal.process does not have; the
3+
// calls the shared bindings make are answered here as the full runner answers them unasked.
4+
#include <openkal.h>
5+
#include "../runner.h"
6+
7+
namespace okrun {
8+
9+
bool profile_active() { return false; }
10+
bool profile_calls() { return false; }
11+
bool profile_samples() { return false; }
12+
bool profile_touches() { return false; }
13+
void profile_phase(const char*) {}
14+
void profile_note(const char*, const char*, kal_u64) {}
15+
void profile_begin_run() {}
16+
void record_call(unsigned long, kal_u64) {}
17+
int profile_counter(const char*, kal_uintptr, const volatile kal_u64*) { return kal_err_not_supported; }
18+
void profile_mark(const char*, kal_uintptr, int) {}
19+
void profile_finish() {}
20+
void profile_loaded(const char*, const void*, kal_u64, const char*, kal_u64) {}
21+
void profile_settle() {}
22+
kal_intptr symbolize(kal_uintptr, char*, kal_uintptr, kal_uintptr*) { return -kal_err_not_found; }
23+
24+
} // namespace okrun
25+
26+
extern "C" void okrun_profile(const char*) {}

0 commit comments

Comments
 (0)