diff --git a/src/header/netdb/mod.rs b/src/header/netdb/mod.rs index 20816291f3..4f7f47e75e 100644 --- a/src/header/netdb/mod.rs +++ b/src/header/netdb/mod.rs @@ -422,7 +422,7 @@ pub unsafe extern "C" fn getnetent() -> *mut netent { n_name: NET_NAME.as_mut().unwrap().as_mut_ptr() as *mut c_char, n_aliases: net_aliases.as_mut_slice().as_mut_ptr() as *mut *mut i8, n_addrtype: AF_INET, - n_net: NET_ADDR.unwrap() as u64, + n_net: NET_ADDR.unwrap() as c_ulong, }; &mut NET_ENTRY as *mut netent } diff --git a/src/header/stdio/lookaheadreader.rs b/src/header/stdio/lookaheadreader.rs index 7b7495b0c7..54abfd1988 100644 --- a/src/header/stdio/lookaheadreader.rs +++ b/src/header/stdio/lookaheadreader.rs @@ -1,5 +1,8 @@ use super::{fseek_locked, ftell_locked, FILE, SEEK_SET}; -use crate::core_io::Read; +use crate::{ + core_io::Read, + platform::types::off_t, +}; struct LookAheadBuffer { buf: *const u8, pos: isize, @@ -40,7 +43,7 @@ impl<'a> LookAheadFile<'a> { fn look_ahead(&mut self) -> Result, i32> { let buf = &mut [0]; let seek = unsafe { ftell_locked(self.f) }; - unsafe { fseek_locked(self.f, self.look_ahead, SEEK_SET) }; + unsafe { fseek_locked(self.f, self.look_ahead as off_t, SEEK_SET) }; let ret = match self.f.read(buf) { Ok(0) => Ok(None), Ok(_) => Ok(Some(buf[0])), @@ -52,7 +55,7 @@ impl<'a> LookAheadFile<'a> { } fn commit(&mut self) { - unsafe { fseek_locked(self.f, self.look_ahead, SEEK_SET) }; + unsafe { fseek_locked(self.f, self.look_ahead as off_t, SEEK_SET) }; } } diff --git a/src/header/stdlib/mod.rs b/src/header/stdlib/mod.rs index e6d3695332..40630f1d29 100644 --- a/src/header/stdlib/mod.rs +++ b/src/header/stdlib/mod.rs @@ -1099,7 +1099,15 @@ pub unsafe extern "C" fn strtoull( endptr: *mut *mut c_char, base: c_int, ) -> c_ulonglong { - strtoul(s, endptr, base) + strto_impl!( + c_ulonglong, + false, + c_ulonglong::max_value(), + c_ulonglong::min_value(), + s, + endptr, + base + ) } #[no_mangle] @@ -1108,7 +1116,15 @@ pub unsafe extern "C" fn strtoll( endptr: *mut *mut c_char, base: c_int, ) -> c_longlong { - strtol(s, endptr, base) + strto_impl!( + c_longlong, + true, + c_longlong::max_value(), + c_longlong::min_value(), + s, + endptr, + base + ) } #[no_mangle] diff --git a/src/header/sys_select/mod.rs b/src/header/sys_select/mod.rs index 7b70fc5337..6303d5cc36 100644 --- a/src/header/sys_select/mod.rs +++ b/src/header/sys_select/mod.rs @@ -20,7 +20,7 @@ use crate::{ // fd_set is also defined in C because cbindgen is incompatible with mem::size_of booo pub const FD_SETSIZE: usize = 1024; -type bitset = BitSet<[c_ulong; FD_SETSIZE / (8 * mem::size_of::())]>; +type bitset = BitSet<[u64; FD_SETSIZE / (8 * mem::size_of::())]>; #[repr(C)] pub struct fd_set { diff --git a/src/header/sys_time/mod.rs b/src/header/sys_time/mod.rs index 467fbf2e5e..edb2fc92d2 100644 --- a/src/header/sys_time/mod.rs +++ b/src/header/sys_time/mod.rs @@ -60,11 +60,11 @@ pub unsafe extern "C" fn utimes(path: *const c_char, times: *const timeval) -> c let times_spec = [ timespec { tv_sec: (*times.offset(0)).tv_sec, - tv_nsec: ((*times.offset(0)).tv_usec as i64) * 1000, + tv_nsec: ((*times.offset(0)).tv_usec as c_long) * 1000, }, timespec { tv_sec: (*times.offset(1)).tv_sec, - tv_nsec: ((*times.offset(1)).tv_usec as i64) * 1000, + tv_nsec: ((*times.offset(1)).tv_usec as c_long) * 1000, }, ]; Sys::utimens(path, times_spec.as_ptr()) diff --git a/src/header/time/mod.rs b/src/header/time/mod.rs index 947bc241d3..dce14c03eb 100644 --- a/src/header/time/mod.rs +++ b/src/header/time/mod.rs @@ -23,7 +23,7 @@ pub struct timespec { impl<'a> From<&'a timespec> for syscall::TimeSpec { fn from(tp: ×pec) -> Self { Self { - tv_sec: tp.tv_sec, + tv_sec: tp.tv_sec as i64, tv_nsec: tp.tv_nsec as i32, } } @@ -370,8 +370,10 @@ pub unsafe extern "C" fn mktime(t: *mut tm) -> time_t { day += MONTH_DAYS[leap][month as usize] as i64; } - -(day * (60 * 60 * 24) + ( + -(day * (60 * 60 * 24) - (((*t).tm_hour as i64) * (60 * 60) + ((*t).tm_min as i64) * 60 + (*t).tm_sec as i64)) + ) as time_t } else { while year > 1970 { year -= 1; @@ -383,10 +385,12 @@ pub unsafe extern "C" fn mktime(t: *mut tm) -> time_t { day += MONTH_DAYS[leap][month as usize] as i64; } - day * (60 * 60 * 24) + ( + day * (60 * 60 * 24) + ((*t).tm_hour as i64) * (60 * 60) + ((*t).tm_min as i64) * 60 + (*t).tm_sec as i64 + ) as time_t } } diff --git a/src/header/unistd/mod.rs b/src/header/unistd/mod.rs index dd8658e11f..49169fa69c 100644 --- a/src/header/unistd/mod.rs +++ b/src/header/unistd/mod.rs @@ -603,7 +603,7 @@ pub extern "C" fn setuid(uid: uid_t) -> c_int { #[no_mangle] pub extern "C" fn sleep(seconds: c_uint) -> c_uint { let rqtp = timespec { - tv_sec: seconds as i64, + tv_sec: seconds as c_long, tv_nsec: 0, }; let rmtp = ptr::null_mut(); @@ -731,8 +731,8 @@ pub unsafe extern "C" fn unlink(path: *const c_char) -> c_int { #[no_mangle] pub extern "C" fn usleep(useconds: useconds_t) -> c_int { let rqtp = timespec { - tv_sec: (useconds / 1_000_000) as i64, - tv_nsec: ((useconds % 1_000_000) * 1000) as i64, + tv_sec: (useconds / 1_000_000) as c_long, + tv_nsec: ((useconds % 1_000_000) * 1000) as c_long, }; let rmtp = ptr::null_mut(); Sys::nanosleep(&rqtp, rmtp) diff --git a/src/platform/pte.rs b/src/platform/pte.rs index cdbbe3a6be..ee70a6e68f 100644 --- a/src/platform/pte.rs +++ b/src/platform/pte.rs @@ -14,7 +14,7 @@ use crate::{ tcb::{Master, Tcb}, }, platform::{ - types::{c_int, c_uint, c_void, pid_t, size_t}, + types::{c_int, c_uint, c_long, c_void, pid_t, size_t}, Pal, Sys, }, sync::{Mutex, Semaphore}, @@ -253,8 +253,8 @@ pub unsafe extern "C" fn pte_osThreadSleep(msecs: c_uint) { Sys::sched_yield(); } else { let tm = timespec { - tv_sec: msecs as i64 / 1000, - tv_nsec: (msecs % 1000) as i64 * 1000000, + tv_sec: msecs as c_long / 1000, + tv_nsec: (msecs % 1000) as c_long * 1000000, }; Sys::nanosleep(&tm, ptr::null_mut()); } @@ -353,7 +353,7 @@ pub unsafe extern "C" fn pte_osSemaphorePend( clock_gettime(CLOCK_MONOTONIC, &mut time); // Add timeout to time - let timeout = *pTimeout as i64; + let timeout = *pTimeout as c_long; time.tv_sec += timeout / 1000; time.tv_nsec += (timeout % 1000) * 1_000_000; while time.tv_nsec >= 1_000_000_000 { diff --git a/src/platform/redox/mod.rs b/src/platform/redox/mod.rs index c6f66a8ca1..405b10772b 100644 --- a/src/platform/redox/mod.rs +++ b/src/platform/redox/mod.rs @@ -190,8 +190,8 @@ impl Pal for Sys { -1 => -1, _ => { unsafe { - (*tp).tv_sec = redox_tp.tv_sec; - (*tp).tv_nsec = redox_tp.tv_nsec as i64; + (*tp).tv_sec = redox_tp.tv_sec as c_long; + (*tp).tv_nsec = redox_tp.tv_nsec as c_long; }; 0 } @@ -302,9 +302,9 @@ impl Pal for Sys { if !buf.is_null() { (*buf).f_bsize = kbuf.f_bsize as c_ulong; (*buf).f_frsize = kbuf.f_bsize as c_ulong; - (*buf).f_blocks = kbuf.f_blocks; - (*buf).f_bfree = kbuf.f_bfree; - (*buf).f_bavail = kbuf.f_bavail; + (*buf).f_blocks = kbuf.f_blocks as c_ulong; + (*buf).f_bfree = kbuf.f_bfree as c_ulong; + (*buf).f_bavail = kbuf.f_bavail as c_ulong; //TODO (*buf).f_files = 0; (*buf).f_ffree = 0; @@ -702,8 +702,8 @@ impl Pal for Sys { _ => { unsafe { if !rmtp.is_null() { - (*rmtp).tv_sec = redox_rmtp.tv_sec; - (*rmtp).tv_nsec = redox_rmtp.tv_nsec as i64; + (*rmtp).tv_sec = redox_rmtp.tv_sec as c_long; + (*rmtp).tv_nsec = redox_rmtp.tv_nsec as c_long; } } 0 diff --git a/src/platform/redox/signal.rs b/src/platform/redox/signal.rs index 6032a37fcf..cfe0dc9319 100644 --- a/src/platform/redox/signal.rs +++ b/src/platform/redox/signal.rs @@ -39,9 +39,9 @@ impl PalSignal for Sys { } unsafe { - (*out).it_interval.tv_sec = spec.it_interval.tv_sec; + (*out).it_interval.tv_sec = spec.it_interval.tv_sec as c_long; (*out).it_interval.tv_usec = spec.it_interval.tv_nsec / 1000; - (*out).it_value.tv_sec = spec.it_value.tv_sec; + (*out).it_value.tv_sec = spec.it_value.tv_sec as c_long; (*out).it_value.tv_usec = spec.it_value.tv_nsec / 1000; } @@ -81,15 +81,15 @@ impl PalSignal for Sys { if count != !0 { unsafe { if !old.is_null() { - (*old).it_interval.tv_sec = spec.it_interval.tv_sec; + (*old).it_interval.tv_sec = spec.it_interval.tv_sec as c_long; (*old).it_interval.tv_usec = spec.it_interval.tv_nsec / 1000; - (*old).it_value.tv_sec = spec.it_value.tv_sec; + (*old).it_value.tv_sec = spec.it_value.tv_sec as c_long; (*old).it_value.tv_usec = spec.it_value.tv_nsec / 1000; } - spec.it_interval.tv_sec = (*new).it_interval.tv_sec; + spec.it_interval.tv_sec = (*new).it_interval.tv_sec as i64; spec.it_interval.tv_nsec = (*new).it_interval.tv_usec * 1000; - spec.it_value.tv_sec = (*new).it_value.tv_sec; + spec.it_value.tv_sec = (*new).it_value.tv_sec as i64; spec.it_value.tv_nsec = (*new).it_value.tv_usec * 1000; } diff --git a/src/platform/redox/socket.rs b/src/platform/redox/socket.rs index 6e9fee0bed..dcd0094a59 100644 --- a/src/platform/redox/socket.rs +++ b/src/platform/redox/socket.rs @@ -362,7 +362,7 @@ impl PalSocket for Sys { } let timespec = syscall::TimeSpec { - tv_sec: timeval.tv_sec, + tv_sec: timeval.tv_sec as i64, tv_nsec: timeval.tv_usec * 1000, }; diff --git a/src/platform/rlb.rs b/src/platform/rlb.rs index 95ccb2ab0b..c71426a213 100644 --- a/src/platform/rlb.rs +++ b/src/platform/rlb.rs @@ -92,7 +92,7 @@ impl RawLineBuffer { /// Seek to a byte position in the file pub fn seek(&mut self, pos: usize) -> off_t { - let ret = lseek(self.fd, pos as i64, SEEK_SET); + let ret = lseek(self.fd, pos as off_t, SEEK_SET); if ret != !0 { self.read = pos; } diff --git a/src/platform/types.rs b/src/platform/types.rs index f4a846aeb1..9c773b73aa 100644 --- a/src/platform/types.rs +++ b/src/platform/types.rs @@ -41,7 +41,13 @@ pub type uintptr_t = usize; pub type ssize_t = isize; pub type c_char = i8; +#[cfg(target_pointer_width = "32")] +pub type c_long = i32; +#[cfg(target_pointer_width = "32")] +pub type c_ulong = u32; +#[cfg(target_pointer_width = "64")] pub type c_long = i64; +#[cfg(target_pointer_width = "64")] pub type c_ulong = u64; pub type wchar_t = i32;