author tbirdbld
Fri, 19 Sep 2014 04:09:42 -0400
changeset 216797 d179d51ba70c0d138332c2355703a262a413a226
parent 214333 91d7659bb35145e10ff737753688e0972c1a79b5
child 217427 1b7d7dcf71e23f6ed68f10a72416f7dc5e58a6c2
permissions -rw-r--r--
Added THUNDERBIRD_33_0b1_RELEASE THUNDERBIRD_33_0b1_BUILD1 tag(s) for changeset 73fcc8d4510c. DONTBUILD CLOSED TREE a=release

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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 */

 * Provides a common interface to the ASan (AddressSanitizer) and Valgrind
 * 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.

#ifndef mozilla_MemoryChecking_h
#define mozilla_MemoryChecking_h

#if defined(MOZ_VALGRIND)
#include "valgrind/memcheck.h"

#if defined(MOZ_ASAN) || defined(MOZ_VALGRIND)

#if defined(MOZ_ASAN)
#include <stddef.h>

#include "mozilla/Types.h"

extern "C" {
/* These definitions are usually provided through the
 * sanitizer/asan_interface.h header installed by ASan.
void MOZ_EXPORT __asan_poison_memory_region(void const volatile *addr, size_t size);
void MOZ_EXPORT __asan_unpoison_memory_region(void const volatile *addr, size_t size);

#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))
#elif defined(MOZ_VALGRIND)
#define MOZ_MAKE_MEM_NOACCESS(addr, size) \

#define MOZ_MAKE_MEM_UNDEFINED(addr, size) \

#define MOZ_MAKE_MEM_DEFINED(addr, size) \

#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)


#endif /* mozilla_MemoryChecking_h */