trace.rs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. // SPDX-License-Identifier: GPL-2.0
  2. // Copyright (C) 2025 Google LLC.
  3. use crate::transaction::Transaction;
  4. use kernel::bindings::{rust_binder_transaction, task_struct};
  5. use kernel::ffi::{c_uint, c_ulong};
  6. use kernel::task::Task;
  7. use kernel::tracepoint::declare_trace;
  8. declare_trace! {
  9. unsafe fn rust_binder_ioctl(cmd: c_uint, arg: c_ulong);
  10. unsafe fn rust_binder_transaction(reply: bool, t: rust_binder_transaction, thread: *mut task_struct);
  11. }
  12. #[inline]
  13. fn raw_transaction(t: &Transaction) -> rust_binder_transaction {
  14. t as *const Transaction as rust_binder_transaction
  15. }
  16. #[inline]
  17. pub(crate) fn trace_ioctl(cmd: u32, arg: usize) {
  18. // SAFETY: Always safe to call.
  19. unsafe { rust_binder_ioctl(cmd, arg as c_ulong) }
  20. }
  21. #[inline]
  22. pub(crate) fn trace_transaction(reply: bool, t: &Transaction, thread: Option<&Task>) {
  23. let thread = match thread {
  24. Some(thread) => thread.as_ptr(),
  25. None => core::ptr::null_mut(),
  26. };
  27. // SAFETY: The raw transaction is valid for the duration of this call. The thread pointer is
  28. // valid or null.
  29. unsafe { rust_binder_transaction(reply, raw_transaction(t), thread) }
  30. }