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