Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion mcpp.toml
Original file line number Diff line number Diff line change
@@ -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"

Expand Down
34 changes: 26 additions & 8 deletions src/rights.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,21 @@ 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;

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
Expand All @@ -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;
Expand All @@ -125,19 +132,30 @@ 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<unsigned short>(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<unsigned short>(i + 1);
return &g_entries[i];
}
return nullptr;
}

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;
}

Expand Down
Loading