1 //===-- mem_map_fuchsia.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 SCUDO_MEM_MAP_FUCHSIA_H_ 10 #define SCUDO_MEM_MAP_FUCHSIA_H_ 11 12 #include "mem_map_base.h" 13 14 #if SCUDO_FUCHSIA 15 16 #include <stdint.h> 17 #include <zircon/types.h> 18 19 namespace scudo { 20 21 class MemMapFuchsia final : public MemMapBase<MemMapFuchsia> { 22 public: 23 constexpr MemMapFuchsia() = default; 24 25 // Impls for base functions. 26 bool mapImpl(uptr Addr, uptr Size, const char *Name, uptr Flags); 27 void unmapImpl(uptr Addr, uptr Size); 28 bool remapImpl(uptr Addr, uptr Size, const char *Name, uptr Flags); 29 void setMemoryPermissionImpl(uptr Addr, uptr Size, uptr Flags); 30 void releasePagesToOSImpl(uptr From, uptr Size) { 31 return releaseAndZeroPagesToOSImpl(From, Size); 32 } 33 void releaseAndZeroPagesToOSImpl(uptr From, uptr Size); 34 uptr getBaseImpl() { return WindowBase; } 35 uptr getCapacityImpl() { return WindowSize; } 36 37 private: 38 friend class ReservedMemoryFuchsia; 39 40 // Used by ReservedMemoryFuchsia::dispatch. 41 MemMapFuchsia(uptr Base, uptr Capacity); 42 43 // Virtual memory address corresponding to VMO offset 0. 44 uptr MapAddr = 0; 45 46 // Virtual memory base address and size of the VMO subrange that is still in 47 // use. unmapImpl() can shrink this range, either at the beginning or at the 48 // end. 49 uptr WindowBase = 0; 50 uptr WindowSize = 0; 51 52 zx_handle_t Vmo = ZX_HANDLE_INVALID; 53 }; 54 55 class ReservedMemoryFuchsia final 56 : public ReservedMemory<ReservedMemoryFuchsia, MemMapFuchsia> { 57 public: 58 constexpr ReservedMemoryFuchsia() = default; 59 60 bool createImpl(uptr Addr, uptr Size, const char *Name, uptr Flags); 61 void releaseImpl(); 62 MemMapT dispatchImpl(uptr Addr, uptr Size); 63 uptr getBaseImpl() { return Base; } 64 uptr getCapacityImpl() { return Capacity; } 65 66 private: 67 uptr Base = 0; 68 uptr Capacity = 0; 69 }; 70 71 } // namespace scudo 72 73 #endif // SCUDO_FUCHSIA 74 75 #endif // SCUDO_MEM_MAP_FUCHSIA_H_ 76