Skip to contentSkip to conversation

rust_binder: avoid name mangling for get_work[_local]

PATCH In review Alice Ryhl 2 participants 2 messages Feb 19

Subsystems (2)
lore
Share & tools
lore

Alice Ryhl

author maintainer
#0 lore raw

PATCH v2 1/1 rust_binder: avoid name mangling for get_work[_local]

Currently ps -A shows processes waiting on schedule() in functions with names such as do_epoll_wait, wait_woken, and the impeccably named _RNvMs2_NtCs8QPsHWIn21X_16rust_binder_main6threadNtB5_6Thread8get_work.

To improve how ps output looks, give explicit non-mangled names to the functions where Rust Binder calls schedule(), since these are the most likely places to show up on ps output.

The name of rust_binder_waitlcl is truncated instead of using _local suffix because rust_binder_wait_local is sufficiently long that ps shows unaligned output.

This is intended to be a temporary workaround until we find a better solution. Adding #[export_name] to every Rust function that calls schedule() is not a great long-term solution.

---
Changes in v2:
- Rebase.
- Clarify that this is a workaround.
- Link to v1: https://lore.kernel.org/r/[email protected]

---
 drivers/android/binder/process.rs | 3 +++
 drivers/android/binder/thread.rs  | 6 ++++++
 2 files changed, 9 insertions(+)
drivers/android/binder/process.rs +3 -0
index 41de5593197cd29b71d1cb49829a1ff878bab249..f62f626f928e7ea4965d03c92cc988f344c6ae81 100644
@@ -1442,6 +1442,9 @@ pub(crate) fn drop_outstanding_txn(&self) {
         }
     }
 
+    // #[export_name] is a temporary workaround so that ps output does not become unreadable from
+    // mangled symbol names.
+    #[export_name = "rust_binder_freeze"]
     pub(crate) fn ioctl_freeze(&self, info: &BinderFreezeInfo) -> Result {
         if info.enable == 0 {
             let msgs = self.prepare_freeze_messages()?;
drivers/android/binder/thread.rs +6 -0
index 0b62d24b2118abe10577029a0129887e4ee8c6ba..6f197be0fa75d9d485c6cd659fa28c872a88af93 100644
@@ -513,6 +513,9 @@ pub(crate) fn has_current_transaction(&self) -> bool {
     /// Attempts to fetch a work item from the thread-local queue. The behaviour if the queue is
     /// empty depends on `wait`: if it is true, the function waits for some work to be queued (or a
     /// signal); otherwise it returns indicating that none is available.
+    // #[export_name] is a temporary workaround so that ps output does not become unreadable from
+    // mangled symbol names.
+    #[export_name = "rust_binder_waitlcl"]
     fn get_work_local(self: &Arc<Self>, wait: bool) -> Result<Option<DLArc<dyn DeliverToRead>>> {
         {
             let mut inner = self.inner.lock();
@@ -551,6 +554,9 @@ fn get_work_local(self: &Arc<Self>, wait: bool) -> Result<Option<DLArc<dyn Deliv
     ///
     /// This must only be called when the thread is not participating in a transaction chain. If it
     /// is, the local version (`get_work_local`) should be used instead.
+    // #[export_name] is a temporary workaround so that ps output does not become unreadable from
+    // mangled symbol names.
+    #[export_name = "rust_binder_wait"]
     fn get_work(self: &Arc<Self>, wait: bool) -> Result<Option<DLArc<dyn DeliverToRead>>> {
         // Try to get work from the thread's work queue, using only a local lock.
         {

---
base-commit: 2961f841b025fb234860bac26dfb7fa7cb0fb122
change-id: 20260213-rust-binder-ps-46d9d060243a

Best regards,

Signature · 1 line
Alice Ryhl <[email protected]>
reviewer Acked-by on v2 1/1
#1 lore raw
Quoted 12 lines · Alice Ryhl

Currently ps -A shows processes waiting on schedule() in functions with names such as do_epoll_wait, wait_woken, and the impeccably named _RNvMs2_NtCs8QPsHWIn21X_16rust_binder_main6threadNtB5_6Thread8get_work.

To improve how ps output looks, give explicit non-mangled names to the functions where Rust Binder calls schedule(), since these are the most likely places to show up on ps output.

The name of rust_binder_waitlcl is truncated instead of using _local suffix because rust_binder_wait_local is sufficiently long that ps shows unaligned output.

Quoted 6 lines

This is intended to be a temporary workaround until we find a better solution. Adding #[export_name] to every Rust function that calls schedule() is not a great long-term solution.

Quoted 69 lines

---
Changes in v2:
- Rebase.
- Clarify that this is a workaround.
- Link to v1:
https://lore.kernel.org/r/[email protected]

---
 drivers/android/binder/process.rs | 3 +++
 drivers/android/binder/thread.rs  | 6 ++++++
 2 files changed, 9 insertions(+)
drivers/android/binder/process.rs +1 -0
index 41de5593197cd29b71d1cb49829a1ff878bab249..f62f626f928e7ea4965d03c92cc988f344c6ae81 100644
@@ -1442,6 +1442,9 @@ pub(crate) fn drop_outstanding_txn(&self) {
         }
     }
 
+    // #[export_name] is a temporary workaround so that ps output does 

not become unreadable from

drivers/android/binder/process.rs +2 -0
+    // mangled symbol names.
+    #[export_name = "rust_binder_freeze"]
     pub(crate) fn ioctl_freeze(&self, info: &BinderFreezeInfo) -> 
Result {
         if info.enable == 0 {
             let msgs = self.prepare_freeze_messages()?;
drivers/android/binder/thread.rs +0 -0
index 0b62d24b2118abe10577029a0129887e4ee8c6ba..6f197be0fa75d9d485c6cd659fa28c872a88af93 100644
@@ -513,6 +513,9 @@ pub(crate) fn has_current_transaction(&self) -> 
 bool {
     /// Attempts to fetch a work item from the thread-local queue. The 

behaviour if the queue is

     /// empty depends on `wait`: if it is true, the function waits for 
some work to be queued (or a
     /// signal); otherwise it returns indicating that none is 

available.
+ // #[export_name] is a temporary workaround so that ps output does
not become unreadable from

drivers/android/binder/thread.rs +2 -0
+    // mangled symbol names.
+    #[export_name = "rust_binder_waitlcl"]
     fn get_work_local(self: &Arc<Self>, wait: bool) -> 
Result<Option<DLArc<dyn DeliverToRead>>> {
         {
             let mut inner = self.inner.lock();
drivers/android/binder/thread.rs +0 -0
@@ -551,6 +554,9 @@ fn get_work_local(self: &Arc<Self>, wait: bool) -> 

Result<Option<DLArc<dyn Deliv

     ///
     /// This must only be called when the thread is not participating 
in a transaction chain. If it
     /// is, the local version (`get_work_local`) should be used 

instead.
+ // #[export_name] is a temporary workaround so that ps output does
not become unreadable from

drivers/android/binder/thread.rs +2 -0
+    // mangled symbol names.
+    #[export_name = "rust_binder_wait"]
     fn get_work(self: &Arc<Self>, wait: bool) -> 
Result<Option<DLArc<dyn DeliverToRead>>> {
         // Try to get work from the thread's work queue, using only a 
local lock.
         {

---
base-commit: 2961f841b025fb234860bac26dfb7fa7cb0fb122
change-id: 20260213-rust-binder-ps-46d9d060243a

Best regards,