From eaab17f8fb2c9dd084a16c337d61b0bf10a5d236 Mon Sep 17 00:00:00 2001 From: Laytan Laats Date: Sun, 5 May 2024 14:16:21 +0200 Subject: sys/linux: fix open bits --- core/sys/linux/bits.odin | 51 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 16 deletions(-) (limited to 'core/sys/linux') diff --git a/core/sys/linux/bits.odin b/core/sys/linux/bits.odin index 4db689643..cfae06013 100644 --- a/core/sys/linux/bits.odin +++ b/core/sys/linux/bits.odin @@ -153,22 +153,41 @@ Errno :: enum i32 { Open_Flags_Bits :: enum { WRONLY = 0, RDWR = 1, - CREAT = 8, - EXCL = 9, - NOCTTY = 10, - TRUNC = 11, - APPEND = 12, - NONBLOCK = 14, - DSYNC = 16, - ASYNC = 17, - DIRECT = 18, - LARGEFILE = 20, - DIRECTORY = 21, - NOFOLLOW = 22, - NOATIME = 24, - CLOEXEC = 25, - PATH = 28, -} + CREAT = 6, + EXCL = 7, + NOCTTY = 8, + TRUNC = 9, + APPEND = 10, + NONBLOCK = 11, + DSYNC = 12, + ASYNC = 13, + DIRECT = 14, + LARGEFILE = 15, + DIRECTORY = 16, + NOFOLLOW = 17, + NOATIME = 18, + CLOEXEC = 19, + PATH = 21, +} + +// https://github.com/torvalds/linux/blob/7367539ad4b0f8f9b396baf02110962333719a48/include/uapi/asm-generic/fcntl.h#L19 +#assert(1 << uint(Open_Flags_Bits.WRONLY) == 0o0000000_1) +#assert(1 << uint(Open_Flags_Bits.RDWR) == 0o0000000_2) +#assert(1 << uint(Open_Flags_Bits.CREAT) == 0o00000_100) +#assert(1 << uint(Open_Flags_Bits.EXCL) == 0o00000_200) +#assert(1 << uint(Open_Flags_Bits.NOCTTY) == 0o00000_400) +#assert(1 << uint(Open_Flags_Bits.TRUNC) == 0o0000_1000) +#assert(1 << uint(Open_Flags_Bits.APPEND) == 0o0000_2000) +#assert(1 << uint(Open_Flags_Bits.NONBLOCK) == 0o0000_4000) +#assert(1 << uint(Open_Flags_Bits.DSYNC) == 0o000_10000) +#assert(1 << uint(Open_Flags_Bits.ASYNC) == 0o000_20000) +#assert(1 << uint(Open_Flags_Bits.DIRECT) == 0o000_40000) +#assert(1 << uint(Open_Flags_Bits.LARGEFILE) == 0o00_100000) +#assert(1 << uint(Open_Flags_Bits.DIRECTORY) == 0o00_200000) +#assert(1 << uint(Open_Flags_Bits.NOFOLLOW) == 0o00_400000) +#assert(1 << uint(Open_Flags_Bits.NOATIME) == 0o0_1000000) +#assert(1 << uint(Open_Flags_Bits.CLOEXEC) == 0o0_2000000) +#assert(1 << uint(Open_Flags_Bits.PATH) == 0o_10000000) /* Bits for FD_Flags bitset -- cgit v1.2.3 From df53fec828e79f73fc540a88d000dc1ba245281f Mon Sep 17 00:00:00 2001 From: Hiroaki Nakamura Date: Mon, 6 May 2024 21:44:59 +0900 Subject: sys/linux: Pass size to epoll_create Without this fix, you can see a random size value is passed to epoll_create by using strace. --- core/sys/linux/sys.odin | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'core/sys/linux') diff --git a/core/sys/linux/sys.odin b/core/sys/linux/sys.odin index 63fb3b776..413c8742b 100644 --- a/core/sys/linux/sys.odin +++ b/core/sys/linux/sys.odin @@ -2314,7 +2314,7 @@ futex :: proc { */ epoll_create :: proc(size: i32 = 1) -> (Fd, Errno) { when ODIN_ARCH != .arm64 { - ret := syscall(SYS_epoll_create) + ret := syscall(SYS_epoll_create, i32(1)) return errno_unwrap(ret, Fd) } else { ret := syscall(SYS_epoll_create1, i32(0)) -- cgit v1.2.3 From d7fdccb08ca811a13715eb21c6c6def6e736558b Mon Sep 17 00:00:00 2001 From: Laytan Date: Thu, 9 May 2024 19:39:48 +0200 Subject: fix a couple of -vet-style failures after f54977336b27c32eab52b77d94e7b1610f4350cf --- core/math/big/helpers.odin | 2 +- core/math/big/internal.odin | 4 ++-- core/math/big/radix.odin | 4 ++-- core/sys/linux/helpers.odin | 30 +++++++++++++++--------------- 4 files changed, 20 insertions(+), 20 deletions(-) (limited to 'core/sys/linux') diff --git a/core/math/big/helpers.odin b/core/math/big/helpers.odin index 35be4f1fd..1969fac49 100644 --- a/core/math/big/helpers.odin +++ b/core/math/big/helpers.odin @@ -356,7 +356,7 @@ int_count_lsb :: proc(a: ^Int, allocator := context.allocator) -> (count: int, e } platform_count_lsb :: #force_inline proc(a: $T) -> (count: int) - where intrinsics.type_is_integer(T) && intrinsics.type_is_unsigned(T) { + where intrinsics.type_is_integer(T), intrinsics.type_is_unsigned(T) { return int(intrinsics.count_trailing_zeros(a)) if a > 0 else 0 } diff --git a/core/math/big/internal.odin b/core/math/big/internal.odin index 07e1e6c03..fa747e46a 100644 --- a/core/math/big/internal.odin +++ b/core/math/big/internal.odin @@ -546,7 +546,7 @@ internal_int_shl1 :: proc(dest, src: ^Int, allocator := context.allocator) -> (e Like `internal_int_mul_digit` but with an integer as the small input. */ internal_int_mul_integer :: proc(dest, a: ^Int, b: $T, allocator := context.allocator) -> (err: Error) -where intrinsics.type_is_integer(T) && T != DIGIT { +where intrinsics.type_is_integer(T), T != DIGIT { context.allocator = allocator t := &Int{} @@ -2806,7 +2806,7 @@ internal_int_count_lsb :: proc(a: ^Int) -> (count: int, err: Error) { } internal_platform_count_lsb :: #force_inline proc(a: $T) -> (count: int) - where intrinsics.type_is_integer(T) && intrinsics.type_is_unsigned(T) { + where intrinsics.type_is_integer(T), intrinsics.type_is_unsigned(T) { return int(intrinsics.count_trailing_zeros(a)) if a > 0 else 0 } diff --git a/core/math/big/radix.odin b/core/math/big/radix.odin index 8d8ea734e..f4eed879f 100644 --- a/core/math/big/radix.odin +++ b/core/math/big/radix.odin @@ -469,7 +469,7 @@ internal_int_pack_count :: proc(a: ^Int, $T: typeid, nails := 0) -> (size_needed Assumes `a` not to be `nil` and to have been initialized. */ internal_int_pack :: proc(a: ^Int, buf: []$T, nails := 0, order := Order.LSB_First) -> (written: int, err: Error) - where intrinsics.type_is_integer(T) && intrinsics.type_is_unsigned(T) && size_of(T) <= 16 { + where intrinsics.type_is_integer(T), intrinsics.type_is_unsigned(T), size_of(T) <= 16 { assert(nails >= 0 && nails < (size_of(T) * 8)) @@ -505,7 +505,7 @@ internal_int_pack :: proc(a: ^Int, buf: []$T, nails := 0, order := Order.LSB_Fir internal_int_unpack :: proc(a: ^Int, buf: []$T, nails := 0, order := Order.LSB_First, allocator := context.allocator) -> (err: Error) - where intrinsics.type_is_integer(T) && intrinsics.type_is_unsigned(T) && size_of(T) <= 16 { + where intrinsics.type_is_integer(T), intrinsics.type_is_unsigned(T), size_of(T) <= 16 { assert(nails >= 0 && nails < (size_of(T) * 8)) context.allocator = allocator diff --git a/core/sys/linux/helpers.odin b/core/sys/linux/helpers.odin index 69c648bf1..75fdd586e 100644 --- a/core/sys/linux/helpers.odin +++ b/core/sys/linux/helpers.odin @@ -26,7 +26,7 @@ where @(private) syscall2 :: #force_inline proc "contextless" (nr: uintptr,p1: $T1, p2: $T2) -> int where - size_of(p1) <= size_of(uintptr) && + size_of(p1) <= size_of(uintptr), size_of(p2) <= size_of(uintptr) { return cast(int) intrinsics.syscall(nr, @@ -36,8 +36,8 @@ where @(private) syscall3 :: #force_inline proc "contextless" (nr: uintptr, p1: $T1, p2: $T2, p3: $T3) -> int where - size_of(p1) <= size_of(uintptr) && - size_of(p2) <= size_of(uintptr) && + size_of(p1) <= size_of(uintptr), + size_of(p2) <= size_of(uintptr), size_of(p3) <= size_of(uintptr) { return cast(int) intrinsics.syscall(nr, @@ -49,9 +49,9 @@ where @(private) syscall4 :: #force_inline proc "contextless" (nr: uintptr, p1: $T1, p2: $T2, p3: $T3, p4: $T4) -> int where - size_of(p1) <= size_of(uintptr) && - size_of(p2) <= size_of(uintptr) && - size_of(p3) <= size_of(uintptr) && + size_of(p1) <= size_of(uintptr), + size_of(p2) <= size_of(uintptr), + size_of(p3) <= size_of(uintptr), size_of(p4) <= size_of(uintptr) { return cast(int) intrinsics.syscall(nr, @@ -64,10 +64,10 @@ where @(private) syscall5 :: #force_inline proc "contextless" (nr: uintptr, p1: $T1, p2: $T2, p3: $T3, p4: $T4, p5: $T5) -> int where - size_of(p1) <= size_of(uintptr) && - size_of(p2) <= size_of(uintptr) && - size_of(p3) <= size_of(uintptr) && - size_of(p4) <= size_of(uintptr) && + size_of(p1) <= size_of(uintptr), + size_of(p2) <= size_of(uintptr), + size_of(p3) <= size_of(uintptr), + size_of(p4) <= size_of(uintptr), size_of(p5) <= size_of(uintptr) { return cast(int) intrinsics.syscall(nr, @@ -81,11 +81,11 @@ where @(private) syscall6 :: #force_inline proc "contextless" (nr: uintptr, p1: $T1, p2: $T2, p3: $T3, p4: $T4, p5: $T5, p6: $T6) -> int where - size_of(p1) <= size_of(uintptr) && - size_of(p2) <= size_of(uintptr) && - size_of(p3) <= size_of(uintptr) && - size_of(p4) <= size_of(uintptr) && - size_of(p5) <= size_of(uintptr) && + size_of(p1) <= size_of(uintptr), + size_of(p2) <= size_of(uintptr), + size_of(p3) <= size_of(uintptr), + size_of(p4) <= size_of(uintptr), + size_of(p5) <= size_of(uintptr), size_of(p6) <= size_of(uintptr) { return cast(int) intrinsics.syscall(nr, -- cgit v1.2.3