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
19namespace scudo {
20
21class MemMapFuchsia final : public MemMapBase<MemMapFuchsia> {
22public:
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 s64 getResidentPagesImpl(uptr From, uptr Size);
37
38private:
39 friend class ReservedMemoryFuchsia;
40
41 // Used by ReservedMemoryFuchsia::dispatch.
42 MemMapFuchsia(uptr Base, uptr Capacity);
43
44 // Virtual memory address corresponding to VMO offset 0.
45 uptr MapAddr = 0;
46
47 // Virtual memory base address and size of the VMO subrange that is still in
48 // use. unmapImpl() can shrink this range, either at the beginning or at the
49 // end.
50 uptr WindowBase = 0;
51 uptr WindowSize = 0;
52
53 zx_handle_t Vmo = ZX_HANDLE_INVALID;
54};
55
56class ReservedMemoryFuchsia final
57 : public ReservedMemory<ReservedMemoryFuchsia, MemMapFuchsia> {
58public:
59 constexpr ReservedMemoryFuchsia() = default;
60
61 bool createImpl(uptr Addr, uptr Size, const char *Name, uptr Flags);
62 void releaseImpl();
63 MemMapT dispatchImpl(uptr Addr, uptr Size);
64 uptr getBaseImpl() { return Base; }
65 uptr getCapacityImpl() { return Capacity; }
66
67private:
68 uptr Base = 0;
69 uptr Capacity = 0;
70};
71
72} // namespace scudo
73
74#endif // SCUDO_FUCHSIA
75
76#endif // SCUDO_MEM_MAP_FUCHSIA_H_
77