How the [Android] file descriptor travels through binder

Source: Internet
Author: User

In Linux, a file descriptor is a process, represented by an integer. by fork, although both the child process and the parent process open the same file, the file descriptor is different.
The same file descriptor values correspond to different file descriptor value arrays in different processes.
Therefore, when the file descriptor is transferred through binder, it cannot be a simple copy of the file descriptor value.
The key is to correspond the file structure to a new file descriptor, so that the other process and the original process through different file descriptors corresponding to the same file.
Fortunately, the structure of open files struct file can be shared between processes, through the file descriptor of process A to obtain a struct file, and then in process B to obtain a new empty file descriptor, and then associate them together, the implementation of the file descriptor between the different processes of transmission.

Key functions and structures
int filedescripter;
To get open file struct file structure through document descriptor
Strcut file = Fget (filedescripter)

Gets the empty file descriptor
NEW_FD = Task_get_unused_fd_flags (Target_proc, o_cloexec);

Establish an association
Task_fd_install (Target_proc, new_fd,strcut file);

Reference:
"An analysis of the principle of anonymous shared memory Ashmem (Anonymous shared memories) sharing between processes in Android system"
http://blog.csdn.net/luoshengyang/article/details/6666491

How the [Android] file descriptor travels through binder

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.