欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Binder系列1—Binder Driver初探

程序员文章站 2024-03-15 14:10:18
...

Binder系列1—Binder Driver初探

 

Binder系列1—Binder Driver初探

 

 

 

 

 

Binder系列1—Binder Driver初探

 

Binder系列1—Binder Driver初探

 

android6.0

kernel/drivers/ (不同Linux分支路径略有不同) - staging/android/binder.c - android/binder.c

./work/android-5.0.2/frameworks/native/cmds/servicemanager/binder.c
./work/linux-3.0.86/drivers/staging/android/binder.c
 

 

Binder系列1—Binder Driver初探

 

Binder系列1—Binder Driver初探

 

Binder系列1—Binder Driver初探

 

Binder系列1—Binder Driver初探

 

流程如下:

IPC 

Zygote socket

Client      Server      ServiceManager binder

Service Server

Service Manager

binder_init

misc_register

binder_open

binder_mmap

void *start,void *end,

物理空间映射到虚拟进程空间

binder_ioctl

binder_get_thread

binder_ref ->BpBinder

binder_node->BnBinder

binder_transaction_data


write_buffer->BC_TRANSACTION

read_buffer->BR_TRANSACTION  write_buffer->BC_TRANSACTION

  union {
        struct {
            binder_uintptr_t    buffer; //数据区起始地址
            binder_uintptr_t    offsets; //数据区IPC对象偏移量
        } ptr;
        __u8    buf[8];
    } data;   //RPC数据


flat_binder_object


struct binder_transaction_data {
    union {
        __u32    handle;       //binder_ref(即handle)->BpBinder(客户端)
        binder_uintptr_t ptr;     //Binder_node的内存地址 - >BnBinder(服务端)
    } target;  //RPC目标

}

binder_ref ->BpBinder

binder_node->BnBinder


binder_transaction

 

 

3. 源码附录

本文基于Linux 4.4源码, 从上之下, 整个Binder架构所涉及的总共有以下5个目录:

/framework/base/core/java/               (Java)
/framework/base/core/jni/                (JNI)
/framework/native/libs/binder            (Native)
/framework/native/cmds/servicemanager/   (Native)
/kernel/drivers/android                  (Driver)

(1)Java framework

/framework/base/core/java/android/os/  
    - IServiceManager.java
    - ServiceManager.java
    - ServiceManagerNative.java
    - IInterface.java
    - IBinder.java
    - Parcel.java
    - Binder.java  

    - IHwInterface.java
    - IHwBinder.java
    - HwParcel.java
    - HwBinder.java
    - HwRemoteBinder.java


/framework/base/core/jni/    
    - AndroidRuntime.cpp
    - android_os_Parcel.cpp
    - android_util_Binder.cpp
    - android_os_HwParcel.cpp
    - android_os_HwBinder.cpp

    - android_os_Parcel.h
    - android_util_Binder.h
    - android_os_HwParcel.h
    - android_os_HwBinder.h

(2)Native framework

/framework/native/libs/binder         
    - IServiceManager.cpp
    - Interface.cpp
    - Binder.cpp
    - BpBinder.cpp
    - Parcel.cpp
    - IPCThreadState.cpp
    - ProcessState.cpp

/framework/native/libs/binder/include/binder
    - IServiceManager.h
    - Interface.h
    - Binder.h
    - BpBinder.h
    - Parcel.h
    - IPCThreadState.h
    - ProcessState.h
    - BinderService.h

/framework/native/cmds/servicemanager/
    - service_manager.c
    - binder.c
    - binder.h

(3)Kernel

/kernel/drivers/android/
    - binder.c
    - binder_alloc.c
    - binder_alloc.h

/kernel/include/uapi/linux/android/
    - binder.h

 

 

 

相关标签: framework