Merge "libcutils: Add ashmem_valid() function" am: d00c7470ea
am: 8b1f7b595c
Change-Id: I1be0fc5d74c609ec42578c29c7af9d897708f8c6
This commit is contained in:
commit
da07f7880c
2 changed files with 23 additions and 15 deletions
|
|
@ -20,6 +20,7 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
int ashmem_valid(int fd);
|
||||||
int ashmem_create_region(const char *name, size_t size);
|
int ashmem_create_region(const char *name, size_t size);
|
||||||
int ashmem_set_prot_region(int fd, int prot);
|
int ashmem_set_prot_region(int fd, int prot);
|
||||||
int ashmem_pin_region(int fd, size_t offset, size_t len);
|
int ashmem_pin_region(int fd, size_t offset, size_t len);
|
||||||
|
|
|
||||||
|
|
@ -85,7 +85,7 @@ static int __ashmem_open()
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Make sure file descriptor references ashmem, negative number means false */
|
/* 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;
|
dev_t rdev;
|
||||||
struct stat st;
|
struct stat st;
|
||||||
|
|
@ -117,22 +117,29 @@ static int __ashmem_is_ashmem(int fd)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rdev) {
|
if (fatal) {
|
||||||
LOG_ALWAYS_FATAL("illegal fd=%d mode=0%o rdev=%d:%d expected 0%o %d:%d",
|
if (rdev) {
|
||||||
fd, st.st_mode, major(st.st_rdev), minor(st.st_rdev),
|
LOG_ALWAYS_FATAL("illegal fd=%d mode=0%o rdev=%d:%d expected 0%o %d:%d",
|
||||||
S_IFCHR | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IRGRP,
|
fd, st.st_mode, major(st.st_rdev), minor(st.st_rdev),
|
||||||
major(rdev), minor(rdev));
|
S_IFCHR | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IRGRP,
|
||||||
} else {
|
major(rdev), minor(rdev));
|
||||||
LOG_ALWAYS_FATAL("illegal fd=%d mode=0%o rdev=%d:%d expected 0%o",
|
} else {
|
||||||
fd, st.st_mode, major(st.st_rdev), minor(st.st_rdev),
|
LOG_ALWAYS_FATAL("illegal fd=%d mode=0%o rdev=%d:%d expected 0%o",
|
||||||
S_IFCHR | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IRGRP);
|
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;
|
errno = ENOTTY;
|
||||||
return -1;
|
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
|
* ashmem_create_region - creates a new ashmem region and returns the file
|
||||||
* descriptor, or <0 on error
|
* descriptor, or <0 on error
|
||||||
|
|
@ -175,7 +182,7 @@ error:
|
||||||
|
|
||||||
int ashmem_set_prot_region(int fd, int prot)
|
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) {
|
if (ret < 0) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
@ -187,7 +194,7 @@ int ashmem_pin_region(int fd, size_t offset, size_t len)
|
||||||
{
|
{
|
||||||
struct ashmem_pin pin = { offset, len };
|
struct ashmem_pin pin = { offset, len };
|
||||||
|
|
||||||
int ret = __ashmem_is_ashmem(fd);
|
int ret = __ashmem_is_ashmem(fd, 1);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
@ -199,7 +206,7 @@ int ashmem_unpin_region(int fd, size_t offset, size_t len)
|
||||||
{
|
{
|
||||||
struct ashmem_pin pin = { offset, len };
|
struct ashmem_pin pin = { offset, len };
|
||||||
|
|
||||||
int ret = __ashmem_is_ashmem(fd);
|
int ret = __ashmem_is_ashmem(fd, 1);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
return ret;
|
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 ashmem_get_size_region(int fd)
|
||||||
{
|
{
|
||||||
int ret = __ashmem_is_ashmem(fd);
|
int ret = __ashmem_is_ashmem(fd, 1);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue