diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d5df34e..55f4ee3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -79,6 +79,8 @@ jobs: echo "$req" grep -q 'openkal.stream' <<<"$req" && ! grep -q 'openkal.net' <<<"$req" \ || { echo "::error::a weak import made the image require its interface"; exit 1; } + # 6 MiB of frames on the main thread, the runner's on Windows (0.5.2). + bash examples/build-image.sh "$arch" "out/$arch/stack.oke" examples/stack/app.c cp "out/$arch/hello.oke" "out/$arch/signed.oke" # The library examples/bind binds for a program of each system. bash examples/build-image.sh "$arch" "out/$arch/libmathlib.okso" examples/bind/mathlib/image/mathlib.c @@ -275,6 +277,10 @@ jobs: n=$("$OKRUN" "out/$a/needed.oke" | tr -d '\r') echo "$n" grep -q "twice(21) = 42, next_value() = 41" <<<"$n" || { echo "::error::an image another needs"; exit 1; } + # THE MAIN THREAD HAS A THREAD'S STACK (0.5.2): on Windows the runner's + # reservation, which was the linker's 1 MiB default. + st=$("$OKRUN" "out/$a/stack.oke" | tr -d '\r') + test "$st" = 'stack: 6 MiB on the main thread' || { echo "::error::the image's main thread has less than a thread's stack: $st"; exit 1; } w=$("$OKRUN" "out/$a/weak.oke" | tr -d '\r') echo "$w" grep -q "weak: openkal.net bound" <<<"$w" || { echo "::error::a weak import the implementation provides was not bound"; exit 1; } diff --git a/README.md b/README.md index 9f93873..14323a1 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,13 @@ rules hold sixteen long grants, and states the kernel layer as compatible ranges (openkal `^0.24.0`, Linux `^0.25.0`, macOS `^0.22.1`, Windows `^0.20.0`). The format, the loader and the import names are unchanged. +Version 0.5.2 gives an image's main thread a thread's stack on Windows. An image +is entered on okrun's main thread, whose stack there is the executable's +reservation, the linker's 1 MiB; okrun.exe now reserves 8 MiB + 256 KiB, a +thread's default under openkal-windows, as Linux and macOS give the main thread +8 MiB. The `stack` example recurses through 6 MiB on the main thread on every +system. + ## An image ```sh diff --git a/bind/mcpp.toml b/bind/mcpp.toml index 31f5b90..eb05ff0 100644 --- a/bind/mcpp.toml +++ b/bind/mcpp.toml @@ -1,7 +1,7 @@ [package] namespace = "mcpplibs" name = "openkal-bind" -version = "0.5.1" +version = "0.5.2" # `mcpp::xpkg_request', `mcpp::decision' (protocol 15). mcpp = ">=2026.10.1.3" description = "A build plugin: a library published as an ok image (.okso) and a C header is called from a program of any system, through a binding generated from the header and libokrun." diff --git a/docs/bind.md b/docs/bind.md index b6d065d..7152d4c 100644 --- a/docs/bind.md +++ b/docs/bind.md @@ -110,6 +110,7 @@ llvm toolchain's clang converts the call. | 0.3.2 | No change of its own; released with the archive, whose runner is built over openkal 0.22's implementations: a started program is given the system's null device at a position (`KAL_SPAWN_NULL_*`). | | 0.5.0 | The binding format is unchanged; the runner selects OpenKal 0.24 and binds its four process-unit operations. | | 0.5.1 | No change of its own; released with the archive, whose runner is built over openkal-macos 0.22.1 (confinement rules sized to their grants). | +| 0.5.2 | No change of its own; released with the archive, whose runner on Windows reserves a thread's stack for the image's main thread. | | 0.4.0 | No change of its own; released with the archive, whose loader places an image at the base `okld place` chose for it (openkal 0.23, `kal_exec_alloc_at`) and then applies only the relocations that name a symbol. | | 0.4.1 | No change of its own; released with the archive, whose runner on macOS is built over openkal-macos 0.21.2 (a sleep is no longer a spin of the processor; the granularity is the same at every start). | | 0.4.2 | No change of its own; released with the archive, whose runner on macOS is built over openkal-macos 0.21.3 (asked before the implementation's initialiser ran, it answers from the loader's record). | diff --git a/examples/stack/app.c b/examples/stack/app.c new file mode 100644 index 0000000..a353059 --- /dev/null +++ b/examples/stack/app.c @@ -0,0 +1,30 @@ +/* The image's main thread has the stack a thread has (openkal-image 0.5.2): an + * image is entered on the runner's main thread, and on Windows that thread's + * stack is the runner's reservation. This one recurses through 6 MiB of + * frames, each touched page by page (-fstack-clash-protection), where a thread + * of openkal-windows has at least 8 MiB and Linux and macOS give the main + * thread 8 MiB. The entry is `int ok_main(void)' (SPEC 12.2). */ +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); + +static void put(const char* s) { + unsigned long n = 0; while (s[n]) ++n; + kal_stream_write(kal_stdout(), s, n); +} + +__attribute__((noinline)) static unsigned descend(unsigned depth) { + volatile unsigned char frame[64 * 1024]; + for (unsigned i = 0; i < sizeof frame; i += 4096) frame[i] = (unsigned char)depth; + unsigned below = depth ? descend(depth - 1) : 0; + return below + frame[depth % sizeof frame]; +} + +__attribute__((visibility("default"))) int ok_main(void) { + descend(96); /* 96 frames of 64 KiB: 6 MiB */ + put("stack: 6 MiB on the main thread\n"); + return 0; +} diff --git a/ld/mcpp.toml b/ld/mcpp.toml index 8ceb501..e2e9faa 100644 --- a/ld/mcpp.toml +++ b/ld/mcpp.toml @@ -1,7 +1,7 @@ [package] namespace = "mcpplibs" name = "openkal-ld" -version = "0.5.1" +version = "0.5.2" description = "libokld: the ok format (openkal image format) --- its definition, a reader of bytes, a checker, a signer, and a loader. Freestanding: no C library, no exceptions." license = "Apache-2.0" authors = ["mcpplibs"] diff --git a/run/mcpp.toml b/run/mcpp.toml index 0f341e4..2183bd7 100644 --- a/run/mcpp.toml +++ b/run/mcpp.toml @@ -1,7 +1,7 @@ [package] namespace = "mcpplibs" name = "openkal-run" -version = "0.5.1" +version = "0.5.2" description = "libokrun: the runner's core --- an ok image's names bound to this process's one openkal implementation, in the image's calling convention, and its entry entered." license = "Apache-2.0" authors = ["mcpplibs"] diff --git a/tools/mcpp.toml b/tools/mcpp.toml index 8980d36..80c09ac 100644 --- a/tools/mcpp.toml +++ b/tools/mcpp.toml @@ -1,7 +1,7 @@ [package] namespace = "mcpplibs" name = "openkal-tools" -version = "0.5.1" +version = "0.5.2" description = "okrun, which runs an ok image on this system, and okld, the format's tool on a build machine (check, note, sign, inspect)." license = "Apache-2.0" authors = ["mcpplibs"] @@ -31,3 +31,18 @@ main = "src/okprof.cpp" [build] sources = [] + +# THE IMAGE'S MAIN THREAD IS THE RUNNER'S (0.5.2): an image is entered on okrun's +# main thread, whose stack on Windows is the executable's reservation, 1 MiB by +# the linker's default. openkal-windows gives every other thread at least 8 MiB +# (kal_task_start), and Linux and macOS give the main thread 8 MiB; an image's +# deep recursion on its main thread -- clangd.okb indexing the MSVC headers with +# `--sync` -- ended in STATUS_STACK_OVERFLOW. The reservation is a thread's +# default and openkal-windows' guard slack, 8 MiB + 256 KiB, spelled for each +# linker: lld-link on the MSVC ABI (a Windows host), the MinGW driver on the GNU +# ABI (the hosted arrangement, and a cross build). +[target.'cfg(all(windows, env = "msvc"))'.build] +ldflags = ["-Wl,/STACK:8650752"] + +[target.'cfg(all(windows, env = "gnu"))'.build] +ldflags = ["-Wl,--stack,8650752"]