diff options
author | Himbeer <himbeer@disroot.org> | 2024-07-04 15:26:28 +0200 |
---|---|---|
committer | Himbeer <himbeer@disroot.org> | 2024-07-04 15:26:28 +0200 |
commit | 2868e2c0363d79f5d1e2c52cdfd089e975748316 (patch) | |
tree | b47fbe97667f2bc719341d09c78aa05ba1ca106f /examples | |
parent | 4e4024841ce20c6bfdcc3e40abd62cb40f8eb002 (diff) |
zero_stream: Fix read callback calling convention and buffer memory region
Diffstat (limited to 'examples')
-rw-r--r-- | examples/zero_stream/src/main.zig | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/examples/zero_stream/src/main.zig b/examples/zero_stream/src/main.zig index 7147972..1536157 100644 --- a/examples/zero_stream/src/main.zig +++ b/examples/zero_stream/src/main.zig @@ -9,6 +9,15 @@ const Result = extern struct { status: usize, }; +// The buffer has to be a global variable +// because a stack buffer would be mapped to different physical memory addresses +// in the driver thread compared to the main thread due to paging +// (because each thread has its own stack). +// This will be fixed in a future kernel version because the same root cause +// also prevents a distinct driver process from accessing the memory +// (its attempt to modify the buffer would raise a page fault). +var buf = [8]u8{ 1, 2, 3, 4, 5, 6, 7, 8 }; + export fn _start() void { main(); } @@ -64,7 +73,6 @@ pub fn main() void { : "a7" ); - var buf = [8]u8{ 1, 2, 3, 4, 5, 6, 7, 8 }; asm volatile ( \\ li a7, 100009 \\ ecall @@ -86,7 +94,9 @@ pub fn main() void { ); } -pub fn read(buffer: []u8) Result { +pub export fn read(ptr: [*]u8, len: usize) Result { + const buffer = ptr[0..len]; + for (buffer, 0..) |_, i| { buffer[i] = 0; } |