| ... | ... | @@ -1755,7 +1755,7 @@ const getrandom_use_libc = @TypeOf(posix.system.getrandom) != void and (native_o |
| 1755 | 1755 | .patch = 0, |
| 1756 | 1756 | })); |
| 1757 | 1757 | |
| 1758 | | const use_dev_urandom = getrandom_use_libc and native_os == .linux; |
| 1758 | const use_dev_urandom = !getrandom_use_libc and native_os == .linux; |
| 1759 | 1759 | |
| 1760 | 1760 | fn async( |
| 1761 | 1761 | userdata: ?*anyopaque, |
| ... | ... | @@ -3711,10 +3711,12 @@ fn dirOpenFilePosix( |
| 3711 | 3711 | }, |
| 3712 | 3712 | }; |
| 3713 | 3713 | |
| 3714 | const mode: posix.mode_t = 0; |
| 3715 | |
| 3714 | 3716 | const fd: posix.fd_t = fd: { |
| 3715 | 3717 | const syscall: Syscall = try .start(); |
| 3716 | 3718 | while (true) { |
| 3717 | | const rc = openat_sym(dir.handle, sub_path_posix, os_flags, @as(posix.mode_t, 0)); |
| 3719 | const rc = openat_sym(dir.handle, sub_path_posix, os_flags, mode); |
| 3718 | 3720 | switch (posix.errno(rc)) { |
| 3719 | 3721 | .SUCCESS => { |
| 3720 | 3722 | syscall.finish(); |
| ... | ... | @@ -4143,9 +4145,11 @@ fn dirOpenDirPosix( |
| 4143 | 4145 | if (@hasField(posix.O, "PATH") and !options.iterate) |
| 4144 | 4146 | flags.PATH = true; |
| 4145 | 4147 | |
| 4148 | const mode: posix.mode_t = 0; |
| 4149 | |
| 4146 | 4150 | const syscall: Syscall = try .start(); |
| 4147 | 4151 | while (true) { |
| 4148 | | const rc = openat_sym(dir.handle, sub_path_posix, flags, @as(usize, 0)); |
| 4152 | const rc = openat_sym(dir.handle, sub_path_posix, flags, mode); |
| 4149 | 4153 | switch (posix.errno(rc)) { |
| 4150 | 4154 | .SUCCESS => { |
| 4151 | 4155 | syscall.finish(); |
| ... | ... | @@ -15270,7 +15274,7 @@ fn randomSecure(userdata: ?*anyopaque, buffer: []u8) Io.RandomSecureError!void { |
| 15270 | 15274 | } |
| 15271 | 15275 | } |
| 15272 | 15276 | |
| 15273 | | fn getRandomFd(t: *Threaded) posix.fd_t { |
| 15277 | fn getRandomFd(t: *Threaded) Io.RandomSecureError!posix.fd_t { |
| 15274 | 15278 | { |
| 15275 | 15279 | t.mutex.lock(); |
| 15276 | 15280 | defer t.mutex.unlock(); |
| ... | ... | @@ -15279,13 +15283,15 @@ fn getRandomFd(t: *Threaded) posix.fd_t { |
| 15279 | 15283 | if (t.random_file.fd != -1) return t.random_file.fd; |
| 15280 | 15284 | } |
| 15281 | 15285 | |
| 15286 | const mode: posix.mode_t = 0; |
| 15287 | |
| 15282 | 15288 | const fd: posix.fd_t = fd: { |
| 15283 | 15289 | const syscall: Syscall = try .start(); |
| 15284 | 15290 | while (true) { |
| 15285 | 15291 | const rc = openat_sym(posix.AT.FDCWD, "/dev/urandom", .{ |
| 15286 | 15292 | .ACCMODE = .RDONLY, |
| 15287 | 15293 | .CLOEXEC = true, |
| 15288 | | }, 0); |
| 15294 | }, mode); |
| 15289 | 15295 | switch (posix.errno(rc)) { |
| 15290 | 15296 | .SUCCESS => { |
| 15291 | 15297 | syscall.finish(); |
| ... | ... | @@ -15295,11 +15301,7 @@ fn getRandomFd(t: *Threaded) posix.fd_t { |
| 15295 | 15301 | try syscall.checkCancel(); |
| 15296 | 15302 | continue; |
| 15297 | 15303 | }, |
| 15298 | | else => { |
| 15299 | | syscall.endSyscall(); |
| 15300 | | t.random_file.fd = -2; |
| 15301 | | return error.EntropyUnavailable; |
| 15302 | | }, |
| 15304 | else => return syscall.fail(error.EntropyUnavailable), |
| 15303 | 15305 | } |
| 15304 | 15306 | } |
| 15305 | 15307 | }; |
| ... | ... | @@ -15314,7 +15316,7 @@ fn getRandomFd(t: *Threaded) posix.fd_t { |
| 15314 | 15316 | switch (sys.errno(sys.statx(fd, "", std.os.linux.AT.EMPTY_PATH, .{ .TYPE = true }, &statx))) { |
| 15315 | 15317 | .SUCCESS => { |
| 15316 | 15318 | syscall.finish(); |
| 15317 | | if (!statx.mask.TYPE) return error.Unexpected; |
| 15319 | if (!statx.mask.TYPE) return error.EntropyUnavailable; |
| 15318 | 15320 | t.mutex.lock(); // Another thread might have won the race. |
| 15319 | 15321 | defer t.mutex.unlock(); |
| 15320 | 15322 | if (t.random_file.fd >= 0) { |
| ... | ... | @@ -15332,10 +15334,7 @@ fn getRandomFd(t: *Threaded) posix.fd_t { |
| 15332 | 15334 | try syscall.checkCancel(); |
| 15333 | 15335 | continue; |
| 15334 | 15336 | }, |
| 15335 | | else => { |
| 15336 | | t.random_file.fd = -2; |
| 15337 | | return error.EntropyUnavailable; |
| 15338 | | }, |
| 15337 | else => return syscall.fail(error.EntropyUnavailable), |
| 15339 | 15338 | } |
| 15340 | 15339 | } |
| 15341 | 15340 | }, |
| ... | ... | @@ -15346,6 +15345,8 @@ fn getRandomFd(t: *Threaded) posix.fd_t { |
| 15346 | 15345 | switch (posix.errno(fstat_sym(fd, &stat))) { |
| 15347 | 15346 | .SUCCESS => { |
| 15348 | 15347 | syscall.finish(); |
| 15348 | t.mutex.lock(); // Another thread might have won the race. |
| 15349 | defer t.mutex.unlock(); |
| 15349 | 15350 | if (t.random_file.fd >= 0) { |
| 15350 | 15351 | posix.close(fd); |
| 15351 | 15352 | return t.random_file.fd; |
| ... | ... | @@ -15361,10 +15362,7 @@ fn getRandomFd(t: *Threaded) posix.fd_t { |
| 15361 | 15362 | try syscall.checkCancel(); |
| 15362 | 15363 | continue; |
| 15363 | 15364 | }, |
| 15364 | | else => { |
| 15365 | | t.random_file.fd = -2; |
| 15366 | | return error.EntropyUnavailable; |
| 15367 | | }, |
| 15365 | else => return syscall.fail(error.EntropyUnavailable), |
| 15368 | 15366 | } |
| 15369 | 15367 | } |
| 15370 | 15368 | }, |