Skip to content

Commit 148ccdc

Browse files
author
Jan Philipp Hafer
committed
more fixes: sema looks successful, but still fails
1 parent 40974b3 commit 148ccdc

File tree

4 files changed

+26
-22
lines changed

4 files changed

+26
-22
lines changed

lib/std/child_process.zig

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -847,7 +847,7 @@ pub const ChildProcess = struct {
847847
fn spawnWindows(self: *ChildProcess) SpawnError!void {
848848
var stdstream_buffer: [3]os.fd_t = undefined;
849849
if (self.handles == null) {
850-
self.handles = stdstream_buffer;
850+
self.handles = &stdstream_buffer;
851851
self.handles.?[0] = self.stdin.?.handle;
852852
self.handles.?[1] = self.stdout.?.handle;
853853
self.handles.?[2] = self.stderr.?.handle;
@@ -978,28 +978,23 @@ pub const ChildProcess = struct {
978978
}
979979
var suc = windows.kernel32.InitializeProcThreadAttributeList(null, 1, 0, &size_attr_list);
980980
std.debug.assert(suc == 0); // DEBUG
981-
attrib_list = try self.allocator.alloc(windows.LPPROC_THREAD_ATTRIBUTE_LIST, self.handles.?.len);
982-
defer attrib_list.free(attrib_list);
981+
var attrib_list_block = try self.allocator.alloc(u8, self.handles.?.len);
982+
defer self.allocator.free(attrib_list_block);
983+
attrib_list = attrib_list_block.ptr;
983984
suc = windows.kernel32.InitializeProcThreadAttributeList(null, 1, 0, &size_attr_list);
984985
std.debug.assert(suc != 0); // DEBUG
985986

986-
const proc_thread_attr = windows.PROC_THREAD_ATTRIBUTE{
987-
.NUMBER = .ProcThreadAttributeHandleList,
988-
.ADDITIVE = false,
989-
.THREAD = true,
990-
.INPUT = false,
991-
};
992987
suc = windows.kernel32.UpdateProcThreadAttribute(
993988
attrib_list,
994989
0,
995-
proc_thread_attr,
996-
self.handles.?.ptr,
990+
windows.PROC_THREAD_ATTRIBUTE_HANDLE_LIST,
991+
@ptrCast(*anyopaque, self.handles.?.ptr),
997992
self.handles.?.len * @sizeOf(windows.HANDLE),
998993
null,
999994
null,
1000995
);
1001996

1002-
var siStartInfo = windows.STARTUPINFOW{
997+
var lpStartInfo = windows.STARTUPINFOW{
1003998
.cb = @sizeOf(windows.STARTUPINFOW),
1004999
.hStdError = g_hChildStd_ERR_Wr,
10051000
.hStdOutput = g_hChildStd_OUT_Wr,
@@ -1021,7 +1016,7 @@ pub const ChildProcess = struct {
10211016
.lpReserved2 = null,
10221017
};
10231018
var ext_info = windows.STARTUPINFOEXW{
1024-
.StartupInfo = siStartInfo,
1019+
.lpStartupInfo = lpStartInfo,
10251020
.lpAttributeList = attrib_list,
10261021
};
10271022

@@ -1462,7 +1457,7 @@ fn windowsCreateProcess(
14621457
@enumToInt(CREATE_UNICODE_ENVIRONMENT) | @enumToInt(EXTENDED_STARTUPINFO_PRESENT),
14631458
@ptrCast(?*anyopaque, envp_ptr),
14641459
cwd_ptr,
1465-
ext_info.lpStartupInfo,
1460+
&ext_info.lpStartupInfo,
14661461
lpProcessInformation,
14671462
);
14681463
}

lib/std/os/windows.zig

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1577,7 +1577,7 @@ pub fn GetEnvironmentVariableW(lpName: LPWSTR, lpBuffer: [*]u16, nSize: DWORD) G
15771577
}
15781578

15791579
// see macro ProcThreadAttributeValue
1580-
pub const PROC_THREAD_ATTRIBUTE = packed struct {
1580+
const PROC_THREAD_ATTRIBUTE = packed struct {
15811581
NUMBER: enum(u16) {
15821582
ProcThreadAttributeParentProcess = 0,
15831583
// <- gap ->
@@ -1609,6 +1609,14 @@ pub const PROC_THREAD_ATTRIBUTE = packed struct {
16091609
INPUT: bool, // 0x00020000
16101610
};
16111611

1612+
pub const PROC_THREAD_ATTRIBUTE_HANDLE_LIST =
1613+
@intCast(DWORD_PTR, @bitCast(u19, PROC_THREAD_ATTRIBUTE{
1614+
.NUMBER = .ProcThreadAttributeHandleList,
1615+
.ADDITIVE = false,
1616+
.THREAD = true,
1617+
.INPUT = false,
1618+
}));
1619+
16121620
pub const LPPROC_THREAD_ATTRIBUTE_LIST = *anyopaque;
16131621

16141622
pub const STARTUPINFOEXW = extern struct {

lib/std/os/windows/kernel32.zig

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const CONSOLE_SCREEN_BUFFER_INFO = windows.CONSOLE_SCREEN_BUFFER_INFO;
88
const CONTEXT = windows.CONTEXT;
99
const COORD = windows.COORD;
1010
const DWORD = windows.DWORD;
11+
const DWORD_PTR = windows.DWORD_PTR;
1112
const DWORD64 = windows.DWORD64;
1213
const FILE_INFO_BY_HANDLE_CLASS = windows.FILE_INFO_BY_HANDLE_CLASS;
1314
const HANDLE = windows.HANDLE;
@@ -118,17 +119,17 @@ pub extern "kernel32" fn InitializeProcThreadAttributeList(
118119
lpAttributeList: ?LPPROC_THREAD_ATTRIBUTE_LIST,
119120
dwAttributeCount: DWORD,
120121
dwFlags: DWORD,
121-
lpSize: ?*usize,
122+
lpSize: ?*SIZE_T,
122123
) callconv(WINAPI) BOOL;
123124

124125
pub extern "kernel32" fn UpdateProcThreadAttribute(
125126
lpAttributeList: ?LPPROC_THREAD_ATTRIBUTE_LIST,
126127
dwFlags: DWORD,
127-
Attribute: usize,
128-
lpValue: ?*anyopaque,
129-
cbSize: usize,
128+
Attribute: DWORD_PTR,
129+
lpValue: *anyopaque,
130+
cbSize: SIZE_T,
130131
lpPreviousValue: ?*anyopaque,
131-
lpReturnSize: ?*usize,
132+
lpReturnSize: ?*SIZE_T,
132133
) callconv(WINAPI) BOOL;
133134

134135
pub extern "kernel32" fn CreateProcessW(

test/standalone/childprocess_extrapipe/child.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ pub fn main() !void {
1111
_ = it.next() orelse unreachable; // skip binary name
1212
const s_handle = it.next() orelse unreachable;
1313
var file_handle = try std.os.stringToHandle(s_handle);
14-
// TODO: Is there a way on Windows to let the Kernel disable inheritance
15-
// after it is inherited in CreateProcess???
14+
1615
if (builtin.target.os.tag == .windows) {
1716
// windows.HANDLE_FLAG_INHERIT is enabled
1817
var handle_flags: windows.DWORD = undefined;
@@ -23,6 +22,7 @@ pub fn main() !void {
2322
var fcntl_flags = try std.os.fcntl(file_handle, std.os.F.GETFD, 0);
2423
try std.testing.expect((fcntl_flags & std.os.FD_CLOEXEC) == 0);
2524
}
25+
2626
try std.os.disableInheritance(file_handle);
2727
var file_in = std.fs.File{ .handle = file_handle }; // read side of pipe
2828
defer file_in.close();

0 commit comments

Comments
 (0)