xref: /llvm-project/compiler-rt/lib/asan/asan_fake_stack.cpp (revision 5b7dfa968fa49b51c850000350daf835b8652b3d)
1217222abSNico Weber //===-- asan_fake_stack.cpp -----------------------------------------------===//
2217222abSNico Weber //
3217222abSNico Weber // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4217222abSNico Weber // See https://llvm.org/LICENSE.txt for license information.
5217222abSNico Weber // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6217222abSNico Weber //
7217222abSNico Weber //===----------------------------------------------------------------------===//
8217222abSNico Weber //
9217222abSNico Weber // This file is a part of AddressSanitizer, an address sanity checker.
10217222abSNico Weber //
11217222abSNico Weber // FakeStack is used to detect use-after-return bugs.
12217222abSNico Weber //===----------------------------------------------------------------------===//
13217222abSNico Weber 
14217222abSNico Weber #include "asan_allocator.h"
15217222abSNico Weber #include "asan_poisoning.h"
16217222abSNico Weber #include "asan_thread.h"
17217222abSNico Weber 
18217222abSNico Weber namespace __asan {
19217222abSNico Weber 
20217222abSNico Weber static const u64 kMagic1 = kAsanStackAfterReturnMagic;
21217222abSNico Weber static const u64 kMagic2 = (kMagic1 << 8) | kMagic1;
22217222abSNico Weber static const u64 kMagic4 = (kMagic2 << 16) | kMagic2;
23217222abSNico Weber static const u64 kMagic8 = (kMagic4 << 32) | kMagic4;
24217222abSNico Weber 
25217222abSNico Weber static const u64 kAllocaRedzoneSize = 32UL;
26217222abSNico Weber static const u64 kAllocaRedzoneMask = 31UL;
27217222abSNico Weber 
28217222abSNico Weber // For small size classes inline PoisonShadow for better performance.
SetShadow(uptr ptr,uptr size,uptr class_id,u64 magic)29217222abSNico Weber ALWAYS_INLINE void SetShadow(uptr ptr, uptr size, uptr class_id, u64 magic) {
30217222abSNico Weber   u64 *shadow = reinterpret_cast<u64*>(MemToShadow(ptr));
31ad56941aSKirill Stoimenov   if (ASAN_SHADOW_SCALE == 3 && class_id <= 6) {
32ad56941aSKirill Stoimenov     // This code expects ASAN_SHADOW_SCALE=3.
33217222abSNico Weber     for (uptr i = 0; i < (((uptr)1) << class_id); i++) {
34217222abSNico Weber       shadow[i] = magic;
35217222abSNico Weber       // Make sure this does not become memset.
36217222abSNico Weber       SanitizerBreakOptimization(nullptr);
37217222abSNico Weber     }
38217222abSNico Weber   } else {
39217222abSNico Weber     // The size class is too big, it's cheaper to poison only size bytes.
40217222abSNico Weber     PoisonShadow(ptr, size, static_cast<u8>(magic));
41217222abSNico Weber   }
42217222abSNico Weber }
43217222abSNico Weber 
Create(uptr stack_size_log)44217222abSNico Weber FakeStack *FakeStack::Create(uptr stack_size_log) {
45217222abSNico Weber   static uptr kMinStackSizeLog = 16;
46217222abSNico Weber   static uptr kMaxStackSizeLog = FIRST_32_SECOND_64(24, 28);
47217222abSNico Weber   if (stack_size_log < kMinStackSizeLog)
48217222abSNico Weber     stack_size_log = kMinStackSizeLog;
49217222abSNico Weber   if (stack_size_log > kMaxStackSizeLog)
50217222abSNico Weber     stack_size_log = kMaxStackSizeLog;
51217222abSNico Weber   uptr size = RequiredSize(stack_size_log);
52217222abSNico Weber   FakeStack *res = reinterpret_cast<FakeStack *>(
53217222abSNico Weber       flags()->uar_noreserve ? MmapNoReserveOrDie(size, "FakeStack")
54217222abSNico Weber                              : MmapOrDie(size, "FakeStack"));
55217222abSNico Weber   res->stack_size_log_ = stack_size_log;
56217222abSNico Weber   u8 *p = reinterpret_cast<u8 *>(res);
5713a442caSMartin Liska   VReport(1,
5813a442caSMartin Liska           "T%d: FakeStack created: %p -- %p stack_size_log: %zd; "
59217222abSNico Weber           "mmapped %zdK, noreserve=%d \n",
6013a442caSMartin Liska           GetCurrentTidOrInvalid(), (void *)p,
6113a442caSMartin Liska           (void *)(p + FakeStack::RequiredSize(stack_size_log)), stack_size_log,
62217222abSNico Weber           size >> 10, flags()->uar_noreserve);
63217222abSNico Weber   return res;
64217222abSNico Weber }
65217222abSNico Weber 
Destroy(int tid)66217222abSNico Weber void FakeStack::Destroy(int tid) {
67217222abSNico Weber   PoisonAll(0);
68217222abSNico Weber   if (Verbosity() >= 2) {
69e0dadf3dSVitaly Buka     InternalScopedString str;
70217222abSNico Weber     for (uptr class_id = 0; class_id < kNumberOfSizeClasses; class_id++)
71*5b7dfa96SVitaly Buka       str.AppendF("%zd: %zd/%zd; ", class_id, hint_position_[class_id],
72217222abSNico Weber                   NumberOfFrames(stack_size_log(), class_id));
73217222abSNico Weber     Report("T%d: FakeStack destroyed: %s\n", tid, str.data());
74217222abSNico Weber   }
75217222abSNico Weber   uptr size = RequiredSize(stack_size_log_);
76217222abSNico Weber   FlushUnneededASanShadowMemory(reinterpret_cast<uptr>(this), size);
77217222abSNico Weber   UnmapOrDie(this, size);
78217222abSNico Weber }
79217222abSNico Weber 
PoisonAll(u8 magic)80217222abSNico Weber void FakeStack::PoisonAll(u8 magic) {
81217222abSNico Weber   PoisonShadow(reinterpret_cast<uptr>(this), RequiredSize(stack_size_log()),
82217222abSNico Weber                magic);
83217222abSNico Weber }
84217222abSNico Weber 
85217222abSNico Weber #if !defined(_MSC_VER) || defined(__clang__)
86217222abSNico Weber ALWAYS_INLINE USED
87217222abSNico Weber #endif
Allocate(uptr stack_size_log,uptr class_id,uptr real_stack)88217222abSNico Weber FakeFrame *FakeStack::Allocate(uptr stack_size_log, uptr class_id,
89217222abSNico Weber                                uptr real_stack) {
90217222abSNico Weber   CHECK_LT(class_id, kNumberOfSizeClasses);
91217222abSNico Weber   if (needs_gc_)
92217222abSNico Weber     GC(real_stack);
93217222abSNico Weber   uptr &hint_position = hint_position_[class_id];
94217222abSNico Weber   const int num_iter = NumberOfFrames(stack_size_log, class_id);
95217222abSNico Weber   u8 *flags = GetFlags(stack_size_log, class_id);
96217222abSNico Weber   for (int i = 0; i < num_iter; i++) {
97217222abSNico Weber     uptr pos = ModuloNumberOfFrames(stack_size_log, class_id, hint_position++);
98217222abSNico Weber     // This part is tricky. On one hand, checking and setting flags[pos]
99217222abSNico Weber     // should be atomic to ensure async-signal safety. But on the other hand,
100217222abSNico Weber     // if the signal arrives between checking and setting flags[pos], the
101217222abSNico Weber     // signal handler's fake stack will start from a different hint_position
102217222abSNico Weber     // and so will not touch this particular byte. So, it is safe to do this
103217222abSNico Weber     // with regular non-atomic load and store (at least I was not able to make
104217222abSNico Weber     // this code crash).
105217222abSNico Weber     if (flags[pos]) continue;
106217222abSNico Weber     flags[pos] = 1;
107217222abSNico Weber     FakeFrame *res = reinterpret_cast<FakeFrame *>(
108217222abSNico Weber         GetFrame(stack_size_log, class_id, pos));
109217222abSNico Weber     res->real_stack = real_stack;
110217222abSNico Weber     *SavedFlagPtr(reinterpret_cast<uptr>(res), class_id) = &flags[pos];
111217222abSNico Weber     return res;
112217222abSNico Weber   }
113217222abSNico Weber   return nullptr; // We are out of fake stack.
114217222abSNico Weber }
115217222abSNico Weber 
AddrIsInFakeStack(uptr ptr,uptr * frame_beg,uptr * frame_end)116217222abSNico Weber uptr FakeStack::AddrIsInFakeStack(uptr ptr, uptr *frame_beg, uptr *frame_end) {
117217222abSNico Weber   uptr stack_size_log = this->stack_size_log();
118217222abSNico Weber   uptr beg = reinterpret_cast<uptr>(GetFrame(stack_size_log, 0, 0));
119217222abSNico Weber   uptr end = reinterpret_cast<uptr>(this) + RequiredSize(stack_size_log);
120217222abSNico Weber   if (ptr < beg || ptr >= end) return 0;
121217222abSNico Weber   uptr class_id = (ptr - beg) >> stack_size_log;
122217222abSNico Weber   uptr base = beg + (class_id << stack_size_log);
123217222abSNico Weber   CHECK_LE(base, ptr);
124217222abSNico Weber   CHECK_LT(ptr, base + (((uptr)1) << stack_size_log));
125217222abSNico Weber   uptr pos = (ptr - base) >> (kMinStackFrameSizeLog + class_id);
126217222abSNico Weber   uptr res = base + pos * BytesInSizeClass(class_id);
127217222abSNico Weber   *frame_end = res + BytesInSizeClass(class_id);
128217222abSNico Weber   *frame_beg = res + sizeof(FakeFrame);
129217222abSNico Weber   return res;
130217222abSNico Weber }
131217222abSNico Weber 
HandleNoReturn()132217222abSNico Weber void FakeStack::HandleNoReturn() {
133217222abSNico Weber   needs_gc_ = true;
134217222abSNico Weber }
135217222abSNico Weber 
1369be88929SVitaly Buka // Hack: The statement below is not true if we take into account sigaltstack or
1379be88929SVitaly Buka // makecontext. It should be possible to make GC to discard wrong stack frame if
1389be88929SVitaly Buka // we use these tools. For now, let's support the simplest case and allow GC to
1399be88929SVitaly Buka // discard only frames from the default stack, assuming there is no buffer on
1409be88929SVitaly Buka // the stack which is used for makecontext or sigaltstack.
1419be88929SVitaly Buka //
142217222abSNico Weber // When throw, longjmp or some such happens we don't call OnFree() and
143217222abSNico Weber // as the result may leak one or more fake frames, but the good news is that
144217222abSNico Weber // we are notified about all such events by HandleNoReturn().
145217222abSNico Weber // If we recently had such no-return event we need to collect garbage frames.
146217222abSNico Weber // We do it based on their 'real_stack' values -- everything that is lower
147217222abSNico Weber // than the current real_stack is garbage.
GC(uptr real_stack)148217222abSNico Weber NOINLINE void FakeStack::GC(uptr real_stack) {
1499be88929SVitaly Buka   AsanThread *curr_thread = GetCurrentThread();
1509be88929SVitaly Buka   if (!curr_thread)
1519be88929SVitaly Buka     return;  // Try again when we have a thread.
1529be88929SVitaly Buka   auto top = curr_thread->stack_top();
1539be88929SVitaly Buka   auto bottom = curr_thread->stack_bottom();
154515c435eSVitaly Buka   if (real_stack < bottom || real_stack > top)
1559be88929SVitaly Buka     return;  // Not the default stack.
1569be88929SVitaly Buka 
157217222abSNico Weber   for (uptr class_id = 0; class_id < kNumberOfSizeClasses; class_id++) {
158217222abSNico Weber     u8 *flags = GetFlags(stack_size_log(), class_id);
159217222abSNico Weber     for (uptr i = 0, n = NumberOfFrames(stack_size_log(), class_id); i < n;
160217222abSNico Weber          i++) {
161217222abSNico Weber       if (flags[i] == 0) continue;  // not allocated.
162217222abSNico Weber       FakeFrame *ff = reinterpret_cast<FakeFrame *>(
163217222abSNico Weber           GetFrame(stack_size_log(), class_id, i));
1649be88929SVitaly Buka       // GC only on the default stack.
165515c435eSVitaly Buka       if (bottom < ff->real_stack && ff->real_stack < real_stack) {
166217222abSNico Weber         flags[i] = 0;
1679be88929SVitaly Buka         // Poison the frame, so the any access will be reported as UAR.
1689be88929SVitaly Buka         SetShadow(reinterpret_cast<uptr>(ff), BytesInSizeClass(class_id),
1699be88929SVitaly Buka                   class_id, kMagic8);
170217222abSNico Weber       }
171217222abSNico Weber     }
172217222abSNico Weber   }
173217222abSNico Weber   needs_gc_ = false;
174217222abSNico Weber }
175217222abSNico Weber 
ForEachFakeFrame(RangeIteratorCallback callback,void * arg)176217222abSNico Weber void FakeStack::ForEachFakeFrame(RangeIteratorCallback callback, void *arg) {
177217222abSNico Weber   for (uptr class_id = 0; class_id < kNumberOfSizeClasses; class_id++) {
178217222abSNico Weber     u8 *flags = GetFlags(stack_size_log(), class_id);
179217222abSNico Weber     for (uptr i = 0, n = NumberOfFrames(stack_size_log(), class_id); i < n;
180217222abSNico Weber          i++) {
181217222abSNico Weber       if (flags[i] == 0) continue;  // not allocated.
182217222abSNico Weber       FakeFrame *ff = reinterpret_cast<FakeFrame *>(
183217222abSNico Weber           GetFrame(stack_size_log(), class_id, i));
184217222abSNico Weber       uptr begin = reinterpret_cast<uptr>(ff);
185217222abSNico Weber       callback(begin, begin + FakeStack::BytesInSizeClass(class_id), arg);
186217222abSNico Weber     }
187217222abSNico Weber   }
188217222abSNico Weber }
189217222abSNico Weber 
190217222abSNico Weber #if (SANITIZER_LINUX && !SANITIZER_ANDROID) || SANITIZER_FUCHSIA
191217222abSNico Weber static THREADLOCAL FakeStack *fake_stack_tls;
192217222abSNico Weber 
GetTLSFakeStack()193217222abSNico Weber FakeStack *GetTLSFakeStack() {
194217222abSNico Weber   return fake_stack_tls;
195217222abSNico Weber }
SetTLSFakeStack(FakeStack * fs)196217222abSNico Weber void SetTLSFakeStack(FakeStack *fs) {
197217222abSNico Weber   fake_stack_tls = fs;
198217222abSNico Weber }
199217222abSNico Weber #else
GetTLSFakeStack()200217222abSNico Weber FakeStack *GetTLSFakeStack() { return 0; }
SetTLSFakeStack(FakeStack * fs)201217222abSNico Weber void SetTLSFakeStack(FakeStack *fs) { }
202217222abSNico Weber #endif  // (SANITIZER_LINUX && !SANITIZER_ANDROID) || SANITIZER_FUCHSIA
203217222abSNico Weber 
GetFakeStack()204217222abSNico Weber static FakeStack *GetFakeStack() {
205217222abSNico Weber   AsanThread *t = GetCurrentThread();
206217222abSNico Weber   if (!t) return nullptr;
2075b0e5055SVitaly Buka   return t->get_or_create_fake_stack();
208217222abSNico Weber }
209217222abSNico Weber 
GetFakeStackFast()210217222abSNico Weber static FakeStack *GetFakeStackFast() {
211217222abSNico Weber   if (FakeStack *fs = GetTLSFakeStack())
212217222abSNico Weber     return fs;
213217222abSNico Weber   if (!__asan_option_detect_stack_use_after_return)
214217222abSNico Weber     return nullptr;
215217222abSNico Weber   return GetFakeStack();
216217222abSNico Weber }
217217222abSNico Weber 
GetFakeStackFastAlways()218af8c59e0SKevin Athey static FakeStack *GetFakeStackFastAlways() {
219af8c59e0SKevin Athey   if (FakeStack *fs = GetTLSFakeStack())
220af8c59e0SKevin Athey     return fs;
221af8c59e0SKevin Athey   return GetFakeStack();
222af8c59e0SKevin Athey }
223af8c59e0SKevin Athey 
OnMalloc(uptr class_id,uptr size)224af8c59e0SKevin Athey static ALWAYS_INLINE uptr OnMalloc(uptr class_id, uptr size) {
225217222abSNico Weber   FakeStack *fs = GetFakeStackFast();
2262b0bfb69SVitaly Buka   if (!fs)
2272b0bfb69SVitaly Buka     return 0;
2282b0bfb69SVitaly Buka   FakeFrame *ff =
2292b0bfb69SVitaly Buka       fs->Allocate(fs->stack_size_log(), class_id, GET_CURRENT_FRAME());
2302b0bfb69SVitaly Buka   if (!ff)
2312b0bfb69SVitaly Buka     return 0;  // Out of fake stack.
232217222abSNico Weber   uptr ptr = reinterpret_cast<uptr>(ff);
233217222abSNico Weber   SetShadow(ptr, size, class_id, 0);
234217222abSNico Weber   return ptr;
235217222abSNico Weber }
236217222abSNico Weber 
OnMallocAlways(uptr class_id,uptr size)237af8c59e0SKevin Athey static ALWAYS_INLINE uptr OnMallocAlways(uptr class_id, uptr size) {
238af8c59e0SKevin Athey   FakeStack *fs = GetFakeStackFastAlways();
239af8c59e0SKevin Athey   if (!fs)
240af8c59e0SKevin Athey     return 0;
2412b0bfb69SVitaly Buka   FakeFrame *ff =
2422b0bfb69SVitaly Buka       fs->Allocate(fs->stack_size_log(), class_id, GET_CURRENT_FRAME());
243af8c59e0SKevin Athey   if (!ff)
244af8c59e0SKevin Athey     return 0;  // Out of fake stack.
245af8c59e0SKevin Athey   uptr ptr = reinterpret_cast<uptr>(ff);
246af8c59e0SKevin Athey   SetShadow(ptr, size, class_id, 0);
247af8c59e0SKevin Athey   return ptr;
248af8c59e0SKevin Athey }
249af8c59e0SKevin Athey 
OnFree(uptr ptr,uptr class_id,uptr size)250af8c59e0SKevin Athey static ALWAYS_INLINE void OnFree(uptr ptr, uptr class_id, uptr size) {
251217222abSNico Weber   FakeStack::Deallocate(ptr, class_id);
252217222abSNico Weber   SetShadow(ptr, size, class_id, kMagic8);
253217222abSNico Weber }
254217222abSNico Weber 
255217222abSNico Weber } // namespace __asan
256217222abSNico Weber 
257217222abSNico Weber // ---------------------- Interface ---------------- {{{1
258217222abSNico Weber using namespace __asan;
259217222abSNico Weber #define DEFINE_STACK_MALLOC_FREE_WITH_CLASS_ID(class_id)                      \
260217222abSNico Weber   extern "C" SANITIZER_INTERFACE_ATTRIBUTE uptr                               \
261217222abSNico Weber       __asan_stack_malloc_##class_id(uptr size) {                             \
262217222abSNico Weber     return OnMalloc(class_id, size);                                          \
263217222abSNico Weber   }                                                                           \
264af8c59e0SKevin Athey   extern "C" SANITIZER_INTERFACE_ATTRIBUTE uptr                               \
265af8c59e0SKevin Athey       __asan_stack_malloc_always_##class_id(uptr size) {                      \
266af8c59e0SKevin Athey     return OnMallocAlways(class_id, size);                                    \
267ddac31c5SKevin Athey   }                                                                           \
268ddac31c5SKevin Athey   extern "C" SANITIZER_INTERFACE_ATTRIBUTE void __asan_stack_free_##class_id( \
269ddac31c5SKevin Athey       uptr ptr, uptr size) {                                                  \
270ddac31c5SKevin Athey     OnFree(ptr, class_id, size);                                              \
271af8c59e0SKevin Athey   }
272217222abSNico Weber 
273217222abSNico Weber DEFINE_STACK_MALLOC_FREE_WITH_CLASS_ID(0)
274217222abSNico Weber DEFINE_STACK_MALLOC_FREE_WITH_CLASS_ID(1)
275217222abSNico Weber DEFINE_STACK_MALLOC_FREE_WITH_CLASS_ID(2)
276217222abSNico Weber DEFINE_STACK_MALLOC_FREE_WITH_CLASS_ID(3)
277217222abSNico Weber DEFINE_STACK_MALLOC_FREE_WITH_CLASS_ID(4)
278217222abSNico Weber DEFINE_STACK_MALLOC_FREE_WITH_CLASS_ID(5)
279217222abSNico Weber DEFINE_STACK_MALLOC_FREE_WITH_CLASS_ID(6)
280217222abSNico Weber DEFINE_STACK_MALLOC_FREE_WITH_CLASS_ID(7)
281217222abSNico Weber DEFINE_STACK_MALLOC_FREE_WITH_CLASS_ID(8)
282217222abSNico Weber DEFINE_STACK_MALLOC_FREE_WITH_CLASS_ID(9)
283217222abSNico Weber DEFINE_STACK_MALLOC_FREE_WITH_CLASS_ID(10)
284af8c59e0SKevin Athey 
285217222abSNico Weber extern "C" {
286af8c59e0SKevin Athey // TODO: remove this method and fix tests that use it by setting
287af8c59e0SKevin Athey // -asan-use-after-return=never, after modal UAR flag lands
288af8c59e0SKevin Athey // (https://github.com/google/sanitizers/issues/1394)
289217222abSNico Weber SANITIZER_INTERFACE_ATTRIBUTE
__asan_get_current_fake_stack()290217222abSNico Weber void *__asan_get_current_fake_stack() { return GetFakeStackFast(); }
291217222abSNico Weber 
292217222abSNico Weber SANITIZER_INTERFACE_ATTRIBUTE
__asan_addr_is_in_fake_stack(void * fake_stack,void * addr,void ** beg,void ** end)293217222abSNico Weber void *__asan_addr_is_in_fake_stack(void *fake_stack, void *addr, void **beg,
294217222abSNico Weber                                    void **end) {
295217222abSNico Weber   FakeStack *fs = reinterpret_cast<FakeStack*>(fake_stack);
296217222abSNico Weber   if (!fs) return nullptr;
297217222abSNico Weber   uptr frame_beg, frame_end;
298217222abSNico Weber   FakeFrame *frame = reinterpret_cast<FakeFrame *>(fs->AddrIsInFakeStack(
299217222abSNico Weber       reinterpret_cast<uptr>(addr), &frame_beg, &frame_end));
300217222abSNico Weber   if (!frame) return nullptr;
301217222abSNico Weber   if (frame->magic != kCurrentStackFrameMagic)
302217222abSNico Weber     return nullptr;
303217222abSNico Weber   if (beg) *beg = reinterpret_cast<void*>(frame_beg);
304217222abSNico Weber   if (end) *end = reinterpret_cast<void*>(frame_end);
305217222abSNico Weber   return reinterpret_cast<void*>(frame->real_stack);
306217222abSNico Weber }
307217222abSNico Weber 
308217222abSNico Weber SANITIZER_INTERFACE_ATTRIBUTE
__asan_alloca_poison(uptr addr,uptr size)309217222abSNico Weber void __asan_alloca_poison(uptr addr, uptr size) {
310217222abSNico Weber   uptr LeftRedzoneAddr = addr - kAllocaRedzoneSize;
311217222abSNico Weber   uptr PartialRzAddr = addr + size;
312217222abSNico Weber   uptr RightRzAddr = (PartialRzAddr + kAllocaRedzoneMask) & ~kAllocaRedzoneMask;
313ad56941aSKirill Stoimenov   uptr PartialRzAligned = PartialRzAddr & ~(ASAN_SHADOW_GRANULARITY - 1);
314217222abSNico Weber   FastPoisonShadow(LeftRedzoneAddr, kAllocaRedzoneSize, kAsanAllocaLeftMagic);
315217222abSNico Weber   FastPoisonShadowPartialRightRedzone(
316ad56941aSKirill Stoimenov       PartialRzAligned, PartialRzAddr % ASAN_SHADOW_GRANULARITY,
317217222abSNico Weber       RightRzAddr - PartialRzAligned, kAsanAllocaRightMagic);
318217222abSNico Weber   FastPoisonShadow(RightRzAddr, kAllocaRedzoneSize, kAsanAllocaRightMagic);
319217222abSNico Weber }
320217222abSNico Weber 
321217222abSNico Weber SANITIZER_INTERFACE_ATTRIBUTE
__asan_allocas_unpoison(uptr top,uptr bottom)322217222abSNico Weber void __asan_allocas_unpoison(uptr top, uptr bottom) {
323217222abSNico Weber   if ((!top) || (top > bottom)) return;
324ad56941aSKirill Stoimenov   REAL(memset)
325ad56941aSKirill Stoimenov   (reinterpret_cast<void *>(MemToShadow(top)), 0,
326ad56941aSKirill Stoimenov    (bottom - top) / ASAN_SHADOW_GRANULARITY);
327217222abSNico Weber }
328217222abSNico Weber } // extern "C"
329