cargo clippy & fmt
This commit is contained in:
parent
8917eb7acc
commit
b96db03e48
62 changed files with 887 additions and 938 deletions
|
@ -3,7 +3,7 @@
|
|||
|
||||
#[macro_use]
|
||||
extern crate user_lib;
|
||||
use user_lib::{fork, yield_, waitpid, exit, wait};
|
||||
use user_lib::{exit, fork, wait, waitpid, yield_};
|
||||
|
||||
const MAGIC: i32 = -0x10384;
|
||||
|
||||
|
@ -13,7 +13,9 @@ pub fn main() -> i32 {
|
|||
let pid = fork();
|
||||
if pid == 0 {
|
||||
println!("I am the child.");
|
||||
for _ in 0..7 { yield_(); }
|
||||
for _ in 0..7 {
|
||||
yield_();
|
||||
}
|
||||
exit(MAGIC);
|
||||
} else {
|
||||
println!("I am parent, fork a child pid {}", pid);
|
||||
|
@ -26,4 +28,3 @@ pub fn main() -> i32 {
|
|||
println!("exit pass.");
|
||||
0
|
||||
}
|
||||
|
||||
|
|
|
@ -41,4 +41,4 @@ pub fn main() -> i32 {
|
|||
println!("{}", color_text!(text, i));
|
||||
}
|
||||
0
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,13 +4,7 @@
|
|||
#[macro_use]
|
||||
extern crate user_lib;
|
||||
|
||||
use user_lib::{
|
||||
open,
|
||||
close,
|
||||
read,
|
||||
write,
|
||||
OpenFlags,
|
||||
};
|
||||
use user_lib::{close, open, read, write, OpenFlags};
|
||||
|
||||
#[no_mangle]
|
||||
pub fn main() -> i32 {
|
||||
|
@ -29,10 +23,7 @@ pub fn main() -> i32 {
|
|||
let read_len = read(fd, &mut buffer) as usize;
|
||||
close(fd);
|
||||
|
||||
assert_eq!(
|
||||
test_str,
|
||||
core::str::from_utf8(&buffer[..read_len]).unwrap(),
|
||||
);
|
||||
assert_eq!(test_str, core::str::from_utf8(&buffer[..read_len]).unwrap(),);
|
||||
println!("file_test passed!");
|
||||
0
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#[macro_use]
|
||||
extern crate user_lib;
|
||||
|
||||
use user_lib::{fork, wait, exit};
|
||||
use user_lib::{exit, fork, wait};
|
||||
|
||||
const MAX_CHILD: usize = 30;
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#[macro_use]
|
||||
extern crate user_lib;
|
||||
|
||||
use user_lib::{fork, wait, getpid, exit, sleep, get_time};
|
||||
use user_lib::{exit, fork, get_time, getpid, sleep, wait};
|
||||
|
||||
static NUM: usize = 30;
|
||||
|
||||
|
@ -14,7 +14,8 @@ pub fn main() -> i32 {
|
|||
let pid = fork();
|
||||
if pid == 0 {
|
||||
let current_time = get_time();
|
||||
let sleep_length = (current_time as i32 as isize) * (current_time as i32 as isize) % 1000 + 1000;
|
||||
let sleep_length =
|
||||
(current_time as i32 as isize) * (current_time as i32 as isize) % 1000 + 1000;
|
||||
println!("pid {} sleep for {} ms", getpid(), sleep_length);
|
||||
sleep(sleep_length as usize);
|
||||
println!("pid {} OK!", getpid());
|
||||
|
@ -30,4 +31,4 @@ pub fn main() -> i32 {
|
|||
assert!(wait(&mut exit_code) < 0);
|
||||
println!("forktest2 test passed!");
|
||||
0
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,4 +25,4 @@ pub fn main() -> i32 {
|
|||
println!("child process pid = {}, exit code = {}", pid, exit_code);
|
||||
0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#[macro_use]
|
||||
extern crate user_lib;
|
||||
|
||||
use user_lib::{sleep, getpid, fork, exit, yield_};
|
||||
use user_lib::{exit, fork, getpid, sleep, yield_};
|
||||
|
||||
const DEPTH: usize = 4;
|
||||
|
||||
|
|
|
@ -8,4 +8,4 @@ extern crate user_lib;
|
|||
pub fn main() -> i32 {
|
||||
println!("Hello world from user mode program!");
|
||||
0
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,19 +4,13 @@
|
|||
#[macro_use]
|
||||
extern crate user_lib;
|
||||
|
||||
use user_lib::{
|
||||
OpenFlags,
|
||||
open,
|
||||
close,
|
||||
write,
|
||||
get_time,
|
||||
};
|
||||
use user_lib::{close, get_time, open, write, OpenFlags};
|
||||
|
||||
#[no_mangle]
|
||||
pub fn main() -> i32 {
|
||||
let mut buffer = [0u8; 1024]; // 1KiB
|
||||
for i in 0..buffer.len() {
|
||||
buffer[i] = i as u8;
|
||||
for (i, ch) in buffer.iter_mut().enumerate() {
|
||||
*ch = i as u8;
|
||||
}
|
||||
let f = open("testf\0", OpenFlags::CREATE | OpenFlags::WRONLY);
|
||||
if f < 0 {
|
||||
|
@ -25,12 +19,15 @@ pub fn main() -> i32 {
|
|||
let f = f as usize;
|
||||
let start = get_time();
|
||||
let size_mb = 1usize;
|
||||
for _ in 0..1024*size_mb {
|
||||
for _ in 0..1024 * size_mb {
|
||||
write(f, &buffer);
|
||||
}
|
||||
close(f);
|
||||
let time_ms = (get_time() - start) as usize;
|
||||
let speed_kbs = size_mb * 1000000 / time_ms;
|
||||
println!("{}MiB written, time cost = {}ms, write speed = {}KiB/s", size_mb, time_ms, speed_kbs);
|
||||
println!(
|
||||
"{}MiB written, time cost = {}ms, write speed = {}KiB/s",
|
||||
size_mb, time_ms, speed_kbs
|
||||
);
|
||||
0
|
||||
}
|
||||
|
|
|
@ -4,12 +4,7 @@
|
|||
#[macro_use]
|
||||
extern crate user_lib;
|
||||
|
||||
use user_lib::{
|
||||
fork,
|
||||
wait,
|
||||
exec,
|
||||
yield_,
|
||||
};
|
||||
use user_lib::{exec, fork, wait, yield_};
|
||||
|
||||
#[no_mangle]
|
||||
fn main() -> i32 {
|
||||
|
@ -25,8 +20,7 @@ fn main() -> i32 {
|
|||
}
|
||||
println!(
|
||||
"[initproc] Released a zombie process, pid={}, exit_code={}",
|
||||
pid,
|
||||
exit_code,
|
||||
pid, exit_code,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
#![no_std]
|
||||
#![no_main]
|
||||
#![allow(clippy::needless_range_loop)]
|
||||
|
||||
#[macro_use]
|
||||
extern crate user_lib;
|
||||
|
||||
use user_lib::{fork, wait, yield_, exit, getpid, get_time};
|
||||
use user_lib::{exit, fork, get_time, getpid, wait, yield_};
|
||||
|
||||
static NUM: usize = 30;
|
||||
const N: usize = 10;
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#[macro_use]
|
||||
extern crate user_lib;
|
||||
|
||||
use user_lib::{fork, exec, wait};
|
||||
use user_lib::{exec, fork, wait};
|
||||
|
||||
#[no_mangle]
|
||||
pub fn main() -> i32 {
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#[macro_use]
|
||||
extern crate user_lib;
|
||||
|
||||
use user_lib::{sleep, exit, get_time, fork, waitpid};
|
||||
use user_lib::{exit, fork, get_time, sleep, waitpid};
|
||||
|
||||
fn sleepy() {
|
||||
let time: usize = 100;
|
||||
|
|
|
@ -13,7 +13,11 @@ pub fn main() -> i32 {
|
|||
println!("current time_msec = {}", start);
|
||||
sleep(100);
|
||||
let end = get_time();
|
||||
println!("time_msec = {} after sleeping 100 ticks, delta = {}ms!", end, end - start);
|
||||
println!(
|
||||
"time_msec = {} after sleeping 100 ticks, delta = {}ms!",
|
||||
end,
|
||||
end - start
|
||||
);
|
||||
println!("r_sleep passed!");
|
||||
0
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
extern crate user_lib;
|
||||
|
||||
fn f(d: usize) {
|
||||
println!("d = {}",d);
|
||||
println!("d = {}", d);
|
||||
f(d + 1);
|
||||
}
|
||||
|
||||
|
@ -14,4 +14,4 @@ pub fn main() -> i32 {
|
|||
println!("It should trigger segmentation fault!");
|
||||
f(0);
|
||||
0
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#![no_std]
|
||||
#![no_main]
|
||||
#![allow(clippy::println_empty_string)]
|
||||
|
||||
extern crate alloc;
|
||||
|
||||
|
@ -12,8 +13,8 @@ const DL: u8 = 0x7fu8;
|
|||
const BS: u8 = 0x08u8;
|
||||
|
||||
use alloc::string::String;
|
||||
use user_lib::{fork, exec, waitpid};
|
||||
use user_lib::console::getchar;
|
||||
use user_lib::{exec, fork, waitpid};
|
||||
|
||||
#[no_mangle]
|
||||
pub fn main() -> i32 {
|
||||
|
@ -60,4 +61,3 @@ pub fn main() -> i32 {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -32,7 +32,10 @@ pub fn main() -> i32 {
|
|||
let mut exit_code: i32 = Default::default();
|
||||
let wait_pid = waitpid(pid as usize, &mut exit_code);
|
||||
assert_eq!(pid, wait_pid);
|
||||
println!("\x1b[32mUsertests: Test {} in Process {} exited with code {}\x1b[0m", test, pid, exit_code);
|
||||
println!(
|
||||
"\x1b[32mUsertests: Test {} in Process {} exited with code {}\x1b[0m",
|
||||
test, pid, exit_code
|
||||
);
|
||||
}
|
||||
}
|
||||
println!("Usertests passed!");
|
||||
|
|
|
@ -14,4 +14,4 @@ pub fn main() -> i32 {
|
|||
}
|
||||
println!("yield pass.");
|
||||
0
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,9 +4,14 @@ use super::exit;
|
|||
fn panic_handler(panic_info: &core::panic::PanicInfo) -> ! {
|
||||
let err = panic_info.message().unwrap();
|
||||
if let Some(location) = panic_info.location() {
|
||||
println!("Panicked at {}:{}, {}", location.file(), location.line(), err);
|
||||
println!(
|
||||
"Panicked at {}:{}, {}",
|
||||
location.file(),
|
||||
location.line(),
|
||||
err
|
||||
);
|
||||
} else {
|
||||
println!("Panicked: {}", err);
|
||||
}
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,15 +5,15 @@
|
|||
|
||||
#[macro_use]
|
||||
pub mod console;
|
||||
mod syscall;
|
||||
mod lang_items;
|
||||
mod syscall;
|
||||
|
||||
extern crate alloc;
|
||||
#[macro_use]
|
||||
extern crate bitflags;
|
||||
|
||||
use syscall::*;
|
||||
use buddy_system_allocator::LockedHeap;
|
||||
use syscall::*;
|
||||
|
||||
const USER_HEAP_SIZE: usize = 32768;
|
||||
|
||||
|
@ -53,20 +53,42 @@ bitflags! {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn open(path: &str, flags: OpenFlags) -> isize { sys_open(path, flags.bits) }
|
||||
pub fn close(fd: usize) -> isize { sys_close(fd) }
|
||||
pub fn read(fd: usize, buf: &mut [u8]) -> isize { sys_read(fd, buf) }
|
||||
pub fn write(fd: usize, buf: &[u8]) -> isize { sys_write(fd, buf) }
|
||||
pub fn exit(exit_code: i32) -> ! { sys_exit(exit_code); }
|
||||
pub fn yield_() -> isize { sys_yield() }
|
||||
pub fn get_time() -> isize { sys_get_time() }
|
||||
pub fn getpid() -> isize { sys_getpid() }
|
||||
pub fn fork() -> isize { sys_fork() }
|
||||
pub fn exec(path: &str) -> isize { sys_exec(path) }
|
||||
pub fn open(path: &str, flags: OpenFlags) -> isize {
|
||||
sys_open(path, flags.bits)
|
||||
}
|
||||
pub fn close(fd: usize) -> isize {
|
||||
sys_close(fd)
|
||||
}
|
||||
pub fn read(fd: usize, buf: &mut [u8]) -> isize {
|
||||
sys_read(fd, buf)
|
||||
}
|
||||
pub fn write(fd: usize, buf: &[u8]) -> isize {
|
||||
sys_write(fd, buf)
|
||||
}
|
||||
pub fn exit(exit_code: i32) -> ! {
|
||||
sys_exit(exit_code);
|
||||
}
|
||||
pub fn yield_() -> isize {
|
||||
sys_yield()
|
||||
}
|
||||
pub fn get_time() -> isize {
|
||||
sys_get_time()
|
||||
}
|
||||
pub fn getpid() -> isize {
|
||||
sys_getpid()
|
||||
}
|
||||
pub fn fork() -> isize {
|
||||
sys_fork()
|
||||
}
|
||||
pub fn exec(path: &str) -> isize {
|
||||
sys_exec(path)
|
||||
}
|
||||
pub fn wait(exit_code: &mut i32) -> isize {
|
||||
loop {
|
||||
match sys_waitpid(-1, exit_code as *mut _) {
|
||||
-2 => { yield_(); }
|
||||
-2 => {
|
||||
yield_();
|
||||
}
|
||||
// -1 or a real pid
|
||||
exit_pid => return exit_pid,
|
||||
}
|
||||
|
@ -76,7 +98,9 @@ pub fn wait(exit_code: &mut i32) -> isize {
|
|||
pub fn waitpid(pid: usize, exit_code: &mut i32) -> isize {
|
||||
loop {
|
||||
match sys_waitpid(pid as isize, exit_code as *mut _) {
|
||||
-2 => { yield_(); }
|
||||
-2 => {
|
||||
yield_();
|
||||
}
|
||||
// -1 or a real pid
|
||||
exit_pid => return exit_pid,
|
||||
}
|
||||
|
|
|
@ -35,7 +35,10 @@ pub fn sys_close(fd: usize) -> isize {
|
|||
}
|
||||
|
||||
pub fn sys_read(fd: usize, buffer: &mut [u8]) -> isize {
|
||||
syscall(SYSCALL_READ, [fd, buffer.as_mut_ptr() as usize, buffer.len()])
|
||||
syscall(
|
||||
SYSCALL_READ,
|
||||
[fd, buffer.as_mut_ptr() as usize, buffer.len()],
|
||||
)
|
||||
}
|
||||
|
||||
pub fn sys_write(fd: usize, buffer: &[u8]) -> isize {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue