Skip to content

binder: Export more constants via the defs module. #314

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions drivers/android/allocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use core::mem::{size_of, MaybeUninit};
use kernel::{bindings, pages::Pages, prelude::*, user_ptr::UserSlicePtrReader, Error};

use crate::{
defs::*,
node::NodeRef,
process::{AllocationInfo, Process},
thread::{BinderError, BinderResult},
Expand Down Expand Up @@ -117,19 +118,19 @@ impl<'a> Allocation<'a> {
let header = view.read::<bindings::binder_object_header>(offset)?;
// TODO: Handle other types.
match header.type_ {
bindings::BINDER_TYPE_WEAK_BINDER | bindings::BINDER_TYPE_BINDER => {
BINDER_TYPE_WEAK_BINDER | BINDER_TYPE_BINDER => {
let obj = view.read::<bindings::flat_binder_object>(offset)?;
let strong = header.type_ == bindings::BINDER_TYPE_BINDER;
let strong = header.type_ == BINDER_TYPE_BINDER;
// SAFETY: The type is `BINDER_TYPE_{WEAK_}BINDER`, so the `binder` field is
// populated.
let ptr = unsafe { obj.__bindgen_anon_1.binder } as usize;
let cookie = obj.cookie as usize;
self.process.update_node(ptr, cookie, strong, false);
Ok(())
}
bindings::BINDER_TYPE_WEAK_HANDLE | bindings::BINDER_TYPE_HANDLE => {
BINDER_TYPE_WEAK_HANDLE | BINDER_TYPE_HANDLE => {
let obj = view.read::<bindings::flat_binder_object>(offset)?;
let strong = header.type_ == bindings::BINDER_TYPE_HANDLE;
let strong = header.type_ == BINDER_TYPE_HANDLE;
// SAFETY: The type is `BINDER_TYPE_{WEAK_}HANDLE`, so the `handle` field is
// populated.
let handle = unsafe { obj.__bindgen_anon_1.handle } as _;
Expand Down Expand Up @@ -203,9 +204,9 @@ impl<'a> AllocationView<'a> {
let newobj = bindings::flat_binder_object {
hdr: bindings::binder_object_header {
type_: if strong {
bindings::BINDER_TYPE_BINDER
BINDER_TYPE_BINDER
} else {
bindings::BINDER_TYPE_WEAK_BINDER
BINDER_TYPE_WEAK_BINDER
},
},
flags: obj.flags,
Expand All @@ -228,9 +229,9 @@ impl<'a> AllocationView<'a> {
let newobj = bindings::flat_binder_object {
hdr: bindings::binder_object_header {
type_: if strong {
bindings::BINDER_TYPE_HANDLE
BINDER_TYPE_HANDLE
} else {
bindings::BINDER_TYPE_WEAK_HANDLE
BINDER_TYPE_WEAK_HANDLE
},
},
flags: obj.flags,
Expand Down
7 changes: 7 additions & 0 deletions drivers/android/defs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ pub_no_prefix!(
BC_DEAD_BINDER_DONE
);

pub_no_prefix!(transaction_flags_, TF_ONE_WAY, TF_ACCEPT_FDS);

pub(crate) use bindings::{
BINDER_TYPE_BINDER, BINDER_TYPE_FD, BINDER_TYPE_HANDLE, BINDER_TYPE_WEAK_BINDER,
BINDER_TYPE_WEAK_HANDLE, FLAT_BINDER_FLAG_ACCEPTS_FDS,
};

macro_rules! decl_wrapper {
($newname:ident, $wrapped:ty) => {
#[derive(Copy, Clone, Default)]
Expand Down
10 changes: 5 additions & 5 deletions drivers/android/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,17 +383,17 @@ impl Thread {
let header = view.read::<bindings::binder_object_header>(offset)?;
// TODO: Handle other types.
match header.type_ {
bindings::BINDER_TYPE_WEAK_BINDER | bindings::BINDER_TYPE_BINDER => {
let strong = header.type_ == bindings::BINDER_TYPE_BINDER;
BINDER_TYPE_WEAK_BINDER | BINDER_TYPE_BINDER => {
let strong = header.type_ == BINDER_TYPE_BINDER;
view.transfer_binder_object(offset, strong, |obj| {
// SAFETY: The type is `BINDER_TYPE_{WEAK_}BINDER`, so `binder` is populated.
let ptr = unsafe { obj.__bindgen_anon_1.binder } as _;
let cookie = obj.cookie as _;
Ok(self.process.get_node(ptr, cookie, strong, Some(self))?)
})?;
}
bindings::BINDER_TYPE_WEAK_HANDLE | bindings::BINDER_TYPE_HANDLE => {
let strong = header.type_ == bindings::BINDER_TYPE_HANDLE;
BINDER_TYPE_WEAK_HANDLE | BINDER_TYPE_HANDLE => {
let strong = header.type_ == BINDER_TYPE_HANDLE;
view.transfer_binder_object(offset, strong, |obj| {
// SAFETY: The type is `BINDER_TYPE_{WEAK_}HANDLE`, so `handle` is populated.
let handle = unsafe { obj.__bindgen_anon_1.handle } as _;
Expand Down Expand Up @@ -615,7 +615,7 @@ impl Thread {
match reader.read::<u32>()? {
BC_TRANSACTION => {
let tr = reader.read::<BinderTransactionData>()?;
if tr.flags & bindings::transaction_flags_TF_ONE_WAY != 0 {
if tr.flags & TF_ONE_WAY != 0 {
self.transaction(&tr, Self::oneway_transaction_inner)
} else {
self.transaction(&tr, Self::transaction_inner)
Expand Down
4 changes: 2 additions & 2 deletions drivers/android/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use alloc::sync::Arc;
use core::sync::atomic::{AtomicBool, Ordering};
use kernel::{
bindings, io_buffer::IoBufferWriter, linked_list::Links, prelude::*, sync::Ref,
io_buffer::IoBufferWriter, linked_list::Links, prelude::*, sync::Ref,
user_ptr::UserSlicePtrWriter,
};

Expand Down Expand Up @@ -179,7 +179,7 @@ impl DeliverToRead for Transaction {

// When this is not a reply and not an async transaction, update `current_transaction`. If
// it's a reply, `current_transaction` has already been updated appropriately.
if self.node_ref.is_some() && tr.flags & bindings::transaction_flags_TF_ONE_WAY == 0 {
if self.node_ref.is_some() && tr.flags & TF_ONE_WAY == 0 {
thread.set_current_transaction(self);
}

Expand Down