1780 Commits

Author SHA1 Message Date
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
Alex Rønne Petersen
f723d69a58
std.os.linux.tls: add hppa support
Turns out Linux on PA-RISC does system calls in a pretty fascinating way; see
arch/parisc/kernel/syscall.S for details.
2025-10-23 09:27:17 +02:00
Alex Rønne Petersen
aff557e4e8
std.os.linux.tls: add sh support 2025-10-23 09:27:17 +02:00
Alex Rønne Petersen
5e921261a0
std.os.linux.tls: add microblaze support
Implemented according to glibc because I'm pretty sure musl gets it wrong.
2025-10-23 09:27:17 +02:00
Alex Rønne Petersen
9fde44229c
std.os.linux.tls: add alpha support 2025-10-23 09:27:17 +02:00
Alex Rønne Petersen
3e2daa509a
std.Target: add arceb and xtensaeb Cpu.Arch tags 2025-10-23 09:27:17 +02:00
Wim de With
49eea79ec2 std.os.linux: add pivot_root syscall 2025-10-19 22:24:24 +02:00
Wim de With
5442e06632 std.os.linux: add setns syscall 2025-10-19 22:24:24 +02:00
Alex Rønne Petersen
c571840e71
std.os.linux: add or1k arch bits 2025-10-18 22:27:35 +02:00
Alex Rønne Petersen
35e819aac8
std.os.linux.tls: implement or1k support 2025-10-18 22:27:35 +02:00
Alex Rønne Petersen
6bf5b7f2b4
Merge pull request #25622 from alexrp/inline-asm-fixes
`std`: some miscellaneous inline asm fixes for mips, mips64, mipsn32, and x32
2025-10-18 22:26:09 +02:00
Alex Rønne Petersen
1466401c15
Merge pull request #25614 from squeek502/windows-rename-delete
windows: Always try using POSIX_SEMANTICS/etc for rename/delete
2025-10-18 20:45:22 +02:00
Alex Rønne Petersen
3585f79f44
std.os.linux: remove syscall7() on mips64/mipsn32
I'm not sure why this was here, but this is only a thing on O32, not N32/N64.
2025-10-18 14:01:41 +02:00
Alex Rønne Petersen
842de66db8
std.os.linux: fix some issues in x32 inline asm
ref https://github.com/ziglang/zig/issues/22189
2025-10-18 11:16:31 +02:00
Alex Rønne Petersen
f3eacec226
std.os.linux: fix some issues in mipsn32 inline asm
ref https://github.com/ziglang/zig/issues/22189
2025-10-18 11:16:31 +02:00
Alex Rønne Petersen
b8d776928a
std: make all MIPS inline asm safe for MIPS I
MIPS I has load hazards so we need to insert nops in a few places. This is not a
problem for MIPS II and later.

While doing this, I also touched up all the inline asm to use ABI register
aliases and a consistent formatting convention. Also fixed a few places that
didn't properly check if the syscall return value should be negated.
2025-10-18 11:16:31 +02:00
Brandon Black
d18f1dde41 os.linux.timeval: use same field names as std.c
Otherwise, the field names in std.posix.timeval vary by target os.
I think this was an accidental change during the work of #25610
2025-10-18 01:51:44 +02:00
Alex Rønne Petersen
1f8a72175b
Merge pull request #25610 from alexrp/std-os-linux-cleanup
`std.os.linux`: some miscellaneous cleanup in arch bits
2025-10-17 12:07:51 +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
Ryan Liptak
3eb3fbec9c windows: make FILE_DISPOSITION_ constants pub 2025-10-17 00:40:17 -07:00
Alex Rønne Petersen
29fb9e4da7
std.os.linux.tls: don't unnecessarily use std.posix 2025-10-17 02:46:47 +02:00
Alex Rønne Petersen
d5481e6536
std.os.linux: add incomplete x32 arch bits file
This is very likely full of wrong stuff. It's effectively just a copy of the
x86_64 file - needed because the former stopped using usize/isize. To be clear,
this is no more broken than the old situation was; this just makes the
brokenness explicit.
2025-10-17 01:20:33 +02:00
Alex Rønne Petersen
502eca7b09
std.os.linux: add incomplete mipsn32 arch bits file
This is very likely full of wrong stuff. It's effectively just a copy of the
mips64 file - needed because the former stopped using usize/isize. To be clear,
this is no more broken than the old situation was; this just makes the
brokenness explicit.
2025-10-17 01:20:33 +02:00
Alex Rønne Petersen
aa8e53908a
std.os.linux: clean up a bunch of dead consts 2025-10-17 01:20:33 +02:00
Alex Rønne Petersen
dc1bc52dd6
std.os.linux: retranslate F_* constants and Flock struct, and move out of arch bits
Flock is now equivalent to struct flock64, and the related F.* constants map to
the 64-bit variants on 32-bit systems.
2025-10-17 01:20:33 +02:00
Alex Rønne Petersen
cfdc0f0e34
std.os.linux: replace usize/isize in arch bits with fixed types for clarity 2025-10-17 01:20:33 +02:00
Alex Rønne Petersen
fc7a5f2ae4
std.os.linux: move some generic decls out of the arch bits 2025-10-17 01:20:31 +02:00
Alex Rønne Petersen
8970d80355
std.os.linux.thumb: remove some @setRuntimeSafety(false) with no clear purpose 2025-10-16 23:17:25 +02:00
Alex Rønne Petersen
d84faceebd
std.os.linux: remove some pointless asm clobbers in naked fns 2025-10-16 23:15:23 +02:00
Alex Rønne Petersen
05b52da15e
std.os.linux: fix a bunch of syscall and time ABI issues on hexagon
I'm not particularly happy with sprinkling this check everywhere, but the
situation should improve once we complete the time64 migration.
2025-10-16 22:12:42 +02:00
Alex Rønne Petersen
0ace906477
std.os.windows.CONTEXT: add sp field to getRegs() result for x86 2025-10-15 13:59:17 +02:00
Alex Rønne Petersen
b34a13da38 std.os.linux.sparc64: use icc instead of xcc in asm clobbers
LLVM currently doesn't recognize xcc; icc does what we want.
2025-10-14 16:56:44 +02:00
Jacob Young
b2bc6073c8 windows: workaround kernel race condition
This was causing flaky CI failures.
2025-10-10 22:47:36 -07: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
Alex Rønne Petersen
6c760d76b9
std.os.linux: define PROT.SEM for xtensa 2025-10-09 20:42:19 +02:00
Alex Rønne Petersen
c8efebcf53
std.os.linux: remove dead/wrong msghdr definitions in some arch bits 2025-10-09 20:42:19 +02:00
Alex Rønne Petersen
0b33891f4c
std.os.linux: add ucontext_t and mcontext_t for mips/mips64 2025-10-07 16:47:57 +02:00
Alex Rønne Petersen
98af7f34e9
std.os.linux: minor NFC corrections to hexagon ucontext_t and mcontext_t 2025-10-07 16:47:57 +02:00
Alex Rønne Petersen
26403fe3f9
std.os.linux: add mcontext_t and ucontext_t for hexagon 2025-10-05 20:08:55 +02:00
Alex Rønne Petersen
006bc5a8ca
std.os.linux: improve the s390x mcontext_t definition
The old one was correct in terms of layout but very user-hostile.
2025-10-03 03:29:20 +02: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
a12ce28224
std: fix os.linux.x86.syscall6
It was possible for `arg6` to be passed as an operand relative to esp.
In that case, the `push` at the top clobbered esp and hence made the
reference to arg6 invalid. This was manifesting in this branch as broken
stack traces on x86-linux due to an `mmap2` syscall accidentally passing
the page offset as non-zero!

This commit fixes a bug introduced in cb0e6d8aa.
2025-09-30 13:44:53 +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
Alex Rønne Petersen
fe468e4fa3
std.os.linux: delete restore and restore_rt for hexagon, loongarch, mips, riscv 2025-09-28 18:24:04 +02:00
Alex Rønne Petersen
42e4411377
std.os.linux: delete SA.RESTORER and k_sigaction.restorer for hexagon, loongarch, mips, riscv
The kABIs for these architectures don't define these concepts.
2025-09-28 18:23:58 +02:00