Created
May 17, 2017 16:37
-
-
Save nicksieger/67a931c649f1d816e7c415de35dade7c to your computer and use it in GitHub Desktop.
Patches Mongo's third party copy of gperftools libc_override_osx.h for Sierra
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/third_party/gperftools-2.0/src/libc_override_osx.h b/src/third_party/gperftools-2.0/src/libc_override_osx.h | |
index 78a0ef2f95..13ec5b8d66 100644 | |
--- a/src/third_party/gperftools-2.0/src/libc_override_osx.h | |
+++ b/src/third_party/gperftools-2.0/src/libc_override_osx.h | |
@@ -205,6 +205,33 @@ extern "C" { | |
size_t malloc_usable_size(void* p) { return tc_malloc_size(p); } | |
} // extern "C" | |
+static malloc_zone_t *get_default_zone() | |
+{ | |
+ malloc_zone_t **zones = NULL; | |
+ unsigned int num_zones = 0; | |
+ | |
+ /* | |
+ * On OSX 10.12, malloc_default_zone returns a special zone that is not | |
+ * present in the list of registered zones. That zone uses a "lite zone" | |
+ * if one is present (apparently enabled when malloc stack logging is | |
+ * enabled), or the first registered zone otherwise. In practice this | |
+ * means unless malloc stack logging is enabled, the first registered | |
+ * zone is the default. | |
+ * So get the list of zones to get the first one, instead of relying on | |
+ * malloc_default_zone. | |
+ */ | |
+ if (KERN_SUCCESS != malloc_get_all_zones(0, NULL, (vm_address_t**) &zones, | |
+ &num_zones)) { | |
+ /* Reset the value in case the failure happened after it was set. */ | |
+ num_zones = 0; | |
+ } | |
+ | |
+ if (num_zones) | |
+ return zones[0]; | |
+ | |
+ return malloc_default_zone(); | |
+} | |
+ | |
static void ReplaceSystemAlloc() { | |
static malloc_introspection_t tcmalloc_introspection; | |
memset(&tcmalloc_introspection, 0, sizeof(tcmalloc_introspection)); | |
@@ -267,7 +294,7 @@ static void ReplaceSystemAlloc() { | |
// zone. The default zone is then re-registered to ensure that | |
// allocations made from it earlier will be handled correctly. | |
// Things are not guaranteed to work that way, but it's how they work now. | |
- malloc_zone_t *default_zone = malloc_default_zone(); | |
+ malloc_zone_t *default_zone = get_default_zone(); | |
malloc_zone_unregister(default_zone); | |
malloc_zone_register(default_zone); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Cribbed the code for
get_default_zone
from jemalloc/jemalloc#427