}
binder_miscdev 即 Binder 设备描述如下:
static struct miscdevice binder_miscdev = {
.minor = MISC_DYNAMIC_MINOR, //自动分配次设备号
.name = “binder”, //驱动名称
.fops = &binder_fops //binder 驱动支持的文件操作
}
binder_fops 为 Binder 设备支持的操作函数,如下:
static const struct file_operations binder_fops = {
.owner = THIS_MODULE,
.poll = binder_poll,
.unlocked_ioctl = binder_ioctl,
.mmap = binder_mmap,
.open = binder_open,
.flush = binder_flush,
.release = binder_release,
};
binder_open
用户应用程序通过 Binder 通信时,需先调用 binder_open() 方法打开 binder 驱动,binder_open() 中主要做了两个工作,对应的分为两部分来看:
//binder.c
static int binder_open(struct inode *nodp, struct file *filp)
{
struct binder_proc *proc;
…
proc = kzalloc(sizeof(*proc), GFP_KERNEL); //创建 binder_proc
if (proc == NULL)
return -ENOMEM;
get_task_struct(current);
proc->tsk = current;
INIT_LIST_HEAD(&proc->todo); //初始化 todo 队列
init_waitqueue_head(&proc->wait); //初始化 todo 队列
proc->default_priority = task_nice(current);
上面代码的主要工作是 「创建及初始化 binder_proc」,binder_proc 就是用来存放 binder 相关数据的结构体,每个进程独有一份。
binder_lock(func);
binder_stats_created(BINDER_