From d2e5c03b987097f3396fa84de444e7ced31faf17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Tue, 7 May 2024 15:33:17 +0200 Subject: [PATCH 1/4] fix(abi): `clockid_t` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Kröning --- hermit-abi/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hermit-abi/src/lib.rs b/hermit-abi/src/lib.rs index 21266575e..d75dbed0a 100644 --- a/hermit-abi/src/lib.rs +++ b/hermit-abi/src/lib.rs @@ -44,8 +44,8 @@ pub const LOW_PRIO: Priority = Priority::from(1); pub struct Handle(usize); pub const FUTEX_RELATIVE_TIMEOUT: u32 = 1; -pub const CLOCK_REALTIME: u64 = 1; -pub const CLOCK_MONOTONIC: u64 = 4; +pub const CLOCK_REALTIME: clockid_t = 1; +pub const CLOCK_MONOTONIC: clockid_t = 4; pub const STDIN_FILENO: c_int = 0; pub const STDOUT_FILENO: c_int = 1; pub const STDERR_FILENO: c_int = 2; From bf10a26ab9feae491db5aeed86ebff4cc724b68a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Tue, 7 May 2024 15:36:04 +0200 Subject: [PATCH 2/4] fix(abi): `sockaddr_in.sin_port` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Kröning --- hermit-abi/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hermit-abi/src/lib.rs b/hermit-abi/src/lib.rs index d75dbed0a..b6d657289 100644 --- a/hermit-abi/src/lib.rs +++ b/hermit-abi/src/lib.rs @@ -209,7 +209,7 @@ pub struct sockaddr { pub struct sockaddr_in { pub sin_len: u8, pub sin_family: sa_family_t, - pub sin_port: u16, + pub sin_port: in_port_t, pub sin_addr: in_addr, pub sin_zero: [u8; 8], } From 3dbc0ee7be4cd21bd02c129154a8a5cd7c264092 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Tue, 7 May 2024 15:38:34 +0200 Subject: [PATCH 3/4] fix(abi): use `c_char` for C strings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Kröning --- hermit-abi/src/lib.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/hermit-abi/src/lib.rs b/hermit-abi/src/lib.rs index b6d657289..5e7fcb6b1 100644 --- a/hermit-abi/src/lib.rs +++ b/hermit-abi/src/lib.rs @@ -201,7 +201,7 @@ pub struct in6_addr { pub struct sockaddr { pub sa_len: u8, pub sa_family: sa_family_t, - pub sa_data: [u8; 14], + pub sa_data: [c_char; 14], } #[repr(C)] @@ -211,7 +211,7 @@ pub struct sockaddr_in { pub sin_family: sa_family_t, pub sin_port: in_port_t, pub sin_addr: in_addr, - pub sin_zero: [u8; 8], + pub sin_zero: [c_char; 8], } #[repr(C)] @@ -233,7 +233,7 @@ pub struct addrinfo { pub ai_socktype: i32, pub ai_protocol: i32, pub ai_addrlen: socklen_t, - pub ai_canonname: *mut u8, + pub ai_canonname: *mut c_char, pub ai_addr: *mut sockaddr, pub ai_next: *mut addrinfo, } @@ -323,7 +323,7 @@ pub struct dirent64 { /// File type pub d_type: u8, /// Filename (null-terminated) - pub d_name: [u8; 256], + pub d_name: [c_char; 256], } pub const DT_UNKNOWN: u8 = 0; @@ -761,8 +761,8 @@ extern "C" { #[link_name = "sys_getaddrinfo"] pub fn getaddrinfo( - nodename: *const i8, - servname: *const u8, + nodename: *const c_char, + servname: *const c_char, hints: *const addrinfo, res: *mut *mut addrinfo, ) -> i32; From ef3ea5508c981f6f6ed7dfd6168489fccc0b89d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Tue, 7 May 2024 15:43:14 +0200 Subject: [PATCH 4/4] fix(abi): remove deprecated IP types MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Kröning --- hermit-abi/src/lib.rs | 34 ----------- hermit-abi/src/tcplistener.rs | 13 ---- hermit-abi/src/tcpstream.rs | 110 ---------------------------------- 3 files changed, 157 deletions(-) delete mode 100644 hermit-abi/src/tcplistener.rs delete mode 100644 hermit-abi/src/tcpstream.rs diff --git a/hermit-abi/src/lib.rs b/hermit-abi/src/lib.rs index 5e7fcb6b1..defbb1ed0 100644 --- a/hermit-abi/src/lib.rs +++ b/hermit-abi/src/lib.rs @@ -7,8 +7,6 @@ #![allow(clippy::result_unit_err)] pub mod errno; -pub mod tcplistener; -pub mod tcpstream; use core::ffi::c_char; pub use core::ffi::{c_int, c_short, c_void}; @@ -39,10 +37,6 @@ pub const HIGH_PRIO: Priority = Priority::from(3); pub const NORMAL_PRIO: Priority = Priority::from(2); pub const LOW_PRIO: Priority = Priority::from(1); -/// A handle, identifying a socket -#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Default, Hash)] -pub struct Handle(usize); - pub const FUTEX_RELATIVE_TIMEOUT: u32 = 1; pub const CLOCK_REALTIME: clockid_t = 1; pub const CLOCK_MONOTONIC: clockid_t = 4; @@ -87,34 +81,6 @@ pub struct timeval { pub tv_usec: suseconds_t, } -/// Internet protocol version. -#[derive(Debug, Hash, PartialEq, Eq, PartialOrd, Ord, Clone, Copy)] -pub enum Version { - Unspecified, - Ipv4, - Ipv6, -} - -/// A four-octet IPv4 address. -#[derive(Debug, Hash, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Default)] -pub struct Ipv4Address(pub [u8; 4]); - -/// A sixteen-octet IPv6 address. -#[derive(Debug, Hash, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Default)] -pub struct Ipv6Address(pub [u8; 16]); - -/// An internetworking address. -#[derive(Debug, Hash, PartialEq, Eq, PartialOrd, Ord, Clone, Copy)] -pub enum IpAddress { - /// An unspecified address. - /// May be used as a placeholder for storage where the address is not assigned yet. - Unspecified, - /// An IPv4 address. - Ipv4(Ipv4Address), - /// An IPv6 address. - Ipv6(Ipv6Address), -} - /// The largest number `rand` will return pub const RAND_MAX: i32 = 2_147_483_647; diff --git a/hermit-abi/src/tcplistener.rs b/hermit-abi/src/tcplistener.rs deleted file mode 100644 index c278dc085..000000000 --- a/hermit-abi/src/tcplistener.rs +++ /dev/null @@ -1,13 +0,0 @@ -//! `tcplistener` provide an interface to establish tcp socket server. - -use crate::{Handle, IpAddress}; - -extern "Rust" { - fn sys_tcp_listener_accept(port: u16) -> Result<(Handle, IpAddress, u16), ()>; -} - -/// Wait for connection at specified address. -#[deprecated(since = "0.3.0", note = "please use new BSD socket interface")] -pub fn accept(port: u16) -> Result<(Handle, IpAddress, u16), ()> { - unsafe { sys_tcp_listener_accept(port) } -} diff --git a/hermit-abi/src/tcpstream.rs b/hermit-abi/src/tcpstream.rs deleted file mode 100644 index c8fcd1891..000000000 --- a/hermit-abi/src/tcpstream.rs +++ /dev/null @@ -1,110 +0,0 @@ -//! `tcpstream` provide an interface to establish tcp socket client. - -use crate::{Handle, IpAddress}; - -extern "Rust" { - fn sys_tcp_stream_connect(ip: &[u8], port: u16, timeout: Option) -> Result; - fn sys_tcp_stream_close(handle: Handle) -> Result<(), ()>; - fn sys_tcp_stream_read(handle: Handle, buffer: &mut [u8]) -> Result; - fn sys_tcp_stream_write(handle: Handle, buffer: &[u8]) -> Result; - fn sys_tcp_stream_set_read_timeout(handle: Handle, timeout: Option) -> Result<(), ()>; - fn sys_tcp_stream_get_read_timeout(handle: Handle) -> Result, ()>; - fn sys_tcp_stream_set_write_timeout(handle: Handle, timeout: Option) -> Result<(), ()>; - fn sys_tcp_stream_get_write_timeout(handle: Handle) -> Result, ()>; - fn sys_tcp_stream_peek(handle: Handle, buf: &mut [u8]) -> Result; - fn sys_tcp_stream_set_nonblocking(handle: Handle, mode: bool) -> Result<(), ()>; - fn sys_tcp_stream_set_tll(handle: Handle, ttl: u32) -> Result<(), ()>; - fn sys_tcp_stream_get_tll(handle: Handle) -> Result; - fn sys_tcp_stream_shutdown(handle: Handle, how: i32) -> Result<(), ()>; - fn sys_tcp_stream_peer_addr(handle: Handle) -> Result<(IpAddress, u16), ()>; -} - -/// Opens a TCP connection to a remote host. -#[deprecated(since = "0.3.0", note = "please use new BSD socket interface")] -pub fn connect(ip: &[u8], port: u16, timeout: Option) -> Result { - unsafe { sys_tcp_stream_connect(ip, port, timeout) } -} - -/// Close a TCP connection -#[deprecated(since = "0.3.0", note = "please use new BSD socket interface")] -pub fn close(handle: Handle) -> Result<(), ()> { - unsafe { sys_tcp_stream_close(handle) } -} - -#[deprecated(since = "0.3.0", note = "please use new BSD socket interface")] -pub fn peek(handle: Handle, buf: &mut [u8]) -> Result { - unsafe { sys_tcp_stream_peek(handle, buf) } -} - -#[deprecated(since = "0.3.0", note = "please use new BSD socket interface")] -pub fn peer_addr(handle: Handle) -> Result<(IpAddress, u16), ()> { - unsafe { sys_tcp_stream_peer_addr(handle) } -} - -#[deprecated(since = "0.3.0", note = "please use new BSD socket interface")] -pub fn read(handle: Handle, buffer: &mut [u8]) -> Result { - unsafe { sys_tcp_stream_read(handle, buffer) } -} - -#[deprecated(since = "0.3.0", note = "please use new BSD socket interface")] -pub fn write(handle: Handle, buffer: &[u8]) -> Result { - unsafe { sys_tcp_stream_write(handle, buffer) } -} - -#[deprecated(since = "0.3.0", note = "please use new BSD socket interface")] -pub fn set_read_timeout(handle: Handle, timeout: Option) -> Result<(), ()> { - unsafe { sys_tcp_stream_set_read_timeout(handle, timeout) } -} - -#[deprecated(since = "0.3.0", note = "please use new BSD socket interface")] -pub fn set_write_timeout(handle: Handle, timeout: Option) -> Result<(), ()> { - unsafe { sys_tcp_stream_set_write_timeout(handle, timeout) } -} - -#[deprecated(since = "0.3.0", note = "please use new BSD socket interface")] -pub fn get_read_timeout(handle: Handle) -> Result, ()> { - unsafe { sys_tcp_stream_get_read_timeout(handle) } -} - -#[deprecated(since = "0.3.0", note = "please use new BSD socket interface")] -pub fn get_write_timeout(handle: Handle) -> Result, ()> { - unsafe { sys_tcp_stream_get_write_timeout(handle) } -} - -#[deprecated(since = "0.3.0", note = "please use new BSD socket interface")] -pub fn set_nodelay(_: Handle, mode: bool) -> Result<(), ()> { - // smoltcp does not support Nagle's algorithm - // => to enable Nagle's algorithm isn't possible - if mode { - Ok(()) - } else { - Err(()) - } -} - -#[deprecated(since = "0.3.0", note = "please use new BSD socket interface")] -pub fn nodelay(_: Handle) -> Result { - // smoltcp does not support Nagle's algorithm - // => return always true - Ok(true) -} - -#[deprecated(since = "0.3.0", note = "please use new BSD socket interface")] -pub fn set_nonblocking(handle: Handle, mode: bool) -> Result<(), ()> { - unsafe { sys_tcp_stream_set_nonblocking(handle, mode) } -} - -#[deprecated(since = "0.3.0", note = "please use new BSD socket interface")] -pub fn set_tll(handle: Handle, ttl: u32) -> Result<(), ()> { - unsafe { sys_tcp_stream_set_tll(handle, ttl) } -} - -#[deprecated(since = "0.3.0", note = "please use new BSD socket interface")] -pub fn get_tll(handle: Handle) -> Result { - unsafe { sys_tcp_stream_get_tll(handle) } -} - -#[deprecated(since = "0.3.0", note = "please use new BSD socket interface")] -pub fn shutdown(handle: Handle, how: i32) -> Result<(), ()> { - unsafe { sys_tcp_stream_shutdown(handle, how) } -}