Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of struct binder_node

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the example analysis of struct binder_node, which is very detailed and has certain reference value. Friends who are interested must finish it!

Struct binder_node {

Int debug_id; / / used to help debug

/ / when the reference count of a Binder entity object changes from 0 to 1 or from 1 to 0, the Binder driver requests the corresponding

/ / the Service component increases or decreases its reference count. The Binder driver encapsulates the reference count modification into a class

Type / is a work item of type binder_node, which sets the value of member work to BINDER_WORK_NODE and sets the

/ / it is added to the todo queue of the corresponding process waiting for processing

Struct binder_work work

Union {

Struct rb_node rb_node

Struct hlist_node dead_node

}

/ / points to the host process, which uses a red-black tree to maintain all its internal Binder entity objects, each of which

/ / the member variable rb_node of the Binder entity object happens to be a node of the red-black tree. If the Binder entity object

If the host process of / / is dead, then the Binder entity object is saved in a full file through its member variable dead_node

/ / in the hash list of the bureau.

Struct binder_proc * proc

/ / an Binder entity object may be referenced by multiple Client components at the same time, so the Binder driver uses structures

/ / binder_ref to describe these reference relationships, and all references that reference the same Binder entity object are saved in the

/ / in a hash list. This hash list is described by the refs member of the Binder entity object, while the Binder driver passes

/ / after refs, you can know which Client components reference the same Binder entity object.

Struct hlist_head refs

Int internal_strong_refs; / / strong reference count describing Bidner entity objects

Int local_weak_refs; / / weak reference count describing Binder entity objects

Int local_strong_refs; / / strong reference count describing Bidner entity objects

Void _ _ user * ptr; / / describes the Service component in user space and points to the shadow object of Service

Void _ _ user * cookie; / / describes the address of the Service component in user space, pointing to the address of Service

/ / when the Binder entity object requests the Service to perform an operation, the strong / weak reference count of the Service is increased

/ / has_strong_ref and has_weak_ref are set to 1

/ / when Service completes the operation requested by Binder, the strong / weak reference count of the Service is decremented, and has_strong_ref and has_weak_ref are set to 0

/ / in the process of requesting Service to increase / decrease the strong / weak reference count, the Binder entity will set the

/ / pending_strong_ref or pending_weak_ref set 1

/ / when Service completes the increase / decrease of strong / weak reference count, the two member variables are set to 0.

Unsigned has_strong_ref:1

Unsigned pending_strong_ref:1

Unsigned has_weak_ref:1

Unsigned pending_weak_ref:1

/ / describes whether the Binder object is handling an asynchronous transaction. The Binder driver saves a transaction in the todo queue

/ / indicates that the thread will handle the transaction. Each transaction is associated with a Binder entity object, which is required to be associated with the Binder real

/ / the Service component corresponding to the body object processes the transaction in the specified thread. However, when the Binder driver finds that a transaction is different

/ / when you step into a transaction, it is saved in an asynchronous transaction queue of the target Binder entity object, which is

/ / is described by the member variable async_todo. Asynchronous transactions are defined as one-way interprocess communication requests, that is, no

/ / the request for interprocess communication to wait for a reply, as opposed to a synchronous transaction. Because there is no need to wait for an answer, the Binder driver just

/ / it is considered that the priority of asynchronous transaction is lower than that of synchronous transaction, which is represented by all asynchronism of a Binder entity object at the same time.

/ / at most one transaction is processed, and the rest are waiting in an asynchronous transaction queue, while synchronous transactions are not subject to this restriction.

Unsigned has_async_transaction:1

/ / describes whether Binder entity objects can receive interprocess communication data containing file descriptors. 1 indicates that it can be received, 0 table

/ / indicates that reception is prohibited. When the data sent by one process to another process contains a file descriptor, the Binder driver

/ / automatically opens the same file in the target process. For security reasons, Binder programs use this variable to prevent

/ / the source process opens the file in the target process.

Unsigned accept_fds:1

/ / indicates the processing thread (that is, the Server process) required by the Binder entity object when it processes requests from the Client process

The minimum thread priority that a thread in / / should have.

Unsigned min_priority:8

Struct list_head async_todo

}

The above is all the content of this article "sample Analysis of struct binder_node". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report