Skip to content

0.1.0: openkal for FreeBSD, on the kernel's system-call interface - #1

Merged
Sunrisepeak merged 6 commits into
mainfrom
feat/0.1.0
Nov 10, 2026
Merged

Sunrisepeak merged 6 commits into
mainfrom
feat/0.1.0

Conversation

@Sunrisepeak

@Sunrisepeak Sunrisepeak commented Nov 10, 2026 •

Copy link
Copy Markdown
Member

Summary

openkal-freebsd 0.1.0 (design 2026-11-10 §6.2 K8) is an implementation of openkal 0.25 for FreeBSD on amd64 and arm64. It issues the kernel's system calls itself and reads no header of a C library. src/sys.h states FreeBSD 14's numbers, flags and structure layouts, read from the base headers by compiling them for both architectures (they are identical); each structure's size is asserted. The carry flag and the first result register are folded into one value: the result, or the error number negated.

  • Provided (14): abort, stream, memory, env, time, random, fs, process, task, exec, terminal, timeout, map and region. provides-interfaces, kal_interfaces() and the exported names state exactly these.
  • Absent: space, net, datagram, prof and debug. Their names are not defined.
  • Unclaimed properties answer not_supported (6.2): confinement, bound lifetime, one-string starts, the 0.24 units, usage and limits, rename without replace, and the timeout forms of accept and recv_from.
  • Hosted arrangement (default). The program's runtime (FreeBSD libc and libthr) starts the program and creates its threads, and this implementation borrows both, as openkal-linux does above a C library. The arguments come from rtld's .init_array call; a context is a libthr thread, and its stack is the one pthread_attr_get_np states. -lthr is named only under cfg(all(os = "freebsd", not(env = "musl"))).
  • Standalone arrangement (feature standalone).
    • _start takes the argument block from %rdi on amd64 and x0 on arm64.
    • The .note.tag ABI brand is emitted (FreeBSD, 1400097).
    • The auxiliary vector is taken in.
    • The PT_TLS block is laid out and the thread pointer set: sysarch(AMD64_SET_FSBASE) on amd64, tpidr_el0 on arm64.
    • The program is handed to a linked C library's __libc_start_main (openkal-musl), or else the initialisers run and main is called.
    • Contexts are created with thr_new on guarded stacks and joined on the thr_exit word (UMTX_OP_WAIT).
    • The first stack comes from AT_USRSTACKBASE and AT_USRSTACKLIM.
  • Both arrangements:
    • process: pdfork(PD_DAEMON|PD_CLOEXEC) (the descriptor is held while the handle is) with fexecve, and wait6(P_PID); process groups as units; sigaction for the stop word, whose handler counts each request, skips zero and wakes waiters with _umtx_op directly.
    • task: _umtx_op private wait and wake.
    • fs: *at, getdirentries, flock.
    • memory: an mmap allocator; sysctl.
    • terminal: the tty ioctls. timeout: ppoll.
    • env: kern.proc.pathname.

How it is examined

  • Hosted, both architectures:
    • CI builds openkal's conformance suite on Linux for <arch>-freebsd above xim:<arch>-freebsd-sysroot@14.5 (ci/freebsd-platform). The engine is mcpp built from feat/cross-platform-infra until 2026.11.10.1 is released.
    • tools/defer-runner puts the suite in .deferred/, and vmactions/freebsd-vm runs it, with arm64 emulated. The verdict step requires status 0 and "0 did not hold".
  • Standalone: tools/check-standalone.sh compiles every source for both architectures -ffreestanding with no system header, and the objects carry the brand. The suite in this arrangement runs above openkal-musl on x86_64-freebsd-musl. That waits for mcpp to realise [c-abi] presents = posix on FreeBSD (cenv.cppm realise(); mcpp PR #916). The openkal-musl 0.29.1 change naming openkal-freebsd standalone is prepared.
  • mtest: 0.5.2's --run-under is not applied to the listing pass, so the suite's text verdict is CI's verdict here. tools/vm-run.py already forwards MTEST_PROTOCOL/REPORT/MODE/SELECT through the VM, and mtest is used once 0.5.3 (the fix) is released.

Test plan

  • Local, FreeBSD 14.5 amd64 VM, hosted, full,exec,random,terminal,timeout,map,region: 334 held, 0 did not hold, 12 not observed. The three-way check holds.
  • CI run 42743720353 at e0605b8, all green:
    • freebsd x86_64, hosted: in a FreeBSD 15.1 amd64 VM (a 14.0-tagged image, run through the kernel's compatibility), 322 held, 0 did not hold, 13 not observed.
    • freebsd aarch64, hosted: in an emulated FreeBSD 15.1 arm64 VM, 322 held, 0 did not hold, 13 not observed (the job took 20 minutes).
    • standalone: compiled for x86_64 and aarch64.
  • Standalone conformance through openkal-musl on x86_64-freebsd-musl (mcpp built from feat/cross-platform-infra 1d34af29, with fe3b78c2's FreeBSD row in cenv). State so far:
    • tools/run-conformance-standalone.sh builds the suite against openkal-musl's feat/freebsd branch, which names this implementation standalone and has FreeBSD's wint_t. The result is a static FreeBSD image with this package's brand (1400097).
    • Small C programs above it run in the FreeBSD 14.5 VM: one returning 3, and one using stdio, pthread_create/pthread_join (thr_new), getenv and getpid, which reports thread=42, HOME=/root.
    • The suite itself stops at once with SIGBUS ("Bus error (core dumped)", status 138), before its first line. It has not been diagnosed yet: an lldb run in the VM did not finish. This job is not in CI yet.

Fourteen of openkal 0.25's interfaces (abort, stream, memory, env, time,
random, fs, process, task, exec, terminal, timeout, map, region),
written as FreeBSD system calls issued directly (src/sys.h: the carry
flag and %rax folded into one value). The program's runtime starts the
program and creates its threads; this implementation borrows both, as
openkal-linux does above a C library, and everything else is a system
call: _umtx_op for the task word, fork and fexecve for a start, wait4,
getdirentries, ppoll, the tty ioctls, sysctl.

space, net, datagram, prof and debug are absent, not stubbed. The
standalone arrangement (_start, .note.tag, sysarch, thr_new) and aarch64
are not in 0.1.

CI builds the conformance suite on Linux for x86_64-freebsd above the
FreeBSD base sysroot (ci/freebsd-platform) and runs it in a FreeBSD
virtual machine.
- src/sys.h states FreeBSD 14's numbers, flags and structure layouts
  itself (read from the base headers for amd64 and arm64, identical,
  sizes asserted); no header of a C library is read.
- arm64 system calls (svc #0, x8, the carry flag).
- A start is pdfork (PD_DAEMON, the descriptor held while the handle is)
  and fexecve; a wait is wait6 (P_PID).
- Feature standalone: _start (%rdi / x0), the .note.tag ABI brand, the
  auxiliary vector, the PT_TLS block and the thread pointer (sysarch
  AMD64_SET_FSBASE / tpidr_el0), the hand-over to a linked C library's
  __libc_start_main, contexts by thr_new joined on the thr_exit word, the
  first stack from AT_USRSTACKBASE and AT_USRSTACKLIM.
- -lthr only on the rows of FreeBSD's own C library.
- CI: hosted conformance for x86_64 and aarch64 (built on Linux, run in
  FreeBSD VMs, aarch64 emulated); the standalone arrangement compiled for
  both architectures without a system header.
…kal-musl

tools/run-conformance-standalone.sh builds the suite for
<arch>-freebsd-musl from working trees (the specification, openkal-musl
naming this tree with the feature standalone, this repository), and runs
it with OPENKAL_CONFORMANCE_RUNNER. vm-run.py runs a program the machine
has itself (an absolute name not offered from here).
… is run in CI

The hosted arrangement's initialiser record(argc, argv, envp) was compiled in the standalone one too, where openkal-musl's start calls the initialisers with no arguments: it recorded what the registers held over the arguments the start had recorded, and the conformance suite stopped with SIGBUS in its first kal_env_arg (a core in a FreeBSD 14.5 VM: okf::length from kal_env_arg). It is now the hosted arrangement's alone. The suite built standalone over openkal-musl for x86_64-freebsd-musl holds every observation in the VM: 323 held, 0 did not hold, 13 not observed. CI runs the conformance job for both arrangements on both architectures; the standalone one builds openkal-musl at its branch of the same name, else feat/freebsd.
The rows <arch>-freebsd-musl have no C++ runtime of their own, and the suite linked the toolchain's libc++ built for the host: by chance on x86_64, and on aarch64 not at all (ld.lld: libc++.a(...) is incompatible). tools/run-conformance-standalone.sh takes the runtime's tree, built over the same openkal-musl, else the index's ^0.20.1; CI clones openkal-musl and openkal-llvm-runtime at their branch of the same name, else feat/freebsd. Locally: x86_64 323 held, 0 did not hold in a FreeBSD 14.5 VM; aarch64 builds and links.
…r branch of the same name, else their default branch
@Sunrisepeak
Sunrisepeak merged commit fd8402c into main Nov 10, 2026
5 of 10 checks passed
@Sunrisepeak
Sunrisepeak deleted the feat/0.1.0 branch November 10, 2026 12:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant