Skip to content

Commit

Permalink
bugfix #144: Do not free kstack when the main thread exits
Browse files Browse the repository at this point in the history
  • Loading branch information
wyfcyx committed Mar 3, 2024
1 parent 03c4188 commit aaab6d3
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions os/src/task/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,13 @@ pub fn exit_current_and_run_next(exit_code: i32) {
process_inner.memory_set.recycle_data_pages();
// drop file descriptors
process_inner.fd_table.clear();
// Remove all tasks except for the main thread itself.
// This is because we are still using the kstack under the TCB
// of the main thread. This TCB, including its kstack, will be
// deallocated when the process is reaped via waitpid.
while process_inner.tasks.len() > 1 {
process_inner.tasks.pop();
}
}
drop(process);
// we do not have to save task context
Expand Down

0 comments on commit aaab6d3

Please sign in to comment.