aboutsummaryrefslogtreecommitdiff
path: root/lib/std/os/linux.zig
AgeCommit message (Collapse)Author
2025-10-29std: make signal numbers into an enumAndrew Kelley
fixes start logic for checking whether IO/POLL exist
2025-10-29std: move DNS record enum to a better namespaceAndrew Kelley
2025-10-29std: fix msghdr and cmsghdr when using musl libcAndrew Kelley
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-29std.Io: implement netSendAndrew Kelley
2025-10-29std.os.linux: remove unnecessary warnings from sendmmsgAndrew Kelley
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-29std.os.linux: remove sendmmsg workaroundAndrew Kelley
This "fix" is too opinionated to belong here. Better instead to document the pitfalls.
2025-10-23std.Target: add arceb and xtensaeb Cpu.Arch tagsAlex Rønne Petersen
2025-10-19std.os.linux: add pivot_root syscallWim de With
2025-10-19std.os.linux: add setns syscallWim de With
2025-10-18std.os.linux: add or1k arch bitsAlex Rønne Petersen
2025-10-18os.linux.timeval: use same field names as std.cBrandon Black
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-17Merge pull request #25610 from alexrp/std-os-linux-cleanupAlex Rønne Petersen
`std.os.linux`: some miscellaneous cleanup in arch bits
2025-10-17std.os.linux: add incomplete x32 arch bits fileAlex Rønne Petersen
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-17std.os.linux: add incomplete mipsn32 arch bits fileAlex Rønne Petersen
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-17std.os.linux: retranslate F_* constants and Flock struct, and move out of ↵Alex Rønne Petersen
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-17std.os.linux: move some generic decls out of the arch bitsAlex Rønne Petersen
2025-10-16std.os.linux: fix a bunch of syscall and time ABI issues on hexagonAlex Rønne Petersen
I'm not particularly happy with sprinkling this check everywhere, but the situation should improve once we complete the time64 migration.
2025-10-10std: stop exposing anything having to do with ucontext_tAlex Rønne Petersen
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-09std.os.linux: define PROT.SEM for xtensaAlex Rønne Petersen
2025-09-30std: rework/remove ucontext_tmlugg
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-28std.os.linux: delete SA.RESTORER and k_sigaction.restorer for hexagon, ↵Alex Rønne Petersen
loongarch, mips, riscv The kABIs for these architectures don't define these concepts.
2025-09-24use copy_file_range syscall on linuxrpkak
2025-09-17Merge pull request #25195 from blblack/netdefsAndrew Kelley
std: Add several sockopt-related constants and structs
2025-09-17Merge pull request #25217 from blblack/setsiderrAndrew Kelley
std.os.linux.setsid(): return raw syscall0 result
2025-09-17Merge pull request #25225 from Justus2308/darwin-fixesAndrew Kelley
std.*.ptrace: support more platforms and features more correctly
2025-09-13std.os.linux.ptrace: add PTRACE_EVENT_* and PTRACE_O_* valuesJustus Klausecker
2025-09-12linux: Doc and check retval for no-fail pid callsBrandon Black
The switch from @bitCast() to @intCast() here safety-checks Linux's assertion that these 3 calls never return errors (negative values as pid_t). getppid() can legally return 0 if the parent is in a different pid namespace, but this is not an error.
2025-09-12std.os.linux.setsid(): return raw syscall0 resultBrandon Black
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-12std.os.linux.socketpair(): switch to unsigned argsBrandon Black
We need std.os.linux and std.c to agree on the types here, or else we'd have to pointlessly cast across the difference up in the std.posix wrapper. I ran into this as a type error the first time I tried to compile my code that calls posix.socketpair() on Linux without libc. All of our existing socket calls with these kinds of arguments in std (including the existing c.socketpair as well as os.linux.socket in this same file) use unsigned for all of these parameters, and so this brings linux.socketpair() into alignment with everything else.
2025-09-09std: add IP, IPV6, IPTOS sockopt constantsBrandon Black
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-09std: add linger struct for SO.LINGERBrandon Black
2025-09-09std: add in_pktinfo and in6_pktinfo structs defsBrandon Black
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-09std: Add SCM constants for socket control messagesBrandon Black
2025-09-03Fix cmsghdr struct for the *nixesBrandon Black
Previously we had a single definition of std.c.cmsghdr for all libc-linking platforms which aliased from the Solaris definition, a superfluous matching one in std.os.dragonfly, and no others. The existing definition from std.c didn't actually work for Linux, as Linux's "len" field is usize in the kernel's definition. Emscripten follows the Linux model of course (but uses the binary-compatible musl definition, which has an endian-sensitive padding scheme to make the len type "socklen_t" even though the kernel uses a usize, which is fair). This unifies and documents all the known *nix-ish cases (I'm not sure if wasi or windows really has cmsghdr support? Could be added later, void for now), such that c.cmsghdr and posix.system.cmsghdr should work correctly for all the known cases here, libc or otherwise.
2025-08-25os.linux: faccessat wrapper prefer to faccessat syscall when flags is zero.Qun He
This make `fs.Dir.access` has compatibility like the zig version before. With this change the `zig build --search-prefix` command would work again like the zig 0.14 version when used on Ubuntu22.04, kernel version 5.4.
2025-08-18Expanded std.os.linux perf-related definitions (#24264)Giuseppe Cesarano
* Added perf_event_header definition * Added perf_event_mmap_page definition * Removed default values for perf_event_header * Fixed comments typos * Updated perf_event_attr definition * Explicit packet struct type * PERF.RECORD from struct to enum * fix typo: miscs to misc * misc as packed struct * cpu_mode as named enum * Rescoping CPU_MODE
2025-08-16implement registering NAPI on IoUring (#24850)Özgür Akkurt
2025-08-14Linux: Use time64 syscalls when availableStephen Gregoratto
Newer 32-bit Linux targets like 32-bit RISC-V only use the 64-bit time ABI, with these syscalls having `time64` as their suffix. This is a stopgap solution in favor of a full audit of `std.os.linux` to prepare for #4726. See also #21440 for prior art.
2025-08-14Linux: Update syscall list for 6.16Stephen Gregoratto
The generic syscall table has different names for syscalls that take a timespec64 on 32-bit targets, in that it adds the `_time64` suffix. Similarly, the `_time32` suffix has been removed. I'm not sure if the existing logic for determining the proper timespec struct to use was subtly broken, but it should be a good chance to finish #4726 - we only have 12 years after all... As for the changes since 6.11..6.16: 6.11: - x86_64 gets `uretprobe`, a syscall to speed up returning BPF probes. - Hexagon gets `clone3`, but don't be fooled: it just returns ENOSYS. 6.13: - The `*xattr` family of syscalls have been enhanced with new `*xattrat` versions, similar to the other file-based `at` calls. 6.15: - Atomically create a detached mount tree and set mount options on it. Finally, this commit also adds the syscall numbers for OpenRISC and maps it to the `or1k` cpu.
2025-08-06#24471: add mlock syscalls to std.os.linuxkj4tmp@gmail.com
2025-07-22aarch64: add new from scratch self-hosted backendJacob Young
2025-07-07std.fmt: breaking API changesAndrew Kelley
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-07os: fix missing and incorrect msghdr definitionsNameless
Macos uses the BSD definition of msghdr All linux architectures share a single msghdr definition. Many architectures had manually inserted padding fields that were endian specific and some had fields with different integers. This unifies all architectures to use a single correct msghdr definition.
2025-06-18linux: futex v2 API updatesPat Tullmann
* `futex2_waitv` always takes a 64-bit timespec. Perhaps the `kernel_timespec` should be renamed `timespec64`? Its used in iouring, too. * Add `packed struct` for futex v2 flags and parameters. * Add very basic "tests" for the futex v2 syscalls (just to ensure the code compiles). * Update the stale or broken comments. (I could also just delete these they're not really documenting Zig-specific behavior.) Given that the futex2 APIs are not used by Zig's library (they're a bit too new), and the fact that these are very specialized syscalls, and they currently provide no benefit over the existing v1 API, I wonder if instead of fixing these up, we should just replace them with a stub that says 'use a 3rd party library'.
2025-06-17linux: futex v1 API cleanupPat Tullmann
* Use `packed struct` for flags arguments. So, instead of `linux.FUTEX.WAIT` use `.{ .cmd = .WAIT, .private = true }` * rename `futex_wait` and `futex_wake` which didn't actually specify wait/wake, as `futex_3arg` and `futex_4arg` (as its the number of parameters that is different, the `op` is whatever is specified. * expose the full six-arg flavor of the syscall (for some of the advanced ops), and add packed structs for their arguments. * Use a `packed union` to support the 4th parameter which is sometimes a `timespec` pointer, and sometimes a `u32`. * Add tests that make sure the structure layout is correct and that the basic argument passing is working (no actual futexes are contended).
2025-05-20compiler: Scaffold stage2_powerpc backend.Alex Rønne Petersen
Nothing interesting here; literally just the bare minimum so I can work on this on and off in a branch without worrying about merge conflicts in the non-backend code.
2025-05-18start: Don't artificially limit some posixCallMainAndExit() logic to Linux.Alex Rønne Petersen
This code applies to ~any POSIX OS where we don't link libc. For example, it'll be useful for FreeBSD and NetBSD. As part of this, move std.os.linux.pie to std.pie since there's really nothing Linux-specific about what that file is doing.
2025-05-10Fix implementation of std.os.linux.accept on x86Michael Pfaff
2025-05-09std.posix: Add sigrtmin() and sigrtmax()Pat Tullmann
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-03disable getauxvalImpl instrumentation as libfuzzer's allocator may need to ↵tjog
call it