forked from rcore-os/zCore
add implement of thread read state syscall
This commit is contained in:
parent
b7583225fa
commit
036c5a7888
|
@ -105,6 +105,9 @@ impl Syscall<'_> {
|
|||
Sys::THREAD_WRITE_STATE => {
|
||||
self.sys_thread_write_state(a0 as _, a1 as _, a2.into(), a3 as _)
|
||||
}
|
||||
Sys::THREAD_READ_STATE => {
|
||||
self.sys_thread_read_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 => {
|
||||
|
|
|
@ -2,8 +2,8 @@ use core::convert::TryFrom;
|
|||
use {super::*, zircon_object::task::*};
|
||||
|
||||
impl Syscall<'_> {
|
||||
/// Create a new process.
|
||||
///
|
||||
/// Create a new process.
|
||||
///
|
||||
/// Upon success, handles for the new process and the root of its address space are returned.
|
||||
pub fn sys_process_create(
|
||||
&self,
|
||||
|
@ -38,7 +38,7 @@ impl Syscall<'_> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
/// Exits the currently running process.
|
||||
/// Exits the currently running process.
|
||||
pub fn sys_process_exit(&mut self, code: i64) -> ZxResult {
|
||||
info!("proc.exit: code={:?}", code);
|
||||
let proc = self.thread.proc();
|
||||
|
@ -46,8 +46,8 @@ impl Syscall<'_> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
/// Creates a thread within the specified process.
|
||||
///
|
||||
/// Creates a thread within the specified process.
|
||||
///
|
||||
/// Upon success a handle for the new thread is returned.
|
||||
pub fn sys_thread_create(
|
||||
&self,
|
||||
|
@ -73,8 +73,8 @@ impl Syscall<'_> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
/// Start execution on a process.
|
||||
///
|
||||
/// Start execution on a process.
|
||||
///
|
||||
/// This system call is similar to `zx_thread_start()`, but is used for the purpose of starting the first thread in a process.
|
||||
pub fn sys_process_start(
|
||||
&self,
|
||||
|
@ -107,8 +107,32 @@ impl Syscall<'_> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
/// Write one aspect of thread state.
|
||||
///
|
||||
/// Read one aspect of thread state.
|
||||
///
|
||||
/// The thread state may only be written when the thread is halted for an exception or the thread is suspended.
|
||||
pub fn sys_thread_read_state(
|
||||
&self,
|
||||
handle: HandleValue,
|
||||
kind: u32,
|
||||
mut buffer: UserOutPtr<u8>,
|
||||
buffer_size: usize,
|
||||
) -> ZxResult {
|
||||
let kind = ThreadStateKind::try_from(kind).map_err(|_| ZxError::INVALID_ARGS)?;
|
||||
info!(
|
||||
"thread.read_state: handle={:#x?}, kind={:#x?}, buf=({:#x?}; {:#x?})",
|
||||
handle, kind, buffer, buffer_size,
|
||||
);
|
||||
let proc = self.thread.proc();
|
||||
let thread = proc.get_object_with_rights::<Thread>(handle, Rights::READ)?;
|
||||
//TODO: Remove allocation
|
||||
let mut buf = vec![0;buffer_size];
|
||||
thread.read_state(kind, &mut buf)?;
|
||||
buffer.write_array(&buf[..])?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Write one aspect of thread state.
|
||||
///
|
||||
/// The thread state may only be written when the thread is halted for an exception or the thread is suspended.
|
||||
pub fn sys_thread_write_state(
|
||||
&self,
|
||||
|
@ -129,8 +153,8 @@ impl Syscall<'_> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
/// Sets process as critical to job.
|
||||
///
|
||||
/// Sets process as critical to job.
|
||||
///
|
||||
/// When process terminates, job will be terminated as if `zx_task_kill()` was called on it.
|
||||
pub fn sys_job_set_critical(
|
||||
&self,
|
||||
|
@ -156,7 +180,7 @@ impl Syscall<'_> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
/// Start execution on a thread.
|
||||
/// Start execution on a thread.
|
||||
pub fn sys_thread_start(
|
||||
&self,
|
||||
handle_value: HandleValue,
|
||||
|
@ -178,7 +202,7 @@ impl Syscall<'_> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
/// Terminate the current running thread.
|
||||
/// Terminate the current running thread.
|
||||
///
|
||||
/// Causes the currently running thread to cease running and exit.
|
||||
pub fn sys_thread_exit(&mut self) -> ZxResult {
|
||||
|
@ -187,7 +211,7 @@ impl Syscall<'_> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
/// Suspend the given task.
|
||||
/// Suspend the given task.
|
||||
///
|
||||
/// > This function replaces task_suspend. When all callers are updated, `zx_task_suspend()` will be deleted and this function will be renamed ```zx_task_suspend()```.
|
||||
pub fn sys_task_suspend_token(
|
||||
|
@ -234,7 +258,7 @@ impl Syscall<'_> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
/// Create a new child job object given a parent job.
|
||||
/// Create a new child job object given a parent job.
|
||||
pub fn sys_job_create(
|
||||
&self,
|
||||
parent: HandleValue,
|
||||
|
@ -258,7 +282,7 @@ impl Syscall<'_> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Sets one or more security and/or resource policies to an empty job.
|
||||
/// Sets one or more security and/or resource policies to an empty job.
|
||||
pub fn sys_job_set_policy(
|
||||
&self,
|
||||
handle: HandleValue,
|
||||
|
@ -299,8 +323,8 @@ impl Syscall<'_> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Read from the given process's address space.
|
||||
///
|
||||
/// Read from the given process's address space.
|
||||
///
|
||||
/// > This function will eventually be replaced with something vmo-centric.
|
||||
pub fn sys_process_read_memory(
|
||||
&self,
|
||||
|
@ -323,7 +347,7 @@ impl Syscall<'_> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
/// Write into the given process's address space.
|
||||
/// Write into the given process's address space.
|
||||
pub fn sys_process_write_memory(
|
||||
&self,
|
||||
handle_value: HandleValue,
|
||||
|
|
Loading…
Reference in New Issue