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

Flow Analysis of binder Mechanism

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

We analyzed the whole process of test_client and test_server in front of the code, so let's summarize the whole process.

Suppose we have such a service scenario: test_server provides HelloService services, as well as GoodbyeService services; test_client to consume services.

For test_server:

1. AddService:

A. test_server constructs a flat_binder_object structure for each service. It contains binder pointers and cookie pointers to different services

b. Call ioctl to send data:

B.1 data contains flat_binder_object + service name

B.2 data contains "destination": handle = 0, which indicates that it is sent to SM.

c. If ioctl is called above, the driver constructs the binder_node structure for each flat_binder_object. The ptr and cookie pointers contained in it come from the binder and cookie pointers in the flat_binder_object structure.

d. The driver finds SM based on handle = 0, then sends the data to SM and creates a binder_ref structure

e. Record the name and desc value of the service in SM.

For test_client:

2. GetService:

A. test_client construction data. Data = name + "purpose (referring to handle = 0)"

b. Call ioctl to send data

c. Then the driver finds SM according to handle = 0 and sends the data to SM.

D. SM finds the corresponding item in the svclist linked list. For example, find the first item based on the name "Hello", handle = 1

E. SM returns data through ioctl. Data = type in flat_binder_object,flat_binder_object structure indicates reference binder_ref,handle = 1

f. Driver: flat_binder_object is found in the data, and type is a reference. Find the corresponding item in the binder_ref linked list of SM (handle = = binder_ref.desc), then find binder_node, and finally create a binder_ref for test_client.

For SM:

3. So how does test_client use HelloService?

a. Construction data, which contains code (which function to call), "purpose" handle = 1

b. Use ioctl to send data

c. Driver: remove handle = 1, find binder_ref, then find binder_node, then find test_server;, finally pass the data to test_server, and set (ptr and cookie) equal to binder_node (ptr and cookie) in the data.

D. Test_server knows which service is invoked based on (ptr and cookie)

1. In test_server, the driver constructs the binder_node structure (placed in the linked list) that contains HelloService and GoodbyeService services. The ptr and cookie and proc,proc structures contained in the binder_node structure point to the process test_server

2. In SM, the driver also constructs a binder_ref structure (also in the form of a linked list) that contains HelloService and GoodbyeService services. The desc and node contained in the binder_ref structure. This node points to the binder_node structure in the previous test_server to find the corresponding service.

3. In test_client, the driver also constructs a binder_ref structure (also in the form of a linked list) that contains HelloService and GoodbyeService services. The desc and node contained in the binder_ref structure, and this node points to the binder_node structure in the previous SM

Similarly, test_client finds the corresponding specific service name according to desc (which service, Hello or Goodbye service)

At this time, the process call of the binder system is very clear, so the core function in this system is the core data on the ioctl;test_client side, and the core data on the handle,test_server side are ptr and cookie.

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

Servers

Wechat

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

12
Report