aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHimbeer <himbeer@disroot.org>2024-07-01 15:35:26 +0200
committerHimbeer <himbeer@disroot.org>2024-07-01 15:35:26 +0200
commiteef85056c996cf86e88c2589dc95429d59362c7b (patch)
treec680d102ca6f0bced9435f84083f3267664496df
parentc188a18be912a03b00d501cd83eeaff63f6ff950 (diff)
syscall: Add provideFile, provideHook and provideDirHook and mkdir stub
-rw-r--r--src/lib/syscall.zig81
-rw-r--r--src/lib/vfs.zig37
2 files changed, 111 insertions, 7 deletions
diff --git a/src/lib/syscall.zig b/src/lib/syscall.zig
index 07c62fd..eece736 100644
--- a/src/lib/syscall.zig
+++ b/src/lib/syscall.zig
@@ -18,7 +18,11 @@ pub fn handle(trap_frame: *trap.Frame) !void {
100001 => open(trap_frame),
100002 => close(trap_frame),
100003 => provideStream(trap_frame),
- 100004 => remove(trap_frame),
+ 100004 => provideFile(trap_frame),
+ 100005 => provideHook(trap_frame),
+ 100006 => mkdir(trap_frame),
+ 100007 => provideDirHook(trap_frame),
+ 100008 => remove(trap_frame),
else => return Error.UnknownSyscall,
}
}
@@ -56,7 +60,7 @@ fn close(trap_frame: *const trap.Frame) void {
// path: [*:0]const u8, // fixme: Kernel panic if null pointer
// readFn: ?vfs.Stream.ReadFn,
// writeFn: ?vfs.Stream.WriteFn,
-// ) Result(usize)
+// ) Result(void)
fn provideStream(trap_frame: *trap.Frame) void {
const path: [*:0]const u8 = @ptrFromInt(trap_frame.general_purpose_registers[10]);
const readFn: ?vfs.Stream.ReadFn = @ptrFromInt(trap_frame.general_purpose_registers[11]);
@@ -70,6 +74,79 @@ fn provideStream(trap_frame: *trap.Frame) void {
}));
}
+// provideFile(
+// path: [*:0]const u8, // fixme: Kernel panic if null pointer
+// openFn: vfs.File.OpenFn,
+// readFn: ?vfs.File.ReadFn,
+// writeFn: ?vfs.File.WriteFn,
+// closeFn: ?vfs.File.CloseFn,
+// ) Result(void)
+fn provideFile(trap_frame: *trap.Frame) void {
+ const path: [*:0]const u8 = @ptrFromInt(trap_frame.general_purpose_registers[10]);
+ const openFn: vfs.File.OpenFn = @ptrFromInt(trap_frame.general_purpose_registers[11]);
+ const readFn: ?vfs.File.ReadFn = @ptrFromInt(trap_frame.general_purpose_registers[12]);
+ const writeFn: ?vfs.File.WriteFn = @ptrFromInt(trap_frame.general_purpose_registers[13]);
+ const closeFn: ?vfs.File.CloseFn = @ptrFromInt(trap_frame.general_purpose_registers[14]);
+
+ sysexchange.frameReturn(trap_frame, vfs.provideResourceZ(path, .{
+ .file = .{
+ .openFn = openFn,
+ .readFn = readFn,
+ .writeFn = writeFn,
+ .closeFn = closeFn,
+ },
+ }));
+}
+
+// provideHook(
+// path: [*:0]const u8, // fixme: Kernel panic if null pointer
+// callback: vfs.Hook.Callback,
+// ) Result(void)
+fn provideHook(trap_frame: *trap.Frame) void {
+ const path: [*:0]const u8 = @ptrFromInt(trap_frame.general_purpose_registers[10]);
+ const callback: vfs.Hook.Callback = @ptrFromInt(trap_frame.general_purpose_registers[11]);
+
+ sysexchange.frameReturn(trap_frame, vfs.provideResourceZ(path, .{
+ .hook = .{
+ .callback = callback,
+ },
+ }));
+}
+
+// mkdir(
+// path: [*:0]const u8, // fixme: Kernel panic if null pointer
+// options: vfs.MkdirOptions,
+// ) Result(void)
+fn mkdir(trap_frame: *trap.Frame) void {
+ const path: [*:0]const u8 = @ptrFromInt(trap_frame.general_purpose_registers[10]);
+ const options: vfs.MkdirOptions = @bitCast(trap_frame.general_purpose_registers[11]);
+
+ _ = path;
+ _ = options;
+ unreachable;
+}
+
+// provideDirHook(
+// path: [*:0]const u8, // fixme: Kernel panic if null pointer
+// provideFn: vfs.DirHook.ProvideFn,
+// findFn: vfs.DirHook.FindFn,
+// removeFn: vfs.DirHook.RemoveFn,
+// ) Result(void)
+fn provideDirHook(trap_frame: *trap.Frame) void {
+ const path: [*:0]const u8 = @ptrFromInt(trap_frame.general_purpose_registers[10]);
+ const provideFn: vfs.DirHook.ProvideFn = @ptrFromInt(trap_frame.general_purpose_registers[11]);
+ const findFn: vfs.DirHook.FindFn = @ptrFromInt(trap_frame.general_purpose_registers[12]);
+ const removeFn: vfs.DirHook.RemoveFn = @ptrFromInt(trap_frame.general_purpose_registers[13]);
+
+ sysexchange.frameReturn(trap_frame, vfs.provideResourceZ(path, .{
+ .dir_hook = .{
+ .provideFn = provideFn,
+ .findFn = findFn,
+ .removeFn = removeFn,
+ },
+ }));
+}
+
// remove(path: [*:0]const u8) Result(usize) // fixme: Kernel panic if null pointer
fn remove(trap_frame: *const trap.Frame) void {
const path: [*:0]const u8 = @ptrFromInt(trap_frame.general_purpose_registers[10]);
diff --git a/src/lib/vfs.zig b/src/lib/vfs.zig
index c324c48..798813f 100644
--- a/src/lib/vfs.zig
+++ b/src/lib/vfs.zig
@@ -22,18 +22,45 @@ pub const Stream = struct {
readFn: ?ReadFn,
writeFn: ?WriteFn,
- pub const ReadFn = *const fn (context: u16, buffer: []u8) sysexchange.Result(usize);
- pub const WriteFn = *const fn (context: u16, bytes: []const u8) sysexchange.Result(usize);
+ pub const ReadFn = *const fn (buffer: []u8) sysexchange.Result(usize);
+ pub const WriteFn = *const fn (bytes: []const u8) sysexchange.Result(usize);
};
// A file is a resource that creates a unique data stream with a driver.
-pub const File = struct {};
+pub const File = struct {
+ openFn: OpenFn,
+ readFn: ?ReadFn,
+ writeFn: ?WriteFn,
+ closeFn: ?CloseFn,
+
+ pub const OpenFn = *allowzero const fn (pid: u16) sysexchange.Result(*anyopaque);
+ pub const ReadFn = *const fn (context: *anyopaque, buffer: []u8) sysexchange.Result(usize);
+ pub const WriteFn = *const fn (context: *anyopaque, bytes: []const u8) sysexchange.Result(usize);
+ pub const CloseFn = *const fn (context: *anyopaque) void;
+};
// A hook is a resource that invokes raw driver callbacks when interacted with.
-pub const Hook = struct {};
+pub const Hook = struct {
+ callback: Callback,
+
+ pub const Callback = *allowzero const fn (pid: u16, data: usize) sysexchange.Result(usize);
+};
+
+pub const MkdirOptions = packed struct(usize) {
+ full: u1,
+ reserved: u63,
+};
// A directory hook is a resource that provides other resources via driver callbacks.
-pub const DirHook = struct {};
+pub const DirHook = struct {
+ provideFn: ProvideFn,
+ findFn: FindFn,
+ removeFn: RemoveFn,
+
+ pub const ProvideFn = *allowzero const fn (inode: Inode) sysexchange.Result(void);
+ pub const FindFn = *allowzero const fn (name: []const u8) ?Inode;
+ pub const RemoveFn = *allowzero const fn (name: []const u8) sysexchange.Result(void);
+};
pub const Resource = union(enum) {
stream: Stream,