Name anonymous mmap mallocs.
Change-Id: Icc53ba1eecb8445210623826d8e99a611d686f7f
This commit is contained in:
parent
69c89942db
commit
8921060253
@ -24,6 +24,10 @@ static void __bionic_heap_error(const char* msg, const char* function, void* p);
|
|||||||
#define USAGE_ERROR_ACTION(m,p) \
|
#define USAGE_ERROR_ACTION(m,p) \
|
||||||
__bionic_heap_error("ARGUMENT IS INVALID HEAP ADDRESS", __FUNCTION__, p)
|
__bionic_heap_error("ARGUMENT IS INVALID HEAP ADDRESS", __FUNCTION__, p)
|
||||||
|
|
||||||
|
/* Bionic named anonymous memory declarations */
|
||||||
|
static void* named_anonymous_mmap(size_t length);
|
||||||
|
#define MMAP(s) named_anonymous_mmap(s)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Ugly inclusion of C file so that bionic specific #defines configure
|
* Ugly inclusion of C file so that bionic specific #defines configure
|
||||||
* dlmalloc.
|
* dlmalloc.
|
||||||
@ -74,3 +78,40 @@ static void __bionic_heap_error(const char* msg, const char* function, void* p)
|
|||||||
/* So that we can get a memory dump around p */
|
/* So that we can get a memory dump around p */
|
||||||
*((int **) 0xdeadbaad) = (int *) p;
|
*((int **) 0xdeadbaad) = (int *) p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Bionic named anonymous memory definitions */
|
||||||
|
#include <linux/ashmem.h>
|
||||||
|
static int __ashmem_create_region(const char* name, size_t size)
|
||||||
|
{
|
||||||
|
int fd, ret;
|
||||||
|
fd = open("/dev/ashmem", O_RDWR);
|
||||||
|
if (fd < 0)
|
||||||
|
return fd;
|
||||||
|
if (name != NULL) {
|
||||||
|
char buf[ASHMEM_NAME_LEN];
|
||||||
|
|
||||||
|
strlcpy(buf, name, sizeof(buf));
|
||||||
|
ret = ioctl(fd, ASHMEM_SET_NAME, buf);
|
||||||
|
if (ret < 0) { /* error */
|
||||||
|
close(fd);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ret = ioctl(fd, ASHMEM_SET_SIZE, size);
|
||||||
|
if (ret < 0) { /* error */
|
||||||
|
close(fd);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
return fd;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void* named_anonymous_mmap(size_t length)
|
||||||
|
{
|
||||||
|
void* ret;
|
||||||
|
int fd = __ashmem_create_region("libc malloc", length);
|
||||||
|
if (fd < 0)
|
||||||
|
return MAP_FAILED;
|
||||||
|
ret = mmap(NULL, length, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0);
|
||||||
|
close (fd);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user