summaryrefslogtreecommitdiff
path: root/mfbt/MemoryChecking.h
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@baserock.org>2013-12-11 22:24:18 +0000
committer <>2014-07-24 09:30:59 +0000
commit59e2936f588aa945e8dcd6c737523c299067e9d0 (patch)
tree97e74980cc54baa19de5faa11f5a50a0121a48ea /mfbt/MemoryChecking.h
downloadmozjs24-59e2936f588aa945e8dcd6c737523c299067e9d0.tar.gz
Imported from /home/lorry/working-area/delta_mozilla_mozjs24/mozjs-24.2.0.tar.bz2.HEADmozjs-24.2.0master
Diffstat (limited to 'mfbt/MemoryChecking.h')
-rw-r--r--mfbt/MemoryChecking.h71
1 files changed, 71 insertions, 0 deletions
diff --git a/mfbt/MemoryChecking.h b/mfbt/MemoryChecking.h
new file mode 100644
index 0000000..3287e57
--- /dev/null
+++ b/mfbt/MemoryChecking.h
@@ -0,0 +1,71 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* 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/. */
+
+/*
+ * 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"
+#endif
+
+#if defined(MOZ_ASAN) || defined(MOZ_VALGRIND)
+#define MOZ_HAVE_MEM_CHECKS 1
+#endif
+
+#if defined(MOZ_ASAN)
+#include <stddef.h>
+
+extern "C" {
+ /* These definitions are usually provided through the
+ * sanitizer/asan_interface.h header installed by ASan.
+ */
+ void __asan_poison_memory_region(void const volatile *addr, size_t size)
+ __attribute__((visibility("default")));
+ void __asan_unpoison_memory_region(void const volatile *addr, size_t size)
+ __attribute__((visibility("default")));
+
+#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) \
+ 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
+
+#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
+
+#endif /* mozilla_MemoryChecking_h_ */