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....@@ -1469,7 +1469,7 @@ fn pwrite(userdata: ?*anyopaque, file: Io.File, buffer: []const u8, offset: std.
1469 .OVERFLOW => return error.Unseekable,1469 .OVERFLOW => return error.Unseekable,
1470 .BUSY => return error.DeviceBusy,1470 .BUSY => return error.DeviceBusy,
1471 .CONNRESET => return error.ConnectionResetByPeer,1471 .CONNRESET => return error.ConnectionResetByPeer,
1472 .MSGSIZE => return error.MessageTooBig,1472 .MSGSIZE => return error.MessageOversize,
1473 else => |err| return std.posix.unexpectedErrno(err),1473 else => |err| return std.posix.unexpectedErrno(err),
1474 }1474 }
1475}1475}
lib/std/Io/Threaded.zig+50-32
...@@ -966,7 +966,7 @@ fn dirStatPathPosix(...@@ -966,7 +966,7 @@ fn dirStatPathPosix(
966 try t.checkCancel();966 try t.checkCancel();
967 var stat = std.mem.zeroes(posix.Stat);967 var stat = std.mem.zeroes(posix.Stat);
968 switch (posix.errno(fstatat_sym(dir.handle, sub_path_posix, &stat, flags))) {968 switch (posix.errno(fstatat_sym(dir.handle, sub_path_posix, &stat, flags))) {
969 .SUCCESS => return statFromPosix(stat),969 .SUCCESS => return statFromPosix(&stat),
970 .INTR => continue,970 .INTR => continue,
971 .INVAL => |err| return errnoBug(err),971 .INVAL => |err| return errnoBug(err),
972 .BADF => |err| return errnoBug(err), // Always a race condition.972 .BADF => |err| return errnoBug(err), // Always a race condition.
...@@ -1166,8 +1166,9 @@ fn dirCreateFilePosix(...@@ -1166,8 +1166,9 @@ fn dirCreateFilePosix(
1166 if (has_flock_open_flags and flags.lock_nonblocking) {1166 if (has_flock_open_flags and flags.lock_nonblocking) {
1167 var fl_flags: usize = while (true) {1167 var fl_flags: usize = while (true) {
1168 try t.checkCancel();1168 try t.checkCancel();
1169 switch (posix.errno(posix.system.fcntl(fd, posix.F.GETFL, 0))) {1169 const rc = posix.system.fcntl(fd, posix.F.GETFL, @as(usize, 0));
1170 .SUCCESS => break,1170 switch (posix.errno(rc)) {
1171 .SUCCESS => break @intCast(rc),
1171 .INTR => continue,1172 .INTR => continue,
1172 else => |err| return posix.unexpectedErrno(err),1173 else => |err| return posix.unexpectedErrno(err),
1173 }1174 }
...@@ -1295,8 +1296,9 @@ fn dirOpenFile(...@@ -1295,8 +1296,9 @@ fn dirOpenFile(
1295 if (has_flock_open_flags and flags.lock_nonblocking) {1296 if (has_flock_open_flags and flags.lock_nonblocking) {
1296 var fl_flags: usize = while (true) {1297 var fl_flags: usize = while (true) {
1297 try t.checkCancel();1298 try t.checkCancel();
1298 switch (posix.errno(posix.system.fcntl(fd, posix.F.GETFL, 0))) {1299 const rc = posix.system.fcntl(fd, posix.F.GETFL, @as(usize, 0));
1299 .SUCCESS => break,1300 switch (posix.errno(rc)) {
1301 .SUCCESS => break @intCast(rc),
1300 .INTR => continue,1302 .INTR => continue,
1301 else => |err| return posix.unexpectedErrno(err),1303 else => |err| return posix.unexpectedErrno(err),
1302 }1304 }
...@@ -1755,7 +1757,7 @@ fn sleepPosix(userdata: ?*anyopaque, timeout: Io.Timeout) Io.SleepError!void {...@@ -1755,7 +1757,7 @@ fn sleepPosix(userdata: ?*anyopaque, timeout: Io.Timeout) Io.SleepError!void {
1755 .sec = std.math.maxInt(sec_type),1757 .sec = std.math.maxInt(sec_type),
1756 .nsec = std.math.maxInt(nsec_type),1758 .nsec = std.math.maxInt(nsec_type),
1757 };1759 };
1758 break :t timestampToPosix(d.duration.nanoseconds);1760 break :t timestampToPosix(d.raw.toNanoseconds());
1759 };1761 };
1760 while (true) {1762 while (true) {
1761 try t.checkCancel();1763 try t.checkCancel();
...@@ -1850,6 +1852,7 @@ fn netListenUnix(...@@ -1850,6 +1852,7 @@ fn netListenUnix(
1850 error.ProtocolUnsupportedBySystem => return error.AddressFamilyUnsupported,1852 error.ProtocolUnsupportedBySystem => return error.AddressFamilyUnsupported,
1851 error.ProtocolUnsupportedByAddressFamily => return error.AddressFamilyUnsupported,1853 error.ProtocolUnsupportedByAddressFamily => return error.AddressFamilyUnsupported,
1852 error.SocketModeUnsupported => return error.AddressFamilyUnsupported,1854 error.SocketModeUnsupported => return error.AddressFamilyUnsupported,
1855 error.OptionUnsupported => return error.Unexpected,
1853 else => |e| return e,1856 else => |e| return e,
1854 };1857 };
1855 errdefer posix.close(socket_fd);1858 errdefer posix.close(socket_fd);
...@@ -2037,7 +2040,10 @@ fn netConnectUnix(...@@ -2037,7 +2040,10 @@ fn netConnectUnix(
2037) net.UnixAddress.ConnectError!net.Socket.Handle {2040) net.UnixAddress.ConnectError!net.Socket.Handle {
2038 if (!net.has_unix_sockets) return error.AddressFamilyUnsupported;2041 if (!net.has_unix_sockets) return error.AddressFamilyUnsupported;
2039 const t: *Threaded = @ptrCast(@alignCast(userdata));2042 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 };
2041 errdefer posix.close(socket_fd);2047 errdefer posix.close(socket_fd);
2042 var storage: UnixAddress = undefined;2048 var storage: UnixAddress = undefined;
2043 const addr_len = addressUnixToPosix(address, &storage);2049 const addr_len = addressUnixToPosix(address, &storage);
...@@ -2064,7 +2070,22 @@ fn netBindIpPosix(...@@ -2064,7 +2070,22 @@ fn netBindIpPosix(
2064 };2070 };
2065}2071}
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 {
2068 const mode = posixSocketMode(options.mode);2089 const mode = posixSocketMode(options.mode);
2069 const protocol = posixProtocol(options.protocol);2090 const protocol = posixProtocol(options.protocol);
2070 const socket_fd = while (true) {2091 const socket_fd = while (true) {
...@@ -2209,7 +2230,7 @@ fn netReadPosix(userdata: ?*anyopaque, fd: net.Socket.Handle, data: [][]u8) net....@@ -2209,7 +2230,7 @@ fn netReadPosix(userdata: ?*anyopaque, fd: net.Socket.Handle, data: [][]u8) net.
2209 .NOTCONN => return error.SocketUnconnected,2230 .NOTCONN => return error.SocketUnconnected,
2210 .CONNRESET => return error.ConnectionResetByPeer,2231 .CONNRESET => return error.ConnectionResetByPeer,
2211 .TIMEDOUT => return error.Timeout,2232 .TIMEDOUT => return error.Timeout,
2212 .PIPE => return error.BrokenPipe,2233 .PIPE => return error.SocketUnconnected,
2213 .NETDOWN => return error.NetworkDown,2234 .NETDOWN => return error.NetworkDown,
2214 else => |err| return posix.unexpectedErrno(err),2235 else => |err| return posix.unexpectedErrno(err),
2215 }2236 }
...@@ -2253,29 +2274,29 @@ fn netSendOne(...@@ -2253,29 +2274,29 @@ fn netSendOne(
2253 flags: u32,2274 flags: u32,
2254) net.Socket.SendError!void {2275) net.Socket.SendError!void {
2255 var addr: PosixAddress = undefined;2276 var addr: PosixAddress = undefined;
2256 var iovec: posix.iovec = .{ .base = @constCast(message.data_ptr), .len = message.data_len };2277 var iovec: posix.iovec_const = .{ .base = @constCast(message.data_ptr), .len = message.data_len };
2257 const msg: posix.msghdr = .{2278 const msg: posix.msghdr_const = .{
2258 .name = &addr.any,2279 .name = &addr.any,
2259 .namelen = addressToPosix(message.address, &addr),2280 .namelen = addressToPosix(message.address, &addr),
2260 .iov = iovec[0..1],2281 .iov = (&iovec)[0..1],
2261 .iovlen = 1,2282 .iovlen = 1,
2262 .control = @constCast(message.control.ptr),2283 .control = @constCast(message.control.ptr),
2263 .controllen = message.control.len,2284 .controllen = @intCast(message.control.len),
2264 .flags = 0,2285 .flags = 0,
2265 };2286 };
2266 while (true) {2287 while (true) {
2267 try t.checkCancel();2288 try t.checkCancel();
2268 const rc = posix.system.sendmsg(handle, msg, flags);2289 const rc = posix.system.sendmsg(handle, &msg, flags);
2269 if (is_windows) {2290 if (is_windows) {
2270 if (rc == windows.ws2_32.SOCKET_ERROR) {2291 if (rc == windows.ws2_32.SOCKET_ERROR) {
2271 switch (windows.ws2_32.WSAGetLastError()) {2292 switch (windows.ws2_32.WSAGetLastError()) {
2272 .WSAEACCES => return error.AccessDenied,2293 .WSAEACCES => return error.AccessDenied,
2273 .WSAEADDRNOTAVAIL => return error.AddressNotAvailable,2294 .WSAEADDRNOTAVAIL => return error.AddressNotAvailable,
2274 .WSAECONNRESET => return error.ConnectionResetByPeer,2295 .WSAECONNRESET => return error.ConnectionResetByPeer,
2275 .WSAEMSGSIZE => return error.MessageTooBig,2296 .WSAEMSGSIZE => return error.MessageOversize,
2276 .WSAENOBUFS => return error.SystemResources,2297 .WSAENOBUFS => return error.SystemResources,
2277 .WSAENOTSOCK => return error.FileDescriptorNotASocket,2298 .WSAENOTSOCK => return error.FileDescriptorNotASocket,
2278 .WSAEAFNOSUPPORT => return error.AddressFamilyNotSupported,2299 .WSAEAFNOSUPPORT => return error.AddressFamilyUnsupported,
2279 .WSAEDESTADDRREQ => unreachable, // A destination address is required.2300 .WSAEDESTADDRREQ => unreachable, // A destination address is required.
2280 .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.2301 .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.
2281 .WSAEHOSTUNREACH => return error.NetworkUnreachable,2302 .WSAEHOSTUNREACH => return error.NetworkUnreachable,
...@@ -2285,7 +2306,6 @@ fn netSendOne(...@@ -2285,7 +2306,6 @@ fn netSendOne(
2285 .WSAENETUNREACH => return error.NetworkUnreachable,2306 .WSAENETUNREACH => return error.NetworkUnreachable,
2286 .WSAENOTCONN => return error.SocketUnconnected,2307 .WSAENOTCONN => return error.SocketUnconnected,
2287 .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.2308 .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,
2289 .WSANOTINITIALISED => unreachable, // A successful WSAStartup call must occur before using this function.2309 .WSANOTINITIALISED => unreachable, // A successful WSAStartup call must occur before using this function.
2290 else => |err| return windows.unexpectedWSAError(err),2310 else => |err| return windows.unexpectedWSAError(err),
2291 }2311 }
...@@ -2299,28 +2319,24 @@ fn netSendOne(...@@ -2299,28 +2319,24 @@ fn netSendOne(
2299 message.data_len = @intCast(rc);2319 message.data_len = @intCast(rc);
2300 return;2320 return;
2301 },2321 },
2322 .INTR => continue,
2323
2302 .ACCES => return error.AccessDenied,2324 .ACCES => return error.AccessDenied,
2303 .AGAIN => return error.WouldBlock,
2304 .ALREADY => return error.FastOpenAlreadyInProgress,2325 .ALREADY => return error.FastOpenAlreadyInProgress,
2305 .BADF => |err| return errnoBug(err),2326 .BADF => |err| return errnoBug(err),
2306 .CONNRESET => return error.ConnectionResetByPeer,2327 .CONNRESET => return error.ConnectionResetByPeer,
2307 .DESTADDRREQ => |err| return errnoBug(err),2328 .DESTADDRREQ => |err| return errnoBug(err),
2308 .FAULT => |err| return errnoBug(err),2329 .FAULT => |err| return errnoBug(err),
2309 .INTR => continue,
2310 .INVAL => |err| return errnoBug(err),2330 .INVAL => |err| return errnoBug(err),
2311 .ISCONN => |err| return errnoBug(err),2331 .ISCONN => |err| return errnoBug(err),
2312 .MSGSIZE => return error.MessageTooBig,2332 .MSGSIZE => return error.MessageOversize,
2313 .NOBUFS => return error.SystemResources,2333 .NOBUFS => return error.SystemResources,
2314 .NOMEM => return error.SystemResources,2334 .NOMEM => return error.SystemResources,
2315 .NOTSOCK => |err| return errnoBug(err),2335 .NOTSOCK => |err| return errnoBug(err),
2316 .OPNOTSUPP => |err| return errnoBug(err),2336 .OPNOTSUPP => |err| return errnoBug(err),
2317 .PIPE => return error.BrokenPipe,2337 .PIPE => return error.SocketUnconnected,
2318 .AFNOSUPPORT => return error.AddressFamilyNotSupported,2338 .AFNOSUPPORT => return error.AddressFamilyUnsupported,
2319 .LOOP => return error.SymLinkLoop,2339 .HOSTUNREACH => return error.HostUnreachable,
2320 .NAMETOOLONG => return error.NameTooLong,
2321 .NOENT => return error.FileNotFound,
2322 .NOTDIR => return error.NotDir,
2323 .HOSTUNREACH => return error.NetworkUnreachable,
2324 .NETUNREACH => return error.NetworkUnreachable,2340 .NETUNREACH => return error.NetworkUnreachable,
2325 .NOTCONN => return error.SocketUnconnected,2341 .NOTCONN => return error.SocketUnconnected,
2326 .NETDOWN => return error.NetworkDown,2342 .NETDOWN => return error.NetworkDown,
...@@ -2447,7 +2463,7 @@ fn netReceive(...@@ -2447,7 +2463,7 @@ fn netReceive(
2447 .iov = (&iov)[0..1],2463 .iov = (&iov)[0..1],
2448 .iovlen = 1,2464 .iovlen = 1,
2449 .control = message.control.ptr,2465 .control = message.control.ptr,
2450 .controllen = message.control.len,2466 .controllen = @intCast(message.control.len),
2451 .flags = undefined,2467 .flags = undefined,
2452 };2468 };
24532469
...@@ -2465,7 +2481,7 @@ fn netReceive(...@@ -2465,7 +2481,7 @@ fn netReceive(
2465 .trunc = (msg.flags & posix.MSG.TRUNC) != 0,2481 .trunc = (msg.flags & posix.MSG.TRUNC) != 0,
2466 .ctrunc = (msg.flags & posix.MSG.CTRUNC) != 0,2482 .ctrunc = (msg.flags & posix.MSG.CTRUNC) != 0,
2467 .oob = (msg.flags & posix.MSG.OOB) != 0,2483 .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,
2469 },2485 },
2470 };2486 };
2471 message_i += 1;2487 message_i += 1;
...@@ -2605,6 +2621,7 @@ fn netInterfaceNameResolve(...@@ -2605,6 +2621,7 @@ fn netInterfaceNameResolve(
2605 error.ProtocolUnsupportedBySystem => return error.Unexpected,2621 error.ProtocolUnsupportedBySystem => return error.Unexpected,
2606 error.ProtocolUnsupportedByAddressFamily => return error.Unexpected,2622 error.ProtocolUnsupportedByAddressFamily => return error.Unexpected,
2607 error.SocketModeUnsupported => return error.Unexpected,2623 error.SocketModeUnsupported => return error.Unexpected,
2624 error.OptionUnsupported => return error.Unexpected,
2608 else => |e| return e,2625 else => |e| return e,
2609 };2626 };
2610 defer posix.close(sock_fd);2627 defer posix.close(sock_fd);
...@@ -3079,9 +3096,10 @@ fn lookupDns(...@@ -3079,9 +3096,10 @@ fn lookupDns(
3079 }3096 }
3080 }3097 }
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];
3083 var any_ip6 = false;3101 var any_ip6 = false;
3084 for (rc.nameservers(), &ip4_mapped) |*ns, *m| {3102 for (rc.nameservers(), ip4_mapped) |*ns, *m| {
3085 m.* = .{ .ip6 = .fromAny(ns.*) };3103 m.* = .{ .ip6 = .fromAny(ns.*) };
3086 any_ip6 = any_ip6 or ns.* == .ip6;3104 any_ip6 = any_ip6 or ns.* == .ip6;
3087 }3105 }
...@@ -3101,7 +3119,7 @@ fn lookupDns(...@@ -3101,7 +3119,7 @@ fn lookupDns(
3101 };3119 };
3102 defer socket.close(t_io);3120 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();
3105 const queries = queries_buffer[0..nq];3123 const queries = queries_buffer[0..nq];
3106 const answers = answers_buffer[0..queries.len];3124 const answers = answers_buffer[0..queries.len];
3107 var answers_remaining = answers.len;3125 var answers_remaining = answers.len;
lib/std/Io/net.zig+7-2
...@@ -209,6 +209,9 @@ pub const IpAddress = union(enum) {...@@ -209,6 +209,9 @@ pub const IpAddress = union(enum) {
209 ProtocolUnsupportedBySystem,209 ProtocolUnsupportedBySystem,
210 ProtocolUnsupportedByAddressFamily,210 ProtocolUnsupportedByAddressFamily,
211 SocketModeUnsupported,211 SocketModeUnsupported,
212 /// One of the `ListenOptions` is not supported by the Io
213 /// implementation.
214 OptionUnsupported,
212 } || Io.UnexpectedError || Io.Cancelable;215 } || Io.UnexpectedError || Io.Cancelable;
213216
214 pub const ListenOptions = struct {217 pub const ListenOptions = struct {
...@@ -1057,6 +1060,9 @@ pub const Socket = struct {...@@ -1057,6 +1060,9 @@ pub const Socket = struct {
1057 /// Local end has been shut down on a connection-oriented socket, or1060 /// Local end has been shut down on a connection-oriented socket, or
1058 /// the socket was never connected.1061 /// the socket was never connected.
1059 SocketUnconnected,1062 SocketUnconnected,
1063 /// An attempt was made to send to a network/broadcast address as
1064 /// though it was a unicast address.
1065 AccessDenied,
1060 } || Io.UnexpectedError || Io.Cancelable;1066 } || Io.UnexpectedError || Io.Cancelable;
10611067
1062 /// Transfers `data` to `dest`, connectionless, in one packet.1068 /// Transfers `data` to `dest`, connectionless, in one packet.
...@@ -1167,7 +1173,6 @@ pub const Stream = struct {...@@ -1167,7 +1173,6 @@ pub const Stream = struct {
11671173
1168 pub const Error = error{1174 pub const Error = error{
1169 SystemResources,1175 SystemResources,
1170 BrokenPipe,
1171 ConnectionResetByPeer,1176 ConnectionResetByPeer,
1172 Timeout,1177 Timeout,
1173 SocketUnconnected,1178 SocketUnconnected,
...@@ -1233,7 +1238,7 @@ pub const Stream = struct {...@@ -1233,7 +1238,7 @@ pub const Stream = struct {
1233 pub const Error = std.posix.SendMsgError || error{1238 pub const Error = std.posix.SendMsgError || error{
1234 ConnectionResetByPeer,1239 ConnectionResetByPeer,
1235 SocketNotBound,1240 SocketNotBound,
1236 MessageTooBig,1241 MessageOversize,
1237 NetworkDown,1242 NetworkDown,
1238 SystemResources,1243 SystemResources,
1239 SocketUnconnected,1244 SocketUnconnected,
lib/std/c.zig+1-1
...@@ -4104,7 +4104,7 @@ pub const msghdr = switch (native_os) {...@@ -4104,7 +4104,7 @@ pub const msghdr = switch (native_os) {
4104 .visionos,4104 .visionos,
4105 .watchos,4105 .watchos,
4106 .serenity, // https://github.com/SerenityOS/serenity/blob/ac44ec5ebc707f9dd0c3d4759a1e17e91db5d74f/Kernel/API/POSIX/sys/socket.h#L74-L824106 .serenity, // https://github.com/SerenityOS/serenity/blob/ac44ec5ebc707f9dd0c3d4759a1e17e91db5d74f/Kernel/API/POSIX/sys/socket.h#L74-L82
4107 => private.posix_msghdr,4107 => posix_msghdr,
4108 else => void,4108 else => void,
4109};4109};
41104110
lib/std/crypto/Certificate/Bundle.zig+24-21
...@@ -70,18 +70,18 @@ pub const RescanError = RescanLinuxError || RescanMacError || RescanWithPathErro...@@ -70,18 +70,18 @@ pub const RescanError = RescanLinuxError || RescanMacError || RescanWithPathErro
70/// file system standard locations for certificates.70/// file system standard locations for certificates.
71/// For operating systems that do not have standard CA installations to be71/// For operating systems that do not have standard CA installations to be
72/// found, this function clears the set of certificates.72/// 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 {
74 switch (builtin.os.tag) {74 switch (builtin.os.tag) {
75 .linux => return rescanLinux(cb, gpa, io),75 .linux => return rescanLinux(cb, gpa, io, now),
76 .macos => return rescanMac(cb, gpa),76 .macos => return rescanMac(cb, gpa, io, now),
77 .freebsd, .openbsd => return rescanWithPath(cb, gpa, io, "/etc/ssl/cert.pem"),77 .freebsd, .openbsd => return rescanWithPath(cb, gpa, io, now, "/etc/ssl/cert.pem"),
78 .netbsd => return rescanWithPath(cb, gpa, io, "/etc/openssl/certs/ca-certificates.crt"),78 .netbsd => return rescanWithPath(cb, gpa, io, now, "/etc/openssl/certs/ca-certificates.crt"),
79 .dragonfly => return rescanWithPath(cb, gpa, io, "/usr/local/etc/ssl/cert.pem"),79 .dragonfly => return rescanWithPath(cb, gpa, io, now, "/usr/local/etc/ssl/cert.pem"),
80 .illumos => return rescanWithPath(cb, gpa, io, "/etc/ssl/cacert.pem"),80 .illumos => return rescanWithPath(cb, gpa, io, now, "/etc/ssl/cacert.pem"),
81 .haiku => return rescanWithPath(cb, gpa, io, "/boot/system/data/ssl/CARootCertificates.pem"),81 .haiku => return rescanWithPath(cb, gpa, io, now, "/boot/system/data/ssl/CARootCertificates.pem"),
82 // https://github.com/SerenityOS/serenity/blob/222acc9d389bc6b490d4c39539761b043a4bfcb0/Ports/ca-certificates/package.sh#L1982 // 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"),83 .serenity => return rescanWithPath(cb, gpa, io, now, "/etc/ssl/certs/ca-certificates.crt"),
84 .windows => return rescanWindows(cb, gpa),84 .windows => return rescanWindows(cb, gpa, io, now),
85 else => {},85 else => {},
86 }86 }
87}87}
...@@ -91,7 +91,7 @@ const RescanMacError = @import("Bundle/macos.zig").RescanMacError;...@@ -91,7 +91,7 @@ const RescanMacError = @import("Bundle/macos.zig").RescanMacError;
9191
92const RescanLinuxError = AddCertsFromFilePathError || AddCertsFromDirPathError;92const 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 {
95 // Possible certificate files; stop after finding one.95 // Possible certificate files; stop after finding one.
96 const cert_file_paths = [_][]const u8{96 const cert_file_paths = [_][]const u8{
97 "/etc/ssl/certs/ca-certificates.crt", // Debian/Ubuntu/Gentoo etc.97 "/etc/ssl/certs/ca-certificates.crt", // Debian/Ubuntu/Gentoo etc.
...@@ -114,7 +114,7 @@ fn rescanLinux(cb: *Bundle, gpa: Allocator, io: Io) RescanLinuxError!void {...@@ -114,7 +114,7 @@ fn rescanLinux(cb: *Bundle, gpa: Allocator, io: Io) RescanLinuxError!void {
114114
115 scan: {115 scan: {
116 for (cert_file_paths) |cert_file_path| {116 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)) |_| {
118 break :scan;118 break :scan;
119 } else |err| switch (err) {119 } else |err| switch (err) {
120 error.FileNotFound => continue,120 error.FileNotFound => continue,
...@@ -123,7 +123,7 @@ fn rescanLinux(cb: *Bundle, gpa: Allocator, io: Io) RescanLinuxError!void {...@@ -123,7 +123,7 @@ fn rescanLinux(cb: *Bundle, gpa: Allocator, io: Io) RescanLinuxError!void {
123 }123 }
124124
125 for (cert_dir_paths) |cert_dir_path| {125 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) {
127 error.FileNotFound => continue,127 error.FileNotFound => continue,
128 else => |e| return e,128 else => |e| return e,
129 };129 };
...@@ -135,10 +135,10 @@ fn rescanLinux(cb: *Bundle, gpa: Allocator, io: Io) RescanLinuxError!void {...@@ -135,10 +135,10 @@ fn rescanLinux(cb: *Bundle, gpa: Allocator, io: Io) RescanLinuxError!void {
135135
136const RescanWithPathError = AddCertsFromFilePathError;136const 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 {
139 cb.bytes.clearRetainingCapacity();139 cb.bytes.clearRetainingCapacity();
140 cb.map.clearRetainingCapacity();140 cb.map.clearRetainingCapacity();
141 try addCertsFromFilePathAbsolute(cb, gpa, io, cert_file_path);141 try addCertsFromFilePathAbsolute(cb, gpa, io, now, cert_file_path);
142 cb.bytes.shrinkAndFree(gpa, cb.bytes.items.len);142 cb.bytes.shrinkAndFree(gpa, cb.bytes.items.len);
143}143}
144144
...@@ -187,17 +187,18 @@ pub fn addCertsFromDirPathAbsolute(...@@ -187,17 +187,18 @@ pub fn addCertsFromDirPathAbsolute(
187 cb: *Bundle,187 cb: *Bundle,
188 gpa: Allocator,188 gpa: Allocator,
189 io: Io,189 io: Io,
190 now: Io.Timestamp,
190 abs_dir_path: []const u8,191 abs_dir_path: []const u8,
191) AddCertsFromDirPathError!void {192) AddCertsFromDirPathError!void {
192 assert(fs.path.isAbsolute(abs_dir_path));193 assert(fs.path.isAbsolute(abs_dir_path));
193 var iterable_dir = try fs.openDirAbsolute(abs_dir_path, .{ .iterate = true });194 var iterable_dir = try fs.openDirAbsolute(abs_dir_path, .{ .iterate = true });
194 defer iterable_dir.close();195 defer iterable_dir.close();
195 return addCertsFromDir(cb, gpa, io, iterable_dir);196 return addCertsFromDir(cb, gpa, io, now, iterable_dir);
196}197}
197198
198pub const AddCertsFromDirError = AddCertsFromFilePathError;199pub 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 {
201 var it = iterable_dir.iterate();202 var it = iterable_dir.iterate();
202 while (try it.next()) |entry| {203 while (try it.next()) |entry| {
203 switch (entry.kind) {204 switch (entry.kind) {
...@@ -205,7 +206,7 @@ pub fn addCertsFromDir(cb: *Bundle, gpa: Allocator, io: Io, iterable_dir: fs.Dir...@@ -205,7 +206,7 @@ pub fn addCertsFromDir(cb: *Bundle, gpa: Allocator, io: Io, iterable_dir: fs.Dir
205 else => continue,206 else => continue,
206 }207 }
207208
208 try addCertsFromFilePath(cb, gpa, io, iterable_dir.adaptToNewApi(), entry.name);209 try addCertsFromFilePath(cb, gpa, io, now, iterable_dir.adaptToNewApi(), entry.name);
209 }210 }
210}211}
211212
...@@ -215,9 +216,9 @@ pub fn addCertsFromFilePathAbsolute(...@@ -215,9 +216,9 @@ pub fn addCertsFromFilePathAbsolute(
215 cb: *Bundle,216 cb: *Bundle,
216 gpa: Allocator,217 gpa: Allocator,
217 io: Io,218 io: Io,
219 now: Io.Timestamp,
218 abs_file_path: []const u8,220 abs_file_path: []const u8,
219) AddCertsFromFilePathError!void {221) AddCertsFromFilePathError!void {
220 const now = try Io.Clock.real.now(io);
221 var file = try fs.openFileAbsolute(abs_file_path, .{});222 var file = try fs.openFileAbsolute(abs_file_path, .{});
222 defer file.close();223 defer file.close();
223 var file_reader = file.reader(io, &.{});224 var file_reader = file.reader(io, &.{});
...@@ -228,10 +229,10 @@ pub fn addCertsFromFilePath(...@@ -228,10 +229,10 @@ pub fn addCertsFromFilePath(
228 cb: *Bundle,229 cb: *Bundle,
229 gpa: Allocator,230 gpa: Allocator,
230 io: Io,231 io: Io,
232 now: Io.Timestamp,
231 dir: Io.Dir,233 dir: Io.Dir,
232 sub_file_path: []const u8,234 sub_file_path: []const u8,
233) AddCertsFromFilePathError!void {235) AddCertsFromFilePathError!void {
234 const now = try Io.Clock.real.now(io);
235 var file = try dir.openFile(io, sub_file_path, .{});236 var file = try dir.openFile(io, sub_file_path, .{});
236 defer file.close(io);237 defer file.close(io);
237 var file_reader = file.reader(io, &.{});238 var file_reader = file.reader(io, &.{});
...@@ -335,5 +336,7 @@ test "scan for OS-provided certificates" {...@@ -335,5 +336,7 @@ test "scan for OS-provided certificates" {
335 var bundle: Bundle = .{};336 var bundle: Bundle = .{};
336 defer bundle.deinit(gpa);337 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);
339}342}
lib/std/crypto/Certificate/Bundle/macos.zig+6-6
...@@ -1,4 +1,5 @@...@@ -1,4 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const Io = std.Io;
2const assert = std.debug.assert;3const assert = std.debug.assert;
3const fs = std.fs;4const fs = std.fs;
4const mem = std.mem;5const mem = std.mem;
...@@ -7,7 +8,7 @@ const Bundle = @import("../Bundle.zig");...@@ -7,7 +8,7 @@ const Bundle = @import("../Bundle.zig");
78
8pub const RescanMacError = Allocator.Error || fs.File.OpenError || fs.File.ReadError || fs.File.SeekError || Bundle.ParseCertError || error{EndOfStream};9pub 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 {
11 cb.bytes.clearRetainingCapacity();12 cb.bytes.clearRetainingCapacity();
12 cb.map.clearRetainingCapacity();13 cb.map.clearRetainingCapacity();
1314
...@@ -16,6 +17,7 @@ pub fn rescanMac(cb: *Bundle, gpa: Allocator) RescanMacError!void {...@@ -16,6 +17,7 @@ pub fn rescanMac(cb: *Bundle, gpa: Allocator) RescanMacError!void {
16 "/Library/Keychains/System.keychain",17 "/Library/Keychains/System.keychain",
17 };18 };
1819
20 _ = io; // TODO migrate file system to use std.Io
19 for (keychain_paths) |keychain_path| {21 for (keychain_paths) |keychain_path| {
20 const bytes = std.fs.cwd().readFileAlloc(keychain_path, gpa, .limited(std.math.maxInt(u32))) catch |err| switch (err) {22 const bytes = std.fs.cwd().readFileAlloc(keychain_path, gpa, .limited(std.math.maxInt(u32))) catch |err| switch (err) {
21 error.StreamTooLong => return error.FileTooBig,23 error.StreamTooLong => return error.FileTooBig,
...@@ -23,8 +25,8 @@ pub fn rescanMac(cb: *Bundle, gpa: Allocator) RescanMacError!void {...@@ -23,8 +25,8 @@ pub fn rescanMac(cb: *Bundle, gpa: Allocator) RescanMacError!void {
23 };25 };
24 defer gpa.free(bytes);26 defer gpa.free(bytes);
2527
26 var reader: std.Io.Reader = .fixed(bytes);28 var reader: Io.Reader = .fixed(bytes);
27 scanReader(cb, gpa, &reader) catch |err| switch (err) {29 scanReader(cb, gpa, &reader, now.toSeconds()) catch |err| switch (err) {
28 error.ReadFailed => unreachable, // prebuffered30 error.ReadFailed => unreachable, // prebuffered
29 else => |e| return e,31 else => |e| return e,
30 };32 };
...@@ -33,7 +35,7 @@ pub fn rescanMac(cb: *Bundle, gpa: Allocator) RescanMacError!void {...@@ -33,7 +35,7 @@ pub fn rescanMac(cb: *Bundle, gpa: Allocator) RescanMacError!void {
33 cb.bytes.shrinkAndFree(gpa, cb.bytes.items.len);35 cb.bytes.shrinkAndFree(gpa, cb.bytes.items.len);
34}36}
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 {
37 const db_header = try reader.takeStruct(ApplDbHeader, .big);39 const db_header = try reader.takeStruct(ApplDbHeader, .big);
38 assert(mem.eql(u8, &db_header.signature, "kych"));40 assert(mem.eql(u8, &db_header.signature, "kych"));
3941
...@@ -49,8 +51,6 @@ fn scanReader(cb: *Bundle, gpa: Allocator, reader: *std.Io.Reader) !void {...@@ -49,8 +51,6 @@ fn scanReader(cb: *Bundle, gpa: Allocator, reader: *std.Io.Reader) !void {
49 table_list[table_idx] = try reader.takeInt(u32, .big);51 table_list[table_idx] = try reader.takeInt(u32, .big);
50 }52 }
5153
52 const now_sec = std.time.timestamp();
53
54 for (table_list) |table_offset| {54 for (table_list) |table_offset| {
55 reader.seek = db_header.schema_offset + table_offset;55 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...@@ -117,11 +117,14 @@ pub fn unwindFrame(si: *SelfInfo, gpa: Allocator, context: *UnwindContext) Error
117 error.ReadFailed,117 error.ReadFailed,
118 error.OutOfMemory,118 error.OutOfMemory,
119 error.Unexpected,119 error.Unexpected,
120 error.Canceled,
120 => |e| return e,121 => |e| return e,
122
121 error.UnsupportedRegister,123 error.UnsupportedRegister,
122 error.UnsupportedAddrSize,124 error.UnsupportedAddrSize,
123 error.UnimplementedUserOpcode,125 error.UnimplementedUserOpcode,
124 => return error.UnsupportedDebugInfo,126 => return error.UnsupportedDebugInfo,
127
125 error.Overflow,128 error.Overflow,
126 error.EndOfStream,129 error.EndOfStream,
127 error.StreamTooLong,130 error.StreamTooLong,
lib/std/fs.zig+2
...@@ -458,6 +458,8 @@ pub const SelfExePathError = error{...@@ -458,6 +458,8 @@ pub const SelfExePathError = error{
458 /// On Windows, the volume does not contain a recognized file system. File458 /// On Windows, the volume does not contain a recognized file system. File
459 /// system drivers might not be loaded, or the volume may be corrupt.459 /// system drivers might not be loaded, or the volume may be corrupt.
460 UnrecognizedVolume,460 UnrecognizedVolume,
461
462 Canceled,
461} || posix.SysCtlError;463} || posix.SysCtlError;
462464
463/// `selfExePath` except allocates the result on the heap.465/// `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...@@ -35,9 +35,11 @@ tls_buffer_size: if (disable_tls) u0 else usize = if (disable_tls) 0 else std.cr
35/// traffic over connections created with this `Client`.35/// traffic over connections created with this `Client`.
36ssl_key_log: ?*std.crypto.tls.Client.SslKeyLog = null,36ssl_key_log: ?*std.crypto.tls.Client.SslKeyLog = null,
3737
38/// When this is `true`, the next time this client performs an HTTPS request,38/// The time used to decide whether certificates are expired.
39/// it will first rescan the system for root certificates.39///
40next_https_rescan_certs: bool = true,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
42/// The pool of connections that can be reused (and currently in use).44/// The pool of connections that can be reused (and currently in use).
43connection_pool: ConnectionPool = .{},45connection_pool: ConnectionPool = .{},
...@@ -295,6 +297,7 @@ pub const Connection = struct {...@@ -295,6 +297,7 @@ pub const Connection = struct {
295 client: std.crypto.tls.Client,297 client: std.crypto.tls.Client,
296 connection: Connection,298 connection: Connection,
297299
300 /// Asserts that `client.now` is non-null.
298 fn create(301 fn create(
299 client: *Client,302 client: *Client,
300 remote_host: HostName,303 remote_host: HostName,
...@@ -320,7 +323,6 @@ pub const Connection = struct {...@@ -320,7 +323,6 @@ pub const Connection = struct {
320 const tls: *Tls = @ptrCast(base);323 const tls: *Tls = @ptrCast(base);
321 var random_buffer: [176]u8 = undefined;324 var random_buffer: [176]u8 = undefined;
322 std.crypto.random.bytes(&random_buffer);325 std.crypto.random.bytes(&random_buffer);
323 const now_ts = if (Io.Clock.real.now(io)) |ts| ts.toSeconds() else |err| return err;
324 tls.* = .{326 tls.* = .{
325 .connection = .{327 .connection = .{
326 .client = client,328 .client = client,
...@@ -333,7 +335,7 @@ pub const Connection = struct {...@@ -333,7 +335,7 @@ pub const Connection = struct {
333 .closing = false,335 .closing = false,
334 .protocol = .tls,336 .protocol = .tls,
335 },337 },
336 // TODO data race here on ca_bundle if the user sets next_https_rescan_certs to true338 // TODO data race here on ca_bundle if the user sets `now` to null
337 .client = std.crypto.tls.Client.init(339 .client = std.crypto.tls.Client.init(
338 &tls.connection.stream_reader.interface,340 &tls.connection.stream_reader.interface,
339 &tls.connection.stream_writer.interface,341 &tls.connection.stream_writer.interface,
...@@ -344,7 +346,7 @@ pub const Connection = struct {...@@ -344,7 +346,7 @@ pub const Connection = struct {
344 .read_buffer = tls_read_buffer,346 .read_buffer = tls_read_buffer,
345 .write_buffer = socket_write_buffer,347 .write_buffer = socket_write_buffer,
346 .entropy = &random_buffer,348 .entropy = &random_buffer,
347 .realtime_now_seconds = now_ts,349 .realtime_now_seconds = client.now.?.toSeconds(),
348 // This is appropriate for HTTPS because the HTTP headers contain350 // This is appropriate for HTTPS because the HTTP headers contain
349 // the content length which is used to detect truncation attacks.351 // the content length which is used to detect truncation attacks.
350 .allow_truncation_attacks = true,352 .allow_truncation_attacks = true,
...@@ -1687,14 +1689,15 @@ pub fn request(...@@ -1687,14 +1689,15 @@ pub fn request(
16871689
1688 if (protocol == .tls) {1690 if (protocol == .tls) {
1689 if (disable_tls) unreachable;1691 if (disable_tls) unreachable;
1690 if (@atomicLoad(bool, &client.next_https_rescan_certs, .acquire)) {1692 {
1691 client.ca_bundle_mutex.lock();1693 client.ca_bundle_mutex.lock();
1692 defer client.ca_bundle_mutex.unlock();1694 defer client.ca_bundle_mutex.unlock();
16931695
1694 if (client.next_https_rescan_certs) {1696 if (client.now == null) {
1695 client.ca_bundle.rescan(client.allocator, io) catch1697 const now = try Io.Clock.real.now(io);
1698 client.now = now;
1699 client.ca_bundle.rescan(client.allocator, io, now) catch
1696 return error.CertificateBundleLoadFailure;1700 return error.CertificateBundleLoadFailure;
1697 @atomicStore(bool, &client.next_https_rescan_certs, false, .release);
1698 }1701 }
1699 }1702 }
1700 }1703 }
lib/std/http/Server.zig+4-4
...@@ -688,7 +688,7 @@ pub const WebSocket = struct {...@@ -688,7 +688,7 @@ pub const WebSocket = struct {
688 pub const ReadSmallTextMessageError = error{688 pub const ReadSmallTextMessageError = error{
689 ConnectionClose,689 ConnectionClose,
690 UnexpectedOpCode,690 UnexpectedOpCode,
691 MessageTooBig,691 MessageOversize,
692 MissingMaskBit,692 MissingMaskBit,
693 ReadFailed,693 ReadFailed,
694 EndOfStream,694 EndOfStream,
...@@ -717,15 +717,15 @@ pub const WebSocket = struct {...@@ -717,15 +717,15 @@ pub const WebSocket = struct {
717 _ => return error.UnexpectedOpCode,717 _ => return error.UnexpectedOpCode,
718 }718 }
719719
720 if (!h0.fin) return error.MessageTooBig;720 if (!h0.fin) return error.MessageOversize;
721 if (!h1.mask) return error.MissingMaskBit;721 if (!h1.mask) return error.MissingMaskBit;
722722
723 const len: usize = switch (h1.payload_len) {723 const len: usize = switch (h1.payload_len) {
724 .len16 => try in.takeInt(u16, .big),724 .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,
726 else => @intFromEnum(h1.payload_len),726 else => @intFromEnum(h1.payload_len),
727 };727 };
728 if (len > in.buffer.len) return error.MessageTooBig;728 if (len > in.buffer.len) return error.MessageOversize;
729 const mask: u32 = @bitCast((try in.takeArray(4)).*);729 const mask: u32 = @bitCast((try in.takeArray(4)).*);
730 const payload = try in.take(len);730 const payload = try in.take(len);
731731
lib/std/os/windows.zig+1-1
...@@ -1653,7 +1653,7 @@ pub fn WSASocketW(...@@ -1653,7 +1653,7 @@ pub fn WSASocketW(
1653 const rc = ws2_32.WSASocketW(af, socket_type, protocol, protocolInfo, g, dwFlags);1653 const rc = ws2_32.WSASocketW(af, socket_type, protocol, protocolInfo, g, dwFlags);
1654 if (rc == ws2_32.INVALID_SOCKET) {1654 if (rc == ws2_32.INVALID_SOCKET) {
1655 switch (ws2_32.WSAGetLastError()) {1655 switch (ws2_32.WSAGetLastError()) {
1656 .WSAEAFNOSUPPORT => return error.AddressFamilyNotSupported,1656 .WSAEAFNOSUPPORT => return error.AddressFamilyUnsupported,
1657 .WSAEMFILE => return error.ProcessFdQuotaExceeded,1657 .WSAEMFILE => return error.ProcessFdQuotaExceeded,
1658 .WSAENOBUFS => return error.SystemResources,1658 .WSAENOBUFS => return error.SystemResources,
1659 .WSAEPROTONOSUPPORT => return error.ProtocolNotSupported,1659 .WSAEPROTONOSUPPORT => return error.ProtocolNotSupported,
lib/std/posix.zig+26-26
...@@ -1205,7 +1205,7 @@ pub const WriteError = error{...@@ -1205,7 +1205,7 @@ pub const WriteError = error{
12051205
1206 /// The socket type requires that message be sent atomically, and the size of the message1206 /// The socket type requires that message be sent atomically, and the size of the message
1207 /// to be sent made this impossible. The message is not transmitted.1207 /// to be sent made this impossible. The message is not transmitted.
1208 MessageTooBig,1208 MessageOversize,
1209} || UnexpectedError;1209} || UnexpectedError;
12101210
1211/// Write to a file descriptor.1211/// Write to a file descriptor.
...@@ -1287,7 +1287,7 @@ pub fn write(fd: fd_t, bytes: []const u8) WriteError!usize {...@@ -1287,7 +1287,7 @@ pub fn write(fd: fd_t, bytes: []const u8) WriteError!usize {
1287 .CONNRESET => return error.ConnectionResetByPeer,1287 .CONNRESET => return error.ConnectionResetByPeer,
1288 .BUSY => return error.DeviceBusy,1288 .BUSY => return error.DeviceBusy,
1289 .NXIO => return error.NoDevice,1289 .NXIO => return error.NoDevice,
1290 .MSGSIZE => return error.MessageTooBig,1290 .MSGSIZE => return error.MessageOversize,
1291 else => |err| return unexpectedErrno(err),1291 else => |err| return unexpectedErrno(err),
1292 }1292 }
1293 }1293 }
...@@ -3487,7 +3487,7 @@ pub const SocketError = error{...@@ -3487,7 +3487,7 @@ pub const SocketError = error{
3487 AccessDenied,3487 AccessDenied,
34883488
3489 /// The implementation does not support the specified address family.3489 /// The implementation does not support the specified address family.
3490 AddressFamilyNotSupported,3490 AddressFamilyUnsupported,
34913491
3492 /// Unknown protocol, or protocol family not available.3492 /// Unknown protocol, or protocol family not available.
3493 ProtocolFamilyNotAvailable,3493 ProtocolFamilyNotAvailable,
...@@ -3553,7 +3553,7 @@ pub fn socket(domain: u32, socket_type: u32, protocol: u32) SocketError!socket_t...@@ -3553,7 +3553,7 @@ pub fn socket(domain: u32, socket_type: u32, protocol: u32) SocketError!socket_t
3553 return fd;3553 return fd;
3554 },3554 },
3555 .ACCES => return error.AccessDenied,3555 .ACCES => return error.AccessDenied,
3556 .AFNOSUPPORT => return error.AddressFamilyNotSupported,3556 .AFNOSUPPORT => return error.AddressFamilyUnsupported,
3557 .INVAL => return error.ProtocolFamilyNotAvailable,3557 .INVAL => return error.ProtocolFamilyNotAvailable,
3558 .MFILE => return error.ProcessFdQuotaExceeded,3558 .MFILE => return error.ProcessFdQuotaExceeded,
3559 .NFILE => return error.SystemFdQuotaExceeded,3559 .NFILE => return error.SystemFdQuotaExceeded,
...@@ -3593,7 +3593,7 @@ pub fn socketpair(domain: u32, socket_type: u32, protocol: u32) SocketError![2]s...@@ -3593,7 +3593,7 @@ pub fn socketpair(domain: u32, socket_type: u32, protocol: u32) SocketError![2]s
3593 return socks;3593 return socks;
3594 },3594 },
3595 .ACCES => return error.AccessDenied,3595 .ACCES => return error.AccessDenied,
3596 .AFNOSUPPORT => return error.AddressFamilyNotSupported,3596 .AFNOSUPPORT => return error.AddressFamilyUnsupported,
3597 .INVAL => return error.ProtocolFamilyNotAvailable,3597 .INVAL => return error.ProtocolFamilyNotAvailable,
3598 .MFILE => return error.ProcessFdQuotaExceeded,3598 .MFILE => return error.ProcessFdQuotaExceeded,
3599 .NFILE => return error.SystemFdQuotaExceeded,3599 .NFILE => return error.SystemFdQuotaExceeded,
...@@ -3676,7 +3676,7 @@ pub const BindError = error{...@@ -3676,7 +3676,7 @@ pub const BindError = error{
3676 AddressNotAvailable,3676 AddressNotAvailable,
36773677
3678 /// The address is not valid for the address family of socket.3678 /// The address is not valid for the address family of socket.
3679 AddressFamilyNotSupported,3679 AddressFamilyUnsupported,
36803680
3681 /// Too many symbolic links were encountered in resolving addr.3681 /// Too many symbolic links were encountered in resolving addr.
3682 SymLinkLoop,3682 SymLinkLoop,
...@@ -3733,7 +3733,7 @@ pub fn bind(sock: socket_t, addr: *const sockaddr, len: socklen_t) BindError!voi...@@ -3733,7 +3733,7 @@ pub fn bind(sock: socket_t, addr: *const sockaddr, len: socklen_t) BindError!voi
3733 .BADF => unreachable, // always a race condition if this error is returned3733 .BADF => unreachable, // always a race condition if this error is returned
3734 .INVAL => unreachable, // invalid parameters3734 .INVAL => unreachable, // invalid parameters
3735 .NOTSOCK => unreachable, // invalid `sockfd`3735 .NOTSOCK => unreachable, // invalid `sockfd`
3736 .AFNOSUPPORT => return error.AddressFamilyNotSupported,3736 .AFNOSUPPORT => return error.AddressFamilyUnsupported,
3737 .ADDRNOTAVAIL => return error.AddressNotAvailable,3737 .ADDRNOTAVAIL => return error.AddressNotAvailable,
3738 .FAULT => unreachable, // invalid `addr` pointer3738 .FAULT => unreachable, // invalid `addr` pointer
3739 .LOOP => return error.SymLinkLoop,3739 .LOOP => return error.SymLinkLoop,
...@@ -4192,7 +4192,7 @@ pub const ConnectError = error{...@@ -4192,7 +4192,7 @@ pub const ConnectError = error{
4192 AddressNotAvailable,4192 AddressNotAvailable,
41934193
4194 /// The passed address didn't have the correct address family in its sa_family field.4194 /// The passed address didn't have the correct address family in its sa_family field.
4195 AddressFamilyNotSupported,4195 AddressFamilyUnsupported,
41964196
4197 /// Insufficient entries in the routing cache.4197 /// Insufficient entries in the routing cache.
4198 SystemResources,4198 SystemResources,
...@@ -4247,7 +4247,7 @@ pub fn connect(sock: socket_t, sock_addr: *const sockaddr, len: socklen_t) Conne...@@ -4247,7 +4247,7 @@ pub fn connect(sock: socket_t, sock_addr: *const sockaddr, len: socklen_t) Conne
4247 .WSAEWOULDBLOCK => return error.WouldBlock,4247 .WSAEWOULDBLOCK => return error.WouldBlock,
4248 .WSAEACCES => unreachable,4248 .WSAEACCES => unreachable,
4249 .WSAENOBUFS => return error.SystemResources,4249 .WSAENOBUFS => return error.SystemResources,
4250 .WSAEAFNOSUPPORT => return error.AddressFamilyNotSupported,4250 .WSAEAFNOSUPPORT => return error.AddressFamilyUnsupported,
4251 else => |err| return windows.unexpectedWSAError(err),4251 else => |err| return windows.unexpectedWSAError(err),
4252 }4252 }
4253 return;4253 return;
...@@ -4260,7 +4260,7 @@ pub fn connect(sock: socket_t, sock_addr: *const sockaddr, len: socklen_t) Conne...@@ -4260,7 +4260,7 @@ pub fn connect(sock: socket_t, sock_addr: *const sockaddr, len: socklen_t) Conne
4260 .PERM => return error.PermissionDenied,4260 .PERM => return error.PermissionDenied,
4261 .ADDRINUSE => return error.AddressInUse,4261 .ADDRINUSE => return error.AddressInUse,
4262 .ADDRNOTAVAIL => return error.AddressNotAvailable,4262 .ADDRNOTAVAIL => return error.AddressNotAvailable,
4263 .AFNOSUPPORT => return error.AddressFamilyNotSupported,4263 .AFNOSUPPORT => return error.AddressFamilyUnsupported,
4264 .AGAIN, .INPROGRESS => return error.WouldBlock,4264 .AGAIN, .INPROGRESS => return error.WouldBlock,
4265 .ALREADY => return error.ConnectionPending,4265 .ALREADY => return error.ConnectionPending,
4266 .BADF => unreachable, // sockfd is not a valid open file descriptor.4266 .BADF => unreachable, // sockfd is not a valid open file descriptor.
...@@ -4322,7 +4322,7 @@ pub fn getsockoptError(sockfd: fd_t) ConnectError!void {...@@ -4322,7 +4322,7 @@ pub fn getsockoptError(sockfd: fd_t) ConnectError!void {
4322 .PERM => return error.PermissionDenied,4322 .PERM => return error.PermissionDenied,
4323 .ADDRINUSE => return error.AddressInUse,4323 .ADDRINUSE => return error.AddressInUse,
4324 .ADDRNOTAVAIL => return error.AddressNotAvailable,4324 .ADDRNOTAVAIL => return error.AddressNotAvailable,
4325 .AFNOSUPPORT => return error.AddressFamilyNotSupported,4325 .AFNOSUPPORT => return error.AddressFamilyUnsupported,
4326 .AGAIN => return error.SystemResources,4326 .AGAIN => return error.SystemResources,
4327 .ALREADY => return error.ConnectionPending,4327 .ALREADY => return error.ConnectionPending,
4328 .BADF => unreachable, // sockfd is not a valid open file descriptor.4328 .BADF => unreachable, // sockfd is not a valid open file descriptor.
...@@ -6039,7 +6039,7 @@ pub const SendError = error{...@@ -6039,7 +6039,7 @@ pub const SendError = error{
60396039
6040 /// The socket type requires that message be sent atomically, and the size of the message6040 /// The socket type requires that message be sent atomically, and the size of the message
6041 /// to be sent made this impossible. The message is not transmitted.6041 /// to be sent made this impossible. The message is not transmitted.
6042 MessageTooBig,6042 MessageOversize,
60436043
6044 /// The output queue for a network interface was full. This generally indicates that the6044 /// The output queue for a network interface was full. This generally indicates that the
6045 /// interface has stopped sending, but may be caused by transient congestion. (Normally,6045 /// interface has stopped sending, but may be caused by transient congestion. (Normally,
...@@ -6066,7 +6066,7 @@ pub const SendError = error{...@@ -6066,7 +6066,7 @@ pub const SendError = error{
60666066
6067pub const SendMsgError = SendError || error{6067pub const SendMsgError = SendError || error{
6068 /// The passed address didn't have the correct address family in its sa_family field.6068 /// The passed address didn't have the correct address family in its sa_family field.
6069 AddressFamilyNotSupported,6069 AddressFamilyUnsupported,
60706070
6071 /// Returned when socket is AF.UNIX and the given path has a symlink loop.6071 /// Returned when socket is AF.UNIX and the given path has a symlink loop.
6072 SymLinkLoop,6072 SymLinkLoop,
...@@ -6098,10 +6098,10 @@ pub fn sendmsg(...@@ -6098,10 +6098,10 @@ pub fn sendmsg(
6098 .WSAEACCES => return error.AccessDenied,6098 .WSAEACCES => return error.AccessDenied,
6099 .WSAEADDRNOTAVAIL => return error.AddressNotAvailable,6099 .WSAEADDRNOTAVAIL => return error.AddressNotAvailable,
6100 .WSAECONNRESET => return error.ConnectionResetByPeer,6100 .WSAECONNRESET => return error.ConnectionResetByPeer,
6101 .WSAEMSGSIZE => return error.MessageTooBig,6101 .WSAEMSGSIZE => return error.MessageOversize,
6102 .WSAENOBUFS => return error.SystemResources,6102 .WSAENOBUFS => return error.SystemResources,
6103 .WSAENOTSOCK => return error.FileDescriptorNotASocket,6103 .WSAENOTSOCK => return error.FileDescriptorNotASocket,
6104 .WSAEAFNOSUPPORT => return error.AddressFamilyNotSupported,6104 .WSAEAFNOSUPPORT => return error.AddressFamilyUnsupported,
6105 .WSAEDESTADDRREQ => unreachable, // A destination address is required.6105 .WSAEDESTADDRREQ => unreachable, // A destination address is required.
6106 .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.6106 .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.
6107 .WSAEHOSTUNREACH => return error.NetworkUnreachable,6107 .WSAEHOSTUNREACH => return error.NetworkUnreachable,
...@@ -6133,13 +6133,13 @@ pub fn sendmsg(...@@ -6133,13 +6133,13 @@ pub fn sendmsg(
6133 .INTR => continue,6133 .INTR => continue,
6134 .INVAL => unreachable, // Invalid argument passed.6134 .INVAL => unreachable, // Invalid argument passed.
6135 .ISCONN => unreachable, // connection-mode socket was connected already but a recipient was specified6135 .ISCONN => unreachable, // connection-mode socket was connected already but a recipient was specified
6136 .MSGSIZE => return error.MessageTooBig,6136 .MSGSIZE => return error.MessageOversize,
6137 .NOBUFS => return error.SystemResources,6137 .NOBUFS => return error.SystemResources,
6138 .NOMEM => return error.SystemResources,6138 .NOMEM => return error.SystemResources,
6139 .NOTSOCK => unreachable, // The file descriptor sockfd does not refer to a socket.6139 .NOTSOCK => unreachable, // The file descriptor sockfd does not refer to a socket.
6140 .OPNOTSUPP => unreachable, // Some bit in the flags argument is inappropriate for the socket type.6140 .OPNOTSUPP => unreachable, // Some bit in the flags argument is inappropriate for the socket type.
6141 .PIPE => return error.BrokenPipe,6141 .PIPE => return error.BrokenPipe,
6142 .AFNOSUPPORT => return error.AddressFamilyNotSupported,6142 .AFNOSUPPORT => return error.AddressFamilyUnsupported,
6143 .LOOP => return error.SymLinkLoop,6143 .LOOP => return error.SymLinkLoop,
6144 .NAMETOOLONG => return error.NameTooLong,6144 .NAMETOOLONG => return error.NameTooLong,
6145 .NOENT => return error.FileNotFound,6145 .NOENT => return error.FileNotFound,
...@@ -6178,7 +6178,7 @@ pub const SendToError = SendMsgError || error{...@@ -6178,7 +6178,7 @@ pub const SendToError = SendMsgError || error{
6178/// Otherwise, the address of the target is given by `dest_addr` with `addrlen` specifying its size.6178/// Otherwise, the address of the target is given by `dest_addr` with `addrlen` specifying its size.
6179///6179///
6180/// If the message is too long to pass atomically through the underlying protocol,6180/// 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.
6182///6182///
6183/// There is no indication of failure to deliver.6183/// There is no indication of failure to deliver.
6184///6184///
...@@ -6201,10 +6201,10 @@ pub fn sendto(...@@ -6201,10 +6201,10 @@ pub fn sendto(
6201 .WSAEACCES => return error.AccessDenied,6201 .WSAEACCES => return error.AccessDenied,
6202 .WSAEADDRNOTAVAIL => return error.AddressNotAvailable,6202 .WSAEADDRNOTAVAIL => return error.AddressNotAvailable,
6203 .WSAECONNRESET => return error.ConnectionResetByPeer,6203 .WSAECONNRESET => return error.ConnectionResetByPeer,
6204 .WSAEMSGSIZE => return error.MessageTooBig,6204 .WSAEMSGSIZE => return error.MessageOversize,
6205 .WSAENOBUFS => return error.SystemResources,6205 .WSAENOBUFS => return error.SystemResources,
6206 .WSAENOTSOCK => return error.FileDescriptorNotASocket,6206 .WSAENOTSOCK => return error.FileDescriptorNotASocket,
6207 .WSAEAFNOSUPPORT => return error.AddressFamilyNotSupported,6207 .WSAEAFNOSUPPORT => return error.AddressFamilyUnsupported,
6208 .WSAEDESTADDRREQ => unreachable, // A destination address is required.6208 .WSAEDESTADDRREQ => unreachable, // A destination address is required.
6209 .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.6209 .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.
6210 .WSAEHOSTUNREACH => return error.NetworkUnreachable,6210 .WSAEHOSTUNREACH => return error.NetworkUnreachable,
...@@ -6238,13 +6238,13 @@ pub fn sendto(...@@ -6238,13 +6238,13 @@ pub fn sendto(
6238 .INTR => continue,6238 .INTR => continue,
6239 .INVAL => return error.UnreachableAddress,6239 .INVAL => return error.UnreachableAddress,
6240 .ISCONN => unreachable, // connection-mode socket was connected already but a recipient was specified6240 .ISCONN => unreachable, // connection-mode socket was connected already but a recipient was specified
6241 .MSGSIZE => return error.MessageTooBig,6241 .MSGSIZE => return error.MessageOversize,
6242 .NOBUFS => return error.SystemResources,6242 .NOBUFS => return error.SystemResources,
6243 .NOMEM => return error.SystemResources,6243 .NOMEM => return error.SystemResources,
6244 .NOTSOCK => unreachable, // The file descriptor sockfd does not refer to a socket.6244 .NOTSOCK => unreachable, // The file descriptor sockfd does not refer to a socket.
6245 .OPNOTSUPP => unreachable, // Some bit in the flags argument is inappropriate for the socket type.6245 .OPNOTSUPP => unreachable, // Some bit in the flags argument is inappropriate for the socket type.
6246 .PIPE => return error.BrokenPipe,6246 .PIPE => return error.BrokenPipe,
6247 .AFNOSUPPORT => return error.AddressFamilyNotSupported,6247 .AFNOSUPPORT => return error.AddressFamilyUnsupported,
6248 .LOOP => return error.SymLinkLoop,6248 .LOOP => return error.SymLinkLoop,
6249 .NAMETOOLONG => return error.NameTooLong,6249 .NAMETOOLONG => return error.NameTooLong,
6250 .NOENT => return error.FileNotFound,6250 .NOENT => return error.FileNotFound,
...@@ -6284,7 +6284,7 @@ pub fn send(...@@ -6284,7 +6284,7 @@ pub fn send(
6284 flags: u32,6284 flags: u32,
6285) SendError!usize {6285) SendError!usize {
6286 return sendto(sockfd, buf, flags, null, 0) catch |err| switch (err) {6286 return sendto(sockfd, buf, flags, null, 0) catch |err| switch (err) {
6287 error.AddressFamilyNotSupported => unreachable,6287 error.AddressFamilyUnsupported => unreachable,
6288 error.SymLinkLoop => unreachable,6288 error.SymLinkLoop => unreachable,
6289 error.NameTooLong => unreachable,6289 error.NameTooLong => unreachable,
6290 error.FileNotFound => unreachable,6290 error.FileNotFound => unreachable,
...@@ -6471,7 +6471,7 @@ pub const RecvFromError = error{...@@ -6471,7 +6471,7 @@ pub const RecvFromError = error{
6471 SocketNotBound,6471 SocketNotBound,
64726472
6473 /// The UDP message was too big for the buffer and part of it has been discarded6473 /// The UDP message was too big for the buffer and part of it has been discarded
6474 MessageTooBig,6474 MessageOversize,
64756475
6476 /// The network subsystem has failed.6476 /// The network subsystem has failed.
6477 NetworkDown,6477 NetworkDown,
...@@ -6504,7 +6504,7 @@ pub fn recvfrom(...@@ -6504,7 +6504,7 @@ pub fn recvfrom(
6504 .WSANOTINITIALISED => unreachable,6504 .WSANOTINITIALISED => unreachable,
6505 .WSAECONNRESET => return error.ConnectionResetByPeer,6505 .WSAECONNRESET => return error.ConnectionResetByPeer,
6506 .WSAEINVAL => return error.SocketNotBound,6506 .WSAEINVAL => return error.SocketNotBound,
6507 .WSAEMSGSIZE => return error.MessageTooBig,6507 .WSAEMSGSIZE => return error.MessageOversize,
6508 .WSAENETDOWN => return error.NetworkDown,6508 .WSAENETDOWN => return error.NetworkDown,
6509 .WSAENOTCONN => return error.SocketUnconnected,6509 .WSAENOTCONN => return error.SocketUnconnected,
6510 .WSAEWOULDBLOCK => return error.WouldBlock,6510 .WSAEWOULDBLOCK => return error.WouldBlock,
...@@ -6575,7 +6575,7 @@ pub fn recvmsg(...@@ -6575,7 +6575,7 @@ pub fn recvmsg(
6575 .NOMEM => return error.SystemResources,6575 .NOMEM => return error.SystemResources,
6576 .NOTCONN => return error.SocketUnconnected,6576 .NOTCONN => return error.SocketUnconnected,
6577 .NOTSOCK => unreachable, // The file descriptor sockfd does not refer to a socket.6577 .NOTSOCK => unreachable, // The file descriptor sockfd does not refer to a socket.
6578 .MSGSIZE => return error.MessageTooBig,6578 .MSGSIZE => return error.MessageOversize,
6579 .PIPE => return error.BrokenPipe,6579 .PIPE => return error.BrokenPipe,
6580 .OPNOTSUPP => unreachable, // Some bit in the flags argument is inappropriate for the socket type.6580 .OPNOTSUPP => unreachable, // Some bit in the flags argument is inappropriate for the socket type.
6581 .CONNRESET => return error.ConnectionResetByPeer,6581 .CONNRESET => return error.ConnectionResetByPeer,