summaryrefslogtreecommitdiff
path: root/libs/binder/Parcel.cpp
diff options
context:
space:
mode:
author Mark Salyzyn <salyzyn@google.com> 2016-02-05 18:12:01 +0000
committer android-build-merger <android-build-merger@google.com> 2016-02-05 18:12:01 +0000
commit6ff4920cb12fa4776d27b54e2e4daa27bb78fc10 (patch)
tree5f9a73f21c552838b705e41b254520a4832e4220 /libs/binder/Parcel.cpp
parent4b41905563dc35190d60e92c2ea51d210e600caa (diff)
parent3196c839af9ea74c59f5860c0d1f6e7e20b7a65e (diff)
Merge "system_server BINDER_TYPE_FD driver ashmem accessors" am: b23a388c64
am: 3196c839af * commit '3196c839af9ea74c59f5860c0d1f6e7e20b7a65e': system_server BINDER_TYPE_FD driver ashmem accessors
Diffstat (limited to 'libs/binder/Parcel.cpp')
-rw-r--r--libs/binder/Parcel.cpp32
1 files changed, 30 insertions, 2 deletions
diff --git a/libs/binder/Parcel.cpp b/libs/binder/Parcel.cpp
index d3fe1589ae..1008f02d8c 100644
--- a/libs/binder/Parcel.cpp
+++ b/libs/binder/Parcel.cpp
@@ -18,7 +18,9 @@
//#define LOG_NDEBUG 0
#include <errno.h>
+#include <fcntl.h>
#include <inttypes.h>
+#include <pthread.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
@@ -95,6 +97,32 @@ enum {
BLOB_ASHMEM_MUTABLE = 2,
};
+static dev_t ashmem_rdev()
+{
+ static dev_t __ashmem_rdev;
+ static pthread_mutex_t __ashmem_rdev_lock = PTHREAD_MUTEX_INITIALIZER;
+
+ pthread_mutex_lock(&__ashmem_rdev_lock);
+
+ dev_t rdev = __ashmem_rdev;
+ if (!rdev) {
+ int fd = TEMP_FAILURE_RETRY(open("/dev/ashmem", O_RDONLY));
+ if (fd >= 0) {
+ struct stat st;
+
+ int ret = TEMP_FAILURE_RETRY(fstat(fd, &st));
+ close(fd);
+ if ((ret >= 0) && S_ISCHR(st.st_mode)) {
+ rdev = __ashmem_rdev = st.st_rdev;
+ }
+ }
+ }
+
+ pthread_mutex_unlock(&__ashmem_rdev_lock);
+
+ return rdev;
+}
+
void acquire_object(const sp<ProcessState>& proc,
const flat_binder_object& obj, const void* who, size_t* outAshmemSize)
{
@@ -126,7 +154,7 @@ void acquire_object(const sp<ProcessState>& proc,
if ((obj.cookie != 0) && (outAshmemSize != NULL)) {
struct stat st;
int ret = fstat(obj.handle, &st);
- if (!ret && S_ISCHR(st.st_mode)) {
+ if (!ret && S_ISCHR(st.st_mode) && (st.st_rdev == ashmem_rdev())) {
// If we own an ashmem fd, keep track of how much memory it refers to.
int size = ashmem_get_size_region(obj.handle);
if (size > 0) {
@@ -179,7 +207,7 @@ static void release_object(const sp<ProcessState>& proc,
if (outAshmemSize != NULL) {
struct stat st;
int ret = fstat(obj.handle, &st);
- if (!ret && S_ISCHR(st.st_mode)) {
+ if (!ret && S_ISCHR(st.st_mode) && (st.st_rdev == ashmem_rdev())) {
int size = ashmem_get_size_region(obj.handle);
if (size > 0) {
*outAshmemSize -= size;