xref: /freebsd/contrib/llvm-project/compiler-rt/lib/scudo/standalone/mem_map_fuchsia.h (revision 06c3fb2749bda94cb5201f81ffdb8fa6c3161b2e)
1*06c3fb27SDimitry Andric //===-- mem_map_fuchsia.h ---------------------------------------*- C++ -*-===//
2*06c3fb27SDimitry Andric //
3*06c3fb27SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*06c3fb27SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5*06c3fb27SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*06c3fb27SDimitry Andric //
7*06c3fb27SDimitry Andric //===----------------------------------------------------------------------===//
8*06c3fb27SDimitry Andric 
9*06c3fb27SDimitry Andric #ifndef SCUDO_MEM_MAP_FUCHSIA_H_
10*06c3fb27SDimitry Andric #define SCUDO_MEM_MAP_FUCHSIA_H_
11*06c3fb27SDimitry Andric 
12*06c3fb27SDimitry Andric #include "mem_map_base.h"
13*06c3fb27SDimitry Andric 
14*06c3fb27SDimitry Andric #if SCUDO_FUCHSIA
15*06c3fb27SDimitry Andric 
16*06c3fb27SDimitry Andric #include <stdint.h>
17*06c3fb27SDimitry Andric #include <zircon/types.h>
18*06c3fb27SDimitry Andric 
19*06c3fb27SDimitry Andric namespace scudo {
20*06c3fb27SDimitry Andric 
21*06c3fb27SDimitry Andric class MemMapFuchsia final : public MemMapBase<MemMapFuchsia> {
22*06c3fb27SDimitry Andric public:
23*06c3fb27SDimitry Andric   constexpr MemMapFuchsia() = default;
24*06c3fb27SDimitry Andric 
25*06c3fb27SDimitry Andric   // Impls for base functions.
26*06c3fb27SDimitry Andric   bool mapImpl(uptr Addr, uptr Size, const char *Name, uptr Flags);
27*06c3fb27SDimitry Andric   void unmapImpl(uptr Addr, uptr Size);
28*06c3fb27SDimitry Andric   bool remapImpl(uptr Addr, uptr Size, const char *Name, uptr Flags);
29*06c3fb27SDimitry Andric   void setMemoryPermissionImpl(uptr Addr, uptr Size, uptr Flags);
releasePagesToOSImpl(uptr From,uptr Size)30*06c3fb27SDimitry Andric   void releasePagesToOSImpl(uptr From, uptr Size) {
31*06c3fb27SDimitry Andric     return releaseAndZeroPagesToOSImpl(From, Size);
32*06c3fb27SDimitry Andric   }
33*06c3fb27SDimitry Andric   void releaseAndZeroPagesToOSImpl(uptr From, uptr Size);
getBaseImpl()34*06c3fb27SDimitry Andric   uptr getBaseImpl() { return WindowBase; }
getCapacityImpl()35*06c3fb27SDimitry Andric   uptr getCapacityImpl() { return WindowSize; }
36*06c3fb27SDimitry Andric 
37*06c3fb27SDimitry Andric private:
38*06c3fb27SDimitry Andric   friend class ReservedMemoryFuchsia;
39*06c3fb27SDimitry Andric 
40*06c3fb27SDimitry Andric   // Used by ReservedMemoryFuchsia::dispatch.
41*06c3fb27SDimitry Andric   MemMapFuchsia(uptr Base, uptr Capacity);
42*06c3fb27SDimitry Andric 
43*06c3fb27SDimitry Andric   // Virtual memory address corresponding to VMO offset 0.
44*06c3fb27SDimitry Andric   uptr MapAddr = 0;
45*06c3fb27SDimitry Andric 
46*06c3fb27SDimitry Andric   // Virtual memory base address and size of the VMO subrange that is still in
47*06c3fb27SDimitry Andric   // use. unmapImpl() can shrink this range, either at the beginning or at the
48*06c3fb27SDimitry Andric   // end.
49*06c3fb27SDimitry Andric   uptr WindowBase = 0;
50*06c3fb27SDimitry Andric   uptr WindowSize = 0;
51*06c3fb27SDimitry Andric 
52*06c3fb27SDimitry Andric   zx_handle_t Vmo = ZX_HANDLE_INVALID;
53*06c3fb27SDimitry Andric };
54*06c3fb27SDimitry Andric 
55*06c3fb27SDimitry Andric class ReservedMemoryFuchsia final
56*06c3fb27SDimitry Andric     : public ReservedMemory<ReservedMemoryFuchsia, MemMapFuchsia> {
57*06c3fb27SDimitry Andric public:
58*06c3fb27SDimitry Andric   constexpr ReservedMemoryFuchsia() = default;
59*06c3fb27SDimitry Andric 
60*06c3fb27SDimitry Andric   bool createImpl(uptr Addr, uptr Size, const char *Name, uptr Flags);
61*06c3fb27SDimitry Andric   void releaseImpl();
62*06c3fb27SDimitry Andric   MemMapT dispatchImpl(uptr Addr, uptr Size);
getBaseImpl()63*06c3fb27SDimitry Andric   uptr getBaseImpl() { return Base; }
getCapacityImpl()64*06c3fb27SDimitry Andric   uptr getCapacityImpl() { return Capacity; }
65*06c3fb27SDimitry Andric 
66*06c3fb27SDimitry Andric private:
67*06c3fb27SDimitry Andric   uptr Base = 0;
68*06c3fb27SDimitry Andric   uptr Capacity = 0;
69*06c3fb27SDimitry Andric };
70*06c3fb27SDimitry Andric 
71*06c3fb27SDimitry Andric } // namespace scudo
72*06c3fb27SDimitry Andric 
73*06c3fb27SDimitry Andric #endif // SCUDO_FUCHSIA
74*06c3fb27SDimitry Andric 
75*06c3fb27SDimitry Andric #endif // SCUDO_MEM_MAP_FUCHSIA_H_
76