当前位置:网站首页>Binder core API

Binder core API

2022-07-08 00:53:00 InfoQ

Binder The core API

1.binder_init

This method is mainly used to register misc equipment ,debugfs_create_dir It means in debugfs Create a directory in the file system , The return value points to dentry The pointer to

null
register misc equipment ,miscdevice Structure , That's the previous registration misc Parameters passed in when the device is installed

null
file_operations Structure , Specify the method of corresponding file operation , You can see that the method in the user space above will eventually call the corresponding method , It's based on this

null
2.binder_open

establish binder_proc object , And save the current process and other information to binder_proc object , This object manages IPC All kinds of information required and have the root structure of other structures ; And then binder_proc Save object to file pointer filp, And the binder_proc Add to the global linked list binder_procs.

null
Binder Drive through static HLIST_HEAD(binder_procs);, Created a global hash linked list binder_procs, Used to save all binder_proc queue , Every time you create a new binder_proc Objects will join binder_procs In the list .

null
3.binder_mmap

The main function : First, in the kernel virtual address space , Apply for a piece of memory of the same size as the user's virtual memory ; Then apply for 1 individual page Size of physical memory , Then the same physical memory is mapped to kernel virtual address space and user virtual memory space respectively , Thus, the user space is realized Buffer And kernel space Buffer The function of synchronous operation .

null
null
summary :

binder_init: Initialize character device ;binder_open: Turn on the drive , The process needs to hold binder_main_lock Synchronization lock ;binder_mmap: Apply for memory space , The process needs to hold binder_mmap_lock Synchronization lock ;binder_ioctl: Execute corresponding ioctl operation , The process needs to hold binder_main_lock Synchronization lock ; When in binder_thread_read The process ,read_buffer If there is no data, release the synchronization lock , And in wait_event_freezable The process , Wake up when data arrives and try to hold the synchronization lock .
原网站

版权声明
本文为[InfoQ]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/189/202207072203456640.html