gecko-dev/mozglue
Mike Hommey 352bb98f8e Bug 1884054 - Always define a rust global allocator. r=emilio
The global allocator we define for Rust code directs all Rust
allocations to the malloc family of functions. Practically speaking,
it's a no-op on Unix systems (the default global allocator would
do the same thing except for tiny details about alignment on some
platforms), but it makes a big difference on Windows, where the Rust
default global allocator uses the HeapAlloc family of functions.

Well, in practice, it doesn't make a huge difference, because we wrap
those functions to fall back to the malloc family of functions. But
it does make a difference in how allocations with large alignment are
handled (because it does its own alignment on top of HeapAlloc).

We're about to stop wrapping the HeapAlloc family of functions, because
it's causing other problems with memory that might have been
HeapAlloc'ated from system libraries, which a wrapped HeapFree can't
handle without overhead.

But, we're only currently defining the Rust global allocator when
mozjemalloc is enabled, meaning removing the wrapping gets us back to
Rust using HeapAlloc/HeapFree on those builds. Unfortunately, that
exchanges of ownership between C/C++ and Rust can lead to allocator
mismatch (and subsequent heap corruption).

One specific case where this causes problems is ASan builds, which
disable mozjemalloc specifically to enable the ASan allocator.

So we need to always define a Rust global allocator that uses the malloc
family of functions, whether or not mozjemalloc is enabled.

Unfortunately, the current code also relies on _aligned_malloc being
redirected to mozjemalloc, so we also need to adjust it to call
_aligned_free to free the corresponding memory on builds where
mozjemalloc is not enabled.

Differential Revision: https://phabricator.services.mozilla.com/D205787
2024-03-28 04:02:02 +00:00
..
android Bug 1874348 - Extra cleanup after bug 1694481 r=firefox-build-system-reviewers,ahochheiden 2024-01-15 22:24:56 +00:00
baseprofiler Bug 1884213 - Part 4: Convert Text and Tracing markers to use BaseMarkerType so they gain ETW support. r=mstange,profiler-reviewers 2024-03-11 20:13:57 +00:00
build Backed out 16 changesets (bug 1770944) as req by asuth. 2024-02-23 21:11:08 +02:00
interposers Bug 1874346 - Always add mozglue/linker to includes on MOZ_LINKER builds. r=firefox-build-system-reviewers,ahochheiden 2024-01-15 21:16:21 +00:00
linker Bug 1879433 - Scoped.h use removed from mozglue. r=glandium 2024-02-13 17:18:59 +00:00
misc Bug 1872920 - Change how we notify the main process when we intercept a crash via WER r=yjuglaret,bobowen 2024-02-21 17:56:31 +00:00
static Bug 1884054 - Always define a rust global allocator. r=emilio 2024-03-28 04:02:02 +00:00
tests Bug 1751781 - Force the old definition of NAN in the Windows SDK. r=ahochheiden 2024-02-28 03:50:07 +00:00
moz.build Bug 1874348 - Extra cleanup after bug 1694481 r=firefox-build-system-reviewers,ahochheiden 2024-01-15 22:24:56 +00:00