Skip to content

Commit 41fb059

Browse files
committed
[compiler-rt] Change GetMaxUserVirtualAddress to invoke syscall
LSan was recently refactored to call GetMaxUserVirtualAddress for diagnostic purposes. This leads to failures for some of our downstream tests which only run with lsan. This occurs because GetMaxUserVirtualAddress depends on setting up shadow via a call to __sanitizer_shadow_bounds, but shadow bounds aren't set for standalone lsan because it doesn't use shadow. This updates the function to invoke the same syscall used by __sanitizer_shadow_bounds calls for getting the memory limit. Ideally this function would only be called once since we only need to get the bounds once. More context in https://fxbug.dev/437346226.
1 parent 04a44fe commit 41fb059

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

compiler-rt/lib/asan/asan_fuchsia.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,9 @@ void EarlySanitizerInit() {}
3232

3333
namespace __asan {
3434

35-
// The system already set up the shadow memory for us.
36-
// __sanitizer::GetMaxUserVirtualAddress has already been called by
37-
// AsanInitInternal->InitializeHighMemEnd (asan_rtl.cpp).
38-
// Just do some additional sanity checks here.
3935
void InitializeShadowMemory() {
36+
InitShadowBounds();
37+
4038
if (Verbosity())
4139
PrintAddressSpaceLayout();
4240

compiler-rt/lib/sanitizer_common/sanitizer_fuchsia.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,20 @@ sanitizer_shadow_bounds_t ShadowBounds;
119119

120120
void InitShadowBounds() { ShadowBounds = __sanitizer_shadow_bounds(); }
121121

122+
// TODO(leonardchan): It's not immediately clear from a user perspective if
123+
// `GetMaxUserVirtualAddress` should be called exatly once on runtime startup
124+
// or can be called multiple times. Currently it looks like most instances of
125+
// `GetMaxUserVirtualAddress` are meant to be called once, but if someone
126+
// decides to call this multiple times in the future, we should have a separate
127+
// function that's ok to call multiple times. Ideally we would just invoke this
128+
// syscall once. Also for Fuchsia, this syscall technically gets invoked twice
129+
// since `__sanitizer_shadow_bounds` also invokes this syscall under the hood.
122130
uptr GetMaxUserVirtualAddress() {
123-
InitShadowBounds();
124-
return ShadowBounds.memory_limit - 1;
131+
zx_info_vmar_t info;
132+
zx_status_t status = _zx_object_get_info(
133+
_zircon_vmar_root_self(), ZX_INFO_VMAR, &info, sizeof(info), NULL, NULL);
134+
CHECK_EQ(status, ZX_OK);
135+
return info.base + info.len - 1;
125136
}
126137

127138
uptr GetMaxVirtualAddress() { return GetMaxUserVirtualAddress(); }

0 commit comments

Comments
 (0)