2

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 done with unix socket + mmap /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 create file in tmpfs, you can use shm_open too

win-t
  • 159
  • 1
  • 9
  • @pskink yes, I've read that, but I still believe that it can be achieved with traditional unix socket and mmap – win-t Feb 13 '18 at 04:49
  • so do you have huge amount of data to be passed between processes? what do you really want to achieve? – pskink Feb 13 '18 at 13:10
  • @pskink, it's not about what I really want to achieve, but the question about "why binder exists at first place? can existing technology do the same thing?", and please don't delete your old comments so others can get the context of our discussion – win-t Feb 13 '18 at 14:19
  • i gave you a link with answer why: https://elinux.org/Android_Binder - see what Dianne Hackborn says for example about tokens, security and permissions – pskink Feb 13 '18 at 14:39
  • @pskink, but still, can be implemented using traditional unix socket (something like systemd-logind implementation), anyway, thanks, but I'm still not satisfied by that, binder is one of the big reason why android kernel cannot merge with upstream linux kernel, I just don't like two (almost) identical software maintaned in two different upstream – win-t Feb 13 '18 at 14:53
  • I think only "link to death" feature that (maybe) cannot be constructed with traditional IPC – win-t Feb 13 '18 at 14:59
  • i think you cannot have tokens like `Binder` provides - try to pass a custom `Binder` object to some different process - see its `binder.getClass().toString()` and then pass it back to the original process and do the same – pskink Feb 13 '18 at 15:03
  • hmm, ok, fair enough, I don't fully understand how java class are stored in ram, but I think on C/C++ level, struct/class can be passed as void* pointer on shared mmap with zero-copy, maybe java class can too, it's just opaque data to the kernel. @pskink can you post that link as an answer? – win-t Feb 13 '18 at 15:16

1 Answers1

0

There are mainly three reason to create new Mechanism of Binder

  1. Complexity
  2. Performance
  3. Security

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

Example : MediaPlayBack -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 Function.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