aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHimbeer <himbeer@disroot.org>2024-07-04 12:27:22 +0200
committerHimbeer <himbeer@disroot.org>2024-07-04 12:27:22 +0200
commitd364e5d8eff96661118f47f15bb64a9a42586259 (patch)
treeb0f5095a486c0c513affca6ad857064e356b2388 /src
parent5a9ba9400538f7a8f3fa494b384e0b6ecdf1c443 (diff)
process: Switch from returning model to callback model for driver callback handling
Diffstat (limited to 'src')
-rw-r--r--src/lib/process.zig16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/lib/process.zig b/src/lib/process.zig
index 87fc374..5c9466c 100644
--- a/src/lib/process.zig
+++ b/src/lib/process.zig
@@ -58,11 +58,13 @@ pub const Info = struct {
pages: []align(paging.page_size) u8,
stack: []align(paging.page_size) u8,
pc: usize,
- terminate_ra: ?usize,
+ termHook: ?TermHook,
page_table: *paging.Table,
state: State,
rds: std.AutoArrayHashMap(usize, vfs.ResourceDescriptor),
+ pub const TermHook = *const fn (proc: *const Info) void;
+
pub fn destroy(self: *Info) !void {
try paging.free(self.stack);
try self.page_table.unmap();
@@ -117,7 +119,7 @@ pub const Info = struct {
.pages = self.pages,
.stack = stack,
.pc = self.pc,
- .terminate_ra = null,
+ .termHook = null,
.page_table = self.page_table,
.state = .suspended,
.rds = self.rds,
@@ -130,7 +132,7 @@ pub const Info = struct {
return &proc_node.data;
}
- pub fn call(self: *Info, function: usize, args: anytype) noreturn {
+ pub fn call(self: *Info, function: usize, args: anytype, termHook: TermHook) void {
const Container = struct {
fn terminate() linksection(".rethooks") callconv(.Naked) noreturn {
// Syscall #100011 is "terminate".
@@ -142,7 +144,7 @@ pub const Info = struct {
};
self.pc = function;
- self.terminate_ra = @returnAddress();
+ self.termHook = termHook;
self.trap_frame.general_purpose_registers[1] = @intFromPtr(&Container.terminate);
inline for (args, 0..) |arg, i| {
if (i >= 6) break;
@@ -178,6 +180,10 @@ pub const Info = struct {
self.rds.deinit();
}
+
+ if (self.termHook) |termHook| {
+ termHook(self);
+ }
}
fn shouldRemove(self: *const Info, candidate: *const Info) bool {
@@ -335,7 +341,7 @@ pub fn create(allocator: std.mem.Allocator, elf_buf: []align(@alignOf(elf.Elf64_
.pages = pages,
.stack = @ptrCast(stack),
.pc = hdr.entry,
- .terminate_ra = null,
+ .termHook = null,
.page_table = procmem,
.state = .waiting,
.rds = std.AutoArrayHashMap(usize, vfs.ResourceDescriptor).init(allocator),