Skip to content

Commit

Permalink
feat: upgrade dep
Browse files Browse the repository at this point in the history
  • Loading branch information
Godones committed May 20, 2024
1 parent 6fe9e7b commit d4ec9cc
Show file tree
Hide file tree
Showing 25 changed files with 222 additions and 197 deletions.
194 changes: 100 additions & 94 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions kernel/src/fs/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub fn sys_mount(
);
let find = vfs::system_support_fs(&fs_type).ok_or(LinuxErrno::EINVAL)?;
let path = VfsPath::new(vfs::system_root_fs(), system_root_fs());
let fs_root = match find.fs_name() {
let fs_root = match find.fs_name().as_str() {
name @ ("tmpfs" | "ramfs" | "fat32") => {
let fs = vfs::system_support_fs(name).unwrap();
let dev = if name.eq("fat32") {
Expand Down Expand Up @@ -365,7 +365,7 @@ pub fn sys_writev(fd: usize, iovec: usize, iovcnt: usize) -> AlienResult<isize>
continue;
}
let len = iov.len;
let buf = process.transfer_buffer(base, len);
let buf = process.transfer_buffer(base as *mut u8, len);
for b in buf.iter() {
let r = file.write(b)?;
count += r;
Expand Down Expand Up @@ -394,7 +394,7 @@ pub fn sys_readv(fd: usize, iovec: usize, iovcnt: usize) -> AlienResult<isize> {
continue;
}
let len = iov.len;
let mut buf = task.transfer_buffer(base, len);
let mut buf = task.transfer_buffer(base as *mut u8, len);
for b in buf.iter_mut() {
info!("read file: {:?}, len:{:?}", fd, b.len());
let r = file.read(b)?;
Expand Down
2 changes: 1 addition & 1 deletion kernel/src/fs/control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const FD_CLOEXEC: usize = 1;
pub fn fcntl(fd: usize, cmd: usize, arg: usize) -> AlienResult<isize> {
let task = current_task().unwrap();
let file = task.get_file(fd).ok_or(LinuxErrno::EBADF)?;
let cmd = Fcntl64Cmd::try_from(cmd).map_err(|_| LinuxErrno::EINVAL)?;
let cmd = Fcntl64Cmd::try_from(cmd as u32).map_err(|_| LinuxErrno::EINVAL)?;
info!("fcntl:{:?} {:?} ", cmd, arg);
match cmd {
Fcntl64Cmd::F_DUPFD => {
Expand Down
27 changes: 18 additions & 9 deletions kernel/src/ipc/signal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ pub fn get_signals_from_tid(tid: usize) -> Option<Arc<Mutex<SignalReceivers>>> {
pub fn send_signal(tid: usize, signum: usize) {
if let Some(signals) = get_signals_from_tid(tid) {
// 获取目标线程(可以是自己)的 signals 数组
warn!("send signal {:?} to {}", SignalNumber::from(signum), tid);
warn!(
"send signal {:?} to {}",
SignalNumber::try_from(signum as u8),
tid
);
signals.lock().try_add_bit(signum);
}
}
Expand All @@ -62,7 +66,7 @@ pub fn sigaction(sig: usize, action: usize, old_action: usize) -> isize {
let action = action as *const SigAction;
let old_action = old_action as *mut SigAction;
// check whether sig is valid
let signum = SignalNumber::from(sig);
let signum = SignalNumber::try_from(sig as u8).unwrap();
if signum == SignalNumber::SIGSTOP
|| signum == SignalNumber::SIGKILL
|| signum == SignalNumber::ERR
Expand Down Expand Up @@ -182,7 +186,7 @@ pub fn sigprocmask(how: usize, set: usize, oldset: usize, _sig_set_size: usize)
let set_mut = task_inner.transfer_raw_ptr_mut(oldset as *mut usize);
*set_mut = signal_receivers.mask.bits();
}
let how = SigProcMaskHow::from(how);
let how = SigProcMaskHow::try_from(how).unwrap();
warn!("sigprocmask: how: {:?}, set: {:x}", how, set);
if set != 0 {
let set = task_inner.transfer_raw_ptr(set as *const usize);
Expand All @@ -196,9 +200,6 @@ pub fn sigprocmask(how: usize, set: usize, oldset: usize, _sig_set_size: usize)
SigProcMaskHow::SigSetMask => {
signal_receivers.mask = SimpleBitSet::from(*set);
}
SigProcMaskHow::Unknown => {
return LinuxErrno::EINVAL as isize;
}
}
}
let mask: Vec<SignalNumber> = signal_receivers.mask.into();
Expand All @@ -222,7 +223,11 @@ pub fn sigprocmask(how: usize, set: usize, oldset: usize, _sig_set_size: usize)
/// Reference: [kill](https://man7.org/linux/man-pages/man2/kill.2.html)
#[syscall_func(129)]
pub fn kill(pid: usize, sig: usize) -> isize {
warn!("kill pid {}, signal id {:?}", pid, SignalNumber::from(sig));
warn!(
"kill pid {}, signal id {:?}",
pid,
SignalNumber::try_from(sig as u8).unwrap()
);
if pid > 0 {
//println!("kill pid {}, signal id {}", pid, signal_id);
if sig > 0 {
Expand All @@ -244,7 +249,11 @@ pub fn kill(pid: usize, sig: usize) -> isize {
/// Reference: [tkill](https://man7.org/linux/man-pages/man2/tkill.2.html)
#[syscall_func(130)]
pub fn tkill(tid: usize, sig: usize) -> isize {
warn!("tkill tid {}, signal id {:?}", tid, SignalNumber::from(sig));
warn!(
"tkill tid {}, signal id {:?}",
tid,
SignalNumber::try_from(sig as u8).unwrap()
);
if tid > 0 && sig > 0 {
//println!("kill pid {}, signal id {}", pid, signal_id);
send_signal(tid, sig);
Expand Down Expand Up @@ -292,7 +301,7 @@ pub fn signal_handler() {
let handler = task_inner.signal_handlers.clone();
let handler = handler.lock();
if let Some(signum) = receiver.get_one_signal() {
let sig = SignalNumber::from(signum);
let sig = SignalNumber::try_from(signum as u8).unwrap();
error!("task {:?} receive signal {:?}", task.tid, sig);
match sig {
SignalNumber::SIGSEGV | SignalNumber::SIGBUS => {
Expand Down
1 change: 0 additions & 1 deletion kernel/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#![feature(atomic_from_mut)]
#![feature(ip_in_core)]
#![no_std]
#![no_main]

Expand Down
12 changes: 6 additions & 6 deletions kernel/src/mm/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use core::ops::Range;

use bitflags::bitflags;
use config::{FRAME_SIZE, PROCESS_HEAP_MAX};
use constants::{io::MapFlags, AlienResult, LinuxErrno};
use constants::{io::MMapFlags, AlienResult, LinuxErrno};
use page_table::{
addr::{align_up_4k, VirtAddr},
pte::MappingFlags,
Expand Down Expand Up @@ -58,7 +58,7 @@ pub struct MMapRegion {
/// The protection flags of the mapping
pub prot: ProtFlags,
/// The flags of the mapping
pub flags: MapFlags,
pub flags: MMapFlags,
/// The file descriptor to map
pub fd: Option<Arc<dyn File>>,
/// The offset in the file to start from
Expand Down Expand Up @@ -121,7 +121,7 @@ impl MMapRegion {
len: usize,
map_len: usize,
prot: ProtFlags,
flags: MapFlags,
flags: MMapFlags,
fd: Option<Arc<dyn File>>,
offset: usize,
) -> Self {
Expand Down Expand Up @@ -152,7 +152,7 @@ impl MMapRegion {
pub fn set_prot(&mut self, prot: ProtFlags) {
self.prot = prot;
}
pub fn set_flags(&mut self, flags: MapFlags) {
pub fn set_flags(&mut self, flags: MMapFlags) {
self.flags = flags;
}
}
Expand All @@ -174,7 +174,7 @@ pub fn do_munmap(start: usize, len: usize) -> isize {
/// + `start`: 所要创建的映射区的起始地址。当该值为0时,内核将自动为其分配一段内存空间创建内存映射。该值在函数运行过程中将被调整为与4K对齐。
/// + `len`: 指明所要创建的映射区的长度。该值在函数运行过程中将被调整为与4K对齐。
/// + `prot`: 指明创建内存映射区的初始保护位。具体可见[`ProtFlags`]。
/// + `flags`: 指明mmap操作的相关设置。具体可见[`MapFlags`]。
/// + `flags`: 指明mmap操作的相关设置。具体可见[`MMapFlags`]。
/// + `fd`: 指明要创建内存映射的文件的文件描述符。
/// + `offset`: 将从文件中偏移量为`offset`处开始映射。该值需要和4K对齐。
///
Expand All @@ -192,7 +192,7 @@ pub fn do_mmap(
let process = current_task().unwrap();
let mut process_inner = process.access_inner();
let prot = ProtFlags::from_bits_truncate(prot);
let flags = MapFlags::from_bits_truncate(flags);
let flags = MMapFlags::from_bits_truncate(flags);
warn!(
"mmap: start: {:#x}, len: {:#x}, prot: {:?}, flags: {:?}, fd: {}, offset: {:#x}",
start, len, prot, flags, fd, offset
Expand Down
5 changes: 3 additions & 2 deletions kernel/src/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
use core::cmp::min;

use constants::{
sys::{Rusage, RusageFlag, Sysinfo, SyslogAction, TimeVal},
sys::{Rusage, RusageFlag, Sysinfo, SyslogAction},
time::TimeVal,
AlienResult, LinuxErrno,
};
use syscall_table::syscall_func;
Expand Down Expand Up @@ -209,7 +210,7 @@ pub fn getrusage(who: isize, usage: usize) -> AlienResult<isize> {
info!("getrusage: who: {:?}, usage: {}", who, usage);
let task = current_task().unwrap();
let static_info = task.access_inner().statistical_data().clone();
let mut task_usage = Rusage::new();
let mut task_usage = Rusage::default();
task_usage.ru_utime = TimeVal::from_freq(static_info.tms_utime);
task_usage.ru_stime = TimeVal::from_freq(static_info.tms_stime);
task.access_inner()
Expand Down
18 changes: 9 additions & 9 deletions kernel/src/task/cpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use constants::{
ipc::FutexOp,
signal::SignalNumber,
task::{CloneFlags, WaitOptions},
AlienError, AlienResult, PrLimit, PrLimitRes,
AlienError, AlienResult, PrLimitResType, RLimit64,
};
use ksync::Mutex;
use log::{info, warn};
Expand Down Expand Up @@ -266,7 +266,7 @@ pub fn clone(flag: usize, stack: usize, ptid: usize, tls: usize, ctid: usize) ->
let clone_flag = CloneFlags::from_bits_truncate(flag as u32);
// check whether flag include signal
let sig = flag & 0xff;
let sig = SignalNumber::from(sig);
let sig = SignalNumber::try_from(sig as u8).unwrap();
let mut task = current_task().unwrap();

let child_num = task.access_inner().children.len();
Expand Down Expand Up @@ -426,23 +426,23 @@ pub fn prlimit64(pid: usize, resource: usize, new_limit: *const u8, old_limit: *
assert!(pid == 0 || pid == current_task().unwrap().get_pid() as usize);
let task = current_task().unwrap();
let mut inner = task.access_inner();
if let Ok(resource) = PrLimitRes::try_from(resource) {
if let Ok(resource) = PrLimitResType::try_from(resource) {
if !old_limit.is_null() {
let limit = inner.get_prlimit(resource);
warn!("get rlimit nofile to {:?}", limit);
inner.copy_to_user(&limit, old_limit as *mut PrLimit);
inner.copy_to_user(&limit, old_limit as *mut RLimit64);
}
match resource {
PrLimitRes::RlimitStack => {}
PrLimitRes::RlimitNofile => {
PrLimitResType::RlimitStack => {}
PrLimitResType::RlimitNofile => {
if !new_limit.is_null() {
let mut limit = PrLimit::new(0, 0);
inner.copy_from_user(new_limit as *const PrLimit, &mut limit);
let mut limit = RLimit64::new(0, 0);
inner.copy_from_user(new_limit as *const RLimit64, &mut limit);
warn!("set rlimit nofile to {:?}", limit);
inner.set_prlimit(resource, limit);
}
}
PrLimitRes::RlimitAs => {}
PrLimitResType::RlimitAs => {}
}
}
0
Expand Down
45 changes: 23 additions & 22 deletions kernel/src/task/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@ use bit_field::BitField;
use config::*;
use constants::{
aux::*,
io::MapFlags,
io::MMapFlags,
ipc::RobustList,
signal::{SignalHandlers, SignalNumber, SignalReceivers, SignalUserContext},
sys::TimeVal,
task::CloneFlags,
time::TimerType,
AlienError, AlienResult, LinuxErrno, PrLimit, PrLimitRes,
time::{TimeVal, TimerType},
AlienError, AlienResult, LinuxErrno, PrLimitResType, RLimit64,
};
use gmanager::MinimalManager;
use ksync::{Mutex, MutexGuard};
Expand Down Expand Up @@ -161,7 +160,7 @@ impl TaskTimer {
/// 清除当前的计数器信息,将 timer_remained 置为 0
pub fn clear(&mut self) {
self.timer_type = TimerType::NONE;
self.timer_interval = TimeVal::new();
self.timer_interval = TimeVal::default();
self.timer_remained = 0;
self.expired = false;
}
Expand All @@ -172,7 +171,7 @@ impl Default for TaskTimer {
fn default() -> Self {
Self {
timer_type: TimerType::NONE,
timer_interval: TimeVal::new(),
timer_interval: TimeVal::default(),
timer_remained: 0,
start: 0,
expired: false,
Expand Down Expand Up @@ -546,26 +545,28 @@ impl TaskInner {
}

/// 获取当前进程对于资源的限制
pub fn get_prlimit(&self, resource: PrLimitRes) -> PrLimit {
pub fn get_prlimit(&self, resource: PrLimitResType) -> RLimit64 {
match resource {
PrLimitRes::RlimitStack => PrLimit::new(USER_STACK_SIZE as u64, USER_STACK_SIZE as u64),
PrLimitRes::RlimitNofile => {
PrLimitResType::RlimitStack => {
RLimit64::new(USER_STACK_SIZE as u64, USER_STACK_SIZE as u64)
}
PrLimitResType::RlimitNofile => {
let max_fd = self.fd_table.lock().max();
PrLimit::new(max_fd as u64, max_fd as u64)
RLimit64::new(max_fd as u64, max_fd as u64)
}
PrLimitRes::RlimitAs => PrLimit::new(u64::MAX, u64::MAX),
PrLimitResType::RlimitAs => RLimit64::new(u64::MAX, u64::MAX),
}
}

/// 设置当前进程对于资源的限制
pub fn set_prlimit(&mut self, resource: PrLimitRes, value: PrLimit) {
pub fn set_prlimit(&mut self, resource: PrLimitResType, value: RLimit64) {
match resource {
PrLimitRes::RlimitStack => {}
PrLimitRes::RlimitNofile => {
PrLimitResType::RlimitStack => {}
PrLimitResType::RlimitNofile => {
let new_max_fd = value.rlim_cur;
self.fd_table.lock().set_max(new_max_fd as usize);
}
PrLimitRes::RlimitAs => {}
PrLimitResType::RlimitAs => {}
}
}

Expand Down Expand Up @@ -913,7 +914,7 @@ impl TaskInner {
}
// 到此说明计时器已经到时间了,更新计时器
// 如果是 one-shot 计时器,则 timer_interval_us == 0,这样赋值也恰好是符合语义的
self.timer.timer_remained = if self.timer.timer_interval == TimeVal::new() {
self.timer.timer_remained = if self.timer.timer_interval == TimeVal::default() {
0
} else {
self.timer.start = now;
Expand Down Expand Up @@ -980,7 +981,7 @@ impl TaskInner {
/// + `start`: 所要创建的映射区的起始地址。当该值为0时,内核将自动为其分配一段内存空间创建内存映射。该值在函数运行过程中将被调整为与4K对齐。
/// + `len`: 指明所要创建的映射区的长度。该值在函数运行过程中将被调整为与4K对齐。
/// + `prot`: 指明创建内存映射区的初始保护位。具体可见[`ProtFlags`]。
/// + `flags`: 指明mmap操作的相关设置。具体可见[`MapFlags`]。
/// + `flags`: 指明mmap操作的相关设置。具体可见[`MMapFlags`]。
/// + `fd`: 指明要创建内存映射的文件的文件描述符。
/// + `offset`: 将从文件中偏移量为`offset`处开始映射。该值需要和4K对齐。
///
Expand All @@ -990,12 +991,12 @@ impl TaskInner {
start: usize,
len: usize,
prot: ProtFlags,
flags: MapFlags,
flags: MMapFlags,
fd: usize,
offset: usize,
) -> AlienResult<usize> {
// start == 0 表明需要OS为其找一段内存,而 MAP_FIXED 表明必须 mmap 在固定位置。两者是冲突的
if start == 0 && flags.contains(MapFlags::MAP_FIXED) {
if start == 0 && flags.contains(MMapFlags::MAP_FIXED) {
return Err(LinuxErrno::EINVAL);
}

Expand All @@ -1005,7 +1006,7 @@ impl TaskInner {
}

// not map to file
let fd = if flags.contains(MapFlags::MAP_ANONYMOUS) {
let fd = if flags.contains(MMapFlags::MAP_ANONYMOUS) {
None
} else {
let file = self
Expand Down Expand Up @@ -1033,7 +1034,7 @@ impl TaskInner {
start = 0x1000;
}
start..start + len
} else if flags.contains(MapFlags::MAP_FIXED) {
} else if flags.contains(MMapFlags::MAP_FIXED) {
let len = align_up_4k(len);
if start > self.heap.lock().start {
error!("mmap fixed address conflict with heap");
Expand Down Expand Up @@ -1296,7 +1297,7 @@ impl TaskInner {
AlienError::EAGAIN
} else {
error!("do_store_page_fault panic :{:#x}", o_addr);
AlienError::ETMP
AlienError::EPERM
}
})?;
// .expect(format!("addr:{:#x}", addr).as_str());
Expand Down
Loading

0 comments on commit d4ec9cc

Please sign in to comment.