zig/lib/std/os
Ryan Liptak e9c48e6631 spawnWindows: Improve worst-case performance considerably
The name of the game here is to avoid CreateProcessW calls at all costs,
and only ever try calling it when we have a real candidate for execution.
Secondarily, we want to minimize the number of syscalls used when checking
for each PATHEXT-appended version of the app name.

An overview of the technique used:
- Open the search directory for iteration (either cwd or a path from PATH)
- Use NtQueryDirectoryFile with a wildcard filename of `<app name>*` to
  check if anything that could possibly match either the unappended version
  of the app name or any of the versions with a PATHEXT value appended exists.
- If the wildcard NtQueryDirectoryFile call found nothing, we can exit early
  without needing to use PATHEXT at all.

This allows us to use a <open dir, NtQueryDirectoryFile, close dir> sequence
for any directory that doesn't contain any possible matches, instead of having
to use a separate look up for each individual filename combination (unappended +
each PATHEXT appended). For directories where the wildcard *does* match something,
we only need to do a maximum of <number of supported PATHEXT extensions> more
NtQueryDirectoryFile calls.

---

In addition, we now only evaluate the extensions in PATHEXT that we know we can handle (.COM, .EXE, .BAT, .CMD) and ignore the rest.

---

This commit also makes two edge cases match Windows behavior:

- If an app name has the extension .exe and it is attempted to be executed, that is now treated as unrecoverable and InvalidExe is immediately returned no matter where the .exe is (cwd or in the PATH). This matches the behavior of the Windows cmd.exe.
- If the app name contains more than just a filename (e.g. it has path separators), then it is excluded from PATH searching and only does a cwd search. This matches the behavior of Windows cmd.exe.
2022-12-18 02:48:34 -08:00
..
linux remove most conditional compilation based on stage1 2022-12-06 20:38:54 -07:00
plan9 plan9: more syscalls 2021-11-09 07:08:27 -05:00
uefi remove most conditional compilation based on stage1 2022-12-06 20:38:54 -07:00
windows std: fix compile error bitrot 2022-12-11 12:48:17 -07:00
darwin.zig darwin: add even more wrappers for Mach syscalls 2022-12-14 00:10:26 +01:00
linux.zig update usages of @call 2022-12-13 13:14:20 +02:00
plan9.zig remove 'builtin.stage2_arch', Sema is smart enough now 2022-08-07 16:07:08 -07:00
posix_spawn.zig std.c: fix incorrect return types 2022-10-13 13:21:19 +02:00
ptrace.zig darwin: add even more wrappers for Mach syscalls 2022-12-14 00:10:26 +01:00
test.zig Add 0-length buffer checks to os.read & os.write 2022-12-12 15:10:59 -05:00
uefi.zig Make invalidFmtError public and use in place of compileErrors for bad format strings (#13526) 2022-11-12 21:03:24 +02:00
wasi.zig std: fix WASI regressions 2022-12-06 12:15:05 -07:00
windows.zig spawnWindows: Improve worst-case performance considerably 2022-12-18 02:48:34 -08:00