aboutsummaryrefslogtreecommitdiff
path: root/lib/std/c/darwin.zig
AgeCommit message (Collapse)Author
2025-09-30std.debug: miscellaneous fixesmlugg
Mostly on macOS, since Loris showed me a not-great stack trace, and I spent 8 hours trying to make it better. The dyld shared cache is designed in a way which makes this really hard to do right, and documentation is non-existent, but this *seems* to work pretty well. I'll leave the ruling on whether I did a good job to CI and our users.
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-20std.c: adjust shm_open to be variadic on darwinJohn Benediktsson
2025-09-17Merge pull request #25195 from blblack/netdefsAndrew Kelley
std: Add several sockopt-related constants and structs
2025-09-13std.posix.ptrace: support more platforms more correctlyJustus Klausecker
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-08-21make some compile errors aliases insteadJustus Klausecker
2025-08-20std.c.darwin: cleanup, expose everything in std.cJustus Klausecker
This mainly just moves stuff around. Justifications for other changes: * `KEVENT.FLAGS` is backed by `c_uint` because that's what the `kevent64` flags param takes (according to the 'latest' manpage from 2008) * `MACH_RCV_NOTIFY` is a legacy name and `MACH_RCV_OVERWRITE` is deprecated (xnu/osfmk/mach/message.h), so I removed them. They were 0 anyway and thus couldn't be represented as a packed struct field. * `MACH.RCV` and `MACH.SEND` are technically the same 'type' because they can both be supplied at the same time to `mach_msg`. I decided to still keep them separate because naming works out better that way and all flags except for `MACH_MSG_STRICT_REPLY` aren't shared anyway. Both are part of a packed union `mach_msg_option_t` which supplies a helper function to combine the two types. * `PT` is backed by `c_int` because that's what `ptrace` takes as a request arg (according to the latest manpage from 2015)
2025-06-24c.darwin: define MSG for macos (#24224)Dacheng
* c.darwin: define MSG for macos * darwin: add series os name * Update lib/std/c.zig Co-authored-by: Alex Rønne Petersen <alex@alexrp.com> --------- Co-authored-by: Alex Rønne Petersen <alex@alexrp.com>
2025-04-30c.zig: glibc/musl export 1024-bit sigset_tPat Tullmann
Export the sigset_t ops (sigaddset, etc) from the C library. Don't rely on the linux.zig defintions (which will be defined to use the kernel ABI). Move Darwin sigset and NSIG declarations into darwin.zig. Remove extraneous (?) sigaddset. The C library sigaddset can reject some signals being added, so need to defer to it.
2025-04-03std.c.darwin.CPUFAMILY: Add ARM_TAHITI and ARM_TUPAI.Alex Rønne Petersen
2025-02-17std.Target: Remove functions that just wrap component functions.Alex Rønne Petersen
Functions like isMinGW() and isGnuLibC() have a good reason to exist: They look at multiple components of the target. But functions like isWasm(), isDarwin(), isGnu(), etc only exist to save 4-8 characters. I don't think this is a good enough reason to keep them, especially given that: * It's not immediately obvious to a reader whether target.isDarwin() means the same thing as target.os.tag.isDarwin() precisely because isMinGW() and similar functions *do* look at multiple components. * It's not clear where we would draw the line. The logical conclusion before this commit would be to also wrap Arch.isX86(), Os.Tag.isSolarish(), Abi.isOpenHarmony(), etc... this obviously quickly gets out of hand. * It's nice to just have a single correct way of doing something.
2025-01-26Revert d714cf33405486d9aa707e9aee8f103a011d06e9 (#21273)Alex Rønne Petersen
Turns out this was already fixed in #21964. I have no idea why GitHub showed an incorrect diff in #21273, or how applying the diff to master was even possible, but here we are.
2025-01-26std.c.darwin: Fix EXC.MASK compile error (#21273)injuly
2025-01-23adding std.c.TCP.NODELAY for macos (#22404)John Benediktsson
closes #17260
2025-01-16all: update to `std.builtin.Type.Pointer.Size` field renamesmlugg
This was done by regex substitution with `sed`. I then manually went over the entire diff and fixed any incorrect changes. This diff also changes a lot of `callconv(.C)` to `callconv(.c)`, since my regex happened to also trigger here. I opted to leave these changes in, since they *are* a correct migration, even if they're not the one I was trying to do!
2024-12-16add m4 {pro,max} detectionDavid Rubin
2024-12-16std.c.darwin.posix_spawn: fix signaturemlugg
And change corresponding signature in `DarwinPosixSpawn`.
2024-11-19std.c.darwin: make os_log_t a pointer to opaqueDaniel Berg
2024-11-13Fix std.c.EXC.MASK struct to match definition in mach/exception_types.h (#21964)Daniel Hooper
Co-authored-by: Alex Rønne Petersen <alex@alexrp.com>
2024-10-03fix typo in segset_tSaurabh Mishra
2024-09-24fix THREAD_STATE_NONE on darwinmatt
#21094
2024-08-28std: update `std.builtin.Type` fields to follow naming conventionsmlugg
The compiler actually doesn't need any functional changes for this: Sema does reification based on the tag indices of `std.builtin.Type` already! So, no zig1.wasm update is necessary. This change is necessary to disallow name clashes between fields and decls on a type, which is a prerequisite of #9938.
2024-08-19std: add native cpu detection for apple m3 (#21116)Meghan Denny
* std.c.darwin: add missing CPUFAMILY fields * std.zig.system.detectNativeCpuAndFeatures: add missing darwin fields * add comment so the prong isnt lost and easily discoverable during next llvm upgrade
2024-07-19move non-libc stuff out of std.cAndrew Kelley
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-07-09std: fix typos (#20560)Jora Troosh
2024-06-17std: fix pthread_{get,set}name_np return type ABIIsaac Freund
I believe this was accidentally broken when the E enum for errno values was introduces. These functions are quite the special case in that they return the error value directly rather than returning -1 and passing the error value through the errno variable. In any case, using a u16 as the return type at the ABI boundary where a c_int is expected is asking for trouble.
2024-03-30cbe: rewrite `CType`Jacob Young
Closes #14904
2024-03-23haiku: debitrotJacob Young
2024-03-19extract std.posix from std.osAndrew Kelley
closes #5019
2024-03-17AstGen: disallow alignment on function typesJacob Young
A pointer type already has an alignment, so this information does not need to be duplicated on the function type. This already has precedence with addrspace which is already disallowed on function types for this reason. Also fixes `@TypeOf(&func)` to have the correct addrspace and alignment.
2024-03-15bsd: debitrot std.cMichael Dusan
- follow-up to f4bf061d8a8 - updated std.fs.Dir to use properly named symbols
2024-03-11std.builtin: make link mode fields lowercaseTristan Ross
2024-02-12std.os.termios: add type safety to lflag fieldAndrew Kelley
This creates `tc_cflag_t` even though such a type is not defined by libc. I also collected the missing flag bits from all the operating systems.
2024-02-12std.os.termios: add type safety to cflag fieldAndrew Kelley
This creates `tc_cflag_t` even though such a type is not defined by libc. I also collected the missing flag bits from all the operating systems.
2024-02-12std.os.termios: add type safety to oflag fieldAndrew Kelley
This creates `tc_oflag_t` even though such a type is not defined by libc. I also collected the missing flag bits from all the operating systems.
2024-02-12std.os.termios: add type safety to iflag fieldAndrew Kelley
This creates `tc_iflag_t` even though such a type is not defined by libc. I also collected the missing flag bits from all the operating systems.
2024-02-12std.os.termios: consolidate and correctAndrew Kelley
2024-02-12std.c.NCSS: consolidate and correctAndrew Kelley
2024-02-12std: add type safety to cc_tAndrew Kelley
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.c.MAP: use a packed structAndrew Kelley
Same as previous commit, but for the libc interface.
2023-10-03correctly detect apple a15 and a16 chipsxdBronch
2023-07-31Revert "std: add a subset of the macOs's libproc api."Andrew Kelley
This reverts commit 7b0e015eb42272d84396f44fc904ab79f38dd696.
2023-07-31Revert "std.c: add mincore api to darwin."Andrew Kelley
This reverts commit 05f9608115a48fb7312ebf38c1240ae10b770c88.
2023-07-31Revert "std.c: add os_proc_available_memory for darwin"Andrew Kelley
This reverts commit 012f9a97eb74c63921ce7f3a036c71816fb59a24.
2023-07-31Revert "Merge pull request #15317 from devnexen/darwin_rand_nativegen"Andrew Kelley
This reverts commit a11113097730693fb915114cec79df9cb4adcc93, reversing changes made to 9f3f9fb40f605de2f2bdcd0ce7a396e06b8b8c0d.
2023-07-31Revert "std.c: adding cpu affinity api for macOs (mainly x86_64)"Andrew Kelley
This reverts commit 4bfd37ddb48af4dbfd2e892aec7a90a822c8cbe7.
2023-07-31Revert "std.c: darwin add host_info based data."Andrew Kelley
This reverts commit ff59c4584041517a2ee07cccf923ef5460032d68.