5. 服务使用过程
test_client进程:
用户态:
(1)已结获得了“hello”服务,handle=1;
(2)构造数据:code(那个函数)和函数参数
(3)发送ioctl后进入内核态,先写后读
(15)取出返回值
内核态:
(4)binder_ioctl被调用,根据handle在binder_proc中根据refs_by_desc找到binder_ref,在根据node找到服务的binder_node结构体,在根据proc找到目的进程test_server
(5)把数据放入test_server的todo链表
(6)唤醒test_server进程,然后在binder_thread_read中休眠
(17)被唤醒后把数据返回给用户空间
test_server进程:
用户态:
(8)取出数据,根据code调用哪个函数,并把参数给函数
(9)把返回值构造为数据
(10)调用ioctl来发送返回数据
内核态:
(7):被唤醒后把数据返回用户空间
(11)找到要回复的进程test_client
(12)把数据放入test_client的todo链表
(13)唤醒test_client进程
使用服务
构造数据(参数),格式:四字节全零+四字节字符串长度+字符串("weidongshan")
txn.code 表示的是哪个函数,就是个整数,为双方约定其代表某个函数
接着调用ioctl先写后读,把数据放入test_server的todo结构体,接着唤醒test_server,然后自身休眠
[ 1580.379989] test_client (1381, 1381), binder_thread_write : BC_TRANSACTION
[ 1580.386741] binder: 1381:1381 BC_TRANSACTION 9 -> 1373 - node 3, data beb20a5c-beb20a4c size 32-0
[ 1580.395634] test_client (1381, 1381), binder_transaction , print data :
[ 1580.402184] 0000: 00 . 00 . 00 . 00 . 0b . 00 . 00 . 00 . 77 w 00 . 65 e 00 . 69 i 00 . 64 d 00 .
[ 1580.411029] 0016: 6f o 00 . 6e n 00 . 67 g 00 . 73 s 00 . 68 h 00 . 61 a 00 . 6e n 00 . 00 . 00 .
[ 1580.419888] test_client (1381, 1381), binder_thread_read : BR_NOOP
test_server被唤醒后返回用户控件,取出code和参数后调用函数执行,得到返回值后构造BC_REPLY类型数据调用ioctl回复给test_client,
[ 1580.426103] test_server (1373, 1373), binder_thread_read : BR_TRANSACTION
[ 1580.432828] test_server (1373, 1373), binder_thread_read , print data :
[ 1580.439419] 0000: 00 . 00 . 00 . 00 . 0b . 00 . 00 . 00 . 77 w 00 . 65 e 00 . 69 i 00 . 64 d 00 .
[ 1580.448263] 0016: 6f o 00 . 6e n 00 . 67 g 00 . 73 s 00 . 68 h 00 . 61 a 00 . 6e n 00 . 00 . 00 .
[ 1580.457129] test_client (1381, 1381), binder_thread_read : BR_TRANSACTION_COMPLETE
//用户空间处理完数据后,把内核态保存数据的buffer释放掉
[ 1580.464710] test_server (1373, 1373), binder_thread_write : BC_FREE_BUFFER
[ 1580.471541] test_server (1373, 1373), binder_thread_write : BC_REPLY
[ 1580.477877] binder: 1373:1373 BC_REPLY 10 -> 1381:1381, data be857a5c-be857a4c size 4-0
[ 1580.485859] test_server (1373, 1373), binder_transaction , print data :
[ 1580.492455] 0000: 01 . 00 . 00 . 00 .
[ 1580.496109] test_client (1381, 1381), binder_thread_read : BR_NOOP
[ 1580.502282] test_server (1373, 1373), binder_thread_read : BR_NOOP
test_client收到BR_REPLY类型数据,返回数据1
[ 1580.508436] test_client (1381, 1381), binder_thread_read : BR_REPLY
[ 1580.514684] test_client (1381, 1381), binder_thread_read , print data :
[ 1580.521301] 0000: 01 . 00 . 00 . 00 .
[ 1580.524929] test_server (1373, 1373), binder_thread_read : BR_TRANSACTION_COMPLETE
[ 1580.532489] test_client (1381, 1381), binder_thread_write : BC_FREE_BUFFER
[ 1580.539345] test_server (1373, 1373), binder_thread_read : BR_NOOP
[ 1580.545510] test_client (1381, 1381), binder_thread_write : BC_RELEASE