Unknown state [2025-08-04]

This commit is contained in:
2025-08-04 22:28:49 -04:00
parent 6e4b76a6d9
commit 3b252de1ca
27 changed files with 24509 additions and 0 deletions

1
loader/.envrc Normal file
View File

@@ -0,0 +1 @@
PATH_add zig-out/bin

47
loader/main.zig Normal file
View File

@@ -0,0 +1,47 @@
const std = @import("std");
const Hook = *const fn (i32, i32) callconv(.c) i32;
pub fn main() !void {
std.log.debug("setting up watches...", .{});
var event: std.os.linux.inotify_event = undefined;
const event_buf = std.mem.asBytes(&event);
const fd: i32 = @intCast(std.os.linux.inotify_init1(std.os.linux.IN.NONBLOCK));
defer _ = std.os.linux.close(fd);
_ = std.os.linux.inotify_add_watch(fd, "./libroot.so", std.os.linux.IN.MODIFY);
std.log.debug("loading dylib...", .{});
var lib = try std.DynLib.open("./libroot.so");
defer lib.close();
var hook: Hook = lib.lookup(Hook, "hook").?;
var polls = [_]std.os.linux.pollfd{
.{ .fd = fd, .events = std.os.linux.POLL.IN, .revents = 0 },
};
while (true) {
const eps = std.os.linux.poll(&polls, polls.len, 0);
std.log.debug("eps: {d}", .{eps});
if (eps > 0) {
std.log.debug("event!", .{});
while (std.os.linux.read(fd, event_buf.ptr, event_buf.len) > 0) {
std.log.debug("consume.", .{});
}
std.log.debug("reloading.", .{});
lib.close();
lib = try std.DynLib.open("./libroot.so");
hook = lib.lookup(Hook, "hook").?;
}
std.log.debug("update", .{});
const res = hook(5, 7);
std.log.debug("hook(5, 7) = {d}", .{res});
std.time.sleep(std.time.ns_per_s);
}
}

6
loader/root.zig Normal file
View File

@@ -0,0 +1,6 @@
const std = @import("std");
pub export fn hook(a: i32, b: i32) i32 {
return a * b;
}

5
loader/sample.txt Normal file
View File

@@ -0,0 +1,5 @@
content

4
loader/test.zig Normal file
View File

@@ -0,0 +1,4 @@
const std = @import("std");
comptime{
@compileLog(std.math.maxInt(u64));
}

41
loader/watch.zig Normal file
View File

@@ -0,0 +1,41 @@
const std = @import("std");
const linux = std.os.linux;
pub fn main() !void {
std.log.debug("setting up watches.", .{});
var event: linux.inotify_event = undefined;
const event_buf = std.mem.asBytes(&event);
const fd: i32 = @intCast(linux.inotify_init1(linux.IN.NONBLOCK));
defer _ = linux.close(fd);
const wd: i32 = @intCast(linux.inotify_add_watch(
fd,
"sample.txt",
linux.IN.MODIFY | linux.IN.CLOSE_WRITE,
));
defer _ = linux.inotify_rm_watch(fd, wd);
var fds = [_]linux.pollfd{
.{ .fd = fd, .events = linux.POLL.IN, .revents = 0 },
};
while (true) {
const k = linux.poll(&fds, fds.len, 1000);
std.log.debug("poll -> {d}", .{k});
if (k > 0) {
while (true) {
const n: isize = @bitCast(linux.read(
fd,
event_buf.ptr,
event_buf.len,
));
std.log.debug("read -> {d}", .{n});
std.time.sleep(500 * std.time.ns_per_ms);
if (n < 0) break;
}
}
}
}