From 6b70922381c8c7abd12357bf5cab9480013c146e Mon Sep 17 00:00:00 2001 From: Sean Cross Date: Fri, 21 May 2021 13:01:03 +0800 Subject: [PATCH] xous: add `JoinThread` syscall The `JoinThread` call will eventually be used to let one thread wait on another. Signed-off-by: Sean Cross --- xous-rs/src/syscall.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/xous-rs/src/syscall.rs b/xous-rs/src/syscall.rs index 8c7c4e4a2..cf0f691ab 100644 --- a/xous-rs/src/syscall.rs +++ b/xous-rs/src/syscall.rs @@ -318,6 +318,9 @@ pub enum SysCall { /// in a future reconnection. Disconnect(CID), + /// Waits for a thread to finish, and returns the return value of that thread. + JoinThread(TID), + /// This syscall does not exist. It captures all possible /// arguments so detailed analysis can be performed. Invalid(usize, usize, usize, usize, usize, usize, usize), @@ -359,6 +362,7 @@ pub enum SysCallNumber { GetProcessId = 33, DestroyServer = 34, Disconnect = 35, + JoinThread = 36, Invalid, } @@ -400,6 +404,7 @@ impl SysCallNumber { 33 => GetProcessId, 34 => DestroyServer, 35 => Disconnect, + 36 => JoinThread, _ => Invalid, } } @@ -721,6 +726,16 @@ impl SysCall { 0, 0, ], + SysCall::JoinThread(tid) => [ + SysCallNumber::JoinThread as usize, + *tid as usize, + 0, + 0, + 0, + 0, + 0, + 0, + ], SysCall::Invalid(a1, a2, a3, a4, a5, a6, a7) => [ SysCallNumber::Invalid as usize, *a1, @@ -882,6 +897,7 @@ impl SysCall { SysCall::DestroyServer(SID::from_u32(a1 as _, a2 as _, a3 as _, a4 as _)) } SysCallNumber::Disconnect => SysCall::Disconnect(a1 as _), + SysCallNumber::JoinThread => SysCall::JoinThread(a1 as _), SysCallNumber::Invalid => SysCall::Invalid(a1, a2, a3, a4, a5, a6, a7), }) } @@ -1568,6 +1584,16 @@ pub unsafe fn disconnect(cid: CID) -> core::result::Result<(), Error> { }) } +pub fn join_thread(tid: TID) -> core::result::Result { + rsyscall(SysCall::JoinThread(tid)).and_then(|result| { + if let Result::Scalar1(val) = result { + Ok(val) + } else { + Err(Error::InternalError) + } + }) +} + pub fn rsyscall(call: SysCall) -> SysCallResult { let mut ret = Result::Ok; let args = call.as_args();