2018-01-26 04:42:44 +08:00
|
|
|
//===-- scudo_malloc.cpp ----------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
///
|
|
|
|
/// Interceptors for malloc related functions.
|
|
|
|
///
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "scudo_allocator.h"
|
|
|
|
|
|
|
|
#include "interception/interception.h"
|
|
|
|
#include "sanitizer_common/sanitizer_platform_interceptors.h"
|
|
|
|
|
2018-07-04 03:03:46 +08:00
|
|
|
#include <stddef.h>
|
|
|
|
|
2018-01-26 04:42:44 +08:00
|
|
|
using namespace __scudo;
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
INTERCEPTOR_ATTRIBUTE void free(void *ptr) {
|
2018-06-12 22:42:40 +08:00
|
|
|
scudoDeallocate(ptr, 0, 0, FromMalloc);
|
2018-01-26 04:42:44 +08:00
|
|
|
}
|
|
|
|
|
2018-07-04 03:03:46 +08:00
|
|
|
INTERCEPTOR_ATTRIBUTE void *malloc(size_t size) {
|
2018-06-12 22:42:40 +08:00
|
|
|
return scudoAllocate(size, 0, FromMalloc);
|
2018-01-26 04:42:44 +08:00
|
|
|
}
|
|
|
|
|
2018-07-04 03:03:46 +08:00
|
|
|
INTERCEPTOR_ATTRIBUTE void *realloc(void *ptr, size_t size) {
|
2018-01-26 04:42:44 +08:00
|
|
|
return scudoRealloc(ptr, size);
|
|
|
|
}
|
|
|
|
|
2018-07-04 03:03:46 +08:00
|
|
|
INTERCEPTOR_ATTRIBUTE void *calloc(size_t nmemb, size_t size) {
|
2018-01-26 04:42:44 +08:00
|
|
|
return scudoCalloc(nmemb, size);
|
|
|
|
}
|
|
|
|
|
2018-07-04 03:03:46 +08:00
|
|
|
INTERCEPTOR_ATTRIBUTE void *valloc(size_t size) {
|
2018-01-26 04:42:44 +08:00
|
|
|
return scudoValloc(size);
|
|
|
|
}
|
|
|
|
|
|
|
|
INTERCEPTOR_ATTRIBUTE
|
2018-07-04 03:03:46 +08:00
|
|
|
int posix_memalign(void **memptr, size_t alignment, size_t size) {
|
2018-01-26 04:42:44 +08:00
|
|
|
return scudoPosixMemalign(memptr, alignment, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if SANITIZER_INTERCEPT_CFREE
|
|
|
|
INTERCEPTOR_ATTRIBUTE void cfree(void *ptr) ALIAS("free");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if SANITIZER_INTERCEPT_MEMALIGN
|
2018-07-04 03:03:46 +08:00
|
|
|
INTERCEPTOR_ATTRIBUTE void *memalign(size_t alignment, size_t size) {
|
2018-06-12 22:42:40 +08:00
|
|
|
return scudoAllocate(size, alignment, FromMemalign);
|
2018-01-26 04:42:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
INTERCEPTOR_ATTRIBUTE
|
2018-07-04 03:03:46 +08:00
|
|
|
void *__libc_memalign(size_t alignment, size_t size) ALIAS("memalign");
|
2018-01-26 04:42:44 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if SANITIZER_INTERCEPT_PVALLOC
|
2018-07-04 03:03:46 +08:00
|
|
|
INTERCEPTOR_ATTRIBUTE void *pvalloc(size_t size) {
|
2018-01-26 04:42:44 +08:00
|
|
|
return scudoPvalloc(size);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if SANITIZER_INTERCEPT_ALIGNED_ALLOC
|
2018-07-04 03:03:46 +08:00
|
|
|
INTERCEPTOR_ATTRIBUTE void *aligned_alloc(size_t alignment, size_t size) {
|
2018-01-26 04:42:44 +08:00
|
|
|
return scudoAlignedAlloc(alignment, size);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if SANITIZER_INTERCEPT_MALLOC_USABLE_SIZE
|
2018-07-04 03:03:46 +08:00
|
|
|
INTERCEPTOR_ATTRIBUTE size_t malloc_usable_size(void *ptr) {
|
2018-01-26 04:42:44 +08:00
|
|
|
return scudoMallocUsableSize(ptr);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if SANITIZER_INTERCEPT_MALLOPT_AND_MALLINFO
|
|
|
|
INTERCEPTOR_ATTRIBUTE int mallopt(int cmd, int value) {
|
2018-10-26 06:15:44 +08:00
|
|
|
return 0;
|
2018-01-26 04:42:44 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
} // extern "C"
|