diff options
author | Himbeer <himbeer@disroot.org> | 2024-07-27 16:07:16 +0200 |
---|---|---|
committer | Himbeer <himbeer@disroot.org> | 2024-07-27 16:08:03 +0200 |
commit | e285d9ee0ad1e47bbfe595431b5e8c4fbb553d50 (patch) | |
tree | 6e3ee50062e3da4dda9f1967ccaa129e117c5c8f /src/lib/process.zig | |
parent | fc888ca37914ffc3aecc111f8c8fd3fc07869367 (diff) |
Remove VFS entirely (#56)
Diffstat (limited to 'src/lib/process.zig')
-rw-r--r-- | src/lib/process.zig | 76 |
1 files changed, 1 insertions, 75 deletions
diff --git a/src/lib/process.zig b/src/lib/process.zig index c7eddf6..2fbab11 100644 --- a/src/lib/process.zig +++ b/src/lib/process.zig @@ -11,7 +11,6 @@ const rethooks = @import("rethooks.zig"); const sysexchange = @import("sysexchange.zig"); const time = @import("sbi/time.zig"); const trap = @import("trap.zig"); -const vfs = @import("vfs.zig"); const elf = std.elf; @@ -61,49 +60,13 @@ pub const Info = struct { pages: []align(paging.page_size) u8, stack: []align(paging.page_size) u8, pc: usize, - cleanup_hook: ?CleanupHook, - term_hook: ?TermHook, page_table: *paging.Table, state: State, - rds: std.AutoArrayHashMap(usize, vfs.ResourceDescriptor), - - pub const CleanupHook = struct { - pub const CleanupFn = *const fn (proc: *const Info, buffer: []u8, copy: []const u8) void; - - cleanupFn: CleanupFn, - buffer: []u8, - copy: []const u8, - }; - - pub const TermHook = struct { - pub const HookFn = *const fn (context: *anyopaque, proc: *const Info) void; - - hookFn: HookFn, - context: *anyopaque, - }; pub fn satp(self: *const Info) paging.Satp { return self.page_table.satp(self.id); } - pub fn createRdHandle(self: *Info, rd: vfs.ResourceDescriptor) !usize { - if (self.rds.count() == std.math.maxInt(usize)) { - return Error.TooManyResourceDescriptors; - } - - var handle = self.rds.count() + 1; - while (self.rds.contains(handle)) : (handle +%= 1) {} - - try self.rds.put(handle, rd); - return handle; - } - - pub fn destroyRdHandle(self: *Info, handle: usize) void { - if (self.rds.fetchSwapRemove(handle)) |kv| { - kv.value.deinit(); - } - } - pub fn createThread(self: *const Info, allocator: ?std.mem.Allocator) !*Info { const alloc = allocator orelse self.allocator; @@ -121,7 +84,7 @@ pub const Info = struct { return Error.TooManyThreads; }; - const proc = .{ + const proc = Info{ .allocator = alloc, .id = self.id, .thread_id = thread_id, @@ -130,10 +93,8 @@ pub const Info = struct { .stack = stack, .pc = self.pc, .cleanup_hook = null, - .term_hook = null, .page_table = self.page_table, .state = .suspended, - .rds = self.rds, }; const proc_node = try alloc.create(std.DoublyLinkedList(Info).Node); @@ -143,24 +104,6 @@ pub const Info = struct { return &proc_node.data; } - pub fn call(self: *Info, function: usize, args: anytype, cleanup_hook: ?CleanupHook, term_hook: ?TermHook) noreturn { - self.pc = function; - self.cleanup_hook = cleanup_hook; - self.term_hook = term_hook; - self.trap_frame.general_purpose_registers[1] = @intFromPtr(&rethooks.terminate); - inline for (args, 0..) |arg, i| { - if (i >= 6) break; - - const value = usizeFromArg(arg); - self.trap_frame.general_purpose_registers[10 + i] = value; - } - - self.state = .waiting; - schedule() catch |err| { - std.debug.panic("schedule error: {}", .{err}); - }; - } - pub fn terminate( self: *Info, ) void { @@ -185,21 +128,7 @@ pub const Info = struct { if (self.thread_id == 0) { self.page_table.unmap(); paging.free(self.page_table); - paging.free(self.pages); - - for (self.rds.values()) |rd| { - rd.deinit(); - } - self.rds.clearAndFree(); - } - - if (self.cleanup_hook) |cleanup_hook| { - cleanup_hook.cleanupFn(self, cleanup_hook.buffer, cleanup_hook.copy); - } - if (self.term_hook) |term_hook| { - sysexchange.frameReturn(void, &self.trap_frame, vfs.Error.Detached); - term_hook.hookFn(term_hook.context, self); } } @@ -408,11 +337,8 @@ pub fn create(allocator: std.mem.Allocator, elf_buf: []align(@alignOf(elf.Elf64_ .pages = pages, .stack = @ptrCast(stack), .pc = hdr.entry, - .cleanup_hook = null, - .term_hook = null, .page_table = procmem, .state = .waiting, - .rds = std.AutoArrayHashMap(usize, vfs.ResourceDescriptor).init(allocator), }; proc.trap_frame.general_purpose_registers[2] = stack_top; |