Improve typesafety of Zig & C syscall flags
This PR is a rework/split of some of my changes from #30067 that were focused on system flags
The plan is to have the General flags changes separated from the IoUring
specific changes, reducing the change set, and making it easy to review
let futex_* syscalls take a pointer to atomic u32
Add typings for AT, W, AF, PF SOCK, MSG, SHUT, and use them where appropriate
Make SOL, SO, IPPROTO typed enums.
The setsockopt syscall is a beast. I tried teaming it with the below
signature to make it more intuitive in Zig, but I have decided to back
out for now and thoroughly think through it before making a PR for that.
My first idea using Io.Threaded's setSocketOption was something like
pubfnsetSocketOption(fd:i32,level:union(enum){sock:posix.SOL,ip:posix.IPPROTO,ipv6:posix.IPPROTO,tcp:posix.IPPROTO,protocal:i32,},opt_name:union(enum){sock:posix.SO,ip:posix.IP,ipv6:posix.IPV6,tcp:posix.TCP,option:u32,},opt_val:u32,)
Namespace Mask in Statx
Fix PF definition for Dragonfly
Add Pipe2 flags for pipe2 syscall
Update C & Zig APIs to use these flags
Remove unnecessary @as coercion and properly format some syscalls
Improve futex2 api and add a Futex2 flag type
socketcall needs a slice of u32s not usize
Add EpollOp enum for epoll operations
Make EPOLL at packed struct
make sa_family_t an AF type
FIX STATX_ATTR not matching the linux kernel github.com/torvalds/linux@bfe62a4545/include/uapi/linux/stat.h (L248)
Move statx_timestamp into Statx namespace
Make MADV and POSIX_FADV typed flags
Cleanup linux/test.zig after the above changes
use fd_t and pid_t over i32 as they are more descriptive
Make FALLOC a typed flag
Bandage IoUring/test so that it passes with the current changes
fix skipKernelLessThan fn to work on WSL Linux
Fix all remaining compile errors and failing tests
Use @hasField over @hasDecl where appropriate
Implement typed SOCK type for all Zig supported platforms
(Note: Haiku https://github.com/haiku/haiku/blob/master/headers/posix/sys/socket.h#L44 actually support socket flags unlike is stated in Io.Threaded implementation)
Get zig build test -Dskip-release -Dskip-non-native passing
Fix issues caught by the above command
Also all std test is already passing
❯ zig build test-std -Dno-matrix --summary all
Build Summary: 3/3 steps succeeded; 3138/3173 tests passed (35 skipped)
test-std success
└─ run test std-native-raptorlake-Debug 3138 pass, 35 skip (3173 total) 20s MaxRSS:160M
└─ compile test Debug native success 23s MaxRSS:881M
One failing test, but it is unrelated to the PR
❯ zig build test -Dskip-release -Dskip-non-native --summary line
test
└─ test-standalone
└─ standalone_test_cases
└─ standalone_test_cases.coff_dwarf
└─ run exe main failure
error: process exited with code 53 (expected exited with code 0)
failed command: PATH=/home/ultracode/.config/carapace/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/home/ultracode/.local/bin:/usr/lib/helix:.zig-cache/o/70cf46fdd7b97320434d99be45adab0f ./.zig-cache/o/f01000c9e497dc8918e1e87d574d578e/main.exe
Build Summary: 4929/5076 steps succeeded (142 skipped, 1 failed); 16113/16333 tests passed (220 skipped)
error: the following build command failed with exit code 1:
Improve typesafety of Zig & C syscall flags
This PR is a rework/split of some of my changes from #30067 that were focused on system flags
The plan is to have the General flags changes separated from the IoUring
specific changes, reducing the change set, and making it easy to review
let futex_* syscalls take a pointer to atomic u32
Add typings for AT, W, AF, PF SOCK, MSG, SHUT, and use them where appropriate
Make SOL, SO, IPPROTO typed enums.
The setsockopt syscall is a beast. I tried teaming it with the below
signature to make it more intuitive in Zig, but I have decided to back
out for now and thoroughly think through it before making a PR for that.
My first idea using Io.Threaded's `setSocketOption` was something like
```Zig
pub fn setSocketOption(
fd: i32,
level: union(enum) {
sock: posix.SOL,
ip: posix.IPPROTO,
ipv6: posix.IPPROTO,
tcp: posix.IPPROTO,
protocal: i32,
},
opt_name: union(enum) {
sock: posix.SO,
ip: posix.IP,
ipv6: posix.IPV6,
tcp: posix.TCP,
option: u32,
},
opt_val: u32,
)
```
Namespace Mask in Statx
Fix PF definition for Dragonfly
Add Pipe2 flags for pipe2 syscall
Update C & Zig APIs to use these flags
Remove unnecessary @as coercion and properly format some syscalls
Improve futex2 api and add a Futex2 flag type
socketcall needs a slice of u32s not usize
Add EpollOp enum for epoll operations
Make EPOLL at packed struct
make sa_family_t an AF type
FIX STATX_ATTR not matching the linux kernel https://github.com/torvalds/linux/blob/bfe62a454542cfad3379f6ef5680b125f41e20f4/include/uapi/linux/stat.h#L248
Move statx_timestamp into Statx namespace
Make MADV and POSIX_FADV typed flags
Cleanup linux/test.zig after the above changes
use fd_t and pid_t over i32 as they are more descriptive
Make FALLOC a typed flag
Bandage IoUring/test so that it passes with the current changes
fix `skipKernelLessThan` fn to work on WSL Linux
Fix all remaining compile errors and failing tests
Use @hasField over @hasDecl where appropriate
Implement typed SOCK type for all Zig supported platforms
(Note: Haiku https://github.com/haiku/haiku/blob/master/headers/posix/sys/socket.h#L44 actually support socket flags unlike is stated in Io.Threaded implementation)
Get zig build test -Dskip-release -Dskip-non-native passing
Fix issues caught by the above command
Also all std test is already passing
```elvish
❯ zig build test-std -Dno-matrix --summary all
Build Summary: 3/3 steps succeeded; 3138/3173 tests passed (35 skipped)
test-std success
└─ run test std-native-raptorlake-Debug 3138 pass, 35 skip (3173 total) 20s MaxRSS:160M
└─ compile test Debug native success 23s MaxRSS:881M
```
One failing test, but it is unrelated to the PR
```elvish
❯ zig build test -Dskip-release -Dskip-non-native --summary line
test
└─ test-standalone
└─ standalone_test_cases
└─ standalone_test_cases.coff_dwarf
└─ run exe main failure
error: process exited with code 53 (expected exited with code 0)
failed command: PATH=/home/ultracode/.config/carapace/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/home/ultracode/.local/bin:/usr/lib/helix:.zig-cache/o/70cf46fdd7b97320434d99be45adab0f ./.zig-cache/o/f01000c9e497dc8918e1e87d574d578e/main.exe
Build Summary: 4929/5076 steps succeeded (142 skipped, 1 failed); 16113/16333 tests passed (220 skipped)
error: the following build command failed with exit code 1:
```