当前位置:网站首页>Binder communication process and servicemanager creation process
Binder communication process and servicemanager creation process
2022-07-05 13:19:00 【51CTO】
Binder Communication process
1. First , A process uses BINDER_SET_CONTEXT_MGR Command to pass Binder The driver registers itself as ServiceManager
2.Server Drive to ServiceManager Register in Binder(Server Medium Binder Entity ), Indicates that services can be provided externally . The driver is this Binder Create entity nodes located in the kernel and ServiceManager References to entities , Package and pass the name and the new reference to ServiceManager,ServiceManger Fill it in the lookup table .
3.Client By name , stay Binder With the help of drive from ServiceManager Get a pair of Binder References to entities , Through this reference, and Server Process communication .
Binder Agent mode of communication
When A The process wants to get B In process object when , Driving doesn't really put object Return to A, But back to a heel object It looks as like as two peas objectProxy, This objectProxy With and object The same way , But these methods do not B In progress object The ability to target those methods , These methods only need to give the request parameters to the driver . about A Process and direct call object The method in is the same .
When Binder The driver receives A After the process message , Find out this is a objectProxy Just check the form you maintain , A search revealed that it was B process object Proxy object of . So I'll call B Process call object Methods , And ask the B The process sends the returned result to itself . When the driver gets B The return result of the process will be forwarded to A process , One communication is done .
ServiceManager The process starts
1.ServiceManager Become Binder managers
First, in the android When the system starts up, it passes init.rc Launched the servicemanager(Native process ) Executable process , The system really ServieManager Management finally passed Native process servicemanager To complete . Next, the analysis is in main That's what's done in the function :
1.binder_open(128*1024) By opening the /dev/binder The device node returns fd File descriptor , adopt mmap Final realization binder drive 128K Memory mapping of size
2.binder_become_context_manager(bs) adopt ioctl Send to the device node BINDER_SET_CONTEXT_MGR Order notice Binder Drive as servicemanager Create a special invariant 0 Handle entity binder_node:binder_context_mgr_node
3.Binder_loop(bs,svcmgr_handler) adopt iotcl send out BINDER_WRITE_READ Command and carry BC_ENTER_LOOPER Request an order to inform Binder The driver created binder Main thread and make binder The driver creates the corresponding binder_thread The structure is stored in binder_proc in , And pass for Cycle into cycle read binder Drive the circular flow of returned information
ServiceManager(native process ) Finally, get binder Drive device node fd Address , And binder Drive memory mapping ( Virtual memory and physical memory mapping ), Turn on binder The main thread reads circularly binder Drive the returned message and become the server ;
After becoming a server, it can continuously receive information from the client ( Server side And clients are collectively referred to as clients ) Of binder Request communication ,ServiceManager(native process ) Complete the registration of other services and save binder Driver created binder Handle value and service name string , Ensure that the client obtains other service reference handles through the string ; thus ServiceManager(native process ) by binder managers ( A bridge between service registration and acquisition ).
2. Client pass ServiceManager Access to services
User processes need and ServiceManager(native process ) Process of communication ,ServiceManager After receiving the request, the process responds
1. The first step of the user process is to instantiate ServiceManager Binder Proxy agent
adopt BinderInternal.getContextObject() The handle value obtained by the call is 0 Of BpBinder native object , Finally through javaObjectForIbinder() Functional jni Convert to BinderProxy Class object is actually filled with this class mObject The object is ServiceManager Binder The reference of the object encapsulates the object , therefore SMN Can pass asInterface Complete the agency Proxy Instantiation
边栏推荐
- #从源头解决# 自定义头文件在VS上出现“无法打开源文件“XX.h“的问题
- Pycharm installation third party library diagram
- Halcon template matching actual code (I)
- leetcode:221. Maximum square [essence of DP state transition]
- 先写API文档还是先写代码?
- 简单上手的页面请求和解析案例
- Go array and slice
- MATLAB论文图表标准格式输出(干货)
- Solve Unicode decodeerror: 'GBK' codec can't decode byte 0xa2 in position 107
- 百日完成国产数据库opengausss的开源任务--openGuass极简版3.0.0安装教程
猜你喜欢
百日完成国产数据库opengausss的开源任务--openGuass极简版3.0.0安装教程
leetcode:221. Maximum square [essence of DP state transition]
数据湖(七):Iceberg概念及回顾什么是数据湖
Detailed explanation of navigation component of openharmony application development
FPGA 学习笔记:Vivado 2019.1 添加 IP MicroBlaze
Android本地Sqlite数据库的备份和还原
爱可生SQLe审核工具顺利完成信通院‘SQL质量管理平台分级能力’评测
ASEMI整流桥HD06参数,HD06图片,HD06应用
ABAP editor in SAP segw transaction code
[深度学习论文笔记]UCTransNet:从transformer的通道角度重新思考U-Net中的跳跃连接
随机推荐
阿里云SLB负载均衡产品基本概念与购买流程
LB10S-ASEMI整流桥LB10S
时钟周期
Run, open circuit
The solution of outputting 64 bits from printf format%lld of cross platform (32bit and 64bit)
Sorry, we can't open xxxxx Docx, because there is a problem with the content (repackaging problem)
Datapipeline was selected into the 2022 digital intelligence atlas and database development report of China Academy of communications and communications
mysql econnreset_Nodejs 套接字报错处理 Error: read ECONNRESET
Detailed explanation of navigation component of openharmony application development
【服务器数据恢复】某品牌服务器存储raid5数据恢复案例
潘多拉 IOT 开发板学习(HAL 库)—— 实验7 窗口看门狗实验(学习笔记)
【Hot100】34. 在排序数组中查找元素的第一个和最后一个位置
将函数放在模块中
MATLAB论文图表标准格式输出(干货)
Notion 类笔记软件如何选择?Notion 、FlowUs 、Wolai 对比评测
How to protect user privacy without password authentication?
山东大学暑期实训一20220620
#从源头解决# 自定义头文件在VS上出现“无法打开源文件“XX.h“的问题
Hiengine: comparable to the local cloud native memory database engine
It's too convenient. You can complete the code release and approval by nailing it!