Skip to content

Commit

Permalink
Merge pull request #11 from Rustin-Liu/rustin-patch-ci
Browse files Browse the repository at this point in the history
ci: add fmt and clippy check
  • Loading branch information
jiegec authored Jun 13, 2020
2 parents fea585c + 41cbe01 commit 969ca1b
Show file tree
Hide file tree
Showing 21 changed files with 91 additions and 100 deletions.
27 changes: 20 additions & 7 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,26 @@ name: CI
on: [push, pull_request]

jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
components: rustfmt, clippy
- name: Setup Environment
run: cd os && make env
- name: Check user
run: cd usr/rust/ && cargo fmt -- --check && cargo clippy -- -D warnings
- name: Check os
run: export USER_IMG="../usr/build/riscv64.img" && cd os && cargo fmt -- --check && cargo clippy -- -D warnings
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup Environment
run: cd os && make env
- name: Build user
run: cd usr && make user_img
- name: Build kernel
run: cd os && make build
- uses: actions/checkout@v2
- name: Setup Environment
run: cd os && make env
- name: Build user
run: cd usr && make user_img
- name: Build kernel
run: cd os && make build
7 changes: 3 additions & 4 deletions os/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub struct Context {
impl Context {
#[naked]
#[inline(never)]
pub unsafe extern "C" fn switch(&mut self, target: &mut Context) {
pub unsafe extern "C" fn switch(&mut self, _target: &mut Context) {
llvm_asm!(include_str!("process/switch.asm") :::: "volatile");
}

Expand Down Expand Up @@ -62,7 +62,7 @@ extern "C" {

impl ContextContent {
fn new_kernel_thread(entry: usize, kstack_top: usize, satp: usize) -> ContextContent {
let content = ContextContent {
ContextContent {
ra: __trapret as usize,
satp,
s: [0; 12],
Expand All @@ -76,8 +76,7 @@ impl ContextContent {
tf.sstatus.set_sie(false);
tf
},
};
content
}
}

fn new_user_thread(entry: usize, ustack_top: usize, satp: usize) -> Self {
Expand Down
12 changes: 7 additions & 5 deletions os/src/fs/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ use rcore_fs::vfs::INode;

#[derive(Copy, Clone, Debug)]
pub enum FileDescriptorType {
FD_NONE,
FD_INODE,
FD_DEVICE,
FdNone,
FdInode,
#[allow(dead_code)]
FdDevice,
}

#[derive(Clone)]
Expand All @@ -21,7 +22,7 @@ pub struct File {
impl File {
pub fn default() -> Self {
File {
fdtype: FileDescriptorType::FD_NONE,
fdtype: FileDescriptorType::FdNone,
readable: false,
writable: false,
inode: None,
Expand Down Expand Up @@ -53,8 +54,9 @@ impl File {
self.offset
}

#[allow(unused_unsafe)]
pub fn open_file(&mut self, path: &'static str, flags: i32) {
self.set_fdtype(FileDescriptorType::FD_INODE);
self.set_fdtype(FileDescriptorType::FdInode);
self.set_readable(true);
if (flags & 1) > 0 {
self.set_readable(false);
Expand Down
10 changes: 5 additions & 5 deletions os/src/interrupt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ pub fn init() {
}

pub unsafe fn init_external_interrupt() {
let HART0_S_MODE_INTERRUPT_ENABLES: *mut u32 = access_pa_via_va(0x0c00_2080) as *mut u32;
let hart0_s_mode_interrupt_enables: *mut u32 = access_pa_via_va(0x0c00_2080) as *mut u32;
const SERIAL: u32 = 0xa;
HART0_S_MODE_INTERRUPT_ENABLES.write_volatile(1 << SERIAL);
hart0_s_mode_interrupt_enables.write_volatile(1 << SERIAL);
}

pub unsafe fn enable_serial_interrupt() {
let UART16550: *mut u8 = access_pa_via_va(0x10000000) as *mut u8;
UART16550.add(4).write_volatile(0x0B);
UART16550.add(1).write_volatile(0x01);
let uart16550: *mut u8 = access_pa_via_va(0x10000000) as *mut u8;
uart16550.add(4).write_volatile(0x0B);
uart16550.add(1).write_volatile(0x01);
}

#[no_mangle]
Expand Down
8 changes: 0 additions & 8 deletions os/src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,6 @@ macro_rules! println {
($($arg:tt)*) => ($crate::print!("{}\n", format_args!($($arg)*)));
}

pub fn getchar() -> char {
let c = sbi::console_getchar() as u8;

match c {
255 => '\0',
c => c as char,
}
}
// 调用 OpenSBI 接口
pub fn getchar_option() -> Option<char> {
let c = sbi::console_getchar() as isize;
Expand Down
1 change: 1 addition & 0 deletions os/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
#![no_main]

#[allow(unused_imports)]
#[allow(clippy::single_component_path_imports)]
use os;
4 changes: 2 additions & 2 deletions os/src/memory/frame_allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ impl SegmentTreeAllocator {
self.n = r - l;
self.m = 1;
while self.m < self.n + 2 {
self.m = self.m << 1;
self.m <<= 1;
}
for i in 1..(self.m << 1) {
self.a[i] = 1;
Expand All @@ -35,7 +35,7 @@ impl SegmentTreeAllocator {
let mut p = 1;
while p < self.m {
if self.a[p << 1] == 0 {
p = p << 1;
p <<= 1;
} else {
p = (p << 1) | 1;
}
Expand Down
6 changes: 4 additions & 2 deletions os/src/memory/memory_set/area.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ impl MemoryArea {
self.handler.map(pt, page, &self.attr);
}
}

#[allow(dead_code)]
fn unmap(&self, pt: &mut PageTableImpl) {
for page in PageRange::new(self.start, self.end) {
self.handler.unmap(pt, page);
Expand All @@ -40,8 +42,8 @@ impl MemoryArea {
MemoryArea {
start: start_addr,
end: end_addr,
handler: handler,
attr: attr,
handler,
attr,
}
}

Expand Down
10 changes: 1 addition & 9 deletions os/src/memory/memory_set/attr.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
use crate::memory::paging::PageEntry;

#[derive(Clone, Debug)]
#[derive(Clone, Default, Debug)]
pub struct MemoryAttr {
user: bool,
readonly: bool,
execute: bool,
}

impl MemoryAttr {
pub fn new() -> Self {
MemoryAttr {
user: false,
readonly: false,
execute: false,
}
}

pub fn set_user(mut self) -> Self {
self.user = true;
self
Expand Down
10 changes: 4 additions & 6 deletions os/src/memory/memory_set/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,9 @@ impl MemoryHandler for Linear {
let dst = core::slice::from_raw_parts_mut(va as *mut u8, PAGE_SIZE);
if length > 0 {
let src = core::slice::from_raw_parts(src as *const u8, PAGE_SIZE);
for i in 0..length {
dst[i] = src[i];
}
dst[..length].clone_from_slice(&src[..length]);
}
#[allow(clippy::needless_range_loop)]
for i in length..PAGE_SIZE {
dst[i] = 0;
}
Expand Down Expand Up @@ -85,10 +84,9 @@ impl MemoryHandler for ByFrame {
let dst = core::slice::from_raw_parts_mut(access_pa_via_va(pa) as *mut u8, PAGE_SIZE);
if length > 0 {
let src = core::slice::from_raw_parts(src as *const u8, PAGE_SIZE);
for i in 0..length {
dst[i] = src[i];
}
dst[..length].clone_from_slice(&src[..length]);
}
#[allow(clippy::needless_range_loop)]
for i in length..PAGE_SIZE {
dst[i] = 0;
}
Expand Down
10 changes: 5 additions & 5 deletions os/src/memory/memory_set/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,39 +68,39 @@ impl MemorySet {
self.push(
stext as usize,
etext as usize,
MemoryAttr::new().set_readonly().set_execute(),
MemoryAttr::default().set_readonly().set_execute(),
Linear::new(offset),
None,
);
// .rodata R
self.push(
srodata as usize,
erodata as usize,
MemoryAttr::new().set_readonly(),
MemoryAttr::default().set_readonly(),
Linear::new(offset),
None,
);
// .data R|W
self.push(
sdata as usize,
edata as usize,
MemoryAttr::new(),
MemoryAttr::default(),
Linear::new(offset),
None,
);
// .bss R|W
self.push(
sbss as usize,
ebss as usize,
MemoryAttr::new(),
MemoryAttr::default(),
Linear::new(offset),
None,
);
// 物理内存 R|W
self.push(
(end as usize / PAGE_SIZE + 1) * PAGE_SIZE,
access_pa_via_va(PHYSICAL_MEMORY_END),
MemoryAttr::new(),
MemoryAttr::default(),
Linear::new(offset),
None,
);
Expand Down
6 changes: 3 additions & 3 deletions os/src/memory/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,21 @@ pub fn kernel_remap() {
memory_set.push(
bootstack as usize,
bootstacktop as usize,
MemoryAttr::new(),
MemoryAttr::default(),
Linear::new(PHYSICAL_MEMORY_OFFSET),
None,
);
memory_set.push(
access_pa_via_va(0x0c00_2000),
access_pa_via_va(0x0c00_3000),
MemoryAttr::new(),
MemoryAttr::default(),
Linear::new(PHYSICAL_MEMORY_OFFSET),
None,
);
memory_set.push(
access_pa_via_va(0x1000_0000),
access_pa_via_va(0x1000_1000),
MemoryAttr::new(),
MemoryAttr::default(),
Linear::new(PHYSICAL_MEMORY_OFFSET),
None,
);
Expand Down
2 changes: 1 addition & 1 deletion os/src/memory/paging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ impl PageTableImpl {

pub fn get_entry(&mut self, va: usize) -> Option<&mut PageEntry> {
let page = Page::of_addr(VirtAddr::new(va));
if let Ok(e) = self.page_table.ref_entry(page.clone()) {
if let Ok(e) = self.page_table.ref_entry(page) {
let e = unsafe { &mut *(e as *mut PageTableEntry) };
self.entry = Some(PageEntry(e, page));
Some(self.entry.as_mut().unwrap())
Expand Down
15 changes: 8 additions & 7 deletions os/src/process/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ impl Processor {
}
}

#[allow(clippy::mut_from_ref)]
fn inner(&self) -> &mut ProcessorInner {
unsafe { &mut *self.inner.get() }
.as_mut()
Expand Down Expand Up @@ -68,14 +69,12 @@ impl Processor {

pub fn tick(&self) {
let inner = self.inner();
if !inner.current.is_none() {
if inner.pool.tick() {
let flags = disable_and_store();
if inner.current.is_some() && inner.pool.tick() {
let flags = disable_and_store();

inner.current.as_mut().unwrap().1.switch_to(&mut inner.idle);
inner.current.as_mut().unwrap().1.switch_to(&mut inner.idle);

restore(flags);
}
restore(flags);
}
}

Expand All @@ -100,9 +99,10 @@ impl Processor {
Thread::get_boot_thread().switch_to(&mut self.inner().idle);
}

#[allow(unused_unsafe)]
pub fn yield_now(&self) {
let inner = self.inner();
if !inner.current.is_none() {
if inner.current.is_some() {
unsafe {
let flags = disable_and_store();
let tid = inner.current.as_mut().unwrap().0;
Expand Down Expand Up @@ -132,6 +132,7 @@ impl Processor {
self.inner().current.as_mut().unwrap().0 as usize
}

#[allow(clippy::mut_from_ref)]
pub fn current_thread_mut(&self) -> &mut Thread {
self.inner().current.as_mut().unwrap().1.as_mut()
}
Expand Down
8 changes: 2 additions & 6 deletions os/src/process/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,9 @@ impl Scheduler for RRScheduler {
let tid = self.current;
if tid != 0 {
self.threads[tid].time -= 1;
if self.threads[tid].time == 0 {
return true;
} else {
return false;
}
return self.threads[tid].time == 0;
}
return true;
true
}

fn exit(&mut self, tid: Tid) {
Expand Down
Loading

0 comments on commit 969ca1b

Please sign in to comment.