将include目录下的rust代码转移到他们应当属于的模块中 (#96)

* 将include目录下的rust代码转移到他们应当属于的模块下。
This commit is contained in:
login 2022-11-27 14:17:36 +08:00 committed by GitHub
parent 27a97abd24
commit 6cb769c423
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 114 additions and 111 deletions

View File

@ -1,3 +0,0 @@
pub mod gfp;
pub mod printk;
pub mod signal;

View File

@ -1,86 +0,0 @@
#![allow(unused)]
// ====== 定义颜色 ======
/// 白色
pub const COLOR_WHITE: u32 = 0x00ffffff;
/// 黑色
pub const COLOR_BLACK: u32 = 0x00000000;
/// 红色
pub const COLOR_RED: u32 = 0x00ff0000;
/// 橙色
pub const COLOR_ORANGE: u32 = 0x00ff8000;
/// 黄色
pub const COLOR_YELLOW: u32 = 0x00ffff00;
/// 绿色
pub const COLOR_GREEN: u32 = 0x0000ff00;
/// 蓝色
pub const COLOR_BLUE: u32 = 0x000000ff;
/// 靛色
pub const COLOR_INDIGO: u32 = 0x0000ffff;
/// 紫色
pub const COLOR_PURPLE: u32 = 0x008000ff;
#[macro_export]
macro_rules! print {
($($arg:tt)*) => ($crate::libs::printk::__printk(format_args!($($arg)*)));
}
#[macro_export]
macro_rules! println {
() => {
$crate::print!("\n");
};
($($arg:tt)*) => ($crate::print!("{}\n", format_args!($($arg)*)));
}
/// 指定颜色,彩色输出
/// @param FRcolor 前景色
/// @param BKcolor 背景色
#[macro_export]
macro_rules! printk_color {
($FRcolor:expr, $BKcolor:expr, $($arg:tt)*) => {
use alloc;
$crate::libs::printk::PrintkWriter.__write_string_color($FRcolor, $BKcolor, alloc::fmt::format(format_args!($($arg)*)).as_str())
};
}
#[macro_export]
macro_rules! kdebug {
($($arg:tt)*) => {
$crate::libs::printk::PrintkWriter.__write_string((alloc::fmt::format(format_args!("[ DEBUG ] ({}:{})\t", file!(), line!()))+
alloc::fmt::format(format_args!($($arg)*)).as_str() + "\n").as_str())
}
}
#[macro_export]
macro_rules! kinfo {
($($arg:tt)*) => {
$crate::libs::printk::PrintkWriter.__write_string((alloc::string::String::from("[ INFO ] ")+ alloc::fmt::format(format_args!($($arg)*)).as_str() + "\n").as_str())
}
}
#[macro_export]
macro_rules! kwarn {
($($arg:tt)*) => {
$crate::libs::printk::PrintkWriter.__write_string_color($crate::include::DragonOS::printk::COLOR_YELLOW, $crate::include::DragonOS::printk::COLOR_BLACK, "[ WARN ] ");
$crate::libs::printk::PrintkWriter.__write_string((alloc::fmt::format(format_args!($($arg)*)) + "\n").as_str())
}
}
#[macro_export]
macro_rules! kerror {
($($arg:tt)*) => {
$crate::libs::printk::PrintkWriter.__write_string_color($crate::include::DragonOS::printk::COLOR_RED, $crate::include::DragonOS::printk::COLOR_BLACK, "[ ERROR ] ");
$crate::libs::printk::PrintkWriter.__write_string((alloc::fmt::format(format_args!("({}:{})\t", file!(), line!())) +
alloc::fmt::format(format_args!($($arg)*)).as_str() + "\n").as_str())
}
}
#[macro_export]
macro_rules! kBUG {
($($arg:tt)*) => {
$crate::libs::printk::PrintkWriter.__write_string_color($crate::include::DragonOS::printk::COLOR_RED, $crate::include::DragonOS::printk::COLOR_BLACK, "[ BUG ] ");
$crate::libs::printk::PrintkWriter.__write_string((alloc::fmt::format(format_args!("({}:{})\t", file!(), line!())) +
alloc::fmt::format(format_args!($($arg)*)).as_str() + "\n").as_str())
}
}

View File

@ -1,3 +1,2 @@
#![allow(non_snake_case)] #![allow(non_snake_case)]
pub mod bindings; pub mod bindings;
pub mod DragonOS;

View File

@ -1 +1,2 @@
pub mod signal; pub mod signal;
pub mod signal_types;

View File

@ -6,10 +6,7 @@ use crate::{
pid_t, process_control_block, process_find_pcb_by_pid, pt_regs, spinlock_t, EINVAL, pid_t, process_control_block, process_find_pcb_by_pid, pt_regs, spinlock_t, EINVAL,
ENOTSUP, ESRCH, PF_EXITING, PF_KTHREAD, PF_WAKEKILL, PROC_INTERRUPTIBLE, ENOTSUP, ESRCH, PF_EXITING, PF_KTHREAD, PF_WAKEKILL, PROC_INTERRUPTIBLE,
}, },
DragonOS::signal::{
si_code_val, sigaction, sigaction__union_u, sighand_struct, siginfo, signal_struct,
sigpending, sigset_t, SignalNumber, MAX_SIG_NUM,
},
}, },
kBUG, kdebug, kwarn, kBUG, kdebug, kwarn,
libs::{ libs::{
@ -23,7 +20,14 @@ use crate::{
}, },
}; };
use crate::include::DragonOS::signal::{__siginfo_union, __siginfo_union_data}; use super::signal_types::{
si_code_val, sigaction, sigaction__union_u, sighand_struct, siginfo, signal_struct,
sigpending, sigset_t, SignalNumber, MAX_SIG_NUM,
};
use super::signal_types::{__siginfo_union, __siginfo_union_data};
/// 默认信号处理程序占位符用于在sighand结构体中的action数组中占位 /// 默认信号处理程序占位符用于在sighand结构体中的action数组中占位
pub static DEFAULT_SIGACTION: sigaction = sigaction { pub static DEFAULT_SIGACTION: sigaction = sigaction {
@ -61,8 +65,8 @@ pub extern "C" fn sys_kill(regs: &pt_regs) -> u64 {
si_code: si_code_val::SI_USER as i32, si_code: si_code_val::SI_USER as i32,
si_errno: 0, si_errno: 0,
reserved: 0, reserved: 0,
_sifields: crate::include::DragonOS::signal::__sifields { _sifields: super::signal_types::__sifields {
_kill: crate::include::DragonOS::signal::__sifields__kill { _pid: pid }, _kill: super::signal_types::__sifields__kill { _pid: pid },
}, },
}, },
}, },

View File

@ -1,7 +1,95 @@
#![allow(unused)]
use crate::include::bindings::bindings::{printk_color, BLACK, WHITE}; use crate::include::bindings::bindings::{printk_color, BLACK, WHITE};
use ::core::ffi::c_char; use ::core::ffi::c_char;
use alloc::vec::Vec; use alloc::vec::Vec;
use core::fmt; use core::fmt;
// ====== 定义颜色 ======
/// 白色
pub const COLOR_WHITE: u32 = 0x00ffffff;
/// 黑色
pub const COLOR_BLACK: u32 = 0x00000000;
/// 红色
pub const COLOR_RED: u32 = 0x00ff0000;
/// 橙色
pub const COLOR_ORANGE: u32 = 0x00ff8000;
/// 黄色
pub const COLOR_YELLOW: u32 = 0x00ffff00;
/// 绿色
pub const COLOR_GREEN: u32 = 0x0000ff00;
/// 蓝色
pub const COLOR_BLUE: u32 = 0x000000ff;
/// 靛色
pub const COLOR_INDIGO: u32 = 0x0000ffff;
/// 紫色
pub const COLOR_PURPLE: u32 = 0x008000ff;
#[macro_export]
macro_rules! print {
($($arg:tt)*) => ($crate::libs::printk::__printk(format_args!($($arg)*)));
}
#[macro_export]
macro_rules! println {
() => {
$crate::print!("\n");
};
($($arg:tt)*) => ($crate::print!("{}\n", format_args!($($arg)*)));
}
/// 指定颜色,彩色输出
/// @param FRcolor 前景色
/// @param BKcolor 背景色
#[macro_export]
macro_rules! printk_color {
($FRcolor:expr, $BKcolor:expr, $($arg:tt)*) => {
use alloc;
$crate::libs::printk::PrintkWriter.__write_string_color($FRcolor, $BKcolor, alloc::fmt::format(format_args!($($arg)*)).as_str())
};
}
#[macro_export]
macro_rules! kdebug {
($($arg:tt)*) => {
$crate::libs::printk::PrintkWriter.__write_string((alloc::fmt::format(format_args!("[ DEBUG ] ({}:{})\t", file!(), line!()))+
alloc::fmt::format(format_args!($($arg)*)).as_str() + "\n").as_str())
}
}
#[macro_export]
macro_rules! kinfo {
($($arg:tt)*) => {
$crate::libs::printk::PrintkWriter.__write_string((alloc::string::String::from("[ INFO ] ")+ alloc::fmt::format(format_args!($($arg)*)).as_str() + "\n").as_str())
}
}
#[macro_export]
macro_rules! kwarn {
($($arg:tt)*) => {
$crate::libs::printk::PrintkWriter.__write_string_color($crate::libs::printk::COLOR_YELLOW, $crate::libs::printk::COLOR_BLACK, "[ WARN ] ");
$crate::libs::printk::PrintkWriter.__write_string((alloc::fmt::format(format_args!($($arg)*)) + "\n").as_str())
}
}
#[macro_export]
macro_rules! kerror {
($($arg:tt)*) => {
$crate::libs::printk::PrintkWriter.__write_string_color($crate::libs::printk::COLOR_RED, $crate::libs::printk::COLOR_BLACK, "[ ERROR ] ");
$crate::libs::printk::PrintkWriter.__write_string((alloc::fmt::format(format_args!("({}:{})\t", file!(), line!())) +
alloc::fmt::format(format_args!($($arg)*)).as_str() + "\n").as_str())
}
}
#[macro_export]
macro_rules! kBUG {
($($arg:tt)*) => {
$crate::libs::printk::PrintkWriter.__write_string_color($crate::libs::printk::COLOR_RED, $crate::libs::printk::COLOR_BLACK, "[ BUG ] ");
$crate::libs::printk::PrintkWriter.__write_string((alloc::fmt::format(format_args!("({}:{})\t", file!(), line!())) +
alloc::fmt::format(format_args!($($arg)*)).as_str() + "\n").as_str())
}
}
pub struct PrintkWriter; pub struct PrintkWriter;
impl PrintkWriter { impl PrintkWriter {

View File

@ -1,5 +1,5 @@
use crate::include::bindings::bindings::{gfp_t, kfree, kmalloc, PAGE_2M_SIZE}; use crate::include::bindings::bindings::{gfp_t, kfree, kmalloc, PAGE_2M_SIZE};
use crate::include::DragonOS::gfp::__GFP_ZERO; use super::gfp::__GFP_ZERO;
use core::alloc::{GlobalAlloc, Layout}; use core::alloc::{GlobalAlloc, Layout};

View File

@ -1 +1,2 @@
pub mod allocator; pub mod allocator;
pub mod gfp;

View File

@ -4,13 +4,13 @@ use alloc::boxed::Box;
use crate::{ use crate::{
arch::x86_64::asm::current::current_pcb, arch::x86_64::asm::current::current_pcb,
include::{ include::bindings::bindings::{
bindings::bindings::{ process_control_block, CLONE_CLEAR_SIGHAND, CLONE_SIGHAND, CLONE_THREAD, ENOMEM,
process_control_block, CLONE_CLEAR_SIGHAND, CLONE_SIGHAND, CLONE_THREAD, ENOMEM, },
}, ipc::{
DragonOS::signal::{sigaction, sighand_struct, signal_struct}, signal::DEFAULT_SIGACTION,
signal_types::{sigaction, sighand_struct, signal_struct},
}, },
ipc::signal::DEFAULT_SIGACTION,
kdebug, kdebug,
libs::{ libs::{
atomic::atomic_set, atomic::atomic_set,

View File

@ -1,11 +1,10 @@
use crate::{ use crate::{
include::{ include::bindings::bindings::{atomic_t, spinlock_t},
bindings::bindings::{atomic_t, spinlock_t},
DragonOS::signal::{sighand_struct, signal_struct, MAX_SIG_NUM},
},
ipc::signal::DEFAULT_SIGACTION, ipc::signal::DEFAULT_SIGACTION,
}; };
use crate::ipc::signal_types::{sighand_struct, signal_struct, MAX_SIG_NUM};
/// @brief 初始进程的signal结构体 /// @brief 初始进程的signal结构体
#[no_mangle] #[no_mangle]
pub static INITIAL_SIGNALS: signal_struct = signal_struct { pub static INITIAL_SIGNALS: signal_struct = signal_struct {