Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

实现SystemV共享内存 #690

Merged
merged 9 commits into from
Apr 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion kernel/src/arch/x86_64/mm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,8 @@ pub fn test_buddy() {
pub struct LockedFrameAllocator;

impl FrameAllocator for LockedFrameAllocator {
unsafe fn allocate(&mut self, count: PageFrameCount) -> Option<(PhysAddr, PageFrameCount)> {
unsafe fn allocate(&mut self, mut count: PageFrameCount) -> Option<(PhysAddr, PageFrameCount)> {
count = count.next_power_of_two();
if let Some(ref mut allocator) = *INNER_ALLOCATOR.lock_irqsave() {
return allocator.allocate(count);
} else {
Expand Down
8 changes: 4 additions & 4 deletions kernel/src/driver/disk/ahci/ahci_inode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::filesystem::vfs::{
core::generate_inode_id, FilePrivateData, FileSystem, FileType, IndexNode, Metadata,
};
use crate::libs::spinlock::SpinLockGuard;
use crate::{libs::spinlock::SpinLock, time::TimeSpec};
use crate::{libs::spinlock::SpinLock, time::PosixTimeSpec};
use alloc::{
string::String,
sync::{Arc, Weak},
Expand Down Expand Up @@ -47,9 +47,9 @@ impl LockedAhciInode {
size: 0,
blk_size: 0,
blocks: 0,
atime: TimeSpec::default(),
mtime: TimeSpec::default(),
ctime: TimeSpec::default(),
atime: PosixTimeSpec::default(),
mtime: PosixTimeSpec::default(),
ctime: PosixTimeSpec::default(),
file_type: FileType::BlockDevice, // 文件夹,block设备,char设备
mode: ModeType::from_bits_truncate(0o666),
nlinks: 1,
Expand Down
8 changes: 4 additions & 4 deletions kernel/src/driver/input/ps2_mouse/ps_mouse_device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ use crate::{
rwlock::{RwLockReadGuard, RwLockWriteGuard},
spinlock::{SpinLock, SpinLockGuard},
},
time::TimeSpec,
time::PosixTimeSpec,
};

static mut PS2_MOUSE_DEVICE: Option<Arc<Ps2MouseDevice>> = None;
Expand Down Expand Up @@ -199,9 +199,9 @@ impl Ps2MouseDevice {
size: 4096,
blk_size: 0,
blocks: 0,
atime: TimeSpec::default(),
mtime: TimeSpec::default(),
ctime: TimeSpec::default(),
atime: PosixTimeSpec::default(),
mtime: PosixTimeSpec::default(),
ctime: PosixTimeSpec::default(),
file_type: FileType::CharDevice, // 文件夹,block设备,char设备
mode: ModeType::from_bits_truncate(0o644),
nlinks: 1,
Expand Down
8 changes: 4 additions & 4 deletions kernel/src/driver/keyboard/ps2_keyboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use crate::{
rwlock::RwLock,
spinlock::{SpinLock, SpinLockGuard},
},
time::TimeSpec,
time::PosixTimeSpec,
};
use system_error::SystemError;

Expand Down Expand Up @@ -83,9 +83,9 @@ impl LockedPS2KeyBoardInode {
size: 0,
blk_size: 0,
blocks: 0,
atime: TimeSpec::default(),
mtime: TimeSpec::default(),
ctime: TimeSpec::default(),
atime: PosixTimeSpec::default(),
mtime: PosixTimeSpec::default(),
ctime: PosixTimeSpec::default(),
file_type: FileType::CharDevice, // 文件夹,block设备,char设备
mode: ModeType::from_bits_truncate(0o666),
nlinks: 1,
Expand Down
4 changes: 2 additions & 2 deletions kernel/src/driver/net/dma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::arch::mm::kernel_page_flags;
use crate::arch::MMArch;

use crate::mm::kernel_mapper::KernelMapper;
use crate::mm::page::{page_manager_lock_irasave, PageFlags};
use crate::mm::page::{page_manager_lock_irqsave, PageFlags};
use crate::mm::{
allocator::page_frame::{
allocate_page_frames, deallocate_page_frames, PageFrameCount, PhysPageFrame,
Expand Down Expand Up @@ -60,7 +60,7 @@ pub unsafe fn dma_dealloc(paddr: usize, vaddr: NonNull<u8>, pages: usize) -> i32
deallocate_page_frames(
PhysPageFrame::new(PhysAddr::new(paddr)),
page_count,
&mut page_manager_lock_irasave(),
&mut page_manager_lock_irqsave(),
);
}
return 0;
Expand Down
4 changes: 2 additions & 2 deletions kernel/src/driver/rtc/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::{
subsys::SubSysPrivate,
},
init::initcall::INITCALL_SUBSYS,
time::{timekeeping::do_settimeofday64, TimeSpec},
time::{timekeeping::do_settimeofday64, PosixTimeSpec},
};

use super::{interface::rtc_read_time, register_default_rtc, sysfs::RtcGeneralDevice};
Expand Down Expand Up @@ -96,7 +96,7 @@ fn rtc_hctosys(dev: &Arc<RtcGeneralDevice>) {
}

let time = r.unwrap();
let timespec64: TimeSpec = time.into();
let timespec64: PosixTimeSpec = time.into();
let r = do_settimeofday64(timespec64);
dev.set_hc2sys_result(r);

Expand Down
6 changes: 3 additions & 3 deletions kernel/src/driver/rtc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use system_error::SystemError;

use crate::{
libs::rwlock::RwLock,
time::{Instant, TimeSpec, NSEC_PER_SEC},
time::{Instant, PosixTimeSpec, NSEC_PER_SEC},
};

use self::sysfs::RtcGeneralDevice;
Expand Down Expand Up @@ -137,7 +137,7 @@ impl RtcTime {
}
}

impl From<RtcTime> for TimeSpec {
impl From<RtcTime> for PosixTimeSpec {
fn from(val: RtcTime) -> Self {
let instant = Instant::mktime64(
val.year_real() as u32,
Expand All @@ -155,7 +155,7 @@ impl From<RtcTime> for TimeSpec {
* 存储最接近的值会减慢同步 API 的速度。因此,这里我们存储截断的值
* 并在后面加上 0.5s 的最佳猜测。
*/
TimeSpec::new(instant.secs(), (NSEC_PER_SEC >> 1).into())
PosixTimeSpec::new(instant.secs(), (NSEC_PER_SEC >> 1).into())
}
}

Expand Down
4 changes: 2 additions & 2 deletions kernel/src/driver/virtio/virtio_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::arch::mm::kernel_page_flags;
use crate::arch::MMArch;

use crate::mm::kernel_mapper::KernelMapper;
use crate::mm::page::{page_manager_lock_irasave, PageFlags};
use crate::mm::page::{page_manager_lock_irqsave, PageFlags};
use crate::mm::{
allocator::page_frame::{
allocate_page_frames, deallocate_page_frames, PageFrameCount, PhysPageFrame,
Expand Down Expand Up @@ -71,7 +71,7 @@ unsafe impl Hal for HalImpl {
deallocate_page_frames(
PhysPageFrame::new(PhysAddr::new(paddr)),
page_count,
&mut page_manager_lock_irasave(),
&mut page_manager_lock_irqsave(),
);
}
return 0;
Expand Down
14 changes: 7 additions & 7 deletions kernel/src/filesystem/devfs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::{
once::Once,
spinlock::{SpinLock, SpinLockGuard},
},
time::TimeSpec,
time::PosixTimeSpec,
};
use alloc::{
collections::BTreeMap,
Expand Down Expand Up @@ -273,9 +273,9 @@ impl DevFSInode {
size: 0,
blk_size: 0,
blocks: 0,
atime: TimeSpec::default(),
mtime: TimeSpec::default(),
ctime: TimeSpec::default(),
atime: PosixTimeSpec::default(),
mtime: PosixTimeSpec::default(),
ctime: PosixTimeSpec::default(),
file_type: dev_type_, // 文件夹
mode,
nlinks: 1,
Expand Down Expand Up @@ -363,9 +363,9 @@ impl LockedDevFSInode {
size: 0,
blk_size: 0,
blocks: 0,
atime: TimeSpec::default(),
mtime: TimeSpec::default(),
ctime: TimeSpec::default(),
atime: PosixTimeSpec::default(),
mtime: PosixTimeSpec::default(),
ctime: PosixTimeSpec::default(),
file_type,
mode,
nlinks: 1,
Expand Down
8 changes: 4 additions & 4 deletions kernel/src/filesystem/devfs/null_dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::filesystem::vfs::{
core::generate_inode_id, FilePrivateData, FileSystem, FileType, IndexNode, Metadata,
};
use crate::libs::spinlock::SpinLockGuard;
use crate::{libs::spinlock::SpinLock, time::TimeSpec};
use crate::{libs::spinlock::SpinLock, time::PosixTimeSpec};
use alloc::{
string::String,
sync::{Arc, Weak},
Expand Down Expand Up @@ -42,9 +42,9 @@ impl LockedNullInode {
size: 0,
blk_size: 0,
blocks: 0,
atime: TimeSpec::default(),
mtime: TimeSpec::default(),
ctime: TimeSpec::default(),
atime: PosixTimeSpec::default(),
mtime: PosixTimeSpec::default(),
ctime: PosixTimeSpec::default(),
file_type: FileType::CharDevice, // 文件夹,block设备,char设备
mode: ModeType::from_bits_truncate(0o666),
nlinks: 1,
Expand Down
8 changes: 4 additions & 4 deletions kernel/src/filesystem/devfs/zero_dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::filesystem::vfs::{
core::generate_inode_id, FilePrivateData, FileSystem, FileType, IndexNode, Metadata,
};
use crate::libs::spinlock::SpinLockGuard;
use crate::{libs::spinlock::SpinLock, time::TimeSpec};
use crate::{libs::spinlock::SpinLock, time::PosixTimeSpec};
use alloc::{
string::String,
sync::{Arc, Weak},
Expand Down Expand Up @@ -42,9 +42,9 @@ impl LockedZeroInode {
size: 0,
blk_size: 0,
blocks: 0,
atime: TimeSpec::default(),
mtime: TimeSpec::default(),
ctime: TimeSpec::default(),
atime: PosixTimeSpec::default(),
mtime: PosixTimeSpec::default(),
ctime: PosixTimeSpec::default(),
file_type: FileType::CharDevice, // 文件夹,block设备,char设备
mode: ModeType::from_bits_truncate(0o666),
nlinks: 1,
Expand Down
10 changes: 5 additions & 5 deletions kernel/src/filesystem/devpts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use crate::{
filesystem::vfs::{syscall::ModeType, FileType, ROOT_INODE},
init::initcall::INITCALL_FS,
libs::spinlock::{SpinLock, SpinLockGuard},
time::TimeSpec,
time::PosixTimeSpec,
};

use super::vfs::{
Expand Down Expand Up @@ -105,11 +105,11 @@ impl LockedDevPtsFSInode {
size: 0,
blk_size: 0,
blocks: 0,
atime: TimeSpec::default(),
mtime: TimeSpec::default(),
ctime: TimeSpec::default(),
atime: PosixTimeSpec::default(),
mtime: PosixTimeSpec::default(),
ctime: PosixTimeSpec::default(),
file_type: FileType::Dir,
mode: ModeType::from_bits_truncate(0x777),
mode: ModeType::from_bits_truncate(0o777),
nlinks: 1,
uid: 0,
gid: 0,
Expand Down
14 changes: 7 additions & 7 deletions kernel/src/filesystem/fat/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use crate::{
spinlock::{SpinLock, SpinLockGuard},
vec_cursor::VecCursor,
},
time::TimeSpec,
time::PosixTimeSpec,
};

use super::entry::FATFile;
Expand Down Expand Up @@ -195,9 +195,9 @@ impl LockedFATInode {
} else {
fs.bpb.total_sectors_16 as usize
},
atime: TimeSpec::default(),
mtime: TimeSpec::default(),
ctime: TimeSpec::default(),
atime: PosixTimeSpec::default(),
mtime: PosixTimeSpec::default(),
ctime: PosixTimeSpec::default(),
file_type,
mode: ModeType::from_bits_truncate(0o777),
nlinks: 1,
Expand Down Expand Up @@ -327,9 +327,9 @@ impl FATFileSystem {
} else {
bpb.total_sectors_16 as usize
},
atime: TimeSpec::default(),
mtime: TimeSpec::default(),
ctime: TimeSpec::default(),
atime: PosixTimeSpec::default(),
mtime: PosixTimeSpec::default(),
ctime: PosixTimeSpec::default(),
file_type: FileType::Dir,
mode: ModeType::from_bits_truncate(0o777),
nlinks: 1,
Expand Down
14 changes: 7 additions & 7 deletions kernel/src/filesystem/kernfs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::{
rwlock::RwLock,
spinlock::{SpinLock, SpinLockGuard},
},
time::TimeSpec,
time::PosixTimeSpec,
};

use self::callback::{KernCallbackData, KernFSCallback, KernInodePrivateData};
Expand Down Expand Up @@ -90,9 +90,9 @@ impl KernFS {
gid: 0,
blk_size: 0,
blocks: 0,
atime: TimeSpec::new(0, 0),
mtime: TimeSpec::new(0, 0),
ctime: TimeSpec::new(0, 0),
atime: PosixTimeSpec::new(0, 0),
mtime: PosixTimeSpec::new(0, 0),
ctime: PosixTimeSpec::new(0, 0),
dev_id: 0,
inode_id: generate_inode_id(),
file_type: FileType::Dir,
Expand Down Expand Up @@ -526,9 +526,9 @@ impl KernFSInode {
gid: 0,
blk_size: 0,
blocks: 0,
atime: TimeSpec::new(0, 0),
mtime: TimeSpec::new(0, 0),
ctime: TimeSpec::new(0, 0),
atime: PosixTimeSpec::new(0, 0),
mtime: PosixTimeSpec::new(0, 0),
ctime: PosixTimeSpec::new(0, 0),
dev_id: 0,
inode_id: generate_inode_id(),
file_type: file_type.into(),
Expand Down
6 changes: 3 additions & 3 deletions kernel/src/filesystem/procfs/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use core::fmt::{Display, Formatter, Result};

use alloc::string::String;

use crate::time::TimeSpec;
use crate::time::PosixTimeSpec;

// /// 日志类型
// #[derive(Default, Clone, Debug)]
Expand Down Expand Up @@ -58,7 +58,7 @@ impl From<usize> for LogLevel {
#[derive(Default, Clone, Debug)]
pub struct LogMessage {
/// 时间戳
timestamp: TimeSpec,
timestamp: PosixTimeSpec,
/// 日志级别
level: LogLevel,
// /// 日志类型
Expand All @@ -68,7 +68,7 @@ pub struct LogMessage {
}

impl LogMessage {
pub fn new(timestamp: TimeSpec, level: LogLevel, message: String) -> Self {
pub fn new(timestamp: PosixTimeSpec, level: LogLevel, message: String) -> Self {
LogMessage {
timestamp,
level,
Expand Down
14 changes: 7 additions & 7 deletions kernel/src/filesystem/procfs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use crate::{
},
mm::allocator::page_frame::FrameAllocator,
process::{Pid, ProcessManager},
time::TimeSpec,
time::PosixTimeSpec,
};

use super::vfs::{
Expand Down Expand Up @@ -314,9 +314,9 @@ impl ProcFS {
size: 0,
blk_size: 0,
blocks: 0,
atime: TimeSpec::default(),
mtime: TimeSpec::default(),
ctime: TimeSpec::default(),
atime: PosixTimeSpec::default(),
mtime: PosixTimeSpec::default(),
ctime: PosixTimeSpec::default(),
file_type: FileType::Dir,
mode: ModeType::from_bits_truncate(0o555),
nlinks: 1,
Expand Down Expand Up @@ -600,9 +600,9 @@ impl IndexNode for LockedProcFSInode {
size: 0,
blk_size: 0,
blocks: 0,
atime: TimeSpec::default(),
mtime: TimeSpec::default(),
ctime: TimeSpec::default(),
atime: PosixTimeSpec::default(),
mtime: PosixTimeSpec::default(),
ctime: PosixTimeSpec::default(),
file_type,
mode,
nlinks: 1,
Expand Down
Loading
Loading