Creating ashmem using the binder

In this lab, you’ll create a service to allocate and manage shared memory (ashmem)

  1. Create an empty android application with C++ support – the service application
  2. Add an android library module
    1. Create a new aidl file – IShmService
    2. Declare an interface with the following functions:
ParcelFileDescriptor createFD(in String name, int size);
ParcelFileDescriptor getFD(in String name)

Service Application

Implement the above interface using native code. To create an ashmem object use the following IOCTLs (taken from the kernel code)

you can include the file from the kernel (~/kernel3.4/goldfish)

jint fd = open("/dev/ashmem",O_RDWR);



map = (int *)mmap(0,size,PROT_READ|PROT_WRITE,MAP_SHARED,fd,0);

In the service implementation java code create and return ParcelFileDescriptor (using the file descriptor number returning from the native library)

Client ApplicationĀ 

Add a client application:

  1. Bind to the service
  2. Use the service to create and memory region
  3. Use native code to mmap the region and test your work