aboutsummaryrefslogtreecommitdiff
path: root/lib/std/os/linux/powerpc.zig
AgeCommit message (Collapse)Author
2025-10-29std.os.linux: fix restore for powerpc/powerpc64Alex Rønne Petersen
sigreturn and rt_sigreturn are distinct syscalls on PowerPC.
2025-10-17std.os.linux: clean up a bunch of dead constsAlex Rønne Petersen
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: replace usize/isize in arch bits with fixed types for clarityAlex Rønne Petersen
2025-10-17std.os.linux: move some generic decls out of the arch bitsAlex Rønne Petersen
2025-10-16std.os.linux: remove some pointless asm clobbers in naked fnsAlex Rønne Petersen
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-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-23Don't specify clobbers in `restore_rt`taylor.fish
Per @alexrp, this is unnecessary in naked functions.
2025-09-23Fix PowerPC `restore_rt`taylor.fish
Clang fails to compile the CBE translation of this code ("non-ASM statement in naked function"). Similar to the implementations of `restore_rt` on x86 and ARM, when the CBE is in use, this commit employs alternative inline assembly that avoids using non-immediate input operands.
2025-09-24Fix PowerPC syscalls causing invalid code from CBEtaylor.fish
Fixes #25209. On PowerPC, some registers are both inputs to syscalls and clobbered by them. An example is r0, which initially contains the syscall number, but may be overwritten during execution of the syscall. musl and glibc use a `+` (read-write) constraint to indicate this, which isn't supported in Zig. The current implementation of PowerPC syscalls in the Zig standard library instead lists these registers as both inputs and clobbers, but this results in the C backend generating code that is invalid for at least some C compilers, like GCC, which doesn't support the specifying the same register as both an input and a clobber. This PR changes the PowerPC syscall functions to list such registers as inputs and outputs rather than inputs and clobbers. Thanks to jacobly0 who pointed out that it's possible to have multiple outputs; I had gotten the wrong idea from the documentation.
2025-08-28std.os.linux: powerpc syscalls clobber ctr and xerAlex Rønne Petersen
https://git.musl-libc.org/cgit/musl/commit/?id=f6944eb3c4ce1c97dc39dc36d32390dc9f70b67b
2025-07-16zig fmtAndrew Kelley
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-22Update 32-bit PowerPC syscall functionstaylor.fish
musl and glibc both specify r0 as an output register because its value may be overwritten by system calls. As with the updates for 64-bit PowerPC in the previous commit, this commit brings Zig's syscall functions for 32-bit PowerPC in line with musl and glibc by adding r0 to the list of clobbers. (Listing r0 as both an input and a clobber is as close as we can get to musl, which declares it as a "+r" read-write output, since Zig doesn't support multiple outputs or the "+" specifier.)
2025-04-30linux: update `sigmask` in every arch `ucontext_t`Pat Tullmann
All the existing code that manipulates `ucontext_t` expects there to be a glibc-compatible sigmask (1024-bit). The `ucontext_t` struct need to be cleaned up so the glibc-dependent format is only used when linking glibc/musl library, but that is a more involved change. In practice, no Zig code looks at the sigset field contents, so it just needs to be the right size.
2025-04-07std.os.linux: use heap.pageSize() instead of MMAP2_UNITStefan Weigl-Bosker
2025-03-05Remove uses of deprecated callconv aliasesLinus Groh
2025-01-19std.os.linux: Don't emit CFI directives if unwind tables are disabled.Alex Rønne Petersen
2024-12-11std.os.linux: Add unwinding protection in clone() implementations.Alex Rønne Petersen
Whatever was in the frame pointer register prior to clone() will no longer be valid in the child process, so zero it to protect FP-based unwinders. Similarly, mark the link register as undefined to protect DWARF-based unwinders. This is only zeroing the frame pointer(s) on Arm/Thumb because of an LLVM assembler bug: https://github.com/llvm/llvm-project/issues/115891
2024-08-07std.os.linux: Move clone() here and stop exporting it.Alex Rønne Petersen
2024-07-19fix regression of flock being called on wasi targetsAndrew Kelley
* common symbols are now public from std.c even if they live in std.posix * LOCK is now one of the common symbols since it is the same on 100% of operating systems. * flock is now void value on wasi and windows * std.fs.Dir now uses flock being void as feature detection, avoiding trying to call it on wasi and windows
2024-07-19std.c reorganizationAndrew Kelley
It is now composed of these main sections: * Declarations that are shared among all operating systems. * Declarations that have the same name, but different type signatures depending on the operating system. Often multiple operating systems share the same type signatures however. * Declarations that are specific to a single operating system. - These are imported one per line so you can see where they come from, protected by a comptime block to prevent accessing the wrong one. Closes #19352 by changing the convention to making types `void` and functions `{}`, so that it becomes possible to update `@hasDecl` sites to use `@TypeOf(f) != void` or `T != void`. Happily, this ended up removing some duplicate logic and update some bitrotted feature detection checks. A handful of types have been modified to gain namespacing and type safety. This is a breaking change. Oh, and the last usage of `usingnamespace` site is eliminated.
2024-03-19extract std.posix from std.osAndrew Kelley
closes #5019
2024-02-11some API work on std.c, std.os, std.os.wasiAndrew Kelley
* std.c: consolidate some definitions, making them share code. For example, freebsd, dragonfly, and openbsd can all share the same `pthread_mutex_t` definition. * add type safety to std.c.O - this caught a bug where mode flags were incorrectly passed as the open flags. * 3 fewer uses of usingnamespace keyword * as per convention, remove purposeless field prefixes from struct field names even if they have those prefixes in the corresponding C code. * fix incorrect wasi libc Stat definition * remove C definitions from incorrectly being in std.os.wasi * make std.os.wasi definitions type safe * go through wasi native APIs even when linking libc because the libc APIs are problematic and wasteful * don't expose WASI definitions in std.posix * remove std.os.wasi.rights_t.ALL: this is a footgun. should it be all future rights too? or only all current rights known? both are the wrong answer.
2024-02-06std.os.linux.MAP: use a packed structAndrew Kelley
Introduces type safety to this constant. Eliminates one use of `usingnamespace`.
2023-07-31std: finish cleanup up asmJacob Young
This also required implementing the necessary syntax in the x86_64 backend.
2023-06-19all: zig fmt and rename "@XToY" to "@YFromX"Eric Joldasov
Signed-off-by: Eric Joldasov <bratishkaerik@getgoogleoff.me>
2022-12-06remove most conditional compilation based on stage1Andrew Kelley
There are still a few occurrences of "stage1" in the standard library and self-hosted compiler source, however, these instances need a bit more careful inspection to ensure no breakage.
2022-09-29std: Replace use of stage1 function pointersominitay
2022-06-27std.os.linux.clone: upgrade to stage2 fn ptr semanticsAndrew Kelley
2022-06-07add const to msghdr_const iov and control pointersJonathan Marler
alongside the typical msghdr struct, Zig has added a msghdr_const type that can be used with sendmsg which allows const data to be provided. I believe that data pointed to by the iov and control fields in msghdr are also left unmodified, in which case they can be marked const as well.
2022-05-16Generate linux syscalls via. the linux source treeStephen Gregoratto
Previously, updating the `SYS` enum for each architecture required manually looking at the syscall tables and inserting any new additions. This commit adds a tool, `generate_linux_syscalls.zig`, that automates this process using the syscall tables in the Linux source tree. On architectures without a table, it runs `zig cc` as a pre-processor to extract the system-call numbers from the Linux headers.
2022-03-22Fix ucontext_tLocria Cyber
2022-03-03os/linux/io_uring: add recvmsg and sendmsg (#10212)Hiroaki Nakamura
* os/linux/io_uring: add recvmsg and sendmsg * Use std.os.iovec and std.os.iovec_const * Remove msg_ prefix in msghdr and msghdr_const in arm64 etc * Strip msg_ prefix in msghdr and msghdr_const for linux arm-eabi * Copy msghdr and msghdr_const from i386 to mips * Add sockaddr to lib/std/os/linux/mips.zig * Copy msghdr and msghdr_const from x86_64 to riscv64
2022-02-15Adds Linux support for POSIX file locking with fcntlAnthony Carrico
On Linux, locking fails with EAGAIN (vs. EACCES on other systems). This commit also adds FcntlErrors for EDEADLK and ENOLCK.
2021-12-19stage1, stage2: rename c_void to anyopaque (#10316)Isaac Freund
zig fmt now replaces c_void with anyopaque to make updating code easy.
2021-10-17Linux: Update syscall numbers for 5.14Stephen Gregoratto
2021-09-01fix regression on linux with kernel_timespecAndrew Kelley
I incorrectly assumed that __kernel_timespec was used when not linking libc, however that is not the case. `std.os.timespec` is used both for libc and non-libc cases. `__kernel_timespec` is a special struct that is used only for io_uring.
2021-09-01std: fix regressions from this branchAndrew Kelley
Also move some usingnamespace test cases from compare_output to behavior.
2021-09-01std, compiler-rt: remove test names where applicableAndrew Kelley
Tests with no names are executed when using `zig test` regardless of the `--test-filter` used. Non-named tests should be used when simply importing unit tests from another file. This allows `zig test` to find all the appropriate tests, even when using `--test-filter`.
2021-09-01std: reorganization that allows new usingnamespace semanticsAndrew Kelley
The proposal #9629 is now accepted, usingnamespace stays but no longer puts identifiers in scope.
2021-09-01std.os: more reorganization effortsAndrew Kelley
* std lib tests are passing on x86_64-linux with and without -lc * stage2 is building from source on x86_64-linux * down to 38 remaining uses of `usingnamespace`
2021-09-01std.os.linux: remove the "bits" namespace altogetherAndrew Kelley
Now there is only 1 architecture-specific file for Linux kernel bits.
2021-09-01std.os reorganization, avoiding `usingnamespace`Andrew Kelley
The main purpose of this branch is to explore avoiding the `usingnamespace` feature of the zig language, specifically with regards to `std.os` and related functionality. If this experiment is successful, it will provide a data point on whether or not it would be practical to entirely remove `usingnamespace` from the language. In this commit, `usingnamespace` has been completely eliminated from the Linux x86_64 compilation path, aside from io_uring. The behavior tests pass, however that's as far as this branch goes. It is very breaking, and a lot more work is needed before it could be considered mergeable. I wanted to put a pull requset up early so that zig programmers have time to provide feedback. This is progress towards closing #6600 since it clarifies where the actual "owner" of each declaration is, and reduces the number of different ways to import the same declarations. One of the main organizational strategies used here is to do namespacing with real namespaces (e.g. structs) rather than by having declarations share a common prefix (the C strategy). It's no coincidence that `usingnamespace` has similar semantics to `#include` and becomes much less necessary when using proper namespaces.
2021-08-29zig fmt: respect trailing commas in inline assemblyjdmichaud
2021-08-24remove redundant license headers from zig standard libraryAndrew Kelley
We already have a LICENSE file that covers the Zig Standard Library. We no longer need to remind everyone that the license is MIT in every single file. Previously this was introduced to clarify the situation for a fork of Zig that made Zig's LICENSE file harder to find, and replaced it with their own license that required annual payments to their company. However that fork now appears to be dead. So there is no need to reinforce the copyright notice in every single file.
2021-08-02Move iovec and log levels to bits/posix.zigN00byEdge
This lets only the OSes that uses them to import them, and removes dependencies on bits.zig for the os/<os>/<arch>.zig files
2021-08-02Make linux syscalls accessible with non-Linux target OSN00byEdge
2021-04-10Add ppc Linux bitsBenjamin Feng