Fix Occlum building warnings

This commit is contained in:
zongmin.gu 2021-12-06 12:34:01 +08:00 committed by Zongmin.Gu
parent 39f268891e
commit e8f262808b
6 changed files with 32 additions and 23 deletions

@ -109,7 +109,7 @@ impl ToErrno for std::alloc::AllocError {
}
}
impl ToErrno for std::alloc::LayoutErr {
impl ToErrno for std::alloc::LayoutError {
fn errno(&self) -> Errno {
EINVAL
}

@ -154,8 +154,8 @@ impl Inner {
pub fn wake(&self) {
if self
.is_woken
.compare_and_swap(false, true, Ordering::SeqCst)
== false
.compare_exchange(false, true, Ordering::SeqCst, Ordering::SeqCst)
.is_ok()
{
self.host_eventfd.write_u64(1);
}
@ -167,8 +167,8 @@ impl Inner {
.filter(|inner| {
inner
.is_woken
.compare_and_swap(false, true, Ordering::SeqCst)
== false
.compare_exchange(false, true, Ordering::SeqCst, Ordering::SeqCst)
.is_ok()
})
.map(|inner| inner.host_eventfd.host_fd())
.collect::<Vec<FileDesc>>();

@ -71,8 +71,9 @@ impl AtomicIoEvents for Atomic<IoEvents> {
let new_val = old_val & !*mask | *ready;
let success_ordering = ordering;
let failure_ordering = Ordering::Relaxed;
if let Ok(_) =
self.compare_exchange(old_val, new_val, success_ordering, failure_ordering)
if self
.compare_exchange(old_val, new_val, success_ordering, failure_ordering)
.is_ok()
{
return;
}

@ -19,5 +19,4 @@ use fs::{AsEvent, AsINodeFile, AsTimer, CreationFlags, File, FileDesc, FileRef,
use std::any::Any;
use std::convert::TryFrom;
use std::fmt;
use std::sync::atomic::spin_loop_hint;
use time::timeval_t;

@ -563,10 +563,10 @@ process_syscall_table_with_callback!(impl_fmt_syscall);
/// Generate the code that can dispatch any system call to its actual implementation function.
macro_rules! impl_dispatch_syscall {
(@do_syscall $fn:ident, $syscall:ident, $arg_i:expr, ($(,)?) -> ($($output:tt)*) ) => {
impl_dispatch_syscall!(@as_expr $fn($($output)*));
impl_dispatch_syscall!(@as_expr $fn($($output)*))
};
(@do_syscall $fn:ident, $syscall:ident, $arg_i:expr, ($_arg_name:ident : $arg_type:ty, $($more_args:tt)*) -> ($($output:tt)*)) => {
impl_dispatch_syscall!(@do_syscall $fn, $syscall, ($arg_i + 1), ($($more_args)*) -> ($($output)* ($syscall.args[$arg_i] as $arg_type),));
impl_dispatch_syscall!(@do_syscall $fn, $syscall, ($arg_i + 1), ($($more_args)*) -> ($($output)* ($syscall.args[$arg_i] as $arg_type),))
};
(@as_expr $e:expr) => { $e };

@ -52,7 +52,8 @@
use super::*;
use crate::process::{futex_wait, futex_wake};
use std::sync::atomic::{spin_loop_hint, AtomicI32, Ordering};
use std::hint;
use std::sync::atomic::{AtomicI32, Ordering};
// The implementaion of RwLock
//
@ -97,7 +98,7 @@ impl RwLockInner {
&& self.rw_lock.load(Ordering::SeqCst) != 0
&& self.rw_waiters.load(Ordering::SeqCst) == 0
{
spin_loop_hint();
hint::spin_loop();
spins -= 1;
}
@ -121,7 +122,8 @@ impl RwLockInner {
self.rw_waiters.fetch_add(1, Ordering::SeqCst);
let tmp = (val as u32 | 0x8000_0000) as i32;
self.rw_lock.compare_and_swap(val, tmp, Ordering::SeqCst);
self.rw_lock
.compare_exchange(val, tmp, Ordering::SeqCst, Ordering::SeqCst);
ret = futex_wait(&self.rw_lock as *const _ as *const i32, tmp, &None);
self.rw_waiters.fetch_sub(1, Ordering::SeqCst);
@ -148,8 +150,8 @@ impl RwLockInner {
if self
.rw_lock
.compare_and_swap(val, val + 1, Ordering::SeqCst)
== val
.compare_exchange(val, val + 1, Ordering::SeqCst, Ordering::SeqCst)
.is_ok()
{
break;
}
@ -168,7 +170,7 @@ impl RwLockInner {
&& self.rw_lock.load(Ordering::SeqCst) != 0
&& self.rw_waiters.load(Ordering::SeqCst) == 0
{
spin_loop_hint();
hint::spin_loop();
spins -= 1;
}
@ -186,7 +188,8 @@ impl RwLockInner {
self.rw_waiters.fetch_add(1, Ordering::SeqCst);
let tmp = (val as u32 | 0x8000_0000) as i32;
self.rw_lock.compare_and_swap(val, tmp, Ordering::SeqCst);
self.rw_lock
.compare_exchange(val, tmp, Ordering::SeqCst, Ordering::SeqCst);
ret = futex_wait(&self.rw_lock as *const _ as *const i32, tmp, &None);
self.rw_waiters.fetch_sub(1, Ordering::SeqCst);
@ -201,12 +204,14 @@ impl RwLockInner {
}
pub fn try_write(&self) -> Result<()> {
let val = self
if self
.rw_lock
.compare_and_swap(0, 0x7FFF_FFFF, Ordering::SeqCst);
match val {
0 => Ok(()),
_ => return_errno!(EBUSY, "the lock is held for reading or writing"),
.compare_exchange(0, 0x7FFF_FFFF, Ordering::SeqCst, Ordering::SeqCst)
.is_ok()
{
Ok(())
} else {
Err(errno!(EBUSY, "the lock is held for reading or writing"))
}
}
@ -227,7 +232,11 @@ impl RwLockInner {
_ => val - 1,
};
if self.rw_lock.compare_and_swap(val, new, Ordering::SeqCst) == val {
if self
.rw_lock
.compare_exchange(val, new, Ordering::SeqCst, Ordering::SeqCst)
.is_ok()
{
break;
}
}