Commit Graph

632 Commits

Author SHA1 Message Date
Carmen 5e9c484745 std.Io.Reader.takeStruct: dont assert buffer capacity is sizeOf(T) 2026-01-27 00:05:42 +01:00
Andrew Kelley 1b235540c1 Revert "Io.Threaded: remove WSA_FLAG_OVERLAPPED from socket call"
The stated reason for this commit was cancelation didn't work. On
further review, we know why cancelation didn't work, and recent
enhancements on master branch make it easy to make it work.

Meanwhile, not using overlapped means that multiple threads cannot use
the same open socket handle. I also added line comments to explain the
choice in this revert commit.

This reverts commit fd3657bf8c.

closes #31011
reopens #30865
2026-01-26 14:16:28 -08:00
Andrew Kelley 5eb55ba866 Merge pull request 'compiler: use Io.MemoryMap' (#30961) from use-mmap into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30961
2026-01-26 22:58:01 +01:00
Andrew Kelley 5c42193b17 std.Io.Threaded: rework cancelation
Now it can handle sync cancelation and alertable cancelation on Windows.

Also fix the API of NtCancelIoFileEx
2026-01-23 12:59:36 -08:00
Andrew Kelley 499ba5d55c compiler: use Io.MemoryMap
Also make setLength return error.OperationUnsupported when it cannot be
done atomically.
2026-01-22 21:25:53 -08:00
Andrew Kelley 1badb2a840 std.Io.Threaded: dirCreateFileWindows uses NtCreateFile directly 2026-01-22 18:08:13 -08:00
Chadwain Holness fd3657bf8c Io.Threaded: remove WSA_FLAG_OVERLAPPED from socket call 2026-01-22 03:39:00 +01:00
Matthew Lugg 35a191ec1c std.Io.Threaded: fix futex timeout race handling 2026-01-21 16:41:55 +01:00
Alex Rønne Petersen a3ea3bd31d std: NetBSD doesn't have a reliable F_GETPATH
It can fail arbitrarily with ENOENT if the kernel happens to not have the FD in
its name cache. That makes it useless for our purposes.

closes https://codeberg.org/ziglang/zig/issues/30843
2026-01-21 16:41:51 +01:00
Alex Rønne Petersen fc59f0e7f0 std.Io.test: skip atime check in setTimestamps on NetBSD 2026-01-21 16:41:30 +01:00
Andrew Kelley d2dda0737b std.Io.Threaded: sendmmsg can return EACCES 2026-01-18 21:40:15 +01:00
Andrew Kelley 7b21fd7244 std.Io.Threaded: fix memory mapping on windows
- set protection flags properly
- handle when mapping fails after unmapping
2026-01-15 14:18:21 -08:00
Andrew Kelley d2585e68a7 std.Io.Threaded: use NtExtendSection in fileMemoryMapSetLength
is this a good idea? not sure yet. reverting in the next commit
2026-01-15 14:18:21 -08:00
Andrew Kelley de347dd6a9 std.Io.Threaded: add missing free in MemoryMap.setLength 2026-01-15 14:18:21 -08:00
Andrew Kelley 7ff6bcc111 std.Io.Threaded: track unaligned mapping length on Windows 2026-01-15 14:18:21 -08:00
Andrew Kelley b2776d097d std.Io.Threaded: implement MemoryMap.setLength for Windows 2026-01-15 14:18:20 -08:00
Andrew Kelley 8527ec9c7b std.Io.Threaded: implement mmap fallback for Windows 2026-01-15 14:18:20 -08:00
Andrew Kelley 3c708b19fe disable test due to wasmtime bug
tracked by #20747
2026-01-15 14:18:20 -08:00
Andrew Kelley 2b01764d86 std: fix handling of EBADF error code
In the context of read/write it's ambiguous, means file was opened
without read/write respectively.
2026-01-15 14:18:20 -08:00
Andrew Kelley cb37a5c1fb std.Io.Threaded: fix fileReadPositional error.IsDir for wasi 2026-01-15 14:18:20 -08:00
Andrew Kelley e70def70ec std.Io.Threaded: passing memory mapping tests on wasm32-wasi 2026-01-15 14:18:20 -08:00
Andrew Kelley c917f619f0 std: fix compilation failures on various targets 2026-01-15 14:18:20 -08:00
Andrew Kelley eb163361d9 std.Io.File.MemoryMap: add some alignment type safety 2026-01-15 14:18:20 -08:00
Andrew Kelley 4821898432 std.Io.File.MemoryMap API tuning
- remove file_size parameter from MemoryMap.write
- remove requirement for mapping length to be aligned
- align allocated fallback memory
- add unit test for std.Io.Threaded.disable_memory_mapping = true
- add unit test for MemoryMap.setLength
2026-01-15 14:18:20 -08:00
Andrew Kelley bed7bc37c4 std.File.MemoryMap updates
- change offset to u64
- make len non-optional
- make write take a file_size parameter
- std.Io.Threaded: introduce disable_memory_mapping flag to force it to
  take the fallback path.

Additionally:

- introduce BlockSize to File.Stat. On Windows, based on cached call to
  NtQuerySystemInformation. On unsupported OS's, set to 1.
- support File.NLink on Windows. this was available the whole time, we
  just didn't see the field at first.
- remove EBADF / INVALID_HANDLE from reading/writing file error sets
2026-01-15 14:18:20 -08:00
Andrew Kelley a70e006157 std: add unit test for memory mapping 2026-01-15 14:18:20 -08:00
Andrew Kelley 5a7dc4b0fa std.Io: introduce File.MemoryMap
by defining the pointer contents to only be synchronized after explicit
sync points, makes it legal to have a fallback implementation based on
file operations while still supporting a handful of use cases for memory
mapping.

furthermore, it makes it legal for evented I/O implementations to use
evented file I/O for the sync points rather than memory mapping.

not yet done:
- implement checking the length when options.len is null
- some windows impl work
- some wasi impl work
- unit tests
- integration with compiler
2026-01-15 14:18:20 -08:00
Matthew Lugg c518593e97 std.Io.Threaded: spurious unparks are possible
Apparently the thread parking APIs on Windows and NetBSD aren't as good
as I thought---or, at least, the way they're *used* makes them not as
good. It's perfectly possible to use these APIs in a way where you don't
trigger spurious wakeups, but standard primitives (SRWLOCK on Windows,
pthread bits on NetBSD) are perfectly happy to leave pending unparks
sitting around, meaning in practice you have to assume spurious unparks
are possible. This brings me great sadness... but we soldier on!
2026-01-15 01:38:09 +01:00
Alex Rønne Petersen 3da6e67199 std.Io.test: disable Group.concurrent on linux w/o libc
https://codeberg.org/ziglang/zig/issues/30096
2026-01-13 21:27:53 +01:00
Ryan Liptak 2301f2ecdf NtSetInformationFile: remove const from FileInformation buffer param
When targeting x86-windows, this parameter referring to read-only memory can result in an ACCESS_VIOLATION error, and this has been seen when using FILE_DISPOSITION_INFORMATION_EX. It's unclear how exactly this ACCESS_VIOLATION is occurring, though, as the memory does not actually change before/after the call.

Closes https://codeberg.org/ziglang/zig/issues/30802
2026-01-13 20:45:38 +01:00
Carl Åstholm 0a8e8e67d7 Misc. std.Io fixes for WASI and Emscripten
- Corrects WASI `UTIME_*` definitions now that the libc build has been
  fixed (see previous commit), and adds the corresponding definitions
  for Emscripten which were missing.
- Fixes `dirReadUnimplemented()`, which didn't compile.
- Prevents a dependency on `pthread_kill` from being pulled in in
  single-threaded Emscripten builds, where it isn't defined.

With these changes, Emscripten can now participate in juicy main.
2026-01-12 22:38:21 +01:00
Ryan Liptak b4831403c9 fileRead functions: handle INVALID_FUNCTION on Windows and map it to error.IsDir
INVALID_FUNCTION may be possible in other scenarios as well, but it is verifiably returned when the handle refers to a directory.
2026-01-11 02:08:18 -08:00
InKryption 707823abdb fix semantic UAFs in std.Io.Threaded 2026-01-10 17:43:33 +01:00
Kevin Primm b929078dac std.Io.Threaded: Raise specific error when DNS lookup returns no A/AAAA records
closes #25948
2026-01-08 20:44:47 -08:00
Jon Parise efe649b13e std.Io.net: make HostName.validate RFC 1123-compliant
The implementation of HostName.validate was too generous. It considered
strings like ".example.com", "exa..mple.com", and "-example.com" to be
valid hostnames, which is incorrect according to RFC 1123 (the currently
accepted standard).

Reviewed-on: https://github.com/ziglang/zig/pull/25710
2026-01-08 20:40:32 -08:00
Andrew Kelley ecea8cc16d std.Io.Threaded: refactor some error handling 2026-01-08 13:35:47 -08:00
Andrew Kelley 09028bac29 std.Io.Threaded: fix init for single-threaded 2026-01-08 12:36:41 -08:00
Andrew Kelley b0570b807f Merge pull request 'std.Io.Threaded: clock_nanosleep is not linux-only' (#30746) from clock_nanosleep into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30746
2026-01-08 21:00:36 +01:00
Andrew Kelley 6f7968f165 Merge branch "remove many std.posix functions"
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30741
2026-01-08 00:19:12 -08:00
Andrew Kelley 4319c8924e std.Io.Threaded: clock_nanosleep is not linux-only
clock_nanosleep is specified by POSIX but not implemented on these
hereby shamed operating systems:
* macOS
* OpenBSD (which defines TIMER_ABSTIME for some reason...?)
2026-01-07 21:13:16 -08:00
moriazoso 514b103edb std.Io.Threaded: correctly initialize PosixAddress/WsaAddress from sockaddr (#30722)
Resolves ziglang/zig#30672 - UB caused by `std.Io.Threaded.netLookupFallible` incorrectly initializing `PosixAddress`/`WsaAddress` from `*sockaddr`.

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30722
Co-authored-by: moriazoso <greysonmurray.dev@gmail.com>
Co-committed-by: moriazoso <greysonmurray.dev@gmail.com>
2026-01-08 06:01:44 +01:00
Andrew Kelley ce89006035 std.Io.Kqueue: fix bitrot 2026-01-07 18:00:36 -08:00
Andrew Kelley 3961fe3de9 std: move posix.kevent to Io.Kqueue 2026-01-07 17:33:07 -08:00
Andrew Kelley 2c6304efc7 std: move posix.kqueue to Io.Kqueue.createFileDescriptor 2026-01-07 17:33:07 -08:00
Andrew Kelley 7248b4a4e4 std.fs: deprecate base64 APIs
100% of std.fs is now deprecated.
2026-01-07 17:33:06 -08:00
Andrew Kelley 5d0929c40d std.Io.Threaded.randomSecure: eliminate dead code 2026-01-07 11:03:37 -08:00
Andrew Kelley 1ddae8585a std.Io.Threaded: add procfs fallback for fileHardLink
oof what a clunky set of functionality we have here
2026-01-07 11:03:37 -08:00
Andrew Kelley 7e8c7e5696 std.Io: fix AT_SYMLINK_FOLLOW flags
hard linking has the backwards default, which uses a different flag
2026-01-07 11:03:37 -08:00
Andrew Kelley ee574f665c std.Io.Dir: introduce renamePreserve and use it in File.Atomic.link
breaking change: the error for renaming over a non-empty directory now
returns error.DirNotEmpty rather than error.PathAlreadyExists.
2026-01-07 11:03:37 -08:00
Andrew Kelley 8e1850e277 std.Io.Threaded: tweak logic for use_dev_urandom 2026-01-07 11:03:37 -08:00