diff options
author | Mark Salyzyn <salyzyn@google.com> | 2016-02-02 09:19:39 -0800 |
---|---|---|
committer | Steve Kondik <steve@cyngn.com> | 2016-07-15 12:34:10 -0700 |
commit | 70a8c7aef01d843eb390e744243667e1af6c5615 (patch) | |
tree | 0aa0e4b5b43921a29c93da71cf8ea6c8dea83c7e | |
parent | 2895e11453da7afc326864a097ff59833a0bffea (diff) | |
download | system_core-70a8c7aef01d843eb390e744243667e1af6c5615.zip system_core-70a8c7aef01d843eb390e744243667e1af6c5615.tar.gz system_core-70a8c7aef01d843eb390e744243667e1af6c5615.tar.bz2 |
libcutils: ashmem print error message for invalid fd
NB: We decided to not sniff for the constant saved __ashmem_rdev in
the early error path; requiring either the use of atomic operations,
or acquiring a lock to do it correctly. The heroics are not worth it.
Bug: 26871259
Change-Id: I46249838850ae32063eb5b7d08c731c5bb0fbf6b
-rw-r--r-- | libcutils/ashmem-dev.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/libcutils/ashmem-dev.c b/libcutils/ashmem-dev.c index 77e4d0d..d6a48c9 100644 --- a/libcutils/ashmem-dev.c +++ b/libcutils/ashmem-dev.c @@ -19,6 +19,7 @@ * ashmem-enabled kernel. See ashmem-sim.c for the "fake" tmp-based version, * used by the simulator. */ +#define LOG_TAG "ashmem" #include <errno.h> #include <fcntl.h> @@ -32,6 +33,7 @@ #include <linux/ashmem.h> #include <cutils/ashmem.h> +#include <log/log.h> #define ASHMEM_DEVICE "/dev/ashmem" @@ -92,6 +94,7 @@ static int __ashmem_is_ashmem(int fd) return -1; } + rdev = 0; /* Too much complexity to sniff __ashmem_rdev */ if (S_ISCHR(st.st_mode) && st.st_rdev) { pthread_mutex_lock(&__ashmem_lock); rdev = __ashmem_rdev; @@ -114,6 +117,17 @@ static int __ashmem_is_ashmem(int fd) } } + if (rdev) { + ALOGE("illegal fd=%d mode=0%o rdev=%d:%d expected 0%o %d:%d", + fd, st.st_mode, major(st.st_rdev), minor(st.st_rdev), + S_IFCHR | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IRGRP, + major(rdev), minor(rdev)); + } else { + ALOGE("illegal fd=%d mode=0%o rdev=%d:%d expected 0%o", + fd, st.st_mode, major(st.st_rdev), minor(st.st_rdev), + S_IFCHR | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IRGRP); + } + errno = ENOTTY; return -1; } |