Skip to content

Commit 6a709f0

Browse files
committed
cleanups and add PROCESS_CREATION_FLAGS
1 parent a0275a7 commit 6a709f0

File tree

3 files changed

+47
-6
lines changed

3 files changed

+47
-6
lines changed

lib/std/child_process.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,12 +1128,12 @@ pub const ChildProcess = struct {
11281128
}
11291129
};
11301130

1131-
const PortPipeReturn = if (builtin.os.tag == .windows) [2]windows.HANDLE else [2]os.fd_t;
1131+
const PortPipeT = if (builtin.os.tag == .windows) [2]windows.HANDLE else [2]os.fd_t;
11321132

11331133
/// Portable pipe creation without handle inheritance
1134-
pub inline fn portablePipe() !PortPipeReturn {
1134+
pub inline fn portablePipe() !PortPipeT {
11351135
// TODO think how to offer user an interface to lpSecurityDescriptor
1136-
var pipe_new: PortPipeReturn = undefined;
1136+
var pipe_new: PortPipeT = undefined;
11371137
if (builtin.os.tag == .windows) {
11381138
const saAttr = windows.SECURITY_ATTRIBUTES{
11391139
.nLength = @sizeOf(windows.SECURITY_ATTRIBUTES),

lib/std/os/windows.zig

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1576,6 +1576,45 @@ pub fn GetEnvironmentVariableW(lpName: LPWSTR, lpBuffer: [*]u16, nSize: DWORD) G
15761576
return rc;
15771577
}
15781578

1579+
// zig fmt: off
1580+
pub const PROCESS_CREATION_FLAGS = enum(u32) {
1581+
// <- gap here ->
1582+
DEBUG_PROCESS = 0x0000_0001,
1583+
DEBUG_ONLY_THIS_PROCESS = 0x0000_0002,
1584+
CREATE_SUSPENDED = 0x0000_0004,
1585+
DETACHED_PROCESS = 0x0000_0008,
1586+
CREATE_NEW_CONSOLE = 0x0000_0010,
1587+
NORMAL_PRIORITY_CLASS = 0x0000_0020,
1588+
IDLE_PRIORITY_CLASS = 0x0000_0040,
1589+
HIGH_PRIORITY_CLASS = 0x0000_0080,
1590+
REALTIME_PRIORITY_CLASS = 0x0000_0100,
1591+
CREATE_NEW_PROCESS_GROUP = 0x0000_0200,
1592+
CREATE_UNICODE_ENVIRONMENT = 0x0000_0400,
1593+
CREATE_SEPARATE_WOW_VDM = 0x0000_0800,
1594+
CREATE_SHARED_WOW_VDM = 0x0000_1000,
1595+
CREATE_FORCEDOS = 0x0000_2000,
1596+
BELOW_NORMAL_PRIORITY_CLASS = 0x0000_4000,
1597+
ABOVE_NORMAL_PRIORITY_CLASS = 0x0000_8000,
1598+
INHERIT_PARENT_AFFINITY = 0x0001_0000,
1599+
INHERIT_CALLER_PRIORITY = 0x0002_0000,
1600+
CREATE_PROTECTED_PROCESS = 0x0004_0000,
1601+
EXTENDED_STARTUPINFO_PRESENT = 0x0008_0000,
1602+
PROCESS_MODE_BACKGROUND_BEGIN = 0x0010_0000,
1603+
PROCESS_MODE_BACKGROUND_END = 0x0020_0000,
1604+
CREATE_SECURE_PROCESS = 0x0040_0000,
1605+
// <- gap here ->
1606+
CREATE_BREAKAWAY_FROM_JOB = 0x0100_0000,
1607+
CREATE_PRESERVE_CODE_AUTHZ_LEVEL = 0x0200_0000,
1608+
CREATE_DEFAULT_ERROR_MODE = 0x0400_0000,
1609+
CREATE_NO_WINDOW = 0x0800_0000,
1610+
PROFILE_USER = 0x1000_0000,
1611+
PROFILE_KERNEL = 0x2000_0000,
1612+
PROFILE_SERVER = 0x4000_0000,
1613+
CREATE_IGNORE_SYSTEM_DEFAULT = 0x8000_0000,
1614+
_,
1615+
};
1616+
// zig fmt: on
1617+
15791618
pub const CreateProcessError = error{
15801619
FileNotFound,
15811620
AccessDenied,
@@ -2919,8 +2958,6 @@ pub const COORD = extern struct {
29192958
Y: SHORT,
29202959
};
29212960

2922-
pub const CREATE_UNICODE_ENVIRONMENT = 1024;
2923-
29242961
pub const TLS_OUT_OF_INDEXES = 4294967295;
29252962
pub const IMAGE_TLS_DIRECTORY = extern struct {
29262963
StartAddressOfRawData: usize,

test/standalone/childprocess_extrapipe/parent.zig

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ pub fn main() !void {
3232
// enabling of file inheritance directly before and closing directly after spawn
3333
// less time to leak => better
3434
{
35+
// Besides being faster to spawn, posix_spawn enables to close pipe[pipe_wr]
36+
// within the child before it is closed from Kernel after execv.
37+
// Note, that posix_spawn is executed in the child, so it does not allow
38+
// to minimize the leaking time of the parent's handle side.
3539
if (os.hasPosixSpawn) child_proc.posix_actions = try os.posix_spawn.Actions.init();
3640
defer if (os.hasPosixSpawn) child_proc.posix_actions.?.deinit();
3741
if (os.hasPosixSpawn) try child_proc.posix_actions.?.close(pipe[pipe_wr]);
@@ -42,7 +46,7 @@ pub fn main() !void {
4246
try child_proc.spawn();
4347
}
4448

45-
// windows does have inheritance disabled on default, but we check to be sure
49+
// check that inheritance was disabled for the handle the whole time
4650
if (builtin.target.os.tag == .windows) {
4751
var handle_flags: windows.DWORD = undefined;
4852
try windows.GetHandleInformation(pipe[pipe_wr], &handle_flags);

0 commit comments

Comments
 (0)