@@ -168,6 +168,33 @@ zone_force_unlock(malloc_zone_t *zone)
168
168
jemalloc_postfork_parent ();
169
169
}
170
170
171
+ static malloc_zone_t * get_default_zone ()
172
+ {
173
+ malloc_zone_t * * zones = NULL ;
174
+ unsigned int num_zones = 0 ;
175
+
176
+ /*
177
+ * On OSX 10.12, malloc_default_zone returns a special zone that is not
178
+ * present in the list of registered zones. That zone uses a "lite zone"
179
+ * if one is present (apparently enabled when malloc stack logging is
180
+ * enabled), or the first registered zone otherwise. In practice this
181
+ * means unless malloc stack logging is enabled, the first registered
182
+ * zone is the default.
183
+ * So get the list of zones to get the first one, instead of relying on
184
+ * malloc_default_zone.
185
+ */
186
+ if (KERN_SUCCESS != malloc_get_all_zones (0 , NULL , (vm_address_t * * ) & zones ,
187
+ & num_zones )) {
188
+ /* Reset the value in case the failure happened after it was set. */
189
+ num_zones = 0 ;
190
+ }
191
+
192
+ if (num_zones )
193
+ return zones [0 ];
194
+
195
+ return malloc_default_zone ();
196
+ }
197
+
171
198
JEMALLOC_ATTR (constructor )
172
199
void
173
200
register_zone (void )
@@ -177,7 +204,7 @@ register_zone(void)
177
204
* If something else replaced the system default zone allocator, don't
178
205
* register jemalloc's.
179
206
*/
180
- malloc_zone_t * default_zone = malloc_default_zone ();
207
+ malloc_zone_t * default_zone = get_default_zone ();
181
208
malloc_zone_t * purgeable_zone = NULL ;
182
209
if (!default_zone -> zone_name ||
183
210
strcmp (default_zone -> zone_name , "DefaultMallocZone" ) != 0 ) {
@@ -246,7 +273,6 @@ register_zone(void)
246
273
malloc_zone_register (& zone );
247
274
248
275
do {
249
- default_zone = malloc_default_zone ();
250
276
/*
251
277
* Unregister and reregister the default zone. On OSX >= 10.6,
252
278
* unregistering takes the last registered zone and places it
@@ -272,5 +298,7 @@ register_zone(void)
272
298
malloc_zone_unregister (purgeable_zone );
273
299
malloc_zone_register (purgeable_zone );
274
300
}
275
- } while (malloc_default_zone () != & zone );
301
+
302
+ default_zone = get_default_zone ();
303
+ } while (default_zone != & zone );
276
304
}
0 commit comments