Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Android Binder IPC for Linux

Android Binder IPC for Linux

binder-for-linux is an experimental project to evaluate the feasibility of porting Android Binder IPC subsystem to Ubuntu Linux.

GitHub: https://github.com/hungys/binder-for-linux

Yu-Hsin Hung

June 29, 2016
Tweet

More Decks by Yu-Hsin Hung

Other Decks in Research

Transcript

  1. ANDROID BINDER IPC FOR LINUX Motivation ▸ Binder IPC subsystem

    is the core part of Android OS ▸ Activity, Service, BroadcastReceiver, ContentProvider ▸ ActivityManager, WindowManager, SurfaceFlinger ▸ Why Android propose another IPC mechanism? ▸ Feasibility of using Binder IPC on common Linux distros
  2. In the Android platform, the binder is used for nearly

    everything that happens across processes in the core platform. Dianne Hackborn ANDROID BINDER IPC FOR LINUX
  3. ANDROID BINDER IPC FOR LINUX Unix IPC ▸ Pipe ▸

    FIFO ▸ Socket ▸ SysV IPC ▸ Shared memory ▸ Message queue ▸ Semaphore
  4. ANDROID BINDER IPC FOR LINUX Binder IPC ▸ Client/server architecture

    ▸ Remote procedure call ▸ Implemented as a Linux device driver ▸ Only one copy (from user to kernel) is needed
  5. ANDROID BINDER IPC FOR LINUX Binder Driver ▸ init() -

    Register a misc device (/dev/binder) ▸ open() - Open binder device ▸ mmap() - Allocate memory and map to kernel space ▸ ioctl() - Write/read IPC
  6. ANDROID BINDER IPC FOR LINUX Binder Driver - ioctl ▸

    No read() & write() ▸ Commands ▸ BINDER_WRITE_READ ▸ BINDER_SET_MAX_THREADS ▸ BINDER_SET_CONTEXT_MGR ▸ BINDER_THREAD_EXIT
  7. ANDROID BINDER IPC FOR LINUX Binder Driver - protocol ▸

    BC_TRANSACTION <-> BR_TRANSACTION ▸ BC_REPLY <-> BR_REPLY ▸ ……
  8. ANDROID BINDER IPC FOR LINUX Binder IPC subsystem - more!

    ▸ ProcessState, IPCThreadState ▸ Parcel ▸ AIDL
  9. ANDROID BINDER IPC FOR LINUX Implementation ▸ Environment & code

    base ▸ Ubuntu 14.04.4 (Linux Kernel 4.2.0-27) ▸ Android 6.0.1_r46 ▸ Components to port ▸ binder & ashmem driver ▸ binder library ▸ Service Manager
  10. ANDROID BINDER IPC FOR LINUX Issues & Challenges ▸ Not

    dynamic loadable ▸ Bionic C library ▸ Atomic library ▸ Dependencies to Android log daemon & SELinux
  11. ANDROID BINDER IPC FOR LINUX Not dynamic loadable ▸ 10+

    symbols are not exported by kernel ▸ Naive way: build kernel along with Binder driver statically ▸ Tricky way: kallsyms + function pointer redirection ▸ Run a shell script in Makefile ▸ Generate additional C source and header files ▸ Compile with Binder driver
  12. ANDROID BINDER IPC FOR LINUX Atomic library ▸ Have tried

    C++11 <atomic> -> no luck :( ▸ x86 supports atomic fetch and add!
  13. ANDROID BINDER IPC FOR LINUX Evaluation - correctness ▸ Integer

    Adder Service ▸ Client: a = iter, b = iter+3 -> Server: calculate a+b
  14. ANDROID BINDER IPC FOR LINUX Evaluation - analysis ▸ Not

    suitable for large payload ▸ mmap allows only 4MB ▸ deferred work (e.g. release buffer) in workqueue ▸ global lock everywhere :(
  15. ANDROID BINDER IPC FOR LINUX Reference ▸ Linux Kernel &

    Android Framework source code ▸ ̽窼獈ቘ薹 Android ໐ஞ戔懯௏మ - ໐ஞ薹䯤缰̾ ▸ Binder羬ڜ - Gityuan玡ਮ ▸ Android IPC Mechanism by jserv ▸ Deep Dive into Android IPC/Binder Framework