From 140ac3e065036d50645a8fa785f6ab01c5564bf3 Mon Sep 17 00:00:00 2001 From: Omooo <869759698@qq.com> Date: Thu, 19 Mar 2020 20:53:52 +0800 Subject: [PATCH] =?UTF-8?q?Create=20=E5=BA=94=E7=94=A8=E6=98=AF=E5=90=AF?= =?UTF-8?q?=E7=94=A8=20binder=20=E6=9C=BA=E5=88=B6.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../应用是启用 binder 机制.md | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 blogs/Android/Framework/Interview/应用进程相关/应用是启用 binder 机制.md diff --git a/blogs/Android/Framework/Interview/应用进程相关/应用是启用 binder 机制.md b/blogs/Android/Framework/Interview/应用进程相关/应用是启用 binder 机制.md new file mode 100644 index 0000000..708a1a4 --- /dev/null +++ b/blogs/Android/Framework/Interview/应用进程相关/应用是启用 binder 机制.md @@ -0,0 +1,52 @@ +--- +应用是怎么启用 binder 机制的? +--- + +1. 了解 binder 是用来干嘛的? +2. 应用里面哪些地方用到了 binder 机制? +3. 应用的大致启动流程是怎样的? +4. 一个进程是怎么启用 binder 机制的? + +#### 什么时候支持 binder 机制的? + +#### binder 启动时机 + +```java +// handleChildProc(...) +static void zygoteInit() { + commonInit(); + nativeZygoteInit(); + applicationInit(...); +} +``` + +```c +void nativeZygoteInit(...) { + gCurRuntime->onZygoteInit(); +} +``` + +```c +virtual void onZygoteInit() { + sp proc = ProcessState::self(); + proc->startThreadPool(); +} +``` + +```c +ProcessState::ProcessState() + // open_driver() 打开 "/dev/binder" 驱动 + :mDriverFD(open_driver()), ... { + if(mDriverFD>=0) { + mVMStart = mmap(0, BINDER_VM_SIZE, PROT_READ, ..., mDriverFD, 0); + } + } +``` + +#### 怎么启用 Binder 机制? + +1. 打开 binder 驱动 +2. 映射内存,分配缓冲区 +3. 注册 binder 线程 +4. 进入 binder loop +