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 {...@@ -650,7 +650,7 @@ pub const ChildProcess = struct {
650 }650 }
651651
652 fn spawnWindows(self: *ChildProcess) SpawnError!void {652 fn spawnWindows(self: *ChildProcess) SpawnError!void {
653 const saAttr = windows.SECURITY_ATTRIBUTES{653 var saAttr = windows.SECURITY_ATTRIBUTES{
654 .nLength = @sizeOf(windows.SECURITY_ATTRIBUTES),654 .nLength = @sizeOf(windows.SECURITY_ATTRIBUTES),
655 .bInheritHandle = windows.TRUE,655 .bInheritHandle = windows.TRUE,
656 .lpSecurityDescriptor = null,656 .lpSecurityDescriptor = null,
...@@ -661,8 +661,9 @@ pub const ChildProcess = struct {...@@ -661,8 +661,9 @@ pub const ChildProcess = struct {
661 const nul_handle = if (any_ignore)661 const nul_handle = if (any_ignore)
662 // "\Device\Null" or "\??\NUL"662 // "\Device\Null" or "\??\NUL"
663 windows.OpenFile(&[_]u16{ '\\', 'D', 'e', 'v', 'i', 'c', 'e', '\\', 'N', 'u', 'l', 'l' }, .{663 windows.OpenFile(&[_]u16{ '\\', 'D', 'e', 'v', 'i', 'c', 'e', '\\', 'N', 'u', 'l', 'l' }, .{
664 .access_mask = windows.GENERIC_READ | windows.SYNCHRONIZE,664 .access_mask = windows.GENERIC_READ | windows.GENERIC_WRITE | windows.SYNCHRONIZE,
665 .share_access = windows.FILE_SHARE_READ,665 .share_access = windows.FILE_SHARE_READ | windows.FILE_SHARE_WRITE,
666 .sa = &saAttr,
666 .creation = windows.OPEN_EXISTING,667 .creation = windows.OPEN_EXISTING,
667 .io_mode = .blocking,668 .io_mode = .blocking,
668 }) catch |err| switch (err) {669 }) catch |err| switch (err) {
...@@ -680,9 +681,6 @@ pub const ChildProcess = struct {...@@ -680,9 +681,6 @@ pub const ChildProcess = struct {
680 defer {681 defer {
681 if (any_ignore) os.close(nul_handle);682 if (any_ignore) os.close(nul_handle);
682 }683 }
683 if (any_ignore) {
684 try windows.SetHandleInformation(nul_handle, windows.HANDLE_FLAG_INHERIT, 0);
685 }
686684
687 var g_hChildStd_IN_Rd: ?windows.HANDLE = null;685 var g_hChildStd_IN_Rd: ?windows.HANDLE = null;
688 var g_hChildStd_IN_Wr: ?windows.HANDLE = null;686 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...@@ -86,7 +86,10 @@ pub fn OpenFile(sub_path_w: []const u16, options: OpenFileOptions) OpenError!HAN
86 var attr = OBJECT_ATTRIBUTES{86 var attr = OBJECT_ATTRIBUTES{
87 .Length = @sizeOf(OBJECT_ATTRIBUTES),87 .Length = @sizeOf(OBJECT_ATTRIBUTES),
88 .RootDirectory = if (std.fs.path.isAbsoluteWindowsWTF16(sub_path_w)) null else options.dir,88 .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,
90 .ObjectName = &nt_name,93 .ObjectName = &nt_name,
91 .SecurityDescriptor = if (options.sa) |ptr| ptr.lpSecurityDescriptor else null,94 .SecurityDescriptor = if (options.sa) |ptr| ptr.lpSecurityDescriptor else null,
92 .SecurityQualityOfService = null,95 .SecurityQualityOfService = null,