authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-12-19 14:14:21-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-12-23 22:15:11-08:00
log3e624e17a40fd65b68dbec45030280008c6b4018
tree9d3097bd2ba2037f32dc152bfe6a4e06b207dac2
parent405db921dc0a053d7bebca6195c5a0031a5b187b

std: fix compilation errors on FreeBSD


4 files changed, 40 insertions(+), 13 deletions(-)

lib/std/Io/File/Writer.zig+2
...@@ -49,6 +49,8 @@ pub const Error = error{...@@ -49,6 +49,8 @@ pub const Error = error{
49pub const WriteFileError = Error || error{49pub const WriteFileError = Error || error{
50 /// Descriptor is not valid or locked, or an mmap(2)-like operation is not available for in_fd.50 /// Descriptor is not valid or locked, or an mmap(2)-like operation is not available for in_fd.
51 Unimplemented,51 Unimplemented,
52 /// Can happen on FreeBSD when using copy_file_range.
53 CorruptedData,
52 EndOfStream,54 EndOfStream,
53 ReadFailed,55 ReadFailed,
54};56};
lib/std/Io/Threaded.zig+33-12
...@@ -366,12 +366,12 @@ const Thread = struct {...@@ -366,12 +366,12 @@ const Thread = struct {
366366
367 fn futexWake(ptr: *const u32, max_waiters: u32) void {367 fn futexWake(ptr: *const u32, max_waiters: u32) void {
368 @branchHint(.cold);368 @branchHint(.cold);
369 assert(max_waiters != 0);
369370
370 if (builtin.single_threaded) return; // nothing to wake up371 if (builtin.single_threaded) return; // nothing to wake up
371372
372 if (builtin.cpu.arch.isWasm()) {373 if (builtin.cpu.arch.isWasm()) {
373 comptime assert(builtin.cpu.has(.wasm, .atomics));374 comptime assert(builtin.cpu.has(.wasm, .atomics));
374 assert(max_waiters != 0);
375 const woken_count = asm volatile (375 const woken_count = asm volatile (
376 \\local.get %[ptr]376 \\local.get %[ptr]
377 \\local.get %[waiters]377 \\local.get %[waiters]
...@@ -416,7 +416,6 @@ const Thread = struct {...@@ -416,7 +416,6 @@ const Thread = struct {
416 }416 }
417 },417 },
418 .windows => {418 .windows => {
419 assert(max_waiters != 0);
420 switch (max_waiters) {419 switch (max_waiters) {
421 1 => windows.ntdll.RtlWakeAddressSingle(ptr),420 1 => windows.ntdll.RtlWakeAddressSingle(ptr),
422 else => windows.ntdll.RtlWakeAddressAll(ptr),421 else => windows.ntdll.RtlWakeAddressAll(ptr),
...@@ -953,7 +952,8 @@ const have_fchown = switch (native_os) {...@@ -953,7 +952,8 @@ const have_fchown = switch (native_os) {
953};952};
954953
955const have_fchmod = switch (native_os) {954const have_fchmod = switch (native_os) {
956 .wasi, .windows => false,955 .windows => false,
956 .wasi => builtin.link_libc,
957 else => true,957 else => true,
958};958};
959959
...@@ -6772,7 +6772,7 @@ fn fileSeekBy(userdata: ?*anyopaque, file: File, offset: i64) File.SeekError!voi...@@ -6772,7 +6772,7 @@ fn fileSeekBy(userdata: ?*anyopaque, file: File, offset: i64) File.SeekError!voi
6772 var result: u64 = undefined;6772 var result: u64 = undefined;
6773 try current_thread.beginSyscall();6773 try current_thread.beginSyscall();
6774 while (true) {6774 while (true) {
6775 switch (posix.errno(posix.system.llseek(fd, offset, &result, posix.SEEK.CUR))) {6775 switch (posix.errno(posix.system.llseek(fd, @bitCast(offset), &result, posix.SEEK.CUR))) {
6776 .SUCCESS => {6776 .SUCCESS => {
6777 current_thread.endSyscall();6777 current_thread.endSyscall();
6778 return;6778 return;
...@@ -7000,7 +7000,7 @@ fn processExecutablePath(userdata: ?*anyopaque, out_buffer: []u8) std.process.Ex...@@ -7000,7 +7000,7 @@ fn processExecutablePath(userdata: ?*anyopaque, out_buffer: []u8) std.process.Ex
7000 if (rc != 0) return error.NameTooLong;7000 if (rc != 0) return error.NameTooLong;
70017001
7002 var real_path_buf: [posix.PATH_MAX]u8 = undefined;7002 var real_path_buf: [posix.PATH_MAX]u8 = undefined;
7003 const n = Io.Dir.realPathAbsolute(ioBasic(t), &symlink_path_buf, &real_path_buf) catch |err| switch (err) {7003 const n = Io.Dir.realPathFileAbsolute(ioBasic(t), &symlink_path_buf, &real_path_buf) catch |err| switch (err) {
7004 error.NetworkNotFound => unreachable, // Windows-only7004 error.NetworkNotFound => unreachable, // Windows-only
7005 else => |e| return e,7005 else => |e| return e,
7006 };7006 };
...@@ -7020,11 +7020,32 @@ fn processExecutablePath(userdata: ?*anyopaque, out_buffer: []u8) std.process.Ex...@@ -7020,11 +7020,32 @@ fn processExecutablePath(userdata: ?*anyopaque, out_buffer: []u8) std.process.Ex
7020 },7020 },
7021 .freebsd, .dragonfly => {7021 .freebsd, .dragonfly => {
7022 const current_thread = Thread.getCurrent(t);7022 const current_thread = Thread.getCurrent(t);
7023 try current_thread.checkCancel();
7024 var mib: [4]c_int = .{ posix.CTL.KERN, posix.KERN.PROC, posix.KERN.PROC_PATHNAME, -1 };7023 var mib: [4]c_int = .{ posix.CTL.KERN, posix.KERN.PROC, posix.KERN.PROC_PATHNAME, -1 };
7025 var out_len: usize = out_buffer.len;7024 var out_len: usize = out_buffer.len;
7026 try posix.sysctl(&mib, out_buffer.ptr, &out_len, null, 0);7025 try current_thread.beginSyscall();
7027 return out_len;7026 while (true) {
7027 switch (posix.errno(posix.system.sysctl(&mib, mib.len, out_buffer.ptr, &out_len, null, 0))) {
7028 .SUCCESS => {
7029 current_thread.endSyscall();
7030 return out_len;
7031 },
7032 .INTR => {
7033 try current_thread.checkCancel();
7034 continue;
7035 },
7036 .CANCELED => return current_thread.endSyscallCanceled(),
7037 else => |e| {
7038 current_thread.endSyscall();
7039 switch (e) {
7040 .FAULT => |err| return errnoBug(err),
7041 .PERM => return error.PermissionDenied,
7042 .NOMEM => return error.SystemResources,
7043 .NOENT => |err| return errnoBug(err),
7044 else => |err| return posix.unexpectedErrno(err),
7045 }
7046 },
7047 }
7048 }
7028 },7049 },
7029 .netbsd => {7050 .netbsd => {
7030 const current_thread = Thread.getCurrent(t);7051 const current_thread = Thread.getCurrent(t);
...@@ -7043,7 +7064,7 @@ fn processExecutablePath(userdata: ?*anyopaque, out_buffer: []u8) std.process.Ex...@@ -7043,7 +7064,7 @@ fn processExecutablePath(userdata: ?*anyopaque, out_buffer: []u8) std.process.Ex
7043 if (std.mem.indexOf(u8, argv0, "/") != null) {7064 if (std.mem.indexOf(u8, argv0, "/") != null) {
7044 // argv[0] is a path (relative or absolute): use realpath(3) directly7065 // argv[0] is a path (relative or absolute): use realpath(3) directly
7045 var real_path_buf: [posix.PATH_MAX]u8 = undefined;7066 var real_path_buf: [posix.PATH_MAX]u8 = undefined;
7046 const real_path = Io.Dir.realPathAbsolute(ioBasic(t), std.os.argv[0], &real_path_buf) catch |err| switch (err) {7067 const real_path = Io.Dir.realPathFileAbsolute(ioBasic(t), std.os.argv[0], &real_path_buf) catch |err| switch (err) {
7047 error.NetworkNotFound => unreachable, // Windows-only7068 error.NetworkNotFound => unreachable, // Windows-only
7048 else => |e| return e,7069 else => |e| return e,
7049 };7070 };
...@@ -7063,7 +7084,7 @@ fn processExecutablePath(userdata: ?*anyopaque, out_buffer: []u8) std.process.Ex...@@ -7063,7 +7084,7 @@ fn processExecutablePath(userdata: ?*anyopaque, out_buffer: []u8) std.process.Ex
7063 }, 0) catch continue;7084 }, 0) catch continue;
70647085
7065 var real_path_buf: [posix.PATH_MAX]u8 = undefined;7086 var real_path_buf: [posix.PATH_MAX]u8 = undefined;
7066 if (Io.Dir.realPathAbsolute(ioBasic(t), resolved_path, &real_path_buf)) |real_path| {7087 if (Io.Dir.realPathFileAbsolute(ioBasic(t), resolved_path, &real_path_buf)) |real_path| {
7067 // found a file, and hope it is the right file7088 // found a file, and hope it is the right file
7068 if (real_path.len > out_buffer.len)7089 if (real_path.len > out_buffer.len)
7069 return error.NameTooLong;7090 return error.NameTooLong;
...@@ -7730,8 +7751,8 @@ fn fileWriteFileStreaming(...@@ -7730,8 +7751,8 @@ fn fileWriteFileStreaming(
7730 .FBIG => return error.FileTooBig,7751 .FBIG => return error.FileTooBig,
7731 .IO => return error.InputOutput,7752 .IO => return error.InputOutput,
7732 .INTEGRITY => return error.CorruptedData,7753 .INTEGRITY => return error.CorruptedData,
7733 .ISDIR => return error.IsDir,
7734 .NOSPC => return error.NoSpaceLeft,7754 .NOSPC => return error.NoSpaceLeft,
7755 .ISDIR => |err| errnoBug(err),
7735 .BADF => |err| errnoBug(err),7756 .BADF => |err| errnoBug(err),
7736 else => |err| posix.unexpectedErrno(err),7757 else => |err| posix.unexpectedErrno(err),
7737 });7758 });
...@@ -7908,11 +7929,11 @@ fn fileWriteFilePositional(...@@ -7908,11 +7929,11 @@ fn fileWriteFilePositional(
7908 .FBIG => return error.FileTooBig,7929 .FBIG => return error.FileTooBig,
7909 .IO => return error.InputOutput,7930 .IO => return error.InputOutput,
7910 .INTEGRITY => return error.CorruptedData,7931 .INTEGRITY => return error.CorruptedData,
7911 .ISDIR => return error.IsDir,
7912 .NOSPC => return error.NoSpaceLeft,7932 .NOSPC => return error.NoSpaceLeft,
7913 .OVERFLOW => return error.Unseekable,7933 .OVERFLOW => return error.Unseekable,
7914 .NXIO => return error.Unseekable,7934 .NXIO => return error.Unseekable,
7915 .SPIPE => return error.Unseekable,7935 .SPIPE => return error.Unseekable,
7936 .ISDIR => |err| errnoBug(err),
7916 .BADF => |err| errnoBug(err),7937 .BADF => |err| errnoBug(err),
7917 else => |err| posix.unexpectedErrno(err),7938 else => |err| posix.unexpectedErrno(err),
7918 });7939 });
lib/std/c.zig+1
...@@ -163,6 +163,7 @@ pub const nlink_t = switch (native_os) {...@@ -163,6 +163,7 @@ pub const nlink_t = switch (native_os) {
163 .freebsd, .serenity => u64,163 .freebsd, .serenity => u64,
164 .openbsd, .netbsd, .illumos => u32,164 .openbsd, .netbsd, .illumos => u32,
165 .haiku => i32,165 .haiku => i32,
166 .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => u16,
166 else => u0,167 else => u0,
167};168};
168169
lib/std/process.zig+4-1
...@@ -2287,7 +2287,10 @@ pub fn exit(status: u8) noreturn {...@@ -2287,7 +2287,10 @@ pub fn exit(status: u8) noreturn {
2287 } else switch (native_os) {2287 } else switch (native_os) {
2288 .windows => windows.ntdll.RtlExitUserProcess(status),2288 .windows => windows.ntdll.RtlExitUserProcess(status),
2289 .wasi => std.os.wasi.proc_exit(status),2289 .wasi => std.os.wasi.proc_exit(status),
2290 .linux => if (!builtin.single_threaded) std.os.linux.exit_group(status),2290 .linux => {
2291 if (!builtin.single_threaded) std.os.linux.exit_group(status);
2292 posix.system.exit(status);
2293 },
2291 .uefi => {2294 .uefi => {
2292 const uefi = std.os.uefi;2295 const uefi = std.os.uefi;
2293 // exit() is only available if exitBootServices() has not been called yet.2296 // exit() is only available if exitBootServices() has not been called yet.