2013-07-24 11:41:39 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2013-02-15 03:50:11 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
/*
|
2014-06-13 10:34:08 +04:00
|
|
|
* Provides a common interface to the ASan (AddressSanitizer) and Valgrind
|
2013-02-15 03:50:11 +04:00
|
|
|
* functions used to mark memory in certain ways. In detail, the following
|
|
|
|
* three macros are provided:
|
|
|
|
*
|
|
|
|
* MOZ_MAKE_MEM_NOACCESS - Mark memory as unsafe to access (e.g. freed)
|
|
|
|
* MOZ_MAKE_MEM_UNDEFINED - Mark memory as accessible, with content undefined
|
|
|
|
* MOZ_MAKE_MEM_DEFINED - Mark memory as accessible, with content defined
|
|
|
|
*
|
|
|
|
* With Valgrind in use, these directly map to the three respective Valgrind
|
|
|
|
* macros. With ASan in use, the NOACCESS macro maps to poisoning the memory,
|
|
|
|
* while the UNDEFINED/DEFINED macros unpoison memory.
|
|
|
|
*
|
|
|
|
* With no memory checker available, all macros expand to the empty statement.
|
|
|
|
*/
|
|
|
|
|
2013-07-24 11:41:39 +04:00
|
|
|
#ifndef mozilla_MemoryChecking_h
|
|
|
|
#define mozilla_MemoryChecking_h
|
2013-02-15 03:50:11 +04:00
|
|
|
|
|
|
|
#if defined(MOZ_VALGRIND)
|
|
|
|
# include "valgrind/memcheck.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(MOZ_ASAN) || defined(MOZ_VALGRIND)
|
|
|
|
# define MOZ_HAVE_MEM_CHECKS 1
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(MOZ_ASAN)
|
|
|
|
# include <stddef.h>
|
|
|
|
|
2014-10-21 15:00:54 +04:00
|
|
|
# include "mozilla/Attributes.h"
|
2014-07-09 06:58:26 +04:00
|
|
|
# include "mozilla/Types.h"
|
|
|
|
|
2014-10-10 18:33:16 +04:00
|
|
|
# ifdef _MSC_VER
|
|
|
|
// In clang-cl based ASAN, we link against the memory poisoning functions
|
|
|
|
// statically.
|
|
|
|
# define MOZ_ASAN_VISIBILITY
|
|
|
|
# else
|
|
|
|
# define MOZ_ASAN_VISIBILITY MOZ_EXPORT
|
|
|
|
# endif
|
|
|
|
|
2013-02-15 03:50:11 +04:00
|
|
|
extern "C" {
|
2014-06-13 10:34:08 +04:00
|
|
|
/* These definitions are usually provided through the
|
|
|
|
* sanitizer/asan_interface.h header installed by ASan.
|
|
|
|
*/
|
2014-07-23 07:54:41 +04:00
|
|
|
void MOZ_ASAN_VISIBILITY __asan_poison_memory_region(void const volatile* addr,
|
|
|
|
size_t size);
|
2014-10-10 18:33:16 +04:00
|
|
|
void MOZ_ASAN_VISIBILITY
|
2014-07-23 07:54:41 +04:00
|
|
|
__asan_unpoison_memory_region(void const volatile* addr, size_t size);
|
2013-02-15 03:50:11 +04:00
|
|
|
|
|
|
|
# define MOZ_MAKE_MEM_NOACCESS(addr, size) \
|
|
|
|
__asan_poison_memory_region((addr), (size))
|
|
|
|
|
|
|
|
# define MOZ_MAKE_MEM_UNDEFINED(addr, size) \
|
|
|
|
__asan_unpoison_memory_region((addr), (size))
|
|
|
|
|
|
|
|
# define MOZ_MAKE_MEM_DEFINED(addr, size) \
|
|
|
|
__asan_unpoison_memory_region((addr), (size))
|
2014-10-21 15:00:54 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* These definitions are usually provided through the
|
|
|
|
* sanitizer/lsan_interface.h header installed by LSan.
|
|
|
|
*/
|
|
|
|
void MOZ_EXPORT __lsan_ignore_object(const void* p);
|
2013-02-15 03:50:11 +04:00
|
|
|
}
|
2014-09-12 01:21:46 +04:00
|
|
|
#elif defined(MOZ_MSAN)
|
|
|
|
# include <stddef.h>
|
|
|
|
|
|
|
|
# include "mozilla/Types.h"
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
/* These definitions are usually provided through the
|
|
|
|
* sanitizer/msan_interface.h header installed by MSan.
|
|
|
|
*/
|
|
|
|
void MOZ_EXPORT __msan_poison(void const volatile* addr, size_t size);
|
|
|
|
void MOZ_EXPORT __msan_unpoison(void const volatile* addr, size_t size);
|
|
|
|
|
|
|
|
# define MOZ_MAKE_MEM_NOACCESS(addr, size) __msan_poison((addr), (size))
|
|
|
|
|
|
|
|
# define MOZ_MAKE_MEM_UNDEFINED(addr, size) __msan_poison((addr), (size))
|
|
|
|
|
|
|
|
# define MOZ_MAKE_MEM_DEFINED(addr, size) __msan_unpoison((addr), (size))
|
|
|
|
}
|
2013-02-15 03:50:11 +04:00
|
|
|
#elif defined(MOZ_VALGRIND)
|
|
|
|
# define MOZ_MAKE_MEM_NOACCESS(addr, size) \
|
|
|
|
VALGRIND_MAKE_MEM_NOACCESS((addr), (size))
|
|
|
|
|
|
|
|
# define MOZ_MAKE_MEM_UNDEFINED(addr, size) \
|
|
|
|
VALGRIND_MAKE_MEM_UNDEFINED((addr), (size))
|
|
|
|
|
|
|
|
# define MOZ_MAKE_MEM_DEFINED(addr, size) \
|
|
|
|
VALGRIND_MAKE_MEM_DEFINED((addr), (size))
|
|
|
|
#else
|
|
|
|
|
2014-07-11 06:10:17 +04:00
|
|
|
# define MOZ_MAKE_MEM_NOACCESS(addr, size) \
|
|
|
|
do { \
|
|
|
|
} while (0)
|
|
|
|
# define MOZ_MAKE_MEM_UNDEFINED(addr, size) \
|
|
|
|
do { \
|
|
|
|
} while (0)
|
|
|
|
# define MOZ_MAKE_MEM_DEFINED(addr, size) \
|
|
|
|
do { \
|
|
|
|
} while (0)
|
2013-02-15 03:50:11 +04:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2014-10-21 15:00:54 +04:00
|
|
|
/*
|
|
|
|
* MOZ_LSAN_INTENTIONAL_LEAK(X) is a macro to tell LeakSanitizer that X
|
|
|
|
* points to a value that will intentionally never be deallocated during
|
|
|
|
* the execution of the process.
|
|
|
|
*
|
|
|
|
* Additional uses of this macro should be reviewed by people
|
|
|
|
* conversant in leak-checking and/or MFBT peers.
|
|
|
|
*/
|
|
|
|
#if defined(MOZ_ASAN)
|
|
|
|
# define MOZ_LSAN_INTENTIONALLY_LEAK_OBJECT(X) __lsan_ignore_object(X)
|
|
|
|
#else
|
|
|
|
# define MOZ_LSAN_INTENTIONALLY_LEAK_OBJECT(X) /* nothing */
|
|
|
|
#endif // defined(MOZ_ASAN)
|
|
|
|
|
2013-07-24 11:41:39 +04:00
|
|
|
#endif /* mozilla_MemoryChecking_h */
|