diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2023-06-24 16:58:19 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-06-24 16:58:19 -0700 |
| commit | 146b79af153bbd5dafda0ba12a040385c7fc58f8 (patch) | |
| tree | 67e3db8b444d65c667e314770fc983a7fc8ba293 /lib/std/os | |
| parent | 13853bef0df3c90633021850cc6d6abaeea03282 (diff) | |
| parent | 21ac0beb436f49fe49c6982a872f2dc48e4bea5e (diff) | |
| download | zig-146b79af153bbd5dafda0ba12a040385c7fc58f8.tar.gz zig-146b79af153bbd5dafda0ba12a040385c7fc58f8.zip | |
Merge pull request #16163 from mlugg/feat/builtins-infer-dest-ty
Infer destination type of cast builtins using result type
Diffstat (limited to 'lib/std/os')
| -rw-r--r-- | lib/std/os/linux.zig | 516 | ||||
| -rw-r--r-- | lib/std/os/linux/bpf.zig | 30 | ||||
| -rw-r--r-- | lib/std/os/linux/bpf/helpers.zig | 282 | ||||
| -rw-r--r-- | lib/std/os/linux/io_uring.zig | 101 | ||||
| -rw-r--r-- | lib/std/os/linux/ioctl.zig | 2 | ||||
| -rw-r--r-- | lib/std/os/linux/start_pie.zig | 8 | ||||
| -rw-r--r-- | lib/std/os/linux/test.zig | 16 | ||||
| -rw-r--r-- | lib/std/os/linux/tls.zig | 6 | ||||
| -rw-r--r-- | lib/std/os/linux/vdso.zig | 30 | ||||
| -rw-r--r-- | lib/std/os/plan9.zig | 4 | ||||
| -rw-r--r-- | lib/std/os/test.zig | 4 | ||||
| -rw-r--r-- | lib/std/os/uefi.zig | 2 | ||||
| -rw-r--r-- | lib/std/os/uefi/pool_allocator.zig | 6 | ||||
| -rw-r--r-- | lib/std/os/uefi/protocols/device_path_protocol.zig | 26 | ||||
| -rw-r--r-- | lib/std/os/uefi/protocols/file_protocol.zig | 4 | ||||
| -rw-r--r-- | lib/std/os/uefi/protocols/hii.zig | 2 | ||||
| -rw-r--r-- | lib/std/os/uefi/protocols/managed_network_protocol.zig | 2 | ||||
| -rw-r--r-- | lib/std/os/uefi/protocols/udp6_protocol.zig | 4 | ||||
| -rw-r--r-- | lib/std/os/uefi/tables/boot_services.zig | 2 | ||||
| -rw-r--r-- | lib/std/os/wasi.zig | 6 | ||||
| -rw-r--r-- | lib/std/os/windows.zig | 166 | ||||
| -rw-r--r-- | lib/std/os/windows/user32.zig | 2 | ||||
| -rw-r--r-- | lib/std/os/windows/ws2_32.zig | 2 |
23 files changed, 608 insertions, 615 deletions
diff --git a/lib/std/os/linux.zig b/lib/std/os/linux.zig index b7ec29383b..6362e9ece1 100644 --- a/lib/std/os/linux.zig +++ b/lib/std/os/linux.zig @@ -175,62 +175,62 @@ const require_aligned_register_pair = // Split a 64bit value into a {LSB,MSB} pair. // The LE/BE variants specify the endianness to assume. fn splitValueLE64(val: i64) [2]u32 { - const u = @bitCast(u64, val); + const u = @as(u64, @bitCast(val)); return [2]u32{ - @truncate(u32, u), - @truncate(u32, u >> 32), + @as(u32, @truncate(u)), + @as(u32, @truncate(u >> 32)), }; } fn splitValueBE64(val: i64) [2]u32 { - const u = @bitCast(u64, val); + const u = @as(u64, @bitCast(val)); return [2]u32{ - @truncate(u32, u >> 32), - @truncate(u32, u), + @as(u32, @truncate(u >> 32)), + @as(u32, @truncate(u)), }; } fn splitValue64(val: i64) [2]u32 { - const u = @bitCast(u64, val); + const u = @as(u64, @bitCast(val)); switch (native_endian) { .Little => return [2]u32{ - @truncate(u32, u), - @truncate(u32, u >> 32), + @as(u32, @truncate(u)), + @as(u32, @truncate(u >> 32)), }, .Big => return [2]u32{ - @truncate(u32, u >> 32), - @truncate(u32, u), + @as(u32, @truncate(u >> 32)), + @as(u32, @truncate(u)), }, } } /// Get the errno from a syscall return value, or 0 for no error. pub fn getErrno(r: usize) E { - const signed_r = @bitCast(isize, r); + const signed_r = @as(isize, @bitCast(r)); const int = if (signed_r > -4096 and signed_r < 0) -signed_r else 0; - return @enumFromInt(E, int); + return @as(E, @enumFromInt(int)); } pub fn dup(old: i32) usize { - return syscall1(.dup, @bitCast(usize, @as(isize, old))); + return syscall1(.dup, @as(usize, @bitCast(@as(isize, old)))); } pub fn dup2(old: i32, new: i32) usize { if (@hasField(SYS, "dup2")) { - return syscall2(.dup2, @bitCast(usize, @as(isize, old)), @bitCast(usize, @as(isize, new))); + return syscall2(.dup2, @as(usize, @bitCast(@as(isize, old))), @as(usize, @bitCast(@as(isize, new)))); } else { if (old == new) { if (std.debug.runtime_safety) { - const rc = syscall2(.fcntl, @bitCast(usize, @as(isize, old)), F.GETFD); - if (@bitCast(isize, rc) < 0) return rc; + const rc = syscall2(.fcntl, @as(usize, @bitCast(@as(isize, old))), F.GETFD); + if (@as(isize, @bitCast(rc)) < 0) return rc; } - return @intCast(usize, old); + return @as(usize, @intCast(old)); } else { - return syscall3(.dup3, @bitCast(usize, @as(isize, old)), @bitCast(usize, @as(isize, new)), 0); + return syscall3(.dup3, @as(usize, @bitCast(@as(isize, old))), @as(usize, @bitCast(@as(isize, new))), 0); } } } pub fn dup3(old: i32, new: i32, flags: u32) usize { - return syscall3(.dup3, @bitCast(usize, @as(isize, old)), @bitCast(usize, @as(isize, new)), flags); + return syscall3(.dup3, @as(usize, @bitCast(@as(isize, old))), @as(usize, @bitCast(@as(isize, new))), flags); } pub fn chdir(path: [*:0]const u8) usize { @@ -238,7 +238,7 @@ pub fn chdir(path: [*:0]const u8) usize { } pub fn fchdir(fd: fd_t) usize { - return syscall1(.fchdir, @bitCast(usize, @as(isize, fd))); + return syscall1(.fchdir, @as(usize, @bitCast(@as(isize, fd)))); } pub fn chroot(path: [*:0]const u8) usize { @@ -273,7 +273,7 @@ pub fn futimens(fd: i32, times: *const [2]timespec) usize { } pub fn utimensat(dirfd: i32, path: ?[*:0]const u8, times: *const [2]timespec, flags: u32) usize { - return syscall4(.utimensat, @bitCast(usize, @as(isize, dirfd)), @intFromPtr(path), @intFromPtr(times), flags); + return syscall4(.utimensat, @as(usize, @bitCast(@as(isize, dirfd))), @intFromPtr(path), @intFromPtr(times), flags); } pub fn fallocate(fd: i32, mode: i32, offset: i64, length: i64) usize { @@ -282,8 +282,8 @@ pub fn fallocate(fd: i32, mode: i32, offset: i64, length: i64) usize { const length_halves = splitValue64(length); return syscall6( .fallocate, - @bitCast(usize, @as(isize, fd)), - @bitCast(usize, @as(isize, mode)), + @as(usize, @bitCast(@as(isize, fd))), + @as(usize, @bitCast(@as(isize, mode))), offset_halves[0], offset_halves[1], length_halves[0], @@ -292,20 +292,20 @@ pub fn fallocate(fd: i32, mode: i32, offset: i64, length: i64) usize { } else { return syscall4( .fallocate, - @bitCast(usize, @as(isize, fd)), - @bitCast(usize, @as(isize, mode)), - @bitCast(u64, offset), - @bitCast(u64, length), + @as(usize, @bitCast(@as(isize, fd))), + @as(usize, @bitCast(@as(isize, mode))), + @as(u64, @bitCast(offset)), + @as(u64, @bitCast(length)), ); } } pub fn futex_wait(uaddr: *const i32, futex_op: u32, val: i32, timeout: ?*const timespec) usize { - return syscall4(.futex, @intFromPtr(uaddr), futex_op, @bitCast(u32, val), @intFromPtr(timeout)); + return syscall4(.futex, @intFromPtr(uaddr), futex_op, @as(u32, @bitCast(val)), @intFromPtr(timeout)); } pub fn futex_wake(uaddr: *const i32, futex_op: u32, val: i32) usize { - return syscall3(.futex, @intFromPtr(uaddr), futex_op, @bitCast(u32, val)); + return syscall3(.futex, @intFromPtr(uaddr), futex_op, @as(u32, @bitCast(val))); } pub fn getcwd(buf: [*]u8, size: usize) usize { @@ -315,7 +315,7 @@ pub fn getcwd(buf: [*]u8, size: usize) usize { pub fn getdents(fd: i32, dirp: [*]u8, len: usize) usize { return syscall3( .getdents, - @bitCast(usize, @as(isize, fd)), + @as(usize, @bitCast(@as(isize, fd))), @intFromPtr(dirp), @min(len, maxInt(c_int)), ); @@ -324,7 +324,7 @@ pub fn getdents(fd: i32, dirp: [*]u8, len: usize) usize { pub fn getdents64(fd: i32, dirp: [*]u8, len: usize) usize { return syscall3( .getdents64, - @bitCast(usize, @as(isize, fd)), + @as(usize, @bitCast(@as(isize, fd))), @intFromPtr(dirp), @min(len, maxInt(c_int)), ); @@ -335,35 +335,35 @@ pub fn inotify_init1(flags: u32) usize { } pub fn inotify_add_watch(fd: i32, pathname: [*:0]const u8, mask: u32) usize { - return syscall3(.inotify_add_watch, @bitCast(usize, @as(isize, fd)), @intFromPtr(pathname), mask); + return syscall3(.inotify_add_watch, @as(usize, @bitCast(@as(isize, fd))), @intFromPtr(pathname), mask); } pub fn inotify_rm_watch(fd: i32, wd: i32) usize { - return syscall2(.inotify_rm_watch, @bitCast(usize, @as(isize, fd)), @bitCast(usize, @as(isize, wd))); + return syscall2(.inotify_rm_watch, @as(usize, @bitCast(@as(isize, fd))), @as(usize, @bitCast(@as(isize, wd)))); } pub fn readlink(noalias path: [*:0]const u8, noalias buf_ptr: [*]u8, buf_len: usize) usize { if (@hasField(SYS, "readlink")) { return syscall3(.readlink, @intFromPtr(path), @intFromPtr(buf_ptr), buf_len); } else { - return syscall4(.readlinkat, @bitCast(usize, @as(isize, AT.FDCWD)), @intFromPtr(path), @intFromPtr(buf_ptr), buf_len); + return syscall4(.readlinkat, @as(usize, @bitCast(@as(isize, AT.FDCWD))), @intFromPtr(path), @intFromPtr(buf_ptr), buf_len); } } pub fn readlinkat(dirfd: i32, noalias path: [*:0]const u8, noalias buf_ptr: [*]u8, buf_len: usize) usize { - return syscall4(.readlinkat, @bitCast(usize, @as(isize, dirfd)), @intFromPtr(path), @intFromPtr(buf_ptr), buf_len); + return syscall4(.readlinkat, @as(usize, @bitCast(@as(isize, dirfd))), @intFromPtr(path), @intFromPtr(buf_ptr), buf_len); } pub fn mkdir(path: [*:0]const u8, mode: u32) usize { if (@hasField(SYS, "mkdir")) { return syscall2(.mkdir, @intFromPtr(path), mode); } else { - return syscall3(.mkdirat, @bitCast(usize, @as(isize, AT.FDCWD)), @intFromPtr(path), mode); + return syscall3(.mkdirat, @as(usize, @bitCast(@as(isize, AT.FDCWD))), @intFromPtr(path), mode); } } pub fn mkdirat(dirfd: i32, path: [*:0]const u8, mode: u32) usize { - return syscall3(.mkdirat, @bitCast(usize, @as(isize, dirfd)), @intFromPtr(path), mode); + return syscall3(.mkdirat, @as(usize, @bitCast(@as(isize, dirfd))), @intFromPtr(path), mode); } pub fn mknod(path: [*:0]const u8, mode: u32, dev: u32) usize { @@ -375,7 +375,7 @@ pub fn mknod(path: [*:0]const u8, mode: u32, dev: u32) usize { } pub fn mknodat(dirfd: i32, path: [*:0]const u8, mode: u32, dev: u32) usize { - return syscall4(.mknodat, @bitCast(usize, @as(isize, dirfd)), @intFromPtr(path), mode, dev); + return syscall4(.mknodat, @as(usize, @bitCast(@as(isize, dirfd))), @intFromPtr(path), mode, dev); } pub fn mount(special: [*:0]const u8, dir: [*:0]const u8, fstype: ?[*:0]const u8, flags: u32, data: usize) usize { @@ -394,7 +394,7 @@ pub fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: u32, fd: i32, of if (@hasField(SYS, "mmap2")) { // Make sure the offset is also specified in multiples of page size if ((offset & (MMAP2_UNIT - 1)) != 0) - return @bitCast(usize, -@as(isize, @intFromEnum(E.INVAL))); + return @as(usize, @bitCast(-@as(isize, @intFromEnum(E.INVAL)))); return syscall6( .mmap2, @@ -402,8 +402,8 @@ pub fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: u32, fd: i32, of length, prot, flags, - @bitCast(usize, @as(isize, fd)), - @truncate(usize, @bitCast(u64, offset) / MMAP2_UNIT), + @as(usize, @bitCast(@as(isize, fd))), + @as(usize, @truncate(@as(u64, @bitCast(offset)) / MMAP2_UNIT)), ); } else { return syscall6( @@ -412,8 +412,8 @@ pub fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: u32, fd: i32, of length, prot, flags, - @bitCast(usize, @as(isize, fd)), - @bitCast(u64, offset), + @as(usize, @bitCast(@as(isize, fd))), + @as(u64, @bitCast(offset)), ); } } @@ -429,7 +429,7 @@ pub const MSF = struct { }; pub fn msync(address: [*]const u8, length: usize, flags: i32) usize { - return syscall3(.msync, @intFromPtr(address), length, @bitCast(u32, flags)); + return syscall3(.msync, @intFromPtr(address), length, @as(u32, @bitCast(flags))); } pub fn munmap(address: [*]const u8, length: usize) usize { @@ -438,7 +438,7 @@ pub fn munmap(address: [*]const u8, length: usize) usize { pub fn poll(fds: [*]pollfd, n: nfds_t, timeout: i32) usize { if (@hasField(SYS, "poll")) { - return syscall3(.poll, @intFromPtr(fds), n, @bitCast(u32, timeout)); + return syscall3(.poll, @intFromPtr(fds), n, @as(u32, @bitCast(timeout))); } else { return syscall5( .ppoll, @@ -462,69 +462,69 @@ pub fn ppoll(fds: [*]pollfd, n: nfds_t, timeout: ?*timespec, sigmask: ?*const si } pub fn read(fd: i32, buf: [*]u8, count: usize) usize { - return syscall3(.read, @bitCast(usize, @as(isize, fd)), @intFromPtr(buf), count); + return syscall3(.read, @as(usize, @bitCast(@as(isize, fd))), @intFromPtr(buf), count); } pub fn preadv(fd: i32, iov: [*]const iovec, count: usize, offset: i64) usize { - const offset_u = @bitCast(u64, offset); + const offset_u = @as(u64, @bitCast(offset)); return syscall5( .preadv, - @bitCast(usize, @as(isize, fd)), + @as(usize, @bitCast(@as(isize, fd))), @intFromPtr(iov), count, // Kernel expects the offset is split into largest natural word-size. // See following link for detail: // https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=601cc11d054ae4b5e9b5babec3d8e4667a2cb9b5 - @truncate(usize, offset_u), - if (usize_bits < 64) @truncate(usize, offset_u >> 32) else 0, + @as(usize, @truncate(offset_u)), + if (usize_bits < 64) @as(usize, @truncate(offset_u >> 32)) else 0, ); } pub fn preadv2(fd: i32, iov: [*]const iovec, count: usize, offset: i64, flags: kernel_rwf) usize { - const offset_u = @bitCast(u64, offset); + const offset_u = @as(u64, @bitCast(offset)); return syscall6( .preadv2, - @bitCast(usize, @as(isize, fd)), + @as(usize, @bitCast(@as(isize, fd))), @intFromPtr(iov), count, // See comments in preadv - @truncate(usize, offset_u), - if (usize_bits < 64) @truncate(usize, offset_u >> 32) else 0, + @as(usize, @truncate(offset_u)), + if (usize_bits < 64) @as(usize, @truncate(offset_u >> 32)) else 0, flags, ); } pub fn readv(fd: i32, iov: [*]const iovec, count: usize) usize { - return syscall3(.readv, @bitCast(usize, @as(isize, fd)), @intFromPtr(iov), count); + return syscall3(.readv, @as(usize, @bitCast(@as(isize, fd))), @intFromPtr(iov), count); } pub fn writev(fd: i32, iov: [*]const iovec_const, count: usize) usize { - return syscall3(.writev, @bitCast(usize, @as(isize, fd)), @intFromPtr(iov), count); + return syscall3(.writev, @as(usize, @bitCast(@as(isize, fd))), @intFromPtr(iov), count); } pub fn pwritev(fd: i32, iov: [*]const iovec_const, count: usize, offset: i64) usize { - const offset_u = @bitCast(u64, offset); + const offset_u = @as(u64, @bitCast(offset)); return syscall5( .pwritev, - @bitCast(usize, @as(isize, fd)), + @as(usize, @bitCast(@as(isize, fd))), @intFromPtr(iov), count, // See comments in preadv - @truncate(usize, offset_u), - if (usize_bits < 64) @truncate(usize, offset_u >> 32) else 0, + @as(usize, @truncate(offset_u)), + if (usize_bits < 64) @as(usize, @truncate(offset_u >> 32)) else 0, ); } pub fn pwritev2(fd: i32, iov: [*]const iovec_const, count: usize, offset: i64, flags: kernel_rwf) usize { - const offset_u = @bitCast(u64, offset); + const offset_u = @as(u64, @bitCast(offset)); return syscall6( .pwritev2, - @bitCast(usize, @as(isize, fd)), + @as(usize, @bitCast(@as(isize, fd))), @intFromPtr(iov), count, // See comments in preadv - @truncate(usize, offset_u), - if (usize_bits < 64) @truncate(usize, offset_u >> 32) else 0, + @as(usize, @truncate(offset_u)), + if (usize_bits < 64) @as(usize, @truncate(offset_u >> 32)) else 0, flags, ); } @@ -533,7 +533,7 @@ pub fn rmdir(path: [*:0]const u8) usize { if (@hasField(SYS, "rmdir")) { return syscall1(.rmdir, @intFromPtr(path)); } else { - return syscall3(.unlinkat, @bitCast(usize, @as(isize, AT.FDCWD)), @intFromPtr(path), AT.REMOVEDIR); + return syscall3(.unlinkat, @as(usize, @bitCast(@as(isize, AT.FDCWD))), @intFromPtr(path), AT.REMOVEDIR); } } @@ -541,12 +541,12 @@ pub fn symlink(existing: [*:0]const u8, new: [*:0]const u8) usize { if (@hasField(SYS, "symlink")) { return syscall2(.symlink, @intFromPtr(existing), @intFromPtr(new)); } else { - return syscall3(.symlinkat, @intFromPtr(existing), @bitCast(usize, @as(isize, AT.FDCWD)), @intFromPtr(new)); + return syscall3(.symlinkat, @intFromPtr(existing), @as(usize, @bitCast(@as(isize, AT.FDCWD))), @intFromPtr(new)); } } pub fn symlinkat(existing: [*:0]const u8, newfd: i32, newpath: [*:0]const u8) usize { - return syscall3(.symlinkat, @intFromPtr(existing), @bitCast(usize, @as(isize, newfd)), @intFromPtr(newpath)); + return syscall3(.symlinkat, @intFromPtr(existing), @as(usize, @bitCast(@as(isize, newfd))), @intFromPtr(newpath)); } pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: i64) usize { @@ -555,7 +555,7 @@ pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: i64) usize { if (require_aligned_register_pair) { return syscall6( .pread64, - @bitCast(usize, @as(isize, fd)), + @as(usize, @bitCast(@as(isize, fd))), @intFromPtr(buf), count, 0, @@ -565,7 +565,7 @@ pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: i64) usize { } else { return syscall5( .pread64, - @bitCast(usize, @as(isize, fd)), + @as(usize, @bitCast(@as(isize, fd))), @intFromPtr(buf), count, offset_halves[0], @@ -580,10 +580,10 @@ pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: i64) usize { .pread; return syscall4( syscall_number, - @bitCast(usize, @as(isize, fd)), + @as(usize, @bitCast(@as(isize, fd))), @intFromPtr(buf), count, - @bitCast(u64, offset), + @as(u64, @bitCast(offset)), ); } } @@ -592,12 +592,12 @@ pub fn access(path: [*:0]const u8, mode: u32) usize { if (@hasField(SYS, "access")) { return syscall2(.access, @intFromPtr(path), mode); } else { - return syscall4(.faccessat, @bitCast(usize, @as(isize, AT.FDCWD)), @intFromPtr(path), mode, 0); + return syscall4(.faccessat, @as(usize, @bitCast(@as(isize, AT.FDCWD))), @intFromPtr(path), mode, 0); } } pub fn faccessat(dirfd: i32, path: [*:0]const u8, mode: u32, flags: u32) usize { - return syscall4(.faccessat, @bitCast(usize, @as(isize, dirfd)), @intFromPtr(path), mode, flags); + return syscall4(.faccessat, @as(usize, @bitCast(@as(isize, dirfd))), @intFromPtr(path), mode, flags); } pub fn pipe(fd: *[2]i32) usize { @@ -615,7 +615,7 @@ pub fn pipe2(fd: *[2]i32, flags: u32) usize { } pub fn write(fd: i32, buf: [*]const u8, count: usize) usize { - return syscall3(.write, @bitCast(usize, @as(isize, fd)), @intFromPtr(buf), count); + return syscall3(.write, @as(usize, @bitCast(@as(isize, fd))), @intFromPtr(buf), count); } pub fn ftruncate(fd: i32, length: i64) usize { @@ -624,7 +624,7 @@ pub fn ftruncate(fd: i32, length: i64) usize { if (require_aligned_register_pair) { return syscall4( .ftruncate64, - @bitCast(usize, @as(isize, fd)), + @as(usize, @bitCast(@as(isize, fd))), 0, length_halves[0], length_halves[1], @@ -632,7 +632,7 @@ pub fn ftruncate(fd: i32, length: i64) usize { } else { return syscall3( .ftruncate64, - @bitCast(usize, @as(isize, fd)), + @as(usize, @bitCast(@as(isize, fd))), length_halves[0], length_halves[1], ); @@ -640,8 +640,8 @@ pub fn ftruncate(fd: i32, length: i64) usize { } else { return syscall2( .ftruncate, - @bitCast(usize, @as(isize, fd)), - @bitCast(usize, length), + @as(usize, @bitCast(@as(isize, fd))), + @as(usize, @bitCast(length)), ); } } @@ -653,7 +653,7 @@ pub fn pwrite(fd: i32, buf: [*]const u8, count: usize, offset: i64) usize { if (require_aligned_register_pair) { return syscall6( .pwrite64, - @bitCast(usize, @as(isize, fd)), + @as(usize, @bitCast(@as(isize, fd))), @intFromPtr(buf), count, 0, @@ -663,7 +663,7 @@ pub fn pwrite(fd: i32, buf: [*]const u8, count: usize, offset: i64) usize { } else { return syscall5( .pwrite64, - @bitCast(usize, @as(isize, fd)), + @as(usize, @bitCast(@as(isize, fd))), @intFromPtr(buf), count, offset_halves[0], @@ -678,10 +678,10 @@ pub fn pwrite(fd: i32, buf: [*]const u8, count: usize, offset: i64) usize { .pwrite; return syscall4( syscall_number, - @bitCast(usize, @as(isize, fd)), + @as(usize, @bitCast(@as(isize, fd))), @intFromPtr(buf), count, - @bitCast(u64, offset), + @as(u64, @bitCast(offset)), ); } } @@ -690,9 +690,9 @@ pub fn rename(old: [*:0]const u8, new: [*:0]const u8) usize { if (@hasField(SYS, "rename")) { return syscall2(.rename, @intFromPtr(old), @intFromPtr(new)); } else if (@hasField(SYS, "renameat")) { - return syscall4(.renameat, @bitCast(usize, @as(isize, AT.FDCWD)), @intFromPtr(old), @bitCast(usize, @as(isize, AT.FDCWD)), @intFromPtr(new)); + return syscall4(.renameat, @as(usize, @bitCast(@as(isize, AT.FDCWD))), @intFromPtr(old), @as(usize, @bitCast(@as(isize, AT.FDCWD))), @intFromPtr(new)); } else { - return syscall5(.renameat2, @bitCast(usize, @as(isize, AT.FDCWD)), @intFromPtr(old), @bitCast(usize, @as(isize, AT.FDCWD)), @intFromPtr(new), 0); + return syscall5(.renameat2, @as(usize, @bitCast(@as(isize, AT.FDCWD))), @intFromPtr(old), @as(usize, @bitCast(@as(isize, AT.FDCWD))), @intFromPtr(new), 0); } } @@ -700,17 +700,17 @@ pub fn renameat(oldfd: i32, oldpath: [*]const u8, newfd: i32, newpath: [*]const if (@hasField(SYS, "renameat")) { return syscall4( .renameat, - @bitCast(usize, @as(isize, oldfd)), + @as(usize, @bitCast(@as(isize, oldfd))), @intFromPtr(oldpath), - @bitCast(usize, @as(isize, newfd)), + @as(usize, @bitCast(@as(isize, newfd))), @intFromPtr(newpath), ); } else { return syscall5( .renameat2, - @bitCast(usize, @as(isize, oldfd)), + @as(usize, @bitCast(@as(isize, oldfd))), @intFromPtr(oldpath), - @bitCast(usize, @as(isize, newfd)), + @as(usize, @bitCast(@as(isize, newfd))), @intFromPtr(newpath), 0, ); @@ -720,9 +720,9 @@ pub fn renameat(oldfd: i32, oldpath: [*]const u8, newfd: i32, newpath: [*]const pub fn renameat2(oldfd: i32, oldpath: [*:0]const u8, newfd: i32, newpath: [*:0]const u8, flags: u32) usize { return syscall5( .renameat2, - @bitCast(usize, @as(isize, oldfd)), + @as(usize, @bitCast(@as(isize, oldfd))), @intFromPtr(oldpath), - @bitCast(usize, @as(isize, newfd)), + @as(usize, @bitCast(@as(isize, newfd))), @intFromPtr(newpath), flags, ); @@ -734,7 +734,7 @@ pub fn open(path: [*:0]const u8, flags: u32, perm: mode_t) usize { } else { return syscall4( .openat, - @bitCast(usize, @as(isize, AT.FDCWD)), + @as(usize, @bitCast(@as(isize, AT.FDCWD))), @intFromPtr(path), flags, perm, @@ -748,7 +748,7 @@ pub fn create(path: [*:0]const u8, perm: mode_t) usize { pub fn openat(dirfd: i32, path: [*:0]const u8, flags: u32, mode: mode_t) usize { // dirfd could be negative, for example AT.FDCWD is -100 - return syscall4(.openat, @bitCast(usize, @as(isize, dirfd)), @intFromPtr(path), flags, mode); + return syscall4(.openat, @as(usize, @bitCast(@as(isize, dirfd))), @intFromPtr(path), flags, mode); } /// See also `clone` (from the arch-specific include) @@ -762,11 +762,11 @@ pub fn clone2(flags: u32, child_stack_ptr: usize) usize { } pub fn close(fd: i32) usize { - return syscall1(.close, @bitCast(usize, @as(isize, fd))); + return syscall1(.close, @as(usize, @bitCast(@as(isize, fd)))); } pub fn fchmod(fd: i32, mode: mode_t) usize { - return syscall2(.fchmod, @bitCast(usize, @as(isize, fd)), mode); + return syscall2(.fchmod, @as(usize, @bitCast(@as(isize, fd))), mode); } pub fn chmod(path: [*:0]const u8, mode: mode_t) usize { @@ -775,7 +775,7 @@ pub fn chmod(path: [*:0]const u8, mode: mode_t) usize { } else { return syscall4( .fchmodat, - @bitCast(usize, @as(isize, AT.FDCWD)), + @as(usize, @bitCast(@as(isize, AT.FDCWD))), @intFromPtr(path), mode, 0, @@ -785,14 +785,14 @@ pub fn chmod(path: [*:0]const u8, mode: mode_t) usize { pub fn fchown(fd: i32, owner: uid_t, group: gid_t) usize { if (@hasField(SYS, "fchown32")) { - return syscall3(.fchown32, @bitCast(usize, @as(isize, fd)), owner, group); + return syscall3(.fchown32, @as(usize, @bitCast(@as(isize, fd))), owner, group); } else { - return syscall3(.fchown, @bitCast(usize, @as(isize, fd)), owner, group); + return syscall3(.fchown, @as(usize, @bitCast(@as(isize, fd))), owner, group); } } pub fn fchmodat(fd: i32, path: [*:0]const u8, mode: mode_t, flags: u32) usize { - return syscall4(.fchmodat, @bitCast(usize, @as(isize, fd)), @intFromPtr(path), mode, flags); + return syscall4(.fchmodat, @as(usize, @bitCast(@as(isize, fd))), @intFromPtr(path), mode, flags); } /// Can only be called on 32 bit systems. For 64 bit see `lseek`. @@ -801,9 +801,9 @@ pub fn llseek(fd: i32, offset: u64, result: ?*u64, whence: usize) usize { // endianness. return syscall5( ._llseek, - @bitCast(usize, @as(isize, fd)), - @truncate(usize, offset >> 32), - @truncate(usize, offset), + @as(usize, @bitCast(@as(isize, fd))), + @as(usize, @truncate(offset >> 32)), + @as(usize, @truncate(offset)), @intFromPtr(result), whence, ); @@ -811,16 +811,16 @@ pub fn llseek(fd: i32, offset: u64, result: ?*u64, whence: usize) usize { /// Can only be called on 64 bit systems. For 32 bit see `llseek`. pub fn lseek(fd: i32, offset: i64, whence: usize) usize { - return syscall3(.lseek, @bitCast(usize, @as(isize, fd)), @bitCast(usize, offset), whence); + return syscall3(.lseek, @as(usize, @bitCast(@as(isize, fd))), @as(usize, @bitCast(offset)), whence); } pub fn exit(status: i32) noreturn { - _ = syscall1(.exit, @bitCast(usize, @as(isize, status))); + _ = syscall1(.exit, @as(usize, @bitCast(@as(isize, status)))); unreachable; } pub fn exit_group(status: i32) noreturn { - _ = syscall1(.exit_group, @bitCast(usize, @as(isize, status))); + _ = syscall1(.exit_group, @as(usize, @bitCast(@as(isize, status)))); unreachable; } @@ -886,15 +886,15 @@ pub fn getrandom(buf: [*]u8, count: usize, flags: u32) usize { } pub fn kill(pid: pid_t, sig: i32) usize { - return syscall2(.kill, @bitCast(usize, @as(isize, pid)), @bitCast(usize, @as(isize, sig))); + return syscall2(.kill, @as(usize, @bitCast(@as(isize, pid))), @as(usize, @bitCast(@as(isize, sig)))); } pub fn tkill(tid: pid_t, sig: i32) usize { - return syscall2(.tkill, @bitCast(usize, @as(isize, tid)), @bitCast(usize, @as(isize, sig))); + return syscall2(.tkill, @as(usize, @bitCast(@as(isize, tid))), @as(usize, @bitCast(@as(isize, sig)))); } pub fn tgkill(tgid: pid_t, tid: pid_t, sig: i32) usize { - return syscall3(.tgkill, @bitCast(usize, @as(isize, tgid)), @bitCast(usize, @as(isize, tid)), @bitCast(usize, @as(isize, sig))); + return syscall3(.tgkill, @as(usize, @bitCast(@as(isize, tgid))), @as(usize, @bitCast(@as(isize, tid))), @as(usize, @bitCast(@as(isize, sig)))); } pub fn link(oldpath: [*:0]const u8, newpath: [*:0]const u8, flags: i32) usize { @@ -903,16 +903,16 @@ pub fn link(oldpath: [*:0]const u8, newpath: [*:0]const u8, flags: i32) usize { .link, @intFromPtr(oldpath), @intFromPtr(newpath), - @bitCast(usize, @as(isize, flags)), + @as(usize, @bitCast(@as(isize, flags))), ); } else { return syscall5( .linkat, - @bitCast(usize, @as(isize, AT.FDCWD)), + @as(usize, @bitCast(@as(isize, AT.FDCWD))), @intFromPtr(oldpath), - @bitCast(usize, @as(isize, AT.FDCWD)), + @as(usize, @bitCast(@as(isize, AT.FDCWD))), @intFromPtr(newpath), - @bitCast(usize, @as(isize, flags)), + @as(usize, @bitCast(@as(isize, flags))), ); } } @@ -920,11 +920,11 @@ pub fn link(oldpath: [*:0]const u8, newpath: [*:0]const u8, flags: i32) usize { pub fn linkat(oldfd: fd_t, oldpath: [*:0]const u8, newfd: fd_t, newpath: [*:0]const u8, flags: i32) usize { return syscall5( .linkat, - @bitCast(usize, @as(isize, oldfd)), + @as(usize, @bitCast(@as(isize, oldfd))), @intFromPtr(oldpath), - @bitCast(usize, @as(isize, newfd)), + @as(usize, @bitCast(@as(isize, newfd))), @intFromPtr(newpath), - @bitCast(usize, @as(isize, flags)), + @as(usize, @bitCast(@as(isize, flags))), ); } @@ -932,22 +932,22 @@ pub fn unlink(path: [*:0]const u8) usize { if (@hasField(SYS, "unlink")) { return syscall1(.unlink, @intFromPtr(path)); } else { - return syscall3(.unlinkat, @bitCast(usize, @as(isize, AT.FDCWD)), @intFromPtr(path), 0); + return syscall3(.unlinkat, @as(usize, @bitCast(@as(isize, AT.FDCWD))), @intFromPtr(path), 0); } } pub fn unlinkat(dirfd: i32, path: [*:0]const u8, flags: u32) usize { - return syscall3(.unlinkat, @bitCast(usize, @as(isize, dirfd)), @intFromPtr(path), flags); + return syscall3(.unlinkat, @as(usize, @bitCast(@as(isize, dirfd))), @intFromPtr(path), flags); } pub fn waitpid(pid: pid_t, status: *u32, flags: u32) usize { - return syscall4(.wait4, @bitCast(usize, @as(isize, pid)), @intFromPtr(status), flags, 0); + return syscall4(.wait4, @as(usize, @bitCast(@as(isize, pid))), @intFromPtr(status), flags, 0); } pub fn wait4(pid: pid_t, status: *u32, flags: u32, usage: ?*rusage) usize { return syscall4( .wait4, - @bitCast(usize, @as(isize, pid)), + @as(usize, @bitCast(@as(isize, pid))), @intFromPtr(status), flags, @intFromPtr(usage), @@ -955,18 +955,18 @@ pub fn wait4(pid: pid_t, status: *u32, flags: u32, usage: ?*rusage) usize { } pub fn waitid(id_type: P, id: i32, infop: *siginfo_t, flags: u32) usize { - return syscall5(.waitid, @intFromEnum(id_type), @bitCast(usize, @as(isize, id)), @intFromPtr(infop), flags, 0); + return syscall5(.waitid, @intFromEnum(id_type), @as(usize, @bitCast(@as(isize, id))), @intFromPtr(infop), flags, 0); } pub fn fcntl(fd: fd_t, cmd: i32, arg: usize) usize { - return syscall3(.fcntl, @bitCast(usize, @as(isize, fd)), @bitCast(usize, @as(isize, cmd)), arg); + return syscall3(.fcntl, @as(usize, @bitCast(@as(isize, fd))), @as(usize, @bitCast(@as(isize, cmd))), arg); } pub fn flock(fd: fd_t, operation: i32) usize { - return syscall2(.flock, @bitCast(usize, @as(isize, fd)), @bitCast(usize, @as(isize, operation))); + return syscall2(.flock, @as(usize, @bitCast(@as(isize, fd))), @as(usize, @bitCast(@as(isize, operation)))); } -var vdso_clock_gettime = @ptrCast(?*const anyopaque, &init_vdso_clock_gettime); +var vdso_clock_gettime = @as(?*const anyopaque, @ptrCast(&init_vdso_clock_gettime)); // We must follow the C calling convention when we call into the VDSO const vdso_clock_gettime_ty = *align(1) const fn (i32, *timespec) callconv(.C) usize; @@ -975,36 +975,36 @@ pub fn clock_gettime(clk_id: i32, tp: *timespec) usize { if (@hasDecl(VDSO, "CGT_SYM")) { const ptr = @atomicLoad(?*const anyopaque, &vdso_clock_gettime, .Unordered); if (ptr) |fn_ptr| { - const f = @ptrCast(vdso_clock_gettime_ty, fn_ptr); + const f = @as(vdso_clock_gettime_ty, @ptrCast(fn_ptr)); const rc = f(clk_id, tp); switch (rc) { - 0, @bitCast(usize, -@as(isize, @intFromEnum(E.INVAL))) => return rc, + 0, @as(usize, @bitCast(-@as(isize, @intFromEnum(E.INVAL)))) => return rc, else => {}, } } } - return syscall2(.clock_gettime, @bitCast(usize, @as(isize, clk_id)), @intFromPtr(tp)); + return syscall2(.clock_gettime, @as(usize, @bitCast(@as(isize, clk_id))), @intFromPtr(tp)); } fn init_vdso_clock_gettime(clk: i32, ts: *timespec) callconv(.C) usize { - const ptr = @ptrFromInt(?*const anyopaque, vdso.lookup(VDSO.CGT_VER, VDSO.CGT_SYM)); + const ptr = @as(?*const anyopaque, @ptrFromInt(vdso.lookup(VDSO.CGT_VER, VDSO.CGT_SYM))); // Note that we may not have a VDSO at all, update the stub address anyway // so that clock_gettime will fall back on the good old (and slow) syscall @atomicStore(?*const anyopaque, &vdso_clock_gettime, ptr, .Monotonic); // Call into the VDSO if available if (ptr) |fn_ptr| { - const f = @ptrCast(vdso_clock_gettime_ty, fn_ptr); + const f = @as(vdso_clock_gettime_ty, @ptrCast(fn_ptr)); return f(clk, ts); } - return @bitCast(usize, -@as(isize, @intFromEnum(E.NOSYS))); + return @as(usize, @bitCast(-@as(isize, @intFromEnum(E.NOSYS)))); } pub fn clock_getres(clk_id: i32, tp: *timespec) usize { - return syscall2(.clock_getres, @bitCast(usize, @as(isize, clk_id)), @intFromPtr(tp)); + return syscall2(.clock_getres, @as(usize, @bitCast(@as(isize, clk_id))), @intFromPtr(tp)); } pub fn clock_settime(clk_id: i32, tp: *const timespec) usize { - return syscall2(.clock_settime, @bitCast(usize, @as(isize, clk_id)), @intFromPtr(tp)); + return syscall2(.clock_settime, @as(usize, @bitCast(@as(isize, clk_id))), @intFromPtr(tp)); } pub fn gettimeofday(tv: *timeval, tz: *timezone) usize { @@ -1053,33 +1053,33 @@ pub fn setregid(rgid: gid_t, egid: gid_t) usize { pub fn getuid() uid_t { if (@hasField(SYS, "getuid32")) { - return @intCast(uid_t, syscall0(.getuid32)); + return @as(uid_t, @intCast(syscall0(.getuid32))); } else { - return @intCast(uid_t, syscall0(.getuid)); + return @as(uid_t, @intCast(syscall0(.getuid))); } } pub fn getgid() gid_t { if (@hasField(SYS, "getgid32")) { - return @intCast(gid_t, syscall0(.getgid32)); + return @as(gid_t, @intCast(syscall0(.getgid32))); } else { - return @intCast(gid_t, syscall0(.getgid)); + return @as(gid_t, @intCast(syscall0(.getgid))); } } pub fn geteuid() uid_t { if (@hasField(SYS, "geteuid32")) { - return @intCast(uid_t, syscall0(.geteuid32)); + return @as(uid_t, @intCast(syscall0(.geteuid32))); } else { - return @intCast(uid_t, syscall0(.geteuid)); + return @as(uid_t, @intCast(syscall0(.geteuid))); } } pub fn getegid() gid_t { if (@hasField(SYS, "getegid32")) { - return @intCast(gid_t, syscall0(.getegid32)); + return @as(gid_t, @intCast(syscall0(.getegid32))); } else { - return @intCast(gid_t, syscall0(.getegid)); + return @as(gid_t, @intCast(syscall0(.getegid))); } } @@ -1154,11 +1154,11 @@ pub fn setgroups(size: usize, list: [*]const gid_t) usize { } pub fn getpid() pid_t { - return @bitCast(pid_t, @truncate(u32, syscall0(.getpid))); + return @as(pid_t, @bitCast(@as(u32, @truncate(syscall0(.getpid))))); } pub fn gettid() pid_t { - return @bitCast(pid_t, @truncate(u32, syscall0(.gettid))); + return @as(pid_t, @bitCast(@as(u32, @truncate(syscall0(.gettid))))); } pub fn sigprocmask(flags: u32, noalias set: ?*const sigset_t, noalias oldset: ?*sigset_t) usize { @@ -1182,9 +1182,9 @@ pub fn sigaction(sig: u6, noalias act: ?*const Sigaction, noalias oact: ?*Sigact .handler = new.handler.handler, .flags = new.flags | SA.RESTORER, .mask = undefined, - .restorer = @ptrCast(k_sigaction_funcs.restorer, restorer_fn), + .restorer = @as(k_sigaction_funcs.restorer, @ptrCast(restorer_fn)), }; - @memcpy(@ptrCast([*]u8, &ksa.mask)[0..mask_size], @ptrCast([*]const u8, &new.mask)); + @memcpy(@as([*]u8, @ptrCast(&ksa.mask))[0..mask_size], @as([*]const u8, @ptrCast(&new.mask))); } const ksa_arg = if (act != null) @intFromPtr(&ksa) else 0; @@ -1199,8 +1199,8 @@ pub fn sigaction(sig: u6, noalias act: ?*const Sigaction, noalias oact: ?*Sigact if (oact) |old| { old.handler.handler = oldksa.handler; - old.flags = @truncate(c_uint, oldksa.flags); - @memcpy(@ptrCast([*]u8, &old.mask)[0..mask_size], @ptrCast([*]const u8, &oldksa.mask)); + old.flags = @as(c_uint, @truncate(oldksa.flags)); + @memcpy(@as([*]u8, @ptrCast(&old.mask))[0..mask_size], @as([*]const u8, @ptrCast(&oldksa.mask))); } return 0; @@ -1211,28 +1211,28 @@ const usize_bits = @typeInfo(usize).Int.bits; pub fn sigaddset(set: *sigset_t, sig: u6) void { const s = sig - 1; // shift in musl: s&8*sizeof *set->__bits-1 - const shift = @intCast(u5, s & (usize_bits - 1)); - const val = @intCast(u32, 1) << shift; - (set.*)[@intCast(usize, s) / usize_bits] |= val; + const shift = @as(u5, @intCast(s & (usize_bits - 1))); + const val = @as(u32, @intCast(1)) << shift; + (set.*)[@as(usize, @intCast(s)) / usize_bits] |= val; } pub fn sigismember(set: *const sigset_t, sig: u6) bool { const s = sig - 1; - return ((set.*)[@intCast(usize, s) / usize_bits] & (@intCast(usize, 1) << (s & (usize_bits - 1)))) != 0; + return ((set.*)[@as(usize, @intCast(s)) / usize_bits] & (@as(usize, @intCast(1)) << (s & (usize_bits - 1)))) != 0; } pub fn getsockname(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t) usize { if (native_arch == .x86) { - return socketcall(SC.getsockname, &[3]usize{ @bitCast(usize, @as(isize, fd)), @intFromPtr(addr), @intFromPtr(len) }); + return socketcall(SC.getsockname, &[3]usize{ @as(usize, @bitCast(@as(isize, fd))), @intFromPtr(addr), @intFromPtr(len) }); } - return syscall3(.getsockname, @bitCast(usize, @as(isize, fd)), @intFromPtr(addr), @intFromPtr(len)); + return syscall3(.getsockname, @as(usize, @bitCast(@as(isize, fd))), @intFromPtr(addr), @intFromPtr(len)); } pub fn getpeername(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t) usize { if (native_arch == .x86) { - return socketcall(SC.getpeername, &[3]usize{ @bitCast(usize, @as(isize, fd)), @intFromPtr(addr), @intFromPtr(len) }); + return socketcall(SC.getpeername, &[3]usize{ @as(usize, @bitCast(@as(isize, fd))), @intFromPtr(addr), @intFromPtr(len) }); } - return syscall3(.getpeername, @bitCast(usize, @as(isize, fd)), @intFromPtr(addr), @intFromPtr(len)); + return syscall3(.getpeername, @as(usize, @bitCast(@as(isize, fd))), @intFromPtr(addr), @intFromPtr(len)); } pub fn socket(domain: u32, socket_type: u32, protocol: u32) usize { @@ -1244,20 +1244,20 @@ pub fn socket(domain: u32, socket_type: u32, protocol: u32) usize { pub fn setsockopt(fd: i32, level: u32, optname: u32, optval: [*]const u8, optlen: socklen_t) usize { if (native_arch == .x86) { - return socketcall(SC.setsockopt, &[5]usize{ @bitCast(usize, @as(isize, fd)), level, optname, @intFromPtr(optval), @intCast(usize, optlen) }); + return socketcall(SC.setsockopt, &[5]usize{ @as(usize, @bitCast(@as(isize, fd))), level, optname, @intFromPtr(optval), @as(usize, @intCast(optlen)) }); } - return syscall5(.setsockopt, @bitCast(usize, @as(isize, fd)), level, optname, @intFromPtr(optval), @intCast(usize, optlen)); + return syscall5(.setsockopt, @as(usize, @bitCast(@as(isize, fd))), level, optname, @intFromPtr(optval), @as(usize, @intCast(optlen))); } pub fn getsockopt(fd: i32, level: u32, optname: u32, noalias optval: [*]u8, noalias optlen: *socklen_t) usize { if (native_arch == .x86) { - return socketcall(SC.getsockopt, &[5]usize{ @bitCast(usize, @as(isize, fd)), level, optname, @intFromPtr(optval), @intFromPtr(optlen) }); + return socketcall(SC.getsockopt, &[5]usize{ @as(usize, @bitCast(@as(isize, fd))), level, optname, @intFromPtr(optval), @intFromPtr(optlen) }); } - return syscall5(.getsockopt, @bitCast(usize, @as(isize, fd)), level, optname, @intFromPtr(optval), @intFromPtr(optlen)); + return syscall5(.getsockopt, @as(usize, @bitCast(@as(isize, fd))), level, optname, @intFromPtr(optval), @intFromPtr(optlen)); } pub fn sendmsg(fd: i32, msg: *const msghdr_const, flags: u32) usize { - const fd_usize = @bitCast(usize, @as(isize, fd)); + const fd_usize = @as(usize, @bitCast(@as(isize, fd))); const msg_usize = @intFromPtr(msg); if (native_arch == .x86) { return socketcall(SC.sendmsg, &[3]usize{ fd_usize, msg_usize, flags }); @@ -1275,13 +1275,13 @@ pub fn sendmmsg(fd: i32, msgvec: [*]mmsghdr_const, vlen: u32, flags: u32) usize var next_unsent: usize = 0; for (msgvec[0..kvlen], 0..) |*msg, i| { var size: i32 = 0; - const msg_iovlen = @intCast(usize, msg.msg_hdr.msg_iovlen); // kernel side this is treated as unsigned + const msg_iovlen = @as(usize, @intCast(msg.msg_hdr.msg_iovlen)); // kernel side this is treated as unsigned for (msg.msg_hdr.msg_iov[0..msg_iovlen]) |iov| { - if (iov.iov_len > std.math.maxInt(i32) or @addWithOverflow(size, @intCast(i32, iov.iov_len))[1] != 0) { + if (iov.iov_len > std.math.maxInt(i32) or @addWithOverflow(size, @as(i32, @intCast(iov.iov_len)))[1] != 0) { // batch-send all messages up to the current message if (next_unsent < i) { const batch_size = i - next_unsent; - const r = syscall4(.sendmmsg, @bitCast(usize, @as(isize, fd)), @intFromPtr(&msgvec[next_unsent]), batch_size, flags); + const r = syscall4(.sendmmsg, @as(usize, @bitCast(@as(isize, fd))), @intFromPtr(&msgvec[next_unsent]), batch_size, flags); if (getErrno(r) != 0) return next_unsent; if (r < batch_size) return next_unsent + r; } @@ -1289,7 +1289,7 @@ pub fn sendmmsg(fd: i32, msgvec: [*]mmsghdr_const, vlen: u32, flags: u32) usize const r = sendmsg(fd, &msg.msg_hdr, flags); if (getErrno(r) != 0) return r; // Linux limits the total bytes sent by sendmsg to INT_MAX, so this cast is safe. - msg.msg_len = @intCast(u32, r); + msg.msg_len = @as(u32, @intCast(r)); next_unsent = i + 1; break; } @@ -1297,17 +1297,17 @@ pub fn sendmmsg(fd: i32, msgvec: [*]mmsghdr_const, vlen: u32, flags: u32) usize } if (next_unsent < kvlen or next_unsent == 0) { // want to make sure at least one syscall occurs (e.g. to trigger MSG.EOR) const batch_size = kvlen - next_unsent; - const r = syscall4(.sendmmsg, @bitCast(usize, @as(isize, fd)), @intFromPtr(&msgvec[next_unsent]), batch_size, flags); + const r = syscall4(.sendmmsg, @as(usize, @bitCast(@as(isize, fd))), @intFromPtr(&msgvec[next_unsent]), batch_size, flags); if (getErrno(r) != 0) return r; return next_unsent + r; } return kvlen; } - return syscall4(.sendmmsg, @bitCast(usize, @as(isize, fd)), @intFromPtr(msgvec), vlen, flags); + return syscall4(.sendmmsg, @as(usize, @bitCast(@as(isize, fd))), @intFromPtr(msgvec), vlen, flags); } pub fn connect(fd: i32, addr: *const anyopaque, len: socklen_t) usize { - const fd_usize = @bitCast(usize, @as(isize, fd)); + const fd_usize = @as(usize, @bitCast(@as(isize, fd))); const addr_usize = @intFromPtr(addr); if (native_arch == .x86) { return socketcall(SC.connect, &[3]usize{ fd_usize, addr_usize, len }); @@ -1317,7 +1317,7 @@ pub fn connect(fd: i32, addr: *const anyopaque, len: socklen_t) usize { } pub fn recvmsg(fd: i32, msg: *msghdr, flags: u32) usize { - const fd_usize = @bitCast(usize, @as(isize, fd)); + const fd_usize = @as(usize, @bitCast(@as(isize, fd))); const msg_usize = @intFromPtr(msg); if (native_arch == .x86) { return socketcall(SC.recvmsg, &[3]usize{ fd_usize, msg_usize, flags }); @@ -1334,7 +1334,7 @@ pub fn recvfrom( noalias addr: ?*sockaddr, noalias alen: ?*socklen_t, ) usize { - const fd_usize = @bitCast(usize, @as(isize, fd)); + const fd_usize = @as(usize, @bitCast(@as(isize, fd))); const buf_usize = @intFromPtr(buf); const addr_usize = @intFromPtr(addr); const alen_usize = @intFromPtr(alen); @@ -1347,46 +1347,46 @@ pub fn recvfrom( pub fn shutdown(fd: i32, how: i32) usize { if (native_arch == .x86) { - return socketcall(SC.shutdown, &[2]usize{ @bitCast(usize, @as(isize, fd)), @bitCast(usize, @as(isize, how)) }); + return socketcall(SC.shutdown, &[2]usize{ @as(usize, @bitCast(@as(isize, fd))), @as(usize, @bitCast(@as(isize, how))) }); } - return syscall2(.shutdown, @bitCast(usize, @as(isize, fd)), @bitCast(usize, @as(isize, how))); + return syscall2(.shutdown, @as(usize, @bitCast(@as(isize, fd))), @as(usize, @bitCast(@as(isize, how)))); } pub fn bind(fd: i32, addr: *const sockaddr, len: socklen_t) usize { if (native_arch == .x86) { - return socketcall(SC.bind, &[3]usize{ @bitCast(usize, @as(isize, fd)), @intFromPtr(addr), @intCast(usize, len) }); + return socketcall(SC.bind, &[3]usize{ @as(usize, @bitCast(@as(isize, fd))), @intFromPtr(addr), @as(usize, @intCast(len)) }); } - return syscall3(.bind, @bitCast(usize, @as(isize, fd)), @intFromPtr(addr), @intCast(usize, len)); + return syscall3(.bind, @as(usize, @bitCast(@as(isize, fd))), @intFromPtr(addr), @as(usize, @intCast(len))); } pub fn listen(fd: i32, backlog: u32) usize { if (native_arch == .x86) { - return socketcall(SC.listen, &[2]usize{ @bitCast(usize, @as(isize, fd)), backlog }); + return socketcall(SC.listen, &[2]usize{ @as(usize, @bitCast(@as(isize, fd))), backlog }); } - return syscall2(.listen, @bitCast(usize, @as(isize, fd)), backlog); + return syscall2(.listen, @as(usize, @bitCast(@as(isize, fd))), backlog); } pub fn sendto(fd: i32, buf: [*]const u8, len: usize, flags: u32, addr: ?*const sockaddr, alen: socklen_t) usize { if (native_arch == .x86) { - return socketcall(SC.sendto, &[6]usize{ @bitCast(usize, @as(isize, fd)), @intFromPtr(buf), len, flags, @intFromPtr(addr), @intCast(usize, alen) }); + return socketcall(SC.sendto, &[6]usize{ @as(usize, @bitCast(@as(isize, fd))), @intFromPtr(buf), len, flags, @intFromPtr(addr), @as(usize, @intCast(alen)) }); } - return syscall6(.sendto, @bitCast(usize, @as(isize, fd)), @intFromPtr(buf), len, flags, @intFromPtr(addr), @intCast(usize, alen)); + return syscall6(.sendto, @as(usize, @bitCast(@as(isize, fd))), @intFromPtr(buf), len, flags, @intFromPtr(addr), @as(usize, @intCast(alen))); } pub fn sendfile(outfd: i32, infd: i32, offset: ?*i64, count: usize) usize { if (@hasField(SYS, "sendfile64")) { return syscall4( .sendfile64, - @bitCast(usize, @as(isize, outfd)), - @bitCast(usize, @as(isize, infd)), + @as(usize, @bitCast(@as(isize, outfd))), + @as(usize, @bitCast(@as(isize, infd))), @intFromPtr(offset), count, ); } else { return syscall4( .sendfile, - @bitCast(usize, @as(isize, outfd)), - @bitCast(usize, @as(isize, infd)), + @as(usize, @bitCast(@as(isize, outfd))), + @as(usize, @bitCast(@as(isize, infd))), @intFromPtr(offset), count, ); @@ -1395,9 +1395,9 @@ pub fn sendfile(outfd: i32, infd: i32, offset: ?*i64, count: usize) usize { pub fn socketpair(domain: i32, socket_type: i32, protocol: i32, fd: *[2]i32) usize { if (native_arch == .x86) { - return socketcall(SC.socketpair, &[4]usize{ @intCast(usize, domain), @intCast(usize, socket_type), @intCast(usize, protocol), @intFromPtr(fd) }); + return socketcall(SC.socketpair, &[4]usize{ @as(usize, @intCast(domain)), @as(usize, @intCast(socket_type)), @as(usize, @intCast(protocol)), @intFromPtr(fd) }); } - return syscall4(.socketpair, @intCast(usize, domain), @intCast(usize, socket_type), @intCast(usize, protocol), @intFromPtr(fd)); + return syscall4(.socketpair, @as(usize, @intCast(domain)), @as(usize, @intCast(socket_type)), @as(usize, @intCast(protocol)), @intFromPtr(fd)); } pub fn accept(fd: i32, noalias addr: ?*sockaddr, noalias len: ?*socklen_t) usize { @@ -1409,16 +1409,16 @@ pub fn accept(fd: i32, noalias addr: ?*sockaddr, noalias len: ?*socklen_t) usize pub fn accept4(fd: i32, noalias addr: ?*sockaddr, noalias len: ?*socklen_t, flags: u32) usize { if (native_arch == .x86) { - return socketcall(SC.accept4, &[4]usize{ @bitCast(usize, @as(isize, fd)), @intFromPtr(addr), @intFromPtr(len), flags }); + return socketcall(SC.accept4, &[4]usize{ @as(usize, @bitCast(@as(isize, fd))), @intFromPtr(addr), @intFromPtr(len), flags }); } - return syscall4(.accept4, @bitCast(usize, @as(isize, fd)), @intFromPtr(addr), @intFromPtr(len), flags); + return syscall4(.accept4, @as(usize, @bitCast(@as(isize, fd))), @intFromPtr(addr), @intFromPtr(len), flags); } pub fn fstat(fd: i32, stat_buf: *Stat) usize { if (@hasField(SYS, "fstat64")) { - return syscall2(.fstat64, @bitCast(usize, @as(isize, fd)), @intFromPtr(stat_buf)); + return syscall2(.fstat64, @as(usize, @bitCast(@as(isize, fd))), @intFromPtr(stat_buf)); } else { - return syscall2(.fstat, @bitCast(usize, @as(isize, fd)), @intFromPtr(stat_buf)); + return syscall2(.fstat, @as(usize, @bitCast(@as(isize, fd))), @intFromPtr(stat_buf)); } } @@ -1440,9 +1440,9 @@ pub fn lstat(pathname: [*:0]const u8, statbuf: *Stat) usize { pub fn fstatat(dirfd: i32, path: [*:0]const u8, stat_buf: *Stat, flags: u32) usize { if (@hasField(SYS, "fstatat64")) { - return syscall4(.fstatat64, @bitCast(usize, @as(isize, dirfd)), @intFromPtr(path), @intFromPtr(stat_buf), flags); + return syscall4(.fstatat64, @as(usize, @bitCast(@as(isize, dirfd))), @intFromPtr(path), @intFromPtr(stat_buf), flags); } else { - return syscall4(.fstatat, @bitCast(usize, @as(isize, dirfd)), @intFromPtr(path), @intFromPtr(stat_buf), flags); + return syscall4(.fstatat, @as(usize, @bitCast(@as(isize, dirfd))), @intFromPtr(path), @intFromPtr(stat_buf), flags); } } @@ -1450,14 +1450,14 @@ pub fn statx(dirfd: i32, path: [*]const u8, flags: u32, mask: u32, statx_buf: *S if (@hasField(SYS, "statx")) { return syscall5( .statx, - @bitCast(usize, @as(isize, dirfd)), + @as(usize, @bitCast(@as(isize, dirfd))), @intFromPtr(path), flags, mask, @intFromPtr(statx_buf), ); } - return @bitCast(usize, -@as(isize, @intFromEnum(E.NOSYS))); + return @as(usize, @bitCast(-@as(isize, @intFromEnum(E.NOSYS)))); } pub fn listxattr(path: [*:0]const u8, list: [*]u8, size: usize) usize { @@ -1513,9 +1513,9 @@ pub fn sched_yield() usize { } pub fn sched_getaffinity(pid: pid_t, size: usize, set: *cpu_set_t) usize { - const rc = syscall3(.sched_getaffinity, @bitCast(usize, @as(isize, pid)), size, @intFromPtr(set)); - if (@bitCast(isize, rc) < 0) return rc; - if (rc < size) @memset(@ptrCast([*]u8, set)[rc..size], 0); + const rc = syscall3(.sched_getaffinity, @as(usize, @bitCast(@as(isize, pid))), size, @intFromPtr(set)); + if (@as(isize, @bitCast(rc)) < 0) return rc; + if (rc < size) @memset(@as([*]u8, @ptrCast(set))[rc..size], 0); return 0; } @@ -1526,18 +1526,18 @@ pub fn getcpu(cpu: *u32, node: *u32) usize { pub fn sched_getcpu() usize { var cpu: u32 = undefined; const rc = syscall3(.getcpu, @intFromPtr(&cpu), 0, 0); - if (@bitCast(isize, rc) < 0) return rc; - return @intCast(usize, cpu); + if (@as(isize, @bitCast(rc)) < 0) return rc; + return @as(usize, @intCast(cpu)); } /// libc has no wrapper for this syscall pub fn mbind(addr: ?*anyopaque, len: u32, mode: i32, nodemask: *const u32, maxnode: u32, flags: u32) usize { - return syscall6(.mbind, @intFromPtr(addr), len, @bitCast(usize, @as(isize, mode)), @intFromPtr(nodemask), maxnode, flags); + return syscall6(.mbind, @intFromPtr(addr), len, @as(usize, @bitCast(@as(isize, mode))), @intFromPtr(nodemask), maxnode, flags); } pub fn sched_setaffinity(pid: pid_t, size: usize, set: *const cpu_set_t) usize { - const rc = syscall3(.sched_setaffinity, @bitCast(usize, @as(isize, pid)), size, @intFromPtr(set)); - if (@bitCast(isize, rc) < 0) return rc; + const rc = syscall3(.sched_setaffinity, @as(usize, @bitCast(@as(isize, pid))), size, @intFromPtr(set)); + if (@as(isize, @bitCast(rc)) < 0) return rc; return 0; } @@ -1550,7 +1550,7 @@ pub fn epoll_create1(flags: usize) usize { } pub fn epoll_ctl(epoll_fd: i32, op: u32, fd: i32, ev: ?*epoll_event) usize { - return syscall4(.epoll_ctl, @bitCast(usize, @as(isize, epoll_fd)), @intCast(usize, op), @bitCast(usize, @as(isize, fd)), @intFromPtr(ev)); + return syscall4(.epoll_ctl, @as(usize, @bitCast(@as(isize, epoll_fd))), @as(usize, @intCast(op)), @as(usize, @bitCast(@as(isize, fd))), @intFromPtr(ev)); } pub fn epoll_wait(epoll_fd: i32, events: [*]epoll_event, maxevents: u32, timeout: i32) usize { @@ -1560,10 +1560,10 @@ pub fn epoll_wait(epoll_fd: i32, events: [*]epoll_event, maxevents: u32, timeout pub fn epoll_pwait(epoll_fd: i32, events: [*]epoll_event, maxevents: u32, timeout: i32, sigmask: ?*const sigset_t) usize { return syscall6( .epoll_pwait, - @bitCast(usize, @as(isize, epoll_fd)), + @as(usize, @bitCast(@as(isize, epoll_fd))), @intFromPtr(events), - @intCast(usize, maxevents), - @bitCast(usize, @as(isize, timeout)), + @as(usize, @intCast(maxevents)), + @as(usize, @bitCast(@as(isize, timeout))), @intFromPtr(sigmask), @sizeOf(sigset_t), ); @@ -1574,7 +1574,7 @@ pub fn eventfd(count: u32, flags: u32) usize { } pub fn timerfd_create(clockid: i32, flags: u32) usize { - return syscall2(.timerfd_create, @bitCast(usize, @as(isize, clockid)), flags); + return syscall2(.timerfd_create, @as(usize, @bitCast(@as(isize, clockid))), flags); } pub const itimerspec = extern struct { @@ -1583,11 +1583,11 @@ pub const itimerspec = extern struct { }; pub fn timerfd_gettime(fd: i32, curr_value: *itimerspec) usize { - return syscall2(.timerfd_gettime, @bitCast(usize, @as(isize, fd)), @intFromPtr(curr_value)); + return syscall2(.timerfd_gettime, @as(usize, @bitCast(@as(isize, fd))), @intFromPtr(curr_value)); } pub fn timerfd_settime(fd: i32, flags: u32, new_value: *const itimerspec, old_value: ?*itimerspec) usize { - return syscall4(.timerfd_settime, @bitCast(usize, @as(isize, fd)), flags, @intFromPtr(new_value), @intFromPtr(old_value)); + return syscall4(.timerfd_settime, @as(usize, @bitCast(@as(isize, fd))), flags, @intFromPtr(new_value), @intFromPtr(old_value)); } pub const sigevent = extern struct { @@ -1609,8 +1609,8 @@ pub const timer_t = ?*anyopaque; pub fn timer_create(clockid: i32, sevp: *sigevent, timerid: *timer_t) usize { var t: timer_t = undefined; - const rc = syscall3(.timer_create, @bitCast(usize, @as(isize, clockid)), @intFromPtr(sevp), @intFromPtr(&t)); - if (@bitCast(isize, rc) < 0) return rc; + const rc = syscall3(.timer_create, @as(usize, @bitCast(@as(isize, clockid))), @intFromPtr(sevp), @intFromPtr(&t)); + if (@as(isize, @bitCast(rc)) < 0) return rc; timerid.* = t; return rc; } @@ -1624,7 +1624,7 @@ pub fn timer_gettime(timerid: timer_t, curr_value: *itimerspec) usize { } pub fn timer_settime(timerid: timer_t, flags: i32, new_value: *const itimerspec, old_value: ?*itimerspec) usize { - return syscall4(.timer_settime, @intFromPtr(timerid), @bitCast(usize, @as(isize, flags)), @intFromPtr(new_value), @intFromPtr(old_value)); + return syscall4(.timer_settime, @intFromPtr(timerid), @as(usize, @bitCast(@as(isize, flags))), @intFromPtr(new_value), @intFromPtr(old_value)); } // Flags for the 'setitimer' system call @@ -1635,11 +1635,11 @@ pub const ITIMER = enum(i32) { }; pub fn getitimer(which: i32, curr_value: *itimerspec) usize { - return syscall2(.getitimer, @bitCast(usize, @as(isize, which)), @intFromPtr(curr_value)); + return syscall2(.getitimer, @as(usize, @bitCast(@as(isize, which))), @intFromPtr(curr_value)); } pub fn setitimer(which: i32, new_value: *const itimerspec, old_value: ?*itimerspec) usize { - return syscall3(.setitimer, @bitCast(usize, @as(isize, which)), @intFromPtr(new_value), @intFromPtr(old_value)); + return syscall3(.setitimer, @as(usize, @bitCast(@as(isize, which))), @intFromPtr(new_value), @intFromPtr(old_value)); } pub fn unshare(flags: usize) usize { @@ -1667,11 +1667,11 @@ pub fn io_uring_setup(entries: u32, p: *io_uring_params) usize { } pub fn io_uring_enter(fd: i32, to_submit: u32, min_complete: u32, flags: u32, sig: ?*sigset_t) usize { - return syscall6(.io_uring_enter, @bitCast(usize, @as(isize, fd)), to_submit, min_complete, flags, @intFromPtr(sig), NSIG / 8); + return syscall6(.io_uring_enter, @as(usize, @bitCast(@as(isize, fd))), to_submit, min_complete, flags, @intFromPtr(sig), NSIG / 8); } pub fn io_uring_register(fd: i32, opcode: IORING_REGISTER, arg: ?*const anyopaque, nr_args: u32) usize { - return syscall4(.io_uring_register, @bitCast(usize, @as(isize, fd)), @intFromEnum(opcode), @intFromPtr(arg), nr_args); + return syscall4(.io_uring_register, @as(usize, @bitCast(@as(isize, fd))), @intFromEnum(opcode), @intFromPtr(arg), nr_args); } pub fn memfd_create(name: [*:0]const u8, flags: u32) usize { @@ -1679,43 +1679,43 @@ pub fn memfd_create(name: [*:0]const u8, flags: u32) usize { } pub fn getrusage(who: i32, usage: *rusage) usize { - return syscall2(.getrusage, @bitCast(usize, @as(isize, who)), @intFromPtr(usage)); + return syscall2(.getrusage, @as(usize, @bitCast(@as(isize, who))), @intFromPtr(usage)); } pub fn tcgetattr(fd: fd_t, termios_p: *termios) usize { - return syscall3(.ioctl, @bitCast(usize, @as(isize, fd)), T.CGETS, @intFromPtr(termios_p)); + return syscall3(.ioctl, @as(usize, @bitCast(@as(isize, fd))), T.CGETS, @intFromPtr(termios_p)); } pub fn tcsetattr(fd: fd_t, optional_action: TCSA, termios_p: *const termios) usize { - return syscall3(.ioctl, @bitCast(usize, @as(isize, fd)), T.CSETS + @intFromEnum(optional_action), @intFromPtr(termios_p)); + return syscall3(.ioctl, @as(usize, @bitCast(@as(isize, fd))), T.CSETS + @intFromEnum(optional_action), @intFromPtr(termios_p)); } pub fn tcgetpgrp(fd: fd_t, pgrp: *pid_t) usize { - return syscall3(.ioctl, @bitCast(usize, @as(isize, fd)), T.IOCGPGRP, @intFromPtr(pgrp)); + return syscall3(.ioctl, @as(usize, @bitCast(@as(isize, fd))), T.IOCGPGRP, @intFromPtr(pgrp)); } pub fn tcsetpgrp(fd: fd_t, pgrp: *const pid_t) usize { - return syscall3(.ioctl, @bitCast(usize, @as(isize, fd)), T.IOCSPGRP, @intFromPtr(pgrp)); + return syscall3(.ioctl, @as(usize, @bitCast(@as(isize, fd))), T.IOCSPGRP, @intFromPtr(pgrp)); } pub fn tcdrain(fd: fd_t) usize { - return syscall3(.ioctl, @bitCast(usize, @as(isize, fd)), T.CSBRK, 1); + return syscall3(.ioctl, @as(usize, @bitCast(@as(isize, fd))), T.CSBRK, 1); } pub fn ioctl(fd: fd_t, request: u32, arg: usize) usize { - return syscall3(.ioctl, @bitCast(usize, @as(isize, fd)), request, arg); + return syscall3(.ioctl, @as(usize, @bitCast(@as(isize, fd))), request, arg); } pub fn signalfd(fd: fd_t, mask: *const sigset_t, flags: u32) usize { - return syscall4(.signalfd4, @bitCast(usize, @as(isize, fd)), @intFromPtr(mask), NSIG / 8, flags); + return syscall4(.signalfd4, @as(usize, @bitCast(@as(isize, fd))), @intFromPtr(mask), NSIG / 8, flags); } pub fn copy_file_range(fd_in: fd_t, off_in: ?*i64, fd_out: fd_t, off_out: ?*i64, len: usize, flags: u32) usize { return syscall6( .copy_file_range, - @bitCast(usize, @as(isize, fd_in)), + @as(usize, @bitCast(@as(isize, fd_in))), @intFromPtr(off_in), - @bitCast(usize, @as(isize, fd_out)), + @as(usize, @bitCast(@as(isize, fd_out))), @intFromPtr(off_out), len, flags, @@ -1731,19 +1731,19 @@ pub fn sync() void { } pub fn syncfs(fd: fd_t) usize { - return syscall1(.syncfs, @bitCast(usize, @as(isize, fd))); + return syscall1(.syncfs, @as(usize, @bitCast(@as(isize, fd)))); } pub fn fsync(fd: fd_t) usize { - return syscall1(.fsync, @bitCast(usize, @as(isize, fd))); + return syscall1(.fsync, @as(usize, @bitCast(@as(isize, fd)))); } pub fn fdatasync(fd: fd_t) usize { - return syscall1(.fdatasync, @bitCast(usize, @as(isize, fd))); + return syscall1(.fdatasync, @as(usize, @bitCast(@as(isize, fd)))); } pub fn prctl(option: i32, arg2: usize, arg3: usize, arg4: usize, arg5: usize) usize { - return syscall5(.prctl, @bitCast(usize, @as(isize, option)), arg2, arg3, arg4, arg5); + return syscall5(.prctl, @as(usize, @bitCast(@as(isize, option))), arg2, arg3, arg4, arg5); } pub fn getrlimit(resource: rlimit_resource, rlim: *rlimit) usize { @@ -1759,8 +1759,8 @@ pub fn setrlimit(resource: rlimit_resource, rlim: *const rlimit) usize { pub fn prlimit(pid: pid_t, resource: rlimit_resource, new_limit: ?*const rlimit, old_limit: ?*rlimit) usize { return syscall4( .prlimit64, - @bitCast(usize, @as(isize, pid)), - @bitCast(usize, @as(isize, @intFromEnum(resource))), + @as(usize, @bitCast(@as(isize, pid))), + @as(usize, @bitCast(@as(isize, @intFromEnum(resource)))), @intFromPtr(new_limit), @intFromPtr(old_limit), ); @@ -1775,14 +1775,14 @@ pub fn madvise(address: [*]u8, len: usize, advice: u32) usize { } pub fn pidfd_open(pid: pid_t, flags: u32) usize { - return syscall2(.pidfd_open, @bitCast(usize, @as(isize, pid)), flags); + return syscall2(.pidfd_open, @as(usize, @bitCast(@as(isize, pid))), flags); } pub fn pidfd_getfd(pidfd: fd_t, targetfd: fd_t, flags: u32) usize { return syscall3( .pidfd_getfd, - @bitCast(usize, @as(isize, pidfd)), - @bitCast(usize, @as(isize, targetfd)), + @as(usize, @bitCast(@as(isize, pidfd))), + @as(usize, @bitCast(@as(isize, targetfd))), flags, ); } @@ -1790,8 +1790,8 @@ pub fn pidfd_getfd(pidfd: fd_t, targetfd: fd_t, flags: u32) usize { pub fn pidfd_send_signal(pidfd: fd_t, sig: i32, info: ?*siginfo_t, flags: u32) usize { return syscall4( .pidfd_send_signal, - @bitCast(usize, @as(isize, pidfd)), - @bitCast(usize, @as(isize, sig)), + @as(usize, @bitCast(@as(isize, pidfd))), + @as(usize, @bitCast(@as(isize, sig))), @intFromPtr(info), flags, ); @@ -1800,7 +1800,7 @@ pub fn pidfd_send_signal(pidfd: fd_t, sig: i32, info: ?*siginfo_t, flags: u32) u pub fn process_vm_readv(pid: pid_t, local: []iovec, remote: []const iovec_const, flags: usize) usize { return syscall6( .process_vm_readv, - @bitCast(usize, @as(isize, pid)), + @as(usize, @bitCast(@as(isize, pid))), @intFromPtr(local.ptr), local.len, @intFromPtr(remote.ptr), @@ -1812,7 +1812,7 @@ pub fn process_vm_readv(pid: pid_t, local: []iovec, remote: []const iovec_const, pub fn process_vm_writev(pid: pid_t, local: []const iovec_const, remote: []const iovec_const, flags: usize) usize { return syscall6( .process_vm_writev, - @bitCast(usize, @as(isize, pid)), + @as(usize, @bitCast(@as(isize, pid))), @intFromPtr(local.ptr), local.len, @intFromPtr(remote.ptr), @@ -1830,7 +1830,7 @@ pub fn fadvise(fd: fd_t, offset: i64, len: i64, advice: usize) usize { return syscall7( .fadvise64, - @bitCast(usize, @as(isize, fd)), + @as(usize, @bitCast(@as(isize, fd))), 0, offset_halves[0], offset_halves[1], @@ -1846,7 +1846,7 @@ pub fn fadvise(fd: fd_t, offset: i64, len: i64, advice: usize) usize { return syscall6( .fadvise64_64, - @bitCast(usize, @as(isize, fd)), + @as(usize, @bitCast(@as(isize, fd))), advice, offset_halves[0], offset_halves[1], @@ -1862,7 +1862,7 @@ pub fn fadvise(fd: fd_t, offset: i64, len: i64, advice: usize) usize { return syscall6( .fadvise64_64, - @bitCast(usize, @as(isize, fd)), + @as(usize, @bitCast(@as(isize, fd))), offset_halves[0], offset_halves[1], length_halves[0], @@ -1872,9 +1872,9 @@ pub fn fadvise(fd: fd_t, offset: i64, len: i64, advice: usize) usize { } else { return syscall4( .fadvise64, - @bitCast(usize, @as(isize, fd)), - @bitCast(usize, offset), - @bitCast(usize, len), + @as(usize, @bitCast(@as(isize, fd))), + @as(usize, @bitCast(offset)), + @as(usize, @bitCast(len)), advice, ); } @@ -1890,9 +1890,9 @@ pub fn perf_event_open( return syscall5( .perf_event_open, @intFromPtr(attr), - @bitCast(usize, @as(isize, pid)), - @bitCast(usize, @as(isize, cpu)), - @bitCast(usize, @as(isize, group_fd)), + @as(usize, @bitCast(@as(isize, pid))), + @as(usize, @bitCast(@as(isize, cpu))), + @as(usize, @bitCast(@as(isize, group_fd))), flags, ); } @@ -1911,7 +1911,7 @@ pub fn ptrace( return syscall5( .ptrace, req, - @bitCast(usize, @as(isize, pid)), + @as(usize, @bitCast(@as(isize, pid))), addr, data, addr2, @@ -2057,7 +2057,7 @@ pub const W = struct { pub const NOWAIT = 0x1000000; pub fn EXITSTATUS(s: u32) u8 { - return @intCast(u8, (s & 0xff00) >> 8); + return @as(u8, @intCast((s & 0xff00) >> 8)); } pub fn TERMSIG(s: u32) u32 { return s & 0x7f; @@ -2069,7 +2069,7 @@ pub const W = struct { return TERMSIG(s) == 0; } pub fn IFSTOPPED(s: u32) bool { - return @truncate(u16, ((s & 0xffff) *% 0x10001) >> 8) > 0x7f00; + return @as(u16, @truncate(((s & 0xffff) *% 0x10001) >> 8)) > 0x7f00; } pub fn IFSIGNALED(s: u32) bool { return (s & 0xffff) -% 1 < 0xff; @@ -2154,9 +2154,9 @@ pub const SIG = if (is_mips) struct { pub const SYS = 31; pub const UNUSED = SIG.SYS; - pub const ERR = @ptrFromInt(?Sigaction.handler_fn, maxInt(usize)); - pub const DFL = @ptrFromInt(?Sigaction.handler_fn, 0); - pub const IGN = @ptrFromInt(?Sigaction.handler_fn, 1); + pub const ERR = @as(?Sigaction.handler_fn, @ptrFromInt(maxInt(usize))); + pub const DFL = @as(?Sigaction.handler_fn, @ptrFromInt(0)); + pub const IGN = @as(?Sigaction.handler_fn, @ptrFromInt(1)); } else if (is_sparc) struct { pub const BLOCK = 1; pub const UNBLOCK = 2; @@ -2198,9 +2198,9 @@ pub const SIG = if (is_mips) struct { pub const PWR = LOST; pub const IO = SIG.POLL; - pub const ERR = @ptrFromInt(?Sigaction.handler_fn, maxInt(usize)); - pub const DFL = @ptrFromInt(?Sigaction.handler_fn, 0); - pub const IGN = @ptrFromInt(?Sigaction.handler_fn, 1); + pub const ERR = @as(?Sigaction.handler_fn, @ptrFromInt(maxInt(usize))); + pub const DFL = @as(?Sigaction.handler_fn, @ptrFromInt(0)); + pub const IGN = @as(?Sigaction.handler_fn, @ptrFromInt(1)); } else struct { pub const BLOCK = 0; pub const UNBLOCK = 1; @@ -2241,9 +2241,9 @@ pub const SIG = if (is_mips) struct { pub const SYS = 31; pub const UNUSED = SIG.SYS; - pub const ERR = @ptrFromInt(?Sigaction.handler_fn, maxInt(usize)); - pub const DFL = @ptrFromInt(?Sigaction.handler_fn, 0); - pub const IGN = @ptrFromInt(?Sigaction.handler_fn, 1); + pub const ERR = @as(?Sigaction.handler_fn, @ptrFromInt(maxInt(usize))); + pub const DFL = @as(?Sigaction.handler_fn, @ptrFromInt(0)); + pub const IGN = @as(?Sigaction.handler_fn, @ptrFromInt(1)); }; pub const kernel_rwf = u32; @@ -3541,7 +3541,7 @@ pub const CAP = struct { } pub fn TO_MASK(cap: u8) u32 { - return @as(u32, 1) << @intCast(u5, cap & 31); + return @as(u32, 1) << @as(u5, @intCast(cap & 31)); } pub fn TO_INDEX(cap: u8) u8 { @@ -3598,7 +3598,7 @@ pub const cpu_count_t = std.meta.Int(.unsigned, std.math.log2(CPU_SETSIZE * 8)); fn cpu_mask(s: usize) cpu_count_t { var x = s & (CPU_SETSIZE * 8); - return @intCast(cpu_count_t, 1) << @intCast(u4, x); + return @as(cpu_count_t, @intCast(1)) << @as(u4, @intCast(x)); } pub fn CPU_COUNT(set: cpu_set_t) cpu_count_t { @@ -3999,7 +3999,7 @@ pub const io_uring_cqe = extern struct { pub fn err(self: io_uring_cqe) E { if (self.res > -4096 and self.res < 0) { - return @enumFromInt(E, -self.res); + return @as(E, @enumFromInt(-self.res)); } return .SUCCESS; } diff --git a/lib/std/os/linux/bpf.zig b/lib/std/os/linux/bpf.zig index 87b92587f9..751e5dc95a 100644 --- a/lib/std/os/linux/bpf.zig +++ b/lib/std/os/linux/bpf.zig @@ -643,7 +643,7 @@ pub const Insn = packed struct { .dst = @intFromEnum(dst), .src = @intFromEnum(src), .off = 0, - .imm = @intCast(i32, @truncate(u32, imm)), + .imm = @as(i32, @intCast(@as(u32, @truncate(imm)))), }; } @@ -653,7 +653,7 @@ pub const Insn = packed struct { .dst = 0, .src = 0, .off = 0, - .imm = @intCast(i32, @truncate(u32, imm >> 32)), + .imm = @as(i32, @intCast(@as(u32, @truncate(imm >> 32)))), }; } @@ -666,11 +666,11 @@ pub const Insn = packed struct { } pub fn ld_map_fd1(dst: Reg, map_fd: fd_t) Insn { - return ld_imm_impl1(dst, @enumFromInt(Reg, PSEUDO_MAP_FD), @intCast(u64, map_fd)); + return ld_imm_impl1(dst, @as(Reg, @enumFromInt(PSEUDO_MAP_FD)), @as(u64, @intCast(map_fd))); } pub fn ld_map_fd2(map_fd: fd_t) Insn { - return ld_imm_impl2(@intCast(u64, map_fd)); + return ld_imm_impl2(@as(u64, @intCast(map_fd))); } pub fn st(comptime size: Size, dst: Reg, off: i16, imm: i32) Insn { @@ -786,17 +786,17 @@ test "opcodes" { // TODO: byteswap instructions try expect_opcode(0xd4, Insn.le(.half_word, .r1)); - try expectEqual(@intCast(i32, 16), Insn.le(.half_word, .r1).imm); + try expectEqual(@as(i32, @intCast(16)), Insn.le(.half_word, .r1).imm); try expect_opcode(0xd4, Insn.le(.word, .r1)); - try expectEqual(@intCast(i32, 32), Insn.le(.word, .r1).imm); + try expectEqual(@as(i32, @intCast(32)), Insn.le(.word, .r1).imm); try expect_opcode(0xd4, Insn.le(.double_word, .r1)); - try expectEqual(@intCast(i32, 64), Insn.le(.double_word, .r1).imm); + try expectEqual(@as(i32, @intCast(64)), Insn.le(.double_word, .r1).imm); try expect_opcode(0xdc, Insn.be(.half_word, .r1)); - try expectEqual(@intCast(i32, 16), Insn.be(.half_word, .r1).imm); + try expectEqual(@as(i32, @intCast(16)), Insn.be(.half_word, .r1).imm); try expect_opcode(0xdc, Insn.be(.word, .r1)); - try expectEqual(@intCast(i32, 32), Insn.be(.word, .r1).imm); + try expectEqual(@as(i32, @intCast(32)), Insn.be(.word, .r1).imm); try expect_opcode(0xdc, Insn.be(.double_word, .r1)); - try expectEqual(@intCast(i32, 64), Insn.be(.double_word, .r1).imm); + try expectEqual(@as(i32, @intCast(64)), Insn.be(.double_word, .r1).imm); // memory instructions try expect_opcode(0x18, Insn.ld_dw1(.r1, 0)); @@ -804,7 +804,7 @@ test "opcodes" { // loading a map fd try expect_opcode(0x18, Insn.ld_map_fd1(.r1, 0)); - try expectEqual(@intCast(u4, PSEUDO_MAP_FD), Insn.ld_map_fd1(.r1, 0).src); + try expectEqual(@as(u4, @intCast(PSEUDO_MAP_FD)), Insn.ld_map_fd1(.r1, 0).src); try expect_opcode(0x00, Insn.ld_map_fd2(0)); try expect_opcode(0x38, Insn.ld_abs(.double_word, .r1, .r2, 0)); @@ -1518,7 +1518,7 @@ pub fn map_create(map_type: MapType, key_size: u32, value_size: u32, max_entries const rc = linux.bpf(.map_create, &attr, @sizeOf(MapCreateAttr)); switch (errno(rc)) { - .SUCCESS => return @intCast(fd_t, rc), + .SUCCESS => return @as(fd_t, @intCast(rc)), .INVAL => return error.MapTypeOrAttrInvalid, .NOMEM => return error.SystemResources, .PERM => return error.AccessDenied, @@ -1668,20 +1668,20 @@ pub fn prog_load( attr.prog_load.prog_type = @intFromEnum(prog_type); attr.prog_load.insns = @intFromPtr(insns.ptr); - attr.prog_load.insn_cnt = @intCast(u32, insns.len); + attr.prog_load.insn_cnt = @as(u32, @intCast(insns.len)); attr.prog_load.license = @intFromPtr(license.ptr); attr.prog_load.kern_version = kern_version; attr.prog_load.prog_flags = flags; if (log) |l| { attr.prog_load.log_buf = @intFromPtr(l.buf.ptr); - attr.prog_load.log_size = @intCast(u32, l.buf.len); + attr.prog_load.log_size = @as(u32, @intCast(l.buf.len)); attr.prog_load.log_level = l.level; } const rc = linux.bpf(.prog_load, &attr, @sizeOf(ProgLoadAttr)); return switch (errno(rc)) { - .SUCCESS => @intCast(fd_t, rc), + .SUCCESS => @as(fd_t, @intCast(rc)), .ACCES => error.UnsafeProgram, .FAULT => unreachable, .INVAL => error.InvalidProgram, diff --git a/lib/std/os/linux/bpf/helpers.zig b/lib/std/os/linux/bpf/helpers.zig index b26e7eda29..027220088e 100644 --- a/lib/std/os/linux/bpf/helpers.zig +++ b/lib/std/os/linux/bpf/helpers.zig @@ -11,147 +11,147 @@ const SkFullSock = @compileError("TODO missing os bits: SkFullSock"); // // Note, these function signatures were created from documentation found in // '/usr/include/linux/bpf.h' -pub const map_lookup_elem = @ptrFromInt(*const fn (map: *const kern.MapDef, key: ?*const anyopaque) ?*anyopaque, 1); -pub const map_update_elem = @ptrFromInt(*const fn (map: *const kern.MapDef, key: ?*const anyopaque, value: ?*const anyopaque, flags: u64) c_long, 2); -pub const map_delete_elem = @ptrFromInt(*const fn (map: *const kern.MapDef, key: ?*const anyopaque) c_long, 3); -pub const probe_read = @ptrFromInt(*const fn (dst: ?*anyopaque, size: u32, unsafe_ptr: ?*const anyopaque) c_long, 4); -pub const ktime_get_ns = @ptrFromInt(*const fn () u64, 5); -pub const trace_printk = @ptrFromInt(*const fn (fmt: [*:0]const u8, fmt_size: u32, arg1: u64, arg2: u64, arg3: u64) c_long, 6); -pub const get_prandom_u32 = @ptrFromInt(*const fn () u32, 7); -pub const get_smp_processor_id = @ptrFromInt(*const fn () u32, 8); -pub const skb_store_bytes = @ptrFromInt(*const fn (skb: *kern.SkBuff, offset: u32, from: ?*const anyopaque, len: u32, flags: u64) c_long, 9); -pub const l3_csum_replace = @ptrFromInt(*const fn (skb: *kern.SkBuff, offset: u32, from: u64, to: u64, size: u64) c_long, 10); -pub const l4_csum_replace = @ptrFromInt(*const fn (skb: *kern.SkBuff, offset: u32, from: u64, to: u64, flags: u64) c_long, 11); -pub const tail_call = @ptrFromInt(*const fn (ctx: ?*anyopaque, prog_array_map: *const kern.MapDef, index: u32) c_long, 12); -pub const clone_redirect = @ptrFromInt(*const fn (skb: *kern.SkBuff, ifindex: u32, flags: u64) c_long, 13); -pub const get_current_pid_tgid = @ptrFromInt(*const fn () u64, 14); -pub const get_current_uid_gid = @ptrFromInt(*const fn () u64, 15); -pub const get_current_comm = @ptrFromInt(*const fn (buf: ?*anyopaque, size_of_buf: u32) c_long, 16); -pub const get_cgroup_classid = @ptrFromInt(*const fn (skb: *kern.SkBuff) u32, 17); +pub const map_lookup_elem = @as(*const fn (map: *const kern.MapDef, key: ?*const anyopaque) ?*anyopaque, @ptrFromInt(1)); +pub const map_update_elem = @as(*const fn (map: *const kern.MapDef, key: ?*const anyopaque, value: ?*const anyopaque, flags: u64) c_long, @ptrFromInt(2)); +pub const map_delete_elem = @as(*const fn (map: *const kern.MapDef, key: ?*const anyopaque) c_long, @ptrFromInt(3)); +pub const probe_read = @as(*const fn (dst: ?*anyopaque, size: u32, unsafe_ptr: ?*const anyopaque) c_long, @ptrFromInt(4)); +pub const ktime_get_ns = @as(*const fn () u64, @ptrFromInt(5)); +pub const trace_printk = @as(*const fn (fmt: [*:0]const u8, fmt_size: u32, arg1: u64, arg2: u64, arg3: u64) c_long, @ptrFromInt(6)); +pub const get_prandom_u32 = @as(*const fn () u32, @ptrFromInt(7)); +pub const get_smp_processor_id = @as(*const fn () u32, @ptrFromInt(8)); +pub const skb_store_bytes = @as(*const fn (skb: *kern.SkBuff, offset: u32, from: ?*const anyopaque, len: u32, flags: u64) c_long, @ptrFromInt(9)); +pub const l3_csum_replace = @as(*const fn (skb: *kern.SkBuff, offset: u32, from: u64, to: u64, size: u64) c_long, @ptrFromInt(10)); +pub const l4_csum_replace = @as(*const fn (skb: *kern.SkBuff, offset: u32, from: u64, to: u64, flags: u64) c_long, @ptrFromInt(11)); +pub const tail_call = @as(*const fn (ctx: ?*anyopaque, prog_array_map: *const kern.MapDef, index: u32) c_long, @ptrFromInt(12)); +pub const clone_redirect = @as(*const fn (skb: *kern.SkBuff, ifindex: u32, flags: u64) c_long, @ptrFromInt(13)); +pub const get_current_pid_tgid = @as(*const fn () u64, @ptrFromInt(14)); +pub const get_current_uid_gid = @as(*const fn () u64, @ptrFromInt(15)); +pub const get_current_comm = @as(*const fn (buf: ?*anyopaque, size_of_buf: u32) c_long, @ptrFromInt(16)); +pub const get_cgroup_classid = @as(*const fn (skb: *kern.SkBuff) u32, @ptrFromInt(17)); // Note vlan_proto is big endian -pub const skb_vlan_push = @ptrFromInt(*const fn (skb: *kern.SkBuff, vlan_proto: u16, vlan_tci: u16) c_long, 18); -pub const skb_vlan_pop = @ptrFromInt(*const fn (skb: *kern.SkBuff) c_long, 19); -pub const skb_get_tunnel_key = @ptrFromInt(*const fn (skb: *kern.SkBuff, key: *kern.TunnelKey, size: u32, flags: u64) c_long, 20); -pub const skb_set_tunnel_key = @ptrFromInt(*const fn (skb: *kern.SkBuff, key: *kern.TunnelKey, size: u32, flags: u64) c_long, 21); -pub const perf_event_read = @ptrFromInt(*const fn (map: *const kern.MapDef, flags: u64) u64, 22); -pub const redirect = @ptrFromInt(*const fn (ifindex: u32, flags: u64) c_long, 23); -pub const get_route_realm = @ptrFromInt(*const fn (skb: *kern.SkBuff) u32, 24); -pub const perf_event_output = @ptrFromInt(*const fn (ctx: ?*anyopaque, map: *const kern.MapDef, flags: u64, data: ?*anyopaque, size: u64) c_long, 25); -pub const skb_load_bytes = @ptrFromInt(*const fn (skb: ?*anyopaque, offset: u32, to: ?*anyopaque, len: u32) c_long, 26); -pub const get_stackid = @ptrFromInt(*const fn (ctx: ?*anyopaque, map: *const kern.MapDef, flags: u64) c_long, 27); +pub const skb_vlan_push = @as(*const fn (skb: *kern.SkBuff, vlan_proto: u16, vlan_tci: u16) c_long, @ptrFromInt(18)); +pub const skb_vlan_pop = @as(*const fn (skb: *kern.SkBuff) c_long, @ptrFromInt(19)); +pub const skb_get_tunnel_key = @as(*const fn (skb: *kern.SkBuff, key: *kern.TunnelKey, size: u32, flags: u64) c_long, @ptrFromInt(20)); +pub const skb_set_tunnel_key = @as(*const fn (skb: *kern.SkBuff, key: *kern.TunnelKey, size: u32, flags: u64) c_long, @ptrFromInt(21)); +pub const perf_event_read = @as(*const fn (map: *const kern.MapDef, flags: u64) u64, @ptrFromInt(22)); +pub const redirect = @as(*const fn (ifindex: u32, flags: u64) c_long, @ptrFromInt(23)); +pub const get_route_realm = @as(*const fn (skb: *kern.SkBuff) u32, @ptrFromInt(24)); +pub const perf_event_output = @as(*const fn (ctx: ?*anyopaque, map: *const kern.MapDef, flags: u64, data: ?*anyopaque, size: u64) c_long, @ptrFromInt(25)); +pub const skb_load_bytes = @as(*const fn (skb: ?*anyopaque, offset: u32, to: ?*anyopaque, len: u32) c_long, @ptrFromInt(26)); +pub const get_stackid = @as(*const fn (ctx: ?*anyopaque, map: *const kern.MapDef, flags: u64) c_long, @ptrFromInt(27)); // from and to point to __be32 -pub const csum_diff = @ptrFromInt(*const fn (from: *u32, from_size: u32, to: *u32, to_size: u32, seed: u32) i64, 28); -pub const skb_get_tunnel_opt = @ptrFromInt(*const fn (skb: *kern.SkBuff, opt: ?*anyopaque, size: u32) c_long, 29); -pub const skb_set_tunnel_opt = @ptrFromInt(*const fn (skb: *kern.SkBuff, opt: ?*anyopaque, size: u32) c_long, 30); +pub const csum_diff = @as(*const fn (from: *u32, from_size: u32, to: *u32, to_size: u32, seed: u32) i64, @ptrFromInt(28)); +pub const skb_get_tunnel_opt = @as(*const fn (skb: *kern.SkBuff, opt: ?*anyopaque, size: u32) c_long, @ptrFromInt(29)); +pub const skb_set_tunnel_opt = @as(*const fn (skb: *kern.SkBuff, opt: ?*anyopaque, size: u32) c_long, @ptrFromInt(30)); // proto is __be16 -pub const skb_change_proto = @ptrFromInt(*const fn (skb: *kern.SkBuff, proto: u16, flags: u64) c_long, 31); -pub const skb_change_type = @ptrFromInt(*const fn (skb: *kern.SkBuff, skb_type: u32) c_long, 32); -pub const skb_under_cgroup = @ptrFromInt(*const fn (skb: *kern.SkBuff, map: ?*const anyopaque, index: u32) c_long, 33); -pub const get_hash_recalc = @ptrFromInt(*const fn (skb: *kern.SkBuff) u32, 34); -pub const get_current_task = @ptrFromInt(*const fn () u64, 35); -pub const probe_write_user = @ptrFromInt(*const fn (dst: ?*anyopaque, src: ?*const anyopaque, len: u32) c_long, 36); -pub const current_task_under_cgroup = @ptrFromInt(*const fn (map: *const kern.MapDef, index: u32) c_long, 37); -pub const skb_change_tail = @ptrFromInt(*const fn (skb: *kern.SkBuff, len: u32, flags: u64) c_long, 38); -pub const skb_pull_data = @ptrFromInt(*const fn (skb: *kern.SkBuff, len: u32) c_long, 39); -pub const csum_update = @ptrFromInt(*const fn (skb: *kern.SkBuff, csum: u32) i64, 40); -pub const set_hash_invalid = @ptrFromInt(*const fn (skb: *kern.SkBuff) void, 41); -pub const get_numa_node_id = @ptrFromInt(*const fn () c_long, 42); -pub const skb_change_head = @ptrFromInt(*const fn (skb: *kern.SkBuff, len: u32, flags: u64) c_long, 43); -pub const xdp_adjust_head = @ptrFromInt(*const fn (xdp_md: *kern.XdpMd, delta: c_int) c_long, 44); -pub const probe_read_str = @ptrFromInt(*const fn (dst: ?*anyopaque, size: u32, unsafe_ptr: ?*const anyopaque) c_long, 45); -pub const get_socket_cookie = @ptrFromInt(*const fn (ctx: ?*anyopaque) u64, 46); -pub const get_socket_uid = @ptrFromInt(*const fn (skb: *kern.SkBuff) u32, 47); -pub const set_hash = @ptrFromInt(*const fn (skb: *kern.SkBuff, hash: u32) c_long, 48); -pub const setsockopt = @ptrFromInt(*const fn (bpf_socket: *kern.SockOps, level: c_int, optname: c_int, optval: ?*anyopaque, optlen: c_int) c_long, 49); -pub const skb_adjust_room = @ptrFromInt(*const fn (skb: *kern.SkBuff, len_diff: i32, mode: u32, flags: u64) c_long, 50); -pub const redirect_map = @ptrFromInt(*const fn (map: *const kern.MapDef, key: u32, flags: u64) c_long, 51); -pub const sk_redirect_map = @ptrFromInt(*const fn (skb: *kern.SkBuff, map: *const kern.MapDef, key: u32, flags: u64) c_long, 52); -pub const sock_map_update = @ptrFromInt(*const fn (skops: *kern.SockOps, map: *const kern.MapDef, key: ?*anyopaque, flags: u64) c_long, 53); -pub const xdp_adjust_meta = @ptrFromInt(*const fn (xdp_md: *kern.XdpMd, delta: c_int) c_long, 54); -pub const perf_event_read_value = @ptrFromInt(*const fn (map: *const kern.MapDef, flags: u64, buf: *kern.PerfEventValue, buf_size: u32) c_long, 55); -pub const perf_prog_read_value = @ptrFromInt(*const fn (ctx: *kern.PerfEventData, buf: *kern.PerfEventValue, buf_size: u32) c_long, 56); -pub const getsockopt = @ptrFromInt(*const fn (bpf_socket: ?*anyopaque, level: c_int, optname: c_int, optval: ?*anyopaque, optlen: c_int) c_long, 57); -pub const override_return = @ptrFromInt(*const fn (regs: *PtRegs, rc: u64) c_long, 58); -pub const sock_ops_cb_flags_set = @ptrFromInt(*const fn (bpf_sock: *kern.SockOps, argval: c_int) c_long, 59); -pub const msg_redirect_map = @ptrFromInt(*const fn (msg: *kern.SkMsgMd, map: *const kern.MapDef, key: u32, flags: u64) c_long, 60); -pub const msg_apply_bytes = @ptrFromInt(*const fn (msg: *kern.SkMsgMd, bytes: u32) c_long, 61); -pub const msg_cork_bytes = @ptrFromInt(*const fn (msg: *kern.SkMsgMd, bytes: u32) c_long, 62); -pub const msg_pull_data = @ptrFromInt(*const fn (msg: *kern.SkMsgMd, start: u32, end: u32, flags: u64) c_long, 63); -pub const bind = @ptrFromInt(*const fn (ctx: *kern.BpfSockAddr, addr: *kern.SockAddr, addr_len: c_int) c_long, 64); -pub const xdp_adjust_tail = @ptrFromInt(*const fn (xdp_md: *kern.XdpMd, delta: c_int) c_long, 65); -pub const skb_get_xfrm_state = @ptrFromInt(*const fn (skb: *kern.SkBuff, index: u32, xfrm_state: *kern.XfrmState, size: u32, flags: u64) c_long, 66); -pub const get_stack = @ptrFromInt(*const fn (ctx: ?*anyopaque, buf: ?*anyopaque, size: u32, flags: u64) c_long, 67); -pub const skb_load_bytes_relative = @ptrFromInt(*const fn (skb: ?*const anyopaque, offset: u32, to: ?*anyopaque, len: u32, start_header: u32) c_long, 68); -pub const fib_lookup = @ptrFromInt(*const fn (ctx: ?*anyopaque, params: *kern.FibLookup, plen: c_int, flags: u32) c_long, 69); -pub const sock_hash_update = @ptrFromInt(*const fn (skops: *kern.SockOps, map: *const kern.MapDef, key: ?*anyopaque, flags: u64) c_long, 70); -pub const msg_redirect_hash = @ptrFromInt(*const fn (msg: *kern.SkMsgMd, map: *const kern.MapDef, key: ?*anyopaque, flags: u64) c_long, 71); -pub const sk_redirect_hash = @ptrFromInt(*const fn (skb: *kern.SkBuff, map: *const kern.MapDef, key: ?*anyopaque, flags: u64) c_long, 72); -pub const lwt_push_encap = @ptrFromInt(*const fn (skb: *kern.SkBuff, typ: u32, hdr: ?*anyopaque, len: u32) c_long, 73); -pub const lwt_seg6_store_bytes = @ptrFromInt(*const fn (skb: *kern.SkBuff, offset: u32, from: ?*const anyopaque, len: u32) c_long, 74); -pub const lwt_seg6_adjust_srh = @ptrFromInt(*const fn (skb: *kern.SkBuff, offset: u32, delta: i32) c_long, 75); -pub const lwt_seg6_action = @ptrFromInt(*const fn (skb: *kern.SkBuff, action: u32, param: ?*anyopaque, param_len: u32) c_long, 76); -pub const rc_repeat = @ptrFromInt(*const fn (ctx: ?*anyopaque) c_long, 77); -pub const rc_keydown = @ptrFromInt(*const fn (ctx: ?*anyopaque, protocol: u32, scancode: u64, toggle: u32) c_long, 78); -pub const skb_cgroup_id = @ptrFromInt(*const fn (skb: *kern.SkBuff) u64, 79); -pub const get_current_cgroup_id = @ptrFromInt(*const fn () u64, 80); -pub const get_local_storage = @ptrFromInt(*const fn (map: ?*anyopaque, flags: u64) ?*anyopaque, 81); -pub const sk_select_reuseport = @ptrFromInt(*const fn (reuse: *kern.SkReusePortMd, map: *const kern.MapDef, key: ?*anyopaque, flags: u64) c_long, 82); -pub const skb_ancestor_cgroup_id = @ptrFromInt(*const fn (skb: *kern.SkBuff, ancestor_level: c_int) u64, 83); -pub const sk_lookup_tcp = @ptrFromInt(*const fn (ctx: ?*anyopaque, tuple: *kern.SockTuple, tuple_size: u32, netns: u64, flags: u64) ?*kern.Sock, 84); -pub const sk_lookup_udp = @ptrFromInt(*const fn (ctx: ?*anyopaque, tuple: *kern.SockTuple, tuple_size: u32, netns: u64, flags: u64) ?*kern.Sock, 85); -pub const sk_release = @ptrFromInt(*const fn (sock: *kern.Sock) c_long, 86); -pub const map_push_elem = @ptrFromInt(*const fn (map: *const kern.MapDef, value: ?*const anyopaque, flags: u64) c_long, 87); -pub const map_pop_elem = @ptrFromInt(*const fn (map: *const kern.MapDef, value: ?*anyopaque) c_long, 88); -pub const map_peek_elem = @ptrFromInt(*const fn (map: *const kern.MapDef, value: ?*anyopaque) c_long, 89); -pub const msg_push_data = @ptrFromInt(*const fn (msg: *kern.SkMsgMd, start: u32, len: u32, flags: u64) c_long, 90); -pub const msg_pop_data = @ptrFromInt(*const fn (msg: *kern.SkMsgMd, start: u32, len: u32, flags: u64) c_long, 91); -pub const rc_pointer_rel = @ptrFromInt(*const fn (ctx: ?*anyopaque, rel_x: i32, rel_y: i32) c_long, 92); -pub const spin_lock = @ptrFromInt(*const fn (lock: *kern.SpinLock) c_long, 93); -pub const spin_unlock = @ptrFromInt(*const fn (lock: *kern.SpinLock) c_long, 94); -pub const sk_fullsock = @ptrFromInt(*const fn (sk: *kern.Sock) ?*SkFullSock, 95); -pub const tcp_sock = @ptrFromInt(*const fn (sk: *kern.Sock) ?*kern.TcpSock, 96); -pub const skb_ecn_set_ce = @ptrFromInt(*const fn (skb: *kern.SkBuff) c_long, 97); -pub const get_listener_sock = @ptrFromInt(*const fn (sk: *kern.Sock) ?*kern.Sock, 98); -pub const skc_lookup_tcp = @ptrFromInt(*const fn (ctx: ?*anyopaque, tuple: *kern.SockTuple, tuple_size: u32, netns: u64, flags: u64) ?*kern.Sock, 99); -pub const tcp_check_syncookie = @ptrFromInt(*const fn (sk: *kern.Sock, iph: ?*anyopaque, iph_len: u32, th: *TcpHdr, th_len: u32) c_long, 100); -pub const sysctl_get_name = @ptrFromInt(*const fn (ctx: *kern.SysCtl, buf: ?*u8, buf_len: c_ulong, flags: u64) c_long, 101); -pub const sysctl_get_current_value = @ptrFromInt(*const fn (ctx: *kern.SysCtl, buf: ?*u8, buf_len: c_ulong) c_long, 102); -pub const sysctl_get_new_value = @ptrFromInt(*const fn (ctx: *kern.SysCtl, buf: ?*u8, buf_len: c_ulong) c_long, 103); -pub const sysctl_set_new_value = @ptrFromInt(*const fn (ctx: *kern.SysCtl, buf: ?*const u8, buf_len: c_ulong) c_long, 104); -pub const strtol = @ptrFromInt(*const fn (buf: *const u8, buf_len: c_ulong, flags: u64, res: *c_long) c_long, 105); -pub const strtoul = @ptrFromInt(*const fn (buf: *const u8, buf_len: c_ulong, flags: u64, res: *c_ulong) c_long, 106); -pub const sk_storage_get = @ptrFromInt(*const fn (map: *const kern.MapDef, sk: *kern.Sock, value: ?*anyopaque, flags: u64) ?*anyopaque, 107); -pub const sk_storage_delete = @ptrFromInt(*const fn (map: *const kern.MapDef, sk: *kern.Sock) c_long, 108); -pub const send_signal = @ptrFromInt(*const fn (sig: u32) c_long, 109); -pub const tcp_gen_syncookie = @ptrFromInt(*const fn (sk: *kern.Sock, iph: ?*anyopaque, iph_len: u32, th: *TcpHdr, th_len: u32) i64, 110); -pub const skb_output = @ptrFromInt(*const fn (ctx: ?*anyopaque, map: *const kern.MapDef, flags: u64, data: ?*anyopaque, size: u64) c_long, 111); -pub const probe_read_user = @ptrFromInt(*const fn (dst: ?*anyopaque, size: u32, unsafe_ptr: ?*const anyopaque) c_long, 112); -pub const probe_read_kernel = @ptrFromInt(*const fn (dst: ?*anyopaque, size: u32, unsafe_ptr: ?*const anyopaque) c_long, 113); -pub const probe_read_user_str = @ptrFromInt(*const fn (dst: ?*anyopaque, size: u32, unsafe_ptr: ?*const anyopaque) c_long, 114); -pub const probe_read_kernel_str = @ptrFromInt(*const fn (dst: ?*anyopaque, size: u32, unsafe_ptr: ?*const anyopaque) c_long, 115); -pub const tcp_send_ack = @ptrFromInt(*const fn (tp: ?*anyopaque, rcv_nxt: u32) c_long, 116); -pub const send_signal_thread = @ptrFromInt(*const fn (sig: u32) c_long, 117); -pub const jiffies64 = @ptrFromInt(*const fn () u64, 118); -pub const read_branch_records = @ptrFromInt(*const fn (ctx: *kern.PerfEventData, buf: ?*anyopaque, size: u32, flags: u64) c_long, 119); -pub const get_ns_current_pid_tgid = @ptrFromInt(*const fn (dev: u64, ino: u64, nsdata: *kern.PidNsInfo, size: u32) c_long, 120); -pub const xdp_output = @ptrFromInt(*const fn (ctx: ?*anyopaque, map: *const kern.MapDef, flags: u64, data: ?*anyopaque, size: u64) c_long, 121); -pub const get_netns_cookie = @ptrFromInt(*const fn (ctx: ?*anyopaque) u64, 122); -pub const get_current_ancestor_cgroup_id = @ptrFromInt(*const fn (ancestor_level: c_int) u64, 123); -pub const sk_assign = @ptrFromInt(*const fn (skb: *kern.SkBuff, sk: *kern.Sock, flags: u64) c_long, 124); -pub const ktime_get_boot_ns = @ptrFromInt(*const fn () u64, 125); -pub const seq_printf = @ptrFromInt(*const fn (m: *kern.SeqFile, fmt: ?*const u8, fmt_size: u32, data: ?*const anyopaque, data_len: u32) c_long, 126); -pub const seq_write = @ptrFromInt(*const fn (m: *kern.SeqFile, data: ?*const u8, len: u32) c_long, 127); -pub const sk_cgroup_id = @ptrFromInt(*const fn (sk: *kern.BpfSock) u64, 128); -pub const sk_ancestor_cgroup_id = @ptrFromInt(*const fn (sk: *kern.BpfSock, ancestor_level: c_long) u64, 129); -pub const ringbuf_output = @ptrFromInt(*const fn (ringbuf: ?*anyopaque, data: ?*anyopaque, size: u64, flags: u64) c_long, 130); -pub const ringbuf_reserve = @ptrFromInt(*const fn (ringbuf: ?*anyopaque, size: u64, flags: u64) ?*anyopaque, 131); -pub const ringbuf_submit = @ptrFromInt(*const fn (data: ?*anyopaque, flags: u64) void, 132); -pub const ringbuf_discard = @ptrFromInt(*const fn (data: ?*anyopaque, flags: u64) void, 133); -pub const ringbuf_query = @ptrFromInt(*const fn (ringbuf: ?*anyopaque, flags: u64) u64, 134); -pub const csum_level = @ptrFromInt(*const fn (skb: *kern.SkBuff, level: u64) c_long, 135); -pub const skc_to_tcp6_sock = @ptrFromInt(*const fn (sk: ?*anyopaque) ?*kern.Tcp6Sock, 136); -pub const skc_to_tcp_sock = @ptrFromInt(*const fn (sk: ?*anyopaque) ?*kern.TcpSock, 137); -pub const skc_to_tcp_timewait_sock = @ptrFromInt(*const fn (sk: ?*anyopaque) ?*kern.TcpTimewaitSock, 138); -pub const skc_to_tcp_request_sock = @ptrFromInt(*const fn (sk: ?*anyopaque) ?*kern.TcpRequestSock, 139); -pub const skc_to_udp6_sock = @ptrFromInt(*const fn (sk: ?*anyopaque) ?*kern.Udp6Sock, 140); -pub const get_task_stack = @ptrFromInt(*const fn (task: ?*anyopaque, buf: ?*anyopaque, size: u32, flags: u64) c_long, 141); +pub const skb_change_proto = @as(*const fn (skb: *kern.SkBuff, proto: u16, flags: u64) c_long, @ptrFromInt(31)); +pub const skb_change_type = @as(*const fn (skb: *kern.SkBuff, skb_type: u32) c_long, @ptrFromInt(32)); +pub const skb_under_cgroup = @as(*const fn (skb: *kern.SkBuff, map: ?*const anyopaque, index: u32) c_long, @ptrFromInt(33)); +pub const get_hash_recalc = @as(*const fn (skb: *kern.SkBuff) u32, @ptrFromInt(34)); +pub const get_current_task = @as(*const fn () u64, @ptrFromInt(35)); +pub const probe_write_user = @as(*const fn (dst: ?*anyopaque, src: ?*const anyopaque, len: u32) c_long, @ptrFromInt(36)); +pub const current_task_under_cgroup = @as(*const fn (map: *const kern.MapDef, index: u32) c_long, @ptrFromInt(37)); +pub const skb_change_tail = @as(*const fn (skb: *kern.SkBuff, len: u32, flags: u64) c_long, @ptrFromInt(38)); +pub const skb_pull_data = @as(*const fn (skb: *kern.SkBuff, len: u32) c_long, @ptrFromInt(39)); +pub const csum_update = @as(*const fn (skb: *kern.SkBuff, csum: u32) i64, @ptrFromInt(40)); +pub const set_hash_invalid = @as(*const fn (skb: *kern.SkBuff) void, @ptrFromInt(41)); +pub const get_numa_node_id = @as(*const fn () c_long, @ptrFromInt(42)); +pub const skb_change_head = @as(*const fn (skb: *kern.SkBuff, len: u32, flags: u64) c_long, @ptrFromInt(43)); +pub const xdp_adjust_head = @as(*const fn (xdp_md: *kern.XdpMd, delta: c_int) c_long, @ptrFromInt(44)); +pub const probe_read_str = @as(*const fn (dst: ?*anyopaque, size: u32, unsafe_ptr: ?*const anyopaque) c_long, @ptrFromInt(45)); +pub const get_socket_cookie = @as(*const fn (ctx: ?*anyopaque) u64, @ptrFromInt(46)); +pub const get_socket_uid = @as(*const fn (skb: *kern.SkBuff) u32, @ptrFromInt(47)); +pub const set_hash = @as(*const fn (skb: *kern.SkBuff, hash: u32) c_long, @ptrFromInt(48)); +pub const setsockopt = @as(*const fn (bpf_socket: *kern.SockOps, level: c_int, optname: c_int, optval: ?*anyopaque, optlen: c_int) c_long, @ptrFromInt(49)); +pub const skb_adjust_room = @as(*const fn (skb: *kern.SkBuff, len_diff: i32, mode: u32, flags: u64) c_long, @ptrFromInt(50)); +pub const redirect_map = @as(*const fn (map: *const kern.MapDef, key: u32, flags: u64) c_long, @ptrFromInt(51)); +pub const sk_redirect_map = @as(*const fn (skb: *kern.SkBuff, map: *const kern.MapDef, key: u32, flags: u64) c_long, @ptrFromInt(52)); +pub const sock_map_update = @as(*const fn (skops: *kern.SockOps, map: *const kern.MapDef, key: ?*anyopaque, flags: u64) c_long, @ptrFromInt(53)); +pub const xdp_adjust_meta = @as(*const fn (xdp_md: *kern.XdpMd, delta: c_int) c_long, @ptrFromInt(54)); +pub const perf_event_read_value = @as(*const fn (map: *const kern.MapDef, flags: u64, buf: *kern.PerfEventValue, buf_size: u32) c_long, @ptrFromInt(55)); +pub const perf_prog_read_value = @as(*const fn (ctx: *kern.PerfEventData, buf: *kern.PerfEventValue, buf_size: u32) c_long, @ptrFromInt(56)); +pub const getsockopt = @as(*const fn (bpf_socket: ?*anyopaque, level: c_int, optname: c_int, optval: ?*anyopaque, optlen: c_int) c_long, @ptrFromInt(57)); +pub const override_return = @as(*const fn (regs: *PtRegs, rc: u64) c_long, @ptrFromInt(58)); +pub const sock_ops_cb_flags_set = @as(*const fn (bpf_sock: *kern.SockOps, argval: c_int) c_long, @ptrFromInt(59)); +pub const msg_redirect_map = @as(*const fn (msg: *kern.SkMsgMd, map: *const kern.MapDef, key: u32, flags: u64) c_long, @ptrFromInt(60)); +pub const msg_apply_bytes = @as(*const fn (msg: *kern.SkMsgMd, bytes: u32) c_long, @ptrFromInt(61)); +pub const msg_cork_bytes = @as(*const fn (msg: *kern.SkMsgMd, bytes: u32) c_long, @ptrFromInt(62)); +pub const msg_pull_data = @as(*const fn (msg: *kern.SkMsgMd, start: u32, end: u32, flags: u64) c_long, @ptrFromInt(63)); +pub const bind = @as(*const fn (ctx: *kern.BpfSockAddr, addr: *kern.SockAddr, addr_len: c_int) c_long, @ptrFromInt(64)); +pub const xdp_adjust_tail = @as(*const fn (xdp_md: *kern.XdpMd, delta: c_int) c_long, @ptrFromInt(65)); +pub const skb_get_xfrm_state = @as(*const fn (skb: *kern.SkBuff, index: u32, xfrm_state: *kern.XfrmState, size: u32, flags: u64) c_long, @ptrFromInt(66)); +pub const get_stack = @as(*const fn (ctx: ?*anyopaque, buf: ?*anyopaque, size: u32, flags: u64) c_long, @ptrFromInt(67)); +pub const skb_load_bytes_relative = @as(*const fn (skb: ?*const anyopaque, offset: u32, to: ?*anyopaque, len: u32, start_header: u32) c_long, @ptrFromInt(68)); +pub const fib_lookup = @as(*const fn (ctx: ?*anyopaque, params: *kern.FibLookup, plen: c_int, flags: u32) c_long, @ptrFromInt(69)); +pub const sock_hash_update = @as(*const fn (skops: *kern.SockOps, map: *const kern.MapDef, key: ?*anyopaque, flags: u64) c_long, @ptrFromInt(70)); +pub const msg_redirect_hash = @as(*const fn (msg: *kern.SkMsgMd, map: *const kern.MapDef, key: ?*anyopaque, flags: u64) c_long, @ptrFromInt(71)); +pub const sk_redirect_hash = @as(*const fn (skb: *kern.SkBuff, map: *const kern.MapDef, key: ?*anyopaque, flags: u64) c_long, @ptrFromInt(72)); +pub const lwt_push_encap = @as(*const fn (skb: *kern.SkBuff, typ: u32, hdr: ?*anyopaque, len: u32) c_long, @ptrFromInt(73)); +pub const lwt_seg6_store_bytes = @as(*const fn (skb: *kern.SkBuff, offset: u32, from: ?*const anyopaque, len: u32) c_long, @ptrFromInt(74)); +pub const lwt_seg6_adjust_srh = @as(*const fn (skb: *kern.SkBuff, offset: u32, delta: i32) c_long, @ptrFromInt(75)); +pub const lwt_seg6_action = @as(*const fn (skb: *kern.SkBuff, action: u32, param: ?*anyopaque, param_len: u32) c_long, @ptrFromInt(76)); +pub const rc_repeat = @as(*const fn (ctx: ?*anyopaque) c_long, @ptrFromInt(77)); +pub const rc_keydown = @as(*const fn (ctx: ?*anyopaque, protocol: u32, scancode: u64, toggle: u32) c_long, @ptrFromInt(78)); +pub const skb_cgroup_id = @as(*const fn (skb: *kern.SkBuff) u64, @ptrFromInt(79)); +pub const get_current_cgroup_id = @as(*const fn () u64, @ptrFromInt(80)); +pub const get_local_storage = @as(*const fn (map: ?*anyopaque, flags: u64) ?*anyopaque, @ptrFromInt(81)); +pub const sk_select_reuseport = @as(*const fn (reuse: *kern.SkReusePortMd, map: *const kern.MapDef, key: ?*anyopaque, flags: u64) c_long, @ptrFromInt(82)); +pub const skb_ancestor_cgroup_id = @as(*const fn (skb: *kern.SkBuff, ancestor_level: c_int) u64, @ptrFromInt(83)); +pub const sk_lookup_tcp = @as(*const fn (ctx: ?*anyopaque, tuple: *kern.SockTuple, tuple_size: u32, netns: u64, flags: u64) ?*kern.Sock, @ptrFromInt(84)); +pub const sk_lookup_udp = @as(*const fn (ctx: ?*anyopaque, tuple: *kern.SockTuple, tuple_size: u32, netns: u64, flags: u64) ?*kern.Sock, @ptrFromInt(85)); +pub const sk_release = @as(*const fn (sock: *kern.Sock) c_long, @ptrFromInt(86)); +pub const map_push_elem = @as(*const fn (map: *const kern.MapDef, value: ?*const anyopaque, flags: u64) c_long, @ptrFromInt(87)); +pub const map_pop_elem = @as(*const fn (map: *const kern.MapDef, value: ?*anyopaque) c_long, @ptrFromInt(88)); +pub const map_peek_elem = @as(*const fn (map: *const kern.MapDef, value: ?*anyopaque) c_long, @ptrFromInt(89)); +pub const msg_push_data = @as(*const fn (msg: *kern.SkMsgMd, start: u32, len: u32, flags: u64) c_long, @ptrFromInt(90)); +pub const msg_pop_data = @as(*const fn (msg: *kern.SkMsgMd, start: u32, len: u32, flags: u64) c_long, @ptrFromInt(91)); +pub const rc_pointer_rel = @as(*const fn (ctx: ?*anyopaque, rel_x: i32, rel_y: i32) c_long, @ptrFromInt(92)); +pub const spin_lock = @as(*const fn (lock: *kern.SpinLock) c_long, @ptrFromInt(93)); +pub const spin_unlock = @as(*const fn (lock: *kern.SpinLock) c_long, @ptrFromInt(94)); +pub const sk_fullsock = @as(*const fn (sk: *kern.Sock) ?*SkFullSock, @ptrFromInt(95)); +pub const tcp_sock = @as(*const fn (sk: *kern.Sock) ?*kern.TcpSock, @ptrFromInt(96)); +pub const skb_ecn_set_ce = @as(*const fn (skb: *kern.SkBuff) c_long, @ptrFromInt(97)); +pub const get_listener_sock = @as(*const fn (sk: *kern.Sock) ?*kern.Sock, @ptrFromInt(98)); +pub const skc_lookup_tcp = @as(*const fn (ctx: ?*anyopaque, tuple: *kern.SockTuple, tuple_size: u32, netns: u64, flags: u64) ?*kern.Sock, @ptrFromInt(99)); +pub const tcp_check_syncookie = @as(*const fn (sk: *kern.Sock, iph: ?*anyopaque, iph_len: u32, th: *TcpHdr, th_len: u32) c_long, @ptrFromInt(100)); +pub const sysctl_get_name = @as(*const fn (ctx: *kern.SysCtl, buf: ?*u8, buf_len: c_ulong, flags: u64) c_long, @ptrFromInt(101)); +pub const sysctl_get_current_value = @as(*const fn (ctx: *kern.SysCtl, buf: ?*u8, buf_len: c_ulong) c_long, @ptrFromInt(102)); +pub const sysctl_get_new_value = @as(*const fn (ctx: *kern.SysCtl, buf: ?*u8, buf_len: c_ulong) c_long, @ptrFromInt(103)); +pub const sysctl_set_new_value = @as(*const fn (ctx: *kern.SysCtl, buf: ?*const u8, buf_len: c_ulong) c_long, @ptrFromInt(104)); +pub const strtol = @as(*const fn (buf: *const u8, buf_len: c_ulong, flags: u64, res: *c_long) c_long, @ptrFromInt(105)); +pub const strtoul = @as(*const fn (buf: *const u8, buf_len: c_ulong, flags: u64, res: *c_ulong) c_long, @ptrFromInt(106)); +pub const sk_storage_get = @as(*const fn (map: *const kern.MapDef, sk: *kern.Sock, value: ?*anyopaque, flags: u64) ?*anyopaque, @ptrFromInt(107)); +pub const sk_storage_delete = @as(*const fn (map: *const kern.MapDef, sk: *kern.Sock) c_long, @ptrFromInt(108)); +pub const send_signal = @as(*const fn (sig: u32) c_long, @ptrFromInt(109)); +pub const tcp_gen_syncookie = @as(*const fn (sk: *kern.Sock, iph: ?*anyopaque, iph_len: u32, th: *TcpHdr, th_len: u32) i64, @ptrFromInt(110)); +pub const skb_output = @as(*const fn (ctx: ?*anyopaque, map: *const kern.MapDef, flags: u64, data: ?*anyopaque, size: u64) c_long, @ptrFromInt(111)); +pub const probe_read_user = @as(*const fn (dst: ?*anyopaque, size: u32, unsafe_ptr: ?*const anyopaque) c_long, @ptrFromInt(112)); +pub const probe_read_kernel = @as(*const fn (dst: ?*anyopaque, size: u32, unsafe_ptr: ?*const anyopaque) c_long, @ptrFromInt(113)); +pub const probe_read_user_str = @as(*const fn (dst: ?*anyopaque, size: u32, unsafe_ptr: ?*const anyopaque) c_long, @ptrFromInt(114)); +pub const probe_read_kernel_str = @as(*const fn (dst: ?*anyopaque, size: u32, unsafe_ptr: ?*const anyopaque) c_long, @ptrFromInt(115)); +pub const tcp_send_ack = @as(*const fn (tp: ?*anyopaque, rcv_nxt: u32) c_long, @ptrFromInt(116)); +pub const send_signal_thread = @as(*const fn (sig: u32) c_long, @ptrFromInt(117)); +pub const jiffies64 = @as(*const fn () u64, @ptrFromInt(118)); +pub const read_branch_records = @as(*const fn (ctx: *kern.PerfEventData, buf: ?*anyopaque, size: u32, flags: u64) c_long, @ptrFromInt(119)); +pub const get_ns_current_pid_tgid = @as(*const fn (dev: u64, ino: u64, nsdata: *kern.PidNsInfo, size: u32) c_long, @ptrFromInt(120)); +pub const xdp_output = @as(*const fn (ctx: ?*anyopaque, map: *const kern.MapDef, flags: u64, data: ?*anyopaque, size: u64) c_long, @ptrFromInt(121)); +pub const get_netns_cookie = @as(*const fn (ctx: ?*anyopaque) u64, @ptrFromInt(122)); +pub const get_current_ancestor_cgroup_id = @as(*const fn (ancestor_level: c_int) u64, @ptrFromInt(123)); +pub const sk_assign = @as(*const fn (skb: *kern.SkBuff, sk: *kern.Sock, flags: u64) c_long, @ptrFromInt(124)); +pub const ktime_get_boot_ns = @as(*const fn () u64, @ptrFromInt(125)); +pub const seq_printf = @as(*const fn (m: *kern.SeqFile, fmt: ?*const u8, fmt_size: u32, data: ?*const anyopaque, data_len: u32) c_long, @ptrFromInt(126)); +pub const seq_write = @as(*const fn (m: *kern.SeqFile, data: ?*const u8, len: u32) c_long, @ptrFromInt(127)); +pub const sk_cgroup_id = @as(*const fn (sk: *kern.BpfSock) u64, @ptrFromInt(128)); +pub const sk_ancestor_cgroup_id = @as(*const fn (sk: *kern.BpfSock, ancestor_level: c_long) u64, @ptrFromInt(129)); +pub const ringbuf_output = @as(*const fn (ringbuf: ?*anyopaque, data: ?*anyopaque, size: u64, flags: u64) c_long, @ptrFromInt(130)); +pub const ringbuf_reserve = @as(*const fn (ringbuf: ?*anyopaque, size: u64, flags: u64) ?*anyopaque, @ptrFromInt(131)); +pub const ringbuf_submit = @as(*const fn (data: ?*anyopaque, flags: u64) void, @ptrFromInt(132)); +pub const ringbuf_discard = @as(*const fn (data: ?*anyopaque, flags: u64) void, @ptrFromInt(133)); +pub const ringbuf_query = @as(*const fn (ringbuf: ?*anyopaque, flags: u64) u64, @ptrFromInt(134)); +pub const csum_level = @as(*const fn (skb: *kern.SkBuff, level: u64) c_long, @ptrFromInt(135)); +pub const skc_to_tcp6_sock = @as(*const fn (sk: ?*anyopaque) ?*kern.Tcp6Sock, @ptrFromInt(136)); +pub const skc_to_tcp_sock = @as(*const fn (sk: ?*anyopaque) ?*kern.TcpSock, @ptrFromInt(137)); +pub const skc_to_tcp_timewait_sock = @as(*const fn (sk: ?*anyopaque) ?*kern.TcpTimewaitSock, @ptrFromInt(138)); +pub const skc_to_tcp_request_sock = @as(*const fn (sk: ?*anyopaque) ?*kern.TcpRequestSock, @ptrFromInt(139)); +pub const skc_to_udp6_sock = @as(*const fn (sk: ?*anyopaque) ?*kern.Udp6Sock, @ptrFromInt(140)); +pub const get_task_stack = @as(*const fn (task: ?*anyopaque, buf: ?*anyopaque, size: u32, flags: u64) c_long, @ptrFromInt(141)); diff --git a/lib/std/os/linux/io_uring.zig b/lib/std/os/linux/io_uring.zig index 875138cf4f..df8cd20773 100644 --- a/lib/std/os/linux/io_uring.zig +++ b/lib/std/os/linux/io_uring.zig @@ -60,7 +60,7 @@ pub const IO_Uring = struct { .NOSYS => return error.SystemOutdated, else => |errno| return os.unexpectedErrno(errno), } - const fd = @intCast(os.fd_t, res); + const fd = @as(os.fd_t, @intCast(res)); assert(fd >= 0); errdefer os.close(fd); @@ -198,7 +198,7 @@ pub const IO_Uring = struct { .INTR => return error.SignalInterrupt, else => |errno| return os.unexpectedErrno(errno), } - return @intCast(u32, res); + return @as(u32, @intCast(res)); } /// Sync internal state with kernel ring state on the SQ side. @@ -937,8 +937,8 @@ pub const IO_Uring = struct { const res = linux.io_uring_register( self.fd, .REGISTER_FILES, - @ptrCast(*const anyopaque, fds.ptr), - @intCast(u32, fds.len), + @as(*const anyopaque, @ptrCast(fds.ptr)), + @as(u32, @intCast(fds.len)), ); try handle_registration_result(res); } @@ -968,8 +968,8 @@ pub const IO_Uring = struct { const res = linux.io_uring_register( self.fd, .REGISTER_FILES_UPDATE, - @ptrCast(*const anyopaque, &update), - @intCast(u32, fds.len), + @as(*const anyopaque, @ptrCast(&update)), + @as(u32, @intCast(fds.len)), ); try handle_registration_result(res); } @@ -982,7 +982,7 @@ pub const IO_Uring = struct { const res = linux.io_uring_register( self.fd, .REGISTER_EVENTFD, - @ptrCast(*const anyopaque, &fd), + @as(*const anyopaque, @ptrCast(&fd)), 1, ); try handle_registration_result(res); @@ -997,7 +997,7 @@ pub const IO_Uring = struct { const res = linux.io_uring_register( self.fd, .REGISTER_EVENTFD_ASYNC, - @ptrCast(*const anyopaque, &fd), + @as(*const anyopaque, @ptrCast(&fd)), 1, ); try handle_registration_result(res); @@ -1022,7 +1022,7 @@ pub const IO_Uring = struct { self.fd, .REGISTER_BUFFERS, buffers.ptr, - @intCast(u32, buffers.len), + @as(u32, @intCast(buffers.len)), ); try handle_registration_result(res); } @@ -1122,20 +1122,17 @@ pub const SubmissionQueue = struct { errdefer os.munmap(mmap_sqes); assert(mmap_sqes.len == size_sqes); - const array = @ptrCast([*]u32, @alignCast(@alignOf(u32), &mmap[p.sq_off.array])); - const sqes = @ptrCast([*]linux.io_uring_sqe, @alignCast(@alignOf(linux.io_uring_sqe), &mmap_sqes[0])); + const array: [*]u32 = @ptrCast(@alignCast(&mmap[p.sq_off.array])); + const sqes: [*]linux.io_uring_sqe = @ptrCast(@alignCast(&mmap_sqes[0])); // We expect the kernel copies p.sq_entries to the u32 pointed to by p.sq_off.ring_entries, // see https://github.com/torvalds/linux/blob/v5.8/fs/io_uring.c#L7843-L7844. - assert( - p.sq_entries == - @ptrCast(*u32, @alignCast(@alignOf(u32), &mmap[p.sq_off.ring_entries])).*, - ); + assert(p.sq_entries == @as(*u32, @ptrCast(@alignCast(&mmap[p.sq_off.ring_entries]))).*); return SubmissionQueue{ - .head = @ptrCast(*u32, @alignCast(@alignOf(u32), &mmap[p.sq_off.head])), - .tail = @ptrCast(*u32, @alignCast(@alignOf(u32), &mmap[p.sq_off.tail])), - .mask = @ptrCast(*u32, @alignCast(@alignOf(u32), &mmap[p.sq_off.ring_mask])).*, - .flags = @ptrCast(*u32, @alignCast(@alignOf(u32), &mmap[p.sq_off.flags])), - .dropped = @ptrCast(*u32, @alignCast(@alignOf(u32), &mmap[p.sq_off.dropped])), + .head = @ptrCast(@alignCast(&mmap[p.sq_off.head])), + .tail = @ptrCast(@alignCast(&mmap[p.sq_off.tail])), + .mask = @as(*u32, @ptrCast(@alignCast(&mmap[p.sq_off.ring_mask]))).*, + .flags = @ptrCast(@alignCast(&mmap[p.sq_off.flags])), + .dropped = @ptrCast(@alignCast(&mmap[p.sq_off.dropped])), .array = array[0..p.sq_entries], .sqes = sqes[0..p.sq_entries], .mmap = mmap, @@ -1160,17 +1157,13 @@ pub const CompletionQueue = struct { assert(fd >= 0); assert((p.features & linux.IORING_FEAT_SINGLE_MMAP) != 0); const mmap = sq.mmap; - const cqes = @ptrCast( - [*]linux.io_uring_cqe, - @alignCast(@alignOf(linux.io_uring_cqe), &mmap[p.cq_off.cqes]), - ); - assert(p.cq_entries == - @ptrCast(*u32, @alignCast(@alignOf(u32), &mmap[p.cq_off.ring_entries])).*); + const cqes: [*]linux.io_uring_cqe = @ptrCast(@alignCast(&mmap[p.cq_off.cqes])); + assert(p.cq_entries == @as(*u32, @ptrCast(@alignCast(&mmap[p.cq_off.ring_entries]))).*); return CompletionQueue{ - .head = @ptrCast(*u32, @alignCast(@alignOf(u32), &mmap[p.cq_off.head])), - .tail = @ptrCast(*u32, @alignCast(@alignOf(u32), &mmap[p.cq_off.tail])), - .mask = @ptrCast(*u32, @alignCast(@alignOf(u32), &mmap[p.cq_off.ring_mask])).*, - .overflow = @ptrCast(*u32, @alignCast(@alignOf(u32), &mmap[p.cq_off.overflow])), + .head = @ptrCast(@alignCast(&mmap[p.cq_off.head])), + .tail = @ptrCast(@alignCast(&mmap[p.cq_off.tail])), + .mask = @as(*u32, @ptrCast(@alignCast(&mmap[p.cq_off.ring_mask]))).*, + .overflow = @ptrCast(@alignCast(&mmap[p.cq_off.overflow])), .cqes = cqes[0..p.cq_entries], }; } @@ -1233,7 +1226,7 @@ pub fn io_uring_prep_rw( .fd = fd, .off = offset, .addr = addr, - .len = @intCast(u32, len), + .len = @as(u32, @intCast(len)), .rw_flags = 0, .user_data = 0, .buf_index = 0, @@ -1319,7 +1312,7 @@ pub fn io_uring_prep_epoll_ctl( op: u32, ev: ?*linux.epoll_event, ) void { - io_uring_prep_rw(.EPOLL_CTL, sqe, epfd, @intFromPtr(ev), op, @intCast(u64, fd)); + io_uring_prep_rw(.EPOLL_CTL, sqe, epfd, @intFromPtr(ev), op, @as(u64, @intCast(fd))); } pub fn io_uring_prep_recv(sqe: *linux.io_uring_sqe, fd: os.fd_t, buffer: []u8, flags: u32) void { @@ -1459,7 +1452,7 @@ pub fn io_uring_prep_fallocate( .fd = fd, .off = offset, .addr = len, - .len = @intCast(u32, mode), + .len = @as(u32, @intCast(mode)), .rw_flags = 0, .user_data = 0, .buf_index = 0, @@ -1514,7 +1507,7 @@ pub fn io_uring_prep_renameat( 0, @intFromPtr(new_path), ); - sqe.len = @bitCast(u32, new_dir_fd); + sqe.len = @as(u32, @bitCast(new_dir_fd)); sqe.rw_flags = flags; } @@ -1569,7 +1562,7 @@ pub fn io_uring_prep_linkat( 0, @intFromPtr(new_path), ); - sqe.len = @bitCast(u32, new_dir_fd); + sqe.len = @as(u32, @bitCast(new_dir_fd)); sqe.rw_flags = flags; } @@ -1582,8 +1575,8 @@ pub fn io_uring_prep_provide_buffers( buffer_id: usize, ) void { const ptr = @intFromPtr(buffers); - io_uring_prep_rw(.PROVIDE_BUFFERS, sqe, @intCast(i32, num), ptr, buffer_len, buffer_id); - sqe.buf_index = @intCast(u16, group_id); + io_uring_prep_rw(.PROVIDE_BUFFERS, sqe, @as(i32, @intCast(num)), ptr, buffer_len, buffer_id); + sqe.buf_index = @as(u16, @intCast(group_id)); } pub fn io_uring_prep_remove_buffers( @@ -1591,8 +1584,8 @@ pub fn io_uring_prep_remove_buffers( num: usize, group_id: usize, ) void { - io_uring_prep_rw(.REMOVE_BUFFERS, sqe, @intCast(i32, num), 0, 0, 0); - sqe.buf_index = @intCast(u16, group_id); + io_uring_prep_rw(.REMOVE_BUFFERS, sqe, @as(i32, @intCast(num)), 0, 0, 0); + sqe.buf_index = @as(u16, @intCast(group_id)); } test "structs/offsets/entries" { @@ -1886,12 +1879,12 @@ test "write_fixed/read_fixed" { try testing.expectEqual(linux.io_uring_cqe{ .user_data = 0x45454545, - .res = @intCast(i32, buffers[0].iov_len), + .res = @as(i32, @intCast(buffers[0].iov_len)), .flags = 0, }, cqe_write); try testing.expectEqual(linux.io_uring_cqe{ .user_data = 0x12121212, - .res = @intCast(i32, buffers[1].iov_len), + .res = @as(i32, @intCast(buffers[1].iov_len)), .flags = 0, }, cqe_read); @@ -2145,7 +2138,7 @@ test "timeout (after a relative time)" { }, cqe); // Tests should not depend on timings: skip test if outside margin. - if (!std.math.approxEqAbs(f64, ms, @floatFromInt(f64, stopped - started), margin)) return error.SkipZigTest; + if (!std.math.approxEqAbs(f64, ms, @as(f64, @floatFromInt(stopped - started)), margin)) return error.SkipZigTest; } test "timeout (after a number of completions)" { @@ -2637,7 +2630,7 @@ test "renameat" { ); try testing.expectEqual(linux.IORING_OP.RENAMEAT, sqe.opcode); try testing.expectEqual(@as(i32, tmp.dir.fd), sqe.fd); - try testing.expectEqual(@as(i32, tmp.dir.fd), @bitCast(i32, sqe.len)); + try testing.expectEqual(@as(i32, tmp.dir.fd), @as(i32, @bitCast(sqe.len))); try testing.expectEqual(@as(u32, 1), try ring.submit()); const cqe = try ring.copy_cqe(); @@ -2850,7 +2843,7 @@ test "linkat" { ); try testing.expectEqual(linux.IORING_OP.LINKAT, sqe.opcode); try testing.expectEqual(@as(i32, tmp.dir.fd), sqe.fd); - try testing.expectEqual(@as(i32, tmp.dir.fd), @bitCast(i32, sqe.len)); + try testing.expectEqual(@as(i32, tmp.dir.fd), @as(i32, @bitCast(sqe.len))); try testing.expectEqual(@as(u32, 1), try ring.submit()); const cqe = try ring.copy_cqe(); @@ -2898,7 +2891,7 @@ test "provide_buffers: read" { // Provide 4 buffers { - const sqe = try ring.provide_buffers(0xcccccccc, @ptrCast([*]u8, &buffers), buffer_len, buffers.len, group_id, buffer_id); + const sqe = try ring.provide_buffers(0xcccccccc, @as([*]u8, @ptrCast(&buffers)), buffer_len, buffers.len, group_id, buffer_id); try testing.expectEqual(linux.IORING_OP.PROVIDE_BUFFERS, sqe.opcode); try testing.expectEqual(@as(i32, buffers.len), sqe.fd); try testing.expectEqual(@as(u32, buffers[0].len), sqe.len); @@ -2939,7 +2932,7 @@ test "provide_buffers: read" { try testing.expectEqual(@as(i32, buffer_len), cqe.res); try testing.expectEqual(@as(u64, 0xdededede), cqe.user_data); - try testing.expectEqualSlices(u8, &([_]u8{0} ** buffer_len), buffers[used_buffer_id][0..@intCast(usize, cqe.res)]); + try testing.expectEqualSlices(u8, &([_]u8{0} ** buffer_len), buffers[used_buffer_id][0..@as(usize, @intCast(cqe.res))]); } // This read should fail @@ -2971,7 +2964,7 @@ test "provide_buffers: read" { const reprovided_buffer_id = 2; { - _ = try ring.provide_buffers(0xabababab, @ptrCast([*]u8, &buffers[reprovided_buffer_id]), buffer_len, 1, group_id, reprovided_buffer_id); + _ = try ring.provide_buffers(0xabababab, @as([*]u8, @ptrCast(&buffers[reprovided_buffer_id])), buffer_len, 1, group_id, reprovided_buffer_id); try testing.expectEqual(@as(u32, 1), try ring.submit()); const cqe = try ring.copy_cqe(); @@ -3003,7 +2996,7 @@ test "provide_buffers: read" { try testing.expectEqual(used_buffer_id, reprovided_buffer_id); try testing.expectEqual(@as(i32, buffer_len), cqe.res); try testing.expectEqual(@as(u64, 0xdfdfdfdf), cqe.user_data); - try testing.expectEqualSlices(u8, &([_]u8{0} ** buffer_len), buffers[used_buffer_id][0..@intCast(usize, cqe.res)]); + try testing.expectEqualSlices(u8, &([_]u8{0} ** buffer_len), buffers[used_buffer_id][0..@as(usize, @intCast(cqe.res))]); } } @@ -3030,7 +3023,7 @@ test "remove_buffers" { // Provide 4 buffers { - _ = try ring.provide_buffers(0xcccccccc, @ptrCast([*]u8, &buffers), buffer_len, buffers.len, group_id, buffer_id); + _ = try ring.provide_buffers(0xcccccccc, @as([*]u8, @ptrCast(&buffers)), buffer_len, buffers.len, group_id, buffer_id); try testing.expectEqual(@as(u32, 1), try ring.submit()); const cqe = try ring.copy_cqe(); @@ -3076,7 +3069,7 @@ test "remove_buffers" { try testing.expect(used_buffer_id >= 0 and used_buffer_id < 4); try testing.expectEqual(@as(i32, buffer_len), cqe.res); try testing.expectEqual(@as(u64, 0xdfdfdfdf), cqe.user_data); - try testing.expectEqualSlices(u8, &([_]u8{0} ** buffer_len), buffers[used_buffer_id][0..@intCast(usize, cqe.res)]); + try testing.expectEqualSlices(u8, &([_]u8{0} ** buffer_len), buffers[used_buffer_id][0..@as(usize, @intCast(cqe.res))]); } // Final read should _not_ work @@ -3119,7 +3112,7 @@ test "provide_buffers: accept/connect/send/recv" { // Provide 4 buffers { - const sqe = try ring.provide_buffers(0xcccccccc, @ptrCast([*]u8, &buffers), buffer_len, buffers.len, group_id, buffer_id); + const sqe = try ring.provide_buffers(0xcccccccc, @as([*]u8, @ptrCast(&buffers)), buffer_len, buffers.len, group_id, buffer_id); try testing.expectEqual(linux.IORING_OP.PROVIDE_BUFFERS, sqe.opcode); try testing.expectEqual(@as(i32, buffers.len), sqe.fd); try testing.expectEqual(@as(u32, buffer_len), sqe.len); @@ -3181,7 +3174,7 @@ test "provide_buffers: accept/connect/send/recv" { try testing.expectEqual(@as(i32, buffer_len), cqe.res); try testing.expectEqual(@as(u64, 0xdededede), cqe.user_data); - const buffer = buffers[used_buffer_id][0..@intCast(usize, cqe.res)]; + const buffer = buffers[used_buffer_id][0..@as(usize, @intCast(cqe.res))]; try testing.expectEqualSlices(u8, &([_]u8{'z'} ** buffer_len), buffer); } @@ -3213,7 +3206,7 @@ test "provide_buffers: accept/connect/send/recv" { const reprovided_buffer_id = 2; { - _ = try ring.provide_buffers(0xabababab, @ptrCast([*]u8, &buffers[reprovided_buffer_id]), buffer_len, 1, group_id, reprovided_buffer_id); + _ = try ring.provide_buffers(0xabababab, @as([*]u8, @ptrCast(&buffers[reprovided_buffer_id])), buffer_len, 1, group_id, reprovided_buffer_id); try testing.expectEqual(@as(u32, 1), try ring.submit()); const cqe = try ring.copy_cqe(); @@ -3259,7 +3252,7 @@ test "provide_buffers: accept/connect/send/recv" { try testing.expectEqual(used_buffer_id, reprovided_buffer_id); try testing.expectEqual(@as(i32, buffer_len), cqe.res); try testing.expectEqual(@as(u64, 0xdfdfdfdf), cqe.user_data); - const buffer = buffers[used_buffer_id][0..@intCast(usize, cqe.res)]; + const buffer = buffers[used_buffer_id][0..@as(usize, @intCast(cqe.res))]; try testing.expectEqualSlices(u8, &([_]u8{'w'} ** buffer_len), buffer); } } diff --git a/lib/std/os/linux/ioctl.zig b/lib/std/os/linux/ioctl.zig index 96ec96c306..7f5d36b72d 100644 --- a/lib/std/os/linux/ioctl.zig +++ b/lib/std/os/linux/ioctl.zig @@ -32,7 +32,7 @@ fn io_impl(dir: Direction, io_type: u8, nr: u8, comptime T: type) u32 { .io_type = io_type, .nr = nr, }; - return @bitCast(u32, request); + return @as(u32, @bitCast(request)); } pub fn IO(io_type: u8, nr: u8) u32 { diff --git a/lib/std/os/linux/start_pie.zig b/lib/std/os/linux/start_pie.zig index c9b1cb1e92..cf557f9d66 100644 --- a/lib/std/os/linux/start_pie.zig +++ b/lib/std/os/linux/start_pie.zig @@ -103,17 +103,17 @@ pub fn relocate(phdrs: []elf.Phdr) void { // Apply the relocations. if (rel_addr != 0) { - const rel = std.mem.bytesAsSlice(elf.Rel, @ptrFromInt([*]u8, rel_addr)[0..rel_size]); + const rel = std.mem.bytesAsSlice(elf.Rel, @as([*]u8, @ptrFromInt(rel_addr))[0..rel_size]); for (rel) |r| { if (r.r_type() != R_RELATIVE) continue; - @ptrFromInt(*usize, base_addr + r.r_offset).* += base_addr; + @as(*usize, @ptrFromInt(base_addr + r.r_offset)).* += base_addr; } } if (rela_addr != 0) { - const rela = std.mem.bytesAsSlice(elf.Rela, @ptrFromInt([*]u8, rela_addr)[0..rela_size]); + const rela = std.mem.bytesAsSlice(elf.Rela, @as([*]u8, @ptrFromInt(rela_addr))[0..rela_size]); for (rela) |r| { if (r.r_type() != R_RELATIVE) continue; - @ptrFromInt(*usize, base_addr + r.r_offset).* += base_addr + @bitCast(usize, r.r_addend); + @as(*usize, @ptrFromInt(base_addr + r.r_offset)).* += base_addr + @as(usize, @bitCast(r.r_addend)); } } } diff --git a/lib/std/os/linux/test.zig b/lib/std/os/linux/test.zig index e1ad36b2e5..170bde6334 100644 --- a/lib/std/os/linux/test.zig +++ b/lib/std/os/linux/test.zig @@ -50,7 +50,7 @@ test "timer" { .it_value = time_interval, }; - err = linux.getErrno(linux.timerfd_settime(@intCast(i32, timer_fd), 0, &new_time, null)); + err = linux.getErrno(linux.timerfd_settime(@as(i32, @intCast(timer_fd)), 0, &new_time, null)); try expect(err == .SUCCESS); var event = linux.epoll_event{ @@ -58,13 +58,13 @@ test "timer" { .data = linux.epoll_data{ .ptr = 0 }, }; - err = linux.getErrno(linux.epoll_ctl(@intCast(i32, epoll_fd), linux.EPOLL.CTL_ADD, @intCast(i32, timer_fd), &event)); + err = linux.getErrno(linux.epoll_ctl(@as(i32, @intCast(epoll_fd)), linux.EPOLL.CTL_ADD, @as(i32, @intCast(timer_fd)), &event)); try expect(err == .SUCCESS); const events_one: linux.epoll_event = undefined; var events = [_]linux.epoll_event{events_one} ** 8; - err = linux.getErrno(linux.epoll_wait(@intCast(i32, epoll_fd), &events, 8, -1)); + err = linux.getErrno(linux.epoll_wait(@as(i32, @intCast(epoll_fd)), &events, 8, -1)); try expect(err == .SUCCESS); } @@ -91,11 +91,11 @@ test "statx" { } try expect(stat_buf.mode == statx_buf.mode); - try expect(@bitCast(u32, stat_buf.uid) == statx_buf.uid); - try expect(@bitCast(u32, stat_buf.gid) == statx_buf.gid); - try expect(@bitCast(u64, @as(i64, stat_buf.size)) == statx_buf.size); - try expect(@bitCast(u64, @as(i64, stat_buf.blksize)) == statx_buf.blksize); - try expect(@bitCast(u64, @as(i64, stat_buf.blocks)) == statx_buf.blocks); + try expect(@as(u32, @bitCast(stat_buf.uid)) == statx_buf.uid); + try expect(@as(u32, @bitCast(stat_buf.gid)) == statx_buf.gid); + try expect(@as(u64, @bitCast(@as(i64, stat_buf.size))) == statx_buf.size); + try expect(@as(u64, @bitCast(@as(i64, stat_buf.blksize))) == statx_buf.blksize); + try expect(@as(u64, @bitCast(@as(i64, stat_buf.blocks))) == statx_buf.blocks); } test "user and group ids" { diff --git a/lib/std/os/linux/tls.zig b/lib/std/os/linux/tls.zig index b60a2ed388..94fa0d1a09 100644 --- a/lib/std/os/linux/tls.zig +++ b/lib/std/os/linux/tls.zig @@ -205,7 +205,7 @@ fn initTLS(phdrs: []elf.Phdr) void { // the data stored in the PT_TLS segment is p_filesz and may be less // than the former tls_align_factor = phdr.p_align; - tls_data = @ptrFromInt([*]u8, img_base + phdr.p_vaddr)[0..phdr.p_filesz]; + tls_data = @as([*]u8, @ptrFromInt(img_base + phdr.p_vaddr))[0..phdr.p_filesz]; tls_data_alloc_size = phdr.p_memsz; } else { tls_align_factor = @alignOf(usize); @@ -263,12 +263,12 @@ fn initTLS(phdrs: []elf.Phdr) void { .dtv_offset = dtv_offset, .data_offset = data_offset, .data_size = tls_data_alloc_size, - .gdt_entry_number = @bitCast(usize, @as(isize, -1)), + .gdt_entry_number = @as(usize, @bitCast(@as(isize, -1))), }; } inline fn alignPtrCast(comptime T: type, ptr: [*]u8) *T { - return @ptrCast(*T, @alignCast(@alignOf(T), ptr)); + return @ptrCast(@alignCast(ptr)); } /// Initializes all the fields of the static TLS area and returns the computed diff --git a/lib/std/os/linux/vdso.zig b/lib/std/os/linux/vdso.zig index c7dc7ae599..50e7ce1dfd 100644 --- a/lib/std/os/linux/vdso.zig +++ b/lib/std/os/linux/vdso.zig @@ -8,7 +8,7 @@ pub fn lookup(vername: []const u8, name: []const u8) usize { const vdso_addr = std.os.system.getauxval(std.elf.AT_SYSINFO_EHDR); if (vdso_addr == 0) return 0; - const eh = @ptrFromInt(*elf.Ehdr, vdso_addr); + const eh = @as(*elf.Ehdr, @ptrFromInt(vdso_addr)); var ph_addr: usize = vdso_addr + eh.e_phoff; var maybe_dynv: ?[*]usize = null; @@ -19,14 +19,14 @@ pub fn lookup(vername: []const u8, name: []const u8) usize { i += 1; ph_addr += eh.e_phentsize; }) { - const this_ph = @ptrFromInt(*elf.Phdr, ph_addr); + const this_ph = @as(*elf.Phdr, @ptrFromInt(ph_addr)); switch (this_ph.p_type) { // On WSL1 as well as older kernels, the VDSO ELF image is pre-linked in the upper half // of the memory space (e.g. p_vaddr = 0xffffffffff700000 on WSL1). // Wrapping operations are used on this line as well as subsequent calculations relative to base // (lines 47, 78) to ensure no overflow check is tripped. elf.PT_LOAD => base = vdso_addr +% this_ph.p_offset -% this_ph.p_vaddr, - elf.PT_DYNAMIC => maybe_dynv = @ptrFromInt([*]usize, vdso_addr + this_ph.p_offset), + elf.PT_DYNAMIC => maybe_dynv = @as([*]usize, @ptrFromInt(vdso_addr + this_ph.p_offset)), else => {}, } } @@ -45,11 +45,11 @@ pub fn lookup(vername: []const u8, name: []const u8) usize { while (dynv[i] != 0) : (i += 2) { const p = base +% dynv[i + 1]; switch (dynv[i]) { - elf.DT_STRTAB => maybe_strings = @ptrFromInt([*]u8, p), - elf.DT_SYMTAB => maybe_syms = @ptrFromInt([*]elf.Sym, p), - elf.DT_HASH => maybe_hashtab = @ptrFromInt([*]linux.Elf_Symndx, p), - elf.DT_VERSYM => maybe_versym = @ptrFromInt([*]u16, p), - elf.DT_VERDEF => maybe_verdef = @ptrFromInt(*elf.Verdef, p), + elf.DT_STRTAB => maybe_strings = @as([*]u8, @ptrFromInt(p)), + elf.DT_SYMTAB => maybe_syms = @as([*]elf.Sym, @ptrFromInt(p)), + elf.DT_HASH => maybe_hashtab = @as([*]linux.Elf_Symndx, @ptrFromInt(p)), + elf.DT_VERSYM => maybe_versym = @as([*]u16, @ptrFromInt(p)), + elf.DT_VERDEF => maybe_verdef = @as(*elf.Verdef, @ptrFromInt(p)), else => {}, } } @@ -65,10 +65,10 @@ pub fn lookup(vername: []const u8, name: []const u8) usize { var i: usize = 0; while (i < hashtab[1]) : (i += 1) { - if (0 == (@as(u32, 1) << @intCast(u5, syms[i].st_info & 0xf) & OK_TYPES)) continue; - if (0 == (@as(u32, 1) << @intCast(u5, syms[i].st_info >> 4) & OK_BINDS)) continue; + if (0 == (@as(u32, 1) << @as(u5, @intCast(syms[i].st_info & 0xf)) & OK_TYPES)) continue; + if (0 == (@as(u32, 1) << @as(u5, @intCast(syms[i].st_info >> 4)) & OK_BINDS)) continue; if (0 == syms[i].st_shndx) continue; - const sym_name = @ptrCast([*:0]u8, strings + syms[i].st_name); + const sym_name = @as([*:0]u8, @ptrCast(strings + syms[i].st_name)); if (!mem.eql(u8, name, mem.sliceTo(sym_name, 0))) continue; if (maybe_versym) |versym| { if (!checkver(maybe_verdef.?, versym[i], vername, strings)) @@ -82,15 +82,15 @@ pub fn lookup(vername: []const u8, name: []const u8) usize { fn checkver(def_arg: *elf.Verdef, vsym_arg: i32, vername: []const u8, strings: [*]u8) bool { var def = def_arg; - const vsym = @bitCast(u32, vsym_arg) & 0x7fff; + const vsym = @as(u32, @bitCast(vsym_arg)) & 0x7fff; while (true) { if (0 == (def.vd_flags & elf.VER_FLG_BASE) and (def.vd_ndx & 0x7fff) == vsym) break; if (def.vd_next == 0) return false; - def = @ptrFromInt(*elf.Verdef, @intFromPtr(def) + def.vd_next); + def = @as(*elf.Verdef, @ptrFromInt(@intFromPtr(def) + def.vd_next)); } - const aux = @ptrFromInt(*elf.Verdaux, @intFromPtr(def) + def.vd_aux); - const vda_name = @ptrCast([*:0]u8, strings + aux.vda_name); + const aux = @as(*elf.Verdaux, @ptrFromInt(@intFromPtr(def) + def.vd_aux)); + const vda_name = @as([*:0]u8, @ptrCast(strings + aux.vda_name)); return mem.eql(u8, vername, mem.sliceTo(vda_name, 0)); } diff --git a/lib/std/os/plan9.zig b/lib/std/os/plan9.zig index b628bc2afc..3e1137c7ce 100644 --- a/lib/std/os/plan9.zig +++ b/lib/std/os/plan9.zig @@ -8,9 +8,9 @@ pub const syscall_bits = switch (builtin.cpu.arch) { pub const E = @import("plan9/errno.zig").E; /// Get the errno from a syscall return value, or 0 for no error. pub fn getErrno(r: usize) E { - const signed_r = @bitCast(isize, r); + const signed_r = @as(isize, @bitCast(r)); const int = if (signed_r > -4096 and signed_r < 0) -signed_r else 0; - return @enumFromInt(E, int); + return @as(E, @enumFromInt(int)); } pub const SIG = struct { /// hangup diff --git a/lib/std/os/test.zig b/lib/std/os/test.zig index 888b2f5c1c..d5451f64ac 100644 --- a/lib/std/os/test.zig +++ b/lib/std/os/test.zig @@ -488,7 +488,7 @@ fn iter_fn(info: *dl_phdr_info, size: usize, counter: *usize) IterFnError!void { const reloc_addr = info.dlpi_addr + phdr.p_vaddr; // Find the ELF header - const elf_header = @ptrFromInt(*elf.Ehdr, reloc_addr - phdr.p_offset); + const elf_header = @as(*elf.Ehdr, @ptrFromInt(reloc_addr - phdr.p_offset)); // Validate the magic if (!mem.eql(u8, elf_header.e_ident[0..4], elf.MAGIC)) return error.BadElfMagic; // Consistency check @@ -751,7 +751,7 @@ test "getrlimit and setrlimit" { } inline for (std.meta.fields(os.rlimit_resource)) |field| { - const resource = @enumFromInt(os.rlimit_resource, field.value); + const resource = @as(os.rlimit_resource, @enumFromInt(field.value)); const limit = try os.getrlimit(resource); // On 32 bit MIPS musl includes a fix which changes limits greater than -1UL/2 to RLIM_INFINITY. diff --git a/lib/std/os/uefi.zig b/lib/std/os/uefi.zig index f51caaa86f..7c6eb08a93 100644 --- a/lib/std/os/uefi.zig +++ b/lib/std/os/uefi.zig @@ -143,7 +143,7 @@ pub const FileHandle = *opaque {}; test "GUID formatting" { var bytes = [_]u8{ 137, 60, 203, 50, 128, 128, 124, 66, 186, 19, 80, 73, 135, 59, 194, 135 }; - var guid = @bitCast(Guid, bytes); + var guid = @as(Guid, @bitCast(bytes)); var str = try std.fmt.allocPrint(std.testing.allocator, "{}", .{guid}); defer std.testing.allocator.free(str); diff --git a/lib/std/os/uefi/pool_allocator.zig b/lib/std/os/uefi/pool_allocator.zig index c24d9416f1..3f64a2f3f6 100644 --- a/lib/std/os/uefi/pool_allocator.zig +++ b/lib/std/os/uefi/pool_allocator.zig @@ -9,7 +9,7 @@ const Allocator = mem.Allocator; const UefiPoolAllocator = struct { fn getHeader(ptr: [*]u8) *[*]align(8) u8 { - return @ptrFromInt(*[*]align(8) u8, @intFromPtr(ptr) - @sizeOf(usize)); + return @as(*[*]align(8) u8, @ptrFromInt(@intFromPtr(ptr) - @sizeOf(usize))); } fn alloc( @@ -22,7 +22,7 @@ const UefiPoolAllocator = struct { assert(len > 0); - const ptr_align = @as(usize, 1) << @intCast(Allocator.Log2Align, log2_ptr_align); + const ptr_align = @as(usize, 1) << @as(Allocator.Log2Align, @intCast(log2_ptr_align)); const metadata_len = mem.alignForward(usize, @sizeOf(usize), ptr_align); @@ -135,5 +135,5 @@ fn uefi_free( ) void { _ = log2_old_ptr_align; _ = ret_addr; - _ = uefi.system_table.boot_services.?.freePool(@alignCast(8, buf.ptr)); + _ = uefi.system_table.boot_services.?.freePool(@alignCast(buf.ptr)); } diff --git a/lib/std/os/uefi/protocols/device_path_protocol.zig b/lib/std/os/uefi/protocols/device_path_protocol.zig index c64084e6ed..a083959521 100644 --- a/lib/std/os/uefi/protocols/device_path_protocol.zig +++ b/lib/std/os/uefi/protocols/device_path_protocol.zig @@ -23,10 +23,10 @@ pub const DevicePathProtocol = extern struct { /// Returns the next DevicePathProtocol node in the sequence, if any. pub fn next(self: *DevicePathProtocol) ?*DevicePathProtocol { - if (self.type == .End and @enumFromInt(EndDevicePath.Subtype, self.subtype) == .EndEntire) + if (self.type == .End and @as(EndDevicePath.Subtype, @enumFromInt(self.subtype)) == .EndEntire) return null; - return @ptrCast(*DevicePathProtocol, @ptrCast([*]u8, self) + self.length); + return @as(*DevicePathProtocol, @ptrCast(@as([*]u8, @ptrCast(self)) + self.length)); } /// Calculates the total length of the device path structure in bytes, including the end of device path node. @@ -48,30 +48,30 @@ pub const DevicePathProtocol = extern struct { // DevicePathProtocol for the extra node before the end var buf = try allocator.alloc(u8, path_size + 2 * (path.len + 1) + @sizeOf(DevicePathProtocol)); - @memcpy(buf[0..path_size.len], @ptrCast([*]const u8, self)[0..path_size]); + @memcpy(buf[0..path_size.len], @as([*]const u8, @ptrCast(self))[0..path_size]); // Pointer to the copy of the end node of the current chain, which is - 4 from the buffer // as the end node itself is 4 bytes (type: u8 + subtype: u8 + length: u16). - var new = @ptrCast(*MediaDevicePath.FilePathDevicePath, buf.ptr + path_size - 4); + var new = @as(*MediaDevicePath.FilePathDevicePath, @ptrCast(buf.ptr + path_size - 4)); new.type = .Media; new.subtype = .FilePath; - new.length = @sizeOf(MediaDevicePath.FilePathDevicePath) + 2 * (@intCast(u16, path.len) + 1); + new.length = @sizeOf(MediaDevicePath.FilePathDevicePath) + 2 * (@as(u16, @intCast(path.len)) + 1); // The same as new.getPath(), but not const as we're filling it in. - var ptr = @ptrCast([*:0]align(1) u16, @ptrCast([*]u8, new) + @sizeOf(MediaDevicePath.FilePathDevicePath)); + var ptr = @as([*:0]align(1) u16, @ptrCast(@as([*]u8, @ptrCast(new)) + @sizeOf(MediaDevicePath.FilePathDevicePath))); for (path, 0..) |s, i| ptr[i] = s; ptr[path.len] = 0; - var end = @ptrCast(*EndDevicePath.EndEntireDevicePath, @ptrCast(*DevicePathProtocol, new).next().?); + var end = @as(*EndDevicePath.EndEntireDevicePath, @ptrCast(@as(*DevicePathProtocol, @ptrCast(new)).next().?)); end.type = .End; end.subtype = .EndEntire; end.length = @sizeOf(EndDevicePath.EndEntireDevicePath); - return @ptrCast(*DevicePathProtocol, buf.ptr); + return @as(*DevicePathProtocol, @ptrCast(buf.ptr)); } pub fn getDevicePath(self: *const DevicePathProtocol) ?DevicePath { @@ -103,7 +103,7 @@ pub const DevicePathProtocol = extern struct { if (self.subtype == tag_val) { // e.g. expr = .{ .Pci = @ptrCast(...) } - return @unionInit(TUnion, subtype.name, @ptrCast(subtype.type, self)); + return @unionInit(TUnion, subtype.name, @as(subtype.type, @ptrCast(self))); } } @@ -332,7 +332,7 @@ pub const AcpiDevicePath = union(Subtype) { pub fn adrs(self: *const AdrDevicePath) []align(1) const u32 { // self.length is a minimum of 8 with one adr which is size 4. var entries = (self.length - 4) / @sizeOf(u32); - return @ptrCast([*]align(1) const u32, &self.adr)[0..entries]; + return @as([*]align(1) const u32, @ptrCast(&self.adr))[0..entries]; } }; @@ -550,7 +550,7 @@ pub const MessagingDevicePath = union(Subtype) { pub fn serial_number(self: *const UsbWwidDevicePath) []align(1) const u16 { var serial_len = (self.length - @sizeOf(UsbWwidDevicePath)) / @sizeOf(u16); - return @ptrCast([*]align(1) const u16, @ptrCast([*]const u8, self) + @sizeOf(UsbWwidDevicePath))[0..serial_len]; + return @as([*]align(1) const u16, @ptrCast(@as([*]const u8, @ptrCast(self)) + @sizeOf(UsbWwidDevicePath)))[0..serial_len]; } }; @@ -943,7 +943,7 @@ pub const MediaDevicePath = union(Subtype) { length: u16 align(1), pub fn getPath(self: *const FilePathDevicePath) [*:0]align(1) const u16 { - return @ptrCast([*:0]align(1) const u16, @ptrCast([*]const u8, self) + @sizeOf(FilePathDevicePath)); + return @as([*:0]align(1) const u16, @ptrCast(@as([*]const u8, @ptrCast(self)) + @sizeOf(FilePathDevicePath))); } }; @@ -1068,7 +1068,7 @@ pub const BiosBootSpecificationDevicePath = union(Subtype) { status_flag: u16 align(1), pub fn getDescription(self: *const BBS101DevicePath) [*:0]const u8 { - return @ptrCast([*:0]const u8, self) + @sizeOf(BBS101DevicePath); + return @as([*:0]const u8, @ptrCast(self)) + @sizeOf(BBS101DevicePath); } }; diff --git a/lib/std/os/uefi/protocols/file_protocol.zig b/lib/std/os/uefi/protocols/file_protocol.zig index 729d4020b4..53ec5f81e3 100644 --- a/lib/std/os/uefi/protocols/file_protocol.zig +++ b/lib/std/os/uefi/protocols/file_protocol.zig @@ -152,7 +152,7 @@ pub const FileInfo = extern struct { attribute: u64, pub fn getFileName(self: *const FileInfo) [*:0]const u16 { - return @ptrCast([*:0]const u16, @ptrCast([*]const u8, self) + @sizeOf(FileInfo)); + return @as([*:0]const u16, @ptrCast(@as([*]const u8, @ptrCast(self)) + @sizeOf(FileInfo))); } pub const efi_file_read_only: u64 = 0x0000000000000001; @@ -182,7 +182,7 @@ pub const FileSystemInfo = extern struct { _volume_label: u16, pub fn getVolumeLabel(self: *const FileSystemInfo) [*:0]const u16 { - return @ptrCast([*:0]const u16, &self._volume_label); + return @as([*:0]const u16, @ptrCast(&self._volume_label)); } pub const guid align(8) = Guid{ diff --git a/lib/std/os/uefi/protocols/hii.zig b/lib/std/os/uefi/protocols/hii.zig index 437fa29739..c7199d2950 100644 --- a/lib/std/os/uefi/protocols/hii.zig +++ b/lib/std/os/uefi/protocols/hii.zig @@ -39,7 +39,7 @@ pub const HIISimplifiedFontPackage = extern struct { number_of_wide_glyphs: u16, pub fn getNarrowGlyphs(self: *HIISimplifiedFontPackage) []NarrowGlyph { - return @ptrCast([*]NarrowGlyph, @ptrCast([*]u8, self) + @sizeOf(HIISimplifiedFontPackage))[0..self.number_of_narrow_glyphs]; + return @as([*]NarrowGlyph, @ptrCast(@as([*]u8, @ptrCast(self)) + @sizeOf(HIISimplifiedFontPackage)))[0..self.number_of_narrow_glyphs]; } }; diff --git a/lib/std/os/uefi/protocols/managed_network_protocol.zig b/lib/std/os/uefi/protocols/managed_network_protocol.zig index aff9febd17..5ea63f5a65 100644 --- a/lib/std/os/uefi/protocols/managed_network_protocol.zig +++ b/lib/std/os/uefi/protocols/managed_network_protocol.zig @@ -118,7 +118,7 @@ pub const ManagedNetworkTransmitData = extern struct { fragment_count: u16, pub fn getFragments(self: *ManagedNetworkTransmitData) []ManagedNetworkFragmentData { - return @ptrCast([*]ManagedNetworkFragmentData, @ptrCast([*]u8, self) + @sizeOf(ManagedNetworkTransmitData))[0..self.fragment_count]; + return @as([*]ManagedNetworkFragmentData, @ptrCast(@as([*]u8, @ptrCast(self)) + @sizeOf(ManagedNetworkTransmitData)))[0..self.fragment_count]; } }; diff --git a/lib/std/os/uefi/protocols/udp6_protocol.zig b/lib/std/os/uefi/protocols/udp6_protocol.zig index 96a1d4c318..f772d38d52 100644 --- a/lib/std/os/uefi/protocols/udp6_protocol.zig +++ b/lib/std/os/uefi/protocols/udp6_protocol.zig @@ -87,7 +87,7 @@ pub const Udp6ReceiveData = extern struct { fragment_count: u32, pub fn getFragments(self: *Udp6ReceiveData) []Udp6FragmentData { - return @ptrCast([*]Udp6FragmentData, @ptrCast([*]u8, self) + @sizeOf(Udp6ReceiveData))[0..self.fragment_count]; + return @as([*]Udp6FragmentData, @ptrCast(@as([*]u8, @ptrCast(self)) + @sizeOf(Udp6ReceiveData)))[0..self.fragment_count]; } }; @@ -97,7 +97,7 @@ pub const Udp6TransmitData = extern struct { fragment_count: u32, pub fn getFragments(self: *Udp6TransmitData) []Udp6FragmentData { - return @ptrCast([*]Udp6FragmentData, @ptrCast([*]u8, self) + @sizeOf(Udp6TransmitData))[0..self.fragment_count]; + return @as([*]Udp6FragmentData, @ptrCast(@as([*]u8, @ptrCast(self)) + @sizeOf(Udp6TransmitData)))[0..self.fragment_count]; } }; diff --git a/lib/std/os/uefi/tables/boot_services.zig b/lib/std/os/uefi/tables/boot_services.zig index bfd3865e95..7fc32decb9 100644 --- a/lib/std/os/uefi/tables/boot_services.zig +++ b/lib/std/os/uefi/tables/boot_services.zig @@ -165,7 +165,7 @@ pub const BootServices = extern struct { try self.openProtocol( handle, &protocol.guid, - @ptrCast(*?*anyopaque, &ptr), + @as(*?*anyopaque, @ptrCast(&ptr)), // Invoking handle (loaded image) uefi.handle, // Control handle (null as not a driver) diff --git a/lib/std/os/wasi.zig b/lib/std/os/wasi.zig index 711352e2fe..951d8ee26d 100644 --- a/lib/std/os/wasi.zig +++ b/lib/std/os/wasi.zig @@ -103,13 +103,13 @@ pub const timespec = extern struct { const tv_sec: timestamp_t = tm / 1_000_000_000; const tv_nsec = tm - tv_sec * 1_000_000_000; return timespec{ - .tv_sec = @intCast(time_t, tv_sec), - .tv_nsec = @intCast(isize, tv_nsec), + .tv_sec = @as(time_t, @intCast(tv_sec)), + .tv_nsec = @as(isize, @intCast(tv_nsec)), }; } pub fn toTimestamp(ts: timespec) timestamp_t { - const tm = @intCast(timestamp_t, ts.tv_sec * 1_000_000_000) + @intCast(timestamp_t, ts.tv_nsec); + const tm = @as(timestamp_t, @intCast(ts.tv_sec * 1_000_000_000)) + @as(timestamp_t, @intCast(ts.tv_nsec)); return tm; } }; diff --git a/lib/std/os/windows.zig b/lib/std/os/windows.zig index 421815c04d..e12e8ac4d3 100644 --- a/lib/std/os/windows.zig +++ b/lib/std/os/windows.zig @@ -30,7 +30,7 @@ pub const gdi32 = @import("windows/gdi32.zig"); pub const winmm = @import("windows/winmm.zig"); pub const crypt32 = @import("windows/crypt32.zig"); -pub const self_process_handle = @ptrFromInt(HANDLE, maxInt(usize)); +pub const self_process_handle = @as(HANDLE, @ptrFromInt(maxInt(usize))); const Self = @This(); @@ -198,9 +198,9 @@ pub fn DeviceIoControl( var io: IO_STATUS_BLOCK = undefined; const in_ptr = if (in) |i| i.ptr else null; - const in_len = if (in) |i| @intCast(ULONG, i.len) else 0; + const in_len = if (in) |i| @as(ULONG, @intCast(i.len)) else 0; const out_ptr = if (out) |o| o.ptr else null; - const out_len = if (out) |o| @intCast(ULONG, o.len) else 0; + const out_len = if (out) |o| @as(ULONG, @intCast(o.len)) else 0; const rc = blk: { if (is_fsctl) { @@ -307,7 +307,7 @@ pub fn WaitForSingleObjectEx(handle: HANDLE, milliseconds: DWORD, alertable: boo pub fn WaitForMultipleObjectsEx(handles: []const HANDLE, waitAll: bool, milliseconds: DWORD, alertable: bool) !u32 { assert(handles.len < MAXIMUM_WAIT_OBJECTS); - const nCount: DWORD = @intCast(DWORD, handles.len); + const nCount: DWORD = @as(DWORD, @intCast(handles.len)); switch (kernel32.WaitForMultipleObjectsEx( nCount, handles.ptr, @@ -419,7 +419,7 @@ pub fn GetQueuedCompletionStatusEx( const success = kernel32.GetQueuedCompletionStatusEx( completion_port, completion_port_entries.ptr, - @intCast(ULONG, completion_port_entries.len), + @as(ULONG, @intCast(completion_port_entries.len)), &num_entries_removed, timeout_ms orelse INFINITE, @intFromBool(alertable), @@ -469,8 +469,8 @@ pub fn ReadFile(in_hFile: HANDLE, buffer: []u8, offset: ?u64, io_mode: std.io.Mo .InternalHigh = 0, .DUMMYUNIONNAME = .{ .DUMMYSTRUCTNAME = .{ - .Offset = @truncate(u32, off), - .OffsetHigh = @truncate(u32, off >> 32), + .Offset = @as(u32, @truncate(off)), + .OffsetHigh = @as(u32, @truncate(off >> 32)), }, }, .hEvent = null, @@ -480,7 +480,7 @@ pub fn ReadFile(in_hFile: HANDLE, buffer: []u8, offset: ?u64, io_mode: std.io.Mo loop.beginOneEvent(); suspend { // TODO handle buffer bigger than DWORD can hold - _ = kernel32.ReadFile(in_hFile, buffer.ptr, @intCast(DWORD, buffer.len), null, &resume_node.base.overlapped); + _ = kernel32.ReadFile(in_hFile, buffer.ptr, @as(DWORD, @intCast(buffer.len)), null, &resume_node.base.overlapped); } var bytes_transferred: DWORD = undefined; if (kernel32.GetOverlappedResult(in_hFile, &resume_node.base.overlapped, &bytes_transferred, FALSE) == 0) { @@ -496,7 +496,7 @@ pub fn ReadFile(in_hFile: HANDLE, buffer: []u8, offset: ?u64, io_mode: std.io.Mo if (offset == null) { // TODO make setting the file position non-blocking const new_off = off + bytes_transferred; - try SetFilePointerEx_CURRENT(in_hFile, @bitCast(i64, new_off)); + try SetFilePointerEx_CURRENT(in_hFile, @as(i64, @bitCast(new_off))); } return @as(usize, bytes_transferred); } else { @@ -510,8 +510,8 @@ pub fn ReadFile(in_hFile: HANDLE, buffer: []u8, offset: ?u64, io_mode: std.io.Mo .InternalHigh = 0, .DUMMYUNIONNAME = .{ .DUMMYSTRUCTNAME = .{ - .Offset = @truncate(u32, off), - .OffsetHigh = @truncate(u32, off >> 32), + .Offset = @as(u32, @truncate(off)), + .OffsetHigh = @as(u32, @truncate(off >> 32)), }, }, .hEvent = null, @@ -563,8 +563,8 @@ pub fn WriteFile( .InternalHigh = 0, .DUMMYUNIONNAME = .{ .DUMMYSTRUCTNAME = .{ - .Offset = @truncate(u32, off), - .OffsetHigh = @truncate(u32, off >> 32), + .Offset = @as(u32, @truncate(off)), + .OffsetHigh = @as(u32, @truncate(off >> 32)), }, }, .hEvent = null, @@ -591,7 +591,7 @@ pub fn WriteFile( if (offset == null) { // TODO make setting the file position non-blocking const new_off = off + bytes_transferred; - try SetFilePointerEx_CURRENT(handle, @bitCast(i64, new_off)); + try SetFilePointerEx_CURRENT(handle, @as(i64, @bitCast(new_off))); } return bytes_transferred; } else { @@ -603,8 +603,8 @@ pub fn WriteFile( .InternalHigh = 0, .DUMMYUNIONNAME = .{ .DUMMYSTRUCTNAME = .{ - .Offset = @truncate(u32, off), - .OffsetHigh = @truncate(u32, off >> 32), + .Offset = @as(u32, @truncate(off)), + .OffsetHigh = @as(u32, @truncate(off >> 32)), }, }, .hEvent = null, @@ -745,19 +745,19 @@ pub fn CreateSymbolicLink( const header_len = @sizeOf(ULONG) + @sizeOf(USHORT) * 2; const symlink_data = SYMLINK_DATA{ .ReparseTag = IO_REPARSE_TAG_SYMLINK, - .ReparseDataLength = @intCast(u16, buf_len - header_len), + .ReparseDataLength = @as(u16, @intCast(buf_len - header_len)), .Reserved = 0, - .SubstituteNameOffset = @intCast(u16, target_path.len * 2), - .SubstituteNameLength = @intCast(u16, target_path.len * 2), + .SubstituteNameOffset = @as(u16, @intCast(target_path.len * 2)), + .SubstituteNameLength = @as(u16, @intCast(target_path.len * 2)), .PrintNameOffset = 0, - .PrintNameLength = @intCast(u16, target_path.len * 2), + .PrintNameLength = @as(u16, @intCast(target_path.len * 2)), .Flags = if (dir) |_| SYMLINK_FLAG_RELATIVE else 0, }; @memcpy(buffer[0..@sizeOf(SYMLINK_DATA)], std.mem.asBytes(&symlink_data)); - @memcpy(buffer[@sizeOf(SYMLINK_DATA)..][0 .. target_path.len * 2], @ptrCast([*]const u8, target_path)); + @memcpy(buffer[@sizeOf(SYMLINK_DATA)..][0 .. target_path.len * 2], @as([*]const u8, @ptrCast(target_path))); const paths_start = @sizeOf(SYMLINK_DATA) + target_path.len * 2; - @memcpy(buffer[paths_start..][0 .. target_path.len * 2], @ptrCast([*]const u8, target_path)); + @memcpy(buffer[paths_start..][0 .. target_path.len * 2], @as([*]const u8, @ptrCast(target_path))); _ = try DeviceIoControl(symlink_handle, FSCTL_SET_REPARSE_POINT, buffer[0..buf_len], null); } @@ -827,10 +827,10 @@ pub fn ReadLink(dir: ?HANDLE, sub_path_w: []const u16, out_buffer: []u8) ReadLin else => |e| return e, }; - const reparse_struct = @ptrCast(*const REPARSE_DATA_BUFFER, @alignCast(@alignOf(REPARSE_DATA_BUFFER), &reparse_buf[0])); + const reparse_struct: *const REPARSE_DATA_BUFFER = @ptrCast(@alignCast(&reparse_buf[0])); switch (reparse_struct.ReparseTag) { IO_REPARSE_TAG_SYMLINK => { - const buf = @ptrCast(*const SYMBOLIC_LINK_REPARSE_BUFFER, @alignCast(@alignOf(SYMBOLIC_LINK_REPARSE_BUFFER), &reparse_struct.DataBuffer[0])); + const buf: *const SYMBOLIC_LINK_REPARSE_BUFFER = @ptrCast(@alignCast(&reparse_struct.DataBuffer[0])); const offset = buf.SubstituteNameOffset >> 1; const len = buf.SubstituteNameLength >> 1; const path_buf = @as([*]const u16, &buf.PathBuffer); @@ -838,7 +838,7 @@ pub fn ReadLink(dir: ?HANDLE, sub_path_w: []const u16, out_buffer: []u8) ReadLin return parseReadlinkPath(path_buf[offset..][0..len], is_relative, out_buffer); }, IO_REPARSE_TAG_MOUNT_POINT => { - const buf = @ptrCast(*const MOUNT_POINT_REPARSE_BUFFER, @alignCast(@alignOf(MOUNT_POINT_REPARSE_BUFFER), &reparse_struct.DataBuffer[0])); + const buf: *const MOUNT_POINT_REPARSE_BUFFER = @ptrCast(@alignCast(&reparse_struct.DataBuffer[0])); const offset = buf.SubstituteNameOffset >> 1; const len = buf.SubstituteNameLength >> 1; const path_buf = @as([*]const u16, &buf.PathBuffer); @@ -884,7 +884,7 @@ pub fn DeleteFile(sub_path_w: []const u16, options: DeleteFileOptions) DeleteFil else FILE_NON_DIRECTORY_FILE | FILE_OPEN_REPARSE_POINT; // would we ever want to delete the target instead? - const path_len_bytes = @intCast(u16, sub_path_w.len * 2); + const path_len_bytes = @as(u16, @intCast(sub_path_w.len * 2)); var nt_name = UNICODE_STRING{ .Length = path_len_bytes, .MaximumLength = path_len_bytes, @@ -1020,7 +1020,7 @@ pub fn SetFilePointerEx_BEGIN(handle: HANDLE, offset: u64) SetFilePointerError!v // "The starting point is zero or the beginning of the file. If [FILE_BEGIN] // is specified, then the liDistanceToMove parameter is interpreted as an unsigned value." // https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-setfilepointerex - const ipos = @bitCast(LARGE_INTEGER, offset); + const ipos = @as(LARGE_INTEGER, @bitCast(offset)); if (kernel32.SetFilePointerEx(handle, ipos, null, FILE_BEGIN) == 0) { switch (kernel32.GetLastError()) { .INVALID_PARAMETER => unreachable, @@ -1064,7 +1064,7 @@ pub fn SetFilePointerEx_CURRENT_get(handle: HANDLE) SetFilePointerError!u64 { } // Based on the docs for FILE_BEGIN, it seems that the returned signed integer // should be interpreted as an unsigned integer. - return @bitCast(u64, result); + return @as(u64, @bitCast(result)); } pub fn QueryObjectName( @@ -1073,7 +1073,7 @@ pub fn QueryObjectName( ) ![]u16 { const out_buffer_aligned = mem.alignInSlice(out_buffer, @alignOf(OBJECT_NAME_INFORMATION)) orelse return error.NameTooLong; - const info = @ptrCast(*OBJECT_NAME_INFORMATION, out_buffer_aligned); + const info = @as(*OBJECT_NAME_INFORMATION, @ptrCast(out_buffer_aligned)); //buffer size is specified in bytes const out_buffer_len = std.math.cast(ULONG, out_buffer_aligned.len * 2) orelse std.math.maxInt(ULONG); //last argument would return the length required for full_buffer, not exposed here @@ -1197,26 +1197,26 @@ pub fn GetFinalPathNameByHandle( }; defer CloseHandle(mgmt_handle); - var input_struct = @ptrCast(*MOUNTMGR_MOUNT_POINT, &input_buf[0]); + var input_struct = @as(*MOUNTMGR_MOUNT_POINT, @ptrCast(&input_buf[0])); input_struct.DeviceNameOffset = @sizeOf(MOUNTMGR_MOUNT_POINT); - input_struct.DeviceNameLength = @intCast(USHORT, volume_name_u16.len * 2); - @memcpy(input_buf[@sizeOf(MOUNTMGR_MOUNT_POINT)..][0 .. volume_name_u16.len * 2], @ptrCast([*]const u8, volume_name_u16.ptr)); + input_struct.DeviceNameLength = @as(USHORT, @intCast(volume_name_u16.len * 2)); + @memcpy(input_buf[@sizeOf(MOUNTMGR_MOUNT_POINT)..][0 .. volume_name_u16.len * 2], @as([*]const u8, @ptrCast(volume_name_u16.ptr))); DeviceIoControl(mgmt_handle, IOCTL_MOUNTMGR_QUERY_POINTS, &input_buf, &output_buf) catch |err| switch (err) { error.AccessDenied => unreachable, else => |e| return e, }; - const mount_points_struct = @ptrCast(*const MOUNTMGR_MOUNT_POINTS, &output_buf[0]); + const mount_points_struct = @as(*const MOUNTMGR_MOUNT_POINTS, @ptrCast(&output_buf[0])); - const mount_points = @ptrCast( + const mount_points = @as( [*]const MOUNTMGR_MOUNT_POINT, - &mount_points_struct.MountPoints[0], + @ptrCast(&mount_points_struct.MountPoints[0]), )[0..mount_points_struct.NumberOfMountPoints]; for (mount_points) |mount_point| { - const symlink = @ptrCast( + const symlink = @as( [*]const u16, - @alignCast(@alignOf(u16), &output_buf[mount_point.SymbolicLinkNameOffset]), + @ptrCast(@alignCast(&output_buf[mount_point.SymbolicLinkNameOffset])), )[0 .. mount_point.SymbolicLinkNameLength / 2]; // Look for `\DosDevices\` prefix. We don't really care if there are more than one symlinks @@ -1282,7 +1282,7 @@ pub fn GetFileSizeEx(hFile: HANDLE) GetFileSizeError!u64 { else => |err| return unexpectedError(err), } } - return @bitCast(u64, file_size); + return @as(u64, @bitCast(file_size)); } pub const GetFileAttributesError = error{ @@ -1313,7 +1313,7 @@ pub fn WSAStartup(majorVersion: u8, minorVersion: u8) !ws2_32.WSADATA { var wsadata: ws2_32.WSADATA = undefined; return switch (ws2_32.WSAStartup((@as(WORD, minorVersion) << 8) | majorVersion, &wsadata)) { 0 => wsadata, - else => |err_int| switch (@enumFromInt(ws2_32.WinsockError, @intCast(u16, err_int))) { + else => |err_int| switch (@as(ws2_32.WinsockError, @enumFromInt(@as(u16, @intCast(err_int))))) { .WSASYSNOTREADY => return error.SystemNotAvailable, .WSAVERNOTSUPPORTED => return error.VersionNotSupported, .WSAEINPROGRESS => return error.BlockingOperationInProgress, @@ -1408,7 +1408,7 @@ pub fn WSASocketW( } pub fn bind(s: ws2_32.SOCKET, name: *const ws2_32.sockaddr, namelen: ws2_32.socklen_t) i32 { - return ws2_32.bind(s, name, @intCast(i32, namelen)); + return ws2_32.bind(s, name, @as(i32, @intCast(namelen))); } pub fn listen(s: ws2_32.SOCKET, backlog: u31) i32 { @@ -1427,15 +1427,15 @@ pub fn closesocket(s: ws2_32.SOCKET) !void { pub fn accept(s: ws2_32.SOCKET, name: ?*ws2_32.sockaddr, namelen: ?*ws2_32.socklen_t) ws2_32.SOCKET { assert((name == null) == (namelen == null)); - return ws2_32.accept(s, name, @ptrCast(?*i32, namelen)); + return ws2_32.accept(s, name, @as(?*i32, @ptrCast(namelen))); } pub fn getsockname(s: ws2_32.SOCKET, name: *ws2_32.sockaddr, namelen: *ws2_32.socklen_t) i32 { - return ws2_32.getsockname(s, name, @ptrCast(*i32, namelen)); + return ws2_32.getsockname(s, name, @as(*i32, @ptrCast(namelen))); } pub fn getpeername(s: ws2_32.SOCKET, name: *ws2_32.sockaddr, namelen: *ws2_32.socklen_t) i32 { - return ws2_32.getpeername(s, name, @ptrCast(*i32, namelen)); + return ws2_32.getpeername(s, name, @as(*i32, @ptrCast(namelen))); } pub fn sendmsg( @@ -1447,28 +1447,28 @@ pub fn sendmsg( if (ws2_32.WSASendMsg(s, msg, flags, &bytes_send, null, null) == ws2_32.SOCKET_ERROR) { return ws2_32.SOCKET_ERROR; } else { - return @as(i32, @intCast(u31, bytes_send)); + return @as(i32, @as(u31, @intCast(bytes_send))); } } pub fn sendto(s: ws2_32.SOCKET, buf: [*]const u8, len: usize, flags: u32, to: ?*const ws2_32.sockaddr, to_len: ws2_32.socklen_t) i32 { - var buffer = ws2_32.WSABUF{ .len = @truncate(u31, len), .buf = @constCast(buf) }; + var buffer = ws2_32.WSABUF{ .len = @as(u31, @truncate(len)), .buf = @constCast(buf) }; var bytes_send: DWORD = undefined; - if (ws2_32.WSASendTo(s, @ptrCast([*]ws2_32.WSABUF, &buffer), 1, &bytes_send, flags, to, @intCast(i32, to_len), null, null) == ws2_32.SOCKET_ERROR) { + if (ws2_32.WSASendTo(s, @as([*]ws2_32.WSABUF, @ptrCast(&buffer)), 1, &bytes_send, flags, to, @as(i32, @intCast(to_len)), null, null) == ws2_32.SOCKET_ERROR) { return ws2_32.SOCKET_ERROR; } else { - return @as(i32, @intCast(u31, bytes_send)); + return @as(i32, @as(u31, @intCast(bytes_send))); } } pub fn recvfrom(s: ws2_32.SOCKET, buf: [*]u8, len: usize, flags: u32, from: ?*ws2_32.sockaddr, from_len: ?*ws2_32.socklen_t) i32 { - var buffer = ws2_32.WSABUF{ .len = @truncate(u31, len), .buf = buf }; + var buffer = ws2_32.WSABUF{ .len = @as(u31, @truncate(len)), .buf = buf }; var bytes_received: DWORD = undefined; var flags_inout = flags; - if (ws2_32.WSARecvFrom(s, @ptrCast([*]ws2_32.WSABUF, &buffer), 1, &bytes_received, &flags_inout, from, @ptrCast(?*i32, from_len), null, null) == ws2_32.SOCKET_ERROR) { + if (ws2_32.WSARecvFrom(s, @as([*]ws2_32.WSABUF, @ptrCast(&buffer)), 1, &bytes_received, &flags_inout, from, @as(?*i32, @ptrCast(from_len)), null, null) == ws2_32.SOCKET_ERROR) { return ws2_32.SOCKET_ERROR; } else { - return @as(i32, @intCast(u31, bytes_received)); + return @as(i32, @as(u31, @intCast(bytes_received))); } } @@ -1489,9 +1489,9 @@ pub fn WSAIoctl( s, dwIoControlCode, if (inBuffer) |i| i.ptr else null, - if (inBuffer) |i| @intCast(DWORD, i.len) else 0, + if (inBuffer) |i| @as(DWORD, @intCast(i.len)) else 0, outBuffer.ptr, - @intCast(DWORD, outBuffer.len), + @as(DWORD, @intCast(outBuffer.len)), &bytes, overlapped, completionRoutine, @@ -1741,7 +1741,7 @@ pub fn QueryPerformanceFrequency() u64 { var result: LARGE_INTEGER = undefined; assert(kernel32.QueryPerformanceFrequency(&result) != 0); // The kernel treats this integer as unsigned. - return @bitCast(u64, result); + return @as(u64, @bitCast(result)); } pub fn QueryPerformanceCounter() u64 { @@ -1750,7 +1750,7 @@ pub fn QueryPerformanceCounter() u64 { var result: LARGE_INTEGER = undefined; assert(kernel32.QueryPerformanceCounter(&result) != 0); // The kernel treats this integer as unsigned. - return @bitCast(u64, result); + return @as(u64, @bitCast(result)); } pub fn InitOnceExecuteOnce(InitOnce: *INIT_ONCE, InitFn: INIT_ONCE_FN, Parameter: ?*anyopaque, Context: ?*anyopaque) void { @@ -1852,7 +1852,7 @@ pub fn teb() *TEB { return switch (native_arch) { .x86 => blk: { if (builtin.zig_backend == .stage2_c) { - break :blk @ptrCast(*TEB, @alignCast(@alignOf(TEB), zig_x86_windows_teb())); + break :blk @ptrCast(@alignCast(zig_x86_windows_teb())); } else { break :blk asm volatile ( \\ movl %%fs:0x18, %[ptr] @@ -1862,7 +1862,7 @@ pub fn teb() *TEB { }, .x86_64 => blk: { if (builtin.zig_backend == .stage2_c) { - break :blk @ptrCast(*TEB, @alignCast(@alignOf(TEB), zig_x86_64_windows_teb())); + break :blk @ptrCast(@alignCast(zig_x86_64_windows_teb())); } else { break :blk asm volatile ( \\ movq %%gs:0x30, %[ptr] @@ -1894,7 +1894,7 @@ pub fn fromSysTime(hns: i64) i128 { pub fn toSysTime(ns: i128) i64 { const hns = @divFloor(ns, 100); - return @intCast(i64, hns) - std.time.epoch.windows * (std.time.ns_per_s / 100); + return @as(i64, @intCast(hns)) - std.time.epoch.windows * (std.time.ns_per_s / 100); } pub fn fileTimeToNanoSeconds(ft: FILETIME) i128 { @@ -1904,22 +1904,22 @@ pub fn fileTimeToNanoSeconds(ft: FILETIME) i128 { /// Converts a number of nanoseconds since the POSIX epoch to a Windows FILETIME. pub fn nanoSecondsToFileTime(ns: i128) FILETIME { - const adjusted = @bitCast(u64, toSysTime(ns)); + const adjusted = @as(u64, @bitCast(toSysTime(ns))); return FILETIME{ - .dwHighDateTime = @truncate(u32, adjusted >> 32), - .dwLowDateTime = @truncate(u32, adjusted), + .dwHighDateTime = @as(u32, @truncate(adjusted >> 32)), + .dwLowDateTime = @as(u32, @truncate(adjusted)), }; } /// Compares two WTF16 strings using RtlEqualUnicodeString pub fn eqlIgnoreCaseWTF16(a: []const u16, b: []const u16) bool { - const a_bytes = @intCast(u16, a.len * 2); + const a_bytes = @as(u16, @intCast(a.len * 2)); const a_string = UNICODE_STRING{ .Length = a_bytes, .MaximumLength = a_bytes, .Buffer = @constCast(a.ptr), }; - const b_bytes = @intCast(u16, b.len * 2); + const b_bytes = @as(u16, @intCast(b.len * 2)); const b_string = UNICODE_STRING{ .Length = b_bytes, .MaximumLength = b_bytes, @@ -2117,7 +2117,7 @@ pub fn wToPrefixedFileW(path: [:0]const u16) !PathSpace { .unc_absolute => nt_prefix.len + 2, else => nt_prefix.len, }; - const buf_len = @intCast(u32, path_space.data.len - path_buf_offset); + const buf_len = @as(u32, @intCast(path_space.data.len - path_buf_offset)); const path_byte_len = ntdll.RtlGetFullPathName_U( path.ptr, buf_len * 2, @@ -2263,7 +2263,7 @@ test getUnprefixedPathType { } fn getFullPathNameW(path: [*:0]const u16, out: []u16) !usize { - const result = kernel32.GetFullPathNameW(path, @intCast(u32, out.len), out.ptr, null); + const result = kernel32.GetFullPathNameW(path, @as(u32, @intCast(out.len)), out.ptr, null); if (result == 0) { switch (kernel32.GetLastError()) { else => |err| return unexpectedError(err), @@ -2284,9 +2284,9 @@ pub fn loadWinsockExtensionFunction(comptime T: type, sock: ws2_32.SOCKET, guid: const rc = ws2_32.WSAIoctl( sock, ws2_32.SIO_GET_EXTENSION_FUNCTION_POINTER, - @ptrCast(*const anyopaque, &guid), + @as(*const anyopaque, @ptrCast(&guid)), @sizeOf(GUID), - @ptrFromInt(?*anyopaque, @intFromPtr(&function)), + @as(?*anyopaque, @ptrFromInt(@intFromPtr(&function))), @sizeOf(T), &num_bytes, null, @@ -2332,7 +2332,7 @@ pub fn unexpectedError(err: Win32Error) std.os.UnexpectedError { } pub fn unexpectedWSAError(err: ws2_32.WinsockError) std.os.UnexpectedError { - return unexpectedError(@enumFromInt(Win32Error, @intFromEnum(err))); + return unexpectedError(@as(Win32Error, @enumFromInt(@intFromEnum(err)))); } /// Call this when you made a windows NtDll call @@ -2530,7 +2530,7 @@ pub fn CTL_CODE(deviceType: u16, function: u12, method: TransferType, access: u2 @intFromEnum(method); } -pub const INVALID_HANDLE_VALUE = @ptrFromInt(HANDLE, maxInt(usize)); +pub const INVALID_HANDLE_VALUE = @as(HANDLE, @ptrFromInt(maxInt(usize))); pub const INVALID_FILE_ATTRIBUTES = @as(DWORD, maxInt(DWORD)); @@ -3119,7 +3119,7 @@ pub const GUID = extern struct { bytes[i] = (try std.fmt.charToDigit(s[hex_offset], 16)) << 4 | try std.fmt.charToDigit(s[hex_offset + 1], 16); } - return @bitCast(GUID, bytes); + return @as(GUID, @bitCast(bytes)); } }; @@ -3150,16 +3150,16 @@ pub const KF_FLAG_SIMPLE_IDLIST = 256; pub const KF_FLAG_ALIAS_ONLY = -2147483648; pub const S_OK = 0; -pub const E_NOTIMPL = @bitCast(c_long, @as(c_ulong, 0x80004001)); -pub const E_NOINTERFACE = @bitCast(c_long, @as(c_ulong, 0x80004002)); -pub const E_POINTER = @bitCast(c_long, @as(c_ulong, 0x80004003)); -pub const E_ABORT = @bitCast(c_long, @as(c_ulong, 0x80004004)); -pub const E_FAIL = @bitCast(c_long, @as(c_ulong, 0x80004005)); -pub const E_UNEXPECTED = @bitCast(c_long, @as(c_ulong, 0x8000FFFF)); -pub const E_ACCESSDENIED = @bitCast(c_long, @as(c_ulong, 0x80070005)); -pub const E_HANDLE = @bitCast(c_long, @as(c_ulong, 0x80070006)); -pub const E_OUTOFMEMORY = @bitCast(c_long, @as(c_ulong, 0x8007000E)); -pub const E_INVALIDARG = @bitCast(c_long, @as(c_ulong, 0x80070057)); +pub const E_NOTIMPL = @as(c_long, @bitCast(@as(c_ulong, 0x80004001))); +pub const E_NOINTERFACE = @as(c_long, @bitCast(@as(c_ulong, 0x80004002))); +pub const E_POINTER = @as(c_long, @bitCast(@as(c_ulong, 0x80004003))); +pub const E_ABORT = @as(c_long, @bitCast(@as(c_ulong, 0x80004004))); +pub const E_FAIL = @as(c_long, @bitCast(@as(c_ulong, 0x80004005))); +pub const E_UNEXPECTED = @as(c_long, @bitCast(@as(c_ulong, 0x8000FFFF))); +pub const E_ACCESSDENIED = @as(c_long, @bitCast(@as(c_ulong, 0x80070005))); +pub const E_HANDLE = @as(c_long, @bitCast(@as(c_ulong, 0x80070006))); +pub const E_OUTOFMEMORY = @as(c_long, @bitCast(@as(c_ulong, 0x8007000E))); +pub const E_INVALIDARG = @as(c_long, @bitCast(@as(c_ulong, 0x80070057))); pub const FILE_FLAG_BACKUP_SEMANTICS = 0x02000000; pub const FILE_FLAG_DELETE_ON_CLOSE = 0x04000000; @@ -3221,7 +3221,7 @@ pub const LSTATUS = LONG; pub const HKEY = *opaque {}; -pub const HKEY_LOCAL_MACHINE: HKEY = @ptrFromInt(HKEY, 0x80000002); +pub const HKEY_LOCAL_MACHINE: HKEY = @as(HKEY, @ptrFromInt(0x80000002)); /// Combines the STANDARD_RIGHTS_REQUIRED, KEY_QUERY_VALUE, KEY_SET_VALUE, KEY_CREATE_SUB_KEY, /// KEY_ENUMERATE_SUB_KEYS, KEY_NOTIFY, and KEY_CREATE_LINK access rights. @@ -4685,7 +4685,7 @@ pub const KUSER_SHARED_DATA = extern struct { /// Read-only user-mode address for the shared data. /// https://www.geoffchappell.com/studies/windows/km/ntoskrnl/inc/api/ntexapi_x/kuser_shared_data/index.htm /// https://msrc-blog.microsoft.com/2022/04/05/randomizing-the-kuser_shared_data-structure-on-windows/ -pub const SharedUserData: *const KUSER_SHARED_DATA = @ptrFromInt(*const KUSER_SHARED_DATA, 0x7FFE0000); +pub const SharedUserData: *const KUSER_SHARED_DATA = @as(*const KUSER_SHARED_DATA, @ptrFromInt(0x7FFE0000)); pub fn IsProcessorFeaturePresent(feature: PF) bool { if (@intFromEnum(feature) >= PROCESSOR_FEATURE_MAX) return false; @@ -4886,7 +4886,7 @@ pub fn WriteProcessMemory(handle: HANDLE, addr: ?LPVOID, buffer: []const u8) Wri switch (ntdll.NtWriteVirtualMemory( handle, addr, - @ptrCast(*const anyopaque, buffer.ptr), + @as(*const anyopaque, @ptrCast(buffer.ptr)), buffer.len, &nwritten, )) { @@ -4919,6 +4919,6 @@ pub fn ProcessBaseAddress(handle: HANDLE) ProcessBaseAddressError!HMODULE { var peb_buf: [@sizeOf(PEB)]u8 align(@alignOf(PEB)) = undefined; const peb_out = try ReadProcessMemory(handle, info.PebBaseAddress, &peb_buf); - const ppeb = @ptrCast(*const PEB, @alignCast(@alignOf(PEB), peb_out.ptr)); + const ppeb: *const PEB = @ptrCast(@alignCast(peb_out.ptr)); return ppeb.ImageBaseAddress; } diff --git a/lib/std/os/windows/user32.zig b/lib/std/os/windows/user32.zig index 0d6fc2c670..8c492cee32 100644 --- a/lib/std/os/windows/user32.zig +++ b/lib/std/os/windows/user32.zig @@ -1275,7 +1275,7 @@ pub const WS_EX_LAYERED = 0x00080000; pub const WS_EX_OVERLAPPEDWINDOW = WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE; pub const WS_EX_PALETTEWINDOW = WS_EX_WINDOWEDGE | WS_EX_TOOLWINDOW | WS_EX_TOPMOST; -pub const CW_USEDEFAULT = @bitCast(i32, @as(u32, 0x80000000)); +pub const CW_USEDEFAULT = @as(i32, @bitCast(@as(u32, 0x80000000))); pub extern "user32" fn CreateWindowExA(dwExStyle: DWORD, lpClassName: [*:0]const u8, lpWindowName: [*:0]const u8, dwStyle: DWORD, X: i32, Y: i32, nWidth: i32, nHeight: i32, hWindParent: ?HWND, hMenu: ?HMENU, hInstance: HINSTANCE, lpParam: ?LPVOID) callconv(WINAPI) ?HWND; pub fn createWindowExA(dwExStyle: u32, lpClassName: [*:0]const u8, lpWindowName: [*:0]const u8, dwStyle: u32, X: i32, Y: i32, nWidth: i32, nHeight: i32, hWindParent: ?HWND, hMenu: ?HMENU, hInstance: HINSTANCE, lpParam: ?*anyopaque) !HWND { diff --git a/lib/std/os/windows/ws2_32.zig b/lib/std/os/windows/ws2_32.zig index 821b903a34..240c8c849d 100644 --- a/lib/std/os/windows/ws2_32.zig +++ b/lib/std/os/windows/ws2_32.zig @@ -21,7 +21,7 @@ const LPARAM = windows.LPARAM; const FARPROC = windows.FARPROC; pub const SOCKET = *opaque {}; -pub const INVALID_SOCKET = @ptrFromInt(SOCKET, ~@as(usize, 0)); +pub const INVALID_SOCKET = @as(SOCKET, @ptrFromInt(~@as(usize, 0))); pub const GROUP = u32; pub const ADDRESS_FAMILY = u16; |
