diff options
author | Mark Salyzyn <salyzyn@google.com> | 2016-08-24 15:48:55 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2016-08-24 15:48:55 +0000 |
commit | 8b1f7b595c51268086d89e830d1046d123160ca3 (patch) | |
tree | 5fbbc2e7e8577beaf97974a3f03f9934abecaf6d /libcutils | |
parent | 8615d79d85e53c86028b702152bc00864b18f9d5 (diff) | |
parent | d00c7470eacaa953b8396c5813b24a933d90e179 (diff) | |
download | system_core-8b1f7b595c51268086d89e830d1046d123160ca3.tar.gz system_core-8b1f7b595c51268086d89e830d1046d123160ca3.tar.bz2 system_core-8b1f7b595c51268086d89e830d1046d123160ca3.zip |
Merge "libcutils: Add ashmem_valid() function"
am: d00c7470ea
Change-Id: Ib09d3ee7bb131c30f59ea273f357c045394206fb
Diffstat (limited to 'libcutils')
-rw-r--r-- | libcutils/ashmem-dev.c | 37 |
1 files changed, 22 insertions, 15 deletions
diff --git a/libcutils/ashmem-dev.c b/libcutils/ashmem-dev.c index 4a07d66bb..09fa09a09 100644 --- a/libcutils/ashmem-dev.c +++ b/libcutils/ashmem-dev.c @@ -85,7 +85,7 @@ static int __ashmem_open() } /* Make sure file descriptor references ashmem, negative number means false */ -static int __ashmem_is_ashmem(int fd) +static int __ashmem_is_ashmem(int fd, int fatal) { dev_t rdev; struct stat st; @@ -117,22 +117,29 @@ static int __ashmem_is_ashmem(int fd) } } - if (rdev) { - LOG_ALWAYS_FATAL("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 { - LOG_ALWAYS_FATAL("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); + if (fatal) { + if (rdev) { + LOG_ALWAYS_FATAL("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 { + LOG_ALWAYS_FATAL("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); + } + /* NOTREACHED */ } - /* NOTREACHED */ errno = ENOTTY; return -1; } +int ashmem_valid(int fd) +{ + return __ashmem_is_ashmem(fd, 0) >= 0; +} + /* * ashmem_create_region - creates a new ashmem region and returns the file * descriptor, or <0 on error @@ -175,7 +182,7 @@ error: int ashmem_set_prot_region(int fd, int prot) { - int ret = __ashmem_is_ashmem(fd); + int ret = __ashmem_is_ashmem(fd, 1); if (ret < 0) { return ret; } @@ -187,7 +194,7 @@ int ashmem_pin_region(int fd, size_t offset, size_t len) { struct ashmem_pin pin = { offset, len }; - int ret = __ashmem_is_ashmem(fd); + int ret = __ashmem_is_ashmem(fd, 1); if (ret < 0) { return ret; } @@ -199,7 +206,7 @@ int ashmem_unpin_region(int fd, size_t offset, size_t len) { struct ashmem_pin pin = { offset, len }; - int ret = __ashmem_is_ashmem(fd); + int ret = __ashmem_is_ashmem(fd, 1); if (ret < 0) { return ret; } @@ -209,7 +216,7 @@ int ashmem_unpin_region(int fd, size_t offset, size_t len) int ashmem_get_size_region(int fd) { - int ret = __ashmem_is_ashmem(fd); + int ret = __ashmem_is_ashmem(fd, 1); if (ret < 0) { return ret; } |