Add support for cpus_allowed_policy
[fio.git] / os / os-android.h
index 070aa1a3eee3cf7392664940d22bc99c2cc8735e..954178ddaecf3c25805db4e55a22ab104f570b69 100644 (file)
@@ -13,6 +13,7 @@
 #include <sched.h>
 #include <linux/unistd.h>
 #include <linux/major.h>
+#include <asm/byteorder.h>
 
 #include "binject.h"
 #include "../file.h"
 #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));
 }
 
-
 #define SPLICE_DEF_SIZE        (64*1024)
 
-static inline int ioprio_set(int which, int who, int ioprio)
-{
-       return syscall(__NR_ioprio_set, which, who, ioprio);
-}
-
 enum {
        IOPRIO_CLASS_NONE,
        IOPRIO_CLASS_RT,
@@ -100,6 +136,18 @@ enum {
 #define IOPRIO_BITS            16
 #define IOPRIO_CLASS_SHIFT     13
 
+static inline int ioprio_set(int which, int who, int ioprio_class, int ioprio)
+{
+       /*
+        * If no class is set, assume BE
+        */
+       if (!ioprio_class)
+               ioprio_class = IOPRIO_CLASS_BE;
+
+       ioprio |= ioprio_class << IOPRIO_CLASS_SHIFT;
+       return syscall(__NR_ioprio_set, which, who, ioprio);
+}
+
 #ifndef BLKGETSIZE64
 #define BLKGETSIZE64   _IOR(0x12,114,size_t)
 #endif