Commit graph

1825 commits

Author SHA1 Message Date
mlugg
dbb4c8d151 Merge pull request 'Remove things deprecated during the 0.15 release cycle' (#30018) from linus/zig:remove-deprecated-stuff into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30018
2025-12-06 08:51:15 +01:00
Andrew Kelley
54a84964f8 std.os.linux: SIG enum is non-exhaustive 2025-12-01 19:17:52 -08:00
Andrew Kelley
9e981c3ae5 std.os.linux: delete unnecessary @compileError
Without this, it already fails to compile with a sufficiently helpful
error message.
2025-12-01 19:17:52 -08:00
Linus Groh
39fa831947 std: Remove a handful of things deprecated during the 0.15 release cycle
- std.Build.Step.Compile.root_module mutators -> std.Build.Module
- std.Build.Step.Compile.want_lto -> std.Build.Step.Compile.lto
- std.Build.Step.ConfigHeader.getOutput -> std.Build.Step.ConfigHeader.getOutputFile
- std.Build.Step.Run.max_stdio_size -> std.Build.Step.Run.stdio_limit
- std.enums.nameCast -> @field(E, tag_name) / @field(E, @tagName(tag))
- std.Io.tty.detectConfig -> std.Io.tty.Config.detect
- std.mem.trimLeft -> std.mem.trimStart
- std.mem.trimRight -> std.mem.trimEnd
- std.meta.intToEnum -> std.enums.fromInt
- std.meta.TagPayload -> @FieldType(U, @tagName(tag))
- std.meta.TagPayloadByName -> @FieldType(U, tag_name)
2025-11-27 20:17:04 +00:00
Ryan Liptak
53e615b920
Merge pull request #25993 from squeek502/windows-paths
Teach `std.fs.path` about the wonderful world of Windows paths
2025-11-24 15:27:24 -08:00
Ryan Liptak
289f2f0d34
Merge pull request #17541 from moosichu/fix/wine-get-final-path-name-by-handle
Windows: Deal with NT namespaced paths in GetFinalPathNameByHandle
2025-11-24 07:17:30 -08:00
Ryan Liptak
bf25816067 Move Windows rename implementation from std.posix to windows.RenameFile
This also unifies the rename implementations, since previously `posix.renameW` used `MoveFileEx` while `posix.renameatW` used `NtOpenFile`/`NtSetInformationFile`. This, in turn, allows the `MoveFileEx` bindings to be deleted as `posix.renameW` was the only usage.
2025-11-23 23:38:01 -08:00
Ryan Liptak
17ecc77fc4 os.windows: Delete unused functions and kernel32 bindings 2025-11-23 23:38:01 -08:00
Ryan Liptak
d48faf1a32 windows.GetFinalPathNameByHandle: add links to bugs tracking the Wine workaround 2025-11-23 19:10:23 -08:00
Alex Rønne Petersen
1231aa9719
Revert "std.os.linux.sparc64: use icc instead of xcc in asm clobbers"
This reverts commit b34a13da38.

This is not the right fix; rather, the C backend needs to translate all of ccr,
icc, and xcc to just icc.
2025-11-23 07:27:45 +01:00
Ryan Liptak
822f412424 fs.path: Fix on big-endian architectures, make PathType.isSep assume WTF-16 is LE
This commit flips usage of PathType.isSep from requiring the caller to convert to native to assuming the input is LE encoded, which is a breaking change. This makes usage a bit nicer, though, and moves the endian conversion work from runtime to comptime.
2025-11-21 22:26:58 -08:00
Tom Read Cutting
689032d571 Deal with NT paths in GetFinalPathNameByHandle
When calling QueryObjectName, NT namespaced paths can be returned. This
change appropriately strips the prefix to turn it into an absolute path.

(The above behaviour was observed at least in Wine so far)

Co-authored-by: Ryan Liptak <squeek502@hotmail.com>
2025-11-21 01:52:50 -08:00
Ryan Liptak
59b8bed222 Teach fs.path about the wonderful world of Windows paths
Previously, fs.path handled a few of the Windows path types, but not all of them, and only a few of them correctly/consistently. This commit aims to make `std.fs.path` correct and consistent in handling all possible Win32 path types.

This commit also slightly nudges the codebase towards a separation of Win32 paths and NT paths, as NT paths are not actually distinguishable from Win32 paths from looking at their contents alone (i.e. `\Device\Foo` could be an NT path or a Win32 rooted path, no way to tell without external context). This commit formalizes `std.fs.path` being fully concerned with Win32 paths, and having no special detection/handling of NT paths.

Resources on Windows path types, and Win32 vs NT paths:

- https://googleprojectzero.blogspot.com/2016/02/the-definitive-guide-on-win32-to-nt.html
- https://chrisdenton.github.io/omnipath/Overview.html
- https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file

API additions/changes/deprecations

- `std.os.windows.getWin32PathType` was added (it is analogous to `RtlDetermineDosPathNameType_U`), while `std.os.windows.getNamespacePrefix` and `std.os.windows.getUnprefixedPathType` were deleted. `getWin32PathType` forms the basis on which the updated `std.fs.path` functions operate.
- `std.fs.path.parsePath`, `std.fs.path.parsePathPosix`, and `std.fs.path.parsePathWindows` were added, while `std.fs.path.windowsParsePath` was deprecated. The new `parsePath` functions provide the "root" and the "kind" of a path, which is platform-specific. The now-deprecated `windowsParsePath` did not handle all possible path types, while the new `parsePathWindows` does.
- `std.fs.path.diskDesignator` has been deprecated in favor of `std.fs.path.parsePath`, and same deal with `diskDesignatorWindows` -> `parsePathWindows`
- `relativeWindows` is now a compile error when *not* targeting Windows, while `relativePosix` is now a compile error when targeting Windows. This is because those functions read/use the CWD path which will behave improperly when used from a system with different path semantics (e.g. calling `relativePosix` from a Windows system with a CWD like `C:\foo\bar` will give you a bogus result since that'd be treated as a single relative component when using POSIX semantics). This also allows `relativeWindows` to use Windows-specific APIs for getting the CWD and environment variables to cut down on allocations.
- `componentIterator`/`ComponentIterator.init` have been made infallible. These functions used to be able to error on UNC paths with an empty server component, and on paths that were assumed to be NT paths, but now:
  + We follow the lead of `RtlDetermineDosPathNameType_U`/`RtlGetFullPathName_U` in how it treats a UNC path with an empty server name (e.g. `\\\share`) and allow it, even if it'll be invalid at the time of usage
  + Now that `std.fs.path` assumes paths are Win32 paths and not NT paths, we don't have to worry about NT paths

Behavior changes

- `std.fs.path` generally: any combinations of mixed path separators for UNC paths are universally supported, e.g. `\/server/share`, `/\server\share`, `/\server/\\//share` are all seen as equivalent UNC paths
- `resolveWindows` handles all path types more appropriately/consistently.
  + `//` and `//foo` used to be treated as a relative path, but are now seen as UNC paths
  + If a rooted/drive-relative path cannot be resolved against anything more definite, the result will remain a rooted/drive-relative path.
  + I've created [a script to generate the results of a huge number of permutations of different path types](https://gist.github.com/squeek502/9eba7f19cad0d0d970ccafbc30f463bf) (the result of running the script is also included for anyone that'd like to vet the behavior).
- `dirnameWindows` now treats the drive-relative root as the dirname of a drive-relative path with a component, e.g. `dirname("C:foo")` is now `C:`, whereas before it would return null. `dirnameWindows` also handles local device paths appropriately now.
- `basenameWindows` now handles all path types more appropriately. The most notable change here is `//a` being treated as a partial UNC path now and therefore `basename` will return `""` for it, whereas before it would return `"a"`
- `relativeWindows` will now do its best to resolve against the most appropriate CWD for each path, e.g. relative for `D:foo` will look at the CWD to check if the drive letter matches, and if not, look at the special environment variable `=D:` to get the shell-defined CWD for that drive, and if that doesn't exist, then it'll resolve against `D:\`.

Implementation details

- `resolveWindows` previously looped through the paths twice to build up the relevant info before doing the actual resolution. Now, `resolveWindows` iterates backwards once and keeps track of which paths are actually relevant using a bit set, which also allows it to break from the loop when it's no longer possible for earlier paths to matter.
- A standalone test was added to test parts of `relativeWindows` since the CWD resolution logic depends on CWD information from the PEB and environment variables

Edge cases worth noting

- A strange piece of trivia that I found out while working on this is that it's technically possible to have a drive letter that it outside the intended A-Z range, or even outside the ASCII range entirely. Since we deal with both WTF-8 and WTF-16 paths, `path[0]`/`path[1]`/`path[2]` will not always refer to the same bits of information, so to get consistent behavior, some decision about how to deal with this edge case had to be made. I've made the choice to conform with how `RtlDetermineDosPathNameType_U` works, i.e. treat the first WTF-16 code unit as the drive letter. This means that when working with WTF-8, checking for drive-relative/drive-absolute paths is a bit more complicated. For more details, see the lengthy comment in `std.os.windows.getWin32PathType`
- `relativeWindows` will now almost always be able to return either a fully-qualified absolute path or a relative path, but there's one scenario where it may return a rooted path: when the CWD gotten from the PEB is not a drive-absolute or UNC path (if that's actually feasible/possible?). An alternative approach to this scenario might be to resolve against the `HOMEDRIVE` env var if available, and/or default to `C:\` as a last resort in order to guarantee the result of `relative` is never a rooted path.
- Partial UNC paths (e.g. `\\server` instead of `\\server\share`) are a bit awkward to handle, generally. Not entirely sure how best to handle them, so there may need to be another pass in the future to iron out any issues that arise. As of now the behavior is:
  + For `relative`, any part of a UNC disk designator is treated as the "root" and therefore isn't applicable for relative paths, e.g. calling `relative` with `\\server` and `\\server\share` will result in `\\server\share` rather than just `share` and if `relative` is called with `\\server\foo` and `\\server\bar` the result will be `\\server\bar` rather than `..\bar`
  + For `resolve`, any part of a UNC disk designator is also treated as the "root", but relative and rooted paths are still elligable for filling in missing portions of the disk designator, e.g. `resolve` with `\\server` and `foo` or `\foo` will result in `\\server\foo`

Fixes #25703
Closes #25702
2025-11-21 00:03:44 -08:00
rpkak
6b4f45f782 system specific errno 2025-11-20 15:03:23 -08:00
Alex Rønne Petersen
508f676bb4
std.os.linux.IoUring: disable bind/listen/connect on s390x
https://github.com/ziglang/zig/issues/25956
2025-11-19 01:42:45 +01:00
Ryan Liptak
adf74ba4fb windows.eqlIgnoreCaseWTF16 -> eqlIgnoreCaseWtf16
Consistent with naming of other, similar functions
2025-11-16 04:03:52 -08:00
Ryan Liptak
6aa3570cb0 windows: Make readLinkW APIs output WTF-16, reduce stack usage of callers
- Affects the following functions:
  + `std.fs.Dir.readLinkW`
  + `std.os.windows.ReadLink`
  + `std.os.windows.ntToWin32Namespace`
  + `std.posix.readlinkW`
  + `std.posix.readlinkatW`

Each of these functions (except `ntToWin32Namespace`) took WTF-16 as input and would output WTF-8, which makes optimal buffer re-use difficult at callsites and could force unnecessary WTF-16 <-> WTF-8 conversion during an intermediate step.

The functions have been updated to output WTF-16, and also allow for the path and the output to re-use the same buffer (i.e. in-place modification), which can reduce the stack usage at callsites. For example, all of `std.fs.Dir.readLink`/`readLinkZ`/`std.posix.readlink`/`readlinkZ`/`readlinkat`/`readlinkatZ` have had their stack usage reduced by one PathSpace struct (64 KiB) when targeting Windows.

The new `ntToWin32Namespace` takes an output buffer and returns a slice from that instead of returning a PathSpace, which is necessary to make the above possible.
2025-11-15 18:16:03 -08:00
Ryan Liptak
06a7597ea8 windows.ReadLink: Use OpenFile now that .filter = .any exists
The reasoning in the comment deleted by this commit no longer applies, since that same benefit can be obtained by using OpenFile with `.filter = .any`.

Also removes a stray debug.print
2025-11-15 18:07:25 -08:00
Jacob Young
57889cae80 posix: reduce the number of assumptions made by dl_iterate_phdr
Not yet fully compatible with the new linker, but still progress.

Closes #25786
2025-11-09 03:31:26 -05:00
qilme
8347791ce3
std.os.windows: eliminate forwarder function in kernel32 (#25766)
#1840

kernel32.AddVectoredExceptionHandler -> ntdll.RtlAddVectoredExceptionHandler
kernel32.RemoveVectoredExceptionHandler -> ntdll.RtlRemoveVectoredExceptionHandler
kernel32.ExitProcess -> ntdll.RtlExitUserProcess
kernel32.InitializeCriticalSection -> ntdll.RtlInitializeCriticalSection
kernel32.EnterCriticalSection -> ntdll.RtlEnterCriticalSection
kernel32.LeaveCriticalSection -> ntdll.RtlLeaveCriticalSection
kernel32.DeleteCriticalSection -> ntdll.RtlDeleteCriticalSection
kernel32.TryAcquireSRWLockExclusive -> ntdll.RtlTryAcquireSRWLockExclusive
kernel32.AcquireSRWLockExclusive -> ntdll.RtlAcquireSRWLockExclusive
kernel32.ReleaseSRWLockExclusive -> ntdll.RtlReleaseSRWLockExclusive
kernel32.WakeConditionVariable -> ntdll.RtlWakeConditionVariable
kernel32.WakeAllConditionVariable -> ntdll.RtlWakeAllConditionVariable
kernel32.HeapReAlloc -> ntdll.RtlReAllocateHeap
kernel32.HeapAlloc -> ntdll.RtlAllocateHeap
2025-10-31 13:54:50 +00:00
John Benediktsson
74c23a237e
Merge pull request #25763 from mrjbq7/cancelled
rename Cancelled to Canceled
2025-10-30 04:40:13 +00:00
Andrew Kelley
a072d821be
Merge pull request #25592 from ziglang/init-std.Io
std: Introduce `Io` Interface
2025-10-29 13:51:37 -07:00
Alex Rønne Petersen
b2bc44e0d5
std.os.linux: fix restore for powerpc/powerpc64
sigreturn and rt_sigreturn are distinct syscalls on PowerPC.
2025-10-29 20:44:43 +01:00
Andrew Kelley
0205ce4736 std.os.linux.IoUring: disable failing test
tracked by https://github.com/ziglang/zig/issues/25734
2025-10-29 06:26:05 -07:00
Andrew Kelley
b1d270d38e std.os.linux.s390x: fix restore function 2025-10-29 06:20:52 -07:00
Andrew Kelley
1553c8eae7 std.os.linux.x86: fix signal restore function
After handling any signal on x86, it would previously segfault.
2025-10-29 06:20:52 -07:00
Andrew Kelley
4114392369 std: fix definition of ws2_32.GetAddrInfoExW
There was a missing parameter.
2025-10-29 06:20:52 -07:00
Andrew Kelley
8b269f7e18 std: make signal numbers into an enum
fixes start logic for checking whether IO/POLL exist
2025-10-29 06:20:51 -07:00
Andrew Kelley
6ccb53bff1 std.Io.Threaded: fix openSelfExe for Windows
missing a call to wToPrefixedFileW
2025-10-29 06:20:51 -07:00
Andrew Kelley
c87fbd5878 std.os.linux.IoUring: use linux msghdr
it disagrees with posix msghdr
2025-10-29 06:20:51 -07:00
Andrew Kelley
a3ddca3657 std.Io.Threaded: delete Windows implementation of if_nametoindex
Microsoft documentation says "The if_nametoindex function is implemented
for portability of applications with Unix environments, but the
ConvertInterface functions are preferred."

This was also the only dependency on iphlpapi.
2025-10-29 06:20:51 -07:00
Andrew Kelley
ab003cd054 std.Io.Threaded: implement netLookup for Windows 2025-10-29 06:20:51 -07:00
Andrew Kelley
dab8dd5e03 std.os.windows.ws2_32: remove 'A' variants 2025-10-29 06:20:51 -07:00
Andrew Kelley
d257b1337a std.Io.Threaded: fix compilation failures on Windows 2025-10-29 06:20:50 -07:00
Andrew Kelley
0b5179a231 std.Io.Threaded: implement netAccept for Windows 2025-10-29 06:20:50 -07:00
Andrew Kelley
34891b528e std.Io.Threaded: implement netListen for Windows 2025-10-29 06:20:50 -07:00
Andrew Kelley
aa6e8eff40 std.Io.Threaded: implement dirAccess for Windows 2025-10-29 06:20:50 -07:00
Andrew Kelley
10b1eef2d3 std: fix compilation errors on Windows 2025-10-29 06:20:50 -07:00
Andrew Kelley
21e195a1a9 std: move some windows path checking logic 2025-10-29 06:20:50 -07:00
Andrew Kelley
2d7d98da0c std.fs: use BadPathName rather than InvalidWtf8 on Windows 2025-10-29 06:20:50 -07:00
Andrew Kelley
3bf0ce65a5 fix miscellaneous compilation errors
- ILSEQ -> error.BadPathName
- implement dirStatPath for WASI
2025-10-29 06:20:50 -07:00
Andrew Kelley
90fdd21df6 std: move DNS record enum to a better namespace 2025-10-29 06:20:50 -07:00
Andrew Kelley
031044b399 std: fix macos compilation errors 2025-10-29 06:20:49 -07:00
Andrew Kelley
750b1431bf std: fix some Io compilation errors 2025-10-29 06:20:49 -07:00
Andrew Kelley
47aa5a70a5 std: updating to std.Io interface
got the build runner compiling
2025-10-29 06:20:48 -07:00
Andrew Kelley
961961cf85 std: fix msghdr and cmsghdr when using musl libc
glibc and linux kernel use size_t for some field lengths while POSIX and
musl use int. This bug would have caused breakage the first time someone
tried to call sendmsg on a 64-bit big endian system when linking musl
libc.

my opinion:
* msghdr.iovlen: kernel and glibc have it right. This field should
  definitely be size_t. With int, the padding bytes are wasted for no
  reason.
* msghdr.controllen: POSIX and musl have it right. 4 bytes is plenty for
  the length, and it saves 4 bytes next to flags.
* cmsghdr.len: POSIX and musl have it right. 4 bytes is plenty for the
  length, and it saves 4 bytes since the other fields are also 32-bits
  each.
2025-10-29 06:20:48 -07:00
Andrew Kelley
95dee2af9c std.Io: implement netSend 2025-10-29 06:20:48 -07:00
Andrew Kelley
bcb6760fa5 std.os.linux: remove unnecessary warnings from sendmmsg
The one about INT_MAX is self-evident from the type system.

The one about kernel having bad types doesn't seem accurate as I checked
the source code and it uses size_t for all the appropriate types,
matching the libc struct definition for msghdr and msghdr_const.
2025-10-29 06:20:48 -07:00
Andrew Kelley
3b80fde6f4 std.os.linux: remove sendmmsg workaround
This "fix" is too opinionated to belong here. Better instead to
document the pitfalls.
2025-10-29 06:20:48 -07:00
GasInfinity
55c0693c4a
fix: make compiler_rt and std.Io.Writer compile on 16-bit platforms. 2025-10-27 11:17:48 +01:00