summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Salyzyn2016-02-02 11:19:39 -0600
committerMark Salyzyn2016-02-03 17:06:45 -0600
commite37111d7516827489232c6c894e114a58952fe4a (patch)
tree197b51e4e57b4963a61b32f05db67f99130544aa /libcutils/ashmem-dev.c
parent1186f3a5ad6581fae6e284fef4bfcefe50462cda (diff)
downloadplatform-system-core-e37111d7516827489232c6c894e114a58952fe4a.tar.gz
platform-system-core-e37111d7516827489232c6c894e114a58952fe4a.tar.xz
platform-system-core-e37111d7516827489232c6c894e114a58952fe4a.zip
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
Diffstat (limited to 'libcutils/ashmem-dev.c')
-rw-r--r--libcutils/ashmem-dev.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/libcutils/ashmem-dev.c b/libcutils/ashmem-dev.c
index 77e4d0d97..d6a48c953 100644
--- a/libcutils/ashmem-dev.c
+++ b/libcutils/ashmem-dev.c
@@ -19,6 +19,7 @@
19 * ashmem-enabled kernel. See ashmem-sim.c for the "fake" tmp-based version, 19 * ashmem-enabled kernel. See ashmem-sim.c for the "fake" tmp-based version,
20 * used by the simulator. 20 * used by the simulator.
21 */ 21 */
22#define LOG_TAG "ashmem"
22 23
23#include <errno.h> 24#include <errno.h>
24#include <fcntl.h> 25#include <fcntl.h>
@@ -32,6 +33,7 @@
32#include <linux/ashmem.h> 33#include <linux/ashmem.h>
33 34
34#include <cutils/ashmem.h> 35#include <cutils/ashmem.h>
36#include <log/log.h>
35 37
36#define ASHMEM_DEVICE "/dev/ashmem" 38#define ASHMEM_DEVICE "/dev/ashmem"
37 39
@@ -92,6 +94,7 @@ static int __ashmem_is_ashmem(int fd)
92 return -1; 94 return -1;
93 } 95 }
94 96
97 rdev = 0; /* Too much complexity to sniff __ashmem_rdev */
95 if (S_ISCHR(st.st_mode) && st.st_rdev) { 98 if (S_ISCHR(st.st_mode) && st.st_rdev) {
96 pthread_mutex_lock(&__ashmem_lock); 99 pthread_mutex_lock(&__ashmem_lock);
97 rdev = __ashmem_rdev; 100 rdev = __ashmem_rdev;
@@ -114,6 +117,17 @@ static int __ashmem_is_ashmem(int fd)
114 } 117 }
115 } 118 }
116 119
120 if (rdev) {
121 ALOGE("illegal fd=%d mode=0%o rdev=%d:%d expected 0%o %d:%d",
122 fd, st.st_mode, major(st.st_rdev), minor(st.st_rdev),
123 S_IFCHR | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IRGRP,
124 major(rdev), minor(rdev));
125 } else {
126 ALOGE("illegal fd=%d mode=0%o rdev=%d:%d expected 0%o",
127 fd, st.st_mode, major(st.st_rdev), minor(st.st_rdev),
128 S_IFCHR | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IRGRP);
129 }
130
117 errno = ENOTTY; 131 errno = ENOTTY;
118 return -1; 132 return -1;
119} 133}