Reputation: 187
I'm trying to learn into Android (Linux) kernel, and I know that Android needs very fast (zero-copy) IPC, but still, I don't get the reason why binder needs to be there.
Can the same thing be done with a Unix socket and mmaping the /dev/shm
file?
Let's say using dbus, but to achieve zero-copy, create and open file in tmpfs (e.g. /dev/shm
) delete it (so another process can accidentally open it), send file descriptor to other process and mmap it.
EDIT:
instead of creating a file in tmpfs, you can use shm_open
too
Upvotes: 3
Views: 2412
Reputation: 63
There are mainly three reason to create new Mechanism of Binder:
Complexity: In the smartphone platform, especially the Android system, in order to provide application developers with a variety of functions, this communication method is ubiquitous, such as media playback, video and audio capture, and various sensors that make mobile phones smarter (acceleration, orientation, temperature, brightness, etc.) are all managed by different Servers, and the application can use these services only by establishing a connection with these Servers as a Client. It takes a little time and effort to develop dazzling functionality.The widespread adoption of the Client-Server approach poses a challenge to inter-process communication (IPC) mechanisms
Performance: As a general-purpose interface, socket has low transmission efficiency and high overhead. It is mainly used for inter-process communication across the network and low-speed communication between processes on the machine. The message queue and pipeline adopt the store-and-forward method, that is, the data is first copied from the sender buffer to the buffer opened by the kernel, and then copied from the kernel buffer to the receiver buffer. There are at least two copy processes. Although shared memory does not need to be copied, it is complicated to control and difficult to use.
Security: As an open platform with many developers, Android comes from a wide range of sources, so it is very important to ensure the security of smart terminals. Traditional IPC does not have any security measures and relies entirely on upper-layer protocols to ensure it. First of all, the receiver of traditional IPC cannot obtain the reliable UID/PID (user ID/process ID) of the other party's process, so it cannot identify the other party's identity.
Android assigns its own UID to each installed application, so the UID of the process is an important symbol to identify the identity of the process. Using traditional IPC, only the user can fill in the UID/PID in the data packet, but this is unreliable and easy to be used by malicious programs.
Secondly, traditional IPC access points are open, and private channels cannot be established.
Based on the above reasons, Android needs to establish a new IPC mechanism to meet the system's requirements for communication methods, transmission performance and security, which is Binder
Upvotes: 1