+2015-01-07 Geoffrey Garen <ggaren@apple.com>
+
+ Make bmalloc work with ASan
+ https://bugs.webkit.org/show_bug.cgi?id=140194
+
+ Reviewed by Mark Lam.
+
+ * bmalloc/BPlatform.h: Added a way to detect Darwin OSes, since we need
+ an OS-specific API to test for loaded runtime libraries.
+
+ * bmalloc/Environment.cpp:
+ (bmalloc::isASanEnabled):
+ (bmalloc::Environment::computeIsBmallocEnabled): Disabled bmalloc if
+ ASan is enabled, since system malloc has the Asan hooks we need.
+
+ You could check for the ASan compile-time flag instead, but doing this
+ check at runtime prepares bmalloc for a world where it is a dynamic
+ library that might be loaded into projects it did not compile with.
+
2015-01-05 Geoffrey Garen <ggaren@apple.com>
Fix up bmalloc's PerThread for use on Linux
#endif
#define BPLATFORM(PLATFORM) (defined BPLATFORM_##PLATFORM && BPLATFORM_##PLATFORM)
+#define BOS(OS) (defined BOS_##OS && BOS_##OS)
#if ((defined(TARGET_OS_EMBEDDED) && TARGET_OS_EMBEDDED) \
|| (defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE) \
#define BPLATFORM_IOS 1
#endif
-#define BCOMPILER_SUPPORTS(COMPILER_FEATURE) (defined BCOMPILER_SUPPORTS_##COMPILER_FEATURE && BCOMPILER_SUPPORTS_##COMPILER_FEATURE)
-#define BCOMPILER_SUPPORTS_CXX_THREAD_LOCAL (defined(__has_feature) && __has_feature(cxx_thread_local))
+#ifdef __APPLE__
+#define BOS_DARWIN 1
+#endif
#endif // BPlatform_h
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#include "BPlatform.h"
#include "Environment.h"
#include <cstdlib>
#include <cstring>
+#if BOS(DARWIN)
+#include <mach-o/dyld.h>
+#endif
namespace bmalloc {
return true;
}
+static bool isASanEnabled()
+{
+#if BOS(DARWIN)
+ uint32_t imageCount = _dyld_image_count();
+ for (uint32_t i = 0; i < imageCount; ++i) {
+ if (strstr(_dyld_get_image_name(i), "/libclang_rt.asan_"))
+ return true;
+ }
+ return false;
+#else
+ return false;
+#endif
+}
+
Environment::Environment()
: m_isBmallocEnabled(computeIsBmallocEnabled())
{
return false;
if (isLibgmallocEnabled())
return false;
+ if (isASanEnabled())
+ return false;
return true;
}