Commit graph

469 commits

Author SHA1 Message Date
Bernard Assan
7d72bdda8a
IoUring: implement outstanding flags and enumerations
Add SYNC_FILE_RANGE_* flags
add XATTR_* flags
Add Madvise for MADV_* constants
Add Fadvise enum type for POSIX_FADV_* constants

Signed-off-by: Bernard Assan <mega.alpha100@gmail.com>
2025-12-01 12:16:00 +00:00
Bernard Assan
1ed7fa4eda
Merge archs that have the same Pipe2 flags
Signed-off-by: Bernard Assan <mega.alpha100@gmail.com>
2025-12-01 12:16:00 +00:00
Bernard Assan
8a280af949
IoUring: implement pipe and pipe_direct operations
Add dedicated Pipe2 flags for pipe2 as O contains some fields which are
invalid in that context

Signed-off-by: Bernard Assan <mega.alpha100@gmail.com>
2025-12-01 12:16:00 +00:00
Bernard Assan
ac53361721
IoUring: Working on Pipe2 flags
Build on the extensive work already done

IoUring: add fixed_fd_install, ftruncate, cmd_discard

Working on IoUring pipe flags

Signed-off-by: Bernard Assan <mega.alpha100@gmail.com>
2025-12-01 12:16:00 +00:00
Bernard Assan
be63611c64
Add a Futex2 Bitset type for futex2 wake and wait syscalls
Cleanup linux/test.zig

type futex/2_* uaddr as *const u32
consider changing to *const atomic.Value(u32)

Use At Flags in fstatat

Use EpollOp in epoll_ctl syscall

Signed-off-by: Bernard Assan <mega.alpha100@gmail.com>
2025-12-01 12:15:59 +00:00
Bernard Assan
35bbe99cb2
IoUring: futex operations
Signed-off-by: Bernard Assan <mega.alpha100@gmail.com>

Add futex_* operations to IoUring

Refactor Futex 2 flags into Futex2 struct

add mpol to Wait flags and fix private field as its 128 not 32

Signed-off-by: Bernard Assan <mega.alpha100@gmail.com>

Update futex2_* functions and constants to use the new Futex2 type

Improve the Api of futex2_* functions to be more idiomatic Zig

Signed-off-by: Bernard Assan <mega.alpha100@gmail.com>
2025-12-01 12:15:59 +00:00
Bernard Assan
33460a78cf
add msg_ring_*, setxattr and getxattr IoUring operations
TODO: add SetXattr flags

Signed-off-by: Bernard Assan <mega.alpha100@gmail.com>
2025-12-01 12:15:58 +00:00
Bernard Assan
f99459a53f
add IoUring send_bundle, send_to, recv_multishot, sync_file_range
ignore prep_openat2* for now

add non-at variant of some unlink, rename, mkdir, symlink, link

TODO: add Sync File Flags

Signed-off-by: Bernard Assan <mega.alpha100@gmail.com>
2025-12-01 12:15:58 +00:00
Bernard Assan
4b0988f167
Implement some more IoUring operations
Add timeout update, cancel_fd, epoll_wait, files_update, open, open_direct, f/madvice

don't implement f/madvice64 for now I doubt it is used by a lot of people in practice

Implement BufferGroup read_multishot

Try to make definition of function align as logically as posible with
liburing to make keeping our implementation in sync easy

TODO: add M/Fadvice enum flags
TODO: understand buffer_selection and how its different from BufferGroup

Signed-off-by: Bernard Assan <mega.alpha100@gmail.com>
2025-12-01 12:15:58 +00:00
Bernard Assan
582d37ea85
Add mips defination for Epoll
Signed-off-by: Bernard Assan <mega.alpha100@gmail.com>
2025-12-01 12:15:57 +00:00
Bernard Assan
cb289b1e7b
Fix posix.W in process/Child.zig
add Deprecated linux.W fns
Signed-off-by: Bernard Assan <mega.alpha100@gmail.com>
2025-12-01 12:15:57 +00:00
Bernard Assan
1ead5f2205
Remove io_uring bit and pieces from linux.zig
now that IoUring.zig is self contained
Signed-off-by: Bernard Assan <mega.alpha100@gmail.com>
2025-12-01 12:15:56 +00:00
Bernard Assan
a07abaa248
Use lower case identifiers for IoUring flags and enums
update io_uring_enter and io_uring_register syscalls to
use IoUring flags and types

Cleanup comments

Signed-off-by: Bernard Assan <mega.alpha100@gmail.com>
2025-12-01 12:15:56 +00:00
Bernard Assan
dbc1282850
fix error of setting some fields in Epoll to true by default
Add Deprecated Op constants for compatibility

Signed-off-by: Bernard Assan <mega.alpha100@gmail.com>
2025-12-01 12:15:56 +00:00
Bernard Assan
2584301978
Replace EPOLL struct with an EpollOp enum and Epoll packed struct type
Prefer Using aliases over packed union field

Fix bug in HANDLE_FID declaration

Use EpollOp op type and Epoll packed struct flag type in IoUring

Signed-off-by: Bernard Assan <mega.alpha100@gmail.com>
2025-12-01 12:15:55 +00:00
Bernard Assan
9d460e7a78
Add So and Sol typed flags
Replace SO with So type and Add SO named constants for compatability

Replace SOL with Sol type and Add SOL named constants for compatability

Replace some more typed flags with their typed equivalent

Remove any unnecessary IoUring dependency on linux.*

Add TODOs for all untyped flags

Signed-off-by: Bernard Assan <mega.alpha100@gmail.com>
2025-12-01 12:15:55 +00:00
Bernard Assan
1ae677fda1
Get test passing for all the newly introduced flags
4❯ zig test lib/std/std.zig --zig-lib-dir lib --test-filter "os.linux"
68/116 os.linux.test.test.futex2_wait...SKIP
69/116 os.linux.test.test.futex2_wake...SKIP
70/116 os.linux.test.test.futex2_requeue...SKIP
111/116 os.linux.IoUring.test.waitid...SKIP
116/116 os.linux.IoUring.test.bind/listen/connect...SKIP
111 passed; 5 skipped; 0 failed.

fix skipKernelLessThan fn to work on wsl linux

fix logical error in flags compatibility check

Update all IoUring to use the implemented flags

bandage types that affect posix for now so that the scope
doesn't become unmanageable

TODO: impl linux.SOL and linux.SO types

Signed-off-by: Bernard Assan <mega.alpha100@gmail.com>
2025-12-01 12:15:55 +00:00
Bernard Assan
0464bcc98d
Replace MSG with Packed Struct Flags
Signed-off-by: Bernard Assan <mega.alpha100@gmail.com>
2025-12-01 12:15:55 +00:00
Bernard Assan
88fa1decbf
Restore deprecated contants using new Flag types
This allows for a gradual transitioning to the new typed flags

Signed-off-by: Bernard Assan <mega.alpha100@gmail.com>
2025-12-01 12:15:54 +00:00
Bernard Assan
b5dab22f26
update some syscall APIs to use the new flags
Add Shut, PF, AF, IPPROTO types

Update IoUring and test to use some of this flags

TODO: avoid breaking API and make transitioning smooth
Instead mark the previous API as deprecated for at least
One zig release while using the new in the Zig codebase

Signed-off-by: Bernard Assan <mega.alpha100@gmail.com>
2025-12-01 12:15:54 +00:00
Bernard Assan
af2397777a
Replace AT,W,SHUT,SOCK with a packed struct Flag type
Use the new Flag types in IoUring

fix some test

Signed-off-by: Bernard Assan <mega.alpha100@gmail.com>
2025-12-01 12:15:54 +00:00
Bernard Assan
86ed53e28f
Improve organization of fn and structs in IoUring
Update std to use Statx.Mask
Update statx syscall to use Statx.Mask

Signed-off-by: Bernard Assan <mega.alpha100@gmail.com>
2025-12-01 12:15:54 +00:00
Bernard Assan
3e4f8ee485
Replace STATX_* with StatxMask & StatxAttr
Add RenameFlags for IoUring renameat

Start update io_uring Types in linux.zig to use IoUring

Continue change options and flags to Typed types

Fix test cases to use updated IoUring flags and options

Signed-off-by: Bernard Assan <mega.alpha100@gmail.com>
2025-12-01 12:15:54 +00:00
rpkak
6b4f45f782 system specific errno 2025-11-20 15:03:23 -08:00
Jacob Young
57889cae80 posix: reduce the number of assumptions made by dl_iterate_phdr
Not yet fully compatible with the new linker, but still progress.

Closes #25786
2025-11-09 03:31:26 -05:00
Andrew Kelley
8b269f7e18 std: make signal numbers into an enum
fixes start logic for checking whether IO/POLL exist
2025-10-29 06:20:51 -07:00
Andrew Kelley
90fdd21df6 std: move DNS record enum to a better namespace 2025-10-29 06:20:50 -07:00
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
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
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
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
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
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
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
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
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
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
rpkak
bc512648db use copy_file_range syscall on linux 2025-09-24 03:08:12 +02: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
Andrew Kelley
d2e4ad613b
Merge pull request #25217 from blblack/setsiderr
std.os.linux.setsid(): return raw syscall0 result
2025-09-17 21:14:08 -07:00
Andrew Kelley
0df89cd0e1
Merge pull request #25225 from Justus2308/darwin-fixes
std.*.ptrace: support more platforms and features more correctly
2025-09-17 21:11:28 -07:00