Flexible I/O Tester development
 help / color / mirror / Atom feed
* android ashmem patch [review request]
@ 2013-04-30 22:04 Akers, Jason B
  2013-05-01  3:34 ` Aaron Carroll
  2013-05-01 19:31 ` Jens Axboe
  0 siblings, 2 replies; 4+ messages in thread
From: Akers, Jason B @ 2013-04-30 22:04 UTC (permalink / raw)
  To: 'fio@vger.kernel.org'

I wrapped the ashmem calls with the existing shm* function definitions. It's a little ugly, but makes for an easy patch touching only os/os-android.h.

Tested on both arm and x86 android phones.

Jason Akers


--- a/os/os-android.h	2013-04-30 14:30:05.014461848 -0700
+++ b/os/os-android.h	2013-04-30 14:24:49.442213734 -0700
@@ -57,24 +57,65 @@
 #include <linux/shm.h>
 #define SHM_HUGETLB    04000
 
+#include <stdio.h>
+#include <linux/ashmem.h>
+#include <sys/mman.h>
+
+#define ASHMEM_DEVICE	"/dev/ashmem"
+
 static inline int shmctl (int __shmid, int __cmd, struct shmid_ds *__buf)
 {
-	return syscall(__NR_shmctl, __shmid, __cmd, __buf);
+	int ret=0;
+	if (__cmd == IPC_RMID)
+	{
+		int length = ioctl(__shmid, ASHMEM_GET_SIZE, NULL);
+		struct ashmem_pin pin = {0 , length};
+		ret = ioctl(__shmid, ASHMEM_UNPIN, &pin);
+		close(__shmid);
+	}
+	return ret;
 }
 
 static inline int shmget (key_t __key, size_t __size, int __shmflg)
 {
-	return syscall(__NR_shmget, __key, __size, __shmflg);
+	int fd,ret;
+	char key[11];
+	
+	fd = open(ASHMEM_DEVICE, O_RDWR);
+	if (fd < 0)
+		return fd;
+
+	sprintf(key,"%d",__key);
+	ret = ioctl(fd, ASHMEM_SET_NAME, key);
+	if (ret < 0)
+		goto error;
+
+	ret = ioctl(fd, ASHMEM_SET_SIZE, __size);
+	if (ret < 0)
+		goto error;
+
+	return fd;
+	
+error:
+	close(fd);
+	return ret;
 }
 
 static inline void *shmat (int __shmid, const void *__shmaddr, int __shmflg)
 {
-	return (void *)syscall(__NR_shmat, __shmid, __shmaddr, __shmflg);
+	size_t *ptr, size = ioctl(__shmid, ASHMEM_GET_SIZE, NULL);
+	ptr = mmap(NULL, size + sizeof(size_t), PROT_READ | PROT_WRITE, MAP_SHARED, __shmid, 0);
+	*ptr = size;    //save size at beginning of buffer, for use with munmap
+	return &ptr[1];
 }
 
 static inline int shmdt (const void *__shmaddr)
 {
-	return syscall(__NR_shmctl, __shmaddr);
+	size_t *ptr, size;
+	ptr = (size_t *)__shmaddr;
+	ptr--;
+	size = *ptr;    //find mmap size which we stored at the beginning of the buffer
+	return munmap((void *)ptr, size + sizeof(size_t));
 }


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-05-01 19:32 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-04-30 22:04 android ashmem patch [review request] Akers, Jason B
2013-05-01  3:34 ` Aaron Carroll
2013-05-01  3:37   ` Aaron Carroll
2013-05-01 19:31 ` Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox