1 //===-- asan_malloc_local.h -------------------------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file is a part of AddressSanitizer, an address sanity checker.
11 // Provide interfaces to check for and handle local pool memory allocation.
12 //===----------------------------------------------------------------------===//
14 #ifndef ASAN_MALLOC_LOCAL_H
15 #define ASAN_MALLOC_LOCAL_H
17 #include "sanitizer_common/sanitizer_platform.h"
18 #include "asan_internal.h"
20 static INLINE bool EarlyMalloc() {
21 return SANITIZER_RTEMS &&
22 (!__asan::asan_inited || __asan::asan_init_is_running);
27 bool IsFromLocalPool(const void *ptr);
28 void *MemalignFromLocalPool(uptr alignment, uptr size);
30 // On RTEMS, we use the local pool to handle memory allocation when the ASan
31 // run-time is not up. This macro is expanded in the context of the operator new
33 #define MAYBE_ALLOCATE_FROM_LOCAL_POOL(nothrow) \
35 if (UNLIKELY(EarlyMalloc())) { \
36 void *res = MemalignFromLocalPool(SHADOW_GRANULARITY, size); \
43 #define IS_FROM_LOCAL_POOL(ptr) UNLIKELY(IsFromLocalPool(ptr))
45 #else // SANITIZER_RTEMS
47 #define MAYBE_ALLOCATE_FROM_LOCAL_POOL(nothrow)
48 #define IS_FROM_LOCAL_POOL(ptr) 0
50 #endif // SANITIZER_RTEMS
52 #endif // ASAN_MALLOC_LOCAL_H