diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 671b149..95bd45e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1180,3 +1180,115 @@ jobs: run: | ./cross-hello-arm64 | tee run.log grep -q -- '-- failures: 0 --' run.log + + # ── AN OK IMAGE (`-openkal`, openkal SPEC clause 12) ───────────────── + # + # The image form of this library: no implementation beneath it (the loader + # that runs the image holds one), `dlopen' over libokld, the entry SPEC 12.2 + # names. Built once on Linux for both architectures, by the mcpp that has the + # target (MCPP_SOURCE_REF until it is released), and the same bytes then run + # through okrun on four systems. + # + # image-dlopen eleven observations of placing another image + # image-early-constructor the library is up before a program's constructor + images: + name: ok images (built once) + runs-on: ubuntu-24.04 + timeout-minutes: 90 + env: + MCPP_SOURCE_REF: ${{ github.event.inputs.mcpp_ref || vars.MCPP_SOURCE_REF || 'release/2026.10.26.2' }} + XLINGS_VERSION: v2026.10.26.1 + steps: + - uses: actions/checkout@v4 + - name: The specification, libokld and the builtins, from the same-named branch + run: bash tools/working-trees.sh '${{ github.head_ref || github.ref_name }}' x86_64-openkal + - name: Install xlings + run: | + curl -fsSL --retry 3 --retry-all-errors --retry-delay 2 \ + 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: The mcpp that has the target + run: | + xlings update > /dev/null 2>&1 || true + xlings install mcpp -y -g + mcpp self config --mirror GLOBAL + src="$RUNNER_TEMP/mcpp-src" + git clone --quiet --depth 1 --branch "$MCPP_SOURCE_REF" https://github.com/mcpp-community/mcpp.git "$src" + rm -f "$src/.xlings.json" + ( cd "$src" && mcpp build --release ) + built=$(find "$src/target" -type f -name mcpp | head -1) + [ -n "$built" ] || { echo "::error::mcpp did not build from $MCPP_SOURCE_REF"; exit 1; } + echo "$(cd "$(dirname "$built")" && pwd)" >> "$GITHUB_PATH" + "$built" --version + - name: The images + run: | + set -euo pipefail + for arch in x86_64 aarch64; do + mkdir -p "out/$arch" + ( cd examples/image-dlopen/plugin && mcpp build --target "$arch-openkal" ) + ( cd examples/image-dlopen && mcpp build --target "$arch-openkal" ) + ( cd examples/image-early-constructor && mcpp build --target "$arch-openkal" ) + cp examples/image-dlopen/plugin/target/"$arch"-openkal/*/bin/libplug.okso "out/$arch/" + cp examples/image-dlopen/target/"$arch"-openkal/*/bin/image-dlopen.oke "out/$arch/" + cp examples/image-early-constructor/target/"$arch"-openkal/*/bin/image-early-constructor.oke "out/$arch/" + done + (cd out && sha256sum */* | tee SHA256SUMS) + - uses: actions/upload-artifact@v4 + with: { name: musl-images, path: out } + + images-run: + name: ok images on ${{ matrix.host }} + needs: images + runs-on: ${{ matrix.os }} + timeout-minutes: 45 + env: + XLINGS_VERSION: v2026.10.26.1 + strategy: + fail-fast: false + matrix: + include: + - { host: linux-x86_64, os: ubuntu-24.04, arch: x86_64 } + - { host: linux-aarch64, os: ubuntu-24.04-arm, arch: aarch64 } + - { host: macos-arm64, os: macos-15, arch: aarch64 } + - { host: windows-x86_64, os: windows-2022, arch: x86_64 } + defaults: + run: + shell: bash + steps: + - uses: actions/download-artifact@v4 + with: { name: musl-images, path: out } + - name: Install xlings (Unix) + if: runner.os != 'Windows' + run: | + curl -fsSL --retry 3 --retry-all-errors --retry-delay 2 \ + 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: Install xlings (Windows) + if: runner.os == 'Windows' + shell: pwsh + run: | + irm https://d2learn.org/xlings-install.ps1.txt | iex + "$env:USERPROFILE\.xlings\subos\current\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append + - name: okrun, built here + run: | + xlings install mcpp -y -g + mcpp self config --mirror GLOBAL + mcpp toolchain install llvm 23.1.3 + mcpp toolchain default llvm@23.1.3 + git clone --quiet --depth 1 --branch openkal-0.17.0 https://github.com/mcpplibs/openkal-image.git "$RUNNER_TEMP/oi" + ( cd "$RUNNER_TEMP/oi/tools" && mcpp build --release ) + okrun=$(find "$RUNNER_TEMP/oi/target" -path '*bin*' \( -name okrun -o -name okrun.exe \) -type f | head -1) + [ -n "$okrun" ] || { echo "::error::okrun did not build"; exit 1; } + echo "OKRUN=$okrun" >> "$GITHUB_ENV" + - name: The same bytes + run: | + set -euo pipefail + a='${{ matrix.arch }}' + if command -v sha256sum > /dev/null; then (cd out && sha256sum -c SHA256SUMS) + else (cd out && shasum -a 256 -c SHA256SUMS); fi + "$OKRUN" "out/$a/image-dlopen.oke" "out/$a/libplug.okso" | tr -d '\r' | tee dlopen.log + grep -q -- '-- failures: 0 --' dlopen.log || { echo "::error::image-dlopen"; exit 1; } + "$OKRUN" "out/$a/image-early-constructor.oke" | tr -d '\r' | tee early.log + grep -q 'the C library was up before the constructor' early.log || { echo "::error::image-early-constructor"; exit 1; } diff --git a/README.md b/README.md index ff89f83..eecab89 100644 --- a/README.md +++ b/README.md @@ -305,6 +305,7 @@ lesser of the two, and the row returns when the schema carries `targets`. | the identity of a node | `st_dev` and `st_ino` are the implementation's answer where it has one, and **zero for both where it has none** | They were the constants 0 and 1, so every file compared equal to every other: `std::filesystem::equivalent` on two separately created files answered `true` **with no error**. openkal 0.9 carries an identity and reports whether it knows one; a caller must not read two zeroes as sameness, which is why nothing is invented for an implementation that cannot distinguish nodes. | | ownership | `chown` reports `ENOSYS`; `stat` reports 1000 for both | as the row above: a capability-oriented environment has no principal for an owner to name. | | a mode given at creation | `open(…, O_CREAT, 0600)` and `mkdir(path, 0700)` **succeed** and `stat` afterwards reports 0666 and 0777 | the row above, in the one place where it does not read as a refusal. openkal opens a file for a purpose and not for an audience, so the argument has nowhere to go. Refusing every mode but the one `stat` will report would refuse nearly every program; what a caller can rely on instead is stated below. | +| processor clocks | `CLOCK_PROCESS_CPUTIME_ID` and `clock()` are the program's processor time (**since 0.22.0**; before, every clock but the wall clock was the monotonic one, and time asleep counted as work); `CLOCK_THREAD_CPUTIME_ID` reports `EINVAL` | openkal 0.17 reports a program's processor time in `kal_program_info` and has no context's own; a clock that answered with another quantity would be answered wrongly rather than refused. | | entropy | `getrandom` reports `ENOSYS` where the backend declines `openkal.random` | openkal has no source of one to require, and this port does not invent one. The allocator's cookie and the stack canary are derived from the clock and from an address; neither is a security property here. | | a signal delivered anywhere | `raise` and `kill` perform a signal's **default action** and nothing else: terminating signals end the program, ignored ones succeed, stopping ones report `ENOSYS`, and musl's own three (32, 33, 34) are refused, so `pthread_cancel` reports `ENOSYS` | there is no delivery, so there is no handler to reach; what remains of a signal is what it does when no handler exists. `abort` reaches `kal_abort`, which raises the signal on Linux and ends with a distinguished status elsewhere — a parent can tell an abnormal end from an ordinary one on every system. | | an immediate answer about a started program | `waitpid(…, WNOHANG)` returns without the program having finished, but may wait up to one polling interval of the implementation beneath (one millisecond on Linux) | `kal_timeout_wait_process` takes a bound and openkal spells "no bound" as zero, so a caller that does not want to wait asks for the smallest bound there is. An environment rounds a bound up to what its clock can distinguish; a bound shorter than the clock is a promise no environment can keep. | @@ -633,6 +634,30 @@ rather than beneath because openkal is deliberately literal about names: it passes on the name it was given and does not know that a program is a kind of file. +## As the C library of an ok image (0.22.0) + +For the target `-openkal` (openkal SPEC clause 12) this library is built +into an **ok image**: one artifact per architecture that `okrun` runs on +Linux, macOS and Windows. Nothing of an implementation is beneath it in the +image --- the loader holds the one implementation of the process and binds the +image's `kal_*` imports to it --- so the image form differs from the others in +four places, all in `port/src/image`: + +| Item | The image form | +|---|---| +| entry | `int ok_main(void)`, the entry SPEC 12.2 names: the library comes up (if its prioritised constructor has not already brought it up), `main` runs, then the `atexit` handlers and the flush of every stream; the loader runs the finalisers and ends with the status | +| thread-local storage | emulated (SPEC 12.2): `__emutls_get_address` keeps each variable under a key of this library's own | +| `dlopen`, `dlsym`, `dladdr`, `dlclose`, `dlerror` | over libokld (`openkal-ld`), filled from `openkal.exec`; a placed image's `kal_*` imports are bound through a table of every name of `SURFACE.txt`, held weakly so that it requires no interface (SPEC 12.4), then to this image's exports and to images placed with `RTLD_GLOBAL` | +| `dl_iterate_phdr` | this image, then every placed one, so an unwinder finds each image's frames | + +The compiler-rt builtins come from `llvm.compiler-rt-builtins` (22.1.8.6), built +with the image's flags, behind the default feature `image-builtins`: on AArch64 +a `long double` is 128 bits and `printf` reaches its routines. A package that +supplies the layer itself (`openkal-llvm-runtime`) depends on this one with +`default-features = false`, since a build has one compiler runtime. `examples/image-dlopen` and +`examples/image-early-constructor` are built once on Linux for both +architectures and run through `okrun` on four systems in CI. + ## What runs above it | | | diff --git a/build.mcpp b/build.mcpp index c053c23..31070fa 100644 --- a/build.mcpp +++ b/build.mcpp @@ -132,6 +132,29 @@ int main() { mcpp::cflag(("-DOKM_VERSION=\\\"" + v + "\\\"").c_str()); } + // AN OK IMAGE'S `dlopen' BINDS A PLACED IMAGE'S `kal_*' IMPORTS BY NAME + // (port/src/image), so the names are the specification's own list, read + // from the openkal this package is built against at every build: a table + // written here by hand would fall behind the specification it names. + if (os == "openkal") { + const std::string dep = env_or_empty("MCPP_DEP_OPENKAL_DIR"); + const std::string out = env_or_empty("MCPP_OUT_DIR"); + const std::filesystem::path surface = std::filesystem::path(dep) / "SURFACE.txt"; + std::ifstream in(surface); + if (dep.empty() || out.empty() || !in) { + std::printf("mcpp:warning=openkal's SURFACE.txt cannot be read; dlopen binds no kal_* name\n"); + } + std::ofstream o(std::filesystem::path(out) / "okm_kal_names.inc"); + o << "/* Generated by openkal-musl's build.mcpp from " << surface.generic_string() << ". */\n"; + std::string line; + while (std::getline(in, line)) { + while (!line.empty() && (line.back() == '\r' || line.back() == ' ')) line.pop_back(); + if (line.rfind("kal_", 0) == 0) o << "OKM_KAL(" << line << ")\n"; + } + std::printf("mcpp:include-dir=%s\n", out.c_str()); + mcpp::rerun_if_changed(surface.string().c_str()); + } + if (fam != "gcc") return 0; // ELF NEEDS IT TOO, AND FOR THE SAME REASON THE PE BLOCK DID. The Linux diff --git a/examples/image-dlopen/mcpp.toml b/examples/image-dlopen/mcpp.toml new file mode 100644 index 0000000..a349212 --- /dev/null +++ b/examples/image-dlopen/mcpp.toml @@ -0,0 +1,17 @@ +# An ok image that places another with `dlopen' (target `-openkal'; +# openkal SPEC clause 12). The image this program places is built from +# plugin/, an image of its own with no C library, and is named on the command +# line: it is not linked to this one. +[package] +name = "image-dlopen" +version = "0.1.0" + +[dependencies] +openkal-musl = { path = "../.." } + +[build-dependencies] +openkal-tools = { git = "https://github.com/mcpplibs/openkal-image.git", branch = "openkal-0.17.0", tools = ["okld", "okrun"] } + +[targets.image-dlopen] +kind = "bin" +main = "src/main.c" diff --git a/examples/image-dlopen/plugin/mcpp.toml b/examples/image-dlopen/plugin/mcpp.toml new file mode 100644 index 0000000..32c3144 --- /dev/null +++ b/examples/image-dlopen/plugin/mcpp.toml @@ -0,0 +1,11 @@ +# The image image-dlopen places: no C library, its exports marked, its imports +# `kal_*' alone. A constructor and a destructor say when the loader ran them. +[package] +name = "plug" +version = "0.1.0" + +[build-dependencies] +openkal-tools = { git = "https://github.com/mcpplibs/openkal-image.git", branch = "openkal-0.17.0", tools = ["okld", "okrun"] } + +[targets.plug] +kind = "shared" diff --git a/examples/image-dlopen/plugin/src/plug.c b/examples/image-dlopen/plugin/src/plug.c new file mode 100644 index 0000000..417e1a1 --- /dev/null +++ b/examples/image-dlopen/plugin/src/plug.c @@ -0,0 +1,23 @@ +/* An image that another places with `dlopen'. It holds no C library: its + * imports are `kal_*' alone, and what it exports is marked. */ +typedef unsigned long kal_uintptr; +typedef long kal_intptr; +struct kal_stream { kal_uintptr h; }; +struct kal_stream kal_stdout(void); +kal_intptr kal_stream_write(struct kal_stream, const void*, kal_uintptr); + +#define EXPORT __attribute__((visibility("default"))) + +EXPORT int plug_ready; +EXPORT void (*plug_on_close)(void); + +__attribute__((constructor)) static void up(void) { plug_ready = 1; } +__attribute__((destructor)) static void down(void) { if (plug_on_close) plug_on_close(); } + +EXPORT int plug_twice(int x) { return 2 * x; } +EXPORT int plug_call(int (*callback)(int), int v) { return callback(v) + 1; } +EXPORT long plug_say(void) +{ + static const char line[] = "plugin: written through kal_stream_write\n"; + return kal_stream_write(kal_stdout(), line, sizeof line - 1); +} diff --git a/examples/image-dlopen/src/main.c b/examples/image-dlopen/src/main.c new file mode 100644 index 0000000..c1dfca2 --- /dev/null +++ b/examples/image-dlopen/src/main.c @@ -0,0 +1,70 @@ +/* `dlopen' in an ok image: eleven observations of libokld placing another + * image beneath openkal-musl. The image to place is the first argument. */ +#define _GNU_SOURCE +#include +#include +#include +#include + +static int failures; +static void check(int held, const char* what) +{ + printf("%s %s\n", held ? " ok " : " FAIL", what); + if (!held) failures++; +} + +static int doubled_by_host(int v) { return v * 10; } +static int closed; +static void on_close(void) { closed = 1; } + +struct seen { int objects; int plugin; }; +static int count(struct dl_phdr_info* info, size_t size, void* data) +{ + (void)size; + struct seen* s = data; + s->objects++; + if (info->dlpi_name && strstr(info->dlpi_name, "libplug")) s->plugin = 1; + return 0; +} + +int main(int argc, char** argv) +{ + if (argc < 2) { puts("usage: image-dlopen "); return 2; } + + check(dlopen("no-such-image.okso", RTLD_NOW) == 0, "an image that is not there is not placed"); + const char* why = dlerror(); + check(why && strstr(why, "no-such-image"), "dlerror names it"); + + void* h = dlopen(argv[1], RTLD_NOW); + if (!h) printf(" (dlerror: %s)\n", dlerror()); + check(h != 0, "the image is placed"); + if (!h) { printf("-- failures: %d --\n", failures); return 1; } + + int (*twice)(int) = (int (*)(int))dlsym(h, "plug_twice"); + check(twice != 0, "dlsym finds an export"); + check(twice && twice(21) == 42, "the export is called and returns"); + int* ready = dlsym(h, "plug_ready"); + check(ready && *ready == 1, "the image's constructor ran when it was placed"); + check(dlsym(h, "plug_absent") == 0 && dlerror() != 0, "a name it does not export is reported"); + + Dl_info info; + check(dladdr((void*)twice, &info) && info.dli_fname && strstr(info.dli_fname, "libplug") + && info.dli_fbase != 0, "dladdr names the image an address is in"); + + struct seen s = { 0, 0 }; + dl_iterate_phdr(count, &s); + check(s.objects >= 2 && s.plugin, "dl_iterate_phdr reports this image and the placed one"); + + int (*call)(int (*)(int), int) = (int (*)(int (*)(int), int))dlsym(h, "plug_call"); + check(call && call(doubled_by_host, 4) == 41, "the placed image calls back into this one"); + + long (*say)(void) = (long (*)(void))dlsym(h, "plug_say"); + check(say && say() > 0, "the placed image's kal_* import is bound"); + + void (**hook)(void) = dlsym(h, "plug_on_close"); + if (hook) *hook = on_close; + check(dlclose(h) == 0 && closed, "dlclose runs its destructor"); + + printf("-- failures: %d --\n", failures); + return failures ? 1 : 0; +} diff --git a/examples/image-early-constructor/mcpp.toml b/examples/image-early-constructor/mcpp.toml new file mode 100644 index 0000000..cdbed2f --- /dev/null +++ b/examples/image-early-constructor/mcpp.toml @@ -0,0 +1,15 @@ +# The C library is up before the program's own constructors run: the loader +# runs an image's initialisers before its entry (openkal SPEC 12.3). +[package] +name = "image-early-constructor" +version = "0.1.0" + +[dependencies] +openkal-musl = { path = "../.." } + +[build-dependencies] +openkal-tools = { git = "https://github.com/mcpplibs/openkal-image.git", branch = "openkal-0.17.0", tools = ["okld", "okrun"] } + +[targets.image-early-constructor] +kind = "bin" +main = "src/main.c" diff --git a/examples/image-early-constructor/src/main.c b/examples/image-early-constructor/src/main.c new file mode 100644 index 0000000..6c94a9b --- /dev/null +++ b/examples/image-early-constructor/src/main.c @@ -0,0 +1,23 @@ +/* A constructor that formats, allocates and reads the environment before + * `main': the loader runs it before the image's entry, so the C library has to + * be up by then (its own initialiser runs first). */ +#include +#include +#include + +static char* g_early; + +__attribute__((constructor)) static void early(void) +{ + g_early = malloc(64); + snprintf(g_early, 64, "early %d %s", 42, getenv("PATH") ? "path" : "nopath"); +} + +int main(int argc, char** argv) +{ + (void)argv; + const int ok = g_early && strncmp(g_early, "early 42 ", 9) == 0 && argc >= 1; + printf("%s\n", g_early ? g_early : "(no early value)"); + printf("early-constructor: %s\n", ok ? "the C library was up before the constructor" : "FAIL"); + return ok ? 0 : 1; +} diff --git a/examples/posix/src/main.c b/examples/posix/src/main.c index 7098a30..d8e58c9 100644 --- a/examples/posix/src/main.c +++ b/examples/posix/src/main.c @@ -177,6 +177,30 @@ int main(int argc, char **argv, char **envp) { check(el >= 20000000, "the monotonic clock advanced by at least the requested interval"); check(time(NULL) > 1700000000, "the wall clock reports a plausible time"); + /* The processor clock counts work, not time asleep: the program slept + * 200 ms above and spins about as long here. */ + { + struct timespec c0, c1, s0, s1; + const int had = clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &c0) == 0; + check(had, "the processor clock is read"); + struct timespec nap = { 0, 200 * 1000 * 1000 }; + nanosleep(&nap, NULL); + clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &c1); + const long long slept = (long long)(c1.tv_sec - c0.tv_sec) * 1000000000 + (c1.tv_nsec - c0.tv_nsec); + check(had && slept < 100000000, "time asleep is not processor time"); + clock_gettime(CLOCK_MONOTONIC, &s0); + volatile unsigned long long sink = 0; + do { + for (int i = 0; i < 100000; ++i) sink = sink + 1; + clock_gettime(CLOCK_MONOTONIC, &s1); + } while ((s1.tv_sec - s0.tv_sec) * 1000000000LL + (s1.tv_nsec - s0.tv_nsec) < 200000000LL); + struct timespec c2; + clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &c2); + const long long worked = (long long)(c2.tv_sec - c1.tv_sec) * 1000000000 + (c2.tv_nsec - c1.tv_nsec); + check(had && worked > 50000000, "and work is"); + check(clock() != (clock_t)-1, "clock() reports the processor time"); + } + /* threads and mutexes: contended */ pthread_t th[4]; counter = 0; diff --git a/mcpp.toml b/mcpp.toml index 3eb2e98..b9254cb 100644 --- a/mcpp.toml +++ b/mcpp.toml @@ -1,7 +1,7 @@ [package] namespace = "mcpplibs" name = "openkal-musl" -version = "0.21.1" +version = "0.22.0" description = "musl 1.2.5 redirected onto openkal: one C library, ported once, above every implementation of the specification rather than above one kernel." license = "Apache-2.0" @@ -163,7 +163,7 @@ lchown = { form = "enosys", note = "as chown" } tcsetattr = { form = "accepted-no-effect", note = "openkal names four positions of the terminal mode word, the fourth covering ICRNL, INLCR, IGNCR and ISTRIP together; a request that alters output post-processing, the line speed, the control characters or VMIN/VTIME is accepted and that part has no effect" } [dependencies] -openkal = "0.16.0" +openkal = "0.17.0" # An ordinary consumer of openkal declares the specification and leaves the # choice of implementation to whoever builds the program, which is what the @@ -178,7 +178,7 @@ openkal = "0.16.0" # # The consequence for a program is that it names this package and nothing else. [target.'cfg(os = "linux")'.dependencies] -openkal-linux = { version = "0.17.0", features = ["standalone"] } +openkal-linux = { version = "0.18.0", features = ["standalone"] } [target.'cfg(os = "macos")'.dependencies] # 0.12.0 is the first release of this implementation that declares which @@ -188,7 +188,7 @@ openkal-linux = { version = "0.17.0", features = ["standalone"] } # is the shape of a check that silently does not run --- while the same # consumer was answered on Linux and Windows, whose implementations have # carried the array since openkal-linux 0.15.0 and openkal-windows 0.10.0. -openkal-macos = { version = "0.14.1", features = ["standalone"] } +openkal-macos = { version = "0.15.0", features = ["standalone"] } # FIRST STEP TOWARD A BARE MACHINE, AND NOT THE WHOLE OF IT. # @@ -223,8 +223,46 @@ openkal-opensbi = { version = "0.8.2", features = ["standalone"] } [target.'cfg(os = "none")'.build] defines = ["OKM_HAS_FS=0", "OKM_HAS_PROCESS=0", "OKM_HAS_TASK=0"] +# AN OK IMAGE (`-openkal`, openkal SPEC clause 12) HOLDS NO IMPLEMENTATION. +# Its `kal_*' names are bound by the loader that runs it, to the one +# implementation of that process; this library is above them as it is above any +# other. What the image form adds is libokld --- the loader the image format +# defines --- for `dlopen', which places further images the same way. +[target.'cfg(os = "openkal")'.dependencies] +openkal-ld = "0.1.0" + +# The routines a compiler emits calls to and no C library defines --- on +# AArch64, every arithmetic operation on a 128-bit `long double`, which +# `printf' reaches. An image carries its own (SPEC 12.2: it imports `kal_*' +# alone), compiled with the image's flags from the source package, as picolibc +# does on a bare machine. Behind the default feature `image-builtins', because +# the layer has one supplier: a package that supplies `mcpp:compiler-runtime' +# itself (openkal-llvm-runtime) depends on this one with +# `default-features = false'. +[target.'cfg(os = "openkal")'.feature-deps.image-builtins] +llvm.compiler-rt-builtins = "22.1.8.6" + +# The image form's own sources (port/src/image): the entry SPEC 12.2 names, +# `dlopen' and its companions over libokld, the image's `dl_iterate_phdr', the +# helper of emulated thread-local storage, and the prioritised constructor that +# brings the library up before any other initialiser --- the loader runs them +# before the entry. musl's own `dl*' sources are for a program linked +# statically and are replaced. +[target.'cfg(os = "openkal")'.build] +sources = [ + "!port/src/okm_phdr.c", + "!musl/src/ldso/dlopen.c", + "!musl/src/ldso/dlsym.c", + "!musl/src/ldso/__dlsym.c", + "!musl/src/ldso/dlclose.c", + "!musl/src/ldso/dladdr.c", + "!musl/src/ldso/dlerror.c", + "!musl/src/ldso/dlinfo.c", + "port/src/image/*.c", +] + [target.'cfg(windows)'.dependencies] -openkal-windows = { version = "0.12.0", features = ["standalone"] } +openkal-windows = { version = "0.13.0", features = ["standalone"] } # The feature macros musl's own build establishes. # @@ -243,8 +281,11 @@ openkal-windows = { version = "0.12.0", features = ["standalone"] } # own sources has a static variable of that name. The macro musl's features.h # would have inferred is therefore not the macro musl is built with. [features] -default = ["posix"] +default = ["posix", "image-builtins"] posix = { defines = ["_XOPEN_SOURCE=700"] } +# The compiler-rt builtins of an ok image (`-openkal'); nothing on any +# other target. See the image form's feature-deps below. +image-builtins = [] [build] c_standard = "c99" @@ -674,7 +715,7 @@ ldflags = ["-nostdlib", "-lSystem", # would land in, not because the content differs today. # musl-generated/README.md records the three lines and how they are # produced. -[target.'cfg(all(arch = "x86_64", not(windows), not(os = "macos")))'.build] +[target.'cfg(all(arch = "x86_64", not(windows), not(os = "macos"), not(os = "openkal")))'.build] include_dirs = ["musl-generated/x86_64", "musl/arch/x86_64", "musl/arch/generic"] [target.'cfg(all(arch = "x86_64", windows))'.build] @@ -715,9 +756,21 @@ include_dirs = ["musl-generated/x86_64-macos", "musl/arch/x86_64", "musl/arch/ge # `kal_u64` comes from the COMPILER (`__UINT64_TYPE__`), which is authoritative # about the target's ABI; `uint64_t` came from these three lines, which carried # Linux's answer. Same width, different type, and the two do not convert. -[target.'cfg(all(arch = "aarch64", not(os = "macos")))'.build] +[target.'cfg(all(arch = "aarch64", not(os = "macos"), not(os = "openkal")))'.build] include_dirs = ["musl-generated/aarch64", "musl/arch/aarch64", "musl/arch/generic"] +# AN OK IMAGE IS COMPILED FOR NO OPERATING SYSTEM (`-unknown-none-elf`), and +# there the compiler states `wint_t` as `int` where the Linux answer is +# `unsigned` --- the one difference `okm_type_identity.c` finds between the two +# triples on either architecture (measured with clang 23, `-dM -E`). The +# calling convention, the data model and every other type are the +# architecture's, as SPEC 12.2 fixes them. +[target.'cfg(all(arch = "x86_64", os = "openkal"))'.build] +include_dirs = ["musl-generated/x86_64-openkal", "musl/arch/x86_64", "musl/arch/generic"] + +[target.'cfg(all(arch = "aarch64", os = "openkal"))'.build] +include_dirs = ["musl-generated/aarch64-openkal", "musl/arch/aarch64", "musl/arch/generic"] + [target.'cfg(all(arch = "aarch64", os = "macos"))'.build] include_dirs = ["musl-generated/aarch64-macos", "musl/arch/aarch64", "musl/arch/generic"] diff --git a/musl-generated/README.md b/musl-generated/README.md index 8f5a373..e5945ed 100644 --- a/musl-generated/README.md +++ b/musl-generated/README.md @@ -122,3 +122,12 @@ until then, `x86_64` targeting macOS fell into the generic `cfg(all(arch = "x86_64", not(windows)))` row and silently got Linux's answer for all four of these, untested, because nothing in this repository builds or runs for it. + +## The ok-image variants (`x86_64-openkal`, `aarch64-openkal`) + +Added for 0.22.0 by the same three commands, with the architecture's `ARCH`, +and one line changed: `typedef int wint_t;` where the generic header has +`typedef unsigned wint_t;`. An ok image is compiled for `-unknown-none-elf`, +and on that triple the compiler's `__WINT_TYPE__` is `int` (clang 23, both +architectures); `port/src/okm_type_identity.c` checks the header against it. +Every other line is the architecture's, as the image convention fixes it. diff --git a/musl-generated/aarch64-openkal/bits/alltypes.h b/musl-generated/aarch64-openkal/bits/alltypes.h new file mode 100644 index 0000000..e4c3db9 --- /dev/null +++ b/musl-generated/aarch64-openkal/bits/alltypes.h @@ -0,0 +1,423 @@ +#define _Addr long +#define _Int64 long +#define _Reg long + +#if __AARCH64EB__ +#define __BYTE_ORDER 4321 +#else +#define __BYTE_ORDER 1234 +#endif + +#define __LONG_MAX 0x7fffffffffffffffL + +#ifndef __cplusplus +#if defined(__NEED_wchar_t) && !defined(__DEFINED_wchar_t) +typedef unsigned wchar_t; +#define __DEFINED_wchar_t +#endif + +#endif +#if defined(__NEED_wint_t) && !defined(__DEFINED_wint_t) +typedef int wint_t; +#define __DEFINED_wint_t +#endif + + +#if defined(__NEED_blksize_t) && !defined(__DEFINED_blksize_t) +typedef int blksize_t; +#define __DEFINED_blksize_t +#endif + +#if defined(__NEED_nlink_t) && !defined(__DEFINED_nlink_t) +typedef unsigned int nlink_t; +#define __DEFINED_nlink_t +#endif + + +#if defined(__NEED_float_t) && !defined(__DEFINED_float_t) +typedef float float_t; +#define __DEFINED_float_t +#endif + +#if defined(__NEED_double_t) && !defined(__DEFINED_double_t) +typedef double double_t; +#define __DEFINED_double_t +#endif + + +#if defined(__NEED_max_align_t) && !defined(__DEFINED_max_align_t) +typedef struct { long long __ll; long double __ld; } max_align_t; +#define __DEFINED_max_align_t +#endif + +#define __LITTLE_ENDIAN 1234 +#define __BIG_ENDIAN 4321 +#define __USE_TIME_BITS64 1 + +#if defined(__NEED_size_t) && !defined(__DEFINED_size_t) +typedef unsigned _Addr size_t; +#define __DEFINED_size_t +#endif + +#if defined(__NEED_uintptr_t) && !defined(__DEFINED_uintptr_t) +typedef unsigned _Addr uintptr_t; +#define __DEFINED_uintptr_t +#endif + +#if defined(__NEED_ptrdiff_t) && !defined(__DEFINED_ptrdiff_t) +typedef _Addr ptrdiff_t; +#define __DEFINED_ptrdiff_t +#endif + +#if defined(__NEED_ssize_t) && !defined(__DEFINED_ssize_t) +typedef _Addr ssize_t; +#define __DEFINED_ssize_t +#endif + +#if defined(__NEED_intptr_t) && !defined(__DEFINED_intptr_t) +typedef _Addr intptr_t; +#define __DEFINED_intptr_t +#endif + +#if defined(__NEED_regoff_t) && !defined(__DEFINED_regoff_t) +typedef _Addr regoff_t; +#define __DEFINED_regoff_t +#endif + +#if defined(__NEED_register_t) && !defined(__DEFINED_register_t) +typedef _Reg register_t; +#define __DEFINED_register_t +#endif + +#if defined(__NEED_time_t) && !defined(__DEFINED_time_t) +typedef _Int64 time_t; +#define __DEFINED_time_t +#endif + +#if defined(__NEED_suseconds_t) && !defined(__DEFINED_suseconds_t) +typedef _Int64 suseconds_t; +#define __DEFINED_suseconds_t +#endif + + +#if defined(__NEED_int8_t) && !defined(__DEFINED_int8_t) +typedef signed char int8_t; +#define __DEFINED_int8_t +#endif + +#if defined(__NEED_int16_t) && !defined(__DEFINED_int16_t) +typedef signed short int16_t; +#define __DEFINED_int16_t +#endif + +#if defined(__NEED_int32_t) && !defined(__DEFINED_int32_t) +typedef signed int int32_t; +#define __DEFINED_int32_t +#endif + +#if defined(__NEED_int64_t) && !defined(__DEFINED_int64_t) +typedef signed _Int64 int64_t; +#define __DEFINED_int64_t +#endif + +#if defined(__NEED_intmax_t) && !defined(__DEFINED_intmax_t) +typedef signed _Int64 intmax_t; +#define __DEFINED_intmax_t +#endif + +#if defined(__NEED_uint8_t) && !defined(__DEFINED_uint8_t) +typedef unsigned char uint8_t; +#define __DEFINED_uint8_t +#endif + +#if defined(__NEED_uint16_t) && !defined(__DEFINED_uint16_t) +typedef unsigned short uint16_t; +#define __DEFINED_uint16_t +#endif + +#if defined(__NEED_uint32_t) && !defined(__DEFINED_uint32_t) +typedef unsigned int uint32_t; +#define __DEFINED_uint32_t +#endif + +#if defined(__NEED_uint64_t) && !defined(__DEFINED_uint64_t) +typedef unsigned _Int64 uint64_t; +#define __DEFINED_uint64_t +#endif + +#if defined(__NEED_u_int64_t) && !defined(__DEFINED_u_int64_t) +typedef unsigned _Int64 u_int64_t; +#define __DEFINED_u_int64_t +#endif + +#if defined(__NEED_uintmax_t) && !defined(__DEFINED_uintmax_t) +typedef unsigned _Int64 uintmax_t; +#define __DEFINED_uintmax_t +#endif + + +#if defined(__NEED_mode_t) && !defined(__DEFINED_mode_t) +typedef unsigned mode_t; +#define __DEFINED_mode_t +#endif + +#if defined(__NEED_nlink_t) && !defined(__DEFINED_nlink_t) +typedef unsigned _Reg nlink_t; +#define __DEFINED_nlink_t +#endif + +#if defined(__NEED_off_t) && !defined(__DEFINED_off_t) +typedef _Int64 off_t; +#define __DEFINED_off_t +#endif + +#if defined(__NEED_ino_t) && !defined(__DEFINED_ino_t) +typedef unsigned _Int64 ino_t; +#define __DEFINED_ino_t +#endif + +#if defined(__NEED_dev_t) && !defined(__DEFINED_dev_t) +typedef unsigned _Int64 dev_t; +#define __DEFINED_dev_t +#endif + +#if defined(__NEED_blksize_t) && !defined(__DEFINED_blksize_t) +typedef long blksize_t; +#define __DEFINED_blksize_t +#endif + +#if defined(__NEED_blkcnt_t) && !defined(__DEFINED_blkcnt_t) +typedef _Int64 blkcnt_t; +#define __DEFINED_blkcnt_t +#endif + +#if defined(__NEED_fsblkcnt_t) && !defined(__DEFINED_fsblkcnt_t) +typedef unsigned _Int64 fsblkcnt_t; +#define __DEFINED_fsblkcnt_t +#endif + +#if defined(__NEED_fsfilcnt_t) && !defined(__DEFINED_fsfilcnt_t) +typedef unsigned _Int64 fsfilcnt_t; +#define __DEFINED_fsfilcnt_t +#endif + + +#if defined(__NEED_wint_t) && !defined(__DEFINED_wint_t) +typedef int wint_t; +#define __DEFINED_wint_t +#endif + +#if defined(__NEED_wctype_t) && !defined(__DEFINED_wctype_t) +typedef unsigned long wctype_t; +#define __DEFINED_wctype_t +#endif + + +#if defined(__NEED_timer_t) && !defined(__DEFINED_timer_t) +typedef void * timer_t; +#define __DEFINED_timer_t +#endif + +#if defined(__NEED_clockid_t) && !defined(__DEFINED_clockid_t) +typedef int clockid_t; +#define __DEFINED_clockid_t +#endif + +#if defined(__NEED_clock_t) && !defined(__DEFINED_clock_t) +typedef long clock_t; +#define __DEFINED_clock_t +#endif + +#if defined(__NEED_struct_timeval) && !defined(__DEFINED_struct_timeval) +struct timeval { time_t tv_sec; suseconds_t tv_usec; }; +#define __DEFINED_struct_timeval +#endif + +#if defined(__NEED_struct_timespec) && !defined(__DEFINED_struct_timespec) +struct timespec { time_t tv_sec; int :8*(sizeof(time_t)-sizeof(long))*(__BYTE_ORDER==4321); long tv_nsec; int :8*(sizeof(time_t)-sizeof(long))*(__BYTE_ORDER!=4321); }; +#define __DEFINED_struct_timespec +#endif + + +#if defined(__NEED_pid_t) && !defined(__DEFINED_pid_t) +typedef int pid_t; +#define __DEFINED_pid_t +#endif + +#if defined(__NEED_id_t) && !defined(__DEFINED_id_t) +typedef unsigned id_t; +#define __DEFINED_id_t +#endif + +#if defined(__NEED_uid_t) && !defined(__DEFINED_uid_t) +typedef unsigned uid_t; +#define __DEFINED_uid_t +#endif + +#if defined(__NEED_gid_t) && !defined(__DEFINED_gid_t) +typedef unsigned gid_t; +#define __DEFINED_gid_t +#endif + +#if defined(__NEED_key_t) && !defined(__DEFINED_key_t) +typedef int key_t; +#define __DEFINED_key_t +#endif + +#if defined(__NEED_useconds_t) && !defined(__DEFINED_useconds_t) +typedef unsigned useconds_t; +#define __DEFINED_useconds_t +#endif + + +#ifdef __cplusplus +#if defined(__NEED_pthread_t) && !defined(__DEFINED_pthread_t) +typedef unsigned long pthread_t; +#define __DEFINED_pthread_t +#endif + +#else +#if defined(__NEED_pthread_t) && !defined(__DEFINED_pthread_t) +typedef struct __pthread * pthread_t; +#define __DEFINED_pthread_t +#endif + +#endif +#if defined(__NEED_pthread_once_t) && !defined(__DEFINED_pthread_once_t) +typedef int pthread_once_t; +#define __DEFINED_pthread_once_t +#endif + +#if defined(__NEED_pthread_key_t) && !defined(__DEFINED_pthread_key_t) +typedef unsigned pthread_key_t; +#define __DEFINED_pthread_key_t +#endif + +#if defined(__NEED_pthread_spinlock_t) && !defined(__DEFINED_pthread_spinlock_t) +typedef int pthread_spinlock_t; +#define __DEFINED_pthread_spinlock_t +#endif + +#if defined(__NEED_pthread_mutexattr_t) && !defined(__DEFINED_pthread_mutexattr_t) +typedef struct { unsigned __attr; } pthread_mutexattr_t; +#define __DEFINED_pthread_mutexattr_t +#endif + +#if defined(__NEED_pthread_condattr_t) && !defined(__DEFINED_pthread_condattr_t) +typedef struct { unsigned __attr; } pthread_condattr_t; +#define __DEFINED_pthread_condattr_t +#endif + +#if defined(__NEED_pthread_barrierattr_t) && !defined(__DEFINED_pthread_barrierattr_t) +typedef struct { unsigned __attr; } pthread_barrierattr_t; +#define __DEFINED_pthread_barrierattr_t +#endif + +#if defined(__NEED_pthread_rwlockattr_t) && !defined(__DEFINED_pthread_rwlockattr_t) +typedef struct { unsigned __attr[2]; } pthread_rwlockattr_t; +#define __DEFINED_pthread_rwlockattr_t +#endif + + +#if defined(__NEED_struct__IO_FILE) && !defined(__DEFINED_struct__IO_FILE) +struct _IO_FILE { char __x; }; +#define __DEFINED_struct__IO_FILE +#endif + +#if defined(__NEED_FILE) && !defined(__DEFINED_FILE) +typedef struct _IO_FILE FILE; +#define __DEFINED_FILE +#endif + + +#if defined(__NEED_va_list) && !defined(__DEFINED_va_list) +typedef __builtin_va_list va_list; +#define __DEFINED_va_list +#endif + +#if defined(__NEED___isoc_va_list) && !defined(__DEFINED___isoc_va_list) +typedef __builtin_va_list __isoc_va_list; +#define __DEFINED___isoc_va_list +#endif + + +#if defined(__NEED_mbstate_t) && !defined(__DEFINED_mbstate_t) +typedef struct __mbstate_t { unsigned __opaque1, __opaque2; } mbstate_t; +#define __DEFINED_mbstate_t +#endif + + +#if defined(__NEED_locale_t) && !defined(__DEFINED_locale_t) +typedef struct __locale_struct * locale_t; +#define __DEFINED_locale_t +#endif + + +#if defined(__NEED_sigset_t) && !defined(__DEFINED_sigset_t) +typedef struct __sigset_t { unsigned long __bits[128/sizeof(long)]; } sigset_t; +#define __DEFINED_sigset_t +#endif + + +#if defined(__NEED_struct_iovec) && !defined(__DEFINED_struct_iovec) +struct iovec { void *iov_base; size_t iov_len; }; +#define __DEFINED_struct_iovec +#endif + + +#if defined(__NEED_struct_winsize) && !defined(__DEFINED_struct_winsize) +struct winsize { unsigned short ws_row, ws_col, ws_xpixel, ws_ypixel; }; +#define __DEFINED_struct_winsize +#endif + + +#if defined(__NEED_socklen_t) && !defined(__DEFINED_socklen_t) +typedef unsigned socklen_t; +#define __DEFINED_socklen_t +#endif + +#if defined(__NEED_sa_family_t) && !defined(__DEFINED_sa_family_t) +typedef unsigned short sa_family_t; +#define __DEFINED_sa_family_t +#endif + + +#if defined(__NEED_pthread_attr_t) && !defined(__DEFINED_pthread_attr_t) +typedef struct { union { int __i[sizeof(long)==8?14:9]; volatile int __vi[sizeof(long)==8?14:9]; unsigned long __s[sizeof(long)==8?7:9]; } __u; } pthread_attr_t; +#define __DEFINED_pthread_attr_t +#endif + +#if defined(__NEED_pthread_mutex_t) && !defined(__DEFINED_pthread_mutex_t) +typedef struct { union { int __i[sizeof(long)==8?10:6]; volatile int __vi[sizeof(long)==8?10:6]; volatile void *volatile __p[sizeof(long)==8?5:6]; } __u; } pthread_mutex_t; +#define __DEFINED_pthread_mutex_t +#endif + +#if defined(__NEED_mtx_t) && !defined(__DEFINED_mtx_t) +typedef struct { union { int __i[sizeof(long)==8?10:6]; volatile int __vi[sizeof(long)==8?10:6]; volatile void *volatile __p[sizeof(long)==8?5:6]; } __u; } mtx_t; +#define __DEFINED_mtx_t +#endif + +#if defined(__NEED_pthread_cond_t) && !defined(__DEFINED_pthread_cond_t) +typedef struct { union { int __i[12]; volatile int __vi[12]; void *__p[12*sizeof(int)/sizeof(void*)]; } __u; } pthread_cond_t; +#define __DEFINED_pthread_cond_t +#endif + +#if defined(__NEED_cnd_t) && !defined(__DEFINED_cnd_t) +typedef struct { union { int __i[12]; volatile int __vi[12]; void *__p[12*sizeof(int)/sizeof(void*)]; } __u; } cnd_t; +#define __DEFINED_cnd_t +#endif + +#if defined(__NEED_pthread_rwlock_t) && !defined(__DEFINED_pthread_rwlock_t) +typedef struct { union { int __i[sizeof(long)==8?14:8]; volatile int __vi[sizeof(long)==8?14:8]; void *__p[sizeof(long)==8?7:8]; } __u; } pthread_rwlock_t; +#define __DEFINED_pthread_rwlock_t +#endif + +#if defined(__NEED_pthread_barrier_t) && !defined(__DEFINED_pthread_barrier_t) +typedef struct { union { int __i[sizeof(long)==8?8:5]; volatile int __vi[sizeof(long)==8?8:5]; void *__p[sizeof(long)==8?4:5]; } __u; } pthread_barrier_t; +#define __DEFINED_pthread_barrier_t +#endif + + +#undef _Addr +#undef _Int64 +#undef _Reg diff --git a/musl-generated/aarch64-openkal/bits/syscall.h b/musl-generated/aarch64-openkal/bits/syscall.h new file mode 100644 index 0000000..710d595 --- /dev/null +++ b/musl-generated/aarch64-openkal/bits/syscall.h @@ -0,0 +1,613 @@ +#define __NR_io_setup 0 +#define __NR_io_destroy 1 +#define __NR_io_submit 2 +#define __NR_io_cancel 3 +#define __NR_io_getevents 4 +#define __NR_setxattr 5 +#define __NR_lsetxattr 6 +#define __NR_fsetxattr 7 +#define __NR_getxattr 8 +#define __NR_lgetxattr 9 +#define __NR_fgetxattr 10 +#define __NR_listxattr 11 +#define __NR_llistxattr 12 +#define __NR_flistxattr 13 +#define __NR_removexattr 14 +#define __NR_lremovexattr 15 +#define __NR_fremovexattr 16 +#define __NR_getcwd 17 +#define __NR_lookup_dcookie 18 +#define __NR_eventfd2 19 +#define __NR_epoll_create1 20 +#define __NR_epoll_ctl 21 +#define __NR_epoll_pwait 22 +#define __NR_dup 23 +#define __NR_dup3 24 +#define __NR_fcntl 25 +#define __NR_inotify_init1 26 +#define __NR_inotify_add_watch 27 +#define __NR_inotify_rm_watch 28 +#define __NR_ioctl 29 +#define __NR_ioprio_set 30 +#define __NR_ioprio_get 31 +#define __NR_flock 32 +#define __NR_mknodat 33 +#define __NR_mkdirat 34 +#define __NR_unlinkat 35 +#define __NR_symlinkat 36 +#define __NR_linkat 37 +#define __NR_renameat 38 +#define __NR_umount2 39 +#define __NR_mount 40 +#define __NR_pivot_root 41 +#define __NR_nfsservctl 42 +#define __NR_statfs 43 +#define __NR_fstatfs 44 +#define __NR_truncate 45 +#define __NR_ftruncate 46 +#define __NR_fallocate 47 +#define __NR_faccessat 48 +#define __NR_chdir 49 +#define __NR_fchdir 50 +#define __NR_chroot 51 +#define __NR_fchmod 52 +#define __NR_fchmodat 53 +#define __NR_fchownat 54 +#define __NR_fchown 55 +#define __NR_openat 56 +#define __NR_close 57 +#define __NR_vhangup 58 +#define __NR_pipe2 59 +#define __NR_quotactl 60 +#define __NR_getdents64 61 +#define __NR_lseek 62 +#define __NR_read 63 +#define __NR_write 64 +#define __NR_readv 65 +#define __NR_writev 66 +#define __NR_pread64 67 +#define __NR_pwrite64 68 +#define __NR_preadv 69 +#define __NR_pwritev 70 +#define __NR_sendfile 71 +#define __NR_pselect6 72 +#define __NR_ppoll 73 +#define __NR_signalfd4 74 +#define __NR_vmsplice 75 +#define __NR_splice 76 +#define __NR_tee 77 +#define __NR_readlinkat 78 +#define __NR_newfstatat 79 +#define __NR_fstat 80 +#define __NR_sync 81 +#define __NR_fsync 82 +#define __NR_fdatasync 83 +#define __NR_sync_file_range 84 +#define __NR_timerfd_create 85 +#define __NR_timerfd_settime 86 +#define __NR_timerfd_gettime 87 +#define __NR_utimensat 88 +#define __NR_acct 89 +#define __NR_capget 90 +#define __NR_capset 91 +#define __NR_personality 92 +#define __NR_exit 93 +#define __NR_exit_group 94 +#define __NR_waitid 95 +#define __NR_set_tid_address 96 +#define __NR_unshare 97 +#define __NR_futex 98 +#define __NR_set_robust_list 99 +#define __NR_get_robust_list 100 +#define __NR_nanosleep 101 +#define __NR_getitimer 102 +#define __NR_setitimer 103 +#define __NR_kexec_load 104 +#define __NR_init_module 105 +#define __NR_delete_module 106 +#define __NR_timer_create 107 +#define __NR_timer_gettime 108 +#define __NR_timer_getoverrun 109 +#define __NR_timer_settime 110 +#define __NR_timer_delete 111 +#define __NR_clock_settime 112 +#define __NR_clock_gettime 113 +#define __NR_clock_getres 114 +#define __NR_clock_nanosleep 115 +#define __NR_syslog 116 +#define __NR_ptrace 117 +#define __NR_sched_setparam 118 +#define __NR_sched_setscheduler 119 +#define __NR_sched_getscheduler 120 +#define __NR_sched_getparam 121 +#define __NR_sched_setaffinity 122 +#define __NR_sched_getaffinity 123 +#define __NR_sched_yield 124 +#define __NR_sched_get_priority_max 125 +#define __NR_sched_get_priority_min 126 +#define __NR_sched_rr_get_interval 127 +#define __NR_restart_syscall 128 +#define __NR_kill 129 +#define __NR_tkill 130 +#define __NR_tgkill 131 +#define __NR_sigaltstack 132 +#define __NR_rt_sigsuspend 133 +#define __NR_rt_sigaction 134 +#define __NR_rt_sigprocmask 135 +#define __NR_rt_sigpending 136 +#define __NR_rt_sigtimedwait 137 +#define __NR_rt_sigqueueinfo 138 +#define __NR_rt_sigreturn 139 +#define __NR_setpriority 140 +#define __NR_getpriority 141 +#define __NR_reboot 142 +#define __NR_setregid 143 +#define __NR_setgid 144 +#define __NR_setreuid 145 +#define __NR_setuid 146 +#define __NR_setresuid 147 +#define __NR_getresuid 148 +#define __NR_setresgid 149 +#define __NR_getresgid 150 +#define __NR_setfsuid 151 +#define __NR_setfsgid 152 +#define __NR_times 153 +#define __NR_setpgid 154 +#define __NR_getpgid 155 +#define __NR_getsid 156 +#define __NR_setsid 157 +#define __NR_getgroups 158 +#define __NR_setgroups 159 +#define __NR_uname 160 +#define __NR_sethostname 161 +#define __NR_setdomainname 162 +#define __NR_getrlimit 163 +#define __NR_setrlimit 164 +#define __NR_getrusage 165 +#define __NR_umask 166 +#define __NR_prctl 167 +#define __NR_getcpu 168 +#define __NR_gettimeofday 169 +#define __NR_settimeofday 170 +#define __NR_adjtimex 171 +#define __NR_getpid 172 +#define __NR_getppid 173 +#define __NR_getuid 174 +#define __NR_geteuid 175 +#define __NR_getgid 176 +#define __NR_getegid 177 +#define __NR_gettid 178 +#define __NR_sysinfo 179 +#define __NR_mq_open 180 +#define __NR_mq_unlink 181 +#define __NR_mq_timedsend 182 +#define __NR_mq_timedreceive 183 +#define __NR_mq_notify 184 +#define __NR_mq_getsetattr 185 +#define __NR_msgget 186 +#define __NR_msgctl 187 +#define __NR_msgrcv 188 +#define __NR_msgsnd 189 +#define __NR_semget 190 +#define __NR_semctl 191 +#define __NR_semtimedop 192 +#define __NR_semop 193 +#define __NR_shmget 194 +#define __NR_shmctl 195 +#define __NR_shmat 196 +#define __NR_shmdt 197 +#define __NR_socket 198 +#define __NR_socketpair 199 +#define __NR_bind 200 +#define __NR_listen 201 +#define __NR_accept 202 +#define __NR_connect 203 +#define __NR_getsockname 204 +#define __NR_getpeername 205 +#define __NR_sendto 206 +#define __NR_recvfrom 207 +#define __NR_setsockopt 208 +#define __NR_getsockopt 209 +#define __NR_shutdown 210 +#define __NR_sendmsg 211 +#define __NR_recvmsg 212 +#define __NR_readahead 213 +#define __NR_brk 214 +#define __NR_munmap 215 +#define __NR_mremap 216 +#define __NR_add_key 217 +#define __NR_request_key 218 +#define __NR_keyctl 219 +#define __NR_clone 220 +#define __NR_execve 221 +#define __NR_mmap 222 +#define __NR_fadvise64 223 +#define __NR_swapon 224 +#define __NR_swapoff 225 +#define __NR_mprotect 226 +#define __NR_msync 227 +#define __NR_mlock 228 +#define __NR_munlock 229 +#define __NR_mlockall 230 +#define __NR_munlockall 231 +#define __NR_mincore 232 +#define __NR_madvise 233 +#define __NR_remap_file_pages 234 +#define __NR_mbind 235 +#define __NR_get_mempolicy 236 +#define __NR_set_mempolicy 237 +#define __NR_migrate_pages 238 +#define __NR_move_pages 239 +#define __NR_rt_tgsigqueueinfo 240 +#define __NR_perf_event_open 241 +#define __NR_accept4 242 +#define __NR_recvmmsg 243 +#define __NR_wait4 260 +#define __NR_prlimit64 261 +#define __NR_fanotify_init 262 +#define __NR_fanotify_mark 263 +#define __NR_name_to_handle_at 264 +#define __NR_open_by_handle_at 265 +#define __NR_clock_adjtime 266 +#define __NR_syncfs 267 +#define __NR_setns 268 +#define __NR_sendmmsg 269 +#define __NR_process_vm_readv 270 +#define __NR_process_vm_writev 271 +#define __NR_kcmp 272 +#define __NR_finit_module 273 +#define __NR_sched_setattr 274 +#define __NR_sched_getattr 275 +#define __NR_renameat2 276 +#define __NR_seccomp 277 +#define __NR_getrandom 278 +#define __NR_memfd_create 279 +#define __NR_bpf 280 +#define __NR_execveat 281 +#define __NR_userfaultfd 282 +#define __NR_membarrier 283 +#define __NR_mlock2 284 +#define __NR_copy_file_range 285 +#define __NR_preadv2 286 +#define __NR_pwritev2 287 +#define __NR_pkey_mprotect 288 +#define __NR_pkey_alloc 289 +#define __NR_pkey_free 290 +#define __NR_statx 291 +#define __NR_io_pgetevents 292 +#define __NR_rseq 293 +#define __NR_kexec_file_load 294 +#define __NR_pidfd_send_signal 424 +#define __NR_io_uring_setup 425 +#define __NR_io_uring_enter 426 +#define __NR_io_uring_register 427 +#define __NR_open_tree 428 +#define __NR_move_mount 429 +#define __NR_fsopen 430 +#define __NR_fsconfig 431 +#define __NR_fsmount 432 +#define __NR_fspick 433 +#define __NR_pidfd_open 434 +#define __NR_clone3 435 +#define __NR_close_range 436 +#define __NR_openat2 437 +#define __NR_pidfd_getfd 438 +#define __NR_faccessat2 439 +#define __NR_process_madvise 440 +#define __NR_epoll_pwait2 441 +#define __NR_mount_setattr 442 +#define __NR_landlock_create_ruleset 444 +#define __NR_landlock_add_rule 445 +#define __NR_landlock_restrict_self 446 +#define __NR_process_mrelease 448 +#define __NR_futex_waitv 449 +#define __NR_set_mempolicy_home_node 450 +#define __NR_cachestat 451 +#define __NR_fchmodat2 452 + +#define SYS_io_setup 0 +#define SYS_io_destroy 1 +#define SYS_io_submit 2 +#define SYS_io_cancel 3 +#define SYS_io_getevents 4 +#define SYS_setxattr 5 +#define SYS_lsetxattr 6 +#define SYS_fsetxattr 7 +#define SYS_getxattr 8 +#define SYS_lgetxattr 9 +#define SYS_fgetxattr 10 +#define SYS_listxattr 11 +#define SYS_llistxattr 12 +#define SYS_flistxattr 13 +#define SYS_removexattr 14 +#define SYS_lremovexattr 15 +#define SYS_fremovexattr 16 +#define SYS_getcwd 17 +#define SYS_lookup_dcookie 18 +#define SYS_eventfd2 19 +#define SYS_epoll_create1 20 +#define SYS_epoll_ctl 21 +#define SYS_epoll_pwait 22 +#define SYS_dup 23 +#define SYS_dup3 24 +#define SYS_fcntl 25 +#define SYS_inotify_init1 26 +#define SYS_inotify_add_watch 27 +#define SYS_inotify_rm_watch 28 +#define SYS_ioctl 29 +#define SYS_ioprio_set 30 +#define SYS_ioprio_get 31 +#define SYS_flock 32 +#define SYS_mknodat 33 +#define SYS_mkdirat 34 +#define SYS_unlinkat 35 +#define SYS_symlinkat 36 +#define SYS_linkat 37 +#define SYS_renameat 38 +#define SYS_umount2 39 +#define SYS_mount 40 +#define SYS_pivot_root 41 +#define SYS_nfsservctl 42 +#define SYS_statfs 43 +#define SYS_fstatfs 44 +#define SYS_truncate 45 +#define SYS_ftruncate 46 +#define SYS_fallocate 47 +#define SYS_faccessat 48 +#define SYS_chdir 49 +#define SYS_fchdir 50 +#define SYS_chroot 51 +#define SYS_fchmod 52 +#define SYS_fchmodat 53 +#define SYS_fchownat 54 +#define SYS_fchown 55 +#define SYS_openat 56 +#define SYS_close 57 +#define SYS_vhangup 58 +#define SYS_pipe2 59 +#define SYS_quotactl 60 +#define SYS_getdents64 61 +#define SYS_lseek 62 +#define SYS_read 63 +#define SYS_write 64 +#define SYS_readv 65 +#define SYS_writev 66 +#define SYS_pread64 67 +#define SYS_pwrite64 68 +#define SYS_preadv 69 +#define SYS_pwritev 70 +#define SYS_sendfile 71 +#define SYS_pselect6 72 +#define SYS_ppoll 73 +#define SYS_signalfd4 74 +#define SYS_vmsplice 75 +#define SYS_splice 76 +#define SYS_tee 77 +#define SYS_readlinkat 78 +#define SYS_newfstatat 79 +#define SYS_fstat 80 +#define SYS_sync 81 +#define SYS_fsync 82 +#define SYS_fdatasync 83 +#define SYS_sync_file_range 84 +#define SYS_timerfd_create 85 +#define SYS_timerfd_settime 86 +#define SYS_timerfd_gettime 87 +#define SYS_utimensat 88 +#define SYS_acct 89 +#define SYS_capget 90 +#define SYS_capset 91 +#define SYS_personality 92 +#define SYS_exit 93 +#define SYS_exit_group 94 +#define SYS_waitid 95 +#define SYS_set_tid_address 96 +#define SYS_unshare 97 +#define SYS_futex 98 +#define SYS_set_robust_list 99 +#define SYS_get_robust_list 100 +#define SYS_nanosleep 101 +#define SYS_getitimer 102 +#define SYS_setitimer 103 +#define SYS_kexec_load 104 +#define SYS_init_module 105 +#define SYS_delete_module 106 +#define SYS_timer_create 107 +#define SYS_timer_gettime 108 +#define SYS_timer_getoverrun 109 +#define SYS_timer_settime 110 +#define SYS_timer_delete 111 +#define SYS_clock_settime 112 +#define SYS_clock_gettime 113 +#define SYS_clock_getres 114 +#define SYS_clock_nanosleep 115 +#define SYS_syslog 116 +#define SYS_ptrace 117 +#define SYS_sched_setparam 118 +#define SYS_sched_setscheduler 119 +#define SYS_sched_getscheduler 120 +#define SYS_sched_getparam 121 +#define SYS_sched_setaffinity 122 +#define SYS_sched_getaffinity 123 +#define SYS_sched_yield 124 +#define SYS_sched_get_priority_max 125 +#define SYS_sched_get_priority_min 126 +#define SYS_sched_rr_get_interval 127 +#define SYS_restart_syscall 128 +#define SYS_kill 129 +#define SYS_tkill 130 +#define SYS_tgkill 131 +#define SYS_sigaltstack 132 +#define SYS_rt_sigsuspend 133 +#define SYS_rt_sigaction 134 +#define SYS_rt_sigprocmask 135 +#define SYS_rt_sigpending 136 +#define SYS_rt_sigtimedwait 137 +#define SYS_rt_sigqueueinfo 138 +#define SYS_rt_sigreturn 139 +#define SYS_setpriority 140 +#define SYS_getpriority 141 +#define SYS_reboot 142 +#define SYS_setregid 143 +#define SYS_setgid 144 +#define SYS_setreuid 145 +#define SYS_setuid 146 +#define SYS_setresuid 147 +#define SYS_getresuid 148 +#define SYS_setresgid 149 +#define SYS_getresgid 150 +#define SYS_setfsuid 151 +#define SYS_setfsgid 152 +#define SYS_times 153 +#define SYS_setpgid 154 +#define SYS_getpgid 155 +#define SYS_getsid 156 +#define SYS_setsid 157 +#define SYS_getgroups 158 +#define SYS_setgroups 159 +#define SYS_uname 160 +#define SYS_sethostname 161 +#define SYS_setdomainname 162 +#define SYS_getrlimit 163 +#define SYS_setrlimit 164 +#define SYS_getrusage 165 +#define SYS_umask 166 +#define SYS_prctl 167 +#define SYS_getcpu 168 +#define SYS_gettimeofday 169 +#define SYS_settimeofday 170 +#define SYS_adjtimex 171 +#define SYS_getpid 172 +#define SYS_getppid 173 +#define SYS_getuid 174 +#define SYS_geteuid 175 +#define SYS_getgid 176 +#define SYS_getegid 177 +#define SYS_gettid 178 +#define SYS_sysinfo 179 +#define SYS_mq_open 180 +#define SYS_mq_unlink 181 +#define SYS_mq_timedsend 182 +#define SYS_mq_timedreceive 183 +#define SYS_mq_notify 184 +#define SYS_mq_getsetattr 185 +#define SYS_msgget 186 +#define SYS_msgctl 187 +#define SYS_msgrcv 188 +#define SYS_msgsnd 189 +#define SYS_semget 190 +#define SYS_semctl 191 +#define SYS_semtimedop 192 +#define SYS_semop 193 +#define SYS_shmget 194 +#define SYS_shmctl 195 +#define SYS_shmat 196 +#define SYS_shmdt 197 +#define SYS_socket 198 +#define SYS_socketpair 199 +#define SYS_bind 200 +#define SYS_listen 201 +#define SYS_accept 202 +#define SYS_connect 203 +#define SYS_getsockname 204 +#define SYS_getpeername 205 +#define SYS_sendto 206 +#define SYS_recvfrom 207 +#define SYS_setsockopt 208 +#define SYS_getsockopt 209 +#define SYS_shutdown 210 +#define SYS_sendmsg 211 +#define SYS_recvmsg 212 +#define SYS_readahead 213 +#define SYS_brk 214 +#define SYS_munmap 215 +#define SYS_mremap 216 +#define SYS_add_key 217 +#define SYS_request_key 218 +#define SYS_keyctl 219 +#define SYS_clone 220 +#define SYS_execve 221 +#define SYS_mmap 222 +#define SYS_fadvise64 223 +#define SYS_swapon 224 +#define SYS_swapoff 225 +#define SYS_mprotect 226 +#define SYS_msync 227 +#define SYS_mlock 228 +#define SYS_munlock 229 +#define SYS_mlockall 230 +#define SYS_munlockall 231 +#define SYS_mincore 232 +#define SYS_madvise 233 +#define SYS_remap_file_pages 234 +#define SYS_mbind 235 +#define SYS_get_mempolicy 236 +#define SYS_set_mempolicy 237 +#define SYS_migrate_pages 238 +#define SYS_move_pages 239 +#define SYS_rt_tgsigqueueinfo 240 +#define SYS_perf_event_open 241 +#define SYS_accept4 242 +#define SYS_recvmmsg 243 +#define SYS_wait4 260 +#define SYS_prlimit64 261 +#define SYS_fanotify_init 262 +#define SYS_fanotify_mark 263 +#define SYS_name_to_handle_at 264 +#define SYS_open_by_handle_at 265 +#define SYS_clock_adjtime 266 +#define SYS_syncfs 267 +#define SYS_setns 268 +#define SYS_sendmmsg 269 +#define SYS_process_vm_readv 270 +#define SYS_process_vm_writev 271 +#define SYS_kcmp 272 +#define SYS_finit_module 273 +#define SYS_sched_setattr 274 +#define SYS_sched_getattr 275 +#define SYS_renameat2 276 +#define SYS_seccomp 277 +#define SYS_getrandom 278 +#define SYS_memfd_create 279 +#define SYS_bpf 280 +#define SYS_execveat 281 +#define SYS_userfaultfd 282 +#define SYS_membarrier 283 +#define SYS_mlock2 284 +#define SYS_copy_file_range 285 +#define SYS_preadv2 286 +#define SYS_pwritev2 287 +#define SYS_pkey_mprotect 288 +#define SYS_pkey_alloc 289 +#define SYS_pkey_free 290 +#define SYS_statx 291 +#define SYS_io_pgetevents 292 +#define SYS_rseq 293 +#define SYS_kexec_file_load 294 +#define SYS_pidfd_send_signal 424 +#define SYS_io_uring_setup 425 +#define SYS_io_uring_enter 426 +#define SYS_io_uring_register 427 +#define SYS_open_tree 428 +#define SYS_move_mount 429 +#define SYS_fsopen 430 +#define SYS_fsconfig 431 +#define SYS_fsmount 432 +#define SYS_fspick 433 +#define SYS_pidfd_open 434 +#define SYS_clone3 435 +#define SYS_close_range 436 +#define SYS_openat2 437 +#define SYS_pidfd_getfd 438 +#define SYS_faccessat2 439 +#define SYS_process_madvise 440 +#define SYS_epoll_pwait2 441 +#define SYS_mount_setattr 442 +#define SYS_landlock_create_ruleset 444 +#define SYS_landlock_add_rule 445 +#define SYS_landlock_restrict_self 446 +#define SYS_process_mrelease 448 +#define SYS_futex_waitv 449 +#define SYS_set_mempolicy_home_node 450 +#define SYS_cachestat 451 +#define SYS_fchmodat2 452 diff --git a/musl-generated/x86_64-openkal/bits/alltypes.h b/musl-generated/x86_64-openkal/bits/alltypes.h new file mode 100644 index 0000000..8099d19 --- /dev/null +++ b/musl-generated/x86_64-openkal/bits/alltypes.h @@ -0,0 +1,415 @@ +#define _Addr long +#define _Int64 long +#define _Reg long + +#define __BYTE_ORDER 1234 +#define __LONG_MAX 0x7fffffffffffffffL + +#ifndef __cplusplus +#if defined(__NEED_wchar_t) && !defined(__DEFINED_wchar_t) +typedef int wchar_t; +#define __DEFINED_wchar_t +#endif + +#endif + +#if defined(__FLT_EVAL_METHOD__) && __FLT_EVAL_METHOD__ == 2 +#if defined(__NEED_float_t) && !defined(__DEFINED_float_t) +typedef long double float_t; +#define __DEFINED_float_t +#endif + +#if defined(__NEED_double_t) && !defined(__DEFINED_double_t) +typedef long double double_t; +#define __DEFINED_double_t +#endif + +#else +#if defined(__NEED_float_t) && !defined(__DEFINED_float_t) +typedef float float_t; +#define __DEFINED_float_t +#endif + +#if defined(__NEED_double_t) && !defined(__DEFINED_double_t) +typedef double double_t; +#define __DEFINED_double_t +#endif + +#endif + +#if defined(__NEED_max_align_t) && !defined(__DEFINED_max_align_t) +typedef struct { long long __ll; long double __ld; } max_align_t; +#define __DEFINED_max_align_t +#endif + +#define __LITTLE_ENDIAN 1234 +#define __BIG_ENDIAN 4321 +#define __USE_TIME_BITS64 1 + +#if defined(__NEED_size_t) && !defined(__DEFINED_size_t) +typedef unsigned _Addr size_t; +#define __DEFINED_size_t +#endif + +#if defined(__NEED_uintptr_t) && !defined(__DEFINED_uintptr_t) +typedef unsigned _Addr uintptr_t; +#define __DEFINED_uintptr_t +#endif + +#if defined(__NEED_ptrdiff_t) && !defined(__DEFINED_ptrdiff_t) +typedef _Addr ptrdiff_t; +#define __DEFINED_ptrdiff_t +#endif + +#if defined(__NEED_ssize_t) && !defined(__DEFINED_ssize_t) +typedef _Addr ssize_t; +#define __DEFINED_ssize_t +#endif + +#if defined(__NEED_intptr_t) && !defined(__DEFINED_intptr_t) +typedef _Addr intptr_t; +#define __DEFINED_intptr_t +#endif + +#if defined(__NEED_regoff_t) && !defined(__DEFINED_regoff_t) +typedef _Addr regoff_t; +#define __DEFINED_regoff_t +#endif + +#if defined(__NEED_register_t) && !defined(__DEFINED_register_t) +typedef _Reg register_t; +#define __DEFINED_register_t +#endif + +#if defined(__NEED_time_t) && !defined(__DEFINED_time_t) +typedef _Int64 time_t; +#define __DEFINED_time_t +#endif + +#if defined(__NEED_suseconds_t) && !defined(__DEFINED_suseconds_t) +typedef _Int64 suseconds_t; +#define __DEFINED_suseconds_t +#endif + + +#if defined(__NEED_int8_t) && !defined(__DEFINED_int8_t) +typedef signed char int8_t; +#define __DEFINED_int8_t +#endif + +#if defined(__NEED_int16_t) && !defined(__DEFINED_int16_t) +typedef signed short int16_t; +#define __DEFINED_int16_t +#endif + +#if defined(__NEED_int32_t) && !defined(__DEFINED_int32_t) +typedef signed int int32_t; +#define __DEFINED_int32_t +#endif + +#if defined(__NEED_int64_t) && !defined(__DEFINED_int64_t) +typedef signed _Int64 int64_t; +#define __DEFINED_int64_t +#endif + +#if defined(__NEED_intmax_t) && !defined(__DEFINED_intmax_t) +typedef signed _Int64 intmax_t; +#define __DEFINED_intmax_t +#endif + +#if defined(__NEED_uint8_t) && !defined(__DEFINED_uint8_t) +typedef unsigned char uint8_t; +#define __DEFINED_uint8_t +#endif + +#if defined(__NEED_uint16_t) && !defined(__DEFINED_uint16_t) +typedef unsigned short uint16_t; +#define __DEFINED_uint16_t +#endif + +#if defined(__NEED_uint32_t) && !defined(__DEFINED_uint32_t) +typedef unsigned int uint32_t; +#define __DEFINED_uint32_t +#endif + +#if defined(__NEED_uint64_t) && !defined(__DEFINED_uint64_t) +typedef unsigned _Int64 uint64_t; +#define __DEFINED_uint64_t +#endif + +#if defined(__NEED_u_int64_t) && !defined(__DEFINED_u_int64_t) +typedef unsigned _Int64 u_int64_t; +#define __DEFINED_u_int64_t +#endif + +#if defined(__NEED_uintmax_t) && !defined(__DEFINED_uintmax_t) +typedef unsigned _Int64 uintmax_t; +#define __DEFINED_uintmax_t +#endif + + +#if defined(__NEED_mode_t) && !defined(__DEFINED_mode_t) +typedef unsigned mode_t; +#define __DEFINED_mode_t +#endif + +#if defined(__NEED_nlink_t) && !defined(__DEFINED_nlink_t) +typedef unsigned _Reg nlink_t; +#define __DEFINED_nlink_t +#endif + +#if defined(__NEED_off_t) && !defined(__DEFINED_off_t) +typedef _Int64 off_t; +#define __DEFINED_off_t +#endif + +#if defined(__NEED_ino_t) && !defined(__DEFINED_ino_t) +typedef unsigned _Int64 ino_t; +#define __DEFINED_ino_t +#endif + +#if defined(__NEED_dev_t) && !defined(__DEFINED_dev_t) +typedef unsigned _Int64 dev_t; +#define __DEFINED_dev_t +#endif + +#if defined(__NEED_blksize_t) && !defined(__DEFINED_blksize_t) +typedef long blksize_t; +#define __DEFINED_blksize_t +#endif + +#if defined(__NEED_blkcnt_t) && !defined(__DEFINED_blkcnt_t) +typedef _Int64 blkcnt_t; +#define __DEFINED_blkcnt_t +#endif + +#if defined(__NEED_fsblkcnt_t) && !defined(__DEFINED_fsblkcnt_t) +typedef unsigned _Int64 fsblkcnt_t; +#define __DEFINED_fsblkcnt_t +#endif + +#if defined(__NEED_fsfilcnt_t) && !defined(__DEFINED_fsfilcnt_t) +typedef unsigned _Int64 fsfilcnt_t; +#define __DEFINED_fsfilcnt_t +#endif + + +#if defined(__NEED_wint_t) && !defined(__DEFINED_wint_t) +typedef int wint_t; +#define __DEFINED_wint_t +#endif + +#if defined(__NEED_wctype_t) && !defined(__DEFINED_wctype_t) +typedef unsigned long wctype_t; +#define __DEFINED_wctype_t +#endif + + +#if defined(__NEED_timer_t) && !defined(__DEFINED_timer_t) +typedef void * timer_t; +#define __DEFINED_timer_t +#endif + +#if defined(__NEED_clockid_t) && !defined(__DEFINED_clockid_t) +typedef int clockid_t; +#define __DEFINED_clockid_t +#endif + +#if defined(__NEED_clock_t) && !defined(__DEFINED_clock_t) +typedef long clock_t; +#define __DEFINED_clock_t +#endif + +#if defined(__NEED_struct_timeval) && !defined(__DEFINED_struct_timeval) +struct timeval { time_t tv_sec; suseconds_t tv_usec; }; +#define __DEFINED_struct_timeval +#endif + +#if defined(__NEED_struct_timespec) && !defined(__DEFINED_struct_timespec) +struct timespec { time_t tv_sec; int :8*(sizeof(time_t)-sizeof(long))*(__BYTE_ORDER==4321); long tv_nsec; int :8*(sizeof(time_t)-sizeof(long))*(__BYTE_ORDER!=4321); }; +#define __DEFINED_struct_timespec +#endif + + +#if defined(__NEED_pid_t) && !defined(__DEFINED_pid_t) +typedef int pid_t; +#define __DEFINED_pid_t +#endif + +#if defined(__NEED_id_t) && !defined(__DEFINED_id_t) +typedef unsigned id_t; +#define __DEFINED_id_t +#endif + +#if defined(__NEED_uid_t) && !defined(__DEFINED_uid_t) +typedef unsigned uid_t; +#define __DEFINED_uid_t +#endif + +#if defined(__NEED_gid_t) && !defined(__DEFINED_gid_t) +typedef unsigned gid_t; +#define __DEFINED_gid_t +#endif + +#if defined(__NEED_key_t) && !defined(__DEFINED_key_t) +typedef int key_t; +#define __DEFINED_key_t +#endif + +#if defined(__NEED_useconds_t) && !defined(__DEFINED_useconds_t) +typedef unsigned useconds_t; +#define __DEFINED_useconds_t +#endif + + +#ifdef __cplusplus +#if defined(__NEED_pthread_t) && !defined(__DEFINED_pthread_t) +typedef unsigned long pthread_t; +#define __DEFINED_pthread_t +#endif + +#else +#if defined(__NEED_pthread_t) && !defined(__DEFINED_pthread_t) +typedef struct __pthread * pthread_t; +#define __DEFINED_pthread_t +#endif + +#endif +#if defined(__NEED_pthread_once_t) && !defined(__DEFINED_pthread_once_t) +typedef int pthread_once_t; +#define __DEFINED_pthread_once_t +#endif + +#if defined(__NEED_pthread_key_t) && !defined(__DEFINED_pthread_key_t) +typedef unsigned pthread_key_t; +#define __DEFINED_pthread_key_t +#endif + +#if defined(__NEED_pthread_spinlock_t) && !defined(__DEFINED_pthread_spinlock_t) +typedef int pthread_spinlock_t; +#define __DEFINED_pthread_spinlock_t +#endif + +#if defined(__NEED_pthread_mutexattr_t) && !defined(__DEFINED_pthread_mutexattr_t) +typedef struct { unsigned __attr; } pthread_mutexattr_t; +#define __DEFINED_pthread_mutexattr_t +#endif + +#if defined(__NEED_pthread_condattr_t) && !defined(__DEFINED_pthread_condattr_t) +typedef struct { unsigned __attr; } pthread_condattr_t; +#define __DEFINED_pthread_condattr_t +#endif + +#if defined(__NEED_pthread_barrierattr_t) && !defined(__DEFINED_pthread_barrierattr_t) +typedef struct { unsigned __attr; } pthread_barrierattr_t; +#define __DEFINED_pthread_barrierattr_t +#endif + +#if defined(__NEED_pthread_rwlockattr_t) && !defined(__DEFINED_pthread_rwlockattr_t) +typedef struct { unsigned __attr[2]; } pthread_rwlockattr_t; +#define __DEFINED_pthread_rwlockattr_t +#endif + + +#if defined(__NEED_struct__IO_FILE) && !defined(__DEFINED_struct__IO_FILE) +struct _IO_FILE { char __x; }; +#define __DEFINED_struct__IO_FILE +#endif + +#if defined(__NEED_FILE) && !defined(__DEFINED_FILE) +typedef struct _IO_FILE FILE; +#define __DEFINED_FILE +#endif + + +#if defined(__NEED_va_list) && !defined(__DEFINED_va_list) +typedef __builtin_va_list va_list; +#define __DEFINED_va_list +#endif + +#if defined(__NEED___isoc_va_list) && !defined(__DEFINED___isoc_va_list) +typedef __builtin_va_list __isoc_va_list; +#define __DEFINED___isoc_va_list +#endif + + +#if defined(__NEED_mbstate_t) && !defined(__DEFINED_mbstate_t) +typedef struct __mbstate_t { unsigned __opaque1, __opaque2; } mbstate_t; +#define __DEFINED_mbstate_t +#endif + + +#if defined(__NEED_locale_t) && !defined(__DEFINED_locale_t) +typedef struct __locale_struct * locale_t; +#define __DEFINED_locale_t +#endif + + +#if defined(__NEED_sigset_t) && !defined(__DEFINED_sigset_t) +typedef struct __sigset_t { unsigned long __bits[128/sizeof(long)]; } sigset_t; +#define __DEFINED_sigset_t +#endif + + +#if defined(__NEED_struct_iovec) && !defined(__DEFINED_struct_iovec) +struct iovec { void *iov_base; size_t iov_len; }; +#define __DEFINED_struct_iovec +#endif + + +#if defined(__NEED_struct_winsize) && !defined(__DEFINED_struct_winsize) +struct winsize { unsigned short ws_row, ws_col, ws_xpixel, ws_ypixel; }; +#define __DEFINED_struct_winsize +#endif + + +#if defined(__NEED_socklen_t) && !defined(__DEFINED_socklen_t) +typedef unsigned socklen_t; +#define __DEFINED_socklen_t +#endif + +#if defined(__NEED_sa_family_t) && !defined(__DEFINED_sa_family_t) +typedef unsigned short sa_family_t; +#define __DEFINED_sa_family_t +#endif + + +#if defined(__NEED_pthread_attr_t) && !defined(__DEFINED_pthread_attr_t) +typedef struct { union { int __i[sizeof(long)==8?14:9]; volatile int __vi[sizeof(long)==8?14:9]; unsigned long __s[sizeof(long)==8?7:9]; } __u; } pthread_attr_t; +#define __DEFINED_pthread_attr_t +#endif + +#if defined(__NEED_pthread_mutex_t) && !defined(__DEFINED_pthread_mutex_t) +typedef struct { union { int __i[sizeof(long)==8?10:6]; volatile int __vi[sizeof(long)==8?10:6]; volatile void *volatile __p[sizeof(long)==8?5:6]; } __u; } pthread_mutex_t; +#define __DEFINED_pthread_mutex_t +#endif + +#if defined(__NEED_mtx_t) && !defined(__DEFINED_mtx_t) +typedef struct { union { int __i[sizeof(long)==8?10:6]; volatile int __vi[sizeof(long)==8?10:6]; volatile void *volatile __p[sizeof(long)==8?5:6]; } __u; } mtx_t; +#define __DEFINED_mtx_t +#endif + +#if defined(__NEED_pthread_cond_t) && !defined(__DEFINED_pthread_cond_t) +typedef struct { union { int __i[12]; volatile int __vi[12]; void *__p[12*sizeof(int)/sizeof(void*)]; } __u; } pthread_cond_t; +#define __DEFINED_pthread_cond_t +#endif + +#if defined(__NEED_cnd_t) && !defined(__DEFINED_cnd_t) +typedef struct { union { int __i[12]; volatile int __vi[12]; void *__p[12*sizeof(int)/sizeof(void*)]; } __u; } cnd_t; +#define __DEFINED_cnd_t +#endif + +#if defined(__NEED_pthread_rwlock_t) && !defined(__DEFINED_pthread_rwlock_t) +typedef struct { union { int __i[sizeof(long)==8?14:8]; volatile int __vi[sizeof(long)==8?14:8]; void *__p[sizeof(long)==8?7:8]; } __u; } pthread_rwlock_t; +#define __DEFINED_pthread_rwlock_t +#endif + +#if defined(__NEED_pthread_barrier_t) && !defined(__DEFINED_pthread_barrier_t) +typedef struct { union { int __i[sizeof(long)==8?8:5]; volatile int __vi[sizeof(long)==8?8:5]; void *__p[sizeof(long)==8?4:5]; } __u; } pthread_barrier_t; +#define __DEFINED_pthread_barrier_t +#endif + + +#undef _Addr +#undef _Int64 +#undef _Reg diff --git a/musl-generated/x86_64-openkal/bits/syscall.h b/musl-generated/x86_64-openkal/bits/syscall.h new file mode 100644 index 0000000..25ccb44 --- /dev/null +++ b/musl-generated/x86_64-openkal/bits/syscall.h @@ -0,0 +1,727 @@ +#define __NR_read 0 +#define __NR_write 1 +#define __NR_open 2 +#define __NR_close 3 +#define __NR_stat 4 +#define __NR_fstat 5 +#define __NR_lstat 6 +#define __NR_poll 7 +#define __NR_lseek 8 +#define __NR_mmap 9 +#define __NR_mprotect 10 +#define __NR_munmap 11 +#define __NR_brk 12 +#define __NR_rt_sigaction 13 +#define __NR_rt_sigprocmask 14 +#define __NR_rt_sigreturn 15 +#define __NR_ioctl 16 +#define __NR_pread64 17 +#define __NR_pwrite64 18 +#define __NR_readv 19 +#define __NR_writev 20 +#define __NR_access 21 +#define __NR_pipe 22 +#define __NR_select 23 +#define __NR_sched_yield 24 +#define __NR_mremap 25 +#define __NR_msync 26 +#define __NR_mincore 27 +#define __NR_madvise 28 +#define __NR_shmget 29 +#define __NR_shmat 30 +#define __NR_shmctl 31 +#define __NR_dup 32 +#define __NR_dup2 33 +#define __NR_pause 34 +#define __NR_nanosleep 35 +#define __NR_getitimer 36 +#define __NR_alarm 37 +#define __NR_setitimer 38 +#define __NR_getpid 39 +#define __NR_sendfile 40 +#define __NR_socket 41 +#define __NR_connect 42 +#define __NR_accept 43 +#define __NR_sendto 44 +#define __NR_recvfrom 45 +#define __NR_sendmsg 46 +#define __NR_recvmsg 47 +#define __NR_shutdown 48 +#define __NR_bind 49 +#define __NR_listen 50 +#define __NR_getsockname 51 +#define __NR_getpeername 52 +#define __NR_socketpair 53 +#define __NR_setsockopt 54 +#define __NR_getsockopt 55 +#define __NR_clone 56 +#define __NR_fork 57 +#define __NR_vfork 58 +#define __NR_execve 59 +#define __NR_exit 60 +#define __NR_wait4 61 +#define __NR_kill 62 +#define __NR_uname 63 +#define __NR_semget 64 +#define __NR_semop 65 +#define __NR_semctl 66 +#define __NR_shmdt 67 +#define __NR_msgget 68 +#define __NR_msgsnd 69 +#define __NR_msgrcv 70 +#define __NR_msgctl 71 +#define __NR_fcntl 72 +#define __NR_flock 73 +#define __NR_fsync 74 +#define __NR_fdatasync 75 +#define __NR_truncate 76 +#define __NR_ftruncate 77 +#define __NR_getdents 78 +#define __NR_getcwd 79 +#define __NR_chdir 80 +#define __NR_fchdir 81 +#define __NR_rename 82 +#define __NR_mkdir 83 +#define __NR_rmdir 84 +#define __NR_creat 85 +#define __NR_link 86 +#define __NR_unlink 87 +#define __NR_symlink 88 +#define __NR_readlink 89 +#define __NR_chmod 90 +#define __NR_fchmod 91 +#define __NR_chown 92 +#define __NR_fchown 93 +#define __NR_lchown 94 +#define __NR_umask 95 +#define __NR_gettimeofday 96 +#define __NR_getrlimit 97 +#define __NR_getrusage 98 +#define __NR_sysinfo 99 +#define __NR_times 100 +#define __NR_ptrace 101 +#define __NR_getuid 102 +#define __NR_syslog 103 +#define __NR_getgid 104 +#define __NR_setuid 105 +#define __NR_setgid 106 +#define __NR_geteuid 107 +#define __NR_getegid 108 +#define __NR_setpgid 109 +#define __NR_getppid 110 +#define __NR_getpgrp 111 +#define __NR_setsid 112 +#define __NR_setreuid 113 +#define __NR_setregid 114 +#define __NR_getgroups 115 +#define __NR_setgroups 116 +#define __NR_setresuid 117 +#define __NR_getresuid 118 +#define __NR_setresgid 119 +#define __NR_getresgid 120 +#define __NR_getpgid 121 +#define __NR_setfsuid 122 +#define __NR_setfsgid 123 +#define __NR_getsid 124 +#define __NR_capget 125 +#define __NR_capset 126 +#define __NR_rt_sigpending 127 +#define __NR_rt_sigtimedwait 128 +#define __NR_rt_sigqueueinfo 129 +#define __NR_rt_sigsuspend 130 +#define __NR_sigaltstack 131 +#define __NR_utime 132 +#define __NR_mknod 133 +#define __NR_uselib 134 +#define __NR_personality 135 +#define __NR_ustat 136 +#define __NR_statfs 137 +#define __NR_fstatfs 138 +#define __NR_sysfs 139 +#define __NR_getpriority 140 +#define __NR_setpriority 141 +#define __NR_sched_setparam 142 +#define __NR_sched_getparam 143 +#define __NR_sched_setscheduler 144 +#define __NR_sched_getscheduler 145 +#define __NR_sched_get_priority_max 146 +#define __NR_sched_get_priority_min 147 +#define __NR_sched_rr_get_interval 148 +#define __NR_mlock 149 +#define __NR_munlock 150 +#define __NR_mlockall 151 +#define __NR_munlockall 152 +#define __NR_vhangup 153 +#define __NR_modify_ldt 154 +#define __NR_pivot_root 155 +#define __NR__sysctl 156 +#define __NR_prctl 157 +#define __NR_arch_prctl 158 +#define __NR_adjtimex 159 +#define __NR_setrlimit 160 +#define __NR_chroot 161 +#define __NR_sync 162 +#define __NR_acct 163 +#define __NR_settimeofday 164 +#define __NR_mount 165 +#define __NR_umount2 166 +#define __NR_swapon 167 +#define __NR_swapoff 168 +#define __NR_reboot 169 +#define __NR_sethostname 170 +#define __NR_setdomainname 171 +#define __NR_iopl 172 +#define __NR_ioperm 173 +#define __NR_create_module 174 +#define __NR_init_module 175 +#define __NR_delete_module 176 +#define __NR_get_kernel_syms 177 +#define __NR_query_module 178 +#define __NR_quotactl 179 +#define __NR_nfsservctl 180 +#define __NR_getpmsg 181 +#define __NR_putpmsg 182 +#define __NR_afs_syscall 183 +#define __NR_tuxcall 184 +#define __NR_security 185 +#define __NR_gettid 186 +#define __NR_readahead 187 +#define __NR_setxattr 188 +#define __NR_lsetxattr 189 +#define __NR_fsetxattr 190 +#define __NR_getxattr 191 +#define __NR_lgetxattr 192 +#define __NR_fgetxattr 193 +#define __NR_listxattr 194 +#define __NR_llistxattr 195 +#define __NR_flistxattr 196 +#define __NR_removexattr 197 +#define __NR_lremovexattr 198 +#define __NR_fremovexattr 199 +#define __NR_tkill 200 +#define __NR_time 201 +#define __NR_futex 202 +#define __NR_sched_setaffinity 203 +#define __NR_sched_getaffinity 204 +#define __NR_set_thread_area 205 +#define __NR_io_setup 206 +#define __NR_io_destroy 207 +#define __NR_io_getevents 208 +#define __NR_io_submit 209 +#define __NR_io_cancel 210 +#define __NR_get_thread_area 211 +#define __NR_lookup_dcookie 212 +#define __NR_epoll_create 213 +#define __NR_epoll_ctl_old 214 +#define __NR_epoll_wait_old 215 +#define __NR_remap_file_pages 216 +#define __NR_getdents64 217 +#define __NR_set_tid_address 218 +#define __NR_restart_syscall 219 +#define __NR_semtimedop 220 +#define __NR_fadvise64 221 +#define __NR_timer_create 222 +#define __NR_timer_settime 223 +#define __NR_timer_gettime 224 +#define __NR_timer_getoverrun 225 +#define __NR_timer_delete 226 +#define __NR_clock_settime 227 +#define __NR_clock_gettime 228 +#define __NR_clock_getres 229 +#define __NR_clock_nanosleep 230 +#define __NR_exit_group 231 +#define __NR_epoll_wait 232 +#define __NR_epoll_ctl 233 +#define __NR_tgkill 234 +#define __NR_utimes 235 +#define __NR_vserver 236 +#define __NR_mbind 237 +#define __NR_set_mempolicy 238 +#define __NR_get_mempolicy 239 +#define __NR_mq_open 240 +#define __NR_mq_unlink 241 +#define __NR_mq_timedsend 242 +#define __NR_mq_timedreceive 243 +#define __NR_mq_notify 244 +#define __NR_mq_getsetattr 245 +#define __NR_kexec_load 246 +#define __NR_waitid 247 +#define __NR_add_key 248 +#define __NR_request_key 249 +#define __NR_keyctl 250 +#define __NR_ioprio_set 251 +#define __NR_ioprio_get 252 +#define __NR_inotify_init 253 +#define __NR_inotify_add_watch 254 +#define __NR_inotify_rm_watch 255 +#define __NR_migrate_pages 256 +#define __NR_openat 257 +#define __NR_mkdirat 258 +#define __NR_mknodat 259 +#define __NR_fchownat 260 +#define __NR_futimesat 261 +#define __NR_newfstatat 262 +#define __NR_unlinkat 263 +#define __NR_renameat 264 +#define __NR_linkat 265 +#define __NR_symlinkat 266 +#define __NR_readlinkat 267 +#define __NR_fchmodat 268 +#define __NR_faccessat 269 +#define __NR_pselect6 270 +#define __NR_ppoll 271 +#define __NR_unshare 272 +#define __NR_set_robust_list 273 +#define __NR_get_robust_list 274 +#define __NR_splice 275 +#define __NR_tee 276 +#define __NR_sync_file_range 277 +#define __NR_vmsplice 278 +#define __NR_move_pages 279 +#define __NR_utimensat 280 +#define __NR_epoll_pwait 281 +#define __NR_signalfd 282 +#define __NR_timerfd_create 283 +#define __NR_eventfd 284 +#define __NR_fallocate 285 +#define __NR_timerfd_settime 286 +#define __NR_timerfd_gettime 287 +#define __NR_accept4 288 +#define __NR_signalfd4 289 +#define __NR_eventfd2 290 +#define __NR_epoll_create1 291 +#define __NR_dup3 292 +#define __NR_pipe2 293 +#define __NR_inotify_init1 294 +#define __NR_preadv 295 +#define __NR_pwritev 296 +#define __NR_rt_tgsigqueueinfo 297 +#define __NR_perf_event_open 298 +#define __NR_recvmmsg 299 +#define __NR_fanotify_init 300 +#define __NR_fanotify_mark 301 +#define __NR_prlimit64 302 +#define __NR_name_to_handle_at 303 +#define __NR_open_by_handle_at 304 +#define __NR_clock_adjtime 305 +#define __NR_syncfs 306 +#define __NR_sendmmsg 307 +#define __NR_setns 308 +#define __NR_getcpu 309 +#define __NR_process_vm_readv 310 +#define __NR_process_vm_writev 311 +#define __NR_kcmp 312 +#define __NR_finit_module 313 +#define __NR_sched_setattr 314 +#define __NR_sched_getattr 315 +#define __NR_renameat2 316 +#define __NR_seccomp 317 +#define __NR_getrandom 318 +#define __NR_memfd_create 319 +#define __NR_kexec_file_load 320 +#define __NR_bpf 321 +#define __NR_execveat 322 +#define __NR_userfaultfd 323 +#define __NR_membarrier 324 +#define __NR_mlock2 325 +#define __NR_copy_file_range 326 +#define __NR_preadv2 327 +#define __NR_pwritev2 328 +#define __NR_pkey_mprotect 329 +#define __NR_pkey_alloc 330 +#define __NR_pkey_free 331 +#define __NR_statx 332 +#define __NR_io_pgetevents 333 +#define __NR_rseq 334 +#define __NR_pidfd_send_signal 424 +#define __NR_io_uring_setup 425 +#define __NR_io_uring_enter 426 +#define __NR_io_uring_register 427 +#define __NR_open_tree 428 +#define __NR_move_mount 429 +#define __NR_fsopen 430 +#define __NR_fsconfig 431 +#define __NR_fsmount 432 +#define __NR_fspick 433 +#define __NR_pidfd_open 434 +#define __NR_clone3 435 +#define __NR_close_range 436 +#define __NR_openat2 437 +#define __NR_pidfd_getfd 438 +#define __NR_faccessat2 439 +#define __NR_process_madvise 440 +#define __NR_epoll_pwait2 441 +#define __NR_mount_setattr 442 +#define __NR_landlock_create_ruleset 444 +#define __NR_landlock_add_rule 445 +#define __NR_landlock_restrict_self 446 +#define __NR_memfd_secret 447 +#define __NR_process_mrelease 448 +#define __NR_futex_waitv 449 +#define __NR_set_mempolicy_home_node 450 +#define __NR_cachestat 451 +#define __NR_fchmodat2 452 + +#define SYS_read 0 +#define SYS_write 1 +#define SYS_open 2 +#define SYS_close 3 +#define SYS_stat 4 +#define SYS_fstat 5 +#define SYS_lstat 6 +#define SYS_poll 7 +#define SYS_lseek 8 +#define SYS_mmap 9 +#define SYS_mprotect 10 +#define SYS_munmap 11 +#define SYS_brk 12 +#define SYS_rt_sigaction 13 +#define SYS_rt_sigprocmask 14 +#define SYS_rt_sigreturn 15 +#define SYS_ioctl 16 +#define SYS_pread64 17 +#define SYS_pwrite64 18 +#define SYS_readv 19 +#define SYS_writev 20 +#define SYS_access 21 +#define SYS_pipe 22 +#define SYS_select 23 +#define SYS_sched_yield 24 +#define SYS_mremap 25 +#define SYS_msync 26 +#define SYS_mincore 27 +#define SYS_madvise 28 +#define SYS_shmget 29 +#define SYS_shmat 30 +#define SYS_shmctl 31 +#define SYS_dup 32 +#define SYS_dup2 33 +#define SYS_pause 34 +#define SYS_nanosleep 35 +#define SYS_getitimer 36 +#define SYS_alarm 37 +#define SYS_setitimer 38 +#define SYS_getpid 39 +#define SYS_sendfile 40 +#define SYS_socket 41 +#define SYS_connect 42 +#define SYS_accept 43 +#define SYS_sendto 44 +#define SYS_recvfrom 45 +#define SYS_sendmsg 46 +#define SYS_recvmsg 47 +#define SYS_shutdown 48 +#define SYS_bind 49 +#define SYS_listen 50 +#define SYS_getsockname 51 +#define SYS_getpeername 52 +#define SYS_socketpair 53 +#define SYS_setsockopt 54 +#define SYS_getsockopt 55 +#define SYS_clone 56 +#define SYS_fork 57 +#define SYS_vfork 58 +#define SYS_execve 59 +#define SYS_exit 60 +#define SYS_wait4 61 +#define SYS_kill 62 +#define SYS_uname 63 +#define SYS_semget 64 +#define SYS_semop 65 +#define SYS_semctl 66 +#define SYS_shmdt 67 +#define SYS_msgget 68 +#define SYS_msgsnd 69 +#define SYS_msgrcv 70 +#define SYS_msgctl 71 +#define SYS_fcntl 72 +#define SYS_flock 73 +#define SYS_fsync 74 +#define SYS_fdatasync 75 +#define SYS_truncate 76 +#define SYS_ftruncate 77 +#define SYS_getdents 78 +#define SYS_getcwd 79 +#define SYS_chdir 80 +#define SYS_fchdir 81 +#define SYS_rename 82 +#define SYS_mkdir 83 +#define SYS_rmdir 84 +#define SYS_creat 85 +#define SYS_link 86 +#define SYS_unlink 87 +#define SYS_symlink 88 +#define SYS_readlink 89 +#define SYS_chmod 90 +#define SYS_fchmod 91 +#define SYS_chown 92 +#define SYS_fchown 93 +#define SYS_lchown 94 +#define SYS_umask 95 +#define SYS_gettimeofday 96 +#define SYS_getrlimit 97 +#define SYS_getrusage 98 +#define SYS_sysinfo 99 +#define SYS_times 100 +#define SYS_ptrace 101 +#define SYS_getuid 102 +#define SYS_syslog 103 +#define SYS_getgid 104 +#define SYS_setuid 105 +#define SYS_setgid 106 +#define SYS_geteuid 107 +#define SYS_getegid 108 +#define SYS_setpgid 109 +#define SYS_getppid 110 +#define SYS_getpgrp 111 +#define SYS_setsid 112 +#define SYS_setreuid 113 +#define SYS_setregid 114 +#define SYS_getgroups 115 +#define SYS_setgroups 116 +#define SYS_setresuid 117 +#define SYS_getresuid 118 +#define SYS_setresgid 119 +#define SYS_getresgid 120 +#define SYS_getpgid 121 +#define SYS_setfsuid 122 +#define SYS_setfsgid 123 +#define SYS_getsid 124 +#define SYS_capget 125 +#define SYS_capset 126 +#define SYS_rt_sigpending 127 +#define SYS_rt_sigtimedwait 128 +#define SYS_rt_sigqueueinfo 129 +#define SYS_rt_sigsuspend 130 +#define SYS_sigaltstack 131 +#define SYS_utime 132 +#define SYS_mknod 133 +#define SYS_uselib 134 +#define SYS_personality 135 +#define SYS_ustat 136 +#define SYS_statfs 137 +#define SYS_fstatfs 138 +#define SYS_sysfs 139 +#define SYS_getpriority 140 +#define SYS_setpriority 141 +#define SYS_sched_setparam 142 +#define SYS_sched_getparam 143 +#define SYS_sched_setscheduler 144 +#define SYS_sched_getscheduler 145 +#define SYS_sched_get_priority_max 146 +#define SYS_sched_get_priority_min 147 +#define SYS_sched_rr_get_interval 148 +#define SYS_mlock 149 +#define SYS_munlock 150 +#define SYS_mlockall 151 +#define SYS_munlockall 152 +#define SYS_vhangup 153 +#define SYS_modify_ldt 154 +#define SYS_pivot_root 155 +#define SYS__sysctl 156 +#define SYS_prctl 157 +#define SYS_arch_prctl 158 +#define SYS_adjtimex 159 +#define SYS_setrlimit 160 +#define SYS_chroot 161 +#define SYS_sync 162 +#define SYS_acct 163 +#define SYS_settimeofday 164 +#define SYS_mount 165 +#define SYS_umount2 166 +#define SYS_swapon 167 +#define SYS_swapoff 168 +#define SYS_reboot 169 +#define SYS_sethostname 170 +#define SYS_setdomainname 171 +#define SYS_iopl 172 +#define SYS_ioperm 173 +#define SYS_create_module 174 +#define SYS_init_module 175 +#define SYS_delete_module 176 +#define SYS_get_kernel_syms 177 +#define SYS_query_module 178 +#define SYS_quotactl 179 +#define SYS_nfsservctl 180 +#define SYS_getpmsg 181 +#define SYS_putpmsg 182 +#define SYS_afs_syscall 183 +#define SYS_tuxcall 184 +#define SYS_security 185 +#define SYS_gettid 186 +#define SYS_readahead 187 +#define SYS_setxattr 188 +#define SYS_lsetxattr 189 +#define SYS_fsetxattr 190 +#define SYS_getxattr 191 +#define SYS_lgetxattr 192 +#define SYS_fgetxattr 193 +#define SYS_listxattr 194 +#define SYS_llistxattr 195 +#define SYS_flistxattr 196 +#define SYS_removexattr 197 +#define SYS_lremovexattr 198 +#define SYS_fremovexattr 199 +#define SYS_tkill 200 +#define SYS_time 201 +#define SYS_futex 202 +#define SYS_sched_setaffinity 203 +#define SYS_sched_getaffinity 204 +#define SYS_set_thread_area 205 +#define SYS_io_setup 206 +#define SYS_io_destroy 207 +#define SYS_io_getevents 208 +#define SYS_io_submit 209 +#define SYS_io_cancel 210 +#define SYS_get_thread_area 211 +#define SYS_lookup_dcookie 212 +#define SYS_epoll_create 213 +#define SYS_epoll_ctl_old 214 +#define SYS_epoll_wait_old 215 +#define SYS_remap_file_pages 216 +#define SYS_getdents64 217 +#define SYS_set_tid_address 218 +#define SYS_restart_syscall 219 +#define SYS_semtimedop 220 +#define SYS_fadvise64 221 +#define SYS_timer_create 222 +#define SYS_timer_settime 223 +#define SYS_timer_gettime 224 +#define SYS_timer_getoverrun 225 +#define SYS_timer_delete 226 +#define SYS_clock_settime 227 +#define SYS_clock_gettime 228 +#define SYS_clock_getres 229 +#define SYS_clock_nanosleep 230 +#define SYS_exit_group 231 +#define SYS_epoll_wait 232 +#define SYS_epoll_ctl 233 +#define SYS_tgkill 234 +#define SYS_utimes 235 +#define SYS_vserver 236 +#define SYS_mbind 237 +#define SYS_set_mempolicy 238 +#define SYS_get_mempolicy 239 +#define SYS_mq_open 240 +#define SYS_mq_unlink 241 +#define SYS_mq_timedsend 242 +#define SYS_mq_timedreceive 243 +#define SYS_mq_notify 244 +#define SYS_mq_getsetattr 245 +#define SYS_kexec_load 246 +#define SYS_waitid 247 +#define SYS_add_key 248 +#define SYS_request_key 249 +#define SYS_keyctl 250 +#define SYS_ioprio_set 251 +#define SYS_ioprio_get 252 +#define SYS_inotify_init 253 +#define SYS_inotify_add_watch 254 +#define SYS_inotify_rm_watch 255 +#define SYS_migrate_pages 256 +#define SYS_openat 257 +#define SYS_mkdirat 258 +#define SYS_mknodat 259 +#define SYS_fchownat 260 +#define SYS_futimesat 261 +#define SYS_newfstatat 262 +#define SYS_unlinkat 263 +#define SYS_renameat 264 +#define SYS_linkat 265 +#define SYS_symlinkat 266 +#define SYS_readlinkat 267 +#define SYS_fchmodat 268 +#define SYS_faccessat 269 +#define SYS_pselect6 270 +#define SYS_ppoll 271 +#define SYS_unshare 272 +#define SYS_set_robust_list 273 +#define SYS_get_robust_list 274 +#define SYS_splice 275 +#define SYS_tee 276 +#define SYS_sync_file_range 277 +#define SYS_vmsplice 278 +#define SYS_move_pages 279 +#define SYS_utimensat 280 +#define SYS_epoll_pwait 281 +#define SYS_signalfd 282 +#define SYS_timerfd_create 283 +#define SYS_eventfd 284 +#define SYS_fallocate 285 +#define SYS_timerfd_settime 286 +#define SYS_timerfd_gettime 287 +#define SYS_accept4 288 +#define SYS_signalfd4 289 +#define SYS_eventfd2 290 +#define SYS_epoll_create1 291 +#define SYS_dup3 292 +#define SYS_pipe2 293 +#define SYS_inotify_init1 294 +#define SYS_preadv 295 +#define SYS_pwritev 296 +#define SYS_rt_tgsigqueueinfo 297 +#define SYS_perf_event_open 298 +#define SYS_recvmmsg 299 +#define SYS_fanotify_init 300 +#define SYS_fanotify_mark 301 +#define SYS_prlimit64 302 +#define SYS_name_to_handle_at 303 +#define SYS_open_by_handle_at 304 +#define SYS_clock_adjtime 305 +#define SYS_syncfs 306 +#define SYS_sendmmsg 307 +#define SYS_setns 308 +#define SYS_getcpu 309 +#define SYS_process_vm_readv 310 +#define SYS_process_vm_writev 311 +#define SYS_kcmp 312 +#define SYS_finit_module 313 +#define SYS_sched_setattr 314 +#define SYS_sched_getattr 315 +#define SYS_renameat2 316 +#define SYS_seccomp 317 +#define SYS_getrandom 318 +#define SYS_memfd_create 319 +#define SYS_kexec_file_load 320 +#define SYS_bpf 321 +#define SYS_execveat 322 +#define SYS_userfaultfd 323 +#define SYS_membarrier 324 +#define SYS_mlock2 325 +#define SYS_copy_file_range 326 +#define SYS_preadv2 327 +#define SYS_pwritev2 328 +#define SYS_pkey_mprotect 329 +#define SYS_pkey_alloc 330 +#define SYS_pkey_free 331 +#define SYS_statx 332 +#define SYS_io_pgetevents 333 +#define SYS_rseq 334 +#define SYS_pidfd_send_signal 424 +#define SYS_io_uring_setup 425 +#define SYS_io_uring_enter 426 +#define SYS_io_uring_register 427 +#define SYS_open_tree 428 +#define SYS_move_mount 429 +#define SYS_fsopen 430 +#define SYS_fsconfig 431 +#define SYS_fsmount 432 +#define SYS_fspick 433 +#define SYS_pidfd_open 434 +#define SYS_clone3 435 +#define SYS_close_range 436 +#define SYS_openat2 437 +#define SYS_pidfd_getfd 438 +#define SYS_faccessat2 439 +#define SYS_process_madvise 440 +#define SYS_epoll_pwait2 441 +#define SYS_mount_setattr 442 +#define SYS_landlock_create_ruleset 444 +#define SYS_landlock_add_rule 445 +#define SYS_landlock_restrict_self 446 +#define SYS_memfd_secret 447 +#define SYS_process_mrelease 448 +#define SYS_futex_waitv 449 +#define SYS_set_mempolicy_home_node 450 +#define SYS_cachestat 451 +#define SYS_fchmodat2 452 diff --git a/port/src/image/okm_image.c b/port/src/image/okm_image.c new file mode 100644 index 0000000..ba50ddc --- /dev/null +++ b/port/src/image/okm_image.c @@ -0,0 +1,395 @@ +/* The C library of an ok image (target `-openkal'; openkal SPEC clause 12). + * + * An image is entered by a loader rather than by a kernel: `okrun' maps it, + * binds the `kal_*' names it imports to the one implementation of the process, + * runs its initialisers and calls its entry. Everything this port already does + * above openkal holds unchanged --- the arguments and the named values come from + * `kal_env_*', the thread pointer is the context table of okm_context.c --- and + * what differs is collected here: + * + * ok_main the entry SPEC 12.2 names. The loader has run the + * initialisers (this library's own first, okm_early_init), + * so it brings the library up if no initialiser did, runs + * `main', the handlers `atexit' registered and the flush of + * every stream, and returns the status; the loader then runs + * the finalisers and ends the program with it. + * dl_iterate_phdr the image itself, then every image `dlopen' placed. + * __emutls_get_address + * an image's thread-local variables are emulated (SPEC + * 12.2); each is a key of this library's own. + * dlopen, dlsym, dladdr, dlclose, dlerror + * libokld, the loader the image format defines, filled + * from openkal.exec beneath this library. A placed image's + * imports are bound to the implementation's names, to this + * image's exports (one C library per process) and to the + * images placed before it with RTLD_GLOBAL. + */ +#define _GNU_SOURCE /* Dl_info */ +#include "../okm.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +void __okm_libc_init(void); +char** __okm_argv(void); +int __okm_argc(void); +extern char** __environ; + +/* musl's own exit sequence, less the end: weak, as exit.c holds them. */ +void __funcs_on_exit(void) __attribute__((__weak__)); +void __stdio_exit(void) __attribute__((__weak__)); + +int main(int, char**, char**); + +int ok_main(void) +{ + __okm_libc_init(); + const int status = main(__okm_argc(), __okm_argv(), __environ); + if (__funcs_on_exit) __funcs_on_exit(); + if (__stdio_exit) __stdio_exit(); + return status; +} + +/* --- this image ------------------------------------------------------------ */ + +extern const ElfW(Ehdr) __ehdr_start __attribute__((__weak__)); +extern ElfW(Dyn) _DYNAMIC[] __attribute__((__weak__)); + +static ElfW(Addr) self_base(void) +{ + const ElfW(Ehdr) *eh = &__ehdr_start; + if (!eh) return 0; + const ElfW(Phdr) *ph = (const ElfW(Phdr) *)((const char *)eh + eh->e_phoff); + for (int i = 0; i < eh->e_phnum; i++) + if (ph[i].p_type == PT_LOAD) return (ElfW(Addr))eh - ph[i].p_vaddr; + return (ElfW(Addr))eh; +} + +/* This image's own export of `name', through its SysV hash table (the image is + * linked with both tables, SPEC 12.2). */ +static void *self_symbol(const char *name) +{ + if (!_DYNAMIC) return 0; + const ElfW(Addr) base = self_base(); + const ElfW(Sym) *symtab = 0; + const char *strtab = 0; + const ElfW(Word) *hash = 0; + for (const ElfW(Dyn) *d = _DYNAMIC; d->d_tag != DT_NULL; d++) { + if (d->d_tag == DT_SYMTAB) symtab = (const ElfW(Sym) *)(base + d->d_un.d_ptr); + else if (d->d_tag == DT_STRTAB) strtab = (const char *)(base + d->d_un.d_ptr); + else if (d->d_tag == DT_HASH) hash = (const ElfW(Word) *)(base + d->d_un.d_ptr); + } + if (!symtab || !strtab || !hash) return 0; + unsigned long h = 0; + for (const unsigned char *p = (const unsigned char *)name; *p; p++) { + h = (h << 4) + *p; + const unsigned long g = h & 0xf0000000ul; + if (g) h ^= g >> 24; + h &= ~g; + } + const ElfW(Word) nbucket = hash[0]; + const ElfW(Word) *bucket = hash + 2, *chain = bucket + nbucket; + for (ElfW(Word) i = bucket[h % nbucket]; i; i = chain[i]) { + const ElfW(Sym) *s = symtab + i; + if (s->st_shndx == SHN_UNDEF || ELF64_ST_BIND(s->st_info) == STB_LOCAL) continue; + if (strcmp(strtab + s->st_name, name) == 0) return (void *)(base + s->st_value); + } + return 0; +} + +/* --- placed images --------------------------------------------------------- */ + +struct placed { + struct okld_module *m; + struct placed *next; + int refs; + int global; +}; +static struct placed *g_placed; +static pthread_mutex_t g_dl_lock = PTHREAD_MUTEX_INITIALIZER; +static char g_dl_error[512]; +static int g_dl_error_set; + +static void dl_fail(const char *a, const char *b) +{ + snprintf(g_dl_error, sizeof g_dl_error, "%s%s", a, b ? b : ""); + g_dl_error_set = 1; +} + +char *dlerror(void) +{ + if (!g_dl_error_set) return 0; + g_dl_error_set = 0; + return g_dl_error; +} + +void *__okm_kal_resolve(const char *name); /* okm_kal_table.c */ + +static void *host_reserve(okld_size n, void *ctx) { (void)ctx; return kal_exec_alloc(n); } +static int host_publish(void *r, okld_size off, okld_size n, void *ctx) { (void)ctx; return kal_exec_publish_part(r, off, n); } +static void host_release(void *r, okld_size n, void *ctx) { (void)ctx; kal_exec_free(r, n); } +static okld_size host_granularity(void *ctx) { (void)ctx; return kal_exec_granularity(); } +static void *host_alloc(okld_size n, void *ctx) { (void)ctx; return malloc(n); } +static void host_free(void *p, okld_size n, void *ctx) { (void)ctx; (void)n; free(p); } + +static void *host_resolve(const char *name, void *ctx) +{ + (void)ctx; + void *s = 0; + if (strncmp(name, "kal_", 4) == 0 && (s = __okm_kal_resolve(name))) return s; + if ((s = self_symbol(name))) return s; + for (struct placed *p = g_placed; p; p = p->next) + if (p->global && (s = okld_symbol(p->m, name))) return s; + return 0; +} + +static void *read_whole(const char *path, okld_size *size) +{ + FILE *f = fopen(path, "rb"); + if (!f) return 0; + size_t cap = 1 << 16, n = 0; + unsigned char *buf = malloc(cap); + while (buf) { + const size_t got = fread(buf + n, 1, cap - n, f); + n += got; + if (n < cap) break; + unsigned char *more = realloc(buf, cap * 2); + if (!more) { free(buf); buf = 0; break; } + buf = more; + cap *= 2; + } + fclose(f); + *size = n; + return buf; +} + +/* An image another names (DT_NEEDED) is looked for beside the image that named + * it, then beside this one. */ +static char g_dl_dir[1024]; + +static const void *host_find_needed(const char *name, okld_size *size, void *ctx) +{ + (void)ctx; + char path[1536]; + void *b; + snprintf(path, sizeof path, "%s/%s", g_dl_dir, name); + if ((b = read_whole(path, size))) return b; + const kal_intptr n = kal_env_image(path, sizeof path - 1); + if (n > 0) { + path[n] = 0; + char *slash = strrchr(path, '/'); + if (slash) { + snprintf(slash + 1, sizeof path - (size_t)(slash + 1 - path), "%s", name); + if ((b = read_whole(path, size))) return b; + } + } + return 0; +} + +static void host_release_bytes(const void *b, okld_size n, void *ctx) { (void)n; (void)ctx; free((void *)b); } + +static void call_image(void *fn, void *ctx) { (void)ctx; ((void (*)(void))fn)(); } + +void *dlopen(const char *path, int flags) +{ + if (!path) return RTLD_DEFAULT; + pthread_mutex_lock(&g_dl_lock); + for (struct placed *p = g_placed; p; p = p->next) + if (strcmp(okld_name(p->m), path) == 0) { + p->refs++; + if (flags & RTLD_GLOBAL) p->global = 1; + pthread_mutex_unlock(&g_dl_lock); + return p; + } + okld_size size = 0; + void *bytes = read_whole(path, &size); + if (!bytes) { + dl_fail("cannot read ", path); + pthread_mutex_unlock(&g_dl_lock); + return 0; + } + snprintf(g_dl_dir, sizeof g_dl_dir, "%s", path); + char *slash = strrchr(g_dl_dir, '/'); + if (slash) *slash = 0; else strcpy(g_dl_dir, "."); + /* Static: the loader keeps the pointer for the module's life and calls + * through it again when the module is unloaded. */ + static const struct okld_host host = { + host_reserve, host_publish, host_release, host_granularity, host_resolve, + host_find_needed, host_release_bytes, host_alloc, host_free, 0, 0, + }; + struct okld_module *m = 0; + struct okld_why why; + const int rc = okld_load(bytes, size, path, &host, &m, &why); + free(bytes); + if (rc != 0) { + dl_fail(path, ": "); + strncat(g_dl_error, why.text, sizeof g_dl_error - strlen(g_dl_error) - 1); + pthread_mutex_unlock(&g_dl_lock); + return 0; + } + struct placed *p = malloc(sizeof *p); + p->m = m; + p->refs = 1; + p->global = (flags & RTLD_GLOBAL) != 0; + p->next = g_placed; + g_placed = p; + pthread_mutex_unlock(&g_dl_lock); + okld_initialise(m, call_image, 0); + return p; +} + +void *dlsym(void *restrict handle, const char *restrict name) +{ + void *s = 0; + pthread_mutex_lock(&g_dl_lock); + if (handle == RTLD_DEFAULT) { + s = host_resolve(name, 0); + } else { + for (struct placed *p = g_placed; p; p = p->next) + if (p == handle) { s = okld_symbol(p->m, name); break; } + } + if (!s) dl_fail("symbol not found: ", name); + pthread_mutex_unlock(&g_dl_lock); + return s; +} + +int dlclose(void *handle) +{ + pthread_mutex_lock(&g_dl_lock); + struct placed **at = &g_placed; + while (*at && *at != handle) at = &(*at)->next; + if (!*at) { + dl_fail("dlclose: not an open image", 0); + pthread_mutex_unlock(&g_dl_lock); + return -1; + } + struct placed *p = *at; + if (--p->refs > 0) { pthread_mutex_unlock(&g_dl_lock); return 0; } + *at = p->next; + pthread_mutex_unlock(&g_dl_lock); + okld_finalise(p->m, call_image, 0); + okld_unload(p->m); + free(p); + return 0; +} + +int dladdr(const void *addr, Dl_info *info) +{ + struct okld_module *m = okld_containing(addr); + if (m) { + info->dli_fname = okld_name(m); + info->dli_fbase = okld_base(m); + info->dli_sname = 0; + info->dli_saddr = 0; + return 1; + } + /* This image: the symbol whose range holds the address. */ + if (!_DYNAMIC) return 0; + const ElfW(Addr) base = self_base(); + const ElfW(Sym) *symtab = 0; + const char *strtab = 0; + const ElfW(Word) *hash = 0; + for (const ElfW(Dyn) *d = _DYNAMIC; d->d_tag != DT_NULL; d++) { + if (d->d_tag == DT_SYMTAB) symtab = (const ElfW(Sym) *)(base + d->d_un.d_ptr); + else if (d->d_tag == DT_STRTAB) strtab = (const char *)(base + d->d_un.d_ptr); + else if (d->d_tag == DT_HASH) hash = (const ElfW(Word) *)(base + d->d_un.d_ptr); + } + if (!symtab || !strtab || !hash) return 0; + const ElfW(Addr) a = (ElfW(Addr))addr; + const ElfW(Sym) *best = 0; + for (ElfW(Word) i = 1; i < hash[1]; i++) { + const ElfW(Sym) *s = symtab + i; + if (s->st_shndx == SHN_UNDEF || !s->st_value) continue; + const ElfW(Addr) at = base + s->st_value; + if (at <= a && (!best || at > base + best->st_value) + && (s->st_size == 0 || a < at + s->st_size)) + best = s; + } + static char self_name[1024]; + const kal_intptr n = kal_env_image(self_name, sizeof self_name - 1); + self_name[n > 0 ? n : 0] = 0; + info->dli_fname = self_name; + info->dli_fbase = (void *)base; + info->dli_sname = best ? strtab + best->st_name : 0; + info->dli_saddr = best ? (void *)(base + best->st_value) : 0; + return 1; +} + +/* --- dl_iterate_phdr ------------------------------------------------------- */ + +struct iterate { int (*callback)(struct dl_phdr_info *, size_t, void *); void *data; int result; }; + +static int each_placed(void *base, const void *phdr, okld_u32 phnum, const char *name, void *ctx) +{ + struct iterate *it = ctx; + struct dl_phdr_info info; + memset(&info, 0, sizeof info); + info.dlpi_addr = (ElfW(Addr))base; + info.dlpi_name = name; + info.dlpi_phdr = phdr; + info.dlpi_phnum = (ElfW(Half))phnum; + info.dlpi_adds = 1; + it->result = it->callback(&info, sizeof info, it->data); + return it->result; +} + +int dl_iterate_phdr(int (*callback)(struct dl_phdr_info *info, size_t size, void *data), void *data) +{ + const ElfW(Ehdr) *eh = &__ehdr_start; + if (eh) { + struct dl_phdr_info info; + memset(&info, 0, sizeof info); + info.dlpi_addr = self_base(); + info.dlpi_name = ""; + info.dlpi_phdr = (const ElfW(Phdr) *)((const char *)eh + eh->e_phoff); + info.dlpi_phnum = eh->e_phnum; + info.dlpi_adds = 1; + const int r = callback(&info, sizeof info, data); + if (r) return r; + } + struct iterate it = { callback, data, 0 }; + okld_iterate(each_placed, &it); + return it.result; +} + +/* --- emulated thread-local storage (SPEC 12.2) ----------------------------- */ + +struct __emutls_control { + size_t size; + size_t align; + union { uintptr_t index; void *address; } object; + void *value; +}; + +static pthread_mutex_t g_emutls_lock = PTHREAD_MUTEX_INITIALIZER; + +void *__emutls_get_address(struct __emutls_control *c) +{ + uintptr_t key = __atomic_load_n(&c->object.index, __ATOMIC_ACQUIRE); + if (!key) { + pthread_mutex_lock(&g_emutls_lock); + if (!c->object.index) { + pthread_key_t k; + if (pthread_key_create(&k, free) != 0) abort(); + __atomic_store_n(&c->object.index, (uintptr_t)k + 1, __ATOMIC_RELEASE); + } + key = c->object.index; + pthread_mutex_unlock(&g_emutls_lock); + } + void *p = pthread_getspecific((pthread_key_t)(key - 1)); + if (!p) { + const size_t align = c->align < sizeof(void *) ? sizeof(void *) : c->align; + p = aligned_alloc(align, (c->size + align - 1) / align * align); + if (!p) abort(); + if (c->value) memcpy(p, c->value, c->size); + else memset(p, 0, c->size); + pthread_setspecific((pthread_key_t)(key - 1), p); + } + return p; +} diff --git a/port/src/image/okm_image_init.c b/port/src/image/okm_image_init.c new file mode 100644 index 0000000..6c5ecd3 --- /dev/null +++ b/port/src/image/okm_image_init.c @@ -0,0 +1,25 @@ +/* The C library up before any other initialiser of the image. + * + * The loader runs an image's initialisers before its entry (SPEC 12.3), so a + * program's own constructor can allocate, format and read the environment + * before `ok_main' is reached. The Mach-O form of this file runs from an + * unprioritised constructor because that format orders initialisers by image; + * here they are one array, ordered by the link, and a program's object comes + * before the library's --- measured: the example's constructor called `malloc' + * with the allocator's secret not yet drawn, and faulted. A priority puts this + * one first: the linker sorts `.init_array.' ahead of the rest. + * + * AND AHEAD OF THE C++ RUN-TIME'S, which is why the priority is in the range + * the implementation reserves (0 to 100). libc++ constructs the standard + * streams at priority 100, and their locale needs this library: at 101 the + * streams came first and faulted in `__stdinbuf::imbue' (measured, a C++ + * image over openkal-llvm-runtime). */ +void __okm_libc_init(void); + +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wprio-ctor-dtor" +__attribute__((constructor(1))) static void okm_image_init(void) +{ + __okm_libc_init(); +} +#pragma clang diagnostic pop diff --git a/port/src/image/okm_kal_table.c b/port/src/image/okm_kal_table.c new file mode 100644 index 0000000..e40bd66 --- /dev/null +++ b/port/src/image/okm_kal_table.c @@ -0,0 +1,27 @@ +/* Every name of the specification, weakly, by name: what a placed image's + * `kal_*' imports are bound to (okm_image.c's dlopen). + * + * Weak, so that an image built on this library requires no interface by + * holding the table (SPEC 12.4: a weak import is optional and enters no + * requirement), and a name the implementation does not provide is zero and is + * reported by the loader as missing. The list is openkal's SURFACE.txt, read by + * build.mcpp into `okm_kal_names.inc'; nothing else here includes a header, so + * the declarations below cannot disagree with the specification's. */ +#include + +#define OKM_KAL(n) extern void n(void) __attribute__((__weak__)); +#include "okm_kal_names.inc" +#undef OKM_KAL + +static const struct { const char *name; void (*fn)(void); } table[] = { +#define OKM_KAL(n) { #n, n }, +#include "okm_kal_names.inc" +#undef OKM_KAL +}; + +void *__okm_kal_resolve(const char *name) +{ + for (unsigned i = 0; i < sizeof table / sizeof table[0]; i++) + if (strcmp(table[i].name, name) == 0) return (void *)table[i].fn; + return 0; +} diff --git a/port/src/okm_syscall.c b/port/src/okm_syscall.c index 8dec097..4808715 100644 --- a/port/src/okm_syscall.c +++ b/port/src/okm_syscall.c @@ -69,6 +69,24 @@ extern __typeof(kal_terminal_size) kal_terminal_size __attribute__((__we * Weak by the same rule as everything else in that interface: a backend may * bound some of its resources and not others, or decline the interface. */ extern __typeof(kal_timeout_wait_process) kal_timeout_wait_process __attribute__((__weak__)); +/* The processor time of this program (openkal 0.17, kal_program_info), for + * CLOCK_PROCESS_CPUTIME_ID; weak by the same rule. */ +extern __typeof(kal_process_self) kal_process_self __attribute__((__weak__)); +extern __typeof(kal_process_info) kal_process_info __attribute__((__weak__)); +extern __typeof(kal_process_close) kal_process_close __attribute__((__weak__)); + +/* This program's processor time in nanoseconds, or -1 where the interface + * cannot say. */ +static long long okm_self_cpu_ns(void) { + if (!kal_process_self || !kal_process_info || !kal_process_close) return -1; + struct kal_process me; + if (kal_process_self(&me) != kal_ok) return -1; + struct kal_program_info info = { .self_size = sizeof info }; + const int rc = kal_process_info(me, KAL_PINFO_CPU, &info); + kal_process_close(me); + if (rc != kal_ok || !(info.present & KAL_PINFO_CPU)) return -1; + return (long long)info.cpu_ns; +} #include #include @@ -2092,11 +2110,30 @@ syscall_arg_t __okm_syscall(syscall_arg_t n, syscall_arg_t a1, syscall_arg_t a2, #endif /* --- time -------------------------------------------------------------- */ + /* A PROCESSOR CLOCK IS THE PROCESSOR TIME, NOT THE MONOTONIC CLOCK. Every + * clock but the wall clock was answered with the monotonic one, so `clock()' + * and CLOCK_PROCESS_CPUTIME_ID counted time asleep as work --- measured above + * this port, a program idle for a second reported a second of processor + * time. The program's is kal_program_info's; a context's own is not in the + * interface, and is refused rather than invented. */ case SYS_clock_gettime: { struct timespec* ts = (struct timespec*)a2; - if ((int)a1 == CLOCK_REALTIME) to_timespec(kal_time_wall(), ts); - else to_timespec(kal_time_monotonic(), ts); - return 0; + switch ((int)a1) { + case CLOCK_REALTIME: + to_timespec(kal_time_wall(), ts); + return 0; + case CLOCK_PROCESS_CPUTIME_ID: { + const long long ns = okm_self_cpu_ns(); + if (ns < 0) return -EINVAL; + to_timespec((kal_duration)ns, ts); + return 0; + } + case CLOCK_THREAD_CPUTIME_ID: + return -EINVAL; + default: + to_timespec(kal_time_monotonic(), ts); + return 0; + } } case SYS_clock_getres: if (a2) to_timespec(kal_time_monotonic_granularity(), (struct timespec*)a2); diff --git a/tools/working-trees.sh b/tools/working-trees.sh index 34dc82d..13b4516 100755 --- a/tools/working-trees.sh +++ b/tools/working-trees.sh @@ -30,6 +30,10 @@ beside="$(cd "$here/.." && pwd)" # at a working tree --- reported as one package requested as a path and as a # version at once, which names neither the host nor the target. case "${target:-$(uname -s)}" in + # An ok image holds no implementation: the loader that runs it does. What + # the image form adds is libokld (openkal-image) and the compiler-rt + # builtins built from source, both taken from the same-named branch. + *openkal*) implementation=none ;; *windows*|MINGW*|MSYS*|CYGWIN*) implementation=openkal-windows ;; *macos*|*darwin*|Darwin) implementation=openkal-macos ;; *linux*|Linux) implementation=openkal-linux ;; @@ -54,7 +58,12 @@ fetch() { } fetch openkal -fetch "$implementation" +if [ "$implementation" = none ]; then + fetch openkal-image + fetch compiler-rt-builtins +else + fetch "$implementation" +fi # AND WHAT WAS FETCHED HAS TO BE WHAT THE MANIFEST ASKED FOR. # @@ -78,6 +87,9 @@ fetch "$implementation" # the same mismatch would have passed while testing the wrong specification. satisfies() { # satisfies --- caret, for 0.x and above local rq="$1" ac="$2" + # The same version satisfies itself, in any number of segments (the + # compiler-rt builtins carry four: LLVM's three and a packaging revision). + [ "$rq" = "$ac" ] && return 0 local rmaj="${rq%%.*}" amaj="${ac%%.*}" [ "$rmaj" = "$amaj" ] || return 1 local rrest="${rq#*.}" arest="${ac#*.}" @@ -120,7 +132,12 @@ in_step() { # in_step } in_step openkal "$beside/openkal" -in_step "$implementation" "$beside/$implementation" +if [ "$implementation" = none ]; then + in_step openkal-ld "$beside/openkal-image/ld" + in_step llvm.compiler-rt-builtins "$beside/compiler-rt-builtins" +else + in_step "$implementation" "$beside/$implementation" +fi # On one of the three systems the shell and the build tool disagree about what # a path is. The translation exists there and is a no-op everywhere else. @@ -152,6 +169,18 @@ point() { echo "pointed $1 at the specification's working tree" } point "$here/mcpp.toml" +if [ "$implementation" = none ]; then + point "$beside/openkal-image/ld/mcpp.toml" + for pair in "openkal-ld:$beside/openkal-image/ld" "llvm.compiler-rt-builtins:$beside/compiler-rt-builtins"; do + pkg="${pair%%:*}"; tree="$(native "${pair#*:}")" + sed "s|^$pkg = .*$|$pkg = { path = \"$tree\" }|" "$here/mcpp.toml" > "$here/mcpp.toml.next" + mv "$here/mcpp.toml.next" "$here/mcpp.toml" + echo "pointed this package at $pkg's working tree" + done + sed -n '/^\[target/,/^$/p' "$here/mcpp.toml" + echo none + exit 0 +fi point "$beside/$implementation/mcpp.toml" # And this package's own reference to the implementation. It names a version,