authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-12-01 19:11:47-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-12-01 19:17:52-08:00
logbb3f56d5d5424c7be42132c047a7146e82b49c74
treee018d8ea82b13a0b1a73c04b4688adecc963e3a4
parentcf82064ebc3063c6a8e8f51388783ed1c01d6281

std.Io.Threaded: separate out ECANCELED handling again

If ECANCELED occurs, it's from pthread_cancel which will *permanently* set that thread to be in a "canceling" state, which means the cancel cannot be ignored. That means it cannot be retried, like EINTR. It must be acknowledged.

1 files changed, 112 insertions(+), 54 deletions(-)

lib/std/Io/Threaded.zig+112-54
...@@ -145,6 +145,13 @@ const Thread = struct {...@@ -145,6 +145,13 @@ const Thread = struct {
145 ) orelse return;145 ) orelse return;
146 }146 }
147147
148 fn endSyscallCanceled(thread: *Thread) Io.Cancelable {
149 if (thread.current_closure) |closure| {
150 @atomicStore(CancelStatus, &closure.cancel_status, .acknowledged, .release);
151 }
152 return error.Canceled;
153 }
154
148 fn currentSignalId() SignaleeId {155 fn currentSignalId() SignaleeId {
149 return if (std.Thread.use_pthreads) std.c.pthread_self() else std.Thread.getCurrentId();156 return if (std.Thread.use_pthreads) std.c.pthread_self() else std.Thread.getCurrentId();
150 }157 }
...@@ -1211,10 +1218,11 @@ fn dirMakePosix(userdata: ?*anyopaque, dir: Io.Dir, sub_path: []const u8, mode:...@@ -1211,10 +1218,11 @@ fn dirMakePosix(userdata: ?*anyopaque, dir: Io.Dir, sub_path: []const u8, mode:
1211 current_thread.endSyscall();1218 current_thread.endSyscall();
1212 return;1219 return;
1213 },1220 },
1214 .INTR, .CANCELED => {1221 .INTR => {
1215 try current_thread.checkCancel();1222 try current_thread.checkCancel();
1216 continue;1223 continue;
1217 },1224 },
1225 .CANCELED => return current_thread.endSyscallCanceled(),
1218 else => |e| {1226 else => |e| {
1219 current_thread.endSyscall();1227 current_thread.endSyscall();
1220 switch (e) {1228 switch (e) {
...@@ -1253,10 +1261,11 @@ fn dirMakeWasi(userdata: ?*anyopaque, dir: Io.Dir, sub_path: []const u8, mode: I...@@ -1253,10 +1261,11 @@ fn dirMakeWasi(userdata: ?*anyopaque, dir: Io.Dir, sub_path: []const u8, mode: I
1253 current_thread.endSyscall();1261 current_thread.endSyscall();
1254 return;1262 return;
1255 },1263 },
1256 .INTR, .CANCELED => {1264 .INTR => {
1257 try current_thread.checkCancel();1265 try current_thread.checkCancel();
1258 continue;1266 continue;
1259 },1267 },
1268 .CANCELED => return current_thread.endSyscallCanceled(),
1260 else => |e| {1269 else => |e| {
1261 current_thread.endSyscall();1270 current_thread.endSyscall();
1262 switch (e) {1271 switch (e) {
...@@ -1518,10 +1527,11 @@ fn dirStatPathLinux(...@@ -1518,10 +1527,11 @@ fn dirStatPathLinux(
1518 current_thread.endSyscall();1527 current_thread.endSyscall();
1519 return statFromLinux(&statx);1528 return statFromLinux(&statx);
1520 },1529 },
1521 .INTR, .CANCELED => {1530 .INTR => {
1522 try current_thread.checkCancel();1531 try current_thread.checkCancel();
1523 continue;1532 continue;
1524 },1533 },
1534 .CANCELED => return current_thread.endSyscallCanceled(),
1525 else => |e| {1535 else => |e| {
1526 current_thread.endSyscall();1536 current_thread.endSyscall();
1527 switch (e) {1537 switch (e) {
...@@ -1563,10 +1573,11 @@ fn dirStatPathPosix(...@@ -1563,10 +1573,11 @@ fn dirStatPathPosix(
1563 current_thread.endSyscall();1573 current_thread.endSyscall();
1564 return statFromPosix(&stat);1574 return statFromPosix(&stat);
1565 },1575 },
1566 .INTR, .CANCELED => {1576 .INTR => {
1567 try current_thread.checkCancel();1577 try current_thread.checkCancel();
1568 continue;1578 continue;
1569 },1579 },
1580 .CANCELED => return current_thread.endSyscallCanceled(),
1570 else => |e| {1581 else => |e| {
1571 current_thread.endSyscall();1582 current_thread.endSyscall();
1572 switch (e) {1583 switch (e) {
...@@ -1623,10 +1634,11 @@ fn dirStatPathWasi(...@@ -1623,10 +1634,11 @@ fn dirStatPathWasi(
1623 current_thread.endSyscall();1634 current_thread.endSyscall();
1624 return statFromWasi(&stat);1635 return statFromWasi(&stat);
1625 },1636 },
1626 .INTR, .CANCELED => {1637 .INTR => {
1627 try current_thread.checkCancel();1638 try current_thread.checkCancel();
1628 continue;1639 continue;
1629 },1640 },
1641 .CANCELED => return current_thread.endSyscallCanceled(),
1630 else => |e| {1642 else => |e| {
1631 current_thread.endSyscall();1643 current_thread.endSyscall();
1632 switch (e) {1644 switch (e) {
...@@ -1668,10 +1680,11 @@ fn fileStatPosix(userdata: ?*anyopaque, file: Io.File) Io.File.StatError!Io.File...@@ -1668,10 +1680,11 @@ fn fileStatPosix(userdata: ?*anyopaque, file: Io.File) Io.File.StatError!Io.File
1668 current_thread.endSyscall();1680 current_thread.endSyscall();
1669 return statFromPosix(&stat);1681 return statFromPosix(&stat);
1670 },1682 },
1671 .INTR, .CANCELED => {1683 .INTR => {
1672 try current_thread.checkCancel();1684 try current_thread.checkCancel();
1673 continue;1685 continue;
1674 },1686 },
1687 .CANCELED => return current_thread.endSyscallCanceled(),
1675 else => |e| {1688 else => |e| {
1676 current_thread.endSyscall();1689 current_thread.endSyscall();
1677 switch (e) {1690 switch (e) {
...@@ -1706,10 +1719,11 @@ fn fileStatLinux(userdata: ?*anyopaque, file: Io.File) Io.File.StatError!Io.File...@@ -1706,10 +1719,11 @@ fn fileStatLinux(userdata: ?*anyopaque, file: Io.File) Io.File.StatError!Io.File
1706 current_thread.endSyscall();1719 current_thread.endSyscall();
1707 return statFromLinux(&statx);1720 return statFromLinux(&statx);
1708 },1721 },
1709 .INTR, .CANCELED => {1722 .INTR => {
1710 try current_thread.checkCancel();1723 try current_thread.checkCancel();
1711 continue;1724 continue;
1712 },1725 },
1726 .CANCELED => return current_thread.endSyscallCanceled(),
1713 else => |e| {1727 else => |e| {
1714 current_thread.endSyscall();1728 current_thread.endSyscall();
1715 switch (e) {1729 switch (e) {
...@@ -1791,10 +1805,11 @@ fn fileStatWasi(userdata: ?*anyopaque, file: Io.File) Io.File.StatError!Io.File....@@ -1791,10 +1805,11 @@ fn fileStatWasi(userdata: ?*anyopaque, file: Io.File) Io.File.StatError!Io.File.
1791 current_thread.endSyscall();1805 current_thread.endSyscall();
1792 return statFromWasi(&stat);1806 return statFromWasi(&stat);
1793 },1807 },
1794 .INTR, .CANCELED => {1808 .INTR => {
1795 try current_thread.checkCancel();1809 try current_thread.checkCancel();
1796 continue;1810 continue;
1797 },1811 },
1812 .CANCELED => return current_thread.endSyscallCanceled(),
1798 else => |e| {1813 else => |e| {
1799 current_thread.endSyscall();1814 current_thread.endSyscall();
1800 switch (e) {1815 switch (e) {
...@@ -1842,10 +1857,11 @@ fn dirAccessPosix(...@@ -1842,10 +1857,11 @@ fn dirAccessPosix(
1842 current_thread.endSyscall();1857 current_thread.endSyscall();
1843 return;1858 return;
1844 },1859 },
1845 .INTR, .CANCELED => {1860 .INTR => {
1846 try current_thread.checkCancel();1861 try current_thread.checkCancel();
1847 continue;1862 continue;
1848 },1863 },
1864 .CANCELED => return current_thread.endSyscallCanceled(),
1849 else => |e| {1865 else => |e| {
1850 current_thread.endSyscall();1866 current_thread.endSyscall();
1851 switch (e) {1867 switch (e) {
...@@ -1891,10 +1907,11 @@ fn dirAccessWasi(...@@ -1891,10 +1907,11 @@ fn dirAccessWasi(
1891 current_thread.endSyscall();1907 current_thread.endSyscall();
1892 break;1908 break;
1893 },1909 },
1894 .INTR, .CANCELED => {1910 .INTR => {
1895 try current_thread.checkCancel();1911 try current_thread.checkCancel();
1896 continue;1912 continue;
1897 },1913 },
1914 .CANCELED => return current_thread.endSyscallCanceled(),
1898 else => |e| {1915 else => |e| {
1899 current_thread.endSyscall();1916 current_thread.endSyscall();
1900 switch (e) {1917 switch (e) {
...@@ -2037,10 +2054,11 @@ fn dirCreateFilePosix(...@@ -2037,10 +2054,11 @@ fn dirCreateFilePosix(
2037 current_thread.endSyscall();2054 current_thread.endSyscall();
2038 break @intCast(rc);2055 break @intCast(rc);
2039 },2056 },
2040 .INTR, .CANCELED => {2057 .INTR => {
2041 try current_thread.checkCancel();2058 try current_thread.checkCancel();
2042 continue;2059 continue;
2043 },2060 },
2061 .CANCELED => return current_thread.endSyscallCanceled(),
2044 else => |e| {2062 else => |e| {
2045 current_thread.endSyscall();2063 current_thread.endSyscall();
2046 switch (e) {2064 switch (e) {
...@@ -2091,10 +2109,11 @@ fn dirCreateFilePosix(...@@ -2091,10 +2109,11 @@ fn dirCreateFilePosix(
2091 current_thread.endSyscall();2109 current_thread.endSyscall();
2092 break;2110 break;
2093 },2111 },
2094 .INTR, .CANCELED => {2112 .INTR => {
2095 try current_thread.checkCancel();2113 try current_thread.checkCancel();
2096 continue;2114 continue;
2097 },2115 },
2116 .CANCELED => return current_thread.endSyscallCanceled(),
2098 else => |e| {2117 else => |e| {
2099 current_thread.endSyscall();2118 current_thread.endSyscall();
2100 switch (e) {2119 switch (e) {
...@@ -2119,7 +2138,7 @@ fn dirCreateFilePosix(...@@ -2119,7 +2138,7 @@ fn dirCreateFilePosix(
2119 current_thread.endSyscall();2138 current_thread.endSyscall();
2120 break @intCast(rc);2139 break @intCast(rc);
2121 },2140 },
2122 .INTR, .CANCELED => {2141 .INTR => {
2123 try current_thread.checkCancel();2142 try current_thread.checkCancel();
2124 continue;2143 continue;
2125 },2144 },
...@@ -2139,7 +2158,7 @@ fn dirCreateFilePosix(...@@ -2139,7 +2158,7 @@ fn dirCreateFilePosix(
2139 current_thread.endSyscall();2158 current_thread.endSyscall();
2140 break;2159 break;
2141 },2160 },
2142 .INTR, .CANCELED => {2161 .INTR => {
2143 try current_thread.checkCancel();2162 try current_thread.checkCancel();
2144 continue;2163 continue;
2145 },2164 },
...@@ -2245,10 +2264,11 @@ fn dirCreateFileWasi(...@@ -2245,10 +2264,11 @@ fn dirCreateFileWasi(
2245 current_thread.endSyscall();2264 current_thread.endSyscall();
2246 return .{ .handle = fd };2265 return .{ .handle = fd };
2247 },2266 },
2248 .INTR, .CANCELED => {2267 .INTR => {
2249 try current_thread.checkCancel();2268 try current_thread.checkCancel();
2250 continue;2269 continue;
2251 },2270 },
2271 .CANCELED => return current_thread.endSyscallCanceled(),
2252 else => |e| {2272 else => |e| {
2253 current_thread.endSyscall();2273 current_thread.endSyscall();
2254 switch (e) {2274 switch (e) {
...@@ -2338,10 +2358,11 @@ fn dirOpenFilePosix(...@@ -2338,10 +2358,11 @@ fn dirOpenFilePosix(
2338 current_thread.endSyscall();2358 current_thread.endSyscall();
2339 break @intCast(rc);2359 break @intCast(rc);
2340 },2360 },
2341 .INTR, .CANCELED => {2361 .INTR => {
2342 try current_thread.checkCancel();2362 try current_thread.checkCancel();
2343 continue;2363 continue;
2344 },2364 },
2365 .CANCELED => return current_thread.endSyscallCanceled(),
2345 else => |e| {2366 else => |e| {
2346 current_thread.endSyscall();2367 current_thread.endSyscall();
2347 switch (e) {2368 switch (e) {
...@@ -2391,10 +2412,11 @@ fn dirOpenFilePosix(...@@ -2391,10 +2412,11 @@ fn dirOpenFilePosix(
2391 current_thread.endSyscall();2412 current_thread.endSyscall();
2392 break;2413 break;
2393 },2414 },
2394 .INTR, .CANCELED => {2415 .INTR => {
2395 try current_thread.checkCancel();2416 try current_thread.checkCancel();
2396 continue;2417 continue;
2397 },2418 },
2419 .CANCELED => return current_thread.endSyscallCanceled(),
2398 else => |e| {2420 else => |e| {
2399 current_thread.endSyscall();2421 current_thread.endSyscall();
2400 switch (e) {2422 switch (e) {
...@@ -2419,10 +2441,11 @@ fn dirOpenFilePosix(...@@ -2419,10 +2441,11 @@ fn dirOpenFilePosix(
2419 current_thread.endSyscall();2441 current_thread.endSyscall();
2420 break @intCast(rc);2442 break @intCast(rc);
2421 },2443 },
2422 .INTR, .CANCELED => {2444 .INTR => {
2423 try current_thread.checkCancel();2445 try current_thread.checkCancel();
2424 continue;2446 continue;
2425 },2447 },
2448 .CANCELED => return current_thread.endSyscallCanceled(),
2426 else => |err| {2449 else => |err| {
2427 current_thread.endSyscall();2450 current_thread.endSyscall();
2428 return posix.unexpectedErrno(err);2451 return posix.unexpectedErrno(err);
...@@ -2439,10 +2462,11 @@ fn dirOpenFilePosix(...@@ -2439,10 +2462,11 @@ fn dirOpenFilePosix(
2439 current_thread.endSyscall();2462 current_thread.endSyscall();
2440 break;2463 break;
2441 },2464 },
2442 .INTR, .CANCELED => {2465 .INTR => {
2443 try current_thread.checkCancel();2466 try current_thread.checkCancel();
2444 continue;2467 continue;
2445 },2468 },
2469 .CANCELED => return current_thread.endSyscallCanceled(),
2446 else => |err| {2470 else => |err| {
2447 current_thread.endSyscall();2471 current_thread.endSyscall();
2448 return posix.unexpectedErrno(err);2472 return posix.unexpectedErrno(err);
...@@ -2637,10 +2661,11 @@ fn dirOpenFileWasi(...@@ -2637,10 +2661,11 @@ fn dirOpenFileWasi(
2637 current_thread.endSyscall();2661 current_thread.endSyscall();
2638 return .{ .handle = fd };2662 return .{ .handle = fd };
2639 },2663 },
2640 .INTR, .CANCELED => {2664 .INTR => {
2641 try current_thread.checkCancel();2665 try current_thread.checkCancel();
2642 continue;2666 continue;
2643 },2667 },
2668 .CANCELED => return current_thread.endSyscallCanceled(),
2644 else => |e| {2669 else => |e| {
2645 current_thread.endSyscall();2670 current_thread.endSyscall();
2646 switch (e) {2671 switch (e) {
...@@ -2720,10 +2745,11 @@ fn dirOpenDirPosix(...@@ -2720,10 +2745,11 @@ fn dirOpenDirPosix(
2720 current_thread.endSyscall();2745 current_thread.endSyscall();
2721 return .{ .handle = @intCast(rc) };2746 return .{ .handle = @intCast(rc) };
2722 },2747 },
2723 .INTR, .CANCELED => {2748 .INTR => {
2724 try current_thread.checkCancel();2749 try current_thread.checkCancel();
2725 continue;2750 continue;
2726 },2751 },
2752 .CANCELED => return current_thread.endSyscallCanceled(),
2727 else => |e| {2753 else => |e| {
2728 current_thread.endSyscall();2754 current_thread.endSyscall();
2729 switch (e) {2755 switch (e) {
...@@ -2772,10 +2798,11 @@ fn dirOpenDirHaiku(...@@ -2772,10 +2798,11 @@ fn dirOpenDirHaiku(
2772 return .{ .handle = rc };2798 return .{ .handle = rc };
2773 }2799 }
2774 switch (@as(posix.E, @enumFromInt(rc))) {2800 switch (@as(posix.E, @enumFromInt(rc))) {
2775 .INTR, .CANCELED => {2801 .INTR => {
2776 try current_thread.checkCancel();2802 try current_thread.checkCancel();
2777 continue;2803 continue;
2778 },2804 },
2805 .CANCELED => return current_thread.endSyscallCanceled(),
2779 else => |e| {2806 else => |e| {
2780 current_thread.endSyscall();2807 current_thread.endSyscall();
2781 switch (e) {2808 switch (e) {
...@@ -2916,10 +2943,11 @@ fn dirOpenDirWasi(...@@ -2916,10 +2943,11 @@ fn dirOpenDirWasi(
2916 current_thread.endSyscall();2943 current_thread.endSyscall();
2917 return .{ .handle = fd };2944 return .{ .handle = fd };
2918 },2945 },
2919 .INTR, .CANCELED => {2946 .INTR => {
2920 try current_thread.checkCancel();2947 try current_thread.checkCancel();
2921 continue;2948 continue;
2922 },2949 },
2950 .CANCELED => return current_thread.endSyscallCanceled(),
2923 else => |e| {2951 else => |e| {
2924 current_thread.endSyscall();2952 current_thread.endSyscall();
2925 switch (e) {2953 switch (e) {
...@@ -2982,10 +3010,11 @@ fn fileReadStreamingPosix(userdata: ?*anyopaque, file: Io.File, data: [][]u8) Io...@@ -2982,10 +3010,11 @@ fn fileReadStreamingPosix(userdata: ?*anyopaque, file: Io.File, data: [][]u8) Io
2982 current_thread.endSyscall();3010 current_thread.endSyscall();
2983 return nread;3011 return nread;
2984 },3012 },
2985 .INTR, .CANCELED => {3013 .INTR => {
2986 try current_thread.checkCancel();3014 try current_thread.checkCancel();
2987 continue;3015 continue;
2988 },3016 },
3017 .CANCELED => return current_thread.endSyscallCanceled(),
2989 else => |e| {3018 else => |e| {
2990 current_thread.endSyscall();3019 current_thread.endSyscall();
2991 switch (e) {3020 switch (e) {
...@@ -3015,10 +3044,11 @@ fn fileReadStreamingPosix(userdata: ?*anyopaque, file: Io.File, data: [][]u8) Io...@@ -3015,10 +3044,11 @@ fn fileReadStreamingPosix(userdata: ?*anyopaque, file: Io.File, data: [][]u8) Io
3015 current_thread.endSyscall();3044 current_thread.endSyscall();
3016 return @intCast(rc);3045 return @intCast(rc);
3017 },3046 },
3018 .INTR, .CANCELED => {3047 .INTR => {
3019 try current_thread.checkCancel();3048 try current_thread.checkCancel();
3020 continue;3049 continue;
3021 },3050 },
3051 .CANCELED => return current_thread.endSyscallCanceled(),
3022 else => |e| {3052 else => |e| {
3023 current_thread.endSyscall();3053 current_thread.endSyscall();
3024 switch (e) {3054 switch (e) {
...@@ -3100,10 +3130,11 @@ fn fileReadPositionalPosix(userdata: ?*anyopaque, file: Io.File, data: [][]u8, o...@@ -3100,10 +3130,11 @@ fn fileReadPositionalPosix(userdata: ?*anyopaque, file: Io.File, data: [][]u8, o
3100 current_thread.endSyscall();3130 current_thread.endSyscall();
3101 return nread;3131 return nread;
3102 },3132 },
3103 .INTR, .CANCELED => {3133 .INTR => {
3104 try current_thread.checkCancel();3134 try current_thread.checkCancel();
3105 continue;3135 continue;
3106 },3136 },
3137 .CANCELED => return current_thread.endSyscallCanceled(),
3107 else => |e| {3138 else => |e| {
3108 current_thread.endSyscall();3139 current_thread.endSyscall();
3109 switch (e) {3140 switch (e) {
...@@ -3137,10 +3168,11 @@ fn fileReadPositionalPosix(userdata: ?*anyopaque, file: Io.File, data: [][]u8, o...@@ -3137,10 +3168,11 @@ fn fileReadPositionalPosix(userdata: ?*anyopaque, file: Io.File, data: [][]u8, o
3137 current_thread.endSyscall();3168 current_thread.endSyscall();
3138 return @bitCast(rc);3169 return @bitCast(rc);
3139 },3170 },
3140 .INTR, .CANCELED => {3171 .INTR => {
3141 try current_thread.checkCancel();3172 try current_thread.checkCancel();
3142 continue;3173 continue;
3143 },3174 },
3175 .CANCELED => return current_thread.endSyscallCanceled(),
3144 else => |e| {3176 else => |e| {
3145 current_thread.endSyscall();3177 current_thread.endSyscall();
3146 switch (e) {3178 switch (e) {
...@@ -3238,10 +3270,11 @@ fn fileSeekTo(userdata: ?*anyopaque, file: Io.File, offset: u64) Io.File.SeekErr...@@ -3238,10 +3270,11 @@ fn fileSeekTo(userdata: ?*anyopaque, file: Io.File, offset: u64) Io.File.SeekErr
3238 current_thread.endSyscall();3270 current_thread.endSyscall();
3239 return;3271 return;
3240 },3272 },
3241 .INTR, .CANCELED => {3273 .INTR => {
3242 try current_thread.checkCancel();3274 try current_thread.checkCancel();
3243 continue;3275 continue;
3244 },3276 },
3277 .CANCELED => return current_thread.endSyscallCanceled(),
3245 else => |e| {3278 else => |e| {
3246 current_thread.endSyscall();3279 current_thread.endSyscall();
3247 switch (e) {3280 switch (e) {
...@@ -3270,10 +3303,11 @@ fn fileSeekTo(userdata: ?*anyopaque, file: Io.File, offset: u64) Io.File.SeekErr...@@ -3270,10 +3303,11 @@ fn fileSeekTo(userdata: ?*anyopaque, file: Io.File, offset: u64) Io.File.SeekErr
3270 current_thread.endSyscall();3303 current_thread.endSyscall();
3271 return;3304 return;
3272 },3305 },
3273 .INTR, .CANCELED => {3306 .INTR => {
3274 try current_thread.checkCancel();3307 try current_thread.checkCancel();
3275 continue;3308 continue;
3276 },3309 },
3310 .CANCELED => return current_thread.endSyscallCanceled(),
3277 else => |e| {3311 else => |e| {
3278 current_thread.endSyscall();3312 current_thread.endSyscall();
3279 switch (e) {3313 switch (e) {
...@@ -3298,10 +3332,11 @@ fn fileSeekTo(userdata: ?*anyopaque, file: Io.File, offset: u64) Io.File.SeekErr...@@ -3298,10 +3332,11 @@ fn fileSeekTo(userdata: ?*anyopaque, file: Io.File, offset: u64) Io.File.SeekErr
3298 current_thread.endSyscall();3332 current_thread.endSyscall();
3299 return;3333 return;
3300 },3334 },
3301 .INTR, .CANCELED => {3335 .INTR => {
3302 try current_thread.checkCancel();3336 try current_thread.checkCancel();
3303 continue;3337 continue;
3304 },3338 },
3339 .CANCELED => return current_thread.endSyscallCanceled(),
3305 else => |e| {3340 else => |e| {
3306 current_thread.endSyscall();3341 current_thread.endSyscall();
3307 switch (e) {3342 switch (e) {
...@@ -3453,10 +3488,11 @@ fn sleepLinux(userdata: ?*anyopaque, timeout: Io.Timeout) Io.SleepError!void {...@@ -3453,10 +3488,11 @@ fn sleepLinux(userdata: ?*anyopaque, timeout: Io.Timeout) Io.SleepError!void {
3453 current_thread.endSyscall();3488 current_thread.endSyscall();
3454 return;3489 return;
3455 },3490 },
3456 .INTR, .CANCELED => {3491 .INTR => {
3457 try current_thread.checkCancel();3492 try current_thread.checkCancel();
3458 continue;3493 continue;
3459 },3494 },
3495 .CANCELED => return current_thread.endSyscallCanceled(),
3460 else => |e| {3496 else => |e| {
3461 current_thread.endSyscall();3497 current_thread.endSyscall();
3462 switch (e) {3498 switch (e) {
...@@ -3530,10 +3566,11 @@ fn sleepPosix(userdata: ?*anyopaque, timeout: Io.Timeout) Io.SleepError!void {...@@ -3530,10 +3566,11 @@ fn sleepPosix(userdata: ?*anyopaque, timeout: Io.Timeout) Io.SleepError!void {
3530 try current_thread.beginSyscall();3566 try current_thread.beginSyscall();
3531 while (true) {3567 while (true) {
3532 switch (posix.errno(posix.system.nanosleep(&timespec, &timespec))) {3568 switch (posix.errno(posix.system.nanosleep(&timespec, &timespec))) {
3533 .INTR, .CANCELED => {3569 .INTR => {
3534 try current_thread.checkCancel();3570 try current_thread.checkCancel();
3535 continue;3571 continue;
3536 },3572 },
3573 .CANCELED => return current_thread.endSyscallCanceled(),
3537 // This prong handles success as well as unexpected errors.3574 // This prong handles success as well as unexpected errors.
3538 else => return current_thread.endSyscall(),3575 else => return current_thread.endSyscall(),
3539 }3576 }
...@@ -3603,10 +3640,11 @@ fn netListenIpPosix(...@@ -3603,10 +3640,11 @@ fn netListenIpPosix(
3603 current_thread.endSyscall();3640 current_thread.endSyscall();
3604 break;3641 break;
3605 },3642 },
3606 .INTR, .CANCELED => {3643 .INTR => {
3607 try current_thread.checkCancel();3644 try current_thread.checkCancel();
3608 continue;3645 continue;
3609 },3646 },
3647 .CANCELED => return current_thread.endSyscallCanceled(),
3610 else => |e| {3648 else => |e| {
3611 current_thread.endSyscall();3649 current_thread.endSyscall();
3612 switch (e) {3650 switch (e) {
...@@ -3766,10 +3804,11 @@ fn netListenUnixPosix(...@@ -3766,10 +3804,11 @@ fn netListenUnixPosix(
3766 current_thread.endSyscall();3804 current_thread.endSyscall();
3767 break;3805 break;
3768 },3806 },
3769 .INTR, .CANCELED => {3807 .INTR => {
3770 try current_thread.checkCancel();3808 try current_thread.checkCancel();
3771 continue;3809 continue;
3772 },3810 },
3811 .CANCELED => return current_thread.endSyscallCanceled(),
3773 else => |e| {3812 else => |e| {
3774 current_thread.endSyscall();3813 current_thread.endSyscall();
3775 switch (e) {3814 switch (e) {
...@@ -3889,10 +3928,11 @@ fn posixBindUnix(...@@ -3889,10 +3928,11 @@ fn posixBindUnix(
3889 current_thread.endSyscall();3928 current_thread.endSyscall();
3890 break;3929 break;
3891 },3930 },
3892 .INTR, .CANCELED => {3931 .INTR => {
3893 try current_thread.checkCancel();3932 try current_thread.checkCancel();
3894 continue;3933 continue;
3895 },3934 },
3935 .CANCELED => return current_thread.endSyscallCanceled(),
3896 else => |e| {3936 else => |e| {
3897 current_thread.endSyscall();3937 current_thread.endSyscall();
3898 switch (e) {3938 switch (e) {
...@@ -3933,10 +3973,11 @@ fn posixBind(...@@ -3933,10 +3973,11 @@ fn posixBind(
3933 current_thread.endSyscall();3973 current_thread.endSyscall();
3934 break;3974 break;
3935 },3975 },
3936 .INTR, .CANCELED => {3976 .INTR => {
3937 try current_thread.checkCancel();3977 try current_thread.checkCancel();
3938 continue;3978 continue;
3939 },3979 },
3980 .CANCELED => return current_thread.endSyscallCanceled(),
3940 else => |e| {3981 else => |e| {
3941 current_thread.endSyscall();3982 current_thread.endSyscall();
3942 switch (e) {3983 switch (e) {
...@@ -3968,10 +4009,11 @@ fn posixConnect(...@@ -3968,10 +4009,11 @@ fn posixConnect(
3968 current_thread.endSyscall();4009 current_thread.endSyscall();
3969 return;4010 return;
3970 },4011 },
3971 .INTR, .CANCELED => {4012 .INTR => {
3972 try current_thread.checkCancel();4013 try current_thread.checkCancel();
3973 continue;4014 continue;
3974 },4015 },
4016 .CANCELED => return current_thread.endSyscallCanceled(),
3975 else => |e| {4017 else => |e| {
3976 current_thread.endSyscall();4018 current_thread.endSyscall();
3977 switch (e) {4019 switch (e) {
...@@ -4014,10 +4056,11 @@ fn posixConnectUnix(...@@ -4014,10 +4056,11 @@ fn posixConnectUnix(
4014 current_thread.endSyscall();4056 current_thread.endSyscall();
4015 return;4057 return;
4016 },4058 },
4017 .INTR, .CANCELED => {4059 .INTR => {
4018 try current_thread.checkCancel();4060 try current_thread.checkCancel();
4019 continue;4061 continue;
4020 },4062 },
4063 .CANCELED => return current_thread.endSyscallCanceled(),
4021 else => |e| {4064 else => |e| {
4022 current_thread.endSyscall();4065 current_thread.endSyscall();
4023 switch (e) {4066 switch (e) {
...@@ -4058,10 +4101,11 @@ fn posixGetSockName(...@@ -4058,10 +4101,11 @@ fn posixGetSockName(
4058 current_thread.endSyscall();4101 current_thread.endSyscall();
4059 break;4102 break;
4060 },4103 },
4061 .INTR, .CANCELED => {4104 .INTR => {
4062 try current_thread.checkCancel();4105 try current_thread.checkCancel();
4063 continue;4106 continue;
4064 },4107 },
4108 .CANCELED => return current_thread.endSyscallCanceled(),
4065 else => |e| {4109 else => |e| {
4066 current_thread.endSyscall();4110 current_thread.endSyscall();
4067 switch (e) {4111 switch (e) {
...@@ -4125,10 +4169,11 @@ fn setSocketOption(current_thread: *Thread, fd: posix.fd_t, level: i32, opt_name...@@ -4125,10 +4169,11 @@ fn setSocketOption(current_thread: *Thread, fd: posix.fd_t, level: i32, opt_name
4125 current_thread.endSyscall();4169 current_thread.endSyscall();
4126 return;4170 return;
4127 },4171 },
4128 .INTR, .CANCELED => {4172 .INTR => {
4129 try current_thread.checkCancel();4173 try current_thread.checkCancel();
4130 continue;4174 continue;
4131 },4175 },
4176 .CANCELED => return current_thread.endSyscallCanceled(),
4132 else => |e| {4177 else => |e| {
4133 current_thread.endSyscall();4178 current_thread.endSyscall();
4134 switch (e) {4179 switch (e) {
...@@ -4457,7 +4502,8 @@ fn openSocketPosix(...@@ -4457,7 +4502,8 @@ fn openSocketPosix(
4457 try current_thread.checkCancel();4502 try current_thread.checkCancel();
4458 switch (posix.errno(posix.system.fcntl(fd, posix.F.SETFD, @as(usize, posix.FD_CLOEXEC)))) {4503 switch (posix.errno(posix.system.fcntl(fd, posix.F.SETFD, @as(usize, posix.FD_CLOEXEC)))) {
4459 .SUCCESS => break,4504 .SUCCESS => break,
4460 .INTR, .CANCELED => continue,4505 .INTR => continue,
4506 .CANCELED => return current_thread.endSyscallCanceled(),
4461 else => |err| {4507 else => |err| {
4462 current_thread.endSyscall();4508 current_thread.endSyscall();
4463 return posix.unexpectedErrno(err);4509 return posix.unexpectedErrno(err);
...@@ -4467,10 +4513,11 @@ fn openSocketPosix(...@@ -4467,10 +4513,11 @@ fn openSocketPosix(
4467 current_thread.endSyscall();4513 current_thread.endSyscall();
4468 break fd;4514 break fd;
4469 },4515 },
4470 .INTR, .CANCELED => {4516 .INTR => {
4471 try current_thread.checkCancel();4517 try current_thread.checkCancel();
4472 continue;4518 continue;
4473 },4519 },
4520 .CANCELED => return current_thread.endSyscallCanceled(),
4474 else => |e| {4521 else => |e| {
4475 current_thread.endSyscall();4522 current_thread.endSyscall();
4476 switch (e) {4523 switch (e) {
...@@ -4558,7 +4605,7 @@ fn netAcceptPosix(userdata: ?*anyopaque, listen_fd: net.Socket.Handle) net.Serve...@@ -4558,7 +4605,7 @@ fn netAcceptPosix(userdata: ?*anyopaque, listen_fd: net.Socket.Handle) net.Serve
4558 try current_thread.checkCancel();4605 try current_thread.checkCancel();
4559 switch (posix.errno(posix.system.fcntl(fd, posix.F.SETFD, @as(usize, posix.FD_CLOEXEC)))) {4606 switch (posix.errno(posix.system.fcntl(fd, posix.F.SETFD, @as(usize, posix.FD_CLOEXEC)))) {
4560 .SUCCESS => break,4607 .SUCCESS => break,
4561 .INTR, .CANCELED => continue,4608 .INTR => continue,
4562 else => |err| {4609 else => |err| {
4563 current_thread.endSyscall();4610 current_thread.endSyscall();
4564 return posix.unexpectedErrno(err);4611 return posix.unexpectedErrno(err);
...@@ -4568,10 +4615,11 @@ fn netAcceptPosix(userdata: ?*anyopaque, listen_fd: net.Socket.Handle) net.Serve...@@ -4568,10 +4615,11 @@ fn netAcceptPosix(userdata: ?*anyopaque, listen_fd: net.Socket.Handle) net.Serve
4568 current_thread.endSyscall();4615 current_thread.endSyscall();
4569 break fd;4616 break fd;
4570 },4617 },
4571 .INTR, .CANCELED => {4618 .INTR => {
4572 try current_thread.checkCancel();4619 try current_thread.checkCancel();
4573 continue;4620 continue;
4574 },4621 },
4622 .CANCELED => return current_thread.endSyscallCanceled(),
4575 else => |e| {4623 else => |e| {
4576 current_thread.endSyscall();4624 current_thread.endSyscall();
4577 switch (e) {4625 switch (e) {
...@@ -4676,10 +4724,11 @@ fn netReadPosix(userdata: ?*anyopaque, fd: net.Socket.Handle, data: [][]u8) net....@@ -4676,10 +4724,11 @@ fn netReadPosix(userdata: ?*anyopaque, fd: net.Socket.Handle, data: [][]u8) net.
4676 current_thread.endSyscall();4724 current_thread.endSyscall();
4677 return n;4725 return n;
4678 },4726 },
4679 .INTR, .CANCELED => {4727 .INTR => {
4680 try current_thread.checkCancel();4728 try current_thread.checkCancel();
4681 continue;4729 continue;
4682 },4730 },
4731 .CANCELED => return current_thread.endSyscallCanceled(),
4683 else => |e| {4732 else => |e| {
4684 current_thread.endSyscall();4733 current_thread.endSyscall();
4685 switch (e) {4734 switch (e) {
...@@ -4708,10 +4757,11 @@ fn netReadPosix(userdata: ?*anyopaque, fd: net.Socket.Handle, data: [][]u8) net....@@ -4708,10 +4757,11 @@ fn netReadPosix(userdata: ?*anyopaque, fd: net.Socket.Handle, data: [][]u8) net.
4708 current_thread.endSyscall();4757 current_thread.endSyscall();
4709 return @intCast(rc);4758 return @intCast(rc);
4710 },4759 },
4711 .INTR, .CANCELED => {4760 .INTR => {
4712 try current_thread.checkCancel();4761 try current_thread.checkCancel();
4713 continue;4762 continue;
4714 },4763 },
4764 .CANCELED => return current_thread.endSyscallCanceled(),
4715 else => |e| {4765 else => |e| {
4716 current_thread.endSyscall();4766 current_thread.endSyscall();
4717 switch (e) {4767 switch (e) {
...@@ -4943,10 +4993,11 @@ fn netSendOne(...@@ -4943,10 +4993,11 @@ fn netSendOne(
4943 message.data_len = @intCast(rc);4993 message.data_len = @intCast(rc);
4944 return;4994 return;
4945 },4995 },
4946 .INTR, .CANCELED => {4996 .INTR => {
4947 try current_thread.checkCancel();4997 try current_thread.checkCancel();
4948 continue;4998 continue;
4949 },4999 },
5000 .CANCELED => return current_thread.endSyscallCanceled(),
4950 else => |e| {5001 else => |e| {
4951 current_thread.endSyscall();5002 current_thread.endSyscall();
4952 switch (e) {5003 switch (e) {
...@@ -5019,10 +5070,11 @@ fn netSendMany(...@@ -5019,10 +5070,11 @@ fn netSendMany(
5019 }5070 }
5020 return n;5071 return n;
5021 },5072 },
5022 .INTR, .CANCELED => {5073 .INTR => {
5023 try current_thread.checkCancel();5074 try current_thread.checkCancel();
5024 continue;5075 continue;
5025 },5076 },
5077 .CANCELED => return current_thread.endSyscallCanceled(),
5026 else => |e| {5078 else => |e| {
5027 current_thread.endSyscall();5079 current_thread.endSyscall();
5028 switch (e) {5080 switch (e) {
...@@ -5154,7 +5206,8 @@ fn netReceivePosix(...@@ -5154,7 +5206,8 @@ fn netReceivePosix(
5154 }5206 }
5155 continue :recv;5207 continue :recv;
5156 },5208 },
5157 .INTR, .CANCELED => continue,5209 .INTR => continue,
5210 .CANCELED => return .{ current_thread.endSyscallCanceled(), message_i },
51585211
5159 .FAULT => |err| return .{ errnoBug(err), message_i },5212 .FAULT => |err| return .{ errnoBug(err), message_i },
5160 .INVAL => |err| return .{ errnoBug(err), message_i },5213 .INVAL => |err| return .{ errnoBug(err), message_i },
...@@ -5162,7 +5215,8 @@ fn netReceivePosix(...@@ -5162,7 +5215,8 @@ fn netReceivePosix(
5162 else => |err| return .{ posix.unexpectedErrno(err), message_i },5215 else => |err| return .{ posix.unexpectedErrno(err), message_i },
5163 }5216 }
5164 },5217 },
5165 .INTR, .CANCELED => continue,5218 .INTR => continue,
5219 .CANCELED => return .{ current_thread.endSyscallCanceled(), message_i },
51665220
5167 .BADF => |err| return .{ errnoBug(err), message_i },5221 .BADF => |err| return .{ errnoBug(err), message_i },
5168 .NFILE => return .{ error.SystemFdQuotaExceeded, message_i },5222 .NFILE => return .{ error.SystemFdQuotaExceeded, message_i },
...@@ -5277,10 +5331,11 @@ fn netWritePosix(...@@ -5277,10 +5331,11 @@ fn netWritePosix(
5277 current_thread.endSyscall();5331 current_thread.endSyscall();
5278 return @intCast(rc);5332 return @intCast(rc);
5279 },5333 },
5280 .INTR, .CANCELED => {5334 .INTR => {
5281 try current_thread.checkCancel();5335 try current_thread.checkCancel();
5282 continue;5336 continue;
5283 },5337 },
5338 .CANCELED => return current_thread.endSyscallCanceled(),
5284 else => |e| {5339 else => |e| {
5285 current_thread.endSyscall();5340 current_thread.endSyscall();
5286 switch (e) {5341 switch (e) {
...@@ -5378,7 +5433,8 @@ fn netWriteWindows(...@@ -5378,7 +5433,8 @@ fn netWriteWindows(
5378 else => |err| err,5433 else => |err| err,
5379 };5434 };
5380 switch (wsa_error) {5435 switch (wsa_error) {
5381 .EINTR, .ECANCELLED, .E_CANCELLED, .OPERATION_ABORTED => continue,5436 .EINTR => continue,
5437 .ECANCELLED, .E_CANCELLED, .OPERATION_ABORTED => return current_thread.endSyscallCanceled(),
5382 .NOTINITIALISED => {5438 .NOTINITIALISED => {
5383 try initializeWsa(t);5439 try initializeWsa(t);
5384 continue;5440 continue;
...@@ -5486,10 +5542,11 @@ fn netInterfaceNameResolve(...@@ -5486,10 +5542,11 @@ fn netInterfaceNameResolve(
5486 current_thread.endSyscall();5542 current_thread.endSyscall();
5487 return .{ .index = @bitCast(ifr.ifru.ivalue) };5543 return .{ .index = @bitCast(ifr.ifru.ivalue) };
5488 },5544 },
5489 .INTR, .CANCELED => {5545 .INTR => {
5490 try current_thread.checkCancel();5546 try current_thread.checkCancel();
5491 continue;5547 continue;
5492 },5548 },
5549 .CANCELED => return current_thread.endSyscallCanceled(),
5493 else => |e| {5550 else => |e| {
5494 current_thread.endSyscall();5551 current_thread.endSyscall();
5495 switch (e) {5552 switch (e) {
...@@ -5786,10 +5843,11 @@ fn netLookupFallible(...@@ -5786,10 +5843,11 @@ fn netLookupFallible(
5786 break;5843 break;
5787 },5844 },
5788 .SYSTEM => switch (posix.errno(-1)) {5845 .SYSTEM => switch (posix.errno(-1)) {
5789 .INTR, .CANCELED => {5846 .INTR => {
5790 try current_thread.checkCancel();5847 try current_thread.checkCancel();
5791 continue;5848 continue;
5792 },5849 },
5850 .CANCELED => return current_thread.endSyscallCanceled(),
5793 else => |e| {5851 else => |e| {
5794 current_thread.endSyscall();5852 current_thread.endSyscall();
5795 return posix.unexpectedErrno(e);5853 return posix.unexpectedErrno(e);