Generalize capability passing from endpoints to memory objects. The per-task
handle table now holds kind-tagged entries (scheduler.HandleObject{kind, ptr});
closeHandles and shareCapability dispatch by kind, so a shared-memory object
rides an ipc_call send_cap exactly like an endpoint and is refcount-freed only
when its last capability drops.
- shm_create(len) -> vaddr, handle: contiguous, zeroed, cacheable frames wrapped
in a refcounted ShmObject, mapped into the caller's shm arena (PML4[230]).
- shm_map(cap) -> vaddr: map the same physical pages into a receiver that got the
capability. mapUserSharedInto maps WB-cacheable + device_grant, so a sharer's
teardown never frees the shared frames — the object owns them.
- runtime.shm: create(len) -> Region{ptr, handle, len}, map(handle) -> ptr.
Gate: qemu_test.py shm — shm-client creates a region, writes a pattern, passes
its capability to shm-server, which maps it and reads the same bytes back
(shm: shared 4096 bytes ok). ipc/ipc-call/ipc-cap/supervision/dma/usermem/
display-service and host tests all still pass — the handle change broke no IPC.
50 lines
1.6 KiB
Zig
50 lines
1.6 KiB
Zig
//! system/services/shm-server — the receiving half of the shm test (docs/display-v2.md V2).
|
|
//! It registers under `ServiceId.shm_test`; when `shm-client` calls it carrying a
|
|
//! shared-memory capability, it `shm_map`s that capability and checks the client's pattern
|
|
//! is visible through the mapping — proving the two processes share the same physical pages
|
|
//! (not a copy). On success it prints `shm: shared 4096 bytes ok`, the test's marker.
|
|
|
|
const runtime = @import("runtime");
|
|
const system = runtime.system;
|
|
const shm = runtime.shm;
|
|
const ipc = runtime.ipc;
|
|
|
|
const pattern_len = 4096;
|
|
|
|
/// The pattern the client writes — must match shm-client.zig.
|
|
fn expected(i: usize) u8 {
|
|
return @truncate(i *% 7 +% 3);
|
|
}
|
|
|
|
fn onMessage(message: []const u8, reply: []u8, sender: u32, capability: ?ipc.Handle) usize {
|
|
_ = message;
|
|
_ = reply;
|
|
_ = sender;
|
|
const cap = capability orelse {
|
|
_ = system.write("shm: shared FAILED (no capability)\n");
|
|
return 0;
|
|
};
|
|
const ptr = shm.map(cap) orelse {
|
|
_ = system.write("shm: shared FAILED (map)\n");
|
|
return 0;
|
|
};
|
|
var i: usize = 0;
|
|
while (i < pattern_len) : (i += 1) {
|
|
if (ptr[i] != expected(i)) {
|
|
_ = system.write("shm: shared FAILED (mismatch)\n");
|
|
return 0;
|
|
}
|
|
}
|
|
_ = system.write("shm: shared 4096 bytes ok\n");
|
|
return 0; // empty reply — the client only needs the round trip to unblock
|
|
}
|
|
|
|
pub fn main() void {
|
|
runtime.service.run(64, .{ .service = .shm_test, .on_message = onMessage });
|
|
}
|
|
|
|
pub const panic = runtime.panic;
|
|
comptime {
|
|
_ = &runtime.start._start;
|
|
}
|