Commit Graph

97 Commits

Author SHA1 Message Date
Michael Dusan 6ab1159e81 netbsd: use correct symbol for lwp_park 2026-01-06 05:27:54 +01:00
Matthew Lugg e57c557ad4 std.Io.Threaded: hugely improve Windows and NetBSD support
The most interesting thing here is the replacement of the pthread futex
implementation with an implementation based on thread park/unpark APIs.
Thread parking tends to be the primitive provided by systems which do
not have a futex primitive, such as NetBSD, so this implementation is
far more efficient than the pthread one. It is also useful on Windows,
where `RtlWaitOnAddress` is itself a userland implementation based on
thread park/unpark; we can implement it ourselves including support for
features which Windows' implementation lacks, such as cancelation and
waking a number of waiters with 1<n<infinity.

Compared to the pthread implementation, this thread-parking-based one
also supports full robust cancelation. Thread parking also turns out to
be useful for implementing `sleep`, so is now used for that on Windows
and NetBSD.

This commit also introduces proper cancelation support for most Windows
operations. The most notable omission right now is DNS lookups through
`GetAddrInfoEx`, just because they're a little more work due to having
a unique cancelation mechanism---but the machinery is all there, so I'll
finish gluing it together soon.

As of this commit, there are very few parts of `Io.Threaded` which do
not support full robust cancelation. The only ones which actually really
matter (because they could block for a prolonged period of time) are DNS
lookups on Windows (as discussed above) and futex waits on WASM.
2026-01-03 15:45:10 +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
Justus Klausecker 9b4cae4750 std.posix.ptrace: support more platforms more correctly 2025-09-13 14:35:19 +02: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
Andrew Kelley e8c4e79499 std.c reorganization
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-19 00:30:32 -07:00
Isaac Freund a1777cb5cb std: fix pthread_{get,set}name_np return type ABI
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-06-17 23:26:53 +02:00
Jacob Young 5a41704f7e cbe: rewrite CType
Closes #14904
2024-03-30 20:50:48 -04:00
Jacob Young 2dd74cd312 haiku: debitrot 2024-03-23 18:11:32 +01:00
Andrew Kelley cd62005f19 extract std.posix from std.os
closes #5019
2024-03-19 11:45:09 -07:00
Jacob Young d10c52c194 AstGen: disallow alignment on function types
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-17 03:06:17 +01:00
Michael Dusan d7cf25f5ca bsd: debitrot std.c
- follow-up to f4bf061d8a
- updated std.fs.Dir to use properly named symbols
2024-03-15 02:28:50 -04:00
Michael Dusan 6724a524d4 bsd: add missing os.IFNAMESIZE
- based on system API value IF_NAMESIZE
- unblocks `zig test lib/std/std.zig`
2024-03-14 18:54:25 -07:00
Michael Dusan 2ff64c7cb2 std.os.termios: add/fix std.c.TCSA for BSDs 2024-02-15 02:40:11 -05:00
Michael Dusan 7e83e7d9a8 bsd: debitrot type-safe std.c.O
Minor changes as per 7680c5330c mostly about pipe2() flags.

closes #18927
2024-02-14 19:26:12 -08:00
Andrew Kelley ae107cf71b std.os.speed_t: add type safety
and collect the missing flag bits from all the operating systems.
2024-02-12 21:49:09 -07:00
Andrew Kelley e97fa8b038 std.os.termios: add type safety to cflag field
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-12 18:24:07 -07:00
Andrew Kelley 20abc0caee std.os.termios: add type safety to oflag field
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-12 17:28:09 -07:00
Andrew Kelley 47643cc5cc std.os.termios: add type safety to iflag field
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-12 16:43:51 -07:00
Andrew Kelley 0c88f927f1 std.os.termios: consolidate and correct 2024-02-12 16:21:21 -07:00
Andrew Kelley 9a64318554 std.c.NCSS: consolidate and correct 2024-02-12 15:52:13 -07:00
Andrew Kelley 5258c3caad std: add type safety to cc_t 2024-02-12 15:41:38 -07:00
Andrew Kelley 7680c5330c some API work on std.c, std.os, std.os.wasi
* 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-11 13:38:55 -07:00
Andrew Kelley a60f219660 std.c.MAP: use a packed struct
Same as previous commit, but for the libc interface.
2024-02-06 22:06:01 -07:00
Michael Dusan 4532ff2780 netbsd: std.c: fix pthread_rwlock_t
- make .owner field optional
2023-08-15 17:29:35 -04:00
Michael Dusan 25542c3443 netbsd: std.c.REG: populate indexes for x86_64 2023-08-15 17:20:04 -04:00
Andrew Kelley 14353590f2 Revert "std: adding netbsd's pthread to cpu affinity api"
This reverts commit 3f259d3550.
2023-07-31 11:23:33 -07:00
Andrew Kelley 5f101b253e Revert "std: adding sigevent to supported platforms."
This reverts commit 23c4f55a61.
2023-07-31 11:20:39 -07:00
Andrew Kelley c9de5304ab Revert "std.c:complete further more netbsd's mmap flags"
This reverts commit 4f248e1b51.
2023-07-31 11:17:25 -07:00
Andrew Kelley a208c59a25 Revert "std.c: add netbsd's accept_filter_data for ACCEPT_FILTER sock opt."
This reverts commit b677b36278.
2023-07-31 10:57:22 -07:00
Andrew Kelley 43162efbf4 Revert "std.c: adding ptrace for netbsd."
This reverts commit ccfb0d408d.
2023-07-31 10:55:03 -07:00
Andrew Kelley 1b9ffa0824 Revert "std.Thread: refining stack size from platform minimum, changes more targetted towards platform like Linux/musl (#15791)"
This reverts commit 41502c6aa5.
2023-07-31 10:54:35 -07:00
Andrew Kelley 9f20d01cfb Revert "std.c: exposing timer api"
This reverts commit 54ea0bbcdd.
2023-07-31 10:51:44 -07:00
Andrew Kelley dad7eea8d9 Revert "std.c: update netbsd/openbsd mman constants"
This reverts commit 64f0059cd3.
2023-07-31 10:50:39 -07:00
Andrew Kelley 95e2605d30 Revert "std.c: msghdr* struct removing prefixes to match linux."
This reverts commit 8f14431bc8.
2023-07-31 10:49:57 -07:00
David CARLIER 8f14431bc8 std.c: msghdr* struct removing prefixes to match linux. 2023-07-01 11:14:39 -07:00
mlugg f26dda2117 all: migrate code to new cast builtin syntax
Most of this migration was performed automatically with `zig fmt`. There
were a few exceptions which I had to manually fix:

* `@alignCast` and `@addrSpaceCast` cannot be automatically rewritten
* `@truncate`'s fixup is incorrect for vectors
* Test cases are not formatted, and their error locations change
2023-06-24 16:56:39 -07:00
David CARLIER 64f0059cd3 std.c: update netbsd/openbsd mman constants 2023-06-22 10:21:48 +00:00
Eric Joldasov 50339f595a all: zig fmt and rename "@XToY" to "@YFromX"
Signed-off-by: Eric Joldasov <bratishkaerik@getgoogleoff.me>
2023-06-19 12:34:42 -07:00
David CARLIER 54ea0bbcdd std.c: exposing timer api 2023-06-18 08:09:42 -07:00
David CARLIER 41502c6aa5 std.Thread: refining stack size from platform minimum, changes more targetted towards platform like Linux/musl (#15791) 2023-05-25 14:32:17 -05:00
David CARLIER ccfb0d408d std.c: adding ptrace for netbsd. 2023-05-20 11:06:11 +03:00
David CARLIER b677b36278 std.c: add netbsd's accept_filter_data for ACCEPT_FILTER sock opt. 2023-05-16 04:31:15 +03:00
David CARLIER 4f248e1b51 std.c:complete further more netbsd's mmap flags 2023-04-30 12:21:35 +03:00
David CARLIER 23c4f55a61 std: adding sigevent to supported platforms. 2023-04-23 19:46:43 +03:00
David CARLIER 3f259d3550 std: adding netbsd's pthread to cpu affinity api 2023-04-22 13:59:00 +03:00
Nikita Ronja d92b5fcfb0 Add NetBSD termios constants to std.c.netbsd 2023-04-06 03:46:44 +03:00
Michael Dusan 599b3ef9e9 netbsd: use versioned __msync13 from libc
The system linker shows warning when `msync` is linked instead of `__msync13`:

  "warning: reference to compatibility msync(); include <sys/mman.h> for correct reference"

closes #14422
2023-01-28 19:05:38 -05:00
Michael Dusan c9f7b32fbd netbsd: add mcontext_t for aarch64
- test `lib/std/std.zig` passes
- stack traces work
2023-01-18 02:50:11 -05:00
Andrew Kelley c9ef277fa7 Merge pull request #13980 from ziglang/std.net
networking: delete std.x; add std.crypto.tls and std.http.Client
2023-01-03 02:43:50 -05:00