From d4a66ca0cdb1b48a6cde337fb6e48bd687830b21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Tue, 7 May 2024 15:39:04 +0200 Subject: [PATCH 1/2] 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 --- src/syscalls/mod.rs | 2 +- src/syscalls/socket.rs | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/syscalls/mod.rs b/src/syscalls/mod.rs index 8674e1602f..f51636885b 100644 --- a/src/syscalls/mod.rs +++ b/src/syscalls/mod.rs @@ -489,7 +489,7 @@ pub struct Dirent64 { /// File type pub d_type: u8, /// Filename (null-terminated) - pub d_name: PhantomData, + pub d_name: PhantomData, } #[hermit_macro::system] diff --git a/src/syscalls/socket.rs b/src/syscalls/socket.rs index 1c93909fdc..c020bdecc3 100644 --- a/src/syscalls/socket.rs +++ b/src/syscalls/socket.rs @@ -1,7 +1,7 @@ #![allow(dead_code)] #![allow(nonstandard_style)] use alloc::sync::Arc; -use core::ffi::c_void; +use core::ffi::{c_char, c_void}; use core::mem::size_of; use core::ops::DerefMut; @@ -83,7 +83,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)] @@ -93,7 +93,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], } #[cfg(all(any(feature = "tcp", feature = "udp"), not(feature = "newlib")))] @@ -239,7 +239,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, } @@ -571,8 +571,8 @@ pub unsafe extern "C" fn sys_freeaddrinfo(_ai: *mut addrinfo) {} #[hermit_macro::system] pub unsafe extern "C" fn sys_getaddrinfo( - _nodename: *const u8, - _servname: *const u8, + _nodename: *const c_char, + _servname: *const c_char, _hints: *const addrinfo, _res: *mut *mut addrinfo, ) -> i32 { From 5ec743b2ba460c5efae2e14a1fabf93f08e2dffc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Tue, 7 May 2024 15:32:26 +0200 Subject: [PATCH 2/2] fix(timer): `clockid_t` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Kröning --- src/syscalls/timer.rs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/syscalls/timer.rs b/src/syscalls/timer.rs index cbcd1f5c00..95d5d2ecf7 100644 --- a/src/syscalls/timer.rs +++ b/src/syscalls/timer.rs @@ -3,10 +3,13 @@ use crate::errno::*; use crate::syscalls::usleep; use crate::time::{itimerval, timespec, timeval}; -pub(crate) const CLOCK_REALTIME: u64 = 1; -pub(crate) const CLOCK_PROCESS_CPUTIME_ID: u64 = 2; -pub(crate) const CLOCK_THREAD_CPUTIME_ID: u64 = 3; -pub(crate) const CLOCK_MONOTONIC: u64 = 4; +#[allow(non_camel_case_types)] +pub type clockid_t = i32; + +pub(crate) const CLOCK_REALTIME: clockid_t = 1; +pub(crate) const CLOCK_PROCESS_CPUTIME_ID: clockid_t = 2; +pub(crate) const CLOCK_THREAD_CPUTIME_ID: clockid_t = 3; +pub(crate) const CLOCK_MONOTONIC: clockid_t = 4; pub(crate) const TIMER_ABSTIME: i32 = 4; /// Finds the resolution (or precision) of a clock. @@ -20,7 +23,7 @@ pub(crate) const TIMER_ABSTIME: i32 = 4; /// - `CLOCK_THREAD_CPUTIME_ID` /// - `CLOCK_MONOTONIC` #[hermit_macro::system] -pub unsafe extern "C" fn sys_clock_getres(clock_id: u64, res: *mut timespec) -> i32 { +pub unsafe extern "C" fn sys_clock_getres(clock_id: clockid_t, res: *mut timespec) -> i32 { assert!( !res.is_null(), "sys_clock_getres called with a zero res parameter" @@ -49,7 +52,7 @@ pub unsafe extern "C" fn sys_clock_getres(clock_id: u64, res: *mut timespec) -> /// - `CLOCK_REALTIME` /// - `CLOCK_MONOTONIC` #[hermit_macro::system] -pub unsafe extern "C" fn sys_clock_gettime(clock_id: u64, tp: *mut timespec) -> i32 { +pub unsafe extern "C" fn sys_clock_gettime(clock_id: clockid_t, tp: *mut timespec) -> i32 { assert!( !tp.is_null(), "sys_clock_gettime called with a zero tp parameter" @@ -86,7 +89,7 @@ pub unsafe extern "C" fn sys_clock_gettime(clock_id: u64, tp: *mut timespec) -> /// - `CLOCK_MONOTONIC` #[hermit_macro::system] pub unsafe extern "C" fn sys_clock_nanosleep( - clock_id: u64, + clock_id: clockid_t, flags: i32, rqtp: *const timespec, _rmtp: *mut timespec, @@ -122,7 +125,7 @@ pub unsafe extern "C" fn sys_clock_nanosleep( } #[hermit_macro::system] -pub unsafe extern "C" fn sys_clock_settime(_clock_id: u64, _tp: *const timespec) -> i32 { +pub unsafe extern "C" fn sys_clock_settime(_clock_id: clockid_t, _tp: *const timespec) -> i32 { // We don't support setting any clocks yet. debug!("sys_clock_settime is unimplemented, returning -EINVAL"); -EINVAL