You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
android-notes/blogs/Android/Framework/Interview/应用进程相关/应用是启用 binder 机制.md

53 lines
984 B

---
应用是怎么启用 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<ProcessState> 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