authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-04-16 22:18:58+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-04-17 22:55:22+02:00
logcfee71385725c0997f319c5d73e2cdaf52cc5918
tree583021969baef501d3b101ddad02c29336e6757f
parent12d0d392234966c61a2d3f3db7981f5c4c2fced3
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

Merge pull request 'Haiku fixes' (#31851) from ypsvlq/zig:master into master

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31851 Reviewed-by: Andrew Kelley <andrew@ziglang.org>

5 files changed, 133 insertions(+), 12 deletions(-)

lib/std/Io/Threaded.zig+124-9
...@@ -5345,7 +5345,7 @@ fn dirOpenDirHaiku(...@@ -5345,7 +5345,7 @@ fn dirOpenDirHaiku(
5345 .NOMEM => return error.SystemResources,5345 .NOMEM => return error.SystemResources,
5346 .NOTDIR => return error.NotDir,5346 .NOTDIR => return error.NotDir,
5347 .PERM => return error.PermissionDenied,5347 .PERM => return error.PermissionDenied,
5348 .BUSY => return error.DeviceBusy,5348 .BUSY => |err| return errnoBug(err),
5349 else => |err| return posix.unexpectedErrno(err),5349 else => |err| return posix.unexpectedErrno(err),
5350 }5350 }
5351 },5351 },
...@@ -5791,10 +5791,119 @@ fn dirReadIllumos(userdata: ?*anyopaque, dr: *Dir.Reader, buffer: []Dir.Entry) D...@@ -5791,10 +5791,119 @@ fn dirReadIllumos(userdata: ?*anyopaque, dr: *Dir.Reader, buffer: []Dir.Entry) D
5791}5791}
57925792
5793fn dirReadHaiku(userdata: ?*anyopaque, dr: *Dir.Reader, buffer: []Dir.Entry) Dir.Reader.Error!usize {5793fn dirReadHaiku(userdata: ?*anyopaque, dr: *Dir.Reader, buffer: []Dir.Entry) Dir.Reader.Error!usize {
5794 _ = userdata;5794 const t: *Threaded = @ptrCast(@alignCast(userdata));
5795 _ = dr;5795 _ = t;
5796 _ = buffer;5796 var buffer_index: usize = 0;
5797 @panic("TODO implement dirReadHaiku");5797 while (buffer.len - buffer_index != 0) {
5798 if (dr.end - dr.index == 0) {
5799 // Refill the buffer, unless we've already created references to
5800 // buffered data.
5801 if (buffer_index != 0) break;
5802 if (dr.state == .reset) {
5803 const syscall: Syscall = try .start();
5804 while (true) {
5805 const rc = posix.system._kern_rewind_dir(dr.dir.handle);
5806 switch (@as(posix.E, @enumFromInt(@min(rc, 0)))) {
5807 .SUCCESS => {
5808 syscall.finish();
5809 break;
5810 },
5811 .INTR => {
5812 try syscall.checkCancel();
5813 continue;
5814 },
5815 else => |e| {
5816 syscall.finish();
5817 switch (e) {
5818 else => |err| return posix.unexpectedErrno(err),
5819 }
5820 },
5821 }
5822 }
5823 dr.state = .reading;
5824 }
5825 const syscall: Syscall = try .start();
5826 const n: usize = while (true) {
5827 const rc = posix.system._kern_read_dir(dr.dir.handle, dr.buffer.ptr, dr.buffer.len, @truncate(dr.buffer.len / @sizeOf(posix.system.DirEnt)));
5828 switch (@as(posix.E, @enumFromInt(@min(rc, 0)))) {
5829 .SUCCESS => {
5830 syscall.finish();
5831 break @intCast(rc);
5832 },
5833 .INTR => {
5834 try syscall.checkCancel();
5835 continue;
5836 },
5837 else => |e| {
5838 syscall.finish();
5839 switch (e) {
5840 else => |err| return posix.unexpectedErrno(err),
5841 }
5842 },
5843 }
5844 };
5845 if (n == 0) {
5846 dr.state = .finished;
5847 return 0;
5848 }
5849 dr.index = 0;
5850 // _kern_read_dir returns entry count, but Dir.Reader is designed for byte count
5851 dr.end = 0;
5852 var i: usize = 0;
5853 while (i < n) : (i += 1) {
5854 const entry = @as(*align(1) posix.system.DirEnt, @ptrCast(&dr.buffer[dr.end]));
5855 dr.end += entry.reclen;
5856 }
5857 }
5858 const entry = @as(*align(1) posix.system.DirEnt, @ptrCast(&dr.buffer[dr.index]));
5859 const next_index = dr.index + entry.reclen;
5860 dr.index = next_index;
5861
5862 const name = std.mem.sliceTo(@as([*:0]u8, @ptrCast(&entry.name)), 0);
5863 if (std.mem.eql(u8, name, ".") or std.mem.eql(u8, name, "..") or entry.ino == 0) continue;
5864
5865 // haiku dirent doesn't expose type, so we have to call stat to get it.
5866 var stat: std.c.Stat = undefined;
5867 {
5868 const syscall: Syscall = try .start();
5869 while (true) {
5870 const rc = posix.system._kern_read_stat(dr.dir.handle, name, false, &stat, @sizeOf(std.c.Stat));
5871 switch (@as(posix.E, @enumFromInt(@min(rc, 0)))) {
5872 .SUCCESS => {
5873 syscall.finish();
5874 break;
5875 },
5876 .INTR => {
5877 try syscall.checkCancel();
5878 continue;
5879 },
5880 else => |e| {
5881 syscall.finish();
5882 switch (e) {
5883 else => |err| return posix.unexpectedErrno(err),
5884 }
5885 },
5886 }
5887 }
5888 }
5889
5890 const entry_kind: File.Kind = switch (stat.mode & posix.S.IFMT) {
5891 posix.S.IFBLK => .block_device,
5892 posix.S.IFCHR => .character_device,
5893 posix.S.IFDIR => .directory,
5894 posix.S.IFIFO => .named_pipe,
5895 posix.S.IFLNK => .sym_link,
5896 posix.S.IFREG => .file,
5897 else => .unknown,
5898 };
5899 buffer[buffer_index] = .{
5900 .name = name,
5901 .kind = entry_kind,
5902 .inode = entry.ino,
5903 };
5904 buffer_index += 1;
5905 }
5906 return buffer_index;
5798}5907}
57995908
5800fn dirReadWindows(userdata: ?*anyopaque, dr: *Dir.Reader, buffer: []Dir.Entry) Dir.Reader.Error!usize {5909fn dirReadWindows(userdata: ?*anyopaque, dr: *Dir.Reader, buffer: []Dir.Entry) Dir.Reader.Error!usize {
...@@ -9812,7 +9921,10 @@ fn fileReadPositionalPosix(file: File, data: []const []u8, offset: u64) File.Rea...@@ -9812,7 +9921,10 @@ fn fileReadPositionalPosix(file: File, data: []const []u8, offset: u64) File.Rea
9812 if (have_preadv) {9921 if (have_preadv) {
9813 const syscall: Syscall = try .start();9922 const syscall: Syscall = try .start();
9814 while (true) {9923 while (true) {
9815 const rc = preadv_sym(file.handle, dest.ptr, @intCast(dest.len), @bitCast(offset));9924 const rc = if (native_os == .haiku)
9925 posix.system.readv_pos(file.handle, @bitCast(offset), dest.ptr, @intCast(dest.len))
9926 else
9927 preadv_sym(file.handle, dest.ptr, @intCast(dest.len), @bitCast(offset));
9816 switch (posix.errno(rc)) {9928 switch (posix.errno(rc)) {
9817 .SUCCESS => {9929 .SUCCESS => {
9818 syscall.finish();9930 syscall.finish();
...@@ -9846,7 +9958,7 @@ fn fileReadPositionalPosix(file: File, data: []const []u8, offset: u64) File.Rea...@@ -9846,7 +9958,7 @@ fn fileReadPositionalPosix(file: File, data: []const []u8, offset: u64) File.Rea
98469958
9847 const syscall: Syscall = try .start();9959 const syscall: Syscall = try .start();
9848 while (true) {9960 while (true) {
9849 const rc = posix.pread(file.handle, dest[0].ptr, @intCast(dest[0].len), @bitCast(offset));9961 const rc = pread_sym(file.handle, dest[0].base, @intCast(dest[0].len), @bitCast(offset));
9850 switch (posix.errno(rc)) {9962 switch (posix.errno(rc)) {
9851 .SUCCESS => {9963 .SUCCESS => {
9852 syscall.finish();9964 syscall.finish();
...@@ -10550,7 +10662,10 @@ fn fileWritePositional(...@@ -10550,7 +10662,10 @@ fn fileWritePositional(
1055010662
10551 const syscall: Syscall = try .start();10663 const syscall: Syscall = try .start();
10552 while (true) {10664 while (true) {
10553 const rc = pwritev_sym(file.handle, &iovecs, @intCast(iovlen), @bitCast(offset));10665 const rc = if (native_os == .haiku)
10666 posix.system.writev_pos(file.handle, @bitCast(offset), &iovecs, @intCast(iovlen))
10667 else
10668 pwritev_sym(file.handle, &iovecs, @intCast(iovlen), @bitCast(offset));
10554 switch (posix.errno(rc)) {10669 switch (posix.errno(rc)) {
10555 .SUCCESS => {10670 .SUCCESS => {
10556 syscall.finish();10671 syscall.finish();
...@@ -14063,7 +14178,7 @@ pub fn posixSocketModeProtocol(family: posix.sa_family_t, mode: net.Socket.Mode,...@@ -14063,7 +14178,7 @@ pub fn posixSocketModeProtocol(family: posix.sa_family_t, mode: net.Socket.Mode,
14063 .dgram => posix.SOCK.DGRAM,14178 .dgram => posix.SOCK.DGRAM,
14064 .seqpacket => posix.SOCK.SEQPACKET,14179 .seqpacket => posix.SOCK.SEQPACKET,
14065 .raw => posix.SOCK.RAW,14180 .raw => posix.SOCK.RAW,
14066 .rdm => posix.SOCK.RDM,14181 .rdm => if (@hasDecl(posix.SOCK, "RDM")) posix.SOCK.RDM else return error.OptionUnsupported,
14067 },14182 },
14068 if (protocol) |p| @intFromEnum(p) else if (is_windows) switch (family) {14183 if (protocol) |p| @intFromEnum(p) else if (is_windows) switch (family) {
14069 posix.AF.UNIX => switch (mode) {14184 posix.AF.UNIX => switch (mode) {
lib/std/c.zig+4-2
...@@ -3260,8 +3260,8 @@ pub const Sigaction = switch (native_os) {...@@ -3260,8 +3260,8 @@ pub const Sigaction = switch (native_os) {
32603260
3261 /// signal handler3261 /// signal handler
3262 handler: extern union {3262 handler: extern union {
3263 handler: handler_fn,3263 handler: ?handler_fn,
3264 sigaction: sigaction_fn,3264 sigaction: ?sigaction_fn,
3265 },3265 },
32663266
3267 /// signal mask to apply3267 /// signal mask to apply
...@@ -11142,6 +11142,8 @@ pub const _kern_open_dir = haiku._kern_open_dir;...@@ -11142,6 +11142,8 @@ pub const _kern_open_dir = haiku._kern_open_dir;
11142pub const _kern_read_dir = haiku._kern_read_dir;11142pub const _kern_read_dir = haiku._kern_read_dir;
11143pub const _kern_read_stat = haiku._kern_read_stat;11143pub const _kern_read_stat = haiku._kern_read_stat;
11144pub const _kern_rewind_dir = haiku._kern_rewind_dir;11144pub const _kern_rewind_dir = haiku._kern_rewind_dir;
11145pub const readv_pos = haiku.readv_pos;
11146pub const writev_pos = haiku.writev_pos;
11145pub const area_id = haiku.area_id;11147pub const area_id = haiku.area_id;
11146pub const area_info = haiku.area_info;11148pub const area_info = haiku.area_info;
11147pub const directory_which = haiku.directory_which;11149pub const directory_which = haiku.directory_which;
lib/std/c/haiku.zig+3
...@@ -6,6 +6,7 @@ const iovec = std.posix.iovec;...@@ -6,6 +6,7 @@ const iovec = std.posix.iovec;
6const iovec_const = std.posix.iovec_const;6const iovec_const = std.posix.iovec_const;
7const socklen_t = std.c.socklen_t;7const socklen_t = std.c.socklen_t;
8const fd_t = std.c.fd_t;8const fd_t = std.c.fd_t;
9const off_t = std.c.off_t;
9const PATH_MAX = std.c.PATH_MAX;10const PATH_MAX = std.c.PATH_MAX;
10const uid_t = std.c.uid_t;11const uid_t = std.c.uid_t;
11const gid_t = std.c.gid_t;12const gid_t = std.c.gid_t;
...@@ -28,6 +29,8 @@ pub extern "root" fn _kern_open_dir(fd: fd_t, path: [*:0]const u8) fd_t;...@@ -28,6 +29,8 @@ pub extern "root" fn _kern_open_dir(fd: fd_t, path: [*:0]const u8) fd_t;
28pub extern "root" fn _kern_read_dir(fd: fd_t, buffer: [*]u8, bufferSize: usize, maxCount: u32) isize;29pub extern "root" fn _kern_read_dir(fd: fd_t, buffer: [*]u8, bufferSize: usize, maxCount: u32) isize;
29pub extern "root" fn _kern_rewind_dir(fd: fd_t) status_t;30pub extern "root" fn _kern_rewind_dir(fd: fd_t) status_t;
30pub extern "root" fn _kern_read_stat(fd: fd_t, path: [*:0]const u8, traverseLink: bool, stat: *std.c.Stat, statSize: usize) status_t;31pub extern "root" fn _kern_read_stat(fd: fd_t, path: [*:0]const u8, traverseLink: bool, stat: *std.c.Stat, statSize: usize) status_t;
32pub extern "root" fn readv_pos(fd: fd_t, pos: off_t, vec: [*]const std.c.iovec, count: i32) isize;
33pub extern "root" fn writev_pos(fd: fd_t, pos: off_t, vec: [*]const std.c.iovec_const, count: i32) isize;
3134
32pub const area_info = extern struct {35pub const area_info = extern struct {
33 area: u32,36 area: u32,
lib/std/debug.zig+1-1
...@@ -1576,12 +1576,12 @@ fn handleSegfaultPosix(sig: posix.SIG, info: *const posix.siginfo_t, ctx_ptr: ?*...@@ -1576,12 +1576,12 @@ fn handleSegfaultPosix(sig: posix.SIG, info: *const posix.siginfo_t, ctx_ptr: ?*
1576 .tvos,1576 .tvos,
1577 .visionos,1577 .visionos,
1578 .watchos,1578 .watchos,
1579 .haiku,
1579 => @intFromPtr(info.addr),1580 => @intFromPtr(info.addr),
1580 .linux,1581 .linux,
1581 => @intFromPtr(info.fields.sigfault.addr),1582 => @intFromPtr(info.fields.sigfault.addr),
1582 .netbsd,1583 .netbsd,
1583 => @intFromPtr(info.info.reason.fault.addr),1584 => @intFromPtr(info.info.reason.fault.addr),
1584 .haiku,
1585 .openbsd,1585 .openbsd,
1586 => @intFromPtr(info.data.fault.addr),1586 => @intFromPtr(info.data.fault.addr),
1587 .illumos,1587 .illumos,
lib/std/zig/LibCInstallation.zig+1
...@@ -459,6 +459,7 @@ fn findNativeCrtDirPosix(self: *LibCInstallation, gpa: Allocator, io: Io, args:...@@ -459,6 +459,7 @@ fn findNativeCrtDirPosix(self: *LibCInstallation, gpa: Allocator, io: Io, args:
459459
460fn findNativeGccDirHaiku(self: *LibCInstallation, gpa: Allocator, io: Io, args: FindNativeOptions) FindError!void {460fn findNativeGccDirHaiku(self: *LibCInstallation, gpa: Allocator, io: Io, args: FindNativeOptions) FindError!void {
461 self.gcc_dir = try ccPrintFileName(gpa, io, .{461 self.gcc_dir = try ccPrintFileName(gpa, io, .{
462 .environ_map = args.environ_map,
462 .search_basename = "crtbeginS.o",463 .search_basename = "crtbeginS.o",
463 .want_dirname = .only_dir,464 .want_dirname = .only_dir,
464 .verbose = args.verbose,465 .verbose = args.verbose,