【问题标题】:How to locate the file in which the method is implement in android binder如何在android binder中找到实现该方法的文件
【发布时间】:2020-11-26 14:56:48
【问题描述】:

当我阅读位于.
/frameworks/native/cmds/servicemanager/binder.c.
的Android binder.c的源代码时 我很困惑在下面的代码中在哪里可以找到开放调用的实现,有没有人有任何想法可以提供帮助?

struct binder_state *binder_open(const char* driver, size_t mapsize)
{
    struct binder_state *bs;
    struct binder_version vers;

    bs = malloc(sizeof(*bs));
    if (!bs) {
        errno = ENOMEM;
        return NULL;
    }

    bs->fd = open(driver, O_RDWR | O_CLOEXEC);
    if (bs->fd < 0) {
        fprintf(stderr,"binder: cannot open %s (%s)\n",
                driver, strerror(errno));
        goto fail_open;
    }

    if ((ioctl(bs->fd, BINDER_VERSION, &vers) == -1) ||
        (vers.protocol_version != BINDER_CURRENT_PROTOCOL_VERSION)) {
        fprintf(stderr,
                "binder: kernel driver version (%d) differs from user space version (%d)\n",
                vers.protocol_version, BINDER_CURRENT_PROTOCOL_VERSION);
        goto fail_open;
    }

    bs->mapsize = mapsize;
    bs->mapped = mmap(NULL, mapsize, PROT_READ, MAP_PRIVATE, bs->fd, 0);
    if (bs->mapped == MAP_FAILED) {
        fprintf(stderr,"binder: cannot map device (%s)\n",
                strerror(errno));
        goto fail_map;
    }

    return bs;

fail_map:
    close(bs->fd);
fail_open:
    free(bs);
    return NULL;
}```

【问题讨论】:

    标签: android android-binder


    【解决方案1】:

    open 的实现发生在 Linux 内核中,特别是 Android IPC 子系统。

    以下结构包含绑定设备节点 (reference) 的函数指针:

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

    对于open 操作,结构包含指向binder_open (reference) 的指针

    init_binder_device 中,binder_fops 结构被分配给设备节点 (reference)。

    【讨论】:

    • 我想你是对的。但是Android是基于Linux内核的,理论上这些代码应该在AOSP中,但是按照你的回复好像不是这样。顺便问一下,有没有文章解释什么是 binder 以及它是如何完全工作的?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-20
    • 1970-01-01
    • 2020-03-26
    相关资源
    最近更新 更多