Coder Social home page Coder Social logo

hungys / binder-for-linux Goto Github PK

View Code? Open in Web Editor NEW
151.0 15.0 73.0 341 KB

An experimental project to port Android Binder IPC subsystem to Ubuntu Linux.

Makefile 0.24% C 29.37% Shell 0.15% C++ 64.78% Assembly 5.36% Python 0.10%
binder android linux ipc

binder-for-linux's Introduction

binder-for-linux

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

Environment

  • Ubuntu 14.04.4 LTS
  • Linux Kernel 4.2.0-27
  • gcc 4.9.3

Codebase

  • Binder driver: mainline kernel 4.2.0-27-generic
  • Android Framework version: android-6.0.1_r46

Modifications

  • Make binder & ashmem driver dynamically loadable
    • Modified as a standard loadable kernel module
    • Use kallsyms and a shell script to generate symbol dependencies that are not exposed by kernel (e.g. get_vm_area)
  • Fix compatability issues after replacing Bionic C library with glibc
  • Fix compatibility issues of atomic library
    • Some are changed to use standard C++ atomic library (C++11 and gcc 4.9.3+ are required)
    • cutils/atomic.h is re-implemented with x86 atomic instructions
  • Dependencies to Android log daemon and SELinux library are removed
  • And other small fixes...

Get Started

To compile all from source,

$ ./project.sh makeall

Now you can install kernel modules (binder & ashmem) by,

$ ./project.sh insmod

Then run Service Manager in background,

$ sudo servicemanager/servicemanager &

We also prepared a benchmark program to perform correctness test and performance test,

$ sudo test/binderAddInts -n 100 -p 0   # correctness test with 100 iterations
$ sudo test/binderAddInts -n 10000 -p 4096   # performance test with 4K payload and 10000 iterations

Results

Performance Evaluation

We found an obvious fact that when the payload size is greater than 16K, the transmission latency grows much more rapidly compared with a small payload. After tracing more source code, we inferred that this may be due to the use of the single global lock. The Binder driver heavily uses a global lock to protect the critical sections, this may lead to low utilization in high concurrency situation. Also, during the driver initialization phase, the Binder driver created a bottom half – workqueue, to handle the release of system resource and buffer. During the benchmark with larger payload and higher iterations (e.g. 10000 per test), the workqueue need to handle the release request more frequently; however, the implementation of release function also need to acquire the global lock, which leads to much lower performance for real data transmission.

binder-for-linux's People

Contributors

hungys avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

binder-for-linux's Issues

project.sh returns an error

OS: Ubuntu 20.04 LTS
Shell: I've tried both BASH and ZSH, with the same results
The Error: When I try to ./project.sh makeall, I get this:

make[1]: Entering directory '/usr/src/linux-headers-5.4.0-42-generic'
  AR      /home/ma-ika/binder-for-linux/driver/binder/built-in.a
  CC [M]  /home/ma-ika/binder-for-linux/driver/binder/deps.o
/home/ma-ika/binder-for-linux/driver/binder/deps.c:32:6: error: conflicting types for ‘zap_page_range’
   32 | void zap_page_range(struct vm_area_struct *vma, unsigned long address, unsigned long size, struct zap_details *details)
      |      ^~~~~~~~~~~~~~
In file included from /home/ma-ika/binder-for-linux/driver/binder/deps.c:5:
./include/linux/mm.h:1457:6: note: previous declaration of ‘zap_page_range’ was here
 1457 | void zap_page_range(struct vm_area_struct *vma, unsigned long address,
      |      ^~~~~~~~~~~~~~
make[2]: *** [scripts/Makefile.build:275: /home/ma-ika/binder-for-linux/driver/binder/deps.o] Error 1
make[1]: *** [Makefile:1731: /home/ma-ika/binder-for-linux/driver/binder] Error 2
make[1]: Leaving directory '/usr/src/linux-headers-5.4.0-42-generic'
make: *** [Makefile:15: all] Error 2
make -C /lib/modules/5.4.0-42-generic/build V=0 M=$PWD
make[1]: Entering directory '/usr/src/linux-headers-5.4.0-42-generic'
  AR      /home/ma-ika/binder-for-linux/driver/ashmem/built-in.a
  CC [M]  /home/ma-ika/binder-for-linux/driver/ashmem/deps.o
  CC [M]  /home/ma-ika/binder-for-linux/driver/ashmem/ashmem.o
In file included from ./include/linux/export.h:42,
                 from ./include/linux/linkage.h:7,
                 from ./include/linux/kernel.h:8,
                 from ./include/linux/list.h:9,
                 from ./include/linux/module.h:9,
                 from /home/ma-ika/binder-for-linux/driver/ashmem/ashmem.c:21:
/home/ma-ika/binder-for-linux/driver/ashmem/ashmem.c: In function ‘ashmem_mmap’:
/home/ma-ika/binder-for-linux/driver/ashmem/ashmem.c:375:33: error: too few arguments to function ‘calc_vm_prot_bits’
  375 |  if (unlikely((vma->vm_flags & ~calc_vm_prot_bits(asma->prot_mask)) &
      |                                 ^~~~~~~~~~~~~~~~~
./include/linux/compiler.h:78:42: note: in definition of macro ‘unlikely’
   78 | # define unlikely(x) __builtin_expect(!!(x), 0)
      |                                          ^
In file included from /home/ma-ika/binder-for-linux/driver/ashmem/ashmem.c:28:
./include/linux/mman.h:117:1: note: declared here
  117 | calc_vm_prot_bits(unsigned long prot, unsigned long pkey)
      | ^~~~~~~~~~~~~~~~~
In file included from ./include/linux/export.h:42,
                 from ./include/linux/linkage.h:7,
                 from ./include/linux/kernel.h:8,
                 from ./include/linux/list.h:9,
                 from ./include/linux/module.h:9,
                 from /home/ma-ika/binder-for-linux/driver/ashmem/ashmem.c:21:
/home/ma-ika/binder-for-linux/driver/ashmem/ashmem.c:376:8: error: too few arguments to function ‘calc_vm_prot_bits’
  376 |        calc_vm_prot_bits(PROT_MASK))) {
      |        ^~~~~~~~~~~~~~~~~
./include/linux/compiler.h:78:42: note: in definition of macro ‘unlikely’
   78 | # define unlikely(x) __builtin_expect(!!(x), 0)
      |                                          ^
In file included from /home/ma-ika/binder-for-linux/driver/ashmem/ashmem.c:28:
./include/linux/mman.h:117:1: note: declared here
  117 | calc_vm_prot_bits(unsigned long prot, unsigned long pkey)
      | ^~~~~~~~~~~~~~~~~
/home/ma-ika/binder-for-linux/driver/ashmem/ashmem.c: In function ‘ashmem_exit’:
/home/ma-ika/binder-for-linux/driver/ashmem/ashmem.c:870:6: error: void value not ignored as it ought to be
  870 |  ret = misc_deregister(&ashmem_misc);
      |      ^
make[2]: *** [scripts/Makefile.build:275: /home/ma-ika/binder-for-linux/driver/ashmem/ashmem.o] Error 1
make[1]: *** [Makefile:1731: /home/ma-ika/binder-for-linux/driver/ashmem] Error 2
make[1]: Leaving directory '/usr/src/linux-headers-5.4.0-42-generic'
make: *** [Makefile:15: all] Error 2
make: Nothing to be done for 'all'.
gcc -I.. -Iinclude -DHAVE_PTHREADS -DHAVE_SYS_UIO_H -DHAVE_ENDIAN_H -DHAVE_ANDROID_OS=1 -std=c++11 -c -o utils/BlobCache.o utils/BlobCache.cpp
In file included from include/utils/SortedVector.h:26,
                 from include/utils/BlobCache.h:24,
                 from utils/BlobCache.cpp:24:
include/utils/Vector.h: In member function ‘const android::Vector<T>& android::Vector<TYPE>::operator=(const android::Vector<TYPE>&) const’:
include/utils/Vector.h:251:64: error: cannot convert ‘const android::Vector<TYPE>*’ to ‘android::VectorImpl*251 |     VectorImpl::operator = (static_cast<const VectorImpl&>(rhs));
      |                                                                ^
In file included from include/utils/Vector.h:26,
                 from include/utils/SortedVector.h:26,
                 from include/utils/BlobCache.h:24,
                 from utils/BlobCache.cpp:24:
include/utils/VectorImpl.h:56:59: note:   initializing argument 'this' of ‘android::VectorImpl& android::VectorImpl::operator=(const android::VectorImpl&)’
   56 |             VectorImpl&     operator = (const VectorImpl& rhs);
      |                                         ~~~~~~~~~~~~~~~~~~^~~
make: *** [Makefile:16: utils/BlobCache.o] Error 1
g++ -std=c++11 -o binderAddInts -I../libs/include -I.. -L../libs -DHAVE_PTHREADS -DHAVE_SYS_UIO_H -DHAVE_ENDIAN_H -DHAVE_ANDROID_OS=1 binderAddInts.cpp testUtil.c -lpthread -lbinder
In file included from ../libs/include/binder/Parcel.h:24,
                 from ../libs/include/binder/IPCThreadState.h:21,
                 from binderAddInts.cpp:49:
../libs/include/utils/Vector.h: In member function ‘const android::Vector<T>& android::Vector<TYPE>::operator=(const android::Vector<TYPE>&) const’:
../libs/include/utils/Vector.h:251:64: error: cannot convert ‘const android::Vector<TYPE>*’ to ‘android::VectorImpl*251 |     VectorImpl::operator = (static_cast<const VectorImpl&>(rhs));
      |                                                                ^
In file included from ../libs/include/utils/Vector.h:26,
                 from ../libs/include/binder/Parcel.h:24,
                 from ../libs/include/binder/IPCThreadState.h:21,
                 from binderAddInts.cpp:49:
../libs/include/utils/VectorImpl.h:56:59: note:   initializing argument 'this' of ‘android::VectorImpl& android::VectorImpl::operator=(const android::VectorImpl&)’
   56 |             VectorImpl&     operator = (const VectorImpl& rhs);
      |                                         ~~~~~~~~~~~~~~~~~~^~~
make: *** [Makefile:4: binderAddInts] Error 1

I then can't ./project.sh insmod or do anything else with binder.

Unknown symbol in module

OS: Manjaro Linux

Kernel version: 4.19.60

I copy binder.c/h, binder_alloc.c/h in linux 4.19.60 source code and overwrite binder.c/h in this projcet. Then I enter driver/binder folder and execute make command like following:

$ uname -r
4.19.60-1-MANJARO
$ cd driver/binder
$ make
make -C /lib/modules/4.19.60-1-MANJARO/build V=0 M=$PWD
make[1]: 进入目录“/usr/lib/modules/4.19.60-1-MANJARO/build”
  Building modules, stage 2.
  MODPOST 1 modules
WARNING: "binder_alloc_free_buf" [/home/xx/code/binder-for-linux-master/driver/binder/binder_linux.ko] undefined!
WARNING: "binder_alloc_prepare_to_free" [/home/xx/code/binder-for-linux-master/driver/binder/binder_linux.ko] undefined!
WARNING: "binder_alloc_get_allocated_count" [/home/xx/code/binder-for-linux-master/driver/binder/binder_linux.ko] undefined!
WARNING: "binder_alloc_new_buf" [/home/xx/code/binder-for-linux-master/driver/binder/binder_linux.ko] undefined!
WARNING: "binder_alloc_print_pages" [/home/xx/code/binder-for-linux-master/driver/binder/binder_linux.ko] undefined!
WARNING: "binder_alloc_vma_close" [/home/xx/code/binder-for-linux-master/driver/binder/binder_linux.ko] undefined!
WARNING: "binder_alloc_mmap_handler" [/home/xx/code/binder-for-linux-master/driver/binder/binder_linux.ko] undefined!
WARNING: "binder_alloc_shrinker_init" [/home/xx/code/binder-for-linux-master/driver/binder/binder_linux.ko] undefined!
WARNING: "binder_alloc_print_allocated" [/home/xx/code/binder-for-linux-master/driver/binder/binder_linux.ko] undefined!
WARNING: "binder_alloc_init" [/home/xx/code/binder-for-linux-master/driver/binder/binder_linux.ko] undefined!
WARNING: "binder_alloc_deferred_release" [/home/xx/code/binder-for-linux-master/driver/binder/binder_linux.ko] undefined!
make[1]: 离开目录“/usr/lib/modules/4.19.60-1-MANJARO/build”
$ sudo insmod binder_linux.ko
insmod: ERROR: could not insert module binder_linux.ko: Unknown symbol in module
$

following is systemd/journal output:

kernel: binder_linux: Unknown symbol binder_alloc_deferred_release (err -2)
kernel: binder_linux: Unknown symbol binder_alloc_init (err -2)
kernel: binder_linux: Unknown symbol binder_alloc_print_allocated (err -2)
kernel: binder_linux: Unknown symbol binder_alloc_shrinker_init (err -2)
kernel: binder_linux: Unknown symbol binder_alloc_mmap_handler (err -2)
kernel: binder_linux: Unknown symbol binder_alloc_vma_close (err -2)
kernel: binder_linux: Unknown symbol binder_alloc_print_pages (err -2)
kernel: binder_linux: Unknown symbol binder_alloc_new_buf (err -2)
kernel: binder_linux: Unknown symbol binder_alloc_get_allocated_count (err -2)
kernel: binder_linux: Unknown symbol binder_alloc_prepare_to_free (err -2)
kernel: binder_linux: Unknown symbol binder_alloc_free_buf (err -2)

How to solve this unknown symbol problem?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.