Avoid crashes when system libraries use the purgeable zone allocator
This commit is contained in:
parent
71a93b8725
commit
3c2ba0dcbc
@ -1175,7 +1175,7 @@ je_valloc(size_t size)
|
|||||||
* to inconsistently reference libc's malloc(3)-compatible functions
|
* to inconsistently reference libc's malloc(3)-compatible functions
|
||||||
* (https://bugzilla.mozilla.org/show_bug.cgi?id=493541).
|
* (https://bugzilla.mozilla.org/show_bug.cgi?id=493541).
|
||||||
*
|
*
|
||||||
* These definitions interpose hooks in glibc. The functions are actually
|
* These definitions interpose hooks in glibc. The functions are actually
|
||||||
* passed an extra argument for the caller return address, which will be
|
* passed an extra argument for the caller return address, which will be
|
||||||
* ignored.
|
* ignored.
|
||||||
*/
|
*/
|
||||||
|
21
src/zone.c
21
src/zone.c
@ -3,6 +3,13 @@
|
|||||||
# error "This source file is for zones on Darwin (OS X)."
|
# error "This source file is for zones on Darwin (OS X)."
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The malloc_default_purgeable_zone function is only available on >= 10.6.
|
||||||
|
* We need to check whether it is present at runtime, thus the weak_import.
|
||||||
|
*/
|
||||||
|
extern malloc_zone_t *malloc_default_purgeable_zone(void)
|
||||||
|
JEMALLOC_ATTR(weak_import);
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
/* Data. */
|
/* Data. */
|
||||||
|
|
||||||
@ -207,6 +214,20 @@ register_zone(void)
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The default purgeable zone is created lazily by OSX's libc. It uses
|
||||||
|
* the default zone when it is created for "small" allocations
|
||||||
|
* (< 15 KiB), but assumes the default zone is a scalable_zone. This
|
||||||
|
* obviously fails when the default zone is the jemalloc zone, so
|
||||||
|
* malloc_default_purgeable_zone is called beforehand so that the
|
||||||
|
* default purgeable zone is created when the default zone is still
|
||||||
|
* a scalable_zone. As purgeable zones only exist on >= 10.6, we need
|
||||||
|
* to check for the existence of malloc_default_purgeable_zone() at
|
||||||
|
* run time.
|
||||||
|
*/
|
||||||
|
if (malloc_default_purgeable_zone != NULL)
|
||||||
|
malloc_default_purgeable_zone();
|
||||||
|
|
||||||
/* Register the custom zone. At this point it won't be the default. */
|
/* Register the custom zone. At this point it won't be the default. */
|
||||||
malloc_zone_register(&zone);
|
malloc_zone_register(&zone);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user