forked from rcore-os/zCore
impl sys_task_kill, bug with bug(kill job cannot work)
This commit is contained in:
parent
a08507045a
commit
bc4124ef6c
|
@ -174,6 +174,10 @@ fn spawn(thread: Arc<Thread>) {
|
|||
let future = async move {
|
||||
kernel_hal::Thread::set_tid(thread.id(), thread.proc().id());
|
||||
loop {
|
||||
if thread.is_killed() {
|
||||
thread.internal_exit();
|
||||
break;
|
||||
}
|
||||
let mut cx = thread.wait_for_run().await;
|
||||
trace!("go to user: {:#x?}", cx);
|
||||
debug!("switch to {}|{}", thread.proc().name(), thread.name());
|
||||
|
|
|
@ -194,6 +194,24 @@ impl Job {
|
|||
pub fn children_ids(&self) -> Vec<KoID> {
|
||||
self.inner.lock().children.iter().map(|j| j.id()).collect()
|
||||
}
|
||||
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.inner.lock().is_empty()
|
||||
}
|
||||
|
||||
pub fn kill(&self) {
|
||||
let mut inner = self.inner.lock();
|
||||
for child in inner.children.iter() {
|
||||
if !child.is_empty() {
|
||||
child.kill();
|
||||
}
|
||||
}
|
||||
inner.children.clear();
|
||||
for proc in inner.processes.iter() {
|
||||
proc.kill();
|
||||
}
|
||||
inner.processes.clear();
|
||||
}
|
||||
}
|
||||
|
||||
impl JobInner {
|
||||
|
|
|
@ -178,6 +178,20 @@ impl Process {
|
|||
self.job.process_exit(self.base.id, retcode);
|
||||
}
|
||||
|
||||
pub fn kill(&self) {
|
||||
let retcode = -1024;
|
||||
let mut inner = self.inner.lock();
|
||||
inner.status = Status::Exited(retcode);
|
||||
// TODO: exit all threads
|
||||
self.base.signal_set(Signal::PROCESS_TERMINATED);
|
||||
for thread in inner.threads.iter() {
|
||||
thread.kill();
|
||||
}
|
||||
inner.threads.clear();
|
||||
inner.handles.clear();
|
||||
self.job.process_exit(self.base.id, retcode);
|
||||
}
|
||||
|
||||
/// Check whether `condition` is allowed in the parent job's policy.
|
||||
pub fn check_policy(&self, condition: PolicyCondition) -> ZxResult {
|
||||
match self
|
||||
|
|
|
@ -118,6 +118,8 @@ struct ThreadInner {
|
|||
state: ThreadState,
|
||||
/// The time this thread has run on cpu
|
||||
time: u128,
|
||||
/// kill by other thread
|
||||
dying: bool,
|
||||
}
|
||||
|
||||
impl ThreadInner {
|
||||
|
@ -217,11 +219,20 @@ impl Thread {
|
|||
self.internal_exit();
|
||||
}
|
||||
|
||||
pub(super) fn internal_exit(&self) {
|
||||
pub fn internal_exit(&self) {
|
||||
self.base.signal_set(Signal::THREAD_TERMINATED);
|
||||
self.inner.lock().state = ThreadState::Dead;
|
||||
}
|
||||
|
||||
pub fn kill(&self) {
|
||||
// self.inner.lock().state = ThreadState::Dying;
|
||||
self.inner.lock().dying = true;
|
||||
}
|
||||
|
||||
pub fn is_killed(&self) -> bool {
|
||||
self.inner.lock().dying
|
||||
}
|
||||
|
||||
/// Read one aspect of thread state.
|
||||
pub fn read_state(&self, kind: ThreadStateKind, buf: &mut [u8]) -> ZxResult<usize> {
|
||||
let inner = self.inner.lock();
|
||||
|
|
|
@ -103,6 +103,7 @@ impl Syscall<'_> {
|
|||
Sys::THREAD_WRITE_STATE => {
|
||||
self.sys_thread_write_state(a0 as _, a1 as _, a2.into(), a3 as _)
|
||||
}
|
||||
Sys::TASK_KILL => self.sys_task_kill(a0 as _),
|
||||
Sys::THREAD_EXIT => self.sys_thread_exit(),
|
||||
Sys::PROCESS_CREATE => {
|
||||
self.sys_process_create(a0 as _, a1.into(), a2 as _, a3 as _, a4.into(), a5.into())
|
||||
|
|
|
@ -189,6 +189,26 @@ impl Syscall<'_> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn sys_task_kill(&self, handle: HandleValue) -> ZxResult {
|
||||
info!("task.kill: handle={:?}", handle);
|
||||
let proc = self.thread.proc();
|
||||
|
||||
if let Ok(_job) = proc.get_object_with_rights::<Job>(handle, Rights::DESTROY) {
|
||||
// job.kill();
|
||||
return Err(ZxError::WRONG_TYPE);
|
||||
} else if let Ok(proc) = proc.get_object_with_rights::<Process>(handle, Rights::DESTROY) {
|
||||
proc.kill();
|
||||
} else if let Ok(thread) = proc.get_object_with_rights::<Thread>(handle, Rights::DESTROY) {
|
||||
match thread.state() {
|
||||
ThreadState::Running | ThreadState::Suspended => thread.kill(),
|
||||
_ => {}
|
||||
}
|
||||
} else {
|
||||
return Err(ZxError::WRONG_TYPE);
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
pub fn sys_job_create(
|
||||
&self,
|
||||
parent: HandleValue,
|
||||
|
|
Loading…
Reference in New Issue