2012-06-04 21:50:10 +08:00
|
|
|
//===-- asan_malloc_linux.cc ----------------------------------------------===//
|
2011-11-30 09:07:02 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file is a part of AddressSanitizer, an address sanity checker.
|
|
|
|
//
|
|
|
|
// Linux-specific malloc interception.
|
|
|
|
// We simply define functions like malloc, free, realloc, etc.
|
|
|
|
// They will replace the corresponding libc functions automagically.
|
|
|
|
//===----------------------------------------------------------------------===//
|
2013-03-19 22:33:38 +08:00
|
|
|
|
|
|
|
#include "sanitizer_common/sanitizer_platform.h"
|
2017-08-09 04:52:54 +08:00
|
|
|
#if SANITIZER_FREEBSD || SANITIZER_FUCHSIA || SANITIZER_LINUX || \
|
[Sanitizers] Basic sanitizer Solaris support (PR 33274)
Summary:
This is the first mostly working version of the Sanitizer port to 32-bit Solaris/x86.
It is currently based on Solaris 11.4 Beta.
This part was initially developed inside libsanitizer in the GCC tree and should apply to
both. Subsequent parts will address changes to clang, the compiler-rt build system
and testsuite.
I'm not yet sure what the right patch granularity is: if it's profitable to split the patch
up, I'd like to get guidance on how to do so.
Most of the changes are probably straightforward with a few exceptions:
* The Solaris syscall interface isn't stable, undocumented and can change within an
OS release. The stable interface is the libc interface, which I'm using here, if possible
using the internal _-prefixed names.
* While the patch primarily target 32-bit x86, I've left a few sparc changes in. They
cannot currently be used with clang due to a backend limitation, but have worked
fine inside the gcc tree.
* Some functions (e.g. largefile versions of functions like open64) only exist in 32-bit
Solaris, so I've introduced a separate SANITIZER_SOLARIS32 to check for that.
The patch (with the subsequent ones to be submitted shortly) was tested
on i386-pc-solaris2.11. Only a few failures remain, some of them analyzed, some
still TBD:
AddressSanitizer-i386-sunos :: TestCases/Posix/concurrent_overflow.cc
AddressSanitizer-i386-sunos :: TestCases/init-order-atexit.cc
AddressSanitizer-i386-sunos :: TestCases/log-path_test.cc
AddressSanitizer-i386-sunos :: TestCases/malloc-no-intercept.c
AddressSanitizer-i386-sunos-dynamic :: TestCases/Posix/concurrent_overflow.cc
AddressSanitizer-i386-sunos-dynamic :: TestCases/Posix/start-deactivated.cc
AddressSanitizer-i386-sunos-dynamic :: TestCases/default_options.cc
AddressSanitizer-i386-sunos-dynamic :: TestCases/init-order-atexit.cc
AddressSanitizer-i386-sunos-dynamic :: TestCases/log-path_test.cc
AddressSanitizer-i386-sunos-dynamic :: TestCases/malloc-no-intercept.c
SanitizerCommon-Unit :: ./Sanitizer-i386-Test/MemoryMappingLayout.DumpListOfModules
SanitizerCommon-Unit :: ./Sanitizer-i386-Test/SanitizerCommon.PthreadDestructorIterations
Maybe this is good enough the get the ball rolling.
Reviewers: kcc, alekseyshl
Reviewed By: alekseyshl
Subscribers: srhines, jyknight, kubamracek, krytarowski, fedor.sergeev, llvm-commits, #sanitizers
Tags: #sanitizers
Differential Revision: https://reviews.llvm.org/D40898
llvm-svn: 320740
2017-12-15 04:14:29 +08:00
|
|
|
SANITIZER_NETBSD || SANITIZER_SOLARIS
|
2011-11-30 09:07:02 +08:00
|
|
|
|
2014-01-29 17:29:16 +08:00
|
|
|
#include "sanitizer_common/sanitizer_tls_get_addr.h"
|
2011-11-30 09:07:02 +08:00
|
|
|
#include "asan_allocator.h"
|
|
|
|
#include "asan_interceptors.h"
|
|
|
|
#include "asan_internal.h"
|
|
|
|
#include "asan_stack.h"
|
|
|
|
|
|
|
|
// ---------------------- Replacement functions ---------------- {{{1
|
|
|
|
using namespace __asan; // NOLINT
|
|
|
|
|
2016-05-16 15:20:53 +08:00
|
|
|
static uptr allocated_for_dlsym;
|
|
|
|
static const uptr kDlsymAllocPoolSize = 1024;
|
|
|
|
static uptr alloc_memory_for_dlsym[kDlsymAllocPoolSize];
|
2015-12-01 17:22:41 +08:00
|
|
|
|
2017-08-03 10:22:11 +08:00
|
|
|
static INLINE bool IsInDlsymAllocPool(const void *ptr) {
|
2016-05-16 15:20:53 +08:00
|
|
|
uptr off = (uptr)ptr - (uptr)alloc_memory_for_dlsym;
|
2017-08-08 09:01:59 +08:00
|
|
|
return off < allocated_for_dlsym * sizeof(alloc_memory_for_dlsym[0]);
|
2016-05-16 15:20:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void *AllocateFromLocalPool(uptr size_in_bytes) {
|
|
|
|
uptr size_in_words = RoundUpTo(size_in_bytes, kWordSize) / kWordSize;
|
|
|
|
void *mem = (void*)&alloc_memory_for_dlsym[allocated_for_dlsym];
|
|
|
|
allocated_for_dlsym += size_in_words;
|
|
|
|
CHECK_LT(allocated_for_dlsym, kDlsymAllocPoolSize);
|
|
|
|
return mem;
|
2015-12-01 17:22:41 +08:00
|
|
|
}
|
|
|
|
|
2017-08-03 10:22:11 +08:00
|
|
|
static INLINE bool MaybeInDlsym() {
|
|
|
|
// Fuchsia doesn't use dlsym-based interceptors.
|
|
|
|
return !SANITIZER_FUCHSIA && asan_init_is_running;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *ReallocFromLocalPool(void *ptr, uptr size) {
|
|
|
|
const uptr offset = (uptr)ptr - (uptr)alloc_memory_for_dlsym;
|
|
|
|
const uptr copy_size = Min(size, kDlsymAllocPoolSize - offset);
|
|
|
|
void *new_ptr;
|
|
|
|
if (UNLIKELY(MaybeInDlsym())) {
|
|
|
|
new_ptr = AllocateFromLocalPool(size);
|
|
|
|
} else {
|
|
|
|
ENSURE_ASAN_INITED();
|
|
|
|
GET_STACK_TRACE_MALLOC;
|
|
|
|
new_ptr = asan_malloc(size, &stack);
|
|
|
|
}
|
|
|
|
internal_memcpy(new_ptr, ptr, copy_size);
|
|
|
|
return new_ptr;
|
|
|
|
}
|
|
|
|
|
2012-02-02 18:39:40 +08:00
|
|
|
INTERCEPTOR(void, free, void *ptr) {
|
2012-12-13 17:34:23 +08:00
|
|
|
GET_STACK_TRACE_FREE;
|
2016-05-16 15:20:53 +08:00
|
|
|
if (UNLIKELY(IsInDlsymAllocPool(ptr)))
|
2015-12-01 17:22:41 +08:00
|
|
|
return;
|
2012-12-21 16:53:59 +08:00
|
|
|
asan_free(ptr, &stack, FROM_MALLOC);
|
2011-11-30 09:07:02 +08:00
|
|
|
}
|
|
|
|
|
Recommit: Stop intercepting some malloc-related functions on FreeBSD and
macOS
Summary:
In https://bugs.freebsd.org/215125 I was notified that some configure
scripts attempt to test for the Linux-specific `mallinfo` and `mallopt`
functions by compiling and linking small programs which references the
functions, and observing whether that results in errors.
FreeBSD and macOS do not have the `mallinfo` and `mallopt` functions, so
normally these tests would fail, but when sanitizers are enabled, they
incorrectly succeed, because the sanitizers define interceptors for
these functions. This also applies to some other malloc-related
functions, such as `memalign`, `pvalloc` and `cfree`.
Fix this by not intercepting `mallinfo`, `mallopt`, `memalign`,
`pvalloc` and `cfree` for FreeBSD and macOS, in all sanitizers.
Also delete the non-functional `cfree` wrapper for Windows, to fix the
test cases on that platform.
Reviewers: emaste, kcc, rnk
Subscribers: timurrrr, eugenis, hans, joerg, llvm-commits, kubamracek
Differential Revision: https://reviews.llvm.org/D27654
llvm-svn: 293536
2017-01-31 03:06:13 +08:00
|
|
|
#if SANITIZER_INTERCEPT_CFREE
|
2012-02-02 18:39:40 +08:00
|
|
|
INTERCEPTOR(void, cfree, void *ptr) {
|
2012-12-13 17:34:23 +08:00
|
|
|
GET_STACK_TRACE_FREE;
|
2016-05-16 15:20:53 +08:00
|
|
|
if (UNLIKELY(IsInDlsymAllocPool(ptr)))
|
2015-12-01 17:22:41 +08:00
|
|
|
return;
|
2012-12-21 16:53:59 +08:00
|
|
|
asan_free(ptr, &stack, FROM_MALLOC);
|
2011-11-30 09:07:02 +08:00
|
|
|
}
|
Recommit: Stop intercepting some malloc-related functions on FreeBSD and
macOS
Summary:
In https://bugs.freebsd.org/215125 I was notified that some configure
scripts attempt to test for the Linux-specific `mallinfo` and `mallopt`
functions by compiling and linking small programs which references the
functions, and observing whether that results in errors.
FreeBSD and macOS do not have the `mallinfo` and `mallopt` functions, so
normally these tests would fail, but when sanitizers are enabled, they
incorrectly succeed, because the sanitizers define interceptors for
these functions. This also applies to some other malloc-related
functions, such as `memalign`, `pvalloc` and `cfree`.
Fix this by not intercepting `mallinfo`, `mallopt`, `memalign`,
`pvalloc` and `cfree` for FreeBSD and macOS, in all sanitizers.
Also delete the non-functional `cfree` wrapper for Windows, to fix the
test cases on that platform.
Reviewers: emaste, kcc, rnk
Subscribers: timurrrr, eugenis, hans, joerg, llvm-commits, kubamracek
Differential Revision: https://reviews.llvm.org/D27654
llvm-svn: 293536
2017-01-31 03:06:13 +08:00
|
|
|
#endif // SANITIZER_INTERCEPT_CFREE
|
2011-11-30 09:07:02 +08:00
|
|
|
|
2012-06-25 17:58:29 +08:00
|
|
|
INTERCEPTOR(void*, malloc, uptr size) {
|
2017-08-03 10:22:11 +08:00
|
|
|
if (UNLIKELY(MaybeInDlsym()))
|
2016-05-16 15:20:53 +08:00
|
|
|
// Hack: dlsym calls malloc before REAL(malloc) is retrieved from dlsym.
|
|
|
|
return AllocateFromLocalPool(size);
|
2017-06-09 15:47:38 +08:00
|
|
|
ENSURE_ASAN_INITED();
|
2012-12-13 17:34:23 +08:00
|
|
|
GET_STACK_TRACE_MALLOC;
|
2011-11-30 09:07:02 +08:00
|
|
|
return asan_malloc(size, &stack);
|
|
|
|
}
|
|
|
|
|
2012-06-25 17:58:29 +08:00
|
|
|
INTERCEPTOR(void*, calloc, uptr nmemb, uptr size) {
|
2017-08-03 10:22:11 +08:00
|
|
|
if (UNLIKELY(MaybeInDlsym()))
|
2012-02-08 21:45:31 +08:00
|
|
|
// Hack: dlsym calls calloc before REAL(calloc) is retrieved from dlsym.
|
2016-05-16 15:20:53 +08:00
|
|
|
return AllocateFromLocalPool(nmemb * size);
|
2017-06-09 15:47:38 +08:00
|
|
|
ENSURE_ASAN_INITED();
|
2012-12-13 17:34:23 +08:00
|
|
|
GET_STACK_TRACE_MALLOC;
|
2011-11-30 09:07:02 +08:00
|
|
|
return asan_calloc(nmemb, size, &stack);
|
|
|
|
}
|
|
|
|
|
2012-06-25 17:58:29 +08:00
|
|
|
INTERCEPTOR(void*, realloc, void *ptr, uptr size) {
|
2017-08-03 10:22:11 +08:00
|
|
|
if (UNLIKELY(IsInDlsymAllocPool(ptr)))
|
|
|
|
return ReallocFromLocalPool(ptr, size);
|
|
|
|
if (UNLIKELY(MaybeInDlsym()))
|
2017-06-09 15:47:38 +08:00
|
|
|
return AllocateFromLocalPool(size);
|
|
|
|
ENSURE_ASAN_INITED();
|
|
|
|
GET_STACK_TRACE_MALLOC;
|
2011-11-30 09:07:02 +08:00
|
|
|
return asan_realloc(ptr, size, &stack);
|
|
|
|
}
|
|
|
|
|
Recommit: Stop intercepting some malloc-related functions on FreeBSD and
macOS
Summary:
In https://bugs.freebsd.org/215125 I was notified that some configure
scripts attempt to test for the Linux-specific `mallinfo` and `mallopt`
functions by compiling and linking small programs which references the
functions, and observing whether that results in errors.
FreeBSD and macOS do not have the `mallinfo` and `mallopt` functions, so
normally these tests would fail, but when sanitizers are enabled, they
incorrectly succeed, because the sanitizers define interceptors for
these functions. This also applies to some other malloc-related
functions, such as `memalign`, `pvalloc` and `cfree`.
Fix this by not intercepting `mallinfo`, `mallopt`, `memalign`,
`pvalloc` and `cfree` for FreeBSD and macOS, in all sanitizers.
Also delete the non-functional `cfree` wrapper for Windows, to fix the
test cases on that platform.
Reviewers: emaste, kcc, rnk
Subscribers: timurrrr, eugenis, hans, joerg, llvm-commits, kubamracek
Differential Revision: https://reviews.llvm.org/D27654
llvm-svn: 293536
2017-01-31 03:06:13 +08:00
|
|
|
#if SANITIZER_INTERCEPT_MEMALIGN
|
2012-06-25 17:58:29 +08:00
|
|
|
INTERCEPTOR(void*, memalign, uptr boundary, uptr size) {
|
2012-12-13 17:34:23 +08:00
|
|
|
GET_STACK_TRACE_MALLOC;
|
2012-12-21 16:53:59 +08:00
|
|
|
return asan_memalign(boundary, size, &stack, FROM_MALLOC);
|
2011-11-30 09:07:02 +08:00
|
|
|
}
|
|
|
|
|
2014-01-29 17:29:16 +08:00
|
|
|
INTERCEPTOR(void*, __libc_memalign, uptr boundary, uptr size) {
|
|
|
|
GET_STACK_TRACE_MALLOC;
|
|
|
|
void *res = asan_memalign(boundary, size, &stack, FROM_MALLOC);
|
2016-01-14 08:04:37 +08:00
|
|
|
DTLS_on_libc_memalign(res, size);
|
2014-01-29 17:29:16 +08:00
|
|
|
return res;
|
|
|
|
}
|
Recommit: Stop intercepting some malloc-related functions on FreeBSD and
macOS
Summary:
In https://bugs.freebsd.org/215125 I was notified that some configure
scripts attempt to test for the Linux-specific `mallinfo` and `mallopt`
functions by compiling and linking small programs which references the
functions, and observing whether that results in errors.
FreeBSD and macOS do not have the `mallinfo` and `mallopt` functions, so
normally these tests would fail, but when sanitizers are enabled, they
incorrectly succeed, because the sanitizers define interceptors for
these functions. This also applies to some other malloc-related
functions, such as `memalign`, `pvalloc` and `cfree`.
Fix this by not intercepting `mallinfo`, `mallopt`, `memalign`,
`pvalloc` and `cfree` for FreeBSD and macOS, in all sanitizers.
Also delete the non-functional `cfree` wrapper for Windows, to fix the
test cases on that platform.
Reviewers: emaste, kcc, rnk
Subscribers: timurrrr, eugenis, hans, joerg, llvm-commits, kubamracek
Differential Revision: https://reviews.llvm.org/D27654
llvm-svn: 293536
2017-01-31 03:06:13 +08:00
|
|
|
#endif // SANITIZER_INTERCEPT_MEMALIGN
|
|
|
|
|
|
|
|
INTERCEPTOR(void*, aligned_alloc, uptr boundary, uptr size) {
|
|
|
|
GET_STACK_TRACE_MALLOC;
|
|
|
|
return asan_memalign(boundary, size, &stack, FROM_MALLOC);
|
|
|
|
}
|
2011-11-30 09:07:02 +08:00
|
|
|
|
2012-06-25 17:58:29 +08:00
|
|
|
INTERCEPTOR(uptr, malloc_usable_size, void *ptr) {
|
2013-11-13 22:46:58 +08:00
|
|
|
GET_CURRENT_PC_BP_SP;
|
|
|
|
(void)sp;
|
|
|
|
return asan_malloc_usable_size(ptr, pc, bp);
|
2012-01-17 14:39:10 +08:00
|
|
|
}
|
|
|
|
|
Recommit: Stop intercepting some malloc-related functions on FreeBSD and
macOS
Summary:
In https://bugs.freebsd.org/215125 I was notified that some configure
scripts attempt to test for the Linux-specific `mallinfo` and `mallopt`
functions by compiling and linking small programs which references the
functions, and observing whether that results in errors.
FreeBSD and macOS do not have the `mallinfo` and `mallopt` functions, so
normally these tests would fail, but when sanitizers are enabled, they
incorrectly succeed, because the sanitizers define interceptors for
these functions. This also applies to some other malloc-related
functions, such as `memalign`, `pvalloc` and `cfree`.
Fix this by not intercepting `mallinfo`, `mallopt`, `memalign`,
`pvalloc` and `cfree` for FreeBSD and macOS, in all sanitizers.
Also delete the non-functional `cfree` wrapper for Windows, to fix the
test cases on that platform.
Reviewers: emaste, kcc, rnk
Subscribers: timurrrr, eugenis, hans, joerg, llvm-commits, kubamracek
Differential Revision: https://reviews.llvm.org/D27654
llvm-svn: 293536
2017-01-31 03:06:13 +08:00
|
|
|
#if SANITIZER_INTERCEPT_MALLOPT_AND_MALLINFO
|
2012-06-25 17:58:29 +08:00
|
|
|
// We avoid including malloc.h for portability reasons.
|
|
|
|
// man mallinfo says the fields are "long", but the implementation uses int.
|
|
|
|
// It doesn't matter much -- we just need to make sure that the libc's mallinfo
|
|
|
|
// is not called.
|
|
|
|
struct fake_mallinfo {
|
|
|
|
int x[10];
|
|
|
|
};
|
|
|
|
|
|
|
|
INTERCEPTOR(struct fake_mallinfo, mallinfo, void) {
|
|
|
|
struct fake_mallinfo res;
|
2012-02-08 21:45:31 +08:00
|
|
|
REAL(memset)(&res, 0, sizeof(res));
|
2011-11-30 09:07:02 +08:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2012-02-02 18:39:40 +08:00
|
|
|
INTERCEPTOR(int, mallopt, int cmd, int value) {
|
2011-11-30 09:07:02 +08:00
|
|
|
return -1;
|
|
|
|
}
|
Recommit: Stop intercepting some malloc-related functions on FreeBSD and
macOS
Summary:
In https://bugs.freebsd.org/215125 I was notified that some configure
scripts attempt to test for the Linux-specific `mallinfo` and `mallopt`
functions by compiling and linking small programs which references the
functions, and observing whether that results in errors.
FreeBSD and macOS do not have the `mallinfo` and `mallopt` functions, so
normally these tests would fail, but when sanitizers are enabled, they
incorrectly succeed, because the sanitizers define interceptors for
these functions. This also applies to some other malloc-related
functions, such as `memalign`, `pvalloc` and `cfree`.
Fix this by not intercepting `mallinfo`, `mallopt`, `memalign`,
`pvalloc` and `cfree` for FreeBSD and macOS, in all sanitizers.
Also delete the non-functional `cfree` wrapper for Windows, to fix the
test cases on that platform.
Reviewers: emaste, kcc, rnk
Subscribers: timurrrr, eugenis, hans, joerg, llvm-commits, kubamracek
Differential Revision: https://reviews.llvm.org/D27654
llvm-svn: 293536
2017-01-31 03:06:13 +08:00
|
|
|
#endif // SANITIZER_INTERCEPT_MALLOPT_AND_MALLINFO
|
2011-11-30 09:07:02 +08:00
|
|
|
|
2012-06-25 17:58:29 +08:00
|
|
|
INTERCEPTOR(int, posix_memalign, void **memptr, uptr alignment, uptr size) {
|
2012-12-13 17:34:23 +08:00
|
|
|
GET_STACK_TRACE_MALLOC;
|
2012-03-21 19:32:46 +08:00
|
|
|
// Printf("posix_memalign: %zx %zu\n", alignment, size);
|
2011-11-30 09:07:02 +08:00
|
|
|
return asan_posix_memalign(memptr, alignment, size, &stack);
|
|
|
|
}
|
|
|
|
|
2012-06-25 17:58:29 +08:00
|
|
|
INTERCEPTOR(void*, valloc, uptr size) {
|
2012-12-13 17:34:23 +08:00
|
|
|
GET_STACK_TRACE_MALLOC;
|
2011-11-30 09:07:02 +08:00
|
|
|
return asan_valloc(size, &stack);
|
|
|
|
}
|
|
|
|
|
Recommit: Stop intercepting some malloc-related functions on FreeBSD and
macOS
Summary:
In https://bugs.freebsd.org/215125 I was notified that some configure
scripts attempt to test for the Linux-specific `mallinfo` and `mallopt`
functions by compiling and linking small programs which references the
functions, and observing whether that results in errors.
FreeBSD and macOS do not have the `mallinfo` and `mallopt` functions, so
normally these tests would fail, but when sanitizers are enabled, they
incorrectly succeed, because the sanitizers define interceptors for
these functions. This also applies to some other malloc-related
functions, such as `memalign`, `pvalloc` and `cfree`.
Fix this by not intercepting `mallinfo`, `mallopt`, `memalign`,
`pvalloc` and `cfree` for FreeBSD and macOS, in all sanitizers.
Also delete the non-functional `cfree` wrapper for Windows, to fix the
test cases on that platform.
Reviewers: emaste, kcc, rnk
Subscribers: timurrrr, eugenis, hans, joerg, llvm-commits, kubamracek
Differential Revision: https://reviews.llvm.org/D27654
llvm-svn: 293536
2017-01-31 03:06:13 +08:00
|
|
|
#if SANITIZER_INTERCEPT_PVALLOC
|
2012-06-25 17:58:29 +08:00
|
|
|
INTERCEPTOR(void*, pvalloc, uptr size) {
|
2012-12-13 17:34:23 +08:00
|
|
|
GET_STACK_TRACE_MALLOC;
|
2011-11-30 09:07:02 +08:00
|
|
|
return asan_pvalloc(size, &stack);
|
|
|
|
}
|
Recommit: Stop intercepting some malloc-related functions on FreeBSD and
macOS
Summary:
In https://bugs.freebsd.org/215125 I was notified that some configure
scripts attempt to test for the Linux-specific `mallinfo` and `mallopt`
functions by compiling and linking small programs which references the
functions, and observing whether that results in errors.
FreeBSD and macOS do not have the `mallinfo` and `mallopt` functions, so
normally these tests would fail, but when sanitizers are enabled, they
incorrectly succeed, because the sanitizers define interceptors for
these functions. This also applies to some other malloc-related
functions, such as `memalign`, `pvalloc` and `cfree`.
Fix this by not intercepting `mallinfo`, `mallopt`, `memalign`,
`pvalloc` and `cfree` for FreeBSD and macOS, in all sanitizers.
Also delete the non-functional `cfree` wrapper for Windows, to fix the
test cases on that platform.
Reviewers: emaste, kcc, rnk
Subscribers: timurrrr, eugenis, hans, joerg, llvm-commits, kubamracek
Differential Revision: https://reviews.llvm.org/D27654
llvm-svn: 293536
2017-01-31 03:06:13 +08:00
|
|
|
#endif // SANITIZER_INTERCEPT_PVALLOC
|
2011-12-02 05:40:52 +08:00
|
|
|
|
2012-12-20 19:54:21 +08:00
|
|
|
INTERCEPTOR(void, malloc_stats, void) {
|
2012-12-26 20:20:35 +08:00
|
|
|
__asan_print_accumulated_stats();
|
2012-12-20 19:54:21 +08:00
|
|
|
}
|
|
|
|
|
2014-07-17 20:48:45 +08:00
|
|
|
#if SANITIZER_ANDROID
|
|
|
|
// Format of __libc_malloc_dispatch has changed in Android L.
|
|
|
|
// While we are moving towards a solution that does not depend on bionic
|
|
|
|
// internals, here is something to support both K* and L releases.
|
|
|
|
struct MallocDebugK {
|
|
|
|
void *(*malloc)(uptr bytes);
|
|
|
|
void (*free)(void *mem);
|
|
|
|
void *(*calloc)(uptr n_elements, uptr elem_size);
|
|
|
|
void *(*realloc)(void *oldMem, uptr bytes);
|
|
|
|
void *(*memalign)(uptr alignment, uptr bytes);
|
|
|
|
uptr (*malloc_usable_size)(void *mem);
|
|
|
|
};
|
|
|
|
|
|
|
|
struct MallocDebugL {
|
|
|
|
void *(*calloc)(uptr n_elements, uptr elem_size);
|
|
|
|
void (*free)(void *mem);
|
|
|
|
fake_mallinfo (*mallinfo)(void);
|
|
|
|
void *(*malloc)(uptr bytes);
|
|
|
|
uptr (*malloc_usable_size)(void *mem);
|
|
|
|
void *(*memalign)(uptr alignment, uptr bytes);
|
|
|
|
int (*posix_memalign)(void **memptr, uptr alignment, uptr size);
|
|
|
|
void* (*pvalloc)(uptr size);
|
|
|
|
void *(*realloc)(void *oldMem, uptr bytes);
|
|
|
|
void* (*valloc)(uptr size);
|
|
|
|
};
|
|
|
|
|
|
|
|
ALIGNED(32) const MallocDebugK asan_malloc_dispatch_k = {
|
|
|
|
WRAP(malloc), WRAP(free), WRAP(calloc),
|
|
|
|
WRAP(realloc), WRAP(memalign), WRAP(malloc_usable_size)};
|
|
|
|
|
|
|
|
ALIGNED(32) const MallocDebugL asan_malloc_dispatch_l = {
|
|
|
|
WRAP(calloc), WRAP(free), WRAP(mallinfo),
|
|
|
|
WRAP(malloc), WRAP(malloc_usable_size), WRAP(memalign),
|
|
|
|
WRAP(posix_memalign), WRAP(pvalloc), WRAP(realloc),
|
|
|
|
WRAP(valloc)};
|
|
|
|
|
|
|
|
namespace __asan {
|
|
|
|
void ReplaceSystemMalloc() {
|
|
|
|
void **__libc_malloc_dispatch_p =
|
|
|
|
(void **)AsanDlSymNext("__libc_malloc_dispatch");
|
|
|
|
if (__libc_malloc_dispatch_p) {
|
|
|
|
// Decide on K vs L dispatch format by the presence of
|
|
|
|
// __libc_malloc_default_dispatch export in libc.
|
|
|
|
void *default_dispatch_p = AsanDlSymNext("__libc_malloc_default_dispatch");
|
|
|
|
if (default_dispatch_p)
|
|
|
|
*__libc_malloc_dispatch_p = (void *)&asan_malloc_dispatch_k;
|
|
|
|
else
|
|
|
|
*__libc_malloc_dispatch_p = (void *)&asan_malloc_dispatch_l;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // namespace __asan
|
|
|
|
|
|
|
|
#else // SANITIZER_ANDROID
|
|
|
|
|
|
|
|
namespace __asan {
|
|
|
|
void ReplaceSystemMalloc() {
|
|
|
|
}
|
|
|
|
} // namespace __asan
|
|
|
|
#endif // SANITIZER_ANDROID
|
|
|
|
|
2017-08-09 07:31:21 +08:00
|
|
|
#endif // SANITIZER_FREEBSD || SANITIZER_FUCHSIA || SANITIZER_LINUX ||
|
[Sanitizers] Basic sanitizer Solaris support (PR 33274)
Summary:
This is the first mostly working version of the Sanitizer port to 32-bit Solaris/x86.
It is currently based on Solaris 11.4 Beta.
This part was initially developed inside libsanitizer in the GCC tree and should apply to
both. Subsequent parts will address changes to clang, the compiler-rt build system
and testsuite.
I'm not yet sure what the right patch granularity is: if it's profitable to split the patch
up, I'd like to get guidance on how to do so.
Most of the changes are probably straightforward with a few exceptions:
* The Solaris syscall interface isn't stable, undocumented and can change within an
OS release. The stable interface is the libc interface, which I'm using here, if possible
using the internal _-prefixed names.
* While the patch primarily target 32-bit x86, I've left a few sparc changes in. They
cannot currently be used with clang due to a backend limitation, but have worked
fine inside the gcc tree.
* Some functions (e.g. largefile versions of functions like open64) only exist in 32-bit
Solaris, so I've introduced a separate SANITIZER_SOLARIS32 to check for that.
The patch (with the subsequent ones to be submitted shortly) was tested
on i386-pc-solaris2.11. Only a few failures remain, some of them analyzed, some
still TBD:
AddressSanitizer-i386-sunos :: TestCases/Posix/concurrent_overflow.cc
AddressSanitizer-i386-sunos :: TestCases/init-order-atexit.cc
AddressSanitizer-i386-sunos :: TestCases/log-path_test.cc
AddressSanitizer-i386-sunos :: TestCases/malloc-no-intercept.c
AddressSanitizer-i386-sunos-dynamic :: TestCases/Posix/concurrent_overflow.cc
AddressSanitizer-i386-sunos-dynamic :: TestCases/Posix/start-deactivated.cc
AddressSanitizer-i386-sunos-dynamic :: TestCases/default_options.cc
AddressSanitizer-i386-sunos-dynamic :: TestCases/init-order-atexit.cc
AddressSanitizer-i386-sunos-dynamic :: TestCases/log-path_test.cc
AddressSanitizer-i386-sunos-dynamic :: TestCases/malloc-no-intercept.c
SanitizerCommon-Unit :: ./Sanitizer-i386-Test/MemoryMappingLayout.DumpListOfModules
SanitizerCommon-Unit :: ./Sanitizer-i386-Test/SanitizerCommon.PthreadDestructorIterations
Maybe this is good enough the get the ball rolling.
Reviewers: kcc, alekseyshl
Reviewed By: alekseyshl
Subscribers: srhines, jyknight, kubamracek, krytarowski, fedor.sergeev, llvm-commits, #sanitizers
Tags: #sanitizers
Differential Revision: https://reviews.llvm.org/D40898
llvm-svn: 320740
2017-12-15 04:14:29 +08:00
|
|
|
// SANITIZER_NETBSD || SANITIZER_SOLARIS
|