diff --git a/src/ipc/server.rs b/src/ipc/server.rs index 1e886d48..08890d15 100755 --- a/src/ipc/server.rs +++ b/src/ipc/server.rs @@ -464,7 +464,7 @@ impl ServerHolder { new_mitm_server_fn: self.new_mitm_server_fn, handle_type: WaitHandleType::Session, mitm_forward_info: mitm_fwd_info, - is_mitm_service: forward_handle != 0, + is_mitm_service: forward_handle != svc::INVALID_HANDLE, service_name: sm::ServiceName::empty(), domain_table: self.domain_table.clone(), }) @@ -519,20 +519,20 @@ impl ServerHolder { "MitM server objects should always own their handles." ); sm.atmosphere_uninstall_mitm(self.service_name)?; - } - else { + } else { sm.unregister_service(self.service_name)?; } } - if self.is_mitm_service { - sf::Session::from(self.mitm_forward_info).close(); - } - sm.detach_client(sf::ProcessId::new())?; } } + // Forward info may be valid despite having an empty service name (like a cloned session) + if self.is_mitm_service { + sf::Session::from(self.mitm_forward_info).close(); + } + // Don't close our session like a normal one (like the forward session below) as we allocated the object IDs ourselves, the only thing we do have to close is the handle if self.info.owns_handle { svc::close_handle(self.info.handle)?; diff --git a/src/thread.rs b/src/thread.rs index a0cc1370..3fae0206 100755 --- a/src/thread.rs +++ b/src/thread.rs @@ -292,23 +292,23 @@ impl Builder { f: F, ) -> crate::result::Result> where - F: FnOnce() -> T, + F: FnOnce() -> T + 'static, F: Send, - T: Send, + T: Send + 'static, { Ok(JoinHandle(unsafe { self.spawn_unchecked_(f, None) }?)) } #[allow(unsafe_op_in_unsafe_fn)] - unsafe fn spawn_unchecked_<'scope, F, T>( + unsafe fn spawn_unchecked_( self, f: F, scope_data: Option>, - ) -> crate::result::Result> + ) -> crate::result::Result> where - F: FnOnce() -> T, + F: FnOnce() -> T + 'static, F: Send, - T: Send, + T: Send + 'static, { let Builder { name, @@ -327,7 +327,7 @@ impl Builder { let my_thread = Thread::new_inner(name); let _their_thread = my_thread.clone(); - let my_packet: Arc> = Arc::new(Packet { + let my_packet: Arc> = Arc::new(Packet { scope: scope_data, result: UnsafeCell::new(None), _marker: PhantomData, @@ -370,7 +370,7 @@ impl Builder { // will call `decrement_num_running_threads` and therefore signal that this thread is // done. drop(their_packet); - // Here, the lifetime `'scope` can end. `main` keeps running for a bit + // Here, the lifetime `'static` can end. `main` keeps running for a bit // after that before returning itself. }; @@ -803,9 +803,9 @@ impl Drop for Packet<'_, T> { // Book-keeping so the scope knows when it's done. if let Some(scope) = &self.scope { // Now that there will be no more user code running on this thread - // that can use 'scope, mark the thread as 'finished'. + // that can use 'static, mark the thread as 'finished'. // It's important we only do this after the `result` has been dropped, - // since dropping it might still use things it borrowed from 'scope. + // since dropping it might still use things it borrowed from 'static. scope.decrement_num_running_threads(unhandled_panic); } } diff --git a/src/thread/scoped.rs b/src/thread/scoped.rs index 07bf73e9..1350ee44 100755 --- a/src/thread/scoped.rs +++ b/src/thread/scoped.rs @@ -189,8 +189,8 @@ impl<'scope> Scope<'scope, '_> { /// [`join`]: ScopedJoinHandle::join pub fn spawn(&'scope self, f: F) -> ScopedJoinHandle<'scope, T> where - F: FnOnce() -> T + Send + 'scope, - T: Send + 'scope, + F: FnOnce() -> T + Send + 'scope + 'static, + T: Send + 'scope + 'static, { Builder::new() .spawn_scoped(self, f) @@ -251,8 +251,8 @@ impl Builder { f: F, ) -> crate::result::Result> where - F: FnOnce() -> T + Send + 'scope, - T: Send + 'scope, + F: FnOnce() -> T + Send + 'scope + 'static, + T: Send + 'scope + 'static, { Ok(ScopedJoinHandle(unsafe { self.spawn_unchecked_(f, Some(scope.data.clone()))