From e7ae7950e972c654c002356459b3c3dbf5158ea0 Mon Sep 17 00:00:00 2001 From: Sunrisepeak Date: Fri, 27 Nov 2026 02:26:52 +0900 Subject: [PATCH] =?UTF-8?q?0.27.3:=20the=20tables=20of=20attenuated=20dire?= =?UTF-8?q?ctories=20in=20.bss=20=E2=80=94=20141,824=20bytes=20fewer=20in?= =?UTF-8?q?=20every=20program=20that=20links=20them?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The table of handles (4,096 entries of 32 bytes) and the table of roots (64 of 168 bytes) began with members initialised to -1, so both were placed in .data: every program that links the attenuation carried 141,824 bytes in its file and loaded them, whether it attenuated a directory or not. A free entry and a free root are now all zero bytes (an entry in use by its `used` flag, a root by `live` as before), and each is given its values where it is made (new_entry, new_root): both tables lie in .bss. The conformance tests pass unchanged (24 programs); in openkal_0_23's program both symbols move from `d` to `b`. --- README.md | 15 ++++++++++++++- mcpp.toml | 2 +- src/rights.cpp | 34 ++++++++++++++++++++++++++-------- 3 files changed, 41 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 2a8a5dd..5b27dea 100644 --- a/README.md +++ b/README.md @@ -8,9 +8,22 @@ for Linux, written on the kernel's own system-call interface. openkal = "0.26.0" [target.'cfg(os = "linux")'.dependencies] -openkal-linux = "0.27.2" +openkal-linux = "0.27.3" ``` +## What 0.27.3 fixes + +**The tables of attenuated directories take no bytes of a program.** The table of +handles (4,096 entries of 32 bytes) and the table of roots (64 of 168 bytes) began +with members initialised to -1 (no descriptor, no root, no record), so the compiler +placed both, 141,824 bytes, in `.data`: every program that links the attenuation +carried them in its file and loaded them, whether it attenuated a directory or +not. A free entry and a free root are now all zero bytes, an entry known to be in +use by its `used` flag and a root by `live` as before, and each is given its values +where it is made (`new_entry`, `new_root`): both tables lie in `.bss`. Measured +with omui's smallest terminal application, which links them through mcpplibs.os: +141,824 bytes fewer loaded (from `.data` to `.bss`), its behaviour the same. + ## What 0.27.2 fixes **The riscv64 record of a signal's action is 32 bytes.** The kernel's record is diff --git a/mcpp.toml b/mcpp.toml index bf94f03..1abc43d 100644 --- a/mcpp.toml +++ b/mcpp.toml @@ -1,7 +1,7 @@ [package] namespace = "mcpplibs" name = "openkal-linux" -version = "0.27.2" +version = "0.27.3" description = "The reference implementation of openkal for Linux, written on the kernel's own system-call interface so that it can be placed beneath a C library as well as above one." license = "Apache-2.0" diff --git a/src/rights.cpp b/src/rights.cpp index 0c9a0a3..0f68536 100644 --- a/src/rights.cpp +++ b/src/rights.cpp @@ -81,6 +81,11 @@ struct keyset { // A ROOT is one attenuation: the directory it was made of, its rights, its // record and what it has listed. Every handle derived from it names the root // and the path beneath it. +// +// BOTH TABLES ARE ZERO UNTIL USED. A free root and a free entry are all zero +// bytes, and each is given its values where it is made (new_root, new_entry): +// so the tables lie in .bss, and a program that never attenuates a directory +// carries none of their 138 KiB in its file or its data. constexpr int kRoots = 64; constexpr okl_uptr kBatch = 64 * 1024; @@ -88,9 +93,9 @@ struct root { bool live = false; int refs = 0; okl_u32 flags = 0; - int base = -1; // a descriptor of the root, to list beneath + int base = 0; // a descriptor of the root, to list beneath (-1 for none: new_root) // The record. - int record = -1; // opened to append + int record = 0; // opened to append (-1 for none: new_root) char* rprefix = nullptr; // where this root lies beneath the directory the record is of okl_uptr rplen = 0; keyset seen; // kind and name, once each @@ -105,10 +110,12 @@ struct root { }; root g_roots[kRoots]; -// A HANDLE: its root and the path of its directory beneath the root. +// A HANDLE: its root and the path of its directory beneath the root. Free +// while `used` is not set. struct entry { - int fd = -1; - int root = -1; + bool used = false; + int fd = 0; + int root = 0; // -1 for none: new_entry okl_u32 flags = 0; char* prefix = nullptr; okl_uptr plen = 0; @@ -125,7 +132,11 @@ entry* entry_of(int fd) { entry* new_entry(int fd) { if (fd < 0 || fd >= okl::kMaxDescriptor) return nullptr; for (int i = 0; i < kEntries; ++i) - if (g_entries[i].fd < 0) { g_entries[i].fd = fd; g_slot[fd] = static_cast(i + 1); return &g_entries[i]; } + if (!g_entries[i].used) { + g_entries[i] = entry{.used = true, .fd = fd, .root = -1}; + g_slot[fd] = static_cast(i + 1); + return &g_entries[i]; + } return nullptr; } @@ -133,11 +144,18 @@ void drop_entry(entry* e) { if (!e) return; if (e->fd >= 0 && e->fd < okl::kMaxDescriptor) g_slot[e->fd] = 0; give_back(e->prefix, e->plen + 1); - *e = entry{}; + *e = entry{}; // free: zero again } int new_root() { - for (int i = 0; i < kRoots; ++i) if (!g_roots[i].live) { g_roots[i] = root{}; g_roots[i].live = true; return i; } + for (int i = 0; i < kRoots; ++i) + if (!g_roots[i].live) { + g_roots[i] = root{}; + g_roots[i].live = true; + g_roots[i].base = -1; + g_roots[i].record = -1; + return i; + } return -1; }