Android binder学习笔记pre - binder驱动

1. 前言

本文主要是binder系列文章的总结笔记,主要是理清binder的总体流程和总体架构,期间会对照Android R进行代码重读,也会按照自己的理解对内容进行调整,以加深对binder总体的理解。本文主要讲述binder驱动部分。

2. binder驱动领域模型

在这里插入图片描述

3. binder_init

static int __init binder_init(void)
    |--binder_alloc_shrinker_init()
    |--atomic_set(&binder_transaction_log.cur, ~0U)
    |  atomic_set(&binder_transaction_log_failed.cur, ~0U)
    |--binder_debugfs_dir_entry_root = debugfs_create_dir("binder", NULL)
    |  debugfs_create_dir("proc",binder_debugfs_dir_entry_root)
    |  在binder_debugfs_dir_entry_root目录下创建debugfs的调试节点
    |--if (!IS_ENABLED(CONFIG_ANDROID_BINDERFS) && strcmp(binder_devices_param, "") != 0)
    |      while ((device_name = strsep(&device_tmp, ",")))
    |           ret = init_binder_device(device_name)
    |               if (ret)
    |                   goto err_init_binder_device_failed
    |--init_binderfs()

1.binder_alloc_shrinker_init:

2.atomic_set:

3.init_binder_device:通过kzalloc分配binder_device结构体并初始化,并通过misc_register(&binder_device->miscdev)进行注册,同时将binder_device链入全局哈希链表binder_devices

4.init_binderfs:

tatic int __init init_binder_device(const char *name)
    |--struct binder_device *binder_device
    |--binder_device = kzalloc(sizeof(*binder_device), GFP_KERNEL)
    |  binder_device->miscdev.fops = &binder_fops
    |  refcount_set(&binder_device->ref, 1)
    |  binder_device->context.binder_context_mgr_uid = INVALID_UID
    | binder_device->context.name = name
    |--misc_register(&binder_device->miscdev)
    |--hlist_add_head(&binder_device->hlist, &binder_devices)

binder_device->miscdev.fops = &binder_fops,此处binder_fops的定义如下,open, mmap binder设备时会调用对应的回调函数

const struct file_operations binder_fops = {
.owner = THIS_MODULE,
.poll = binder_poll,
.unlocked_ioctl = binder_ioctl,
.compat_ioctl = binder_ioctl,
.mmap = binder_mmap,
.open = binder_open,
.flush = binder_flush,
.release = binder_release,
};

Guess you like

Origin blog.csdn.net/jasonactions/article/details/119855712