From 0ba49eacc9062622cb1aa55cf7b7e0b7d95aff9f Mon Sep 17 00:00:00 2001 From: Andrea Fioraldi Date: Fri, 30 Aug 2019 12:20:33 +0200 Subject: move android-ashmem.h to include/ --- android-ashmem.h | 81 ------------------------------------------------ include/android-ashmem.h | 81 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+), 81 deletions(-) delete mode 100644 android-ashmem.h create mode 100644 include/android-ashmem.h diff --git a/android-ashmem.h b/android-ashmem.h deleted file mode 100644 index a787c04b..00000000 --- a/android-ashmem.h +++ /dev/null @@ -1,81 +0,0 @@ -#ifndef _ANDROID_ASHMEM_H -#define _ANDROID_ASHMEM_H - -#include -#include -#include -#include -#include - -#if __ANDROID_API__ >= 26 -#define shmat bionic_shmat -#define shmctl bionic_shmctl -#define shmdt bionic_shmdt -#define shmget bionic_shmget -#endif - #include -#undef shmat -#undef shmctl -#undef shmdt -#undef shmget -#include - -#define ASHMEM_DEVICE "/dev/ashmem" - -static inline int shmctl(int __shmid, int __cmd, struct shmid_ds *__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) -{ - int fd,ret; - char ourkey[11]; - - fd = open(ASHMEM_DEVICE, O_RDWR); - if (fd < 0) - return fd; - - sprintf(ourkey,"%d",__key); - ret = ioctl(fd, ASHMEM_SET_NAME, ourkey); - 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) -{ - int size; - void *ptr; - - size = ioctl(__shmid, ASHMEM_GET_SIZE, NULL); - if (size < 0) { - return NULL; - } - - ptr = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, __shmid, 0); - if (ptr == MAP_FAILED) { - return NULL; - } - - return ptr; -} - -#endif diff --git a/include/android-ashmem.h b/include/android-ashmem.h new file mode 100644 index 00000000..a787c04b --- /dev/null +++ b/include/android-ashmem.h @@ -0,0 +1,81 @@ +#ifndef _ANDROID_ASHMEM_H +#define _ANDROID_ASHMEM_H + +#include +#include +#include +#include +#include + +#if __ANDROID_API__ >= 26 +#define shmat bionic_shmat +#define shmctl bionic_shmctl +#define shmdt bionic_shmdt +#define shmget bionic_shmget +#endif + #include +#undef shmat +#undef shmctl +#undef shmdt +#undef shmget +#include + +#define ASHMEM_DEVICE "/dev/ashmem" + +static inline int shmctl(int __shmid, int __cmd, struct shmid_ds *__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) +{ + int fd,ret; + char ourkey[11]; + + fd = open(ASHMEM_DEVICE, O_RDWR); + if (fd < 0) + return fd; + + sprintf(ourkey,"%d",__key); + ret = ioctl(fd, ASHMEM_SET_NAME, ourkey); + 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) +{ + int size; + void *ptr; + + size = ioctl(__shmid, ASHMEM_GET_SIZE, NULL); + if (size < 0) { + return NULL; + } + + ptr = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, __shmid, 0); + if (ptr == MAP_FAILED) { + return NULL; + } + + return ptr; +} + +#endif -- cgit 1.4.1