summaryrefslogtreecommitdiff
path: root/src/Addon.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/Addon.zig')
-rw-r--r--src/Addon.zig33
1 files changed, 32 insertions, 1 deletions
diff --git a/src/Addon.zig b/src/Addon.zig
index 80d8fdd8..a2c46b35 100644
--- a/src/Addon.zig
+++ b/src/Addon.zig
@@ -174,6 +174,7 @@ var found: [Kind.max_kinds]Loaded = undefined;
var found_words: [Kind.max_kinds][64]LoadedWord = undefined;
var found_text: [Kind.max_kinds][2][4096]u8 = undefined;
var nfound: usize = 0;
+var scanned = false;
/// The addons compiled in (`zig build static`, and any build off Linux):
/// the image and pdf modules' `pardes_addon` declarations, which only a
@@ -191,6 +192,8 @@ else
/// library of the two directories, in name order each, the user's first. A
/// library that crashed at its last load is listed, not loaded.
pub fn scan() []const Loaded {
+ if (scanned) return found[0..nfound];
+ scanned = true;
for (compiled_in) |ops| {
found[nfound] = loadedOf(ops, "builtin", @splat(0), &found_words[nfound]);
if (ops.init) |init| if (init(&Kind.api) != Kind.c.PA_OK) {
@@ -365,10 +368,37 @@ pub fn loadedOf(ops: *const Kind.Ops, path: []const u8, hash: [32]u8, words: *[6
.address = ops.address != null,
.view = ops.view != null,
.pictures = h.flags & Kind.c.PA_PICTURES != 0,
+ .plain = h.flags & Kind.c.PA_PLAIN != 0,
},
};
}
+/// 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 {
+ 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;
+ for (found[0..nfound]) |l| 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))) return @ptrFromInt(l.ops);
+ return null;
+}
+
+/// Kinds a client found breaking PA_PLAIN: shown by the session's line
+/// from its next join on.
+var distrusted: [Kind.max_kinds][16]u8 = undefined;
+var ndistrusted: 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;
+}
+
/// The kind that opens `path`, by its extension (any case).
pub fn forPath(r: *const Kind.Registry, path: []const u8) ?u8 {
const dot = std.mem.lastIndexOfScalar(u8, path, '.') orelse return null;
@@ -411,7 +441,8 @@ pub fn take(r: *Kind.Registry, l: Loaded, except: []const u8) ?[]const u8 {
return e.why.slice();
}
e.why.set("loaded");
- r.ops[r.n] = if (tape.replaying()) null else @ptrFromInt(l.ops);
+ // A client's: its own code for a plain kind, or none (the session's).
+ r.ops[r.n] = if (tape.replaying()) plainOps(e) else @ptrFromInt(l.ops);
for (l.words) |w| {
r.words[r.nwords] = .{ .kind = r.n, .arg = w.arg, .opens = w.opens };
r.words[r.nwords].name.set(w.name);