Clippy fixes
This commit is contained in:
parent
515a03b870
commit
8e0f54cb31
11
clippy.sh
11
clippy.sh
|
@ -2,15 +2,6 @@
|
|||
|
||||
set -e
|
||||
|
||||
# https://github.com/rust-lang/rust-clippy/issues/4579
|
||||
export RUSTUP_TOOLCHAIN="nightly-2019-07-19"
|
||||
rustup update "${RUSTUP_TOOLCHAIN}"
|
||||
rustup component add clippy --toolchain "${RUSTUP_TOOLCHAIN}"
|
||||
rustup component add rust-src --toolchain "${RUSTUP_TOOLCHAIN}"
|
||||
|
||||
# Cause recompilation
|
||||
touch src/lib.rs
|
||||
|
||||
export RUST_TARGET_PATH="${PWD}/targets"
|
||||
export RUSTFLAGS="-C soft-float -C debuginfo=2"
|
||||
xargo clippy --lib --release --target x86_64-unknown-none
|
||||
cargo clippy --lib --release --target x86_64-unknown-none "$@"
|
||||
|
|
|
@ -176,9 +176,9 @@ impl Madt {
|
|||
let flags = unsafe { *(sdt.data_address() as *const u32).offset(1) };
|
||||
|
||||
Some(Madt {
|
||||
sdt: sdt,
|
||||
local_address: local_address,
|
||||
flags: flags
|
||||
sdt,
|
||||
local_address,
|
||||
flags
|
||||
})
|
||||
} else {
|
||||
None
|
||||
|
|
|
@ -194,12 +194,12 @@ impl CpuInfo {
|
|||
pub fn cpu_info<W: Write>(w: &mut W) -> Result {
|
||||
let cpuinfo = CpuInfo::new();
|
||||
|
||||
write!(w, "Implementer: {}\n", cpuinfo.implementer)?;
|
||||
write!(w, "Variant: {}\n", cpuinfo.variant)?;
|
||||
write!(w, "Architecture version: {}\n", cpuinfo.architecture)?;
|
||||
write!(w, "Part Number: {}\n", cpuinfo.part_number)?;
|
||||
write!(w, "Revision: {}\n", cpuinfo.revision)?;
|
||||
write!(w, "\n")?;
|
||||
writeln!(w, "Implementer: {}", cpuinfo.implementer)?;
|
||||
writeln!(w, "Variant: {}", cpuinfo.variant)?;
|
||||
writeln!(w, "Architecture version: {}", cpuinfo.architecture)?;
|
||||
writeln!(w, "Part Number: {}", cpuinfo.part_number)?;
|
||||
writeln!(w, "Revision: {}", cpuinfo.revision)?;
|
||||
writeln!(w)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -134,7 +134,7 @@ const fn new_idt_reservations() -> [AtomicU32; 8] {
|
|||
/// Initialize the IDT for a
|
||||
pub unsafe fn init_paging_post_heap(is_bsp: bool, cpu_id: usize) {
|
||||
let mut idts_guard = IDTS.write();
|
||||
let idts_btree = idts_guard.get_or_insert_with(|| BTreeMap::new());
|
||||
let idts_btree = idts_guard.get_or_insert_with(BTreeMap::new);
|
||||
|
||||
if is_bsp {
|
||||
idts_btree.insert(cpu_id, &mut INIT_BSP_IDT);
|
||||
|
|
|
@ -131,7 +131,7 @@ const fn new_idt_reservations() -> [AtomicU64; 4] {
|
|||
/// Initialize the IDT for a
|
||||
pub unsafe fn init_paging_post_heap(is_bsp: bool, cpu_id: usize) {
|
||||
let mut idts_guard = IDTS.write();
|
||||
let idts_btree = idts_guard.get_or_insert_with(|| BTreeMap::new());
|
||||
let idts_btree = idts_guard.get_or_insert_with(BTreeMap::new);
|
||||
|
||||
if is_bsp {
|
||||
idts_btree.insert(cpu_id, &mut INIT_BSP_IDT);
|
||||
|
|
|
@ -160,7 +160,7 @@ pub unsafe fn init(
|
|||
let flush_all = map_percpu(cpu_id, KernelMapper::lock_manually(cpu_id).get_mut().expect("expected KernelMapper not to be locked re-entrant in paging::init"));
|
||||
flush_all.flush();
|
||||
|
||||
return init_tcb(cpu_id);
|
||||
init_tcb(cpu_id)
|
||||
}
|
||||
|
||||
pub unsafe fn init_ap(
|
||||
|
|
|
@ -96,9 +96,9 @@ pub unsafe extern fn kstart(args_ptr: *const KernelArgs) -> ! {
|
|||
// Initialize logger
|
||||
log::init_logger(|r| {
|
||||
use core::fmt::Write;
|
||||
let _ = write!(
|
||||
let _ = writeln!(
|
||||
super::debug::Writer::new(),
|
||||
"{}:{} -- {}\n",
|
||||
"{}:{} -- {}",
|
||||
r.target(),
|
||||
r.level(),
|
||||
r.args()
|
||||
|
|
|
@ -165,7 +165,7 @@ pub unsafe fn switch_to(prev: &mut super::Context, next: &mut super::Context) {
|
|||
// Since Arc is essentially just wraps a pointer, in this case a regular pointer (as
|
||||
// opposed to dyn or slice fat pointers), and NonNull optimization exists, map_or will
|
||||
// hopefully be optimized down to checking prev and next pointers, as next cannot be null.
|
||||
Some(ref next_space) => if prev.addr_space.as_ref().map_or(true, |prev_space| !Arc::ptr_eq(&prev_space, &next_space)) {
|
||||
Some(ref next_space) => if prev.addr_space.as_ref().map_or(true, |prev_space| !Arc::ptr_eq(prev_space, next_space)) {
|
||||
// Suppose we have two sibling threads A and B. A runs on CPU 0 and B on CPU 1. A
|
||||
// recently called yield and is now here about to switch back. Meanwhile, B is
|
||||
// currently creating a new mapping in their shared address space, for example a
|
||||
|
|
|
@ -285,7 +285,7 @@ impl<T, const ALIGN: usize> AlignedBox<T, ALIGN> {
|
|||
Ok(unsafe {
|
||||
let ptr = crate::ALLOCATOR.alloc_zeroed(Self::LAYOUT);
|
||||
if ptr.is_null() {
|
||||
return Err(Enomem)?;
|
||||
return Err(Enomem);
|
||||
}
|
||||
Self {
|
||||
inner: Unique::new_unchecked(ptr.cast()),
|
||||
|
|
|
@ -97,7 +97,7 @@ impl AddrSpace {
|
|||
// TODO: Remove reborrow? In that case, physmapped memory will need to either be
|
||||
// remapped when cloning, or be backed by a file descriptor (like
|
||||
// `memory:physical`).
|
||||
new_grant = Grant::reborrow(&grant, Page::containing_address(grant.start_address()), this_mapper, new_mapper, ())?;
|
||||
new_grant = Grant::reborrow(grant, Page::containing_address(grant.start_address()), this_mapper, new_mapper, ())?;
|
||||
}
|
||||
|
||||
new_guard.grants.insert(new_grant);
|
||||
|
|
|
@ -16,8 +16,8 @@ impl DebugDisplay {
|
|||
display,
|
||||
x: 0,
|
||||
y: 0,
|
||||
w: w,
|
||||
h: h,
|
||||
w,
|
||||
h,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ use self::display::Display;
|
|||
pub mod debug;
|
||||
pub mod display;
|
||||
|
||||
pub static FONT: &'static [u8] = include_bytes!("../../../res/unifont.font");
|
||||
pub static FONT: &[u8] = include_bytes!("../../../res/unifont.font");
|
||||
|
||||
pub static DEBUG_DISPLAY: Mutex<Option<DebugDisplay>> = Mutex::new(None);
|
||||
|
||||
|
|
|
@ -153,7 +153,7 @@ pub fn sync(reg_key: RegKey) -> Result<EventFlags> {
|
|||
let scheme = {
|
||||
let schemes = scheme::schemes();
|
||||
let scheme = schemes.get(reg_key.scheme).ok_or(Error::new(EBADF))?;
|
||||
Arc::clone(&scheme)
|
||||
Arc::clone(scheme)
|
||||
};
|
||||
|
||||
scheme.fevent(reg_key.number, flags)
|
||||
|
|
|
@ -45,7 +45,7 @@ impl ::log::Log for RedoxLogger {
|
|||
false
|
||||
}
|
||||
fn log(&self, record: &log::Record<'_>) {
|
||||
(self.log_func)(&record)
|
||||
(self.log_func)(record)
|
||||
}
|
||||
fn flush(&self) {}
|
||||
}
|
||||
|
|
|
@ -59,7 +59,7 @@ pub fn allocate_frames_complex(count: usize, flags: PhysallocFlags, strategy: Op
|
|||
strategy,
|
||||
min
|
||||
);
|
||||
return None;
|
||||
None
|
||||
}
|
||||
|
||||
/// Deallocate a range of frames frame
|
||||
|
|
|
@ -242,7 +242,7 @@ pub fn wait(pid: ContextId) -> Result<()> {
|
|||
let sessions = sessions();
|
||||
|
||||
match sessions.get(&pid) {
|
||||
Some(session) => Arc::clone(&session),
|
||||
Some(session) => Arc::clone(session),
|
||||
_ => return Ok(())
|
||||
}
|
||||
};
|
||||
|
@ -283,7 +283,7 @@ pub fn breakpoint_callback(match_flags: PtraceFlags, event: Option<PtraceEvent>)
|
|||
let sessions = sessions();
|
||||
let session = sessions.get(&context.id)?;
|
||||
|
||||
Arc::clone(&session)
|
||||
Arc::clone(session)
|
||||
};
|
||||
|
||||
let mut data = session.data.lock();
|
||||
|
|
|
@ -189,7 +189,7 @@ impl Scheme for IrqScheme {
|
|||
}
|
||||
|
||||
Handle::Avail(cpu_id, data.into_bytes(), AtomicUsize::new(0))
|
||||
} else if path_str.chars().next() == Some('/') {
|
||||
} else if path_str.starts_with('/') {
|
||||
let path_str = &path_str[1..];
|
||||
Self::open_ext_irq(flags, cpu_id, path_str)?
|
||||
} else {
|
||||
|
@ -227,7 +227,7 @@ impl Scheme for IrqScheme {
|
|||
Ok(0)
|
||||
}
|
||||
} else {
|
||||
return Err(Error::new(EINVAL));
|
||||
Err(Error::new(EINVAL))
|
||||
}
|
||||
&Handle::Bsp => {
|
||||
if buffer.len() < mem::size_of::<usize>() {
|
||||
|
@ -237,7 +237,7 @@ impl Scheme for IrqScheme {
|
|||
unsafe { *(buffer.as_mut_ptr() as *mut usize) = bsp_apic_id as usize; }
|
||||
Ok(mem::size_of::<usize>())
|
||||
} else {
|
||||
return Err(Error::new(EBADFD));
|
||||
Err(Error::new(EBADFD))
|
||||
}
|
||||
}
|
||||
&Handle::Avail(_, ref buf, ref offset) | &Handle::TopLevel(ref buf, ref offset) => {
|
||||
|
@ -262,7 +262,7 @@ impl Scheme for IrqScheme {
|
|||
offset.store(new_offset as usize, Ordering::SeqCst);
|
||||
Ok(new_offset)
|
||||
}
|
||||
_ => return Err(Error::new(ESPIPE)),
|
||||
_ => Err(Error::new(ESPIPE)),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -285,9 +285,9 @@ impl Scheme for IrqScheme {
|
|||
Ok(0)
|
||||
}
|
||||
} else {
|
||||
return Err(Error::new(EINVAL));
|
||||
Err(Error::new(EINVAL))
|
||||
}
|
||||
_ => return Err(Error::new(EBADF)),
|
||||
_ => Err(Error::new(EBADF)),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -295,8 +295,8 @@ impl Scheme for IrqScheme {
|
|||
let handles_guard = HANDLES.read();
|
||||
let handle = handles_guard.as_ref().unwrap().get(&id).ok_or(Error::new(EBADF))?;
|
||||
|
||||
match handle {
|
||||
&Handle::Irq { irq: handle_irq, .. } => {
|
||||
match *handle {
|
||||
Handle::Irq { irq: handle_irq, .. } => {
|
||||
stat.st_mode = MODE_CHR | 0o600;
|
||||
stat.st_size = mem::size_of::<usize>() as u64;
|
||||
stat.st_blocks = 1;
|
||||
|
@ -304,7 +304,7 @@ impl Scheme for IrqScheme {
|
|||
stat.st_ino = handle_irq.into();
|
||||
stat.st_nlink = 1;
|
||||
}
|
||||
&Handle::Bsp => {
|
||||
Handle::Bsp => {
|
||||
stat.st_mode = MODE_CHR | 0o400;
|
||||
stat.st_size = mem::size_of::<usize>() as u64;
|
||||
stat.st_blocks = 1;
|
||||
|
@ -312,13 +312,13 @@ impl Scheme for IrqScheme {
|
|||
stat.st_ino = INO_BSP;
|
||||
stat.st_nlink = 1;
|
||||
}
|
||||
&Handle::Avail(cpu_id, ref buf, _) => {
|
||||
Handle::Avail(cpu_id, ref buf, _) => {
|
||||
stat.st_mode = MODE_DIR | 0o700;
|
||||
stat.st_size = buf.len() as u64;
|
||||
stat.st_ino = INO_AVAIL | u64::from(cpu_id) << 32;
|
||||
stat.st_nlink = 2;
|
||||
}
|
||||
&Handle::TopLevel(ref buf, _) => {
|
||||
Handle::TopLevel(ref buf, _) => {
|
||||
stat.st_mode = MODE_DIR | 0o500;
|
||||
stat.st_size = buf.len() as u64;
|
||||
stat.st_ino = INO_TOPLEVEL;
|
||||
|
@ -341,10 +341,10 @@ impl Scheme for IrqScheme {
|
|||
let handle = handles_guard.as_ref().unwrap().get(&id).ok_or(Error::new(EBADF))?;
|
||||
|
||||
let scheme_path = match handle {
|
||||
&Handle::Irq { irq, .. } => format!("irq:{}", irq),
|
||||
&Handle::Bsp => format!("irq:bsp"),
|
||||
&Handle::Avail(cpu_id, _, _) => format!("irq:cpu-{:2x}", cpu_id),
|
||||
&Handle::TopLevel(_, _) => format!("irq:"),
|
||||
Handle::Irq { irq, .. } => format!("irq:{}", irq),
|
||||
Handle::Bsp => format!("irq:bsp"),
|
||||
Handle::Avail(cpu_id, _, _) => format!("irq:cpu-{:2x}", cpu_id),
|
||||
Handle::TopLevel(_, _) => format!("irq:"),
|
||||
}.into_bytes();
|
||||
|
||||
let mut i = 0;
|
||||
|
|
|
@ -53,7 +53,7 @@ impl Scheme for PipeScheme {
|
|||
// Clone to prevent deadlocks
|
||||
let pipe = {
|
||||
let pipes = PIPES.read();
|
||||
pipes.0.get(&id).map(|pipe| pipe.clone()).ok_or(Error::new(EBADF))?
|
||||
pipes.0.get(&id).cloned().ok_or(Error::new(EBADF))?
|
||||
};
|
||||
|
||||
pipe.read(buf)
|
||||
|
@ -63,7 +63,7 @@ impl Scheme for PipeScheme {
|
|||
// Clone to prevent deadlocks
|
||||
let pipe = {
|
||||
let pipes = PIPES.read();
|
||||
pipes.1.get(&id).map(|pipe| pipe.clone()).ok_or(Error::new(EBADF))?
|
||||
pipes.1.get(&id).cloned().ok_or(Error::new(EBADF))?
|
||||
};
|
||||
|
||||
pipe.write(buf)
|
||||
|
|
|
@ -366,7 +366,7 @@ impl ProcScheme {
|
|||
|
||||
let mut data = String::new();
|
||||
for index in target.files.read().iter().enumerate().filter_map(|(idx, val)| val.as_ref().map(|_| idx)) {
|
||||
write!(data, "{}\n", index).unwrap();
|
||||
writeln!(data, "{}", index).unwrap();
|
||||
}
|
||||
data.into_bytes().into_boxed_slice()
|
||||
}));
|
||||
|
@ -624,8 +624,8 @@ impl Scheme for ProcScheme {
|
|||
// in that case, what scheme?
|
||||
b"empty" => (Operation::AddrSpace { addrspace: new_addrspace()? }, false),
|
||||
b"exclusive" => (Operation::AddrSpace { addrspace: addrspace.write().try_clone()? }, false),
|
||||
b"mem" => (Operation::Memory { addrspace: Arc::clone(&addrspace) }, true),
|
||||
b"mmap-min-addr" => (Operation::MmapMinAddr(Arc::clone(&addrspace)), false),
|
||||
b"mem" => (Operation::Memory { addrspace: Arc::clone(addrspace) }, true),
|
||||
b"mmap-min-addr" => (Operation::MmapMinAddr(Arc::clone(addrspace)), false),
|
||||
|
||||
grant_handle if grant_handle.starts_with(b"grant-") => {
|
||||
let start_addr = usize::from_str_radix(core::str::from_utf8(&grant_handle[6..]).map_err(|_| Error::new(EINVAL))?, 16).map_err(|_| Error::new(EINVAL))?;
|
||||
|
@ -742,7 +742,7 @@ impl Scheme for ProcScheme {
|
|||
|
||||
Ok((Output { float: context.get_fx_regs() }, mem::size_of::<FloatRegisters>()))
|
||||
})?,
|
||||
RegsKind::Int => try_stop_context(info.pid, |context| match unsafe { ptrace::regs_for(&context) } {
|
||||
RegsKind::Int => try_stop_context(info.pid, |context| match unsafe { ptrace::regs_for(context) } {
|
||||
None => {
|
||||
assert!(!context.running, "try_stop_context is broken, clearly");
|
||||
println!("{}:{}: Couldn't read registers from stopped process", file!(), line!());
|
||||
|
@ -838,7 +838,7 @@ impl Scheme for ProcScheme {
|
|||
// TODO: Find a better way to switch address spaces, since they also require switching
|
||||
// the instruction and stack pointer. Maybe remove `<pid>/regs` altogether and replace it
|
||||
// with `<pid>/ctx`
|
||||
_ => return Err(Error::new(EBADF)),
|
||||
_ => Err(Error::new(EBADF)),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1043,7 +1043,7 @@ impl Scheme for ProcScheme {
|
|||
}
|
||||
Ok(buf.len())
|
||||
}
|
||||
Operation::Filetable { .. } => return Err(Error::new(EBADF)),
|
||||
Operation::Filetable { .. } => Err(Error::new(EBADF)),
|
||||
|
||||
Operation::CurrentFiletable => {
|
||||
let filetable_fd = usize::from_ne_bytes(<[u8; mem::size_of::<usize>()]>::try_from(buf).map_err(|_| Error::new(EINVAL))?);
|
||||
|
@ -1081,7 +1081,7 @@ impl Scheme for ProcScheme {
|
|||
addrspace.write().mmap_min = val;
|
||||
Ok(mem::size_of::<usize>())
|
||||
}
|
||||
_ => return Err(Error::new(EBADF)),
|
||||
_ => Err(Error::new(EBADF)),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1135,7 +1135,7 @@ impl Scheme for ProcScheme {
|
|||
_ => return Err(Error::new(EOPNOTSUPP)),
|
||||
});
|
||||
|
||||
read_from(buf, &path.as_bytes(), &mut 0)
|
||||
read_from(buf, path.as_bytes(), &mut 0)
|
||||
}
|
||||
|
||||
fn fstat(&self, id: usize, stat: &mut Stat) -> Result<usize> {
|
||||
|
@ -1328,14 +1328,14 @@ impl KernelScheme for ProcScheme {
|
|||
if let Some(before) = before { src_addr_space.grants.insert(before); }
|
||||
if let Some(after) = after { src_addr_space.grants.insert(after); }
|
||||
|
||||
dst_addr_space.mmap(requested_dst_page, grant_page_count, map.flags, |dst_page, _flags, dst_mapper, dst_flusher| Ok(Grant::transfer(middle, dst_page, src_mapper, dst_mapper, InactiveFlusher::new(), dst_flusher)?))?
|
||||
dst_addr_space.mmap(requested_dst_page, grant_page_count, map.flags, |dst_page, _flags, dst_mapper, dst_flusher| Grant::transfer(middle, dst_page, src_mapper, dst_mapper, InactiveFlusher::new(), dst_flusher))?
|
||||
} else {
|
||||
dst_addr_space.mmap(requested_dst_page, grant_page_count, map.flags, |dst_page, flags, dst_mapper, flusher| Ok(Grant::borrow(Page::containing_address(src_grant_region.start_address()), dst_page, grant_page_count, flags, None, src_mapper, dst_mapper, flusher)?))?
|
||||
};
|
||||
|
||||
Ok(result_page.start_address().data())
|
||||
}
|
||||
_ => return Err(Error::new(EBADF)),
|
||||
_ => Err(Error::new(EBADF)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -79,7 +79,7 @@ impl Scheme for RootScheme {
|
|||
let context = {
|
||||
let contexts = context::contexts();
|
||||
let context = contexts.current().ok_or(Error::new(ESRCH))?;
|
||||
Arc::downgrade(&context)
|
||||
Arc::downgrade(context)
|
||||
};
|
||||
|
||||
let id = self.next_id.fetch_add(1, Ordering::SeqCst);
|
||||
|
|
|
@ -93,7 +93,7 @@ impl Scheme for SysScheme {
|
|||
let data = entry.1()?;
|
||||
self.handles.write().insert(id, Handle {
|
||||
path: entry.0,
|
||||
data: data,
|
||||
data,
|
||||
mode: MODE_FILE | 0o444,
|
||||
seek: 0
|
||||
});
|
||||
|
|
|
@ -15,7 +15,7 @@ pub fn resource() -> Result<Vec<u8>> {
|
|||
let contexts = context::contexts();
|
||||
for (id, context_lock) in contexts.iter() {
|
||||
let context = context_lock.read();
|
||||
rows.push((*id, context.name.read().clone(), context.syscall.clone()));
|
||||
rows.push((*id, context.name.read().clone(), context.syscall));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -298,16 +298,14 @@ impl UserInner {
|
|||
// TODO: Faster, cleaner mechanism to get descriptor
|
||||
let scheme = self.scheme_id.load(Ordering::SeqCst);
|
||||
let mut desc_res = Err(Error::new(EBADF));
|
||||
for context_file_opt in context.files.read().iter() {
|
||||
if let Some(context_file) = context_file_opt {
|
||||
let (context_scheme, context_number) = {
|
||||
let desc = context_file.description.read();
|
||||
(desc.scheme, desc.number)
|
||||
};
|
||||
if context_scheme == scheme && context_number == file {
|
||||
desc_res = Ok(context_file.clone());
|
||||
break;
|
||||
}
|
||||
for context_file in context.files.read().iter().flatten() {
|
||||
let (context_scheme, context_number) = {
|
||||
let desc = context_file.description.read();
|
||||
(desc.scheme, desc.number)
|
||||
};
|
||||
if context_scheme == scheme && context_number == file {
|
||||
desc_res = Ok(context_file.clone());
|
||||
break;
|
||||
}
|
||||
}
|
||||
let desc = desc_res?;
|
||||
|
|
|
@ -43,7 +43,7 @@ impl WaitCondition {
|
|||
let context_lock = {
|
||||
let contexts = context::contexts();
|
||||
let context_lock = contexts.current().expect("WaitCondition::wait: no context");
|
||||
Arc::clone(&context_lock)
|
||||
Arc::clone(context_lock)
|
||||
};
|
||||
|
||||
{
|
||||
|
|
|
@ -24,7 +24,7 @@ pub fn file_op(a: usize, fd: FileHandle, c: usize, d: usize) -> Result<usize> {
|
|||
let scheme = {
|
||||
let schemes = scheme::schemes();
|
||||
let scheme = schemes.get(file.description.read().scheme).ok_or(Error::new(EBADF))?;
|
||||
Arc::clone(&scheme)
|
||||
Arc::clone(scheme)
|
||||
};
|
||||
|
||||
let mut packet = Packet {
|
||||
|
@ -71,7 +71,7 @@ pub fn open(path: &str, flags: usize) -> Result<FileHandle> {
|
|||
let (scheme_id, scheme) = {
|
||||
let schemes = scheme::schemes();
|
||||
let (scheme_id, scheme) = schemes.get_name(scheme_ns, scheme_name).ok_or(Error::new(ENODEV))?;
|
||||
(scheme_id, Arc::clone(&scheme))
|
||||
(scheme_id, Arc::clone(scheme))
|
||||
};
|
||||
|
||||
(scheme_id, scheme.open(reference, flags, uid, gid)?)
|
||||
|
@ -142,7 +142,7 @@ pub fn rmdir(path: &str) -> Result<usize> {
|
|||
let scheme = {
|
||||
let schemes = scheme::schemes();
|
||||
let (_scheme_id, scheme) = schemes.get_name(scheme_ns, scheme_name).ok_or(Error::new(ENODEV))?;
|
||||
Arc::clone(&scheme)
|
||||
Arc::clone(scheme)
|
||||
};
|
||||
scheme.rmdir(reference, uid, gid)
|
||||
}
|
||||
|
@ -163,7 +163,7 @@ pub fn unlink(path: &str) -> Result<usize> {
|
|||
let scheme = {
|
||||
let schemes = scheme::schemes();
|
||||
let (_scheme_id, scheme) = schemes.get_name(scheme_ns, scheme_name).ok_or(Error::new(ENODEV))?;
|
||||
Arc::clone(&scheme)
|
||||
Arc::clone(scheme)
|
||||
};
|
||||
scheme.unlink(reference, uid, gid)
|
||||
}
|
||||
|
@ -200,7 +200,7 @@ fn duplicate_file(fd: FileHandle, buf: &[u8]) -> Result<FileDescriptor> {
|
|||
let scheme = {
|
||||
let schemes = scheme::schemes();
|
||||
let scheme = schemes.get(description.scheme).ok_or(Error::new(EBADF))?;
|
||||
Arc::clone(&scheme)
|
||||
Arc::clone(scheme)
|
||||
};
|
||||
scheme.dup(description.number, buf)?
|
||||
};
|
||||
|
@ -260,7 +260,7 @@ pub fn fcntl(fd: FileHandle, cmd: usize, arg: usize) -> Result<usize> {
|
|||
let scheme = {
|
||||
let schemes = scheme::schemes();
|
||||
let scheme = schemes.get(description.scheme).ok_or(Error::new(EBADF))?;
|
||||
Arc::clone(&scheme)
|
||||
Arc::clone(scheme)
|
||||
};
|
||||
scheme.fcntl(description.number, cmd, arg)?;
|
||||
};
|
||||
|
@ -354,7 +354,7 @@ pub fn fstat(fd: FileHandle, stat: &mut Stat) -> Result<usize> {
|
|||
let scheme = {
|
||||
let schemes = scheme::schemes();
|
||||
let scheme = schemes.get(description.scheme).ok_or(Error::new(EBADF))?;
|
||||
Arc::clone(&scheme)
|
||||
Arc::clone(scheme)
|
||||
};
|
||||
// Fill in scheme number as device number
|
||||
stat.st_dev = description.scheme.into() as u64;
|
||||
|
|
|
@ -80,7 +80,7 @@ pub fn futex(addr: usize, op: usize, val: usize, val2: usize, addr2: usize) -> R
|
|||
let context_lock = {
|
||||
let contexts = context::contexts();
|
||||
let context_lock = contexts.current().ok_or(Error::new(ESRCH))?;
|
||||
Arc::clone(&context_lock)
|
||||
Arc::clone(context_lock)
|
||||
};
|
||||
|
||||
// TODO: Is the implicit SeqCst ordering too strong here?
|
||||
|
@ -127,7 +127,7 @@ pub fn futex(addr: usize, op: usize, val: usize, val2: usize, addr2: usize) -> R
|
|||
let context_lock = {
|
||||
let contexts = context::contexts();
|
||||
let context_lock = contexts.current().ok_or(Error::new(ESRCH))?;
|
||||
Arc::clone(&context_lock)
|
||||
Arc::clone(context_lock)
|
||||
};
|
||||
|
||||
{
|
||||
|
|
|
@ -67,7 +67,7 @@ pub fn exit(status: usize) -> ! {
|
|||
{
|
||||
let context_lock = context::current().expect("exit failed to find context");
|
||||
|
||||
let mut close_files;
|
||||
let close_files;
|
||||
let pid = {
|
||||
let mut context = context_lock.write();
|
||||
close_files = Arc::try_unwrap(mem::take(&mut context.files)).map_or_else(|_| Vec::new(), RwLock::into_inner);
|
||||
|
@ -91,7 +91,7 @@ pub fn exit(status: usize) -> ! {
|
|||
}
|
||||
|
||||
// Files must be closed while context is valid so that messages can be passed
|
||||
for (_fd, file_opt) in close_files.drain(..).enumerate() {
|
||||
for (_fd, file_opt) in close_files.into_iter().enumerate() {
|
||||
if let Some(file) = file_opt {
|
||||
let _ = file.close();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue