1 //===-- asan_malloc_local.h -------------------------------------*- C++ -*-===// 2 // 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 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // This file is a part of AddressSanitizer, an address sanity checker. 10 // 11 // Provide interfaces to check for and handle local pool memory allocation. 12 //===----------------------------------------------------------------------===// 13 14 #ifndef ASAN_MALLOC_LOCAL_H 15 #define ASAN_MALLOC_LOCAL_H 16 17 #include "sanitizer_common/sanitizer_platform.h" 18 #include "asan_internal.h" 19 EarlyMalloc()20static inline bool EarlyMalloc() { 21 return SANITIZER_RTEMS && 22 (!__asan::asan_inited || __asan::asan_init_is_running); 23 } 24 25 #if SANITIZER_RTEMS 26 27 bool IsFromLocalPool(const void *ptr); 28 void *MemalignFromLocalPool(uptr alignment, uptr size); 29 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 32 // implementation. 33 #define MAYBE_ALLOCATE_FROM_LOCAL_POOL(nothrow) \ 34 do { \ 35 if (UNLIKELY(EarlyMalloc())) { \ 36 void *res = MemalignFromLocalPool(SHADOW_GRANULARITY, size); \ 37 if (!nothrow) \ 38 CHECK(res); \ 39 return res; \ 40 } \ 41 } while (0) 42 43 #define IS_FROM_LOCAL_POOL(ptr) UNLIKELY(IsFromLocalPool(ptr)) 44 45 #else // SANITIZER_RTEMS 46 47 #define MAYBE_ALLOCATE_FROM_LOCAL_POOL(nothrow) 48 #define IS_FROM_LOCAL_POOL(ptr) 0 49 50 #endif // SANITIZER_RTEMS 51 52 #endif // ASAN_MALLOC_LOCAL_H 53