mirror of
https://github.com/GrapheneOS/hardened_malloc.git
synced 2025-11-05 02:06:32 +01:00
Merge 39b1b13bce into 4fe9018b6f
This commit is contained in:
commit
20ca6578e7
2 changed files with 23 additions and 0 deletions
21
h_malloc.c
21
h_malloc.c
|
|
@ -1874,6 +1874,27 @@ EXPORT size_t h_malloc_object_size_fast(const void *p) {
|
||||||
return SIZE_MAX;
|
return SIZE_MAX;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EXPORT void *h_memcpy(void *dst, const void *src, size_t len) {
|
||||||
|
if (len > malloc_object_size(src)) {
|
||||||
|
fatal_error("memcpy: length greater than source");
|
||||||
|
}
|
||||||
|
if (len > malloc_object_size(dst)) {
|
||||||
|
fatal_error("memcpy: destination too small");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dst == src) {
|
||||||
|
return dst;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *d = (char *)dst;
|
||||||
|
const char *s = (const char *)src;
|
||||||
|
for (size_t i = 0; i < len; ++i) {
|
||||||
|
d[i] = s[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
return dst;
|
||||||
|
}
|
||||||
|
|
||||||
EXPORT int h_mallopt(UNUSED int param, UNUSED int value) {
|
EXPORT int h_mallopt(UNUSED int param, UNUSED int value) {
|
||||||
#ifdef __ANDROID__
|
#ifdef __ANDROID__
|
||||||
if (param == M_PURGE) {
|
if (param == M_PURGE) {
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ extern "C" {
|
||||||
#define h_realloc realloc
|
#define h_realloc realloc
|
||||||
#define h_aligned_alloc aligned_alloc
|
#define h_aligned_alloc aligned_alloc
|
||||||
#define h_free free
|
#define h_free free
|
||||||
|
#define h_memcpy memcpy
|
||||||
|
|
||||||
#define h_posix_memalign posix_memalign
|
#define h_posix_memalign posix_memalign
|
||||||
|
|
||||||
|
|
@ -54,6 +55,7 @@ __attribute__((alloc_size(2))) void *h_realloc(void *ptr, size_t size);
|
||||||
__attribute__((malloc)) __attribute__((alloc_size(2))) __attribute__((alloc_align(1)))
|
__attribute__((malloc)) __attribute__((alloc_size(2))) __attribute__((alloc_align(1)))
|
||||||
void *h_aligned_alloc(size_t alignment, size_t size);
|
void *h_aligned_alloc(size_t alignment, size_t size);
|
||||||
void h_free(void *ptr);
|
void h_free(void *ptr);
|
||||||
|
void *h_memcpy(void *dstpp, const void *srcpp, size_t len);
|
||||||
|
|
||||||
// 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);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue