From 0c9679b7104ca3f0be17ecb566f3e689d4b00b39 Mon Sep 17 00:00:00 2001 From: WangRunji Date: Sun, 15 Jul 2018 01:07:25 +0800 Subject: [PATCH] Fix fork and syscall return value. --- crate/memory/src/memory_set.rs | 6 ++++++ kernel/src/arch/riscv32/context.rs | 2 +- kernel/src/arch/riscv32/interrupt.rs | 4 ++-- kernel/src/arch/x86_64/interrupt/handler.rs | 4 ++-- kernel/src/consts.rs | 4 ++-- 5 files changed, 13 insertions(+), 7 deletions(-) diff --git a/crate/memory/src/memory_set.rs b/crate/memory/src/memory_set.rs index aceb6a3..ca3e7dc 100644 --- a/crate/memory/src/memory_set.rs +++ b/crate/memory/src/memory_set.rs @@ -205,6 +205,12 @@ impl Clone for MemorySet { } } +impl Drop for MemorySet { + fn drop(&mut self) { + self.clear(); + } +} + impl Debug for MemorySet { fn fmt(&self, f: &mut Formatter) -> Result<(), Error> { f.debug_list() diff --git a/kernel/src/arch/riscv32/context.rs b/kernel/src/arch/riscv32/context.rs index 5089784..4a00cfa 100644 --- a/kernel/src/arch/riscv32/context.rs +++ b/kernel/src/arch/riscv32/context.rs @@ -153,7 +153,7 @@ impl Context { context: ContextData::new(cr3), tf: { let mut tf = tf.clone(); - tf.x[1] = 0; // ra + tf.x[10] = 0; // a0 tf }, }.push_at(kstack_top) diff --git a/kernel/src/arch/riscv32/interrupt.rs b/kernel/src/arch/riscv32/interrupt.rs index eed2678..e629e5e 100644 --- a/kernel/src/arch/riscv32/interrupt.rs +++ b/kernel/src/arch/riscv32/interrupt.rs @@ -53,9 +53,9 @@ fn timer() { } fn syscall(tf: &mut TrapFrame) { + tf.sepc += 4; // Must before syscall, because of fork. let ret = ::syscall::syscall(tf.x[10], [tf.x[11], tf.x[12], tf.x[13], tf.x[14], tf.x[15], tf.x[16]], tf); - unsafe { *(&tf.x[10] as *const _ as *mut i32) = ret; } - tf.sepc += 4; + tf.x[10] = ret as usize; } extern { diff --git a/kernel/src/arch/x86_64/interrupt/handler.rs b/kernel/src/arch/x86_64/interrupt/handler.rs index f845f94..7ae856b 100644 --- a/kernel/src/arch/x86_64/interrupt/handler.rs +++ b/kernel/src/arch/x86_64/interrupt/handler.rs @@ -160,14 +160,14 @@ fn syscall(tf: &mut TrapFrame) { trace!("\nInterupt: Syscall {:#x?}", tf.rax); use syscall::syscall; let ret = syscall(tf.rax, [tf.rdi, tf.rsi, tf.rdx, tf.rcx, tf.r8, tf.r9], tf); - unsafe { *(&tf.rax as *const _ as *mut i32) = ret; } + tf.rax = ret as usize; } fn syscall32(tf: &mut TrapFrame) { trace!("\nInterupt: Syscall {:#x?}", tf.rax); use syscall::syscall; let ret = syscall(tf.rax, [tf.rdx, tf.rcx, tf.rbx, tf.rdi, tf.rsi, 0], tf); - unsafe { *(&tf.rax as *const _ as *mut i32) = ret; } + tf.rax = ret as usize; } fn error(tf: &TrapFrame) { diff --git a/kernel/src/consts.rs b/kernel/src/consts.rs index b4a3661..272ccf1 100644 --- a/kernel/src/consts.rs +++ b/kernel/src/consts.rs @@ -6,7 +6,7 @@ pub use self::riscv::*; pub use self::x86_64::*; pub const MAX_CPU_NUM: usize = 8; -pub const MAX_PROCESS_NUM: usize = 32; +pub const MAX_PROCESS_NUM: usize = 48; #[cfg(target_arch = "riscv")] mod riscv { @@ -18,7 +18,7 @@ mod riscv { pub const KERNEL_OFFSET: usize = 0; pub const KERNEL_PML4: usize = 0x8000_0000 >> 22; pub const KERNEL_HEAP_OFFSET: usize = 0x8020_0000; - pub const KERNEL_HEAP_SIZE: usize = 0x0010_0000; + pub const KERNEL_HEAP_SIZE: usize = 0x0020_0000; pub const MEMORY_OFFSET: usize = 0x8000_0000; pub const MEMORY_END: usize = 0x8080_0000; pub const USER_STACK_OFFSET: usize = 0x70000000;