Skip to content

Commit c508c81

Browse files
cargo fmt
1 parent 811d49e commit c508c81

File tree

239 files changed

+5333
-4413
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

239 files changed

+5333
-4413
lines changed

qkernel/src/interrupt/mod.rs

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ mod idt;
1717

1818
use super::asm::*;
1919
use super::qlib::addr::*;
20+
use super::qlib::backtracer;
2021
use super::qlib::common::*;
2122
use super::qlib::kernel::TSC;
2223
use super::qlib::linux_def::*;
23-
use super::qlib::backtracer;
2424
use super::qlib::singleton::*;
2525
use super::qlib::vcpu_mgr::*;
2626
use super::task::*;
@@ -530,7 +530,13 @@ pub extern "C" fn PageFaultHandler(ptRegs: &mut PtRegs, errorCode: u64) {
530530
//error!("InstallPage 1, range is {:x?}, address is {:x}, vma.growsDown is {}",
531531
// &range, pageAddr, vma.growsDown);
532532
//let startTime = TSC.Rdtsc();
533-
let addr = currTask.mm.pagetable.write().pt.SwapInPage(Addr(pageAddr)).unwrap();
533+
let addr = currTask
534+
.mm
535+
.pagetable
536+
.write()
537+
.pt
538+
.SwapInPage(Addr(pageAddr))
539+
.unwrap();
534540
//let endtime = TSC.Rdtsc();
535541
if addr > 0 {
536542
//use crate::qlib::kernel::Tsc;
@@ -636,26 +642,26 @@ pub fn HandleFault(
636642
print!("the map 3 is {}", &map);
637643
panic!();
638644
}
639-
645+
640646
//task.SaveFp();
641-
647+
642648
let mut info = SignalInfo {
643649
Signo: signal, //Signal::SIGBUS,
644650
..Default::default()
645651
};
646-
652+
647653
let sigfault = info.SigFault();
648654
sigfault.addr = cr2;
649655
//let read = errorCode & (1<<1) == 0;
650656
let write = errorCode & (1 << 1) != 0;
651657
let execute = errorCode & (1 << 4) != 0;
652-
658+
653659
if !write && !execute {
654660
info.Code = 1; // SEGV_MAPERR.
655661
} else {
656662
info.Code = 2; // SEGV_ACCERR.
657663
}
658-
664+
659665
let thread = task.Thread();
660666
// Synchronous signal. Send it to ourselves. Assume the signal is
661667
// legitimate and force it (work around the signal being ignored or
@@ -667,7 +673,7 @@ pub fn HandleFault(
667673
.expect("PageFaultHandler send signal fail");
668674
MainRun(task, TaskRunState::RunApp);
669675
//task.mm.VcpuEnter();
670-
676+
671677
task.RestoreFp();
672678
CPULocal::Myself().SetMode(VcpuMode::User);
673679
task.mm.HandleTlbShootdown();
@@ -705,7 +711,8 @@ pub extern "C" fn VirtualizationHandler(ptRegs: &mut PtRegs) {
705711
let currTask = Task::Current();
706712
//currTask.mm.VcpuLeave();
707713

708-
if ptRegs.cs & 0x3 == 0 { // kernel mode
714+
if ptRegs.cs & 0x3 == 0 {
715+
// kernel mode
709716
error!("VirtualizationHandler kernel ...");
710717
//CPULocal::Myself().SetMode(VcpuMode::User);
711718
currTask.mm.HandleTlbShootdown();
@@ -720,8 +727,8 @@ pub extern "C" fn VirtualizationHandler(ptRegs: &mut PtRegs) {
720727

721728
if CPULocal::InterruptByTlbShootdown(mask) {
722729
// no need special operation
723-
}
724-
730+
}
731+
725732
if CPULocal::InterruptByThreadTimeout(mask) {
726733
/*if SHARESPACE.config.read().KernelPagetable {
727734
Task::SetKernelPageTable();
@@ -750,7 +757,7 @@ pub extern "C" fn VirtualizationHandler(ptRegs: &mut PtRegs) {
750757

751758
CPULocal::SetKernelStack(currTask.GetKernelSp());
752759
//currTask.mm.VcpuEnter();
753-
760+
754761
CPULocal::Myself().SetMode(VcpuMode::User);
755762
currTask.mm.HandleTlbShootdown();
756763
}

qkernel/src/kernel_def.rs

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,29 @@
1414
//
1515

1616
use core::alloc::{GlobalAlloc, Layout};
17+
use core::arch::asm;
1718
use core::sync::atomic::AtomicBool;
1819
use core::sync::atomic::AtomicU64;
1920
use core::sync::atomic::Ordering;
20-
use core::arch::asm;
2121

2222
use crate::qlib::fileinfo::*;
2323

2424
use super::qlib::kernel::asm::*;
25+
use super::qlib::kernel::quring::uring_async::UringAsyncMgr;
2526
use super::qlib::kernel::taskMgr::*;
2627
use super::qlib::kernel::threadmgr::task_sched::*;
28+
use super::qlib::kernel::vcpu::*;
2729
use super::qlib::kernel::SHARESPACE;
2830
use super::qlib::kernel::TSC;
29-
use super::qlib::kernel::vcpu::*;
30-
use super::qlib::kernel::quring::uring_async::UringAsyncMgr;
3131

3232
use super::qlib::common::*;
3333
use super::qlib::kernel::memmgr::pma::*;
3434
use super::qlib::kernel::task::*;
3535
use super::qlib::kernel::taskMgr;
3636
use super::qlib::linux_def::*;
3737
use super::qlib::loader::*;
38-
use super::qlib::mem::list_allocator::*;
3938
use super::qlib::mem::bitmap_allocator::*;
39+
use super::qlib::mem::list_allocator::*;
4040
use super::qlib::mutex::*;
4141
use super::qlib::perf_tunning::*;
4242
use super::qlib::qmsg::*;
@@ -84,12 +84,7 @@ impl IoUring {
8484
unsafe { self.enter(len as _, want as _, flags) }
8585
}
8686

87-
pub unsafe fn enter(
88-
&self,
89-
to_submit: u32,
90-
min_complete: u32,
91-
flag: u32,
92-
) -> Result<usize> {
87+
pub unsafe fn enter(&self, to_submit: u32, min_complete: u32, flag: u32) -> Result<usize> {
9388
return io_uring_enter(to_submit, min_complete, flag);
9489
}
9590

@@ -223,7 +218,7 @@ pub fn switch(from: TaskId, to: TaskId) {
223218
toCtx.SwitchPageTable();
224219
}
225220
toCtx.SetFS();
226-
221+
227222
fromCtx.mm.VcpuLeave();
228223
toCtx.mm.VcpuEnter();
229224

@@ -286,7 +281,7 @@ pub fn HyperCall64(type_: u16, para1: u64, para2: u64, para3: u64, para4: u64) {
286281
)
287282
}
288283
}
289-
284+
290285
impl CPULocal {
291286
pub fn CpuId() -> usize {
292287
return GetVcpuId();
@@ -384,7 +379,7 @@ impl BitmapAllocatorWrapper {
384379
pub const fn New() -> Self {
385380
return Self {
386381
addr: AtomicU64::new(MemoryDef::HEAP_OFFSET),
387-
}
382+
};
388383
}
389384

390385
pub fn Init(&self) {
@@ -431,26 +426,23 @@ pub fn HugepageDontNeed(addr: u64) {
431426

432427
impl IOMgr {
433428
pub fn Init() -> Result<Self> {
434-
return Err(Error::Common(format!("IOMgr can't init in kernel")))
429+
return Err(Error::Common(format!("IOMgr can't init in kernel")));
435430
}
436431
}
437432

438-
439433
unsafe impl GlobalAlloc for GlobalVcpuAllocator {
440434
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
441435
if !self.init.load(Ordering::Relaxed) {
442-
return GLOBAL_ALLOCATOR
443-
.alloc(layout);
436+
return GLOBAL_ALLOCATOR.alloc(layout);
444437
}
445-
return CPU_LOCAL[VcpuId()].AllocatorMut().alloc(layout)
438+
return CPU_LOCAL[VcpuId()].AllocatorMut().alloc(layout);
446439
}
447440

448441
unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {
449442
if !self.init.load(Ordering::Relaxed) {
450-
return GLOBAL_ALLOCATOR
451-
.dealloc(ptr, layout);
443+
return GLOBAL_ALLOCATOR.dealloc(ptr, layout);
452444
}
453-
return CPU_LOCAL[VcpuId()].AllocatorMut().dealloc(ptr, layout)
445+
return CPU_LOCAL[VcpuId()].AllocatorMut().dealloc(ptr, layout);
454446
}
455447
}
456448

@@ -463,7 +455,7 @@ impl UringAsyncMgr {
463455
loop {
464456
let id = match self.freeids.lock().pop_front() {
465457
None => break,
466-
Some(id) => id
458+
Some(id) => id,
467459
};
468460
self.freeSlot(id as _);
469461
}
@@ -476,4 +468,4 @@ pub fn IsKernel() -> bool {
476468

477469
pub fn ReapSwapIn() {
478470
HostSpace::SwapIn();
479-
}
471+
}

qkernel/src/lib.rs

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ extern crate spin;
5252
extern crate x86_64;
5353
extern crate xmas_elf;
5454

55-
use core::{mem, ptr};
5655
use core::panic::PanicInfo;
5756
use core::sync::atomic::{AtomicI32, AtomicUsize, Ordering};
57+
use core::{mem, ptr};
5858

5959
use spin::mutex::Mutex;
6060

@@ -74,36 +74,36 @@ use self::kernel_def::*;
7474
use self::loader::vdso::*;
7575
//use linked_list_allocator::LockedHeap;
7676
//use buddy_system_allocator::LockedHeap;
77-
use self::qlib::{ShareSpaceRef, SysCallID};
7877
use self::qlib::common::*;
7978
use self::qlib::config::*;
8079
use self::qlib::control_msg::*;
8180
use self::qlib::cpuid::*;
82-
use self::qlib::kernel::*;
8381
use self::qlib::kernel::arch;
8482
use self::qlib::kernel::asm;
8583
use self::qlib::kernel::boot;
8684
use self::qlib::kernel::fd;
8785
use self::qlib::kernel::fs;
8886
use self::qlib::kernel::kernel;
89-
use self::qlib::kernel::Kernel;
9087
use self::qlib::kernel::loader;
9188
use self::qlib::kernel::memmgr;
9289
use self::qlib::kernel::perflog;
9390
use self::qlib::kernel::quring;
91+
use self::qlib::kernel::Kernel;
92+
use self::qlib::kernel::*;
93+
use self::qlib::{ShareSpaceRef, SysCallID};
9494
//use self::vcpu::*;
95-
use self::qlib::kernel::Scale;
96-
use self::qlib::kernel::SignalDef;
9795
use self::qlib::kernel::socket;
9896
use self::qlib::kernel::task;
9997
use self::qlib::kernel::taskMgr;
10098
use self::qlib::kernel::threadmgr;
101-
use self::qlib::kernel::TSC;
10299
use self::qlib::kernel::util;
103100
use self::qlib::kernel::vcpu;
104101
use self::qlib::kernel::vcpu::*;
105-
use self::qlib::kernel::VcpuFreqInit;
106102
use self::qlib::kernel::version;
103+
use self::qlib::kernel::Scale;
104+
use self::qlib::kernel::SignalDef;
105+
use self::qlib::kernel::VcpuFreqInit;
106+
use self::qlib::kernel::TSC;
107107
use self::qlib::linux::time::*;
108108
use self::qlib::linux_def::MemoryDef;
109109
use self::qlib::loader::*;
@@ -137,16 +137,14 @@ pub const HEAP_SIZE: usize = 0x1000_0000;
137137
//use buddy_system_allocator::*;
138138
//#[global_allocator]
139139

140-
141140
#[global_allocator]
142141
pub static VCPU_ALLOCATOR: GlobalVcpuAllocator = GlobalVcpuAllocator::New();
143142

144143
pub static GLOBAL_ALLOCATOR: HostAllocator = HostAllocator::New();
145144
//pub static GLOBAL_ALLOCATOR: BitmapAllocatorWrapper = BitmapAllocatorWrapper::New();
146145

147-
148146
lazy_static! {
149-
pub static ref GLOBAL_LOCK : Mutex<()> = Mutex::new(());
147+
pub static ref GLOBAL_LOCK: Mutex<()> = Mutex::new(());
150148
}
151149

152150
//static ALLOCATOR: QAllocator = QAllocator::New();
@@ -283,7 +281,8 @@ pub extern "C" fn syscall_handler(
283281
let llevel = SHARESPACE.config.read().LogLevel;
284282
callId = if nr < SysCallID::UnknowSyscall as u64 {
285283
unsafe { mem::transmute(nr as u64) }
286-
} else if SysCallID::sys_socket_produce as u64 <= nr && nr < SysCallID::EXTENSION_MAX as u64 {
284+
} else if SysCallID::sys_socket_produce as u64 <= nr && nr < SysCallID::EXTENSION_MAX as u64
285+
{
287286
unsafe { mem::transmute(nr as u64) }
288287
} else {
289288
nr = SysCallID::UnknowSyscall as _;
@@ -343,7 +342,7 @@ pub extern "C" fn syscall_handler(
343342
currTask.SwitchPageTable();
344343
}*/
345344
//currTask.mm.VcpuEnter();
346-
345+
347346
CPULocal::Myself().SetEnterAppTimestamp(TSC.Rdtsc());
348347
CPULocal::Myself().SetMode(VcpuMode::User);
349348
currTask.mm.HandleTlbShootdown();
@@ -404,7 +403,7 @@ pub fn MainRun(currTask: &mut Task, mut state: TaskRunState) {
404403
let dummyTask = DUMMY_TASK.read();
405404
currTask.blocker = dummyTask.blocker.clone();
406405
}
407-
406+
408407
let mm = thread.lock().memoryMgr.clone();
409408
thread.lock().memoryMgr = currTask.mm.clone();
410409
CPULocal::SetPendingFreeStack(currTask.taskId);
@@ -488,7 +487,7 @@ pub extern "C" fn rust_main(
488487
GlobalIOMgr().InitPollHostEpoll(SHARESPACE.HostHostEpollfd());
489488
SetVCPCount(vcpuCnt as usize);
490489
VDSO.Initialization(vdsoParamAddr);
491-
490+
492491
// release other vcpus
493492
HyperCall64(qlib::HYPERCALL_RELEASE_VCPU, 0, 0, 0, 0);
494493
} else {
@@ -567,7 +566,10 @@ fn StartRootContainer(_para: *const u8) -> ! {
567566
let mut processArgs = LOADER.Lock(task).unwrap().Init(process);
568567
match LOADER.LoadRootProcess(&mut processArgs) {
569568
Err(e) => {
570-
error!("load root process failure with error {:?}, shutting down...", e);
569+
error!(
570+
"load root process failure with error {:?}, shutting down...",
571+
e
572+
);
571573
SHARESPACE.StoreShutdown();
572574
Kernel::HostSpace::ExitVM(2);
573575
panic!("exiting ...");

qkernel/src/syscalls/mod.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,38 +21,38 @@ pub mod sys_file;
2121
pub mod sys_futex;
2222
pub mod sys_getdents;
2323
pub mod sys_identity;
24+
pub mod sys_inotify;
2425
pub mod sys_membarrier;
26+
pub mod sys_memfd;
2527
pub mod sys_mempolicy;
2628
pub mod sys_mmap;
29+
pub mod sys_mmap_socket;
30+
pub mod sys_msgqueue;
2731
pub mod sys_pipe;
2832
pub mod sys_poll;
2933
pub mod sys_prctl;
34+
pub mod sys_proxy;
3035
pub mod sys_random;
3136
pub mod sys_read;
3237
pub mod sys_rlimit;
3338
pub mod sys_rusage;
39+
pub mod sys_sched;
3440
pub mod sys_seccomp;
41+
pub mod sys_sem;
42+
pub mod sys_shm;
3543
pub mod sys_signal;
3644
pub mod sys_socket;
3745
pub mod sys_splice;
3846
pub mod sys_stat;
3947
pub mod sys_sync;
4048
pub mod sys_sysinfo;
49+
pub mod sys_syslog;
4150
pub mod sys_thread;
4251
pub mod sys_time;
4352
pub mod sys_timer;
4453
pub mod sys_timerfd;
4554
pub mod sys_tls;
4655
pub mod sys_utsname;
4756
pub mod sys_write;
48-
pub mod syscalls;
49-
pub mod sys_memfd;
50-
pub mod sys_sched;
51-
pub mod sys_inotify;
5257
pub mod sys_xattr;
53-
pub mod sys_sem;
54-
pub mod sys_shm;
55-
pub mod sys_msgqueue;
56-
pub mod sys_syslog;
57-
pub mod sys_mmap_socket;
58-
pub mod sys_proxy;
58+
pub mod syscalls;

0 commit comments

Comments
 (0)