Replace all Arc::try_new with Arc::new
The global allocator panics when out of memory rather than returning an errors. In addition there are plenty of other places where we don't handle allocation failure anyway. At some point in the future we should systematically handle out of memory conditions, but until then let's not pretend we do and get rid of the usage of the unstable allocator_api feature that is unlikely to get stabilized any time soon.
This commit is contained in:
@@ -87,11 +87,10 @@ pub struct AddrSpaceWrapper {
|
||||
}
|
||||
impl AddrSpaceWrapper {
|
||||
pub fn new() -> Result<Arc<Self>> {
|
||||
Arc::try_new(Self {
|
||||
Ok(Arc::new(Self {
|
||||
inner: RwLock::new(AddrSpace::new()?),
|
||||
tlb_ack: AtomicU32::new(0),
|
||||
})
|
||||
.map_err(|_| Error::new(ENOMEM))
|
||||
}))
|
||||
}
|
||||
pub fn acquire_read(&self) -> RwLockReadGuard<'_, AddrSpace> {
|
||||
let my_percpu = PercpuBlock::current();
|
||||
|
||||
+2
-4
@@ -4,7 +4,6 @@
|
||||
|
||||
use alloc::{collections::BTreeSet, sync::Arc};
|
||||
use core::num::NonZeroUsize;
|
||||
use syscall::ENOMEM;
|
||||
|
||||
use crate::{
|
||||
context::memory::AddrSpaceWrapper,
|
||||
@@ -15,7 +14,7 @@ use crate::{
|
||||
ArcRwLockWriteGuard, CleanLockToken, LockToken, RwLock, RwLockReadGuard, RwLockWriteGuard,
|
||||
L0, L1, L2,
|
||||
},
|
||||
syscall::error::{Error, Result},
|
||||
syscall::error::Result,
|
||||
};
|
||||
|
||||
use self::context::Kstack;
|
||||
@@ -159,8 +158,7 @@ pub fn spawn(
|
||||
) -> Result<Arc<ContextLock>> {
|
||||
let stack = Kstack::new()?;
|
||||
|
||||
let context_lock = Arc::try_new(ContextLock::new(Context::new(owner_proc_id)?))
|
||||
.map_err(|_| Error::new(ENOMEM))?;
|
||||
let context_lock = Arc::new(ContextLock::new(Context::new(owner_proc_id)?));
|
||||
|
||||
contexts_mut(token.token()).insert(ContextRef(Arc::clone(&context_lock)));
|
||||
|
||||
|
||||
@@ -40,7 +40,6 @@
|
||||
// Ensure that all must_use results are used
|
||||
#![deny(unused_must_use)]
|
||||
#![warn(static_mut_refs)] // FIXME deny once all occurences are fixed
|
||||
#![feature(allocator_api)]
|
||||
#![feature(if_let_guard)]
|
||||
#![feature(int_roundings)]
|
||||
#![feature(iter_next_chunk)]
|
||||
|
||||
+2
-3
@@ -87,8 +87,8 @@ impl Session {
|
||||
.as_ref()?
|
||||
.upgrade()
|
||||
}
|
||||
pub fn try_new(file_id: usize) -> Result<Arc<Session>> {
|
||||
Arc::try_new(Session {
|
||||
pub fn new(file_id: usize) -> Arc<Session> {
|
||||
Arc::new(Session {
|
||||
data: Mutex::new(SessionData {
|
||||
breakpoint: None,
|
||||
events: VecDeque::new(),
|
||||
@@ -97,7 +97,6 @@ impl Session {
|
||||
tracee: WaitCondition::new(),
|
||||
tracer: WaitCondition::new(),
|
||||
})
|
||||
.map_err(|_| Error::new(ENOMEM))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-2
@@ -729,8 +729,7 @@ impl KernelScheme for ProcScheme {
|
||||
}
|
||||
let filetable = filetable.upgrade().ok_or(Error::new(EOWNERDEAD))?;
|
||||
|
||||
let new_filetable = Arc::try_new(spin::RwLock::new(filetable.read().clone()))
|
||||
.map_err(|_| Error::new(ENOMEM))?;
|
||||
let new_filetable = Arc::new(spin::RwLock::new(filetable.read().clone()));
|
||||
|
||||
handle(
|
||||
Handle {
|
||||
|
||||
Reference in New Issue
Block a user