1

Binder核心API

 2 years ago
source link: https://blog.51cto.com/u_14689064/5452565
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Binder核心API

原创

Binder核心API

1.binder_init

该方法主要是为了注册misc设备,debugfs_create_dir是指在debugfs文件系统中创建一个目录,返回值是指向dentry的指针

Binder核心API_同步锁

注册misc设备,miscdevice结构体,便是前面注册misc设备时传递进去的参数

Binder核心API_插入图片_02

file_operations结构体,指定相应文件操作的方法,可以看到在上面用户空间的方法会最终调用到对应的方法,就是根据这个来定的

Binder核心API_插入图片_03

2.binder_open

创建binder_proc对象,并把当前进程等信息保存到binder_proc对象,该对象管理IPC所需的各种信息并拥有其他结构体的根结构体;再把binder_proc对象保存到文件指针filp,以及把binder_proc加入到全局链表binder_procs。

Binder核心API_链表_04

Binder驱动中通过static HLIST_HEAD(binder_procs);,创建了全局的哈希链表binder_procs,用于保存所有的binder_proc队列,每次新创建的binder_proc对象都会加入binder_procs链表中。

Binder核心API_链表_05

3.binder_mmap

主要功能:首先在内核虚拟地址空间,申请一块与用户虚拟内存相同大小的内存;然后再申请1个page大小的物理内存,再将同一块物理内存分别映射到内核虚拟地址空间和用户虚拟内存空间,从而实现了用户空间的Buffer和内核空间的Buffer同步操作的功能。

Binder核心API_链表_06
Binder核心API_插入图片_07

binder_init:初始化字符设备;
binder_open:打开驱动设备,过程需要持有binder_main_lock同步锁;
binder_mmap:申请内存空间,该过程需要持有binder_mmap_lock同步锁;
binder_ioctl:执行相应的ioctl操作,该过程需要持有binder_main_lock同步锁;
当处于binder_thread_read过程,read_buffer无数据则释放同步锁,并处于wait_event_freezable过程,等有数据到来则唤醒并尝试持有同步锁。

  • 收藏
  • 评论
  • 分享
  • 举报

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK