authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-12-19 16:19:01-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-12-23 22:15:11-08:00
log52ba2a4c72cee39292d09506655197811feceede
treef438c100d0c5d40094da3871250bfcaed11a2e9b
parent6cfd2df695df04834b935c21b1b40ddac0d39594

std.Io.Threaded: don't assume dirents are aligned

Linux kernel seems to do it but qemu user mode seems not to.

1 files changed, 4 insertions(+), 1 deletions(-)

lib/std/Io/Threaded.zig+4-1
......@@ -3440,7 +3440,10 @@ fn dirReadLinux(userdata: ?*anyopaque, dr: *Dir.Reader, buffer: []Dir.Entry) Dir
34403440 // by looking at only the 8 bytes before the next record. However since
34413441 // file names are usually short it's better to keep the machine code
34423442 // simpler.
3443 const linux_entry: *linux.dirent64 = @ptrCast(@alignCast(&dr.buffer[dr.index]));
3443 //
3444 // Furthermore, I observed qemu user mode to not align this struct, so
3445 // this code makes the conservative choice to not assume alignment.
3446 const linux_entry: *align(1) linux.dirent64 = @ptrCast(&dr.buffer[dr.index]);
34443447 const next_index = dr.index + linux_entry.reclen;
34453448 dr.index = next_index;
34463449 const name_ptr: [*]u8 = &linux_entry.name;