authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-10-15 19:31:28-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-10-29 06:20:49-07:00
log031044b3994d4510f64bd08ecba0ab01a7ed48c6
tree7fa8e0372e2f1cff77ef83ea76441b1c7bad7dd3
parentf7d47aed47b3fb8f593c398a8e38e66e2d10e1c1

std: fix macos compilation errors


12 files changed, 138 insertions(+), 104 deletions(-)

lib/std/Io/IoUring.zig+1-1
......@@ -1469,7 +1469,7 @@ fn pwrite(userdata: ?*anyopaque, file: Io.File, buffer: []const u8, offset: std.
14691469 .OVERFLOW => return error.Unseekable,
14701470 .BUSY => return error.DeviceBusy,
14711471 .CONNRESET => return error.ConnectionResetByPeer,
1472 .MSGSIZE => return error.MessageTooBig,
1472 .MSGSIZE => return error.MessageOversize,
14731473 else => |err| return std.posix.unexpectedErrno(err),
14741474 }
14751475}
lib/std/Io/Threaded.zig+50-32
......@@ -966,7 +966,7 @@ fn dirStatPathPosix(
966966 try t.checkCancel();
967967 var stat = std.mem.zeroes(posix.Stat);
968968 switch (posix.errno(fstatat_sym(dir.handle, sub_path_posix, &stat, flags))) {
969 .SUCCESS => return statFromPosix(stat),
969 .SUCCESS => return statFromPosix(&stat),
970970 .INTR => continue,
971971 .INVAL => |err| return errnoBug(err),
972972 .BADF => |err| return errnoBug(err), // Always a race condition.
......@@ -1166,8 +1166,9 @@ fn dirCreateFilePosix(
11661166 if (has_flock_open_flags and flags.lock_nonblocking) {
11671167 var fl_flags: usize = while (true) {
11681168 try t.checkCancel();
1169 switch (posix.errno(posix.system.fcntl(fd, posix.F.GETFL, 0))) {
1170 .SUCCESS => break,
1169 const rc = posix.system.fcntl(fd, posix.F.GETFL, @as(usize, 0));
1170 switch (posix.errno(rc)) {
1171 .SUCCESS => break @intCast(rc),
11711172 .INTR => continue,
11721173 else => |err| return posix.unexpectedErrno(err),
11731174 }
......@@ -1295,8 +1296,9 @@ fn dirOpenFile(
12951296 if (has_flock_open_flags and flags.lock_nonblocking) {
12961297 var fl_flags: usize = while (true) {
12971298 try t.checkCancel();
1298 switch (posix.errno(posix.system.fcntl(fd, posix.F.GETFL, 0))) {
1299 .SUCCESS => break,
1299 const rc = posix.system.fcntl(fd, posix.F.GETFL, @as(usize, 0));
1300 switch (posix.errno(rc)) {
1301 .SUCCESS => break @intCast(rc),
13001302 .INTR => continue,
13011303 else => |err| return posix.unexpectedErrno(err),
13021304 }
......@@ -1755,7 +1757,7 @@ fn sleepPosix(userdata: ?*anyopaque, timeout: Io.Timeout) Io.SleepError!void {
17551757 .sec = std.math.maxInt(sec_type),
17561758 .nsec = std.math.maxInt(nsec_type),
17571759 };
1758 break :t timestampToPosix(d.duration.nanoseconds);
1760 break :t timestampToPosix(d.raw.toNanoseconds());
17591761 };
17601762 while (true) {
17611763 try t.checkCancel();
......@@ -1850,6 +1852,7 @@ fn netListenUnix(
18501852 error.ProtocolUnsupportedBySystem => return error.AddressFamilyUnsupported,
18511853 error.ProtocolUnsupportedByAddressFamily => return error.AddressFamilyUnsupported,
18521854 error.SocketModeUnsupported => return error.AddressFamilyUnsupported,
1855 error.OptionUnsupported => return error.Unexpected,
18531856 else => |e| return e,
18541857 };
18551858 errdefer posix.close(socket_fd);
......@@ -2037,7 +2040,10 @@ fn netConnectUnix(
20372040) net.UnixAddress.ConnectError!net.Socket.Handle {
20382041 if (!net.has_unix_sockets) return error.AddressFamilyUnsupported;
20392042 const t: *Threaded = @ptrCast(@alignCast(userdata));
2040 const socket_fd = try openSocketPosix(t, posix.AF.UNIX, .{ .mode = .stream });
2043 const socket_fd = openSocketPosix(t, posix.AF.UNIX, .{ .mode = .stream }) catch |err| switch (err) {
2044 error.OptionUnsupported => return error.Unexpected,
2045 else => |e| return e,
2046 };
20412047 errdefer posix.close(socket_fd);
20422048 var storage: UnixAddress = undefined;
20432049 const addr_len = addressUnixToPosix(address, &storage);
......@@ -2064,7 +2070,22 @@ fn netBindIpPosix(
20642070 };
20652071}
20662072
2067fn openSocketPosix(t: *Threaded, family: posix.sa_family_t, options: IpAddress.BindOptions) !posix.socket_t {
2073fn openSocketPosix(
2074 t: *Threaded,
2075 family: posix.sa_family_t,
2076 options: IpAddress.BindOptions,
2077) error{
2078 AddressFamilyUnsupported,
2079 ProtocolUnsupportedBySystem,
2080 ProcessFdQuotaExceeded,
2081 SystemFdQuotaExceeded,
2082 SystemResources,
2083 ProtocolUnsupportedByAddressFamily,
2084 SocketModeUnsupported,
2085 OptionUnsupported,
2086 Unexpected,
2087 Canceled,
2088}!posix.socket_t {
20682089 const mode = posixSocketMode(options.mode);
20692090 const protocol = posixProtocol(options.protocol);
20702091 const socket_fd = while (true) {
......@@ -2209,7 +2230,7 @@ fn netReadPosix(userdata: ?*anyopaque, fd: net.Socket.Handle, data: [][]u8) net.
22092230 .NOTCONN => return error.SocketUnconnected,
22102231 .CONNRESET => return error.ConnectionResetByPeer,
22112232 .TIMEDOUT => return error.Timeout,
2212 .PIPE => return error.BrokenPipe,
2233 .PIPE => return error.SocketUnconnected,
22132234 .NETDOWN => return error.NetworkDown,
22142235 else => |err| return posix.unexpectedErrno(err),
22152236 }
......@@ -2253,29 +2274,29 @@ fn netSendOne(
22532274 flags: u32,
22542275) net.Socket.SendError!void {
22552276 var addr: PosixAddress = undefined;
2256 var iovec: posix.iovec = .{ .base = @constCast(message.data_ptr), .len = message.data_len };
2257 const msg: posix.msghdr = .{
2277 var iovec: posix.iovec_const = .{ .base = @constCast(message.data_ptr), .len = message.data_len };
2278 const msg: posix.msghdr_const = .{
22582279 .name = &addr.any,
22592280 .namelen = addressToPosix(message.address, &addr),
2260 .iov = iovec[0..1],
2281 .iov = (&iovec)[0..1],
22612282 .iovlen = 1,
22622283 .control = @constCast(message.control.ptr),
2263 .controllen = message.control.len,
2284 .controllen = @intCast(message.control.len),
22642285 .flags = 0,
22652286 };
22662287 while (true) {
22672288 try t.checkCancel();
2268 const rc = posix.system.sendmsg(handle, msg, flags);
2289 const rc = posix.system.sendmsg(handle, &msg, flags);
22692290 if (is_windows) {
22702291 if (rc == windows.ws2_32.SOCKET_ERROR) {
22712292 switch (windows.ws2_32.WSAGetLastError()) {
22722293 .WSAEACCES => return error.AccessDenied,
22732294 .WSAEADDRNOTAVAIL => return error.AddressNotAvailable,
22742295 .WSAECONNRESET => return error.ConnectionResetByPeer,
2275 .WSAEMSGSIZE => return error.MessageTooBig,
2296 .WSAEMSGSIZE => return error.MessageOversize,
22762297 .WSAENOBUFS => return error.SystemResources,
22772298 .WSAENOTSOCK => return error.FileDescriptorNotASocket,
2278 .WSAEAFNOSUPPORT => return error.AddressFamilyNotSupported,
2299 .WSAEAFNOSUPPORT => return error.AddressFamilyUnsupported,
22792300 .WSAEDESTADDRREQ => unreachable, // A destination address is required.
22802301 .WSAEFAULT => unreachable, // The lpBuffers, lpTo, lpOverlapped, lpNumberOfBytesSent, or lpCompletionRoutine parameters are not part of the user address space, or the lpTo parameter is too small.
22812302 .WSAEHOSTUNREACH => return error.NetworkUnreachable,
......@@ -2285,7 +2306,6 @@ fn netSendOne(
22852306 .WSAENETUNREACH => return error.NetworkUnreachable,
22862307 .WSAENOTCONN => return error.SocketUnconnected,
22872308 .WSAESHUTDOWN => unreachable, // The socket has been shut down; it is not possible to WSASendTo on a socket after shutdown has been invoked with how set to SD_SEND or SD_BOTH.
2288 .WSAEWOULDBLOCK => return error.WouldBlock,
22892309 .WSANOTINITIALISED => unreachable, // A successful WSAStartup call must occur before using this function.
22902310 else => |err| return windows.unexpectedWSAError(err),
22912311 }
......@@ -2299,28 +2319,24 @@ fn netSendOne(
22992319 message.data_len = @intCast(rc);
23002320 return;
23012321 },
2322 .INTR => continue,
2323
23022324 .ACCES => return error.AccessDenied,
2303 .AGAIN => return error.WouldBlock,
23042325 .ALREADY => return error.FastOpenAlreadyInProgress,
23052326 .BADF => |err| return errnoBug(err),
23062327 .CONNRESET => return error.ConnectionResetByPeer,
23072328 .DESTADDRREQ => |err| return errnoBug(err),
23082329 .FAULT => |err| return errnoBug(err),
2309 .INTR => continue,
23102330 .INVAL => |err| return errnoBug(err),
23112331 .ISCONN => |err| return errnoBug(err),
2312 .MSGSIZE => return error.MessageTooBig,
2332 .MSGSIZE => return error.MessageOversize,
23132333 .NOBUFS => return error.SystemResources,
23142334 .NOMEM => return error.SystemResources,
23152335 .NOTSOCK => |err| return errnoBug(err),
23162336 .OPNOTSUPP => |err| return errnoBug(err),
2317 .PIPE => return error.BrokenPipe,
2318 .AFNOSUPPORT => return error.AddressFamilyNotSupported,
2319 .LOOP => return error.SymLinkLoop,
2320 .NAMETOOLONG => return error.NameTooLong,
2321 .NOENT => return error.FileNotFound,
2322 .NOTDIR => return error.NotDir,
2323 .HOSTUNREACH => return error.NetworkUnreachable,
2337 .PIPE => return error.SocketUnconnected,
2338 .AFNOSUPPORT => return error.AddressFamilyUnsupported,
2339 .HOSTUNREACH => return error.HostUnreachable,
23242340 .NETUNREACH => return error.NetworkUnreachable,
23252341 .NOTCONN => return error.SocketUnconnected,
23262342 .NETDOWN => return error.NetworkDown,
......@@ -2447,7 +2463,7 @@ fn netReceive(
24472463 .iov = (&iov)[0..1],
24482464 .iovlen = 1,
24492465 .control = message.control.ptr,
2450 .controllen = message.control.len,
2466 .controllen = @intCast(message.control.len),
24512467 .flags = undefined,
24522468 };
24532469
......@@ -2465,7 +2481,7 @@ fn netReceive(
24652481 .trunc = (msg.flags & posix.MSG.TRUNC) != 0,
24662482 .ctrunc = (msg.flags & posix.MSG.CTRUNC) != 0,
24672483 .oob = (msg.flags & posix.MSG.OOB) != 0,
2468 .errqueue = (msg.flags & posix.MSG.ERRQUEUE) != 0,
2484 .errqueue = if (@hasDecl(posix.MSG, "ERRQUEUE")) (msg.flags & posix.MSG.ERRQUEUE) != 0 else false,
24692485 },
24702486 };
24712487 message_i += 1;
......@@ -2605,6 +2621,7 @@ fn netInterfaceNameResolve(
26052621 error.ProtocolUnsupportedBySystem => return error.Unexpected,
26062622 error.ProtocolUnsupportedByAddressFamily => return error.Unexpected,
26072623 error.SocketModeUnsupported => return error.Unexpected,
2624 error.OptionUnsupported => return error.Unexpected,
26082625 else => |e| return e,
26092626 };
26102627 defer posix.close(sock_fd);
......@@ -3079,9 +3096,10 @@ fn lookupDns(
30793096 }
30803097 }
30813098
3082 var ip4_mapped: [HostName.ResolvConf.max_nameservers]IpAddress = undefined;
3099 var ip4_mapped_buffer: [HostName.ResolvConf.max_nameservers]IpAddress = undefined;
3100 const ip4_mapped = ip4_mapped_buffer[0..rc.nameservers_len];
30833101 var any_ip6 = false;
3084 for (rc.nameservers(), &ip4_mapped) |*ns, *m| {
3102 for (rc.nameservers(), ip4_mapped) |*ns, *m| {
30853103 m.* = .{ .ip6 = .fromAny(ns.*) };
30863104 any_ip6 = any_ip6 or ns.* == .ip6;
30873105 }
......@@ -3101,7 +3119,7 @@ fn lookupDns(
31013119 };
31023120 defer socket.close(t_io);
31033121
3104 const mapped_nameservers = if (any_ip6) ip4_mapped[0..rc.nameservers_len] else rc.nameservers();
3122 const mapped_nameservers = if (any_ip6) ip4_mapped else rc.nameservers();
31053123 const queries = queries_buffer[0..nq];
31063124 const answers = answers_buffer[0..queries.len];
31073125 var answers_remaining = answers.len;
lib/std/Io/net.zig+7-2
......@@ -209,6 +209,9 @@ pub const IpAddress = union(enum) {
209209 ProtocolUnsupportedBySystem,
210210 ProtocolUnsupportedByAddressFamily,
211211 SocketModeUnsupported,
212 /// One of the `ListenOptions` is not supported by the Io
213 /// implementation.
214 OptionUnsupported,
212215 } || Io.UnexpectedError || Io.Cancelable;
213216
214217 pub const ListenOptions = struct {
......@@ -1057,6 +1060,9 @@ pub const Socket = struct {
10571060 /// Local end has been shut down on a connection-oriented socket, or
10581061 /// the socket was never connected.
10591062 SocketUnconnected,
1063 /// An attempt was made to send to a network/broadcast address as
1064 /// though it was a unicast address.
1065 AccessDenied,
10601066 } || Io.UnexpectedError || Io.Cancelable;
10611067
10621068 /// Transfers `data` to `dest`, connectionless, in one packet.
......@@ -1167,7 +1173,6 @@ pub const Stream = struct {
11671173
11681174 pub const Error = error{
11691175 SystemResources,
1170 BrokenPipe,
11711176 ConnectionResetByPeer,
11721177 Timeout,
11731178 SocketUnconnected,
......@@ -1233,7 +1238,7 @@ pub const Stream = struct {
12331238 pub const Error = std.posix.SendMsgError || error{
12341239 ConnectionResetByPeer,
12351240 SocketNotBound,
1236 MessageTooBig,
1241 MessageOversize,
12371242 NetworkDown,
12381243 SystemResources,
12391244 SocketUnconnected,
lib/std/c.zig+1-1
......@@ -4104,7 +4104,7 @@ pub const msghdr = switch (native_os) {
41044104 .visionos,
41054105 .watchos,
41064106 .serenity, // https://github.com/SerenityOS/serenity/blob/ac44ec5ebc707f9dd0c3d4759a1e17e91db5d74f/Kernel/API/POSIX/sys/socket.h#L74-L82
4107 => private.posix_msghdr,
4107 => posix_msghdr,
41084108 else => void,
41094109};
41104110
lib/std/crypto/Certificate/Bundle.zig+24-21
......@@ -70,18 +70,18 @@ pub const RescanError = RescanLinuxError || RescanMacError || RescanWithPathErro
7070/// file system standard locations for certificates.
7171/// For operating systems that do not have standard CA installations to be
7272/// found, this function clears the set of certificates.
73pub fn rescan(cb: *Bundle, gpa: Allocator, io: Io) RescanError!void {
73pub fn rescan(cb: *Bundle, gpa: Allocator, io: Io, now: Io.Timestamp) RescanError!void {
7474 switch (builtin.os.tag) {
75 .linux => return rescanLinux(cb, gpa, io),
76 .macos => return rescanMac(cb, gpa),
77 .freebsd, .openbsd => return rescanWithPath(cb, gpa, io, "/etc/ssl/cert.pem"),
78 .netbsd => return rescanWithPath(cb, gpa, io, "/etc/openssl/certs/ca-certificates.crt"),
79 .dragonfly => return rescanWithPath(cb, gpa, io, "/usr/local/etc/ssl/cert.pem"),
80 .illumos => return rescanWithPath(cb, gpa, io, "/etc/ssl/cacert.pem"),
81 .haiku => return rescanWithPath(cb, gpa, io, "/boot/system/data/ssl/CARootCertificates.pem"),
75 .linux => return rescanLinux(cb, gpa, io, now),
76 .macos => return rescanMac(cb, gpa, io, now),
77 .freebsd, .openbsd => return rescanWithPath(cb, gpa, io, now, "/etc/ssl/cert.pem"),
78 .netbsd => return rescanWithPath(cb, gpa, io, now, "/etc/openssl/certs/ca-certificates.crt"),
79 .dragonfly => return rescanWithPath(cb, gpa, io, now, "/usr/local/etc/ssl/cert.pem"),
80 .illumos => return rescanWithPath(cb, gpa, io, now, "/etc/ssl/cacert.pem"),
81 .haiku => return rescanWithPath(cb, gpa, io, now, "/boot/system/data/ssl/CARootCertificates.pem"),
8282 // https://github.com/SerenityOS/serenity/blob/222acc9d389bc6b490d4c39539761b043a4bfcb0/Ports/ca-certificates/package.sh#L19
83 .serenity => return rescanWithPath(cb, gpa, io, "/etc/ssl/certs/ca-certificates.crt"),
84 .windows => return rescanWindows(cb, gpa),
83 .serenity => return rescanWithPath(cb, gpa, io, now, "/etc/ssl/certs/ca-certificates.crt"),
84 .windows => return rescanWindows(cb, gpa, io, now),
8585 else => {},
8686 }
8787}
......@@ -91,7 +91,7 @@ const RescanMacError = @import("Bundle/macos.zig").RescanMacError;
9191
9292const RescanLinuxError = AddCertsFromFilePathError || AddCertsFromDirPathError;
9393
94fn rescanLinux(cb: *Bundle, gpa: Allocator, io: Io) RescanLinuxError!void {
94fn rescanLinux(cb: *Bundle, gpa: Allocator, io: Io, now: Io.Timestamp) RescanLinuxError!void {
9595 // Possible certificate files; stop after finding one.
9696 const cert_file_paths = [_][]const u8{
9797 "/etc/ssl/certs/ca-certificates.crt", // Debian/Ubuntu/Gentoo etc.
......@@ -114,7 +114,7 @@ fn rescanLinux(cb: *Bundle, gpa: Allocator, io: Io) RescanLinuxError!void {
114114
115115 scan: {
116116 for (cert_file_paths) |cert_file_path| {
117 if (addCertsFromFilePathAbsolute(cb, gpa, io, cert_file_path)) |_| {
117 if (addCertsFromFilePathAbsolute(cb, gpa, io, now, cert_file_path)) |_| {
118118 break :scan;
119119 } else |err| switch (err) {
120120 error.FileNotFound => continue,
......@@ -123,7 +123,7 @@ fn rescanLinux(cb: *Bundle, gpa: Allocator, io: Io) RescanLinuxError!void {
123123 }
124124
125125 for (cert_dir_paths) |cert_dir_path| {
126 addCertsFromDirPathAbsolute(cb, gpa, io, cert_dir_path) catch |err| switch (err) {
126 addCertsFromDirPathAbsolute(cb, gpa, io, now, cert_dir_path) catch |err| switch (err) {
127127 error.FileNotFound => continue,
128128 else => |e| return e,
129129 };
......@@ -135,10 +135,10 @@ fn rescanLinux(cb: *Bundle, gpa: Allocator, io: Io) RescanLinuxError!void {
135135
136136const RescanWithPathError = AddCertsFromFilePathError;
137137
138fn rescanWithPath(cb: *Bundle, gpa: Allocator, io: Io, cert_file_path: []const u8) RescanWithPathError!void {
138fn rescanWithPath(cb: *Bundle, gpa: Allocator, io: Io, now: Io.Timestamp, cert_file_path: []const u8) RescanWithPathError!void {
139139 cb.bytes.clearRetainingCapacity();
140140 cb.map.clearRetainingCapacity();
141 try addCertsFromFilePathAbsolute(cb, gpa, io, cert_file_path);
141 try addCertsFromFilePathAbsolute(cb, gpa, io, now, cert_file_path);
142142 cb.bytes.shrinkAndFree(gpa, cb.bytes.items.len);
143143}
144144
......@@ -187,17 +187,18 @@ pub fn addCertsFromDirPathAbsolute(
187187 cb: *Bundle,
188188 gpa: Allocator,
189189 io: Io,
190 now: Io.Timestamp,
190191 abs_dir_path: []const u8,
191192) AddCertsFromDirPathError!void {
192193 assert(fs.path.isAbsolute(abs_dir_path));
193194 var iterable_dir = try fs.openDirAbsolute(abs_dir_path, .{ .iterate = true });
194195 defer iterable_dir.close();
195 return addCertsFromDir(cb, gpa, io, iterable_dir);
196 return addCertsFromDir(cb, gpa, io, now, iterable_dir);
196197}
197198
198199pub const AddCertsFromDirError = AddCertsFromFilePathError;
199200
200pub fn addCertsFromDir(cb: *Bundle, gpa: Allocator, io: Io, iterable_dir: fs.Dir) AddCertsFromDirError!void {
201pub fn addCertsFromDir(cb: *Bundle, gpa: Allocator, io: Io, now: Io.Timestamp, iterable_dir: fs.Dir) AddCertsFromDirError!void {
201202 var it = iterable_dir.iterate();
202203 while (try it.next()) |entry| {
203204 switch (entry.kind) {
......@@ -205,7 +206,7 @@ pub fn addCertsFromDir(cb: *Bundle, gpa: Allocator, io: Io, iterable_dir: fs.Dir
205206 else => continue,
206207 }
207208
208 try addCertsFromFilePath(cb, gpa, io, iterable_dir.adaptToNewApi(), entry.name);
209 try addCertsFromFilePath(cb, gpa, io, now, iterable_dir.adaptToNewApi(), entry.name);
209210 }
210211}
211212
......@@ -215,9 +216,9 @@ pub fn addCertsFromFilePathAbsolute(
215216 cb: *Bundle,
216217 gpa: Allocator,
217218 io: Io,
219 now: Io.Timestamp,
218220 abs_file_path: []const u8,
219221) AddCertsFromFilePathError!void {
220 const now = try Io.Clock.real.now(io);
221222 var file = try fs.openFileAbsolute(abs_file_path, .{});
222223 defer file.close();
223224 var file_reader = file.reader(io, &.{});
......@@ -228,10 +229,10 @@ pub fn addCertsFromFilePath(
228229 cb: *Bundle,
229230 gpa: Allocator,
230231 io: Io,
232 now: Io.Timestamp,
231233 dir: Io.Dir,
232234 sub_file_path: []const u8,
233235) AddCertsFromFilePathError!void {
234 const now = try Io.Clock.real.now(io);
235236 var file = try dir.openFile(io, sub_file_path, .{});
236237 defer file.close(io);
237238 var file_reader = file.reader(io, &.{});
......@@ -335,5 +336,7 @@ test "scan for OS-provided certificates" {
335336 var bundle: Bundle = .{};
336337 defer bundle.deinit(gpa);
337338
338 try bundle.rescan(gpa, io);
339 const now = try Io.Clock.real.now(io);
340
341 try bundle.rescan(gpa, io, now);
339342}
lib/std/crypto/Certificate/Bundle/macos.zig+6-6
......@@ -1,4 +1,5 @@
11const std = @import("std");
2const Io = std.Io;
23const assert = std.debug.assert;
34const fs = std.fs;
45const mem = std.mem;
......@@ -7,7 +8,7 @@ const Bundle = @import("../Bundle.zig");
78
89pub const RescanMacError = Allocator.Error || fs.File.OpenError || fs.File.ReadError || fs.File.SeekError || Bundle.ParseCertError || error{EndOfStream};
910
10pub fn rescanMac(cb: *Bundle, gpa: Allocator) RescanMacError!void {
11pub fn rescanMac(cb: *Bundle, gpa: Allocator, io: Io, now: Io.Timestamp) RescanMacError!void {
1112 cb.bytes.clearRetainingCapacity();
1213 cb.map.clearRetainingCapacity();
1314
......@@ -16,6 +17,7 @@ pub fn rescanMac(cb: *Bundle, gpa: Allocator) RescanMacError!void {
1617 "/Library/Keychains/System.keychain",
1718 };
1819
20 _ = io; // TODO migrate file system to use std.Io
1921 for (keychain_paths) |keychain_path| {
2022 const bytes = std.fs.cwd().readFileAlloc(keychain_path, gpa, .limited(std.math.maxInt(u32))) catch |err| switch (err) {
2123 error.StreamTooLong => return error.FileTooBig,
......@@ -23,8 +25,8 @@ pub fn rescanMac(cb: *Bundle, gpa: Allocator) RescanMacError!void {
2325 };
2426 defer gpa.free(bytes);
2527
26 var reader: std.Io.Reader = .fixed(bytes);
27 scanReader(cb, gpa, &reader) catch |err| switch (err) {
28 var reader: Io.Reader = .fixed(bytes);
29 scanReader(cb, gpa, &reader, now.toSeconds()) catch |err| switch (err) {
2830 error.ReadFailed => unreachable, // prebuffered
2931 else => |e| return e,
3032 };
......@@ -33,7 +35,7 @@ pub fn rescanMac(cb: *Bundle, gpa: Allocator) RescanMacError!void {
3335 cb.bytes.shrinkAndFree(gpa, cb.bytes.items.len);
3436}
3537
36fn scanReader(cb: *Bundle, gpa: Allocator, reader: *std.Io.Reader) !void {
38fn scanReader(cb: *Bundle, gpa: Allocator, reader: *Io.Reader, now_sec: i64) !void {
3739 const db_header = try reader.takeStruct(ApplDbHeader, .big);
3840 assert(mem.eql(u8, &db_header.signature, "kych"));
3941
......@@ -49,8 +51,6 @@ fn scanReader(cb: *Bundle, gpa: Allocator, reader: *std.Io.Reader) !void {
4951 table_list[table_idx] = try reader.takeInt(u32, .big);
5052 }
5153
52 const now_sec = std.time.timestamp();
53
5454 for (table_list) |table_offset| {
5555 reader.seek = db_header.schema_offset + table_offset;
5656
lib/std/debug/SelfInfo/MachO.zig+3
......@@ -117,11 +117,14 @@ pub fn unwindFrame(si: *SelfInfo, gpa: Allocator, context: *UnwindContext) Error
117117 error.ReadFailed,
118118 error.OutOfMemory,
119119 error.Unexpected,
120 error.Canceled,
120121 => |e| return e,
122
121123 error.UnsupportedRegister,
122124 error.UnsupportedAddrSize,
123125 error.UnimplementedUserOpcode,
124126 => return error.UnsupportedDebugInfo,
127
125128 error.Overflow,
126129 error.EndOfStream,
127130 error.StreamTooLong,
lib/std/fs.zig+2
......@@ -458,6 +458,8 @@ pub const SelfExePathError = error{
458458 /// On Windows, the volume does not contain a recognized file system. File
459459 /// system drivers might not be loaded, or the volume may be corrupt.
460460 UnrecognizedVolume,
461
462 Canceled,
461463} || posix.SysCtlError;
462464
463465/// `selfExePath` except allocates the result on the heap.
lib/std/http/Client.zig+13-10
......@@ -35,9 +35,11 @@ tls_buffer_size: if (disable_tls) u0 else usize = if (disable_tls) 0 else std.cr
3535/// traffic over connections created with this `Client`.
3636ssl_key_log: ?*std.crypto.tls.Client.SslKeyLog = null,
3737
38/// When this is `true`, the next time this client performs an HTTPS request,
39/// it will first rescan the system for root certificates.
40next_https_rescan_certs: bool = true,
38/// The time used to decide whether certificates are expired.
39///
40/// When this is `null`, the next time this client performs an HTTPS request,
41/// it will first check the time and rescan the system for root certificates.
42now: ?Io.Timestamp = null,
4143
4244/// The pool of connections that can be reused (and currently in use).
4345connection_pool: ConnectionPool = .{},
......@@ -295,6 +297,7 @@ pub const Connection = struct {
295297 client: std.crypto.tls.Client,
296298 connection: Connection,
297299
300 /// Asserts that `client.now` is non-null.
298301 fn create(
299302 client: *Client,
300303 remote_host: HostName,
......@@ -320,7 +323,6 @@ pub const Connection = struct {
320323 const tls: *Tls = @ptrCast(base);
321324 var random_buffer: [176]u8 = undefined;
322325 std.crypto.random.bytes(&random_buffer);
323 const now_ts = if (Io.Clock.real.now(io)) |ts| ts.toSeconds() else |err| return err;
324326 tls.* = .{
325327 .connection = .{
326328 .client = client,
......@@ -333,7 +335,7 @@ pub const Connection = struct {
333335 .closing = false,
334336 .protocol = .tls,
335337 },
336 // TODO data race here on ca_bundle if the user sets next_https_rescan_certs to true
338 // TODO data race here on ca_bundle if the user sets `now` to null
337339 .client = std.crypto.tls.Client.init(
338340 &tls.connection.stream_reader.interface,
339341 &tls.connection.stream_writer.interface,
......@@ -344,7 +346,7 @@ pub const Connection = struct {
344346 .read_buffer = tls_read_buffer,
345347 .write_buffer = socket_write_buffer,
346348 .entropy = &random_buffer,
347 .realtime_now_seconds = now_ts,
349 .realtime_now_seconds = client.now.?.toSeconds(),
348350 // This is appropriate for HTTPS because the HTTP headers contain
349351 // the content length which is used to detect truncation attacks.
350352 .allow_truncation_attacks = true,
......@@ -1687,14 +1689,15 @@ pub fn request(
16871689
16881690 if (protocol == .tls) {
16891691 if (disable_tls) unreachable;
1690 if (@atomicLoad(bool, &client.next_https_rescan_certs, .acquire)) {
1692 {
16911693 client.ca_bundle_mutex.lock();
16921694 defer client.ca_bundle_mutex.unlock();
16931695
1694 if (client.next_https_rescan_certs) {
1695 client.ca_bundle.rescan(client.allocator, io) catch
1696 if (client.now == null) {
1697 const now = try Io.Clock.real.now(io);
1698 client.now = now;
1699 client.ca_bundle.rescan(client.allocator, io, now) catch
16961700 return error.CertificateBundleLoadFailure;
1697 @atomicStore(bool, &client.next_https_rescan_certs, false, .release);
16981701 }
16991702 }
17001703 }
lib/std/http/Server.zig+4-4
......@@ -688,7 +688,7 @@ pub const WebSocket = struct {
688688 pub const ReadSmallTextMessageError = error{
689689 ConnectionClose,
690690 UnexpectedOpCode,
691 MessageTooBig,
691 MessageOversize,
692692 MissingMaskBit,
693693 ReadFailed,
694694 EndOfStream,
......@@ -717,15 +717,15 @@ pub const WebSocket = struct {
717717 _ => return error.UnexpectedOpCode,
718718 }
719719
720 if (!h0.fin) return error.MessageTooBig;
720 if (!h0.fin) return error.MessageOversize;
721721 if (!h1.mask) return error.MissingMaskBit;
722722
723723 const len: usize = switch (h1.payload_len) {
724724 .len16 => try in.takeInt(u16, .big),
725 .len64 => std.math.cast(usize, try in.takeInt(u64, .big)) orelse return error.MessageTooBig,
725 .len64 => std.math.cast(usize, try in.takeInt(u64, .big)) orelse return error.MessageOversize,
726726 else => @intFromEnum(h1.payload_len),
727727 };
728 if (len > in.buffer.len) return error.MessageTooBig;
728 if (len > in.buffer.len) return error.MessageOversize;
729729 const mask: u32 = @bitCast((try in.takeArray(4)).*);
730730 const payload = try in.take(len);
731731
lib/std/os/windows.zig+1-1
......@@ -1653,7 +1653,7 @@ pub fn WSASocketW(
16531653 const rc = ws2_32.WSASocketW(af, socket_type, protocol, protocolInfo, g, dwFlags);
16541654 if (rc == ws2_32.INVALID_SOCKET) {
16551655 switch (ws2_32.WSAGetLastError()) {
1656 .WSAEAFNOSUPPORT => return error.AddressFamilyNotSupported,
1656 .WSAEAFNOSUPPORT => return error.AddressFamilyUnsupported,
16571657 .WSAEMFILE => return error.ProcessFdQuotaExceeded,
16581658 .WSAENOBUFS => return error.SystemResources,
16591659 .WSAEPROTONOSUPPORT => return error.ProtocolNotSupported,
lib/std/posix.zig+26-26
......@@ -1205,7 +1205,7 @@ pub const WriteError = error{
12051205
12061206 /// The socket type requires that message be sent atomically, and the size of the message
12071207 /// to be sent made this impossible. The message is not transmitted.
1208 MessageTooBig,
1208 MessageOversize,
12091209} || UnexpectedError;
12101210
12111211/// Write to a file descriptor.
......@@ -1287,7 +1287,7 @@ pub fn write(fd: fd_t, bytes: []const u8) WriteError!usize {
12871287 .CONNRESET => return error.ConnectionResetByPeer,
12881288 .BUSY => return error.DeviceBusy,
12891289 .NXIO => return error.NoDevice,
1290 .MSGSIZE => return error.MessageTooBig,
1290 .MSGSIZE => return error.MessageOversize,
12911291 else => |err| return unexpectedErrno(err),
12921292 }
12931293 }
......@@ -3487,7 +3487,7 @@ pub const SocketError = error{
34873487 AccessDenied,
34883488
34893489 /// The implementation does not support the specified address family.
3490 AddressFamilyNotSupported,
3490 AddressFamilyUnsupported,
34913491
34923492 /// Unknown protocol, or protocol family not available.
34933493 ProtocolFamilyNotAvailable,
......@@ -3553,7 +3553,7 @@ pub fn socket(domain: u32, socket_type: u32, protocol: u32) SocketError!socket_t
35533553 return fd;
35543554 },
35553555 .ACCES => return error.AccessDenied,
3556 .AFNOSUPPORT => return error.AddressFamilyNotSupported,
3556 .AFNOSUPPORT => return error.AddressFamilyUnsupported,
35573557 .INVAL => return error.ProtocolFamilyNotAvailable,
35583558 .MFILE => return error.ProcessFdQuotaExceeded,
35593559 .NFILE => return error.SystemFdQuotaExceeded,
......@@ -3593,7 +3593,7 @@ pub fn socketpair(domain: u32, socket_type: u32, protocol: u32) SocketError![2]s
35933593 return socks;
35943594 },
35953595 .ACCES => return error.AccessDenied,
3596 .AFNOSUPPORT => return error.AddressFamilyNotSupported,
3596 .AFNOSUPPORT => return error.AddressFamilyUnsupported,
35973597 .INVAL => return error.ProtocolFamilyNotAvailable,
35983598 .MFILE => return error.ProcessFdQuotaExceeded,
35993599 .NFILE => return error.SystemFdQuotaExceeded,
......@@ -3676,7 +3676,7 @@ pub const BindError = error{
36763676 AddressNotAvailable,
36773677
36783678 /// The address is not valid for the address family of socket.
3679 AddressFamilyNotSupported,
3679 AddressFamilyUnsupported,
36803680
36813681 /// Too many symbolic links were encountered in resolving addr.
36823682 SymLinkLoop,
......@@ -3733,7 +3733,7 @@ pub fn bind(sock: socket_t, addr: *const sockaddr, len: socklen_t) BindError!voi
37333733 .BADF => unreachable, // always a race condition if this error is returned
37343734 .INVAL => unreachable, // invalid parameters
37353735 .NOTSOCK => unreachable, // invalid `sockfd`
3736 .AFNOSUPPORT => return error.AddressFamilyNotSupported,
3736 .AFNOSUPPORT => return error.AddressFamilyUnsupported,
37373737 .ADDRNOTAVAIL => return error.AddressNotAvailable,
37383738 .FAULT => unreachable, // invalid `addr` pointer
37393739 .LOOP => return error.SymLinkLoop,
......@@ -4192,7 +4192,7 @@ pub const ConnectError = error{
41924192 AddressNotAvailable,
41934193
41944194 /// The passed address didn't have the correct address family in its sa_family field.
4195 AddressFamilyNotSupported,
4195 AddressFamilyUnsupported,
41964196
41974197 /// Insufficient entries in the routing cache.
41984198 SystemResources,
......@@ -4247,7 +4247,7 @@ pub fn connect(sock: socket_t, sock_addr: *const sockaddr, len: socklen_t) Conne
42474247 .WSAEWOULDBLOCK => return error.WouldBlock,
42484248 .WSAEACCES => unreachable,
42494249 .WSAENOBUFS => return error.SystemResources,
4250 .WSAEAFNOSUPPORT => return error.AddressFamilyNotSupported,
4250 .WSAEAFNOSUPPORT => return error.AddressFamilyUnsupported,
42514251 else => |err| return windows.unexpectedWSAError(err),
42524252 }
42534253 return;
......@@ -4260,7 +4260,7 @@ pub fn connect(sock: socket_t, sock_addr: *const sockaddr, len: socklen_t) Conne
42604260 .PERM => return error.PermissionDenied,
42614261 .ADDRINUSE => return error.AddressInUse,
42624262 .ADDRNOTAVAIL => return error.AddressNotAvailable,
4263 .AFNOSUPPORT => return error.AddressFamilyNotSupported,
4263 .AFNOSUPPORT => return error.AddressFamilyUnsupported,
42644264 .AGAIN, .INPROGRESS => return error.WouldBlock,
42654265 .ALREADY => return error.ConnectionPending,
42664266 .BADF => unreachable, // sockfd is not a valid open file descriptor.
......@@ -4322,7 +4322,7 @@ pub fn getsockoptError(sockfd: fd_t) ConnectError!void {
43224322 .PERM => return error.PermissionDenied,
43234323 .ADDRINUSE => return error.AddressInUse,
43244324 .ADDRNOTAVAIL => return error.AddressNotAvailable,
4325 .AFNOSUPPORT => return error.AddressFamilyNotSupported,
4325 .AFNOSUPPORT => return error.AddressFamilyUnsupported,
43264326 .AGAIN => return error.SystemResources,
43274327 .ALREADY => return error.ConnectionPending,
43284328 .BADF => unreachable, // sockfd is not a valid open file descriptor.
......@@ -6039,7 +6039,7 @@ pub const SendError = error{
60396039
60406040 /// The socket type requires that message be sent atomically, and the size of the message
60416041 /// to be sent made this impossible. The message is not transmitted.
6042 MessageTooBig,
6042 MessageOversize,
60436043
60446044 /// The output queue for a network interface was full. This generally indicates that the
60456045 /// interface has stopped sending, but may be caused by transient congestion. (Normally,
......@@ -6066,7 +6066,7 @@ pub const SendError = error{
60666066
60676067pub const SendMsgError = SendError || error{
60686068 /// The passed address didn't have the correct address family in its sa_family field.
6069 AddressFamilyNotSupported,
6069 AddressFamilyUnsupported,
60706070
60716071 /// Returned when socket is AF.UNIX and the given path has a symlink loop.
60726072 SymLinkLoop,
......@@ -6098,10 +6098,10 @@ pub fn sendmsg(
60986098 .WSAEACCES => return error.AccessDenied,
60996099 .WSAEADDRNOTAVAIL => return error.AddressNotAvailable,
61006100 .WSAECONNRESET => return error.ConnectionResetByPeer,
6101 .WSAEMSGSIZE => return error.MessageTooBig,
6101 .WSAEMSGSIZE => return error.MessageOversize,
61026102 .WSAENOBUFS => return error.SystemResources,
61036103 .WSAENOTSOCK => return error.FileDescriptorNotASocket,
6104 .WSAEAFNOSUPPORT => return error.AddressFamilyNotSupported,
6104 .WSAEAFNOSUPPORT => return error.AddressFamilyUnsupported,
61056105 .WSAEDESTADDRREQ => unreachable, // A destination address is required.
61066106 .WSAEFAULT => unreachable, // The lpBuffers, lpTo, lpOverlapped, lpNumberOfBytesSent, or lpCompletionRoutine parameters are not part of the user address space, or the lpTo parameter is too small.
61076107 .WSAEHOSTUNREACH => return error.NetworkUnreachable,
......@@ -6133,13 +6133,13 @@ pub fn sendmsg(
61336133 .INTR => continue,
61346134 .INVAL => unreachable, // Invalid argument passed.
61356135 .ISCONN => unreachable, // connection-mode socket was connected already but a recipient was specified
6136 .MSGSIZE => return error.MessageTooBig,
6136 .MSGSIZE => return error.MessageOversize,
61376137 .NOBUFS => return error.SystemResources,
61386138 .NOMEM => return error.SystemResources,
61396139 .NOTSOCK => unreachable, // The file descriptor sockfd does not refer to a socket.
61406140 .OPNOTSUPP => unreachable, // Some bit in the flags argument is inappropriate for the socket type.
61416141 .PIPE => return error.BrokenPipe,
6142 .AFNOSUPPORT => return error.AddressFamilyNotSupported,
6142 .AFNOSUPPORT => return error.AddressFamilyUnsupported,
61436143 .LOOP => return error.SymLinkLoop,
61446144 .NAMETOOLONG => return error.NameTooLong,
61456145 .NOENT => return error.FileNotFound,
......@@ -6178,7 +6178,7 @@ pub const SendToError = SendMsgError || error{
61786178/// Otherwise, the address of the target is given by `dest_addr` with `addrlen` specifying its size.
61796179///
61806180/// If the message is too long to pass atomically through the underlying protocol,
6181/// `SendError.MessageTooBig` is returned, and the message is not transmitted.
6181/// `SendError.MessageOversize` is returned, and the message is not transmitted.
61826182///
61836183/// There is no indication of failure to deliver.
61846184///
......@@ -6201,10 +6201,10 @@ pub fn sendto(
62016201 .WSAEACCES => return error.AccessDenied,
62026202 .WSAEADDRNOTAVAIL => return error.AddressNotAvailable,
62036203 .WSAECONNRESET => return error.ConnectionResetByPeer,
6204 .WSAEMSGSIZE => return error.MessageTooBig,
6204 .WSAEMSGSIZE => return error.MessageOversize,
62056205 .WSAENOBUFS => return error.SystemResources,
62066206 .WSAENOTSOCK => return error.FileDescriptorNotASocket,
6207 .WSAEAFNOSUPPORT => return error.AddressFamilyNotSupported,
6207 .WSAEAFNOSUPPORT => return error.AddressFamilyUnsupported,
62086208 .WSAEDESTADDRREQ => unreachable, // A destination address is required.
62096209 .WSAEFAULT => unreachable, // The lpBuffers, lpTo, lpOverlapped, lpNumberOfBytesSent, or lpCompletionRoutine parameters are not part of the user address space, or the lpTo parameter is too small.
62106210 .WSAEHOSTUNREACH => return error.NetworkUnreachable,
......@@ -6238,13 +6238,13 @@ pub fn sendto(
62386238 .INTR => continue,
62396239 .INVAL => return error.UnreachableAddress,
62406240 .ISCONN => unreachable, // connection-mode socket was connected already but a recipient was specified
6241 .MSGSIZE => return error.MessageTooBig,
6241 .MSGSIZE => return error.MessageOversize,
62426242 .NOBUFS => return error.SystemResources,
62436243 .NOMEM => return error.SystemResources,
62446244 .NOTSOCK => unreachable, // The file descriptor sockfd does not refer to a socket.
62456245 .OPNOTSUPP => unreachable, // Some bit in the flags argument is inappropriate for the socket type.
62466246 .PIPE => return error.BrokenPipe,
6247 .AFNOSUPPORT => return error.AddressFamilyNotSupported,
6247 .AFNOSUPPORT => return error.AddressFamilyUnsupported,
62486248 .LOOP => return error.SymLinkLoop,
62496249 .NAMETOOLONG => return error.NameTooLong,
62506250 .NOENT => return error.FileNotFound,
......@@ -6284,7 +6284,7 @@ pub fn send(
62846284 flags: u32,
62856285) SendError!usize {
62866286 return sendto(sockfd, buf, flags, null, 0) catch |err| switch (err) {
6287 error.AddressFamilyNotSupported => unreachable,
6287 error.AddressFamilyUnsupported => unreachable,
62886288 error.SymLinkLoop => unreachable,
62896289 error.NameTooLong => unreachable,
62906290 error.FileNotFound => unreachable,
......@@ -6471,7 +6471,7 @@ pub const RecvFromError = error{
64716471 SocketNotBound,
64726472
64736473 /// The UDP message was too big for the buffer and part of it has been discarded
6474 MessageTooBig,
6474 MessageOversize,
64756475
64766476 /// The network subsystem has failed.
64776477 NetworkDown,
......@@ -6504,7 +6504,7 @@ pub fn recvfrom(
65046504 .WSANOTINITIALISED => unreachable,
65056505 .WSAECONNRESET => return error.ConnectionResetByPeer,
65066506 .WSAEINVAL => return error.SocketNotBound,
6507 .WSAEMSGSIZE => return error.MessageTooBig,
6507 .WSAEMSGSIZE => return error.MessageOversize,
65086508 .WSAENETDOWN => return error.NetworkDown,
65096509 .WSAENOTCONN => return error.SocketUnconnected,
65106510 .WSAEWOULDBLOCK => return error.WouldBlock,
......@@ -6575,7 +6575,7 @@ pub fn recvmsg(
65756575 .NOMEM => return error.SystemResources,
65766576 .NOTCONN => return error.SocketUnconnected,
65776577 .NOTSOCK => unreachable, // The file descriptor sockfd does not refer to a socket.
6578 .MSGSIZE => return error.MessageTooBig,
6578 .MSGSIZE => return error.MessageOversize,
65796579 .PIPE => return error.BrokenPipe,
65806580 .OPNOTSUPP => unreachable, // Some bit in the flags argument is inappropriate for the socket type.
65816581 .CONNRESET => return error.ConnectionResetByPeer,