ANDROID: rust_binder: rework process cleanup

Rust Binder cleanup is reworked to match the order in which C Binder
cleans up things. A few notes on the changes:

* Actually dropping thread objects is done at the very end because they
  contain a call to synchronize_rcu() which is slow. This ensures that
  death notifications are sent without waiting for those calls. This
  avoids failures in rustBinderTest. (The test is already flaky, but
  this extra sleep makes the flake much more likely to happen.)

* We now free refs on remote nodes in release explicitly. Previously
  that only happened implicitly when everything keeping the ref alive
  has been dropped. To avoid spurious warnings from this, the warning
  print about dropping a ref that doesn't exist is only printed if the
  process is alive.

Bug: 431914626
Change-Id: I3d1f4f15ffac7587d1bb0113a41330b2aea69b3d
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
This commit is contained in:
Alice Ryhl
2025-08-05 11:59:13 +00:00
parent b632dc2e1d
commit 5a41bb32dd
4 changed files with 67 additions and 66 deletions
+8 -4
View File
@@ -78,6 +78,13 @@ impl PollCondVar {
inner <- CondVar::new(name, key),
})
}
/// Clear anything registered using `register_wait`.
pub fn clear(&self) {
// SAFETY: The pointer points at a valid `wait_queue_head`. The destructor waits an rcu
// grace period before the wait queue is freed.
unsafe { bindings::__wake_up_pollfree(self.inner.wait_queue_head.get()) };
}
}
// Make the `CondVar` methods callable on `PollCondVar`.
@@ -92,10 +99,7 @@ impl Deref for PollCondVar {
#[pinned_drop]
impl PinnedDrop for PollCondVar {
fn drop(self: Pin<&mut Self>) {
// Clear anything registered using `register_wait`.
//
// SAFETY: The pointer points at a valid `wait_queue_head`.
unsafe { bindings::__wake_up_pollfree(self.inner.wait_queue_head.get()) };
self.clear();
// Wait for epoll items to be properly removed.
//