Merge "libcutils: Implement ashmem_valid on host." am: 915521c7d8 am: dedee60d25
am: 74984481ab
Change-Id: Ia00ca53744af52d8366da8e432e51dce7d0717ea
This commit is contained in:
commit
d3c0e89fbc
1 changed files with 24 additions and 12 deletions
|
|
@ -34,6 +34,29 @@
|
||||||
|
|
||||||
#include <utils/Compat.h>
|
#include <utils/Compat.h>
|
||||||
|
|
||||||
|
static bool ashmem_validate_stat(int fd, struct stat* buf) {
|
||||||
|
int result = fstat(fd, buf);
|
||||||
|
if (result == -1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Check if this is an "ashmem" region.
|
||||||
|
* TODO: This is very hacky, and can easily break.
|
||||||
|
* We need some reliable indicator.
|
||||||
|
*/
|
||||||
|
if (!(buf->st_nlink == 0 && S_ISREG(buf->st_mode))) {
|
||||||
|
errno = ENOTTY;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ashmem_valid(int fd) {
|
||||||
|
struct stat buf;
|
||||||
|
return ashmem_validate_stat(fd, &buf);
|
||||||
|
}
|
||||||
|
|
||||||
int ashmem_create_region(const char* /*ignored*/, size_t size) {
|
int ashmem_create_region(const char* /*ignored*/, size_t size) {
|
||||||
char pattern[PATH_MAX];
|
char pattern[PATH_MAX];
|
||||||
snprintf(pattern, sizeof(pattern), "/tmp/android-ashmem-%d-XXXXXXXXX", getpid());
|
snprintf(pattern, sizeof(pattern), "/tmp/android-ashmem-%d-XXXXXXXXX", getpid());
|
||||||
|
|
@ -65,18 +88,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)
|
||||||
{
|
{
|
||||||
struct stat buf;
|
struct stat buf;
|
||||||
int result = fstat(fd, &buf);
|
if (!ashmem_validate_stat(fd, &buf)) {
|
||||||
if (result == -1) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Check if this is an "ashmem" region.
|
|
||||||
* TODO: This is very hacky, and can easily break.
|
|
||||||
* We need some reliable indicator.
|
|
||||||
*/
|
|
||||||
if (!(buf.st_nlink == 0 && S_ISREG(buf.st_mode))) {
|
|
||||||
errno = ENOTTY;
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue