mirror of
https://github.com/GrapheneOS/hardened_malloc.git
synced 2024-12-20 21:34:23 -05:00
support Android malloc_usable_size
This commit is contained in:
parent
7917966eca
commit
ced3b0e070
12
h_malloc.c
12
h_malloc.c
@ -511,12 +511,12 @@ static inline void *allocate_small(size_t requested_size) {
|
|||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
static size_t slab_size_class(void *p) {
|
static size_t slab_size_class(const void *p) {
|
||||||
size_t offset = (char *)p - (char *)ro.slab_region_start;
|
size_t offset = (const char *)p - (const char *)ro.slab_region_start;
|
||||||
return offset / REAL_CLASS_REGION_SIZE;
|
return offset / REAL_CLASS_REGION_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static size_t slab_usable_size(void *p) {
|
static size_t slab_usable_size(const void *p) {
|
||||||
return size_classes[slab_size_class(p)];
|
return size_classes[slab_size_class(p)];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -742,7 +742,7 @@ static void regions_quarantine_deallocate_pages(void *p, size_t size, size_t gua
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static size_t hash_page(void *p) {
|
static size_t hash_page(const void *p) {
|
||||||
uintptr_t u = (uintptr_t)p >> PAGE_SHIFT;
|
uintptr_t u = (uintptr_t)p >> PAGE_SHIFT;
|
||||||
size_t sum = u;
|
size_t sum = u;
|
||||||
sum = (sum << 7) - sum + (u >> 16);
|
sum = (sum << 7) - sum + (u >> 16);
|
||||||
@ -814,7 +814,7 @@ static int regions_insert(void *p, size_t size, size_t guard_size) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct region_metadata *regions_find(void *p) {
|
static struct region_metadata *regions_find(const void *p) {
|
||||||
struct region_allocator *ra = ro.region_allocator;
|
struct region_allocator *ra = ro.region_allocator;
|
||||||
|
|
||||||
size_t mask = ra->total - 1;
|
size_t mask = ra->total - 1;
|
||||||
@ -1363,7 +1363,7 @@ EXPORT void h_free_sized(void *p, size_t expected_size) {
|
|||||||
thread_seal_metadata();
|
thread_seal_metadata();
|
||||||
}
|
}
|
||||||
|
|
||||||
EXPORT size_t h_malloc_usable_size(void *p) {
|
EXPORT size_t h_malloc_usable_size(H_MALLOC_USABLE_SIZE_CONST void *p) {
|
||||||
if (p == NULL) {
|
if (p == NULL) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -47,8 +47,14 @@ void h_free(void *ptr);
|
|||||||
// POSIX
|
// POSIX
|
||||||
int h_posix_memalign(void **memptr, size_t alignment, size_t size);
|
int h_posix_memalign(void **memptr, size_t alignment, size_t size);
|
||||||
|
|
||||||
|
#ifdef __ANDROID__
|
||||||
|
#define H_MALLOC_USABLE_SIZE_CONST const
|
||||||
|
#else
|
||||||
|
#define H_MALLOC_USABLE_SIZE_CONST
|
||||||
|
#endif
|
||||||
|
|
||||||
// glibc extensions
|
// glibc extensions
|
||||||
size_t h_malloc_usable_size(void *ptr);
|
size_t h_malloc_usable_size(H_MALLOC_USABLE_SIZE_CONST void *ptr);
|
||||||
int h_mallopt(int param, int value);
|
int h_mallopt(int param, int value);
|
||||||
int h_malloc_trim(size_t pad);
|
int h_malloc_trim(size_t pad);
|
||||||
void h_malloc_stats(void);
|
void h_malloc_stats(void);
|
||||||
|
Loading…
Reference in New Issue
Block a user