1 //===-- sanitizer_stack_store.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 #ifndef SANITIZER_STACK_STORE_H 10 #define SANITIZER_STACK_STORE_H 11 12 #include "sanitizer_atomic.h" 13 #include "sanitizer_internal_defs.h" 14 #include "sanitizer_mutex.h" 15 #include "sanitizer_stacktrace.h" 16 17 namespace __sanitizer { 18 19 class StackStore { 20 public: 21 constexpr StackStore() = default; 22 23 using Id = uptr; 24 25 Id Store(const StackTrace &trace); 26 StackTrace Load(Id id); 27 uptr Allocated() const { return atomic_load_relaxed(&mapped_size_); } 28 29 void TestOnlyUnmap(); 30 31 private: 32 uptr *Alloc(uptr count = 1); 33 uptr *TryAlloc(uptr count); 34 uptr *RefillAndAlloc(uptr count); 35 mutable StaticSpinMutex mtx_ = {}; // Protects alloc of new blocks. 36 atomic_uintptr_t region_pos_ = {}; // Region allocator for Node's. 37 atomic_uintptr_t region_end_ = {}; 38 atomic_uintptr_t mapped_size_ = {}; 39 40 struct BlockInfo { 41 const BlockInfo *next; 42 uptr ptr; 43 uptr size; 44 }; 45 const BlockInfo *curr_ = nullptr; 46 }; 47 48 } // namespace __sanitizer 49 50 #endif // SANITIZER_STACK_STORE_H 51