Skip to content

Commit 032ee8a

Browse files
0.21.0 --- openkal 0.23: a region at an address, the hint compared
Co-authored-by: speak-agent <248744407+speak-agent@users.noreply.github.com>
1 parent b3643d9 commit 032ee8a

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 @@ written on the kernel's own calls.
55

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

1010
[target.'cfg(os = "macos")'.dependencies]
11-
openkal-macos = "0.20.0"
11+
openkal-macos = "0.21.0"
1212
```
1313

1414
Its purpose is as much to test the specification as to be used. A specification
@@ -167,6 +167,13 @@ same image parses as fast on Linux arm64. Since 0.17.1 it is the same kernel ide
167167
this system's library keeps for each thread (`pthread_threadid_np`, a name no C
168168
library in this ecosystem defines).
169169

170+
## What 0.21 adds (openkal 0.23)
171+
172+
**A region at an address.** `kal_exec_alloc_at` passes the address as a hint,
173+
which this kernel honours where nothing is there, and releases a mapping placed
174+
elsewhere: `MAP_FIXED` would replace what is there. `KAL_EXEC_PROP_PLACE` is
175+
claimed where executable memory is available.
176+
170177
## What 0.20 adds (openkal 0.22)
171178

172179
**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-macos"
4-
version = "0.20.0"
4+
version = "0.21.0"
55
description = "An implementation of openkal for macOS, written on the kernel's own calls. Its purpose is as much to test the specification as to be used."
66
license = "Apache-2.0"
77

@@ -59,7 +59,7 @@ provides-interfaces = [
5959
]
6060

6161
[dependencies]
62-
openkal = "0.22.0"
62+
openkal = "0.23.0"
6363

6464
[build]
6565
# The flags are attached to this package's own sources rather than to the whole

‎src/exec.cpp‎

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

164+
// AT AN ADDRESS (0.23): the address as a hint, which this kernel honours where
165+
// nothing is there, and the answer compared. A mapping placed elsewhere is
166+
// released: MAP_FIXED would replace what is there, which is the one thing a
167+
// reservation at an address must not do.
168+
void* kal_exec_alloc_at(void* at, kal_uintptr size) {
169+
const okm_uptr where = reinterpret_cast<okm_uptr>(at);
170+
if (size == 0 || where == 0 || (where & (granularity() - 1)) != 0) return nullptr;
171+
if (!available()) return nullptr;
172+
const okm_uptr bytes = round_up(static_cast<okm_uptr>(size), granularity());
173+
const okm_long r = okm::sys(okm::nr_mmap, static_cast<okm_long>(where), static_cast<okm_long>(bytes),
174+
okm::prot_read | okm::prot_write,
175+
okm::map_private | okm::map_anon, -1, 0);
176+
if (okm::failed(r)) return nullptr;
177+
if (static_cast<okm_uptr>(r) != where) {
178+
okm::sys(okm::nr_munmap, r, static_cast<okm_long>(bytes));
179+
return nullptr;
180+
}
181+
return at;
182+
}
183+
164184
int kal_exec_publish(void* p, kal_uintptr size) {
165185
if (p == nullptr || size == 0) return kal_err_invalid;
166186
const okm_uptr bytes = round_up(static_cast<okm_uptr>(size), granularity());
@@ -234,7 +254,7 @@ void kal_exec_free(void* p, kal_uintptr size) {
234254
// bytes reserves a second region and abandons the first, which is what the
235255
// header says a zero in that position means.
236256
kal_uintptr kal_exec_props(void) {
237-
return available() ? KAL_EXEC_PROP_AVAILABLE | KAL_EXEC_PROP_FILE : 0;
257+
return available() ? KAL_EXEC_PROP_AVAILABLE | KAL_EXEC_PROP_FILE | KAL_EXEC_PROP_PLACE : 0;
238258
}
239259

240260
} // extern "C"

0 commit comments

Comments
 (0)