Android binder inter-process communication mechanism 1-binder driver, android1-binder

Source: Internet
Author: User

Android binder inter-process communication mechanism 1-binder driver, android1-binder

The following content is only an outline. To understand the details, see the source code:

Statement: I am a cainiao. I hope I can get some advice from the experts.

Binder device:/dev/binder

The binder process communication involves four roles:

Client Service ServiceManager Binder driver

1. Binder driver

Source code location: kernel/[vendor]/[codename]/drivers/staging/android/binder. c

Kernel/[vendor]/[codename]/drivers/staging/android/binder. h

And other related files.

1. Basic Data Structure

Struct binder_work: describes the work items to be processed.

 

Struct binder_node: describes a binder entity object. Each Service component corresponds to a Binder entity object in the Binder driver to describe its status in the kernel.

Struct binder_ref_death: Describe the death receipt notification of a Service component

Struct binder_ref: describes a Binder reference object. Each Client component corresponds to a Binder reference object in the Binder driver to describe its status in the kernel.

 

Struct binder_buffer: describes a kernel buffer used to transmit data between processes. Every process that uses the communication mechanism between Binder processes has a list of kernel buffers in the Binder driver to save the kernel buffers allocated to it by the Binder driver.

Struct binder_proc: used to describe a process using the Binder communication mechanism. When the process calls open to open/dev/binder, the Binder driver creates this struct for the process.

Struct binder_thread: describes a thread in the Binder thread pool.

 

Struct binder_transaction: Describes the communication process between processes.

Struct binder_write_read: describes the data transmitted during inter-process communication, including input and output data.

Enum BinderDriverCommandProtocol: defines the command protocol code of the input (Binder driver) and is used when writing data to the Binder.

Enum BinderDriverReturnProctocol: defines the return protocol code of the output (Binder driver), which is used to read the returned results from the Binder.

 

Struct binder_ptr_cookie: Describes the death receipt notification of a Binder object or a Service component.

 

Stuct binder_transaction_data: describes the data transmitted during inter-process communication. It is used as a parameter of the command protocol code BC_TRANSACTION and BC_REPLY.

 

2. Binder usage process:

Initialization: binder_init

Create/proc/binder/proc directory on the target device

Every process that uses the Binder Mechanism to communicate has a corresponding file under this directory. The file can be used to read the Binder thread pool and Binder object of the process, binder references objects, kernel buffers, and other information.

The state states transactions transaction_log failed_taransaction_log file is created to record the running status of the Binder driver.

Binder device open: binder_open

Create a binder_proc struct for the process and add it to the global hash queue binder_procs.

Binder Device File Memory ing: binder_mmap

Allocate a kernel buffer for the process so that it can be used to transmit inter-process communication data.

 

3. kernel buffer management:

Allocate the kernel buffer: binder_alloc_buf

Release the kernel buffer: binder_free_buf

Query the kernel buffer: binder_buffer_lookup


Why does android not directly use the linux shared memory mechanism for inter-process communication, but use AIDL to publish service interfaces?

Android seems to be using the Binder driver at the underlying layer for sharing. This driver can avoid many problems with shared memory in Linux. I have not analyzed the details.

What is Android Binder? Binder is a driver.

In Android, Binder is used for inter-process communication. ViewBinder should be a Binder class. When this class is called by the last application, this class calls the underlying library.

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.