From f6e699cd22828e50b00fb867e8ee573da9f6ca9a Mon Sep 17 00:00:00 2001 From: Erik Isidore Date: Thu, 30 May 2024 00:14:00 -0300 Subject: [PATCH 1/3] core:sys/linux - Add support for Unix Domain Socket addresses --- core/sys/linux/sys.odin | 5 +++++ core/sys/linux/types.odin | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/core/sys/linux/sys.odin b/core/sys/linux/sys.odin index 413c8742b..171829cde 100644 --- a/core/sys/linux/sys.odin +++ b/core/sys/linux/sys.odin @@ -487,6 +487,7 @@ connect :: proc "contextless" (sock: Fd, addr: ^$T) -> (Errno) where T == Sock_Addr_In || T == Sock_Addr_In6 || + T == Sock_Addr_Un || T == Sock_Addr_Any { ret := syscall(SYS_connect, sock, addr, size_of(T)) @@ -502,6 +503,7 @@ accept :: proc "contextless" (sock: Fd, addr: ^$T, sockflags: Socket_FD_Flags = where T == Sock_Addr_In || T == Sock_Addr_In6 || + T == Sock_Addr_Un || T == Sock_Addr_Any { addr_len: i32 = size_of(T) @@ -514,6 +516,7 @@ recvfrom :: proc "contextless" (sock: Fd, buf: []u8, flags: Socket_Msg, addr: ^$ where T == Sock_Addr_In || T == Sock_Addr_In6 || + T == Sock_Addr_Un || T == Sock_Addr_Any { addr_len: i32 = size_of(T) @@ -531,6 +534,7 @@ sendto :: proc "contextless" (sock: Fd, buf: []u8, flags: Socket_Msg, addr: ^$T) where T == Sock_Addr_In || T == Sock_Addr_In6 || + T == Sock_Addr_Un || T == Sock_Addr_Any { ret := syscall(SYS_sendto, sock, raw_data(buf), len(buf), transmute(i32) flags, addr, size_of(T)) @@ -590,6 +594,7 @@ bind :: proc "contextless" (sock: Fd, addr: ^$T) -> (Errno) where T == Sock_Addr_In || T == Sock_Addr_In6 || + T == Sock_Addr_Un || T == Sock_Addr_Any { ret := syscall(SYS_bind, sock, addr, size_of(T)) diff --git a/core/sys/linux/types.odin b/core/sys/linux/types.odin index 677bac7e0..fe48d195e 100644 --- a/core/sys/linux/types.odin +++ b/core/sys/linux/types.odin @@ -631,6 +631,14 @@ Sock_Addr_In6 :: struct #packed { sin6_scope_id: u32, } +/* + Struct representing Unix Domain Socket address +*/ +Sock_Addr_Un :: struct #packed { + sun_family: Address_Family, + sun_path: [108]u8 +} + /* Struct representing an arbitrary socket address. */ @@ -641,6 +649,7 @@ Sock_Addr_Any :: struct #raw_union { }, using ipv4: Sock_Addr_In, using ipv6: Sock_Addr_In6, + using uds: Sock_Addr_Un, } /* From 0514ee0410826d00f71fd8ce188371cf7afab494 Mon Sep 17 00:00:00 2001 From: Erik Isidore Date: Thu, 30 May 2024 16:12:20 -0300 Subject: [PATCH 2/3] PR#3655 - small linter issue correction --- core/sys/linux/types.odin | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/sys/linux/types.odin b/core/sys/linux/types.odin index fe48d195e..5053e1e1c 100644 --- a/core/sys/linux/types.odin +++ b/core/sys/linux/types.odin @@ -636,7 +636,7 @@ Sock_Addr_In6 :: struct #packed { */ Sock_Addr_Un :: struct #packed { sun_family: Address_Family, - sun_path: [108]u8 + sun_path: [108]u8, } /* From 3a0ec3d6a88efcd8cf7466eb54a76dc6e0d027f5 Mon Sep 17 00:00:00 2001 From: Laytan Laats Date: Fri, 31 May 2024 16:32:27 +0200 Subject: [PATCH 3/3] wasm: fix target wasm64p32 runtime procs LLVM generates calls with `i32` regardless of target, so if a call to any of these procs was generated this failed to compile. I opted to fix by changing from `int` to `i32` on wasm64p32 and adding `#any_int` so existing code keeps working. --- base/runtime/procs.odin | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/base/runtime/procs.odin b/base/runtime/procs.odin index 454574c35..c9347463b 100644 --- a/base/runtime/procs.odin +++ b/base/runtime/procs.odin @@ -26,12 +26,18 @@ when ODIN_NO_CRT && ODIN_OS == .Windows { return dst } } else when ODIN_NO_CRT || (ODIN_ARCH == .wasm32 || ODIN_ARCH == .wasm64p32) { + // NOTE: on wasm, calls to these procs are generated (by LLVM) with type `i32` instead of `int`. + // + // NOTE: `#any_int` is also needed, because calls that we generate (and package code) + // will be using `int` and need to be converted. + int_t :: i32 when ODIN_ARCH == .wasm64p32 else int + @(link_name="memset", linkage="strong", require) - memset :: proc "c" (ptr: rawptr, val: i32, len: int) -> rawptr { + memset :: proc "c" (ptr: rawptr, val: i32, #any_int len: int_t) -> rawptr { if ptr != nil && len != 0 { b := byte(val) p := ([^]byte)(ptr) - for i := 0; i < len; i += 1 { + for i := int_t(0); i < len; i += 1 { p[i] = b } } @@ -39,10 +45,10 @@ when ODIN_NO_CRT && ODIN_OS == .Windows { } @(link_name="bzero", linkage="strong", require) - bzero :: proc "c" (ptr: rawptr, len: int) -> rawptr { + bzero :: proc "c" (ptr: rawptr, #any_int len: int_t) -> rawptr { if ptr != nil && len != 0 { p := ([^]byte)(ptr) - for i := 0; i < len; i += 1 { + for i := int_t(0); i < len; i += 1 { p[i] = 0 } } @@ -50,7 +56,7 @@ when ODIN_NO_CRT && ODIN_OS == .Windows { } @(link_name="memmove", linkage="strong", require) - memmove :: proc "c" (dst, src: rawptr, len: int) -> rawptr { + memmove :: proc "c" (dst, src: rawptr, #any_int len: int_t) -> rawptr { d, s := ([^]byte)(dst), ([^]byte)(src) if d == s || len == 0 { return dst @@ -63,7 +69,7 @@ when ODIN_NO_CRT && ODIN_OS == .Windows { } if s > d && uintptr(s)-uintptr(d) < uintptr(len) { - for i := 0; i < len; i += 1 { + for i := int_t(0); i < len; i += 1 { d[i] = s[i] } return dst @@ -71,10 +77,10 @@ when ODIN_NO_CRT && ODIN_OS == .Windows { return memcpy(dst, src, len) } @(link_name="memcpy", linkage="strong", require) - memcpy :: proc "c" (dst, src: rawptr, len: int) -> rawptr { + memcpy :: proc "c" (dst, src: rawptr, #any_int len: int_t) -> rawptr { d, s := ([^]byte)(dst), ([^]byte)(src) if d != s { - for i := 0; i < len; i += 1 { + for i := int_t(0); i < len; i += 1 { d[i] = s[i] } } @@ -92,4 +98,4 @@ when ODIN_NO_CRT && ODIN_OS == .Windows { } return ptr } -} \ No newline at end of file +}