source: trunk/dports/devel/jemalloc/files/0002-Change-how-the-default-zone-is-found.patch

Last change on this file was 152980, checked in by larryv@…, 3 years ago

jemalloc: Fix malloc zone registration on Sierra

Closes: #52238

File size: 2.5 KB
  • src/zone.c

    From 19c9a3e828ed46f1576521c264640e60bd0cb01f Mon Sep 17 00:00:00 2001
    From: Mike Hommey <mh@glandium.org>
    Date: Fri, 8 Jul 2016 13:35:35 +0900
    Subject: [PATCH 2/2] Change how the default zone is found
    
    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.
    ---
     src/zone.c | 31 +++++++++++++++++++++++++++++--
     1 file changed, 29 insertions(+), 2 deletions(-)
    
    diff --git a/src/zone.c b/src/zone.c
    index 9432f45..9238161 100644
    a b zone_force_unlock(malloc_zone_t *zone) 
    168168                jemalloc_postfork_parent();
    169169}
    170170
     171static 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
    171198JEMALLOC_ATTR(constructor)
    172199void
    173200register_zone(void)
    register_zone(void) 
    177204         * If something else replaced the system default zone allocator, don't
    178205         * register jemalloc's.
    179206         */
    180         malloc_zone_t *default_zone = malloc_default_zone();
     207        malloc_zone_t *default_zone = get_default_zone();
    181208        malloc_zone_t *purgeable_zone = NULL;
    182209        if (!default_zone->zone_name ||
    183210            strcmp(default_zone->zone_name, "DefaultMallocZone") != 0) {
    register_zone(void) 
    272299                        malloc_zone_register(purgeable_zone);
    273300                }
    274301
    275                 default_zone = malloc_default_zone();
     302                default_zone = get_default_zone();
    276303        } while (default_zone != &zone);
    277304}
Note: See TracBrowser for help on using the repository browser.