Android ION

One of the features google added to linux kernel is a general purpose allocator /dev/ion. The new allocator allows us to allocate memory from different heaps and devices, virtual and physical

User space usage

#include<stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/mman.h>

#include "/home/developer/kernel3.4/goldfish/include/linux/ion.h"

void main()
{
	int *p;
	struct ion_fd_data fd_data;
	struct ion_allocation_data ionAllocData;
	ionAllocData.len=0x1000;
	ionAllocData.align = 0;
	ionAllocData.flags = ION_HEAP_TYPE_SYSTEM;

	int fd=open("/dev/ion",O_RDWR);
	ioctl(fd,ION_IOC_ALLOC, &ionAllocData);
	fd_data.handle = ionAllocData.handle;
	ioctl(fd,ION_IOC_SHARE,&fd_data); 
        p=mmap(0,0x1000,PROT_READ|PROT_WRITE,MAP_SHARED,fd_data.fd,0);
	p[0]=99;
	perror("test");
	printf("hello all %d\n",p[0]);
}

Kernel usage

extern struct ion_device *idev;

void allocfromion()
{
    int *buf;
    struct ion_handle *data;

    client = ion_client_create(idev, -1, "user");
    data = ion_alloc(client,0x1000,0,ION_HEAP_SYSTEM_MASK);
    
    buf = ion_map_kernel(client,data);
}

 

Tagged , ,

1 thought on “Android ION

  1. […] abusando do sistema de gerenciamento de memória do Android – o alocador de memória Android ION. O ION foi introduzido com o Android 4.0 no final de 2011 e simplesmente fornece aos aplicativos a […]

Comments are closed.