diff options
Diffstat (limited to 'core/Addon.zig')
| -rw-r--r-- | core/Addon.zig | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/core/Addon.zig b/core/Addon.zig index 5c3f84e2..5c23ed51 100644 --- a/core/Addon.zig +++ b/core/Addon.zig @@ -342,11 +342,11 @@ fn listed(data: []const u8, path: []const u8, n: usize, why: *Why) Loaded { /// Kind `k`'s code, a session's (a replica's is `plainOps`'s or none): its /// library loaded at the first pane of its kind, from the file the start /// listed it from (`listed`); null, and why, when it will not load. -pub fn need(r: *Kind.Registry, k: u8, why: *Why) ?*const Kind.Ops { +pub fn need(r: *Kind.Registry, k: u8, why: *Why, distrusted: ?*const Distrusted) ?*const Kind.Ops { if (r.ops[k] != null) return r.ops[k]; // A client's: its own code for a plain kind, loaded at its first pane. if (tape.replaying()) { - r.ops[k] = plainOps(&r.kinds[k]); + r.ops[k] = plainOps(&r.kinds[k], distrusted); return r.ops[k]; } const e = &r.kinds[k]; @@ -551,12 +551,13 @@ pub fn loadedOf(ops: *const Kind.Ops, path: []const u8, hash: [32]u8, words: *[6 /// This process's code for a kind a session's core lists, which a client /// runs itself: PA_PLAIN, of the same name, version, ABI and functions (a /// compiled-in addon's library hash is 0: never by the hash), and not -/// caught breaking its promise here (`distrust`). Null: its panes say so. -pub fn plainOps(e: *const Kind.Entry) ?*const Kind.Ops { +/// caught breaking its promise here (`distrusted`, the client's). Null: its +/// panes say so. +pub fn plainOps(e: *const Kind.Entry, distrusted: ?*const Distrusted) ?*const Kind.Ops { if (!e.caps.plain or e.refused) return null; // A client scans for its addons only when its session has a plain kind. _ = scan(); - for (distrusted[0..ndistrusted]) |*d| if (std.mem.eql(u8, std.mem.sliceTo(d, 0), e.nameOf())) return null; + if (distrusted) |d| for (d.names[0..d.n]) |*name| if (std.mem.eql(u8, std.mem.sliceTo(name, 0), e.nameOf())) return null; for (found[0..nfound], 0..) |*l, i| if (l.why.len == 0 and std.mem.eql(u8, l.name, e.nameOf()) and l.version == e.version and l.abi == e.abi and @as(u16, @bitCast(l.caps)) == @as(u16, @bitCast(e.caps))) { @@ -568,16 +569,20 @@ pub fn plainOps(e: *const Kind.Entry) ?*const Kind.Ops { } /// Kinds a client found breaking PA_PLAIN: shown by the session's line -/// from its next join on. A process's (test/replicas.zig keeps one a client). -pub var distrusted: [Kind.max_kinds][16]u8 = undefined; -pub var ndistrusted: usize = 0; +/// from its next join on. The client's, which outlives each core it joins +/// with (its frontend's, handed to them as `Options.distrusted`): no core's +/// state, never rolled back. +pub const Distrusted = struct { + names: [Kind.max_kinds][16]u8 = undefined, + n: usize = 0, -pub fn distrust(name: []const u8) void { - if (ndistrusted == distrusted.len) return; - distrusted[ndistrusted] = @splat(0); - @memcpy(distrusted[ndistrusted][0..@min(15, name.len)], name[0..@min(15, name.len)]); - ndistrusted += 1; -} + pub fn add(d: *Distrusted, name: []const u8) void { + if (d.n == d.names.len) return; + d.names[d.n] = @splat(0); + @memcpy(d.names[d.n][0..@min(15, name.len)], name[0..@min(15, name.len)]); + d.n += 1; + } +}; /// The kind that opens `path`, by its extension (any case). pub fn forPath(r: *const Kind.Registry, path: []const u8) ?u8 { |
