aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHimbeer <himbeer@disroot.org>2024-07-04 12:37:03 +0200
committerHimbeer <himbeer@disroot.org>2024-07-04 12:37:14 +0200
commit680558985053f99a018190ff84c1851b22cf6665 (patch)
treee8282bf250e946af4650427188f7e183c31962e0
parent035cee7824b599303d526e26f43ae210a15e2126 (diff)
process: Make termination hooks receive a *anyopaque context
-rw-r--r--src/lib/process.zig19
1 files changed, 11 insertions, 8 deletions
diff --git a/src/lib/process.zig b/src/lib/process.zig
index 0f7f368..c155243 100644
--- a/src/lib/process.zig
+++ b/src/lib/process.zig
@@ -58,12 +58,15 @@ pub const Info = struct {
pages: []align(paging.page_size) u8,
stack: []align(paging.page_size) u8,
pc: usize,
- termHook: ?TermHook,
+ term_hook: ?TermHook,
page_table: *paging.Table,
state: State,
rds: std.AutoArrayHashMap(usize, vfs.ResourceDescriptor),
- pub const TermHook = *const fn (proc: *const Info) void;
+ pub const TermHook = struct {
+ hookFn: *const fn (context: *anyopaque, proc: *const Info) void,
+ context: *anyopaque,
+ };
pub fn destroy(self: *Info) !void {
try paging.free(self.stack);
@@ -119,7 +122,7 @@ pub const Info = struct {
.pages = self.pages,
.stack = stack,
.pc = self.pc,
- .termHook = null,
+ .term_hook = null,
.page_table = self.page_table,
.state = .suspended,
.rds = self.rds,
@@ -132,7 +135,7 @@ pub const Info = struct {
return &proc_node.data;
}
- pub fn call(self: *Info, function: usize, args: anytype, termHook: ?TermHook) noreturn {
+ pub fn call(self: *Info, function: usize, args: anytype, term_hook: ?TermHook) noreturn {
const Container = struct {
fn terminate() linksection(".rethooks") callconv(.Naked) noreturn {
// Syscall #100011 is "terminate".
@@ -144,7 +147,7 @@ pub const Info = struct {
};
self.pc = function;
- self.termHook = termHook;
+ self.term_hook = term_hook;
self.trap_frame.general_purpose_registers[1] = @intFromPtr(&Container.terminate);
inline for (args, 0..) |arg, i| {
if (i >= 6) break;
@@ -181,8 +184,8 @@ pub const Info = struct {
self.rds.deinit();
}
- if (self.termHook) |termHook| {
- termHook(self);
+ if (self.term_hook) |term_hook| {
+ term_hook.hookFn(term_hook.context, self);
}
}
@@ -341,7 +344,7 @@ pub fn create(allocator: std.mem.Allocator, elf_buf: []align(@alignOf(elf.Elf64_
.pages = pages,
.stack = @ptrCast(stack),
.pc = hdr.entry,
- .termHook = null,
+ .term_hook = null,
.page_table = procmem,
.state = .waiting,
.rds = std.AutoArrayHashMap(usize, vfs.ResourceDescriptor).init(allocator),