Skip to content

Commit

Permalink
Merge pull request torvalds#312 from wedsonaf/node-flags
Browse files Browse the repository at this point in the history
binder: Store node flags on creation.
  • Loading branch information
ojeda authored May 28, 2021
2 parents 82057dd + 85b23ab commit 7c23865
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
4 changes: 3 additions & 1 deletion drivers/android/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,13 +212,14 @@ pub(crate) struct Node {
pub(crate) global_id: u64,
ptr: usize,
cookie: usize,
pub(crate) flags: u32,
pub(crate) owner: Ref<Process>,
inner: LockedBy<NodeInner, Mutex<ProcessInner>>,
links: Links<dyn DeliverToRead>,
}

impl Node {
pub(crate) fn new(ptr: usize, cookie: usize, owner: Ref<Process>) -> Self {
pub(crate) fn new(ptr: usize, cookie: usize, flags: u32, owner: Ref<Process>) -> Self {
static NEXT_ID: AtomicU64 = AtomicU64::new(1);
let inner = LockedBy::new(
&owner.inner,
Expand All @@ -232,6 +233,7 @@ impl Node {
global_id: NEXT_ID.fetch_add(1, Ordering::Relaxed),
ptr,
cookie,
flags,
owner,
inner,
links: Links::new(),
Expand Down
17 changes: 12 additions & 5 deletions drivers/android/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,12 +367,18 @@ impl Process {
}

fn set_as_manager(&self, info: Option<FlatBinderObject>, thread: &Thread) -> Result {
let (ptr, cookie) = if let Some(obj) = info {
(unsafe { obj.__bindgen_anon_1.binder }, obj.cookie)
let (ptr, cookie, flags) = if let Some(obj) = info {
(
// SAFETY: The object type for this ioctl is implicitly `BINDER_TYPE_BINDER`, so it
// is safe to access the `binder` field.
unsafe { obj.__bindgen_anon_1.binder },
obj.cookie,
obj.flags,
)
} else {
(0, 0)
(0, 0, 0)
};
let node_ref = self.get_node(ptr as _, cookie as _, true, Some(thread))?;
let node_ref = self.get_node(ptr as _, cookie as _, flags as _, true, Some(thread))?;
let node = node_ref.node.clone();
self.ctx.set_manager_node(node_ref)?;
self.inner.lock().is_manager = true;
Expand All @@ -387,6 +393,7 @@ impl Process {
&self,
ptr: usize,
cookie: usize,
flags: u32,
strong: bool,
thread: Option<&Thread>,
) -> Result<NodeRef> {
Expand All @@ -399,7 +406,7 @@ impl Process {
}

// Allocate the node before reacquiring the lock.
let node = Arc::try_new(Node::new(ptr, cookie, Ref::new_from(self)))?;
let node = Arc::try_new(Node::new(ptr, cookie, flags, Ref::new_from(self)))?;

let mut inner = self.inner.lock();
if let Some(node) = inner.get_existing_node_ref(ptr, cookie, strong, thread)? {
Expand Down
5 changes: 4 additions & 1 deletion drivers/android/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,10 @@ impl Thread {
// 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))?)
let flags = obj.flags as _;
Ok(self
.process
.get_node(ptr, cookie, flags, strong, Some(self))?)
})?;
}
BINDER_TYPE_WEAK_HANDLE | BINDER_TYPE_HANDLE => {
Expand Down

0 comments on commit 7c23865

Please sign in to comment.