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{
4949pub const WriteFileError = Error || error{
5050 /// Descriptor is not valid or locked, or an mmap(2)-like operation is not available for in_fd.
5151 Unimplemented,
52 /// Can happen on FreeBSD when using copy_file_range.
53 CorruptedData,
5254 EndOfStream,
5355 ReadFailed,
5456};
lib/std/Io/Threaded.zig+33-12
......@@ -366,12 +366,12 @@ const Thread = struct {
366366
367367 fn futexWake(ptr: *const u32, max_waiters: u32) void {
368368 @branchHint(.cold);
369 assert(max_waiters != 0);
369370
370371 if (builtin.single_threaded) return; // nothing to wake up
371372
372373 if (builtin.cpu.arch.isWasm()) {
373374 comptime assert(builtin.cpu.has(.wasm, .atomics));
374 assert(max_waiters != 0);
375375 const woken_count = asm volatile (
376376 \\local.get %[ptr]
377377 \\local.get %[waiters]
......@@ -416,7 +416,6 @@ const Thread = struct {
416416 }
417417 },
418418 .windows => {
419 assert(max_waiters != 0);
420419 switch (max_waiters) {
421420 1 => windows.ntdll.RtlWakeAddressSingle(ptr),
422421 else => windows.ntdll.RtlWakeAddressAll(ptr),
......@@ -953,7 +952,8 @@ const have_fchown = switch (native_os) {
953952};
954953
955954const have_fchmod = switch (native_os) {
956 .wasi, .windows => false,
955 .windows => false,
956 .wasi => builtin.link_libc,
957957 else => true,
958958};
959959
......@@ -6772,7 +6772,7 @@ fn fileSeekBy(userdata: ?*anyopaque, file: File, offset: i64) File.SeekError!voi
67726772 var result: u64 = undefined;
67736773 try current_thread.beginSyscall();
67746774 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))) {
67766776 .SUCCESS => {
67776777 current_thread.endSyscall();
67786778 return;
......@@ -7000,7 +7000,7 @@ fn processExecutablePath(userdata: ?*anyopaque, out_buffer: []u8) std.process.Ex
70007000 if (rc != 0) return error.NameTooLong;
70017001
70027002 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) {
70047004 error.NetworkNotFound => unreachable, // Windows-only
70057005 else => |e| return e,
70067006 };
......@@ -7020,11 +7020,32 @@ fn processExecutablePath(userdata: ?*anyopaque, out_buffer: []u8) std.process.Ex
70207020 },
70217021 .freebsd, .dragonfly => {
70227022 const current_thread = Thread.getCurrent(t);
7023 try current_thread.checkCancel();
70247023 var mib: [4]c_int = .{ posix.CTL.KERN, posix.KERN.PROC, posix.KERN.PROC_PATHNAME, -1 };
70257024 var out_len: usize = out_buffer.len;
7026 try posix.sysctl(&mib, out_buffer.ptr, &out_len, null, 0);
7027 return out_len;
7025 try current_thread.beginSyscall();
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 }
70287049 },
70297050 .netbsd => {
70307051 const current_thread = Thread.getCurrent(t);
......@@ -7043,7 +7064,7 @@ fn processExecutablePath(userdata: ?*anyopaque, out_buffer: []u8) std.process.Ex
70437064 if (std.mem.indexOf(u8, argv0, "/") != null) {
70447065 // argv[0] is a path (relative or absolute): use realpath(3) directly
70457066 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) {
70477068 error.NetworkNotFound => unreachable, // Windows-only
70487069 else => |e| return e,
70497070 };
......@@ -7063,7 +7084,7 @@ fn processExecutablePath(userdata: ?*anyopaque, out_buffer: []u8) std.process.Ex
70637084 }, 0) catch continue;
70647085
70657086 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| {
70677088 // found a file, and hope it is the right file
70687089 if (real_path.len > out_buffer.len)
70697090 return error.NameTooLong;
......@@ -7730,8 +7751,8 @@ fn fileWriteFileStreaming(
77307751 .FBIG => return error.FileTooBig,
77317752 .IO => return error.InputOutput,
77327753 .INTEGRITY => return error.CorruptedData,
7733 .ISDIR => return error.IsDir,
77347754 .NOSPC => return error.NoSpaceLeft,
7755 .ISDIR => |err| errnoBug(err),
77357756 .BADF => |err| errnoBug(err),
77367757 else => |err| posix.unexpectedErrno(err),
77377758 });
......@@ -7908,11 +7929,11 @@ fn fileWriteFilePositional(
79087929 .FBIG => return error.FileTooBig,
79097930 .IO => return error.InputOutput,
79107931 .INTEGRITY => return error.CorruptedData,
7911 .ISDIR => return error.IsDir,
79127932 .NOSPC => return error.NoSpaceLeft,
79137933 .OVERFLOW => return error.Unseekable,
79147934 .NXIO => return error.Unseekable,
79157935 .SPIPE => return error.Unseekable,
7936 .ISDIR => |err| errnoBug(err),
79167937 .BADF => |err| errnoBug(err),
79177938 else => |err| posix.unexpectedErrno(err),
79187939 });
lib/std/c.zig+1
......@@ -163,6 +163,7 @@ pub const nlink_t = switch (native_os) {
163163 .freebsd, .serenity => u64,
164164 .openbsd, .netbsd, .illumos => u32,
165165 .haiku => i32,
166 .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => u16,
166167 else => u0,
167168};
168169
lib/std/process.zig+4-1
......@@ -2287,7 +2287,10 @@ pub fn exit(status: u8) noreturn {
22872287 } else switch (native_os) {
22882288 .windows => windows.ntdll.RtlExitUserProcess(status),
22892289 .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 },
22912294 .uefi => {
22922295 const uefi = std.os.uefi;
22932296 // exit() is only available if exitBootServices() has not been called yet.