Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,58 @@ jobs:

# EVERY JOB'S TEST RUNS AS ONE REPORT (`mtest ci report`, the workflow run's
# group): libokld's vectors on the image machine and on each system.
# AN I386 IMAGE STARTS IMAGES (0.7.3, openkal-image#46): starts.oke for i686, run
# by okrun built for i686-linux-musl over the platform that serves the row. A
# program built over the runner is the loader of an image's start of an image
# file through okrun_main; under 0.7.2 the platform's carrier, the i686 row's
# runner, named none, and the start was refused (status 127 in a copy).
i686:
name: run (linux-i686 on linux-x86_64)
runs-on: ubuntu-24.04
timeout-minutes: 60
env:
# The row's platform, stated by the build, reads a newer engine.
MCPP_VERSION: 2026.11.22.1
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@v4
- name: Install xlings
run: |
curl -fsSL https://raw.githubusercontent.com/openxlings/xlings/main/tools/other/quick_install.sh | bash -s "$XLINGS_VERSION"
echo "$HOME/.xlings/subos/current/bin" >> "$GITHUB_PATH"
- name: okld for this machine, okrun for i686-linux-musl
run: |
xlings update
xlings install "mcpp@$MCPP_VERSION" -y -g
test "$(mcpp --version)" = "mcpp $MCPP_VERSION"
mcpp self config --mirror GLOBAL
mcpp toolchain install llvm 23.1.3
mcpp toolchain default "$LLVM"
(cd tools && mcpp build --release)
echo "OKLD=$(find "$PWD/target" -path '*bin*' -name okld -type f | head -1)" >> "$GITHUB_ENV"
printf '\n[target.i686-linux-musl]\nplatform = "openkal-platform@0.31.2"\ntoolchain = "%s"\n' "$LLVM" >> tools/mcpp.toml
(cd tools && mcpp build --release --target i686-linux-musl)
okrun=$(find "$PWD/target/i686-linux-musl" -path '*bin*' -name okrun -type f | head -1)
file "$okrun"
file "$okrun" | grep -q 'ELF 32-bit' || { echo "::error::okrun is not an i386 program"; exit 1; }
echo "OKRUN32=$okrun" >> "$GITHUB_ENV"
- name: An i386 image starts images, each entered by the runner
run: |
bin="$HOME/.mcpp/registry/data/xpkgs/xim-x-llvm/23.1.3/bin"
export CLANG="$bin/clang" LLD="$bin/ld.lld"
spec=$(find "$HOME/.mcpp" -path '*openkal*0.26.*/include/openkal/process.h' -type f | sort -V | tail -1)
test -n "$spec"
mkdir -p out/i686
bash examples/build-image.sh i686 out/i686/exits.oke examples/exits/app.c
CPATH="${spec%/openkal/process.h}" bash examples/build-image.sh i686 out/i686/starts.oke examples/starts/app.c
out=$({ "$OKRUN32" out/i686/starts.oke /bin/sh -c "exit 5" || true; } | tr -d '\r')
echo "$out"
grep -qx "starts: itself 7" <<<"$out" && grep -qx "starts: ok" <<<"$out" \
|| { echo "::error::an i386 image's start of an image, or of a program of the system"; exit 1; }
echo " ok an i386 image starts itself, exits.oke and a program of the system"

report:
name: tests (report)
needs: [images, run]
Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,17 @@ joined, and the image's requests to end are its own. `examples/forks` ends a
copy with `kal_exit(7)`, and CI expects 7 on Linux. A release's programs are
built over openkal-platform 0.31.2, whose group holds this release.

Version 0.7.3 makes okrun's command line a function of the runner,
`okrun_main` (`include/okrun.h`), so that every program built over the runner
that runs the image it is given names itself as the loader an image's start of
an image file goes through (#46). The program `okrun` is that function; so is a
platform's carrier where it is its package's runner. Under 0.7.2 the carrier
named no loader, and on `i686-openkal`, whose runner is the carrier, an image
that started an image was refused (`ENOEXEC` from `posix_spawn`, status 127 in
a copy that called exec). A CI job builds okrun for `i686-linux-musl` and runs
`examples/starts` for i686: the image starts itself, `exits.oke` and a program
of the system.

## An image

```sh
Expand Down
2 changes: 1 addition & 1 deletion bind/mcpp.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
namespace = "mcpplibs"
name = "openkal-bind"
version = "0.7.2"
version = "0.7.3"
# `mcpp::xpkg_request', `mcpp::decision' (protocol 15).
mcpp = ">=2026.10.1.3"
description = "A build plugin: a library published as an ok image (.okso) and a C header is called from a program of any system, through a binding generated from the header and libokrun."
Expand Down
2 changes: 1 addition & 1 deletion ld/mcpp.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
namespace = "mcpplibs"
name = "openkal-ld"
version = "0.7.2"
version = "0.7.3"
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."
license = "Apache-2.0"
authors = ["mcpplibs"]
Expand Down
11 changes: 11 additions & 0 deletions run/include/okrun.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@ struct okrun_options {
const char* loader;
};

/* okrun's command line (0.7.3): `[--require-signature] [--trust <hex>]...
* [--debugger] [--prof=<what>[:dir]] [--argv0=<name>] [--] image|okb
* [arguments...]', and `cache [list | gc [--all]]'. The program that calls it
* is the loader an image's start of an image file goes through (its own name,
* kal_env_image), so a program built over the runner that runs the image it is
* given -- `okrun', a platform's carrier as its package's runner -- starts an
* image an image starts as `okrun' does. Returns only when the image could not
* be started (127, the reason written to standard error) or for a usage error
* (2). */
int okrun_main(int argc, char** argv);

/* Runs an image that lies in memory. `name' is what the image is told its
* own name is (`kal_env_image'); `argv' is what it is told its arguments are,
* the first being its name as it was started. Bytes that are an archive of
Expand Down
4 changes: 2 additions & 2 deletions run/mcpp.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
namespace = "mcpplibs"
name = "openkal-run"
version = "0.7.2"
version = "0.7.3"
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."
license = "Apache-2.0"
authors = ["mcpplibs"]
Expand Down Expand Up @@ -39,7 +39,7 @@ requires-interfaces = [
]

[build]
sources = ["src/okrun.cppm", "src/bindings.cpp", "src/adapters.cpp", "src/waits.cpp"]
sources = ["src/okrun.cppm", "src/bindings.cpp", "src/adapters.cpp", "src/waits.cpp", "src/command.cpp"]
include_dirs = ["include"]
flags = [
{ glob = "src/*.cpp", cxxflags = ["-fno-exceptions", "-fno-rtti"] },
Expand Down
117 changes: 117 additions & 0 deletions run/src/command.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
// okrun's command line, as a function of the runner (0.7.3): the program
// `okrun' is this function, and so is every program built over the runner that
// runs the image it is given (a platform's carrier, its package's runner), so
// that each is the loader the start of an image file goes through.
//
// The command line --- runs an ok image, or an okb (docs/okb.md): `okrun [options] image
// [arguments...]'. An okb runs this machine's architecture's entry.
//
// --require-signature refuse an image that is not signed
// --trust <hex> a public key (64 hexadecimal digits) whose images run;
// given at least once, an image signed by another is refused
// --debugger announce the image to gdb and lldb (GDB JIT interface)
// --prof=<what>[:dir] measure the image: calls, counters, perfmap (comma
// separated); the report goes to <dir>/okprof-<id>.json,
// which `okprof report' reads (OKRUN_PROF says the same)
// --argv0=<name> the name the image is told it was started as, its
// first argument, in place of the image's name (0.7.1)
//
// `okrun cache [list]' lists what the runner keeps for this machine (0.4: an
// image's data for this boot's base, snapshots, their markers); `okrun cache gc'
// removes what was prepared for another boot, and `--all' everything.
//
// The image is told its arguments are the image's (or the okb's) name, or the
// name `--argv0' gives, and what follows it. The images it needs are found
// beside it, in `lib/<arch>/' and `lib/' there, and in OKRUN_PATH.
//
// AN IMAGE THAT STARTS AN IMAGE FILE (0.7.1) starts it through this program,
// which the runner is told is its loader: the started image is entered by a
// runner as this one was, with this one's signature requirements, and observes
// the arguments its starter gave (openkal clause 7.6), the first by `--argv0'.
#include <okrun.h>
#include <openkal.h>

namespace {
unsigned long length(const char* s) { unsigned long n = 0; while (s && s[n]) ++n; return n; }
void say(const char* s) { kal_stream_write(kal_stderr(), s, length(s)); }
void put(const char* s) { kal_stream_write(kal_stdout(), s, length(s)); }
bool same(const char* a, const char* b) { for (;; ++a, ++b) { if (*a != *b) return false; if (!*a) return true; } }
int hex(char c) { return c >= '0' && c <= '9' ? c - '0' : c >= 'a' && c <= 'f' ? c - 'a' + 10 : c >= 'A' && c <= 'F' ? c - 'A' + 10 : -1; }
} // namespace

// `okrun cache [gc [--all]]': what the runner keeps for this machine (0.4).
static int cache(int argc, char** argv) {
auto number = [](unsigned long long v) {
char d[24]; int n = 0;
do { d[n++] = static_cast<char>('0' + v % 10); v /= 10; } while (v);
char out[24]; int k = 0;
while (n) out[k++] = d[--n];
out[k] = 0;
say(out);
};
if (argc >= 3 && same(argv[2], "gc")) {
const bool all = argc >= 4 && same(argv[3], "--all");
const unsigned long long bytes = okrun_cache_reclaim(all ? 1 : 0);
say("okrun: removed "); number(bytes); say(all ? " bytes, everything the runner keeps\n" : " bytes prepared for another boot\n");
return 0;
}
if (argc >= 3 && !same(argv[2], "list")) { say("usage: okrun cache [list | gc [--all]]\n"); return 2; }
const unsigned long long bytes = okrun_cache_list([](const char* name, unsigned long long size, int current, void*) {
unsigned long long v = size;
char d[24]; int n = 0;
do { d[n++] = static_cast<char>('0' + v % 10); v /= 10; } while (v);
char out[24]; int k = 0;
while (n) out[k++] = d[--n];
out[k] = 0;
put(out); put("\t"); put(current ? "this boot" : "another boot"); put("\t"); put(name); put("\n");
}, nullptr);
say("okrun: "); number(bytes); say(" bytes\n");
return 0;
}

extern "C" int okrun_main(int argc, char** argv) {
if (argc >= 2 && same(argv[1], "cache")) return cache(argc, argv);
okrun_options options{};
static unsigned char keys[16 * 32];
// This program is the loader an image's start of an image file goes
// through (0.7.1): its own name, as the implementation states it.
static char self[4096];
if (const kal_intptr n = kal_env_image(self, sizeof self - 1); n > 0 && n < static_cast<kal_intptr>(sizeof self)) {
self[n] = 0;
options.loader = self;
}
const char* argv0 = nullptr;
int i = 1;
for (; i < argc && argv[i][0] == '-' && argv[i][1] == '-'; ++i) {
if (same(argv[i], "--")) { ++i; break; }
if (argv[i][2] == 'a' && argv[i][3] == 'r' && argv[i][4] == 'g' && argv[i][5] == 'v'
&& argv[i][6] == '0' && argv[i][7] == '=') { argv0 = argv[i] + 8; continue; }
if (same(argv[i], "--require-signature")) { options.require_signature = 1; continue; }
if (same(argv[i], "--debugger")) { options.debugger = 1; continue; }
if (argv[i][2] == 'p' && argv[i][3] == 'r' && argv[i][4] == 'o' && argv[i][5] == 'f'
&& argv[i][6] == '=') { okrun_profile(argv[i] + 7); continue; }
if (same(argv[i], "--trust") && i + 1 < argc && options.trusted_count < 16 && length(argv[i + 1]) == 64) {
const char* k = argv[++i];
for (int b = 0; b < 32; ++b) {
const int hi = hex(k[2 * b]), lo = hex(k[2 * b + 1]);
if (hi < 0 || lo < 0) { say("okrun: --trust takes 64 hexadecimal digits\n"); return 2; }
keys[options.trusted_count * 32 + b] = static_cast<unsigned char>(hi * 16 + lo);
}
++options.trusted_count;
continue;
}
say("okrun: unknown option "); say(argv[i]); say("\n");
return 2;
}
options.trusted = keys;
if (i >= argc) {
say("usage: okrun [--require-signature] [--trust <hex>]... [--debugger] [--prof=<what>[:dir]] [--argv0=<name>] image|okb [arguments...]\n");
return 2;
}
char why[512];
const char* path = argv[i];
if (argv0) argv[i] = const_cast<char*>(argv0);
okrun_run_file(path, argc - i, const_cast<const char* const*>(argv + i), &options, why, sizeof why);
say("okrun: "); say(why); say("\n");
return 127;
}
2 changes: 1 addition & 1 deletion tools/mcpp.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
namespace = "mcpplibs"
name = "openkal-tools"
version = "0.7.2"
version = "0.7.3"
description = "okrun, which runs an ok image on this system, and okld, the format's tool on a build machine (check, note, sign, inspect)."
license = "Apache-2.0"
authors = ["mcpplibs"]
Expand Down
86 changes: 1 addition & 85 deletions tools/src/okrun.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,89 +24,5 @@
// runner as this one was, with this one's signature requirements, and observes
// the arguments its starter gave (openkal clause 7.6), the first by `--argv0'.
#include <okrun.h>
#include <openkal.h>

namespace {
unsigned long length(const char* s) { unsigned long n = 0; while (s && s[n]) ++n; return n; }
void say(const char* s) { kal_stream_write(kal_stderr(), s, length(s)); }
void put(const char* s) { kal_stream_write(kal_stdout(), s, length(s)); }
bool same(const char* a, const char* b) { for (;; ++a, ++b) { if (*a != *b) return false; if (!*a) return true; } }
int hex(char c) { return c >= '0' && c <= '9' ? c - '0' : c >= 'a' && c <= 'f' ? c - 'a' + 10 : c >= 'A' && c <= 'F' ? c - 'A' + 10 : -1; }
} // namespace

// `okrun cache [gc [--all]]': what the runner keeps for this machine (0.4).
int cache(int argc, char** argv) {
auto number = [](unsigned long long v) {
char d[24]; int n = 0;
do { d[n++] = static_cast<char>('0' + v % 10); v /= 10; } while (v);
char out[24]; int k = 0;
while (n) out[k++] = d[--n];
out[k] = 0;
say(out);
};
if (argc >= 3 && same(argv[2], "gc")) {
const bool all = argc >= 4 && same(argv[3], "--all");
const unsigned long long bytes = okrun_cache_reclaim(all ? 1 : 0);
say("okrun: removed "); number(bytes); say(all ? " bytes, everything the runner keeps\n" : " bytes prepared for another boot\n");
return 0;
}
if (argc >= 3 && !same(argv[2], "list")) { say("usage: okrun cache [list | gc [--all]]\n"); return 2; }
const unsigned long long bytes = okrun_cache_list([](const char* name, unsigned long long size, int current, void*) {
unsigned long long v = size;
char d[24]; int n = 0;
do { d[n++] = static_cast<char>('0' + v % 10); v /= 10; } while (v);
char out[24]; int k = 0;
while (n) out[k++] = d[--n];
out[k] = 0;
put(out); put("\t"); put(current ? "this boot" : "another boot"); put("\t"); put(name); put("\n");
}, nullptr);
say("okrun: "); number(bytes); say(" bytes\n");
return 0;
}

int main(int argc, char** argv) {
if (argc >= 2 && same(argv[1], "cache")) return cache(argc, argv);
okrun_options options{};
static unsigned char keys[16 * 32];
// This program is the loader an image's start of an image file goes
// through (0.7.1): its own name, as the implementation states it.
static char self[4096];
if (const kal_intptr n = kal_env_image(self, sizeof self - 1); n > 0 && n < static_cast<kal_intptr>(sizeof self)) {
self[n] = 0;
options.loader = self;
}
const char* argv0 = nullptr;
int i = 1;
for (; i < argc && argv[i][0] == '-' && argv[i][1] == '-'; ++i) {
if (same(argv[i], "--")) { ++i; break; }
if (argv[i][2] == 'a' && argv[i][3] == 'r' && argv[i][4] == 'g' && argv[i][5] == 'v'
&& argv[i][6] == '0' && argv[i][7] == '=') { argv0 = argv[i] + 8; continue; }
if (same(argv[i], "--require-signature")) { options.require_signature = 1; continue; }
if (same(argv[i], "--debugger")) { options.debugger = 1; continue; }
if (argv[i][2] == 'p' && argv[i][3] == 'r' && argv[i][4] == 'o' && argv[i][5] == 'f'
&& argv[i][6] == '=') { okrun_profile(argv[i] + 7); continue; }
if (same(argv[i], "--trust") && i + 1 < argc && options.trusted_count < 16 && length(argv[i + 1]) == 64) {
const char* k = argv[++i];
for (int b = 0; b < 32; ++b) {
const int hi = hex(k[2 * b]), lo = hex(k[2 * b + 1]);
if (hi < 0 || lo < 0) { say("okrun: --trust takes 64 hexadecimal digits\n"); return 2; }
keys[options.trusted_count * 32 + b] = static_cast<unsigned char>(hi * 16 + lo);
}
++options.trusted_count;
continue;
}
say("okrun: unknown option "); say(argv[i]); say("\n");
return 2;
}
options.trusted = keys;
if (i >= argc) {
say("usage: okrun [--require-signature] [--trust <hex>]... [--debugger] [--prof=<what>[:dir]] [--argv0=<name>] image|okb [arguments...]\n");
return 2;
}
char why[512];
const char* path = argv[i];
if (argv0) argv[i] = const_cast<char*>(argv0);
okrun_run_file(path, argc - i, const_cast<const char* const*>(argv + i), &options, why, sizeof why);
say("okrun: "); say(why); say("\n");
return 127;
}
int main(int argc, char** argv) { return okrun_main(argc, argv); }
Loading