6. Binder codeflow (async transaction)
BpBinder::transact()
IPCThreadState::self()->transact(…)
waitForResponse(…)
talkWithDriver()
ioctl(mProcess->mDriveFD, BINDER_WRITE_READ, &bwr)
ioctl_open(…)
binder_transaction(…)
binder_thread_write(…)
binder_thread_read(…)
User space
Kernel space
copy_from_user(&bwr, ubuf, sizeof(bwr))
7. binder relation between client and
server (async transaction)
binder_ref
BBinder
binder_node
Process A Process B
binder_proc B
BpBinder
binder_proc A
Thread A1
binder_thread A1
rb_node
User space
Kernel space
8. binder relation between client and
server (async transaction)
BBinder
binder_node
Process A Process B
binder_proc B
BpBinder
Thread A1
binder_transaction t1
binder_transaction_d
ata tr1
binder_thread A1
binder_thread
*from
(2) copy_form_user(…)
binder_proc
*to_proc
rb_node
binder_work
User space
Kernel space
todo list
(1) last slide
(3)
(4)
9. binder_workbinder_work
Binder async todo list
binder_proc
list_head todo
binder_transaction
(async)
list_head
binder_transaction
(async)
list_head
binder_node
unsigned
has_async_transaction
list_head async_todo
11. binder_workbinder_work
Binder transaction linked list
binder_proc
list_head todo
binder_transaction
list_head
binder_transaction
list_head
binder_workbinder_work
binder_thread
list_head todo
binder_transaction
list_head
binder_transaction
list_head
*proc
12. Proc2
Binder driver sync transaction example
T
binder_transaction_stack
NULL
from_parent
TODO T
th1 TODO complete
binder_thread_read()binder_thread_write()
thread 1
thread 2
add list tail
add list tail
th1 stack
th1->SP
T_D
copy to user
Proc2
TODO T
Wakeup a sleep thread of Proc2
th1 TODO complete
proc 14054
thread 14073: l 10
transaction complete
pending transaction 39997494: ffffffc09a69ec00 from 0:0 to 14054:14073 code 0 flags 0 pri 0 r0 size 48:8 d
ata ffffff8004700050
13. Binder driver sync transaction example
(cont.)
binder_thread_write()binder_thread_read()
thread 1
thread 2
T
th1 stack
th2 stack
pop
T_reply
th1 TODO T_reply
th2 TODO complete
Proc2
TODO T
T
NULL
to_parent
push
th2 stack
th2->SP
add list tail
add list tail
Wait for thread2’s reply
Create a reply transaction
14. Binder driver sync transaction example
(cont.)
binder_thread_read()
thread 1
thread 2
th2 TODO complete
th1 TODO T_reply
T_D
copy to user
T_replyth1 TODO