mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 13:51:41 +00:00
Bug 838150 - Add ASan and Valgrind annotations to JS LifoAlloc. r=bhackett
This commit is contained in:
parent
ea7eaf690e
commit
27cd3a543c
@ -11,6 +11,11 @@
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/DebugOnly.h"
|
||||
#include "mozilla/GuardObjects.h"
|
||||
#include "mozilla/ASan.h"
|
||||
|
||||
#if defined(MOZ_VALGRIND)
|
||||
#include "valgrind/memcheck.h"
|
||||
#endif
|
||||
|
||||
/*
|
||||
* This data structure supports stacky LIFO allocation (mark/release and
|
||||
@ -66,7 +71,9 @@ class BumpChunk
|
||||
void setBump(void *ptr) {
|
||||
JS_ASSERT(bumpBase() <= ptr);
|
||||
JS_ASSERT(ptr <= limit);
|
||||
mozilla::DebugOnly<char *> prevBump = bump;
|
||||
#if defined(DEBUG) || defined(MOZ_ASAN) || defined(MOZ_VALGRIND)
|
||||
char* prevBump = bump;
|
||||
#endif
|
||||
bump = static_cast<char *>(ptr);
|
||||
#ifdef DEBUG
|
||||
JS_ASSERT(contains(prevBump));
|
||||
@ -75,6 +82,19 @@ class BumpChunk
|
||||
if (prevBump > bump)
|
||||
memset(bump, 0xcd, prevBump - bump);
|
||||
#endif
|
||||
|
||||
/* Poison/Unpoison memory that we just free'd/allocated */
|
||||
#if defined(MOZ_ASAN)
|
||||
if (prevBump > bump)
|
||||
ASAN_POISON_MEMORY_REGION(bump, prevBump - bump);
|
||||
else if (bump > prevBump)
|
||||
ASAN_UNPOISON_MEMORY_REGION(prevBump, bump - prevBump);
|
||||
#elif defined(MOZ_VALGRIND)
|
||||
if (prevBump > bump)
|
||||
VALGRIND_MAKE_MEM_NOACCESS(bump, prevBump - bump);
|
||||
else if (bump > prevBump)
|
||||
VALGRIND_MAKE_MEM_UNDEFINED(prevBump, bump - prevBump);
|
||||
#endif
|
||||
}
|
||||
|
||||
public:
|
||||
|
@ -24,21 +24,9 @@
|
||||
#endif
|
||||
|
||||
#include "mozilla/StandardInteger.h"
|
||||
#include "mozilla/ASan.h"
|
||||
|
||||
#if defined(MOZ_ASAN)
|
||||
// XXX These come from sanitizer/asan_interface.h but that header doesn't seem
|
||||
// to be installed by default?
|
||||
extern "C" {
|
||||
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 ASAN_POISON_MEMORY_REGION(addr, size) \
|
||||
__asan_poison_memory_region((addr), (size))
|
||||
#define ASAN_UNPOISON_MEMORY_REGION(addr, size) \
|
||||
__asan_unpoison_memory_region((addr), (size))
|
||||
}
|
||||
#elif defined(MOZ_VALGRIND)
|
||||
#if defined(MOZ_VALGRIND)
|
||||
#include "valgrind/memcheck.h"
|
||||
#endif
|
||||
|
||||
|
27
mfbt/ASan.h
Normal file
27
mfbt/ASan.h
Normal file
@ -0,0 +1,27 @@
|
||||
/* -*- 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 ASan (AddressSanitizer) specific functions that are normally
|
||||
* provided through the sanitizer/asan_interface.h header installed by ASan.
|
||||
*/
|
||||
|
||||
#ifndef mozilla_ASan_h_
|
||||
#define mozilla_ASan_h_
|
||||
|
||||
#ifdef MOZ_ASAN
|
||||
extern "C" {
|
||||
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 ASAN_POISON_MEMORY_REGION(addr, size) \
|
||||
__asan_poison_memory_region((addr), (size))
|
||||
#define ASAN_UNPOISON_MEMORY_REGION(addr, size) \
|
||||
__asan_unpoison_memory_region((addr), (size))
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* mozilla_ASan_h_ */
|
@ -9,6 +9,7 @@
|
||||
EXPORTS_NAMESPACES += mozilla
|
||||
|
||||
EXPORTS_mozilla += \
|
||||
ASan.h \
|
||||
Assertions.h \
|
||||
Attributes.h \
|
||||
BloomFilter.h \
|
||||
|
Loading…
Reference in New Issue
Block a user