authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-01-16 15:03:25-08:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2024-01-16 15:03:25-08:00
loga338c279f82bfeb68e37b40cd4fc59557336b6ce
treee4a99e0758638e49f96a16aed15f6280ecb6676b
parent1ce12db5c8b8d0369d431cbfa90fa6dc4c0141ce
parent194ed308259e49af3f4725659e22ccd7457404e0
signaturebadge-check Signed by PGP key B5690EEEBB952194

Merge pull request #15565 from xEgoist/spawnWindows

child_process: Add write and inheritable access to the null handle

2 files changed, 8 insertions(+), 7 deletions(-)

lib/std/child_process.zig+4-6
......@@ -650,7 +650,7 @@ pub const ChildProcess = struct {
650650 }
651651
652652 fn spawnWindows(self: *ChildProcess) SpawnError!void {
653 const saAttr = windows.SECURITY_ATTRIBUTES{
653 var saAttr = windows.SECURITY_ATTRIBUTES{
654654 .nLength = @sizeOf(windows.SECURITY_ATTRIBUTES),
655655 .bInheritHandle = windows.TRUE,
656656 .lpSecurityDescriptor = null,
......@@ -661,8 +661,9 @@ pub const ChildProcess = struct {
661661 const nul_handle = if (any_ignore)
662662 // "\Device\Null" or "\??\NUL"
663663 windows.OpenFile(&[_]u16{ '\\', 'D', 'e', 'v', 'i', 'c', 'e', '\\', 'N', 'u', 'l', 'l' }, .{
664 .access_mask = windows.GENERIC_READ | windows.SYNCHRONIZE,
665 .share_access = windows.FILE_SHARE_READ,
664 .access_mask = windows.GENERIC_READ | windows.GENERIC_WRITE | windows.SYNCHRONIZE,
665 .share_access = windows.FILE_SHARE_READ | windows.FILE_SHARE_WRITE,
666 .sa = &saAttr,
666667 .creation = windows.OPEN_EXISTING,
667668 .io_mode = .blocking,
668669 }) catch |err| switch (err) {
......@@ -680,9 +681,6 @@ pub const ChildProcess = struct {
680681 defer {
681682 if (any_ignore) os.close(nul_handle);
682683 }
683 if (any_ignore) {
684 try windows.SetHandleInformation(nul_handle, windows.HANDLE_FLAG_INHERIT, 0);
685 }
686684
687685 var g_hChildStd_IN_Rd: ?windows.HANDLE = null;
688686 var g_hChildStd_IN_Wr: ?windows.HANDLE = null;
lib/std/os/windows.zig+4-1
......@@ -86,7 +86,10 @@ pub fn OpenFile(sub_path_w: []const u16, options: OpenFileOptions) OpenError!HAN
8686 var attr = OBJECT_ATTRIBUTES{
8787 .Length = @sizeOf(OBJECT_ATTRIBUTES),
8888 .RootDirectory = if (std.fs.path.isAbsoluteWindowsWTF16(sub_path_w)) null else options.dir,
89 .Attributes = 0, // Note we do not use OBJ_CASE_INSENSITIVE here.
89 .Attributes = if (options.sa) |ptr| blk: { // Note we do not use OBJ_CASE_INSENSITIVE here.
90 const inherit: ULONG = if (ptr.bInheritHandle == TRUE) OBJ_INHERIT else 0;
91 break :blk inherit;
92 } else 0,
9093 .ObjectName = &nt_name,
9194 .SecurityDescriptor = if (options.sa) |ptr| ptr.lpSecurityDescriptor else null,
9295 .SecurityQualityOfService = null,