1
0
mirror of https://github.com/rcore-os/rCore.git synced 2024-11-25 09:26:17 +04:00

use wrapping add to prevent panic

This commit is contained in:
function2-llx 2020-05-09 11:07:28 +08:00
parent 1aaa2aad20
commit 64957a6d2e
4 changed files with 13 additions and 7 deletions

View File

@ -252,7 +252,7 @@ impl<T: PageTableExt> MemorySet<T> {
// subset
let area = self.areas.remove(i);
area.unmap(&mut self.page_table);
i -= 1;
i = i.wrapping_sub(1);
} else if self.areas[i].start_addr >= start_addr
&& self.areas[i].start_addr < end_addr
{
@ -324,7 +324,7 @@ impl<T: PageTableExt> MemorySet<T> {
i += 1;
}
}
i += 1;
i = i.wrapping_add(1);
}
}

View File

@ -25,7 +25,9 @@ impl Condvar {
Condvar::default()
}
pub fn wait_queue_len(&self) -> usize { self.wait_queue.lock().len() }
pub fn wait_queue_len(&self) -> usize {
self.wait_queue.lock().len()
}
/// Park current thread and wait for this condvar to be notified.
#[deprecated(note = "this may leads to lost wakeup problem. please use `wait` instead.")]

View File

@ -7,7 +7,6 @@ use super::SpinNoIrqLock as Mutex;
use crate::syscall::SysError;
use core::cell::Cell;
use core::ops::Deref;
use crate::process::Pid;
struct SemaphoreInner {
pub count: isize,
@ -95,8 +94,12 @@ impl Semaphore {
self.cvar.wait_queue_len()
}
pub fn get_pid(&self) -> usize { self.lock.lock().pid }
pub fn set_pid(&self, pid: usize) { self.lock.lock().pid = pid; }
pub fn get_pid(&self) -> usize {
self.lock.lock().pid
}
pub fn set_pid(&self, pid: usize) {
self.lock.lock().pid = pid;
}
/// Set the current count
pub fn set(&self, value: isize) {

View File

@ -74,7 +74,8 @@ impl Syscall<'_> {
Ok(0)
}
IPC_STAT => {
*unsafe { self.vm().check_write_ptr(arg as *mut SemidDs)? } = *sem_array.semid_ds.lock();
*unsafe { self.vm().check_write_ptr(arg as *mut SemidDs)? } =
*sem_array.semid_ds.lock();
Ok(0)
}
_ => {