第6课第4节_Binder系统_驱动情景分析_服务注册过程_分析
Service_manager.c 8074 2017/6/30 首先从应用程序分析(Android) binder_loop(bs, svcmgr_handler) { readbuf[0] = BC_ENTER_LOOPER; res = ioctl(bs->fd, BINDER_WRITE_READ, &bwr); /导致驱动程序的ioctl调用-------》会创建一个binder_thread } Binder.c (linux-3.0.86\drivers\staging\android) 105029 2015/3/24 static long binder_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) { 两个重要的结构体: struct binder_proc *proc = filp->private_data; struct binder_thread *thread; 一个重要的函数: thread = binder_get_thread(proc); switch (cmd) { case BINDER_WRITE_READ: { struct binder_write_read bwr; if (size != sizeof(struct binder_write_read)) { ret = -EINVAL; goto err; } if (copy_from_user(&bwr, ubuf, sizeof(bwr))) { ret = -EFAULT; goto err; } binder_debug(BINDER_DEBUG_READ_WRITE, "binder: %d:%d write %ld at %08lx, read %ld at %08lx\n", proc->pid, thread->pid, bwr.write_size, bwr.write_buffer, bwr.read_size, bwr.read_buffer); if (bwr.write_size > 0) { ret = binder_thread_write(proc, thread, (void __user *)bwr.write_buffer, bwr.write_size, &bwr.write_consumed); if (ret < 0) { bwr.read_consumed = 0; if (copy_to_user(ubuf, &bwr, sizeof(bwr))) ret = -EFAULT; goto err; } } }
在Linux内核中 Binder.c (linux-3.0.86\drivers\staging\android) 105029 2015/3/24
调用对应的
binder_ioctl
{
读操作
ret = binder_thread_read(proc, thread, (void __user *)bwr.read_buffer, bwr.read_size, &bwr.read_consumed, filp->f_flags & O_NONBLOCK);
}
binder_thread_read{
BR_NOOP 对于所有的读操作,数据头都是BR_NOOP
读出的数据 binder_write_read.redbuf-------------->BR_NOOP , cmd | 数据, cmd | 数据
}
进入休眠,等待text_server(Android)
bio_init(&msg, iodata, sizeof(iodata), 4); bio_put_uint32(&msg, 0); // strict mode header bio_put_string16_x(&msg, SVC_MGR_NAME); bio_put_string16_x(&msg, name); bio_put_obj(&msg, ptr);
#define SVC_MGR_NAME "android.os.IServiceManager"
binder_thread_read : BR_TRANSACTION service_manager (1362, 1362), binder_thread_read , print data : 0000: 00 . 00 . 00 . 00 . 1a . 00 . 00 . 00 . 61 a 00 . 6e n 00 . 64 d 00 . 72 r 00 . 0016: 6f o 00 . 69 i 00 . 64 d 00 . 2e . 00 . 6f o 00 . 73 s 00 . 2e . 00 . 49 I 00 . 0032: 53 S 00 . 65 e 00 . 72 r 00 . 76 v 00 . 69 i 00 . 63 c 00 . 65 e 00 . 4d M 00 . 0048: 61 a 00 . 6e n 00 . 61 a 00 . 67 g 00 . 65 e 00 . 72 r 00 . 00 . 00 . 00 . 00 . 0064: 05 . 00 . 00 . 00 . 68 h 00 . 65 e 00 . 6c l 00 . 6c l 00 . 6f o 00 . 00 . 00 . 0080: 85 . 2a * 68 h 73 s 7f . 01 . 00 . 00 . 01 . 00 . 00 . 00 . 00 . 00 . 00 . 00 .