Commit graph

141 commits

Author SHA1 Message Date
Andrew Kelley
a6347a68a9 std.Io.net: implement receiving connectionless messages 2025-10-29 06:20:48 -07:00
Andrew Kelley
0e9280ef1a std.Io: extract Dir to separate file 2025-10-29 06:20:48 -07:00
Andrew Kelley
fc1e3d5bc9 Io.net: partial implementation of dns lookup 2025-10-29 06:20:48 -07:00
Andrew Kelley
e7729a7b89 std: start moving fs.File to Io 2025-10-29 06:20:48 -07:00
Alex Rønne Petersen
dba1bf9353 remove all Oracle Solaris support
There is no straightforward way for the Zig team to access the Solaris system
headers; to do this, one has to create an Oracle account, accept their EULA to
download the installer ISO, and finally install it on a machine or VM. We do not
have to jump through hoops like this for any other OS that we support, and no
one on the team has expressed willingness to do it.

As a result, we cannot audit any Solaris contributions to std.c or other
similarly sensitive parts of the standard library. The best we would be able to
do is assume that Solaris and illumos are 100% compatible with no way to verify
that assumption. But at that point, the solaris and illumos OS tags would be
functionally identical anyway.

For Solaris especially, any contributions that involve APIs introduced after the
OS was made closed-source would also be inherently more risky than equivalent
contributions for other proprietary OSs due to the case of Google LLC v. Oracle
America, Inc., wherein Oracle clearly demonstrated its willingness to pursue
legal action against entities that merely copy API declarations.

Finally, Oracle laid off most of the Solaris team in 2017; the OS has been in
maintenance mode since, presumably to be retired completely sometime in the 2030s.

For these reasons, this commit removes all Oracle Solaris support.

Anyone who still wishes to use Zig on Solaris can try their luck by simply using
illumos instead of solaris in target triples - chances are it'll work. But there
will be no effort from the Zig team to support this use case; we recommend that
people move to illumos instead.
2025-10-27 07:35:38 -07:00
Wim de With
8d4b5662cd std.{c,posix}: add getgid and getegid 2025-10-21 06:10:41 +02:00
Ryan Liptak
88fd8ce860 windows: Always try using POSIX_SEMANTICS/etc for rename/delete
The compile-time check against the minimum version here wasn't appropriate, since it still makes sense to try using FILE_RENAME_INFORMATION_EX even if the minimum version is something like `xp`, since that doesn't rule out the possibility of the compiled code running on Windows 10/11. This compile-time check was doubly bad since the default minimum windows version (`.win10`) was below the `.win10_rs5` that was checked for, so when providing a target like `x86_64-windows-gnu` it'd always rule out using this syscall.

After this commit, we always try using FILE_RENAME_INFORMATION_EX and then let the operating system tell us when some aspect of it is not supported. This allows us to get the benefits of these new syscalls/flags whenever it's actually possible.

The possible error returns were validated experimentally:
- INVALID_PARAMETER is returned when the underlying filesystem is FAT32
- INVALID_INFO_CLASS is returned on Windows 7 when trying to use FileRenameInformationEx/FileDispositionInformationEx
- NOT_SUPPORTED is returned on Windows 10 >= .win10_rs5 when setting a bogus flag value (I used `0x1000`)
2025-10-17 00:50:16 -07:00
mlugg
923ddd94a1
std.posix: panic on unexpected error in munmap
This is to help diagnose #25498. We can't use `unexpectedErrno` here,
because `std.posix.munmap` is infallible. So, when the flag is set to
report unexpected errnos, we just call `std.debug.panic` to provide
details instead of doing `unreachable`.

Pushing straight to master after running checks locally; there's no
point waiting for CI on the PR just for this.
2025-10-11 11:46:30 +01:00
usebeforefree
62e3d46287 replaced https://simonsapin.github.io/wtf-8/ with https://wtf-8.codeberg.page/ 2025-10-10 23:53:00 +02:00
Alex Rønne Petersen
36dbe66cf4
std: stop exposing anything having to do with ucontext_t
This type is useful for two things:

* Doing non-local control flow with ucontext.h functions.
* Inspecting machine state in a signal handler.

The first use case is not one we support; we no longer expose bindings to those
functions in the standard library. They're also deprecated in POSIX and, as a
result, not available in musl.

The second use case is valid, but is very poorly served by the standard library.
As evidenced by my changes to std.debug.cpu_context.signal_context_t, users will
be better served rolling their own ucontext_t and especially mcontext_t types
which fit their specific situation. Further, these types tend to evolve
frequently as architectures evolve, and the standard library has not done a good
job keeping up, or even providing them for all supported targets.
2025-10-10 04:43:18 +02:00
Michael Pfaff
7bf740ee71 Deprecate old realpathW correctly
- Rename modified `realpathW` to `realpathW2`
- Re-add original `realpathW`
- Add deprecation notice to `realpathW`
2025-10-08 17:07:38 -07:00
Michael Pfaff
eb46bbba34 Fix realpathW out_buffer size 2025-10-08 17:07:38 -07:00
Michael Pfaff
a7dfc6470f Reuse pathname_w buffer as out_buffer when calling realpathW 2025-10-08 17:07:38 -07:00
Michael Pfaff
f2227ae677 Return WTF16LE encoded path from realpathW 2025-10-08 17:07:38 -07:00
mlugg
dae703d3c0
std.posix.abort: only trigger breakpoint on Windows if being debugged
Processes should reasonably be able to expect their children to abort
with typical exit codes, rather than a debugger breakpoint signal. This
flag in the PEB is what would be checked by `IsDebuggerPresent` in
kernel32, which is the function you would typically use for this
purpose.

This fixes `test-stack-trace` failures on Windows, as these tests were
expecting exit code 3 to indicate abort.
2025-09-30 13:44:55 +01:00
mlugg
a18fd41064
std: rework/remove ucontext_t
Our usage of `ucontext_t` in the standard library was kind of
problematic. We unnecessarily mimiced libc-specific structures, and our
`getcontext` implementation was overkill for our use case of stack
tracing.

This commit introduces a new namespace, `std.debug.cpu_context`, which
contains "context" types for various architectures (currently x86,
x86_64, ARM, and AARCH64) containing the general-purpose CPU registers;
the ones needed in practice for stack unwinding. Each implementation has
a function `current` which populates the structure using inline
assembly. The structure is user-overrideable, though that should only be
necessary if the standard library does not have an implementation for
the *architecture*: that is to say, none of this is OS-dependent.

Of course, in POSIX signal handlers, we get a `ucontext_t` from the
kernel. The function `std.debug.cpu_context.fromPosixSignalContext`
converts this to a `std.debug.cpu_context.Native` with a big ol' target
switch.

This functionality is not exposed from `std.c` or `std.posix`, and
neither are `ucontext_t`, `mcontext_t`, or `getcontext`. The rationale
is that these types and functions do not conform to a specific ABI, and
in fact tend to get updated over time based on CPU features and
extensions; in addition, different libcs use different structures which
are "partially compatible" with the kernel structure. Overall, it's a
mess, but all we need is the kernel context, so we can just define a
kernel-compatible structure as long as we don't claim C compatibility by
putting it in `std.c` or `std.posix`.

This change resulted in a few nice `std.debug` simplifications, but
nothing too noteworthy. However, the main benefit of this change is that
DWARF unwinding---sometimes necessary for collecting stack traces
reliably---now requires far less target-specific integration.

Also fix a bug I noticed in `PageAllocator` (I found this due to a bug
in my distro's QEMU distribution; thanks, broken QEMU patch!) and I
think a couple of minor bugs in `std.debug`.

Resolves: #23801
Resolves: #23802
2025-09-30 13:44:54 +01:00
mlugg
c2ada49354
replace usages of old std.debug APIs
src/crash_handler.zig is still TODO though, i am planning bigger changes there
2025-09-30 13:44:51 +01:00
mlugg
67fa5664b7
std.posix: mark getcontext as unsupported by default 2025-09-30 13:44:51 +01:00
rpkak
bc512648db use copy_file_range syscall on linux 2025-09-24 03:08:12 +02:00
John Benediktsson
37ecaae639
std.fmt: migrate bufPrintZ to bufPrintSentinel (#25260) 2025-09-19 05:02:22 +00:00
Andrew Kelley
d6b4e1918b
Merge pull request #25195 from blblack/netdefs
std: Add several sockopt-related constants and structs
2025-09-17 21:43:23 -07:00
Andrew Kelley
d2e4ad613b
Merge pull request #25217 from blblack/setsiderr
std.os.linux.setsid(): return raw syscall0 result
2025-09-17 21:14:08 -07:00
Justus Klausecker
9b4cae4750 std.posix.ptrace: support more platforms more correctly 2025-09-13 14:35:19 +02:00
Brandon Black
04071d64bb std.os.linux.setsid(): return raw syscall0 result
When not linking libc on 64-bit Linux and calling posix.setsid(),
we get a type error at compile time inside of posix.errno().  This
is because posix.errno()'s non-libc branch expects a usize-sized
value, which is what all the error-returning os.linux syscalls
return, and linux.setsid() instead returned a pid_t, which is only
32 bits wide.

This and the other 3 pid-related calls just below it (getpid(),
getppid(), and gettid()) are the only Linux syscall examples here
that are casting their return values to pid_t. For the other 3
this makes sense: those calls are documented to have no possible
errors and always return a valid pid_t value.

However, setsid() actually can return the error EPERM, and
therefore needs to return the raw value from syscall0 for
posix.errno() to process like normal.

Additionally, posix.setsid() needs an @intCast(rc) for the success
case as a result, like most other such cases.
2025-09-12 07:19:01 -05:00
Brandon Black
7995697527 std: add IP, IPV6, IPTOS sockopt constants
Because these lists are very long in several cases and quite
varied, I opted to place them in the existing c/foo.zig files.

There are many other sets of network-related constants like this
to add over time across all the OSes.  For now I picked these
because I needed a few constants from each of these namespaces for
my own project, so I tried to flesh out these namespaces
completely as best I could, at least for basic sockopt purposes.

Note windows has some of these already defined in ws2_32 as
individual constants rather than contained in a namespacing
struct.  I'm not sure what to do with that in the long run (break
it and namespace them?), but this doesn't change the status quo
for windows in any case.
2025-09-09 17:01:20 -05:00
Brandon Black
0e45b9d5db std: add linger struct for SO.LINGER 2025-09-09 16:59:50 -05:00
Brandon Black
3e372f1994 std: add in_pktinfo and in6_pktinfo structs defs
in_pktinfo is only used on a few targets for the IP_PKTINFO
sockopt, as many BSDs use an alternate mechanism (IP_RECVDSTADDR)
that doesn't require a special struct.  in6_pktinfo is more
universal.
2025-09-09 16:59:50 -05:00
Brandon Black
c70521e7b1 std: Add SCM constants for socket control messages 2025-09-09 16:59:50 -05:00
Brandon Black
c4c6c01cc5 recvmsg: posix wrapper, void on windows
Also, added EPIPE to recvfrom() error set (it's a documented error
for unix and tcp sockets, at least), which recvmsg() largely
shares.  Windows has an odd, callback-based form of recvmsg() that
doesn't fit the normal interface here.
2025-09-08 14:45:51 -05:00
Brandon Black
79313d844f socketpair: posix wrapper, void on windows
socketpair is something like a pipe2() for sockets, and generally
only works for AF_UNIX sockets for most platforms.  Winsock2
explicitly does not support this call, even though it does have
AF_UNIX sockets.
2025-09-08 14:45:51 -05:00
Brandon Black
048f9126b8 Return runtime err for EISCONN when connecting
Fixes #25063
2025-09-03 22:01:45 +02:00
Linus Groh
deb46e1dd3 std.posix: Fix getRandomBytesDevURandom()
This is not exercised in CI because most platforms have a dedicated
implementation in getrandom().
2025-09-03 02:23:19 +01:00
Andrew Kelley
79f267f6b9 std.Io: delete GenericReader
and delete deprecated alias std.io
2025-08-29 17:14:26 -07:00
Sardorbek Imomaliev
01b5023868
drop NameTooLong from sysctlbynameZ error set (#24909) 2025-08-21 12:36:57 +02:00
Brandon Black
8248597a27 Add mlock syscalls to std.c and std.posix
Linux already gained the relevant syscalls and consts in #24473

The basic mlock() and munlock() are fairly universal across the
*nix world with a consistent interface, but are missing on wasi
and windows.

The mlockall() and munlockall() calls are not as widely supported
as the basic ones.  Notable non-implementers include darwin,
haiku, and serenity (and of course wasi and windows again).

mlock2() is Linux-only, as are its MLOCK flags.
2025-08-20 23:38:45 +02:00
kcbanner
95f57c3369 net: Always set WSA_FLAG_OVERLAPPED when creating Windows sockets. Rework send and receive logic to use overlapped I/O.
build-web: Remove the now-redundant supports_recv logic
2025-08-09 18:48:15 -04:00
TibboddiT
2cf15bee03
Fix some libc version checks for Bionic 2025-08-08 01:26:00 +00:00
Linus Groh
ce776d3245 std: Add serenity to more OS checks 2025-07-30 23:28:58 +01:00
Linus Groh
813a0f125e std.posix: Default ACCMODE to NONE for serenity
Unlike all other platforms where RDONLY is 0 it does not work as a
default for the O flags on serenity - various syscalls other than
'open', e.g. 'pipe', return EINVAL if unexpected bits are set in the
flags.
2025-07-30 23:27:32 +01:00
Andrew Kelley
733b208256 std.posix.ftruncate: handle NonResizable properly 2025-07-25 14:15:33 -07:00
Linus Groh
26bd74e87f std.posix: Fix ACCMODE values for serenity 2025-07-24 00:54:40 +01:00
Andrew Kelley
96cbdd145d std.fs.File.Reader: fix sendFile logic
it wasn't accounting for both writer and reader buffering
2025-07-21 20:00:45 -07:00
Brandon Black
e8a4e47d38 Add setsid to std.(c|posix)
The interface and errors for this seem to be very universal and
generic. Note Linux already has this defined as a syscall as well.
2025-07-14 07:26:49 +02:00
Carmen
5b4e982169
std.os.uefi.tables: ziggify boot and runtime services (#23441)
* std.os.uefi.tables: ziggify boot and runtime services

* avoid T{} syntax

Co-authored-by: linusg <mail@linusgroh.de>

* misc fixes

* work

* self-review quickfixes

* dont make MemoryMapSlice generic

* more review fixes, work

* more work

* more work

* review fixes

* update boot/runtime services references throughout codebase

* self-review fixes

* couple of fixes i forgot to commit earlier

* fixes from integrating in my own project

* fixes from refAllDeclsRecursive

* Apply suggestions from code review

Co-authored-by: truemedian <truemedian@gmail.com>

* more fixes from review

* fixes from project integration

* make natural alignment of Guid align-8

* EventRegistration is a new opaque type

* fix getNextHighMonotonicCount

* fix locateProtocol

* fix exit

* partly revert 7372d65

* oops exit data_len is num of bytes

* fixes from project integration

* MapInfo consistency, MemoryType update per review

* turn EventRegistration back into a pointer

* forgot to finish updating MemoryType methods

* fix IntFittingRange calls

* set uefi.Page nat alignment

* Back out "set uefi.Page nat alignment"

This backs out commit cdd9bd6f7f5fb763f994b8fbe3e1a1c2996a2393.

* get rid of some error.NotFound-s

* fix .exit call in panic

* review comments, add format method

* fix resetSystem data alignment

* oops, didnt do a final refAllDeclsRecursive i guess

* review comments

* writergate update MemoryType.format

* fix rename

---------

Co-authored-by: linusg <mail@linusgroh.de>
Co-authored-by: truemedian <truemedian@gmail.com>
2025-07-12 17:18:53 +00:00
Atlas Yu
2cda4cfb39 std.posix.send: should expect ConnectionRefused
Closes: #20219
2025-07-11 13:06:13 +02:00
Andrew Kelley
0e37ff0d59 std.fmt: breaking API changes
added adapter to AnyWriter and GenericWriter to help bridge the gap
between old and new API

make std.testing.expectFmt work at compile-time

std.fmt no longer has a dependency on std.unicode. Formatted printing
was never properly unicode-aware. Now it no longer pretends to be.

Breakage/deprecations:
* std.fs.File.reader -> std.fs.File.deprecatedReader
* std.fs.File.writer -> std.fs.File.deprecatedWriter
* std.io.GenericReader -> std.io.Reader
* std.io.GenericWriter -> std.io.Writer
* std.io.AnyReader -> std.io.Reader
* std.io.AnyWriter -> std.io.Writer
* std.fmt.format -> std.fmt.deprecatedFormat
* std.fmt.fmtSliceEscapeLower -> std.ascii.hexEscape
* std.fmt.fmtSliceEscapeUpper -> std.ascii.hexEscape
* std.fmt.fmtSliceHexLower -> {x}
* std.fmt.fmtSliceHexUpper -> {X}
* std.fmt.fmtIntSizeDec -> {B}
* std.fmt.fmtIntSizeBin -> {Bi}
* std.fmt.fmtDuration -> {D}
* std.fmt.fmtDurationSigned -> {D}
* {} -> {f} when there is a format method
* format method signature
  - anytype -> *std.io.Writer
  - inferred error set -> error{WriteFailed}
  - options -> (deleted)
* std.fmt.Formatted
  - now takes context type explicitly
  - no fmt string
2025-07-07 22:43:51 -07:00
jaune
ef8db03d52 std.posix.accept: add WSAENOTSOCK 2025-07-07 00:26:21 +02:00
Brandon Black
aa1556156e std.posix.getsockopt: set option length correctly
Fixes #24293
2025-07-03 09:41:26 +02:00
Jacob Young
1f98c98fff x86_64: increase passing test coverage on windows
Now that codegen has no references to linker state this is much easier.

Closes #24153
2025-06-19 18:41:12 -04:00
Pat Tullmann
6eb5e56306 std.posix: Add sigrtmin() and sigrtmax()
For C code the macros SIGRTMIN and SIGRTMAX provide these values.  In
practice what looks like a constant is actually provided by a libc call.
So the Zig implementations are explicitly function calls.

glibc (and Musl) export a run-time minimum "real-time" signal number,
based on how many signals are reserved for internal implementation details
(generally threading).  In practice, on Linux, sigrtmin() is 35 on glibc
with the older LinuxThread and 34 with the newer NPTL-based
implementation.  Musl always returns 35.  The maximum "real-time" signal
number is NSIG - 1 (64 on most Linux kernels, but 128 on MIPS).

When not linking a C Library, Zig can report the full range of "rt"
signals (none are reserved by Zig).

Fixes #21189
2025-05-09 15:10:25 +02:00