Forráskód Böngészése

change(Process): remove `do_kill_process` and use `do_exit` for those use cases

greatbridf 7 hónapja
szülő
commit
c9fc06cae9

+ 1 - 1
src/kernel/syscall/procops.rs

@@ -610,7 +610,7 @@ fn sigreturn() -> KResult<SyscallNoReturn> {
                 "`sigreturn` failed in thread {} with error {err}!",
                 thread.tid
             );
-            Task::block_on(thread.process.force_kill(Signal::SIGSEGV));
+            Task::block_on(thread.force_kill(Signal::SIGSEGV));
         })?;
 
     Ok(SyscallNoReturn)

+ 0 - 8
src/kernel/task/process.rs

@@ -486,14 +486,6 @@ impl Process {
             needs_notify: false,
         }
     }
-
-    pub async fn force_kill(self: &Arc<Self>, signal: Signal) {
-        let mut proc_list = ProcessList::get().write().await;
-        unsafe {
-            // SAFETY: Preemption is disabled.
-            proc_list.do_kill_process(self, WaitType::Signaled(signal));
-        }
-    }
 }
 
 impl WaitList {

+ 1 - 62
src/kernel/task/process_list.rs

@@ -104,71 +104,10 @@ impl ProcessList {
     }
 
     /// Make the process a zombie and notify the parent.
-    /// # Safet
+    /// # Safety
     /// This function will destroy the process and all its threads.
     /// It is the caller's responsibility to ensure that the process is not
     /// running or will not run after this function is called.
-    pub unsafe fn do_kill_process(&mut self, process: &Arc<Process>, status: WaitType) {
-        if process.pid == 1 {
-            panic!("init exited");
-        }
-
-        let inner = process.inner.access_mut(self.prove_mut());
-        // TODO!!!!!!: When we are killing multiple threads, we need to wait until all
-        // the threads are stopped then proceed.
-        for thread in inner.threads.values().map(|t| t.upgrade().unwrap()) {
-            assert!(thread.tid == Thread::current().tid);
-            // TODO: Send SIGKILL to all threads.
-            thread.files.close_all();
-            thread.dead.store(true, Ordering::SeqCst);
-        }
-
-        // If we are the session leader, we should drop the control terminal.
-        if process.session(self.prove()).sid == process.pid {
-            if let Some(terminal) =
-                Task::block_on(process.session(self.prove()).drop_control_terminal())
-            {
-                terminal.drop_session();
-            }
-        }
-
-        // Release the MMList as well as the page table.
-        unsafe {
-            // SAFETY: We are exiting the process, so no one might be using it.
-            process.mm_list.replace(None);
-        }
-
-        // Make children orphans (adopted by init)
-        {
-            let init = self.init_process();
-            inner.children.retain(|_, child| {
-                let child = child.upgrade().unwrap();
-                // SAFETY: `child.parent` must be ourself. So we don't need to free it.
-                unsafe { child.parent.swap(Some(init.clone())) };
-                init.add_child(&child, self.prove_mut());
-
-                false
-            });
-        }
-
-        let mut init_notify = self.init_process().notify_batch();
-        process
-            .wait_list
-            .drain_exited()
-            .into_iter()
-            .for_each(|item| init_notify.notify(item));
-        init_notify.finish(self.prove());
-
-        process.parent(self.prove()).notify(
-            process.exit_signal.expect("Process must set exit signal"),
-            WaitObject {
-                pid: process.pid,
-                code: status,
-            },
-            self.prove(),
-        );
-    }
-
     pub async unsafe fn do_exit(
         &mut self,
         thread: &Thread,

+ 2 - 2
src/kernel/task/signal.rs

@@ -250,8 +250,8 @@ impl SignalList {
                     }
                 }
                 signal => {
-                    // Default to terminate the process.
-                    Thread::current().process.force_kill(signal).await;
+                    // Default to terminate the thread.
+                    Thread::current().force_kill(signal).await;
                     return;
                 }
             }

+ 10 - 0
src/kernel/task/thread.rs

@@ -377,6 +377,16 @@ impl Thread {
         }
     }
 
+    pub async fn force_kill(&self, signal: Signal) {
+        let mut proc_list = ProcessList::get().write().await;
+        unsafe {
+            // SAFETY: Preemption is disabled.
+            proc_list
+                .do_exit(self, WaitType::Signaled(signal), false)
+                .await;
+        }
+    }
+
     pub fn is_dead(&self) -> bool {
         self.dead.load(Ordering::SeqCst)
     }