Skip to content

Commit 9ceb058

Browse files
0.24.0 --- openkal 0.23: a region at an address, MAP_FIXED_NOREPLACE
Co-authored-by: speak-agent <248744407+speak-agent@users.noreply.github.com>
1 parent e146e78 commit 9ceb058

3 files changed

Lines changed: 32 additions & 5 deletions

File tree

‎README.md‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ for Linux, written on the kernel's own system-call interface.
55

66
```toml
77
[dependencies]
8-
openkal = "0.22.0"
8+
openkal = "0.23.0"
99

1010
[target.'cfg(os = "linux")'.dependencies]
11-
openkal-linux = "0.23.0"
11+
openkal-linux = "0.24.0"
1212
```
1313

1414
## Why it does not use a C library
@@ -102,6 +102,13 @@ A program that carries a runtime of its own answers from that runtime instead
102102
(`pthread_getattr_np`), because in that arrangement the runtime is what owns the
103103
stacks and is what a program above openkal would ask for itself.
104104

105+
## What 0.24 adds (openkal 0.23)
106+
107+
**A region at an address.** `kal_exec_alloc_at` maps the region with
108+
`MAP_FIXED_NOREPLACE`, which refuses rather than replaces what is there; a kernel
109+
before 4.17 reads the flag as a hint, so a mapping placed elsewhere is released
110+
and the request refused. `KAL_EXEC_PROP_PLACE` is claimed.
111+
105112
## What 0.23 adds (openkal 0.22)
106113

107114
**The null device at a position.** `KAL_SPAWN_NULL_IN`, `KAL_SPAWN_NULL_OUT` and

‎mcpp.toml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
namespace = "mcpplibs"
33
name = "openkal-linux"
4-
version = "0.23.0"
4+
version = "0.24.0"
55
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."
66
license = "Apache-2.0"
77

@@ -65,7 +65,7 @@ provides-interfaces = [
6565
]
6666

6767
[dependencies]
68-
openkal = "0.22.0"
68+
openkal = "0.23.0"
6969

7070
# The package contributes definitions and no modules. The interface it
7171
# implements is declared by the specification package, which this package

‎src/exec.cpp‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,26 @@ void* kal_exec_alloc(kal_uintptr size) {
5151
return reinterpret_cast<void*>(r);
5252
}
5353

54+
// AT AN ADDRESS (0.23): MAP_FIXED_NOREPLACE, which refuses rather than replaces
55+
// what is there. A kernel before 4.17 does not know the flag and reads the
56+
// address as a hint, so the answer is compared and a mapping placed elsewhere
57+
// released: the address is either given or refused, never approximated.
58+
void* kal_exec_alloc_at(void* at, kal_uintptr size) {
59+
const okl_uptr where = reinterpret_cast<okl_uptr>(at);
60+
if (size == 0 || where == 0 || (where & (page() - 1)) != 0) return nullptr;
61+
const okl_uptr bytes = round_up(static_cast<okl_uptr>(size), page());
62+
const okl_long r = okl::sys(okl::nr_mmap, static_cast<okl_long>(where), static_cast<okl_long>(bytes),
63+
okl::prot_read | okl::prot_write,
64+
okl::map_private | okl::map_anonymous | 0x100000 /* MAP_FIXED_NOREPLACE */,
65+
-1, 0);
66+
if (okl::failed(r)) return nullptr;
67+
if (static_cast<okl_uptr>(r) != where) {
68+
okl::sys(okl::nr_munmap, r, static_cast<okl_long>(bytes));
69+
return nullptr;
70+
}
71+
return at;
72+
}
73+
5474
int kal_exec_publish(void* p, kal_uintptr size) {
5575
if (p == nullptr || size == 0) return kal_err_invalid;
5676
const okl_uptr bytes = round_up(static_cast<okl_uptr>(size), page());
@@ -163,7 +183,7 @@ void kal_exec_free(void* p, kal_uintptr size) {
163183
kal_uintptr kal_exec_props(void) {
164184
// Executable memory is available to every artifact on this kernel: nothing
165185
// here is granted only to a program produced in a particular way.
166-
return KAL_EXEC_PROP_REPUBLISH | KAL_EXEC_PROP_AVAILABLE | KAL_EXEC_PROP_FILE;
186+
return KAL_EXEC_PROP_REPUBLISH | KAL_EXEC_PROP_AVAILABLE | KAL_EXEC_PROP_FILE | KAL_EXEC_PROP_PLACE;
167187
}
168188

169189
} // extern "C"

0 commit comments

Comments
 (0)