Modify the import of modules in kernel to remove dependencies of lib.rs
This commit is contained in:
parent
06f798908a
commit
9a0f63b33e
|
|
@ -1,8 +1,9 @@
|
|||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
use super::{Events, EventsFilter};
|
||||
use crate::prelude::*;
|
||||
|
||||
crate::bitflags! {
|
||||
bitflags! {
|
||||
pub struct IoEvents: u32 {
|
||||
const IN = 0x0001;
|
||||
const PRI = 0x0002;
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ use crate::{
|
|||
},
|
||||
},
|
||||
prelude::*,
|
||||
Result,
|
||||
};
|
||||
|
||||
/// An inode abstraction used in the cgroup file system.
|
||||
|
|
|
|||
|
|
@ -351,7 +351,7 @@ impl CgroupNode {
|
|||
/// This will succeed only if the cgroup node is empty and is alive.
|
||||
/// Here, a cgroup node is considered empty if it has no child nodes and no
|
||||
/// processes bound to it.
|
||||
pub(super) fn mark_as_dead(&self) -> crate::Result<()> {
|
||||
pub(super) fn mark_as_dead(&self) -> crate::prelude::Result<()> {
|
||||
let mut inner = self.inner.write();
|
||||
let Some(inner_ref) = inner.as_ref() else {
|
||||
return_errno_with_message!(Errno::ENOENT, "the cgroup node is already dead");
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ use crate::{
|
|||
FileSystem, Inode, InodeMode, Metadata,
|
||||
},
|
||||
},
|
||||
Result,
|
||||
prelude::*,
|
||||
};
|
||||
|
||||
/// An inode abstraction used in the `ConfigFs`.
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ use crate::{
|
|||
utils::{mkmod, AccessMode, OpenArgs},
|
||||
},
|
||||
prelude::*,
|
||||
thread::kernel_thread::ThreadOptions,
|
||||
};
|
||||
|
||||
fn start_block_device(device_name: &str) -> Result<Arc<dyn BlockDevice>> {
|
||||
|
|
@ -47,7 +48,7 @@ fn start_block_device(device_name: &str) -> Result<Arc<dyn BlockDevice>> {
|
|||
virtio_block_device.handle_requests();
|
||||
}
|
||||
};
|
||||
crate::ThreadOptions::new(task_fn).spawn();
|
||||
ThreadOptions::new(task_fn).spawn();
|
||||
Ok(device)
|
||||
} else {
|
||||
return_errno_with_message!(Errno::ENOENT, "Device does not exist")
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ use crate::{
|
|||
utils::{mkmod, Inode},
|
||||
},
|
||||
prelude::*,
|
||||
Process,
|
||||
process::Process,
|
||||
};
|
||||
|
||||
/// Represents the inode at `/proc/[pid]/task/[tid]/environ` (and also `/proc/[pid]/environ`).
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ use crate::{
|
|||
utils::{mkmod, Inode},
|
||||
},
|
||||
prelude::*,
|
||||
Process,
|
||||
process::Process,
|
||||
};
|
||||
|
||||
/// Represents the inode at `/proc/[pid]/task/[tid]/mem` (and also `/proc/[pid]/mem`).
|
||||
|
|
|
|||
|
|
@ -22,9 +22,8 @@ use crate::{
|
|||
utils::{mkmod, DirEntryVecExt, Inode},
|
||||
},
|
||||
prelude::*,
|
||||
process::{posix_thread::AsPosixThread, task_set::TidEvent},
|
||||
process::{posix_thread::AsPosixThread, task_set::TidEvent, Process},
|
||||
thread::{AsThread, Thread, Tid},
|
||||
Process,
|
||||
};
|
||||
|
||||
mod cgroup;
|
||||
|
|
|
|||
|
|
@ -127,7 +127,7 @@ impl FsRegistry {
|
|||
}
|
||||
|
||||
/// Registers a file system control interface.
|
||||
fn register(&self, new_type: &'static dyn FsType) -> crate::Result<()> {
|
||||
fn register(&self, new_type: &'static dyn FsType) -> Result<()> {
|
||||
let mut fs_table = self.fs_table.lock();
|
||||
if fs_table.contains_key(new_type.name()) {
|
||||
return_errno_with_message!(Errno::EEXIST, "the file system type already exists");
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ use crate::{
|
|||
FileSystem, Inode, InodeMode, InodeType, Metadata,
|
||||
},
|
||||
prelude::*,
|
||||
Result,
|
||||
};
|
||||
|
||||
/// An inode abstraction used in the sysfs file system.
|
||||
|
|
|
|||
|
|
@ -11,13 +11,13 @@ use ostd::mm::{VmReader, VmWriter};
|
|||
use spin::Once;
|
||||
|
||||
/// Registers a new kernel `SysNode`.
|
||||
pub(super) fn register(config_obj: Arc<dyn SysNode>) -> crate::Result<()> {
|
||||
pub(super) fn register(config_obj: Arc<dyn SysNode>) -> crate::prelude::Result<()> {
|
||||
KERNEL_SYS_NODE_ROOT.get().unwrap().add_child(config_obj)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Unregisters a kernel `SysNode`.
|
||||
pub(super) fn unregister(name: &str) -> crate::Result<()> {
|
||||
pub(super) fn unregister(name: &str) -> crate::prelude::Result<()> {
|
||||
let _ = KERNEL_SYS_NODE_ROOT.get().unwrap().remove_child(name)?;
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,8 +28,8 @@ use crate::{
|
|||
sysfs::{self, fs::SysFs},
|
||||
utils::{mkmod, DirentVisitor, FileSystem, InodeType},
|
||||
},
|
||||
prelude::*,
|
||||
time::clocks::init_for_ktest as time_init_for_ktest,
|
||||
Result,
|
||||
};
|
||||
|
||||
// --- Mock SysTree Components ---
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ use core::sync::atomic::AtomicU16;
|
|||
|
||||
use atomic_integer_wrapper::define_atomic_version_of_integer_like_type;
|
||||
|
||||
use crate::error::Error;
|
||||
use crate::prelude::*;
|
||||
|
||||
/// A mask for the file mode of a newly-created file or directory.
|
||||
///
|
||||
|
|
@ -28,12 +28,12 @@ impl Default for FileCreationMask {
|
|||
}
|
||||
|
||||
impl TryFrom<u16> for FileCreationMask {
|
||||
type Error = crate::Error;
|
||||
type Error = Error;
|
||||
|
||||
fn try_from(value: u16) -> Result<Self, Self::Error> {
|
||||
fn try_from(value: u16) -> Result<Self> {
|
||||
if value & !Self::MASK != 0 {
|
||||
Err(Error::with_message(
|
||||
crate::Errno::EINVAL,
|
||||
Errno::EINVAL,
|
||||
"Invalid FileCreationMask.",
|
||||
))
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -21,11 +21,10 @@ use crate::{
|
|||
IoctlCmd, Metadata, MknodType, StatusFlags,
|
||||
},
|
||||
},
|
||||
prelude::{VmReader, VmWriter},
|
||||
prelude::*,
|
||||
process::{signal::PollHandle, Gid, Uid},
|
||||
return_errno, return_errno_with_message,
|
||||
time::{clocks::RealTimeCoarseClock, Clock},
|
||||
Errno, Error, Result,
|
||||
};
|
||||
|
||||
type Ino = u64;
|
||||
|
|
|
|||
|
|
@ -174,7 +174,7 @@ fn print_banner() {
|
|||
println!("{}", logo_ascii_art::get_gradient_color_version());
|
||||
}
|
||||
|
||||
pub(super) fn init_in_first_process(ctx: &Context) {
|
||||
pub(crate) fn on_first_process_startup(ctx: &Context) {
|
||||
component::init_all(InitStage::Process, component::parse_metadata!()).unwrap();
|
||||
crate::device::init_in_first_process(ctx).unwrap();
|
||||
crate::fs::init_in_first_process(ctx);
|
||||
|
|
|
|||
|
|
@ -60,10 +60,6 @@ mod util;
|
|||
mod vdso;
|
||||
mod vm;
|
||||
|
||||
use crate::{
|
||||
init::init_in_first_process, prelude::*, process::Process, thread::kernel_thread::ThreadOptions,
|
||||
};
|
||||
|
||||
#[ostd::main]
|
||||
#[controlled]
|
||||
fn main() {
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ use super::{iter_all_ifaces, Iface};
|
|||
use crate::{
|
||||
sched::{Nice, SchedPolicy},
|
||||
thread::kernel_thread::ThreadOptions,
|
||||
WaitTimeout,
|
||||
time::wait::WaitTimeout,
|
||||
};
|
||||
|
||||
pub fn init_in_first_kthread() {
|
||||
|
|
|
|||
|
|
@ -5,10 +5,10 @@ use ostd::sync::RwMutex;
|
|||
use super::SendRecvFlags;
|
||||
use crate::{
|
||||
events::IoEvents,
|
||||
prelude::*,
|
||||
process::signal::Pollee,
|
||||
return_errno_with_message,
|
||||
util::{MultiRead, MultiWrite},
|
||||
Errno, Error, Result,
|
||||
};
|
||||
|
||||
pub trait Unbound {
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ pub enum DynamicClockIdInfo {
|
|||
}
|
||||
|
||||
impl TryFrom<clockid_t> for DynamicClockIdInfo {
|
||||
type Error = crate::Error;
|
||||
type Error = Error;
|
||||
|
||||
fn try_from(value: clockid_t) -> core::prelude::v1::Result<Self, Self::Error> {
|
||||
const CPU_CLOCK_TYPE_MASK: i32 = 0b11;
|
||||
|
|
@ -129,7 +129,7 @@ pub fn read_clock(clockid: clockid_t, ctx: &Context) -> Result<Duration> {
|
|||
match dynamic_clockid_info {
|
||||
DynamicClockIdInfo::Pid(pid, clock_type) => {
|
||||
let process = process_table::get_process(pid)
|
||||
.ok_or_else(|| crate::Error::with_message(Errno::EINVAL, "invalid clock ID"))?;
|
||||
.ok_or_else(|| Error::with_message(Errno::EINVAL, "invalid clock ID"))?;
|
||||
match clock_type {
|
||||
DynamicClockType::Profiling => Ok(process.prof_clock().read_time()),
|
||||
DynamicClockType::Virtual => Ok(process.prof_clock().user_clock().read_time()),
|
||||
|
|
|
|||
|
|
@ -144,7 +144,7 @@ where
|
|||
match dynamic_clockid_info {
|
||||
DynamicClockIdInfo::Pid(pid, clock_type) => {
|
||||
let process = process_table::get_process(pid)
|
||||
.ok_or_else(|| crate::Error::with_message(Errno::EINVAL, "invalid clock id"))?;
|
||||
.ok_or_else(|| Error::with_message(Errno::EINVAL, "invalid clock id"))?;
|
||||
let process_timer_manager = process.timer_manager();
|
||||
match clock_type {
|
||||
DynamicClockType::Profiling => process_timer_manager.create_prof_timer(func),
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ pub fn create_new_user_task(
|
|||
let has_kernel_event_fn = || ctx.has_pending();
|
||||
|
||||
if is_init_process {
|
||||
crate::init_in_first_process(&ctx);
|
||||
crate::init::on_first_process_startup(&ctx);
|
||||
}
|
||||
|
||||
while !current_thread.is_exited() {
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ impl From<timeval_t> for timespec_t {
|
|||
}
|
||||
|
||||
impl TryFrom<timespec_t> for Duration {
|
||||
type Error = crate::Error;
|
||||
type Error = Error;
|
||||
|
||||
fn try_from(value: timespec_t) -> Result<Self> {
|
||||
if value.sec < 0 || value.nsec < 0 {
|
||||
|
|
@ -112,7 +112,7 @@ impl From<Duration> for timeval_t {
|
|||
}
|
||||
|
||||
impl TryFrom<timeval_t> for Duration {
|
||||
type Error = crate::Error;
|
||||
type Error = Error;
|
||||
|
||||
fn try_from(timeval: timeval_t) -> Result<Self> {
|
||||
if timeval.sec < 0 || timeval.usec < 0 {
|
||||
|
|
|
|||
Loading…
Reference in New Issue