Skip to content

openkal-linux 0.5.0: implement on the kernel, so that a C library can sit above - #1

Merged
Sunrisepeak merged 5 commits into
mainfrom
feat/musl-on-openkal
Aug 20, 2026
Merged

openkal-linux 0.5.0: implement on the kernel, so that a C library can sit above#1
Sunrisepeak merged 5 commits into
mainfrom
feat/musl-on-openkal

Conversation

@Sunrisepeak

Copy link
Copy Markdown
Member

The finding this release exists for

Version 0.4 was written upon the C library of the host. That is a correct
implementation of openkal for a program that carries no runtime of its own, and
it is wrong for the program clause 1 of the specification names first among the
consumers it expects.

A C library ported onto openkal defines write, malloc and open. So does
the host's. Two definitions of one name cannot both be reached from one program,
so an implementation that calls the host's calls the ported one instead — and
the ported one calls openkal, which calls the implementation, which calls it
again. The recursion is unbounded and it is not visible in either side's
source.

The remedy is not a linking arrangement. An implementation that may sit beneath
a program supplying its own runtime must not depend upon one. Every source is
rewritten on the kernel's own system-call interface, and CI asserts the property
against the objects rather than against the source, because a source can reach a
C library through a macro.

A second consequence is less obvious and equally binding. A structure passed to
the kernel has the kernel's layout, which is not the layout of the same-named
structure in any particular C library: musl's struct stat and glibc's differ,
and an implementation compiled against one and linked with the other reads the
wrong fields. The kernel's own layouts are declared in src/sys.h.

What is new

  • src/sys.h — the calling convention for x86_64 and aarch64, the numbers, the
    kernel's structure layouts, and the error table.
  • src/tls.h, src/start.cpp — under the standalone feature: the program
    entry, a thread-local block per execution context built from the program's own
    PT_TLS, and execution contexts created with clone directly.
  • The 0.5 additions: kal_fs_open with its six flags, kal_fs_truncate,
    kal_fs_file_info, kal_stream_props, the five error values, and
    KAL_TASK_PROP_THREAD_LOCAL.
  • tests/conformance_additions.cpp — twenty assertions on those additions.

freestanding is now standalone

The feature is a statement about the program, not about how much of a C library
is present. openkal says nothing about what else a program contains: ordinarily
a program carries a runtime that has already received control and already
creates execution contexts, and this implementation borrows both. Sometimes
there is none, and then this implementation supplies both. The consumer that
knows which arrangement holds is the one that declares it.

Continuous integration

Two compiler families, gcc and llvm. Each row runs the specification's own
conformance suite (91 observations, all held), this package's tests, the
surface comparison in both forms, the assertion that the objects reference no C
library symbol, and a probe that the last assertion fails when it should.

Requires mcpplibs/openkal#1.

mcpplibs and others added 5 commits August 20, 2026 07:59
… sit above

Version 0.4 was written upon the C library of the host. That is a correct
implementation of openkal and it fails for the program openkal exists to
support. A C library ported onto openkal defines write, malloc and open; so
does the host's; one program cannot reach both definitions, so this
implementation's calls resolved to the ported library, which called openkal,
which called this implementation again. Neither side reads as though anything
is wrong.

Every interface is now implemented on the kernel's own system-call interface
for x86_64 and aarch64, and the objects reference no C library symbol - which
CI asserts against the objects rather than the source, and which a probe
confirms the check can detect the absence of.

The kernel's structure layouts are declared here rather than taken from a
header, because the same-named structure differs between C libraries and an
implementation compiled against one and linked with another would read the
wrong fields.

A "freestanding" feature supplies what a C library's first object ordinarily
supplies, for a program that is a C library: the program entry, a thread-local
storage block per execution context built from the program's own PT_TLS
segment, and execution contexts created with clone. Without it, contexts come
from the C library the program is linked against, which is the ordinary
configuration and remains the default.

kal_fs_preopen(0) now reports the working directory's absolute path rather than
".", because a C library above openkal must report a working directory and
could not have done so.

The four operations and one property openkal 0.5 adds are implemented, and a
sixth conformance suite observes each of them by its effect.
The feature is renamed from 'freestanding' to 'standalone' and restated: what
it selects is whether this implementation is the whole of the program's
environment, which is a property of the program. The finding that produced it
is unchanged and is now stated generally --- an implementation must not depend
upon a runtime the program may itself supply --- with a C library as the
instance rather than as the subject.
…s own name

The workflow named a feature this package renamed --- `freestanding' became
`standalone', because the arrangement is a statement about the program and not
about how much of a C library is present --- so the two steps that assert this
version's central property were building the default configuration and asserting
nothing about the one they name.

It also ran only this package's own tests. The specification now carries the
behavioural half of clause 9 as a suite every implementation runs, so that is
run first and this package's own tests, which examine the operations version 0.5
added, follow it.

Both are now run under two compiler families. An implementation is a contract's
evidence, and a contract that holds only under the compiler its author used is a
description of that compiler.
@Sunrisepeak
Sunrisepeak merged commit 9976346 into main Aug 20, 2026
2 checks passed
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