2014-12-11 Geoffrey Garen <ggaren@apple.com>
+ bmalloc should support system memory analysis tools (part 2)
+ https://bugs.webkit.org/show_bug.cgi?id=139565
+
+ Reviewed by Mark Lam.
+
+ This patch actually queries the environment to see if memory analysis
+ tools have been enabled.
+
+ * bmalloc/Deallocator.cpp:
+ (bmalloc::Deallocator::scavenge): Don't process the object log if
+ we've disabled bmalloc because it will be full of invalid nullptrs.
+
+ * bmalloc/Environment.cpp:
+ (bmalloc::isMallocEnvironmentVariableSet): Test for the list of known
+ Malloc debugging flags. I also added a plain "Malloc" catch-all for
+ when you want to disable bmalloc without enabling any kind of funny
+ business.
+
+ It would be slightly nicer just to iterate the list of environment
+ variables and strstr them, but getenv is the more portable option,
+ and performance here doesn't really matter.
+
+ (bmalloc::isLibgmallocEnabled): Test for the libgmalloc insertion
+ environment variable.
+
+ (bmalloc::Environment::computeIsBmallocEnabled):
+
+2014-12-11 Geoffrey Garen <ggaren@apple.com>
+
Try to fix the iOS simulator build.
#include the declaration of malloc / free.
*/
#include "Environment.h"
+#include <cstdlib>
+#include <cstring>
namespace bmalloc {
+static bool isMallocEnvironmentVariableSet()
+{
+ const char* list[] = {
+ "Malloc",
+ "MallocLogFile",
+ "MallocGuardEdges",
+ "MallocDoNotProtectPrelude",
+ "MallocDoNotProtectPostlude",
+ "MallocStackLogging",
+ "MallocStackLoggingNoCompact",
+ "MallocStackLoggingDirectory",
+ "MallocScribble",
+ "MallocCheckHeapStart",
+ "MallocCheckHeapEach",
+ "MallocCheckHeapSleep",
+ "MallocCheckHeapAbort",
+ "MallocErrorAbort",
+ "MallocCorruptionAbort",
+ "MallocHelp"
+ };
+ size_t size = sizeof(list) / sizeof(const char*);
+
+ for (size_t i = 0; i < size; ++i) {
+ if (getenv(list[i]))
+ return true;
+ }
+
+ return false;
+}
+
+static bool isLibgmallocEnabled()
+{
+ char* variable = getenv("DYLD_INSERT_LIBRARIES");
+ if (!variable)
+ return false;
+ if (!strstr(variable, "libgmalloc"))
+ return false;
+ return true;
+}
+
Environment::Environment()
: m_isBmallocEnabled(computeIsBmallocEnabled())
{
bool Environment::computeIsBmallocEnabled()
{
+ if (isMallocEnvironmentVariableSet())
+ return false;
+ if (isLibgmallocEnabled())
+ return false;
return true;
}