X-Git-Url: https://git.kernel.dk/?p=fio.git;a=blobdiff_plain;f=os%2Fos-android.h;h=f371116f8f6a9a45a37372b3044f71c77f88f368;hp=1d11cccde42bdd8b1db35bf016ccb65d8f38ac62;hb=d87674757a6afddc059e5bbfae3fcf267236a44e;hpb=0fa5c986746489c68dc5e57251117c660ceedfdd diff --git a/os/os-android.h b/os/os-android.h index 1d11cccd..f371116f 100644 --- a/os/os-android.h +++ b/os/os-android.h @@ -57,18 +57,17 @@ #define MAP_HUGETLB 0x40000 /* arch specific */ #endif - +#ifndef CONFIG_NO_SHM /* * The Android NDK doesn't currently export , so define the * necessary stuff here. */ -#include +#include #define SHM_HUGETLB 04000 #include #include -#include #define ASHMEM_DEVICE "/dev/ashmem" @@ -88,23 +87,24 @@ static inline int shmctl (int __shmid, int __cmd, struct shmid_ds *__buf) static inline int shmget (key_t __key, size_t __size, int __shmflg) { int fd,ret; - char key[11]; - + char keybuf[11]; + fd = open(ASHMEM_DEVICE, O_RDWR); if (fd < 0) return fd; - sprintf(key,"%d",__key); - ret = ioctl(fd, ASHMEM_SET_NAME, key); + sprintf(keybuf,"%d",__key); + ret = ioctl(fd, ASHMEM_SET_NAME, keybuf); if (ret < 0) goto error; - ret = ioctl(fd, ASHMEM_SET_SIZE, __size); + /* Stores size in first 8 bytes, allocate extra space */ + ret = ioctl(fd, ASHMEM_SET_SIZE, __size + sizeof(uint64_t)); if (ret < 0) goto error; return fd; - + error: close(fd); return ret; @@ -112,20 +112,22 @@ error: static inline void *shmat (int __shmid, const void *__shmaddr, int __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]; + size_t size = ioctl(__shmid, ASHMEM_GET_SIZE, NULL); + /* Needs to be 8-byte aligned to prevent SIGBUS on 32-bit ARM */ + uint64_t *ptr = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, __shmid, 0); + /* Save size at beginning of buffer, for use with munmap */ + *ptr = size; + return ptr + 1; } static inline int shmdt (const void *__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)); + /* Find mmap size which we stored at the beginning of the buffer */ + uint64_t *ptr = (uint64_t *)__shmaddr - 1; + size_t size = *ptr; + return munmap(ptr, size); } +#endif #define SPLICE_DEF_SIZE (64*1024)