mirror of
https://github.com/ziglang/zig.git
synced 2024-11-16 09:03:12 +00:00
e9c48e6631
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. |
||
---|---|---|
.. | ||
linux | ||
plan9 | ||
uefi | ||
windows | ||
darwin.zig | ||
linux.zig | ||
plan9.zig | ||
posix_spawn.zig | ||
ptrace.zig | ||
test.zig | ||
uefi.zig | ||
wasi.zig | ||
windows.zig |