system/corennnnn
Révision | 70a8c7aef01d843eb390e744243667e1af6c5615 (tree) |
---|---|
l'heure | 2016-07-16 04:34:10 |
Auteur | Mark Salyzyn <salyzyn@goog...> |
Commiter | Steve Kondik |
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
@@ -19,6 +19,7 @@ | ||
19 | 19 | * ashmem-enabled kernel. See ashmem-sim.c for the "fake" tmp-based version, |
20 | 20 | * used by the simulator. |
21 | 21 | */ |
22 | +#define LOG_TAG "ashmem" | |
22 | 23 | |
23 | 24 | #include <errno.h> |
24 | 25 | #include <fcntl.h> |
@@ -32,6 +33,7 @@ | ||
32 | 33 | #include <linux/ashmem.h> |
33 | 34 | |
34 | 35 | #include <cutils/ashmem.h> |
36 | +#include <log/log.h> | |
35 | 37 | |
36 | 38 | #define ASHMEM_DEVICE "/dev/ashmem" |
37 | 39 |
@@ -92,6 +94,7 @@ static int __ashmem_is_ashmem(int fd) | ||
92 | 94 | return -1; |
93 | 95 | } |
94 | 96 | |
97 | + rdev = 0; /* Too much complexity to sniff __ashmem_rdev */ | |
95 | 98 | if (S_ISCHR(st.st_mode) && st.st_rdev) { |
96 | 99 | pthread_mutex_lock(&__ashmem_lock); |
97 | 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 | 131 | errno = ENOTTY; |
118 | 132 | return -1; |
119 | 133 | } |