1
0
mirror of https://github.com/rcore-os/rCore.git synced 2025-01-19 01:07:05 +04:00

Run cargo fmt

This commit is contained in:
Jiajie Chen 2020-03-24 20:03:02 +08:00
parent 5fb1fb08c8
commit d5c0e0d58c
5 changed files with 34 additions and 30 deletions

View File

@ -3,12 +3,12 @@ mod shared_mem;
pub use self::semary::*;
pub use self::shared_mem::*;
use crate::memory::GlobalFrameAlloc;
use crate::sync::SpinLock as Mutex;
use alloc::collections::BTreeMap;
use alloc::sync::Arc;
use rcore_memory::memory_set::handler::{Shared, SharedGuard};
use crate::memory::GlobalFrameAlloc;
use crate::sync::SpinLock as Mutex;
use rcore_memory::{PAGE_SIZE, VirtAddr, PhysAddr};
use rcore_memory::{PhysAddr, VirtAddr, PAGE_SIZE};
/// Semaphore table in a process
#[derive(Default)]
@ -19,11 +19,10 @@ pub struct SemProc {
undos: BTreeMap<(SemId, SemNum), SemOp>,
}
// TODO: Remove hack
#[derive(Default)]
pub struct ShmProc {
shmIdentifiers: BTreeMap<ShmId, ShmIdentifier>
shmIdentifiers: BTreeMap<ShmId, ShmIdentifier>,
}
/// Semaphore set identifier (in a process)
@ -91,14 +90,16 @@ impl ShmProc {
let id = self.get_free_id();
let shmIdentifier = ShmIdentifier {
addr: 0,
sharedGuard: sharedGuard
sharedGuard: sharedGuard,
};
self.shmIdentifiers.insert(id, shmIdentifier);
id
}
/// Get a free ID
fn get_free_id(&self) -> ShmId {
(0..).find(|i| self.shmIdentifiers.get(i).is_none()).unwrap()
(0..)
.find(|i| self.shmIdentifiers.get(i).is_none())
.unwrap()
}
/// Get an semaphore set by `id`
pub fn get(&self, id: ShmId) -> Option<ShmIdentifier> {
@ -127,7 +128,7 @@ impl ShmProc {
impl Clone for ShmProc {
fn clone(&self) -> Self {
ShmProc {
shmIdentifiers: self.shmIdentifiers.clone()
shmIdentifiers: self.shmIdentifiers.clone(),
}
}
}
}

View File

@ -1,42 +1,46 @@
use crate::memory::{FrameAllocator, GlobalFrameAlloc};
use crate::sync::Semaphore;
use crate::sync::SpinLock as Mutex;
use alloc::{boxed::Box, collections::BTreeMap, string::String, sync::Arc, sync::Weak, vec::Vec};
use core::cell::UnsafeCell;
use lazy_static::lazy_static;
use spin::RwLock;
use rcore_memory::{VirtAddr, PhysAddr};
use rcore_memory::memory_set::handler::{Shared, SharedGuard};
use crate::memory::{GlobalFrameAlloc, FrameAllocator};
use rcore_memory::{PhysAddr, VirtAddr};
use spin::RwLock;
lazy_static! {
static ref KEY2SHM: RwLock<BTreeMap<usize, Weak<spin::Mutex<SharedGuard<GlobalFrameAlloc>>>>> = RwLock::new(BTreeMap::new());
static ref KEY2SHM: RwLock<BTreeMap<usize, Weak<spin::Mutex<SharedGuard<GlobalFrameAlloc>>>>> =
RwLock::new(BTreeMap::new());
}
#[derive(Clone)]
pub struct ShmIdentifier {
pub addr: VirtAddr,
pub sharedGuard: Arc<spin::Mutex<SharedGuard<GlobalFrameAlloc>>>
pub sharedGuard: Arc<spin::Mutex<SharedGuard<GlobalFrameAlloc>>>,
}
impl ShmIdentifier {
pub fn setAddr(&mut self, addr: VirtAddr) {
self.addr = addr;
}
pub fn new_sharedGuard(key: usize, memsize: usize) -> Arc<spin::Mutex<SharedGuard<GlobalFrameAlloc>>> {
pub fn new_sharedGuard(
key: usize,
memsize: usize,
) -> Arc<spin::Mutex<SharedGuard<GlobalFrameAlloc>>> {
let mut key2shm = KEY2SHM.write();
// found in the map
if let Some(weak_guard) = key2shm.get(&key) {
if let Some(guard) = weak_guard.upgrade() {
return guard;
}
}
let mut sharedGuard = Arc::new(spin::Mutex::new(SharedGuard::new_with_size(GlobalFrameAlloc, memsize)));
let mut sharedGuard = Arc::new(spin::Mutex::new(SharedGuard::new_with_size(
GlobalFrameAlloc,
memsize,
)));
// insert to global map
key2shm.insert(key, Arc::downgrade(&sharedGuard));
sharedGuard
}
}

View File

@ -7,10 +7,10 @@ use spin::RwLock;
pub use crate::ipc::*;
use rcore_memory::memory_set::MemoryAttr;
use rcore_memory::{PAGE_SIZE, VirtAddr, PhysAddr};
use rcore_memory::memory_set::handler::{Shared, SharedGuard};
use crate::memory::GlobalFrameAlloc;
use rcore_memory::memory_set::handler::{Shared, SharedGuard};
use rcore_memory::memory_set::MemoryAttr;
use rcore_memory::{PhysAddr, VirtAddr, PAGE_SIZE};
use super::*;
@ -81,8 +81,11 @@ impl Syscall<'_> {
}
pub fn sys_shmat(&self, id: usize, mut addr: VirtAddr, shmflg: usize) -> SysResult {
let mut shmIdentifier = self.process().shmIdentifiers.get(id).ok_or(SysError::EINVAL)?;
let mut shmIdentifier = self
.process()
.shmIdentifiers
.get(id)
.ok_or(SysError::EINVAL)?;
let mut proc = self.process();
if addr == 0 {
@ -108,9 +111,7 @@ impl Syscall<'_> {
}
pub fn sys_shmdt(&self, id: usize, addr: VirtAddr, shmflg: usize) -> SysResult {
info!(
"shmdt: addr={:#x}", addr
);
info!("shmdt: addr={:#x}", addr);
let mut proc = self.process();
let optId = proc.shmIdentifiers.getId(addr);
if let Some(id) = optId {

View File

@ -58,7 +58,6 @@ impl Syscall<'_> {
);
return Ok(addr);
}
} else {
let file = proc.get_file(fd)?;
info!("mmap path is {} ", &*file.path);

View File

@ -299,7 +299,6 @@ impl Syscall<'_> {
args[1],
args[2] /* should be shmid_ds *buf */
),*/
// system
SYS_GETPID => self.sys_getpid(),
SYS_GETTID => self.sys_gettid(),