question about ioctl() and mmap() functions of binder driver

646 views
Skip to first unread message

AndroidHolder

unread,
Sep 27, 2011, 9:48:05 PM9/27/11
to android-porting
First,to be honest,my doubt comes from the binder driver part in /
kernel/drivers/android/binder.c
// 1. register binder as a misc device
static int __init binder_init(void){
int ret;
...
ret = misc_register(&binder_miscdev);
...
}
// 2.declare fops as &binder_fops
static struct miscdevice binder_miscdev = {
.minor = MISC_DYNAMIC_MINOR,
.name = "binder",
.fops = &binder_fops
};
// 3.binder_fops is defined as follows
static 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,
};
Then take a look at /framework/base/cmds/servicemanager/binder.c,there
are one place where runs ioctl and another place where runs mmap.
int binder_become_context_manager(struct binder_state *bs)
{
return ioctl(bs->fd, BINDER_SET_CONTEXT_MGR, 0);
}
struct binder_state *binder_open(unsigned mapsize)
{
struct binder_state *bs;

...
bs->mapped = mmap(NULL, mapsize, PROT_READ, MAP_PRIVATE, bs->fd,
0);
...
}
Since above,I am not sure the relationship between ioctl() and
binder_ioctl() defined in driver ,along with the relationship between
mmap() and binder_mmap() defined in driver,could someone help me to
make it clear,thanks.

Nigel Sheridan-Smith

unread,
Sep 28, 2011, 11:22:36 PM9/28/11
to skybr...@yahoo.cn, android-porting

Hi,

The 'binder' kernel driver registers itself with the kernel under a device name, e.g. /dev/binder. Using "binder_fops" is passes all of the module's functions to the kernel as callbacks for different events (open, mmap, flush, release, etc against that device name).

So the Binder IPC client must open("/dev/binder", ...) as a file descriptor and then read and write to the descriptor to pass data to the binder kernel driver. An 'mmap' in this case, maps memory between processes, but it is associated with this file descriptor to tell the kernel that the binder module is responsible for managing the process of memory sharing between the kernel module and the client process.

Cheers,

Nigel



AndroidHolder

unread,
Sep 29, 2011, 9:26:27 PM9/29/11
to android-porting
Dear Nigel,
Thanks very much for your explanation. It's very excited that my guess
is similarly with your opinion.Besides,now I am sure about what the
binder driver acts.
Best regards!
Reply all
Reply to author
Forward
0 new messages