diff --git a/ch9-log/os/mm/frame_allocator/fn.frame_alloc.html b/ch9-log/os/mm/frame_allocator/fn.frame_alloc.html index a8cd4c05..edeef209 100644 --- a/ch9-log/os/mm/frame_allocator/fn.frame_alloc.html +++ b/ch9-log/os/mm/frame_allocator/fn.frame_alloc.html @@ -2,5 +2,5 @@
pub fn frame_alloc() -> Option<FrameTracker>
+

Function os::mm::frame_allocator::frame_alloc

source · []
pub fn frame_alloc() -> Option<FrameTracker>
\ No newline at end of file diff --git a/ch9-log/os/mm/frame_allocator/fn.frame_allocator_test.html b/ch9-log/os/mm/frame_allocator/fn.frame_allocator_test.html index ac59e9c1..9be1e55c 100644 --- a/ch9-log/os/mm/frame_allocator/fn.frame_allocator_test.html +++ b/ch9-log/os/mm/frame_allocator/fn.frame_allocator_test.html @@ -2,5 +2,5 @@
pub fn frame_allocator_test()
+

Function os::mm::frame_allocator::frame_allocator_test

source · []
pub fn frame_allocator_test()
\ No newline at end of file diff --git a/ch9-log/os/mm/frame_allocator/fn.frame_dealloc.html b/ch9-log/os/mm/frame_allocator/fn.frame_dealloc.html index 7633ddf9..ed1bb4b8 100644 --- a/ch9-log/os/mm/frame_allocator/fn.frame_dealloc.html +++ b/ch9-log/os/mm/frame_allocator/fn.frame_dealloc.html @@ -2,5 +2,5 @@
pub fn frame_dealloc(ppn: PhysPageNum)
+

Function os::mm::frame_allocator::frame_dealloc

source · []
pub fn frame_dealloc(ppn: PhysPageNum)
\ No newline at end of file diff --git a/ch9-log/os/mm/frame_allocator/fn.init_frame_allocator.html b/ch9-log/os/mm/frame_allocator/fn.init_frame_allocator.html index ba9a495d..4d7a843b 100644 --- a/ch9-log/os/mm/frame_allocator/fn.init_frame_allocator.html +++ b/ch9-log/os/mm/frame_allocator/fn.init_frame_allocator.html @@ -2,5 +2,5 @@
pub fn init_frame_allocator()
+

Function os::mm::frame_allocator::init_frame_allocator

source · []
pub fn init_frame_allocator()
\ No newline at end of file diff --git a/ch9-log/os/mm/frame_allocator/index.html b/ch9-log/os/mm/frame_allocator/index.html index dcc683f2..2858d2c0 100644 --- a/ch9-log/os/mm/frame_allocator/index.html +++ b/ch9-log/os/mm/frame_allocator/index.html @@ -2,7 +2,7 @@

Structs

+

Module os::mm::frame_allocator

source · []

Structs

Traits

Functions

Type Definitions

diff --git a/ch9-log/os/mm/frame_allocator/struct.FRAME_ALLOCATOR.html b/ch9-log/os/mm/frame_allocator/struct.FRAME_ALLOCATOR.html index 7f22badc..12002c85 100644 --- a/ch9-log/os/mm/frame_allocator/struct.FRAME_ALLOCATOR.html +++ b/ch9-log/os/mm/frame_allocator/struct.FRAME_ALLOCATOR.html @@ -2,12 +2,12 @@
pub struct FRAME_ALLOCATOR {
+    

Struct os::mm::frame_allocator::FRAME_ALLOCATOR

source · []
pub struct FRAME_ALLOCATOR {
     __private_field: (),
 }

Fields

__private_field: ()

Methods from Deref<Target = UPIntrFreeCell<StackFrameAllocator>>

Panic if the data has been borrowed.

-

Trait Implementations

The resulting type after dereferencing.

-

Dereferences the value.

-

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

+

Trait Implementations

The resulting type after dereferencing.

+

Dereferences the value.

+

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

diff --git a/ch9-log/os/mm/frame_allocator/struct.FrameTracker.html b/ch9-log/os/mm/frame_allocator/struct.FrameTracker.html index dfc45fe7..68b6f751 100644 --- a/ch9-log/os/mm/frame_allocator/struct.FrameTracker.html +++ b/ch9-log/os/mm/frame_allocator/struct.FrameTracker.html @@ -5,7 +5,7 @@

Struct os::mm::frame_allocator::FrameTracker

source · []
pub struct FrameTracker {
     pub ppn: PhysPageNum,
 }

Fields

ppn: PhysPageNum

Implementations

Trait Implementations

Formats the value using the given formatter. Read more

-

Executes the destructor for this type. Read more

+

Executes the destructor for this type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

diff --git a/ch9-log/os/mm/frame_allocator/struct.StackFrameAllocator.html b/ch9-log/os/mm/frame_allocator/struct.StackFrameAllocator.html index 5a401b3a..b77a3686 100644 --- a/ch9-log/os/mm/frame_allocator/struct.StackFrameAllocator.html +++ b/ch9-log/os/mm/frame_allocator/struct.StackFrameAllocator.html @@ -2,11 +2,11 @@
pub struct StackFrameAllocator {
+    

Struct os::mm::frame_allocator::StackFrameAllocator

source · []
pub struct StackFrameAllocator {
     current: usize,
     end: usize,
     recycled: Vec<usize>,
-}

Fields

current: usizeend: usizerecycled: Vec<usize>

Implementations

Trait Implementations

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

+}

Fields

current: usizeend: usizerecycled: Vec<usize>

Implementations

Trait Implementations

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

diff --git a/ch9-log/os/mm/frame_allocator/trait.FrameAllocator.html b/ch9-log/os/mm/frame_allocator/trait.FrameAllocator.html index 00839253..092d55c2 100644 --- a/ch9-log/os/mm/frame_allocator/trait.FrameAllocator.html +++ b/ch9-log/os/mm/frame_allocator/trait.FrameAllocator.html @@ -2,9 +2,9 @@
trait FrameAllocator {
+    

Trait os::mm::frame_allocator::FrameAllocator

source · []
trait FrameAllocator {
     fn new() -> Self;
 
fn alloc(&mut self) -> Option<PhysPageNum>;
fn dealloc(&mut self, ppn: PhysPageNum); -}

Required methods

Implementors

+}

Required methods

Implementors

\ No newline at end of file diff --git a/ch9-log/os/mm/frame_allocator/type.FrameAllocatorImpl.html b/ch9-log/os/mm/frame_allocator/type.FrameAllocatorImpl.html index d9a85d3e..f815ee1d 100644 --- a/ch9-log/os/mm/frame_allocator/type.FrameAllocatorImpl.html +++ b/ch9-log/os/mm/frame_allocator/type.FrameAllocatorImpl.html @@ -2,5 +2,5 @@
type FrameAllocatorImpl = StackFrameAllocator;
+

Type Definition os::mm::frame_allocator::FrameAllocatorImpl

source · []
type FrameAllocatorImpl = StackFrameAllocator;
\ No newline at end of file diff --git a/ch9-log/os/syscall/process/fn.sys_kill.html b/ch9-log/os/syscall/process/fn.sys_kill.html index 14c8e709..79179522 100644 --- a/ch9-log/os/syscall/process/fn.sys_kill.html +++ b/ch9-log/os/syscall/process/fn.sys_kill.html @@ -2,5 +2,5 @@
pub fn sys_kill(pid: usize, signal: u32) -> isize
+

Function os::syscall::process::sys_kill

source · []
pub fn sys_kill(pid: usize, signal: u32) -> isize
\ No newline at end of file diff --git a/ch9-log/os/syscall/process/fn.sys_waitpid.html b/ch9-log/os/syscall/process/fn.sys_waitpid.html index d953fce3..37262294 100644 --- a/ch9-log/os/syscall/process/fn.sys_waitpid.html +++ b/ch9-log/os/syscall/process/fn.sys_waitpid.html @@ -2,7 +2,7 @@
pub fn sys_waitpid(pid: isize, exit_code_ptr: *mut i32) -> isize
Expand description

If there is not a child process whose pid is same as given, return -1. +

Function os::syscall::process::sys_waitpid

source · []
pub fn sys_waitpid(pid: isize, exit_code_ptr: *mut i32) -> isize
Expand description

If there is not a child process whose pid is same as given, return -1. Else if there is a child process but it is still running, return -2.

\ No newline at end of file diff --git a/ch9-log/os/syscall/process/index.html b/ch9-log/os/syscall/process/index.html index 8bd8e19e..f19b6958 100644 --- a/ch9-log/os/syscall/process/index.html +++ b/ch9-log/os/syscall/process/index.html @@ -2,7 +2,7 @@

Functions

If there is not a child process whose pid is same as given, return -1. Else if there is a child process but it is still running, return -2.

diff --git a/ch9-log/os/task/fn.add_initproc.html b/ch9-log/os/task/fn.add_initproc.html index 8ec0a18a..7988ba17 100644 --- a/ch9-log/os/task/fn.add_initproc.html +++ b/ch9-log/os/task/fn.add_initproc.html @@ -2,5 +2,5 @@
-

Function os::task::add_initproc

source · []
pub fn add_initproc()
+

Function os::task::add_initproc

source · []
pub fn add_initproc()
\ No newline at end of file diff --git a/ch9-log/os/task/fn.check_signals_of_current.html b/ch9-log/os/task/fn.check_signals_of_current.html index 81459e61..5b23d860 100644 --- a/ch9-log/os/task/fn.check_signals_of_current.html +++ b/ch9-log/os/task/fn.check_signals_of_current.html @@ -2,5 +2,5 @@
pub fn check_signals_of_current() -> Option<(i32, &'static str)>
+

Function os::task::check_signals_of_current

source · []
pub fn check_signals_of_current() -> Option<(i32, &'static str)>
\ No newline at end of file diff --git a/ch9-log/os/task/fn.current_add_signal.html b/ch9-log/os/task/fn.current_add_signal.html index 2cab1c52..a500b44c 100644 --- a/ch9-log/os/task/fn.current_add_signal.html +++ b/ch9-log/os/task/fn.current_add_signal.html @@ -2,5 +2,5 @@
pub fn current_add_signal(signal: SignalFlags)
+

Function os::task::current_add_signal

source · []
pub fn current_add_signal(signal: SignalFlags)
\ No newline at end of file diff --git a/ch9-log/os/task/fn.exit_current_and_run_next.html b/ch9-log/os/task/fn.exit_current_and_run_next.html index c622f748..c73bb31e 100644 --- a/ch9-log/os/task/fn.exit_current_and_run_next.html +++ b/ch9-log/os/task/fn.exit_current_and_run_next.html @@ -2,5 +2,5 @@
pub fn exit_current_and_run_next(exit_code: i32)
+

Function os::task::exit_current_and_run_next

source · []
pub fn exit_current_and_run_next(exit_code: i32)
\ No newline at end of file diff --git a/ch9-log/os/task/id/fn.kernel_stack_position.html b/ch9-log/os/task/id/fn.kernel_stack_position.html index d1cccf2e..a646aa00 100644 --- a/ch9-log/os/task/id/fn.kernel_stack_position.html +++ b/ch9-log/os/task/id/fn.kernel_stack_position.html @@ -2,6 +2,6 @@
pub fn kernel_stack_position(kstack_id: usize) -> (usize, usize)
Expand description

Return (bottom, top) of a kernel stack in kernel space.

+

Function os::task::id::kernel_stack_position

source · []
pub fn kernel_stack_position(kstack_id: usize) -> (usize, usize)
Expand description

Return (bottom, top) of a kernel stack in kernel space.

\ No newline at end of file diff --git a/ch9-log/os/task/id/fn.kstack_alloc.html b/ch9-log/os/task/id/fn.kstack_alloc.html index dce55a0a..64310b1d 100644 --- a/ch9-log/os/task/id/fn.kstack_alloc.html +++ b/ch9-log/os/task/id/fn.kstack_alloc.html @@ -2,5 +2,5 @@
-

Function os::task::id::kstack_alloc

source · []
pub fn kstack_alloc() -> KernelStack
+

Function os::task::id::kstack_alloc

source · []
pub fn kstack_alloc() -> KernelStack
\ No newline at end of file diff --git a/ch9-log/os/task/id/fn.trap_cx_bottom_from_tid.html b/ch9-log/os/task/id/fn.trap_cx_bottom_from_tid.html index 6dd4e16a..99b5a350 100644 --- a/ch9-log/os/task/id/fn.trap_cx_bottom_from_tid.html +++ b/ch9-log/os/task/id/fn.trap_cx_bottom_from_tid.html @@ -2,5 +2,5 @@
fn trap_cx_bottom_from_tid(tid: usize) -> usize
+

Function os::task::id::trap_cx_bottom_from_tid

source · []
fn trap_cx_bottom_from_tid(tid: usize) -> usize
\ No newline at end of file diff --git a/ch9-log/os/task/id/fn.ustack_bottom_from_tid.html b/ch9-log/os/task/id/fn.ustack_bottom_from_tid.html index 51f9b842..5ec81526 100644 --- a/ch9-log/os/task/id/fn.ustack_bottom_from_tid.html +++ b/ch9-log/os/task/id/fn.ustack_bottom_from_tid.html @@ -2,5 +2,5 @@
fn ustack_bottom_from_tid(ustack_base: usize, tid: usize) -> usize
+

Function os::task::id::ustack_bottom_from_tid

source · []
fn ustack_bottom_from_tid(ustack_base: usize, tid: usize) -> usize
\ No newline at end of file diff --git a/ch9-log/os/task/id/index.html b/ch9-log/os/task/id/index.html index dcb26f62..c85967ac 100644 --- a/ch9-log/os/task/id/index.html +++ b/ch9-log/os/task/id/index.html @@ -2,7 +2,7 @@
-

Module os::task::id

source · []

Structs

+

Module os::task::id

source · []

Structs

Functions

diff --git a/ch9-log/os/task/id/struct.KernelStack.html b/ch9-log/os/task/id/struct.KernelStack.html index 277ad428..51811571 100644 --- a/ch9-log/os/task/id/struct.KernelStack.html +++ b/ch9-log/os/task/id/struct.KernelStack.html @@ -2,7 +2,7 @@
-

Struct os::task::id::KernelStack

source · []
pub struct KernelStack(pub usize);

Tuple Fields

0: usize

Implementations

Trait Implementations

Executes the destructor for this type. Read more

+

Struct os::task::id::KernelStack

source · []
pub struct KernelStack(pub usize);

Tuple Fields

0: usize

Implementations

Trait Implementations

Executes the destructor for this type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

diff --git a/ch9-log/os/task/id/struct.PidHandle.html b/ch9-log/os/task/id/struct.PidHandle.html index d6b5e351..153fc82f 100644 --- a/ch9-log/os/task/id/struct.PidHandle.html +++ b/ch9-log/os/task/id/struct.PidHandle.html @@ -2,7 +2,7 @@
-

Struct os::task::id::PidHandle

source · []
pub struct PidHandle(pub usize);

Tuple Fields

0: usize

Trait Implementations

Executes the destructor for this type. Read more

+

Struct os::task::id::PidHandle

source · []
pub struct PidHandle(pub usize);

Tuple Fields

0: usize

Trait Implementations

Executes the destructor for this type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

diff --git a/ch9-log/os/task/id/struct.TaskUserRes.html b/ch9-log/os/task/id/struct.TaskUserRes.html index 04767589..a24d16b4 100644 --- a/ch9-log/os/task/id/struct.TaskUserRes.html +++ b/ch9-log/os/task/id/struct.TaskUserRes.html @@ -2,11 +2,11 @@
-

Struct os::task::id::TaskUserRes

source · []
pub struct TaskUserRes {
+    

Struct os::task::id::TaskUserRes

source · []
pub struct TaskUserRes {
     pub tid: usize,
     pub ustack_base: usize,
     pub process: Weak<ProcessControlBlock>,
-}

Fields

tid: usizeustack_base: usizeprocess: Weak<ProcessControlBlock>

Implementations

Trait Implementations

Executes the destructor for this type. Read more

+}

Fields

tid: usizeustack_base: usizeprocess: Weak<ProcessControlBlock>

Implementations

Trait Implementations

Executes the destructor for this type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

diff --git a/ch9-log/os/task/index.html b/ch9-log/os/task/index.html index 3c546869..e1a045eb 100644 --- a/ch9-log/os/task/index.html +++ b/ch9-log/os/task/index.html @@ -2,7 +2,7 @@
-

Module os::task

source · []

Re-exports

+

Module os::task

source · []

Re-exports

pub use context::TaskContext;
pub use id::kstack_alloc;
pub use id::pid_alloc;
pub use id::KernelStack;
pub use id::PidHandle;
pub use manager::add_task;
pub use manager::pid2process;
pub use manager::remove_from_pid2process;
pub use processor::current_kstack_top;
pub use processor::current_process;
pub use processor::current_task;
pub use processor::current_trap_cx;
pub use processor::current_trap_cx_user_va;
pub use processor::current_user_token;
pub use processor::run_tasks;
pub use processor::schedule;
pub use processor::take_current_task;
pub use signal::SignalFlags;
pub use task::TaskControlBlock;
pub use task::TaskStatus;

Modules

Structs

Functions

diff --git a/ch9-log/os/task/process/index.html b/ch9-log/os/task/process/index.html index 0d655786..90542358 100644 --- a/ch9-log/os/task/process/index.html +++ b/ch9-log/os/task/process/index.html @@ -2,6 +2,6 @@
-

Module os::task::process

source · []

Structs

+

Module os::task::process

source · []

Structs

\ No newline at end of file diff --git a/ch9-log/os/task/process/struct.ProcessControlBlock.html b/ch9-log/os/task/process/struct.ProcessControlBlock.html index 1638ed93..f57ed16a 100644 --- a/ch9-log/os/task/process/struct.ProcessControlBlock.html +++ b/ch9-log/os/task/process/struct.ProcessControlBlock.html @@ -5,9 +5,9 @@

Struct os::task::process::ProcessControlBlock

source · []
pub struct ProcessControlBlock {
     pub pid: PidHandle,
     inner: UPIntrFreeCell<ProcessControlBlockInner>,
-}

Fields

pid: PidHandleinner: UPIntrFreeCell<ProcessControlBlockInner>

Implementations

Only support processes with a single thread.

-

Only support processes with a single thread.

-

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

+}

Fields

pid: PidHandleinner: UPIntrFreeCell<ProcessControlBlockInner>

Implementations

Only support processes with a single thread.

+

Only support processes with a single thread.

+

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

diff --git a/ch9-log/os/task/struct.INITPROC.html b/ch9-log/os/task/struct.INITPROC.html index 9a5fbd45..518fa4ae 100644 --- a/ch9-log/os/task/struct.INITPROC.html +++ b/ch9-log/os/task/struct.INITPROC.html @@ -2,11 +2,11 @@
-

Struct os::task::INITPROC

source · []
pub struct INITPROC {
+    

Struct os::task::INITPROC

source · []
pub struct INITPROC {
     __private_field: (),
-}

Fields

__private_field: ()

Trait Implementations

The resulting type after dereferencing.

-

Dereferences the value.

-

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

+}

Fields

__private_field: ()

Trait Implementations

The resulting type after dereferencing.

+

Dereferences the value.

+

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

diff --git a/ch9-log/src/os/mm/frame_allocator.rs.html b/ch9-log/src/os/mm/frame_allocator.rs.html index a5d115e8..1d88410e 100644 --- a/ch9-log/src/os/mm/frame_allocator.rs.html +++ b/ch9-log/src/os/mm/frame_allocator.rs.html @@ -132,6 +132,8 @@ 129 130 131 +132 +133
use super::{PhysAddr, PhysPageNum};
 use crate::config::MEMORY_END;
 use crate::sync::UPIntrFreeCell;
@@ -162,7 +164,9 @@
 
 impl Drop for FrameTracker {
     fn drop(&mut self) {
+        kprintln!("[KERN] mm::frame_allocator::Drop<FrameTracker>::drop begin");
         frame_dealloc(self.ppn);
+        kprintln!("[KERN] mm::frame_allocator::Drop<FrameTracker>::drop end");
     }
 }
 
diff --git a/ch9-log/src/os/syscall/process.rs.html b/ch9-log/src/os/syscall/process.rs.html
index 5ec1c1cc..fc0c06ce 100644
--- a/ch9-log/src/os/syscall/process.rs.html
+++ b/ch9-log/src/os/syscall/process.rs.html
@@ -127,6 +127,9 @@
 124
 125
 126
+127
+128
+129
 
use crate::fs::{open_file, OpenFlags};
 use crate::mm::{translated_ref, translated_refmut, translated_str};
 use crate::task::{
@@ -225,14 +228,17 @@
         // ++++ release child PCB
     });
     if let Some((idx, _)) = pair {
+        kprintln!("[KERN] syscall::process::sys_waitpid(): remove child from PCB's children Vector");
         let child = inner.children.remove(idx);
         // confirm that child will be deallocated after being removed from children list
         assert_eq!(Arc::strong_count(&child), 1);
         let found_pid = child.getpid();
         // ++++ temporarily access child PCB exclusively
+        kprintln!("[KERN] syscall::process::sys_waitpid(): get child's exit_code and return child pid");
         let exit_code = child.inner_exclusive_access().exit_code;
         // ++++ release child PCB
         *translated_refmut(inner.memory_set.token(), exit_code_ptr) = exit_code;
+        kprintln!("[KERN] syscall::process::sys_waitpid(): release child PCB");
         found_pid as isize
     } else {
         -2
diff --git a/ch9-log/src/os/task/id.rs.html b/ch9-log/src/os/task/id.rs.html
index b282ac95..cce40c2b 100644
--- a/ch9-log/src/os/task/id.rs.html
+++ b/ch9-log/src/os/task/id.rs.html
@@ -247,6 +247,12 @@
 244
 245
 246
+247
+248
+249
+250
+251
+252
 
use super::ProcessControlBlock;
 use crate::config::{KERNEL_STACK_SIZE, PAGE_SIZE, TRAMPOLINE, TRAP_CONTEXT_BASE, USER_STACK_SIZE};
 use crate::mm::{MapPermission, PhysPageNum, VirtAddr, KERNEL_SPACE};
@@ -310,7 +316,9 @@
 
 impl Drop for PidHandle {
     fn drop(&mut self) {
+        kprintln!("[KERN] task::id::Drop<PidHandle>::drop begin");
         PID_ALLOCATOR.exclusive_access().dealloc(self.0);
+        kprintln!("[KERN] task::id::Drop<PidHandle>::drop end");
     }
 }
 
@@ -340,11 +348,13 @@
 
 impl Drop for KernelStack {
     fn drop(&mut self) {
+        kprintln!("[KERN] task::id::Drop<KernelStack>::drop begin");
         let (kernel_stack_bottom, _) = kernel_stack_position(self.0);
         let kernel_stack_bottom_va: VirtAddr = kernel_stack_bottom.into();
         KERNEL_SPACE
             .exclusive_access()
             .remove_area_with_start_vpn(kernel_stack_bottom_va.into());
+        kprintln!("[KERN] task::id::Drop<KernelStack>::drop end");    
     }
 }
 
@@ -489,8 +499,10 @@
 
 impl Drop for TaskUserRes {
     fn drop(&mut self) {
+        kprintln!("[KERN] task::id::Drop<TaskUserRes>::drop begin");
         self.dealloc_tid();
         self.dealloc_user_res();
+        kprintln!("[KERN] task::id::Drop<TaskUserRes>::drop end");
     }
 }
 
diff --git a/ch9-log/src/os/task/mod.rs.html b/ch9-log/src/os/task/mod.rs.html index 0079ce67..f375edc7 100644 --- a/ch9-log/src/os/task/mod.rs.html +++ b/ch9-log/src/os/task/mod.rs.html @@ -143,6 +143,18 @@ 140 141 142 +143 +144 +145 +146 +147 +148 +149 +150 +151 +152 +153 +154
mod context;
 mod id;
 mod manager;
@@ -212,24 +224,32 @@
     let process = task.process.upgrade().unwrap();
     let tid = task_inner.res.as_ref().unwrap().tid;
     // record exit code
+    kprintln!("[KERN] task::exit_current_and_run_next(): record exit code in task_inner");
     task_inner.exit_code = Some(exit_code);
+    kprintln!("[KERN] task::exit_current_and_run_next(): TaskUserRes =>None");
     task_inner.res = None;
     // here we do not remove the thread since we are still using the kstack
     // it will be deallocated when sys_waittid is called
+    kprintln!("[KERN] task::exit_current_and_run_next(): drop task_inner");
     drop(task_inner);
+    kprintln!("[KERN] task::exit_current_and_run_next(): drop task");
     drop(task);
     // however, if this is the main thread of current process
     // the process should terminate at once
     if tid == 0 {
+        kprintln!("[KERN] task::exit_current_and_run_next(): it's main thread, process should terminate at once");
         remove_from_pid2process(process.getpid());
         let mut process_inner = process.inner_exclusive_access();
         // mark this process as a zombie process
+        kprintln!("[KERN] task::exit_current_and_run_next(): mark this process as a zombie process");
         process_inner.is_zombie = true;
         // record exit code of main process
+        kprintln!("[KERN] task::exit_current_and_run_next(): record exit code in process_inner");
         process_inner.exit_code = exit_code;
 
         {
             // move all child processes under init process
+            kprintln!("[KERN] task::exit_current_and_run_next(): move all child processes under INITPROC");
             let mut initproc_inner = INITPROC.inner_exclusive_access();
             for child in process_inner.children.iter() {
                 child.inner_exclusive_access().parent = Some(Arc::downgrade(&INITPROC));
@@ -240,22 +260,26 @@
         // deallocate user res (including tid/trap_cx/ustack) of all threads
         // it has to be done before we dealloc the whole memory_set
         // otherwise they will be deallocated twice
+        kprintln!("[KERN] task::exit_current_and_run_next(): deallocate user res (tid/trap_cx/ustack) of all threads");
         for task in process_inner.tasks.iter().filter(|t| t.is_some()) {
             let task = task.as_ref().unwrap();
             let mut task_inner = task.inner_exclusive_access();
             task_inner.res = None;
         }
-
+        kprintln!("[KERN] task::exit_current_and_run_next(): clear children Vector in process_inner");
         process_inner.children.clear();
         // deallocate other data in user space i.e. program code/data section
+        kprintln!("[KERN] task::exit_current_and_run_next(): deallocate code/data in user space");
         process_inner.memory_set.recycle_data_pages();
         // drop file descriptors
+        kprintln!("[KERN] task::exit_current_and_run_next(): drop file descriptors");
         process_inner.fd_table.clear();
     }
+    kprintln!("[KERN] task::exit_current_and_run_next(): drop process");
     drop(process);
     // we do not have to save task context
     let mut _unused = TaskContext::zero_init();
-    kprintln!("[KERN] task::exit_current_and_run_next() end");
+    kprintln!("[KERN] task::exit_current_and_run_next() end, sched next task");
     schedule(&mut _unused as *mut _);
 }
 
diff --git a/ch9-log/src/os/task/process.rs.html b/ch9-log/src/os/task/process.rs.html
index 3b280376..5dc10c16 100644
--- a/ch9-log/src/os/task/process.rs.html
+++ b/ch9-log/src/os/task/process.rs.html
@@ -285,6 +285,12 @@
 282
 283
 284
+285
+286
+287
+288
+289
+290
 
use super::id::RecycleAllocator;
 use super::manager::insert_into_pid2process;
 use super::TaskControlBlock;
@@ -359,14 +365,14 @@
     }
 
     pub fn new(elf_data: &[u8]) -> Arc<Self> {
-        // memory_set with elf program headers/trampoline/trap context/user stack
-        kprintln!("[KERN] task::process::new() begin");
-        kprintln!("[KERN] task::process::new(): build MemorySet, set user_stack_base, set entry_point");
+        // memory_set with elf program headers/trampoline/user stack_base addr/entry_point
+        kprintln!("[KERN] task::process::PCB::new() begin");
+        kprintln!("[KERN] task::process::PCB::new(): build MemorySet, set trampoline, user_stack_base, entry_point...");
         let (memory_set, ustack_base, entry_point) = MemorySet::from_elf(elf_data);
         // allocate a pid
-        kprintln!("[KERN] task::process::new(): allocate a pid");
+        kprintln!("[KERN] task::process::PCB::new(): allocate a pid");
         let pid_handle = pid_alloc();
-        kprintln!("[KERN] task::process::new(): new ProcessControlBlockInner");
+        kprintln!("[KERN] task::process::PCB::new(): new ProcessControlBlockInner");
         let process = Arc::new(Self {
             pid: pid_handle,
             inner: unsafe {
@@ -394,15 +400,15 @@
             },
         });
         // create a main thread, we should allocate ustack and trap_cx here
-        kprintln!("[KERN] task::process::new(): create a main thread begin");
-        kprintln!("[KERN] task::process::new(): create a main thread: new TCB(alloc kstack, utack & trap_cx...) ");
+        kprintln!("[KERN] task::process::PCB::new(): create a main thread... start");
+        kprintln!("[KERN] task::process::PCB::new(): create a main thread: new TCB(alloc kstack, utack & trap_cx...) ");
         let task = Arc::new(TaskControlBlock::new(
             Arc::clone(&process),
             ustack_base,
             true,
         ));
         // prepare trap_cx of main thread
-        kprintln!("[KERN] task::process::new(): create a main thread: set trap_cx(entry_point, ustack_top, k_satp, k_sp, trap_handler) ");
+        kprintln!("[KERN] task::process::PCB::new(): create a main thread: set trap_cx(entry_point, ustack_top, k_satp, k_sp, trap_handler) ");
         let task_inner = task.inner_exclusive_access();
         let trap_cx = task_inner.get_trap_cx();
         let ustack_top = task_inner.res.as_ref().unwrap().ustack_top();
@@ -415,38 +421,43 @@
             kstack_top,
             trap_handler as usize,
         );
-        kprintln!("[KERN] task::process::new(): create a main thread end");
+        kprintln!("[KERN] task::process::PCB::new(): create a main thread... done");
         // add main thread to the process
-        kprintln!("[KERN] task::process::new(): add main thread to the process");
+        kprintln!("[KERN] task::process::PCB::new(): add main thread to the process");
         let mut process_inner = process.inner_exclusive_access();
         process_inner.tasks.push(Some(Arc::clone(&task)));
         drop(process_inner);
-        kprintln!("[KERN] task::process::new(): insert <pid, PCB> in PID2PCB BTreeMap");
+        kprintln!("[KERN] task::process::PCB::new(): insert <pid, PCB> in PID2PCB BTreeMap");
         insert_into_pid2process(process.getpid(), Arc::clone(&process));
         // add main thread to scheduler
-        kprintln!("[KERN] task::process::new(): add_task(task): add main thread to scheduler");
+        kprintln!("[KERN] task::process::PCB::new(): add_task(task): add main thread to scheduler");
         add_task(task);
-        kprintln!("[KERN] task::process::new() end");
+        kprintln!("[KERN] task::process::PCB::new() end");
         process
     }
 
     /// Only support processes with a single thread.
     pub fn exec(self: &Arc<Self>, elf_data: &[u8], args: Vec<String>) {
+        kprintln!("[KERN] task::process::PCB::exec() begin");
         assert_eq!(self.inner_exclusive_access().thread_count(), 1);
-        // memory_set with elf program headers/trampoline/trap context/user stack
-        kprintln!("[KERN] task::process::exec() begin");
+        // memory_set with elf program headers/trampoline/user_stack_base addr/entry_point
+        kprintln!("[KERN] task::process::PCB::exec(): build MemorySet,  trampoline, user_stack_base, entry_point...");
         let (memory_set, ustack_base, entry_point) = MemorySet::from_elf(elf_data);
         let new_token = memory_set.token();
         // substitute memory_set
+        kprintln!("[KERN] task::process::PCB::exec():  substitute memory_set, ustack_base");
         self.inner_exclusive_access().memory_set = memory_set;
         // then we alloc user resource for main thread again
         // since memory_set has been changed
         let task = self.inner_exclusive_access().get_task(0);
         let mut task_inner = task.inner_exclusive_access();
         task_inner.res.as_mut().unwrap().ustack_base = ustack_base;
+        kprintln!("[KERN] task::process::PCB::exec():  alloc user resource for this thread");
         task_inner.res.as_mut().unwrap().alloc_user_res();
+        kprintln!("[KERN] task::process::PCB::exec():  set  trap_cx_ppn for this thread");
         task_inner.trap_cx_ppn = task_inner.res.as_mut().unwrap().trap_cx_ppn();
         // push arguments on user stack
+        kprintln!("[KERN] task::process::PCB::exec():  push arguments on user stack for this thread");
         let mut user_sp = task_inner.res.as_mut().unwrap().ustack_top();
         user_sp -= (args.len() + 1) * core::mem::size_of::<usize>();
         let argv_base = user_sp;
@@ -472,6 +483,7 @@
         // make the user_sp aligned to 8B for k210 platform
         user_sp -= user_sp % core::mem::size_of::<usize>();
         // initialize trap_cx
+        kprintln!("[KERN] task::process::PCB::exec():  set trap_cx(entry_point, ustack_top, k_satp, k_sp, trap_handler, argc=x[10], argv=x[11])");
         let mut trap_cx = TrapContext::app_init_context(
             entry_point,
             user_sp,
@@ -482,22 +494,22 @@
         trap_cx.x[10] = args.len();
         trap_cx.x[11] = argv_base;
         *task_inner.get_trap_cx() = trap_cx;
-        kprintln!("[KERN] task::process::exec() end");
+        kprintln!("[KERN] task::process::PCB::exec() end");
     }
 
     /// Only support processes with a single thread.
     pub fn fork(self: &Arc<Self>) -> Arc<Self> {
-        kprintln!("[KERN] task::process::fork() begin");
+        kprintln!("[KERN] task::process::PCB::fork() begin");
         let mut parent = self.inner_exclusive_access();
         assert_eq!(parent.thread_count(), 1);
         // clone parent's memory_set completely including trampoline/ustacks/trap_cxs
-        kprintln!("[KERN] task::process::fork(): clone parent's memory_set for child");
+        kprintln!("[KERN] task::process::PCB::fork(): clone parent's memory_set for child");
         let memory_set = MemorySet::from_existed_user(&parent.memory_set);
         // alloc a pid
-        kprintln!("[KERN] task::process::fork(): alloc a new pid for child");
+        kprintln!("[KERN] task::process::PCB::fork(): alloc a new pid for child");
         let pid = pid_alloc();
         // copy fd table
-        kprintln!("[KERN] task::process::fork(): copy fd table for child");
+        kprintln!("[KERN] task::process::PCB::fork(): copy fd table for child");
         let mut new_fd_table: Vec<Option<Arc<dyn File + Send + Sync>>> = Vec::new();
         for fd in parent.fd_table.iter() {
             if let Some(file) = fd {
@@ -507,7 +519,7 @@
             }
         }
         // create child process pcb
-        kprintln!("[KERN] task::process::fork(): new child PCB with new pid, memory_set, fd_table, ...");
+        kprintln!("[KERN] task::process::PCB::fork(): new child PCB with new pid, memory_set, fd_table, ...");
         let child = Arc::new(Self {
             pid,
             inner: unsafe {
@@ -528,10 +540,10 @@
             },
         });
         // add child
-        kprintln!("[KERN] task::process::fork(): add child link in parent' children Vec");
+        kprintln!("[KERN] task::process::PCB::fork(): add child link in parent' children Vec");
         parent.children.push(Arc::clone(&child));
         // create main thread of child process
-        kprintln!("[KERN] task::process::fork(): TaskControlBlock::new(): create main thread of child process");
+        kprintln!("[KERN] task::process::PCB::fork(): TaskControlBlock::new(): create main thread of child process");
         let task = Arc::new(TaskControlBlock::new(
             Arc::clone(&child),
             parent
@@ -546,22 +558,22 @@
             false,
         ));
         // attach task to child process
-        kprintln!("[KERN] task::process::fork(): attach child TCB to child PCB");
+        kprintln!("[KERN] task::process::PCB::fork(): attach child TCB to child PCB");
         let mut child_inner = child.inner_exclusive_access();
         child_inner.tasks.push(Some(Arc::clone(&task)));
         drop(child_inner);
         // modify kstack_top in trap_cx of this thread
-        kprintln!("[KERN] task::process::fork(): modify child's kstack_top in trap_cx of child");
+        kprintln!("[KERN] task::process::PCB::fork(): modify child's kstack_top in trap_cx of child");
         let task_inner = task.inner_exclusive_access();
         let trap_cx = task_inner.get_trap_cx();
         trap_cx.kernel_sp = task.kstack.get_top();
         drop(task_inner);
-        kprintln!("[KERN] task::process::fork(): insert <child pid, child PCB> in PID2PCB BTreeMap");
+        kprintln!("[KERN] task::process::PCB::fork(): insert <child pid, child PCB> in PID2PCB BTreeMap");
         insert_into_pid2process(child.getpid(), Arc::clone(&child));
         // add this thread to scheduler
-        kprintln!("[KERN] task::process::fork(): add_task(child task): add child thread to scheduler");
+        kprintln!("[KERN] task::process::PCB::fork(): add_task(child task): add child thread to scheduler");
         add_task(task);
-        kprintln!("[KERN] task::process::fork() end");
+        kprintln!("[KERN] task::process::PCB::fork() end");
         child
     }
 
diff --git a/ch9-log/src/os/task/task.rs.html b/ch9-log/src/os/task/task.rs.html
index 806c0f4e..68a22206 100644
--- a/ch9-log/src/os/task/task.rs.html
+++ b/ch9-log/src/os/task/task.rs.html
@@ -132,13 +132,13 @@
         ustack_base: usize,
         alloc_user_res: bool,
     ) -> Self {
-        kprintln!("[KERN] TaskControlBlock::new() begin");
+        kprintln!("[KERN] task::task::TaskControlBlock::new() begin");
         let res = TaskUserRes::new(Arc::clone(&process), ustack_base, alloc_user_res);
         let trap_cx_ppn = res.trap_cx_ppn();
-        kprintln!("[KERN] TaskControlBlock::new(): alloc kernel stack for TCB");
+        kprintln!("[KERN] task::task::TaskControlBlock::new(): alloc kernel stack for TCB");
         let kstack = kstack_alloc();
         let kstack_top = kstack.get_top();
-        kprintln!("[KERN] TaskControlBlock::new() end");
+        kprintln!("[KERN] task::task::TaskControlBlock::new() end");
         Self {
             process: Arc::downgrade(&process),
             kstack,