1//===-- mem_map_linux.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_LINUX_H_
10#define SCUDO_MEM_MAP_LINUX_H_
11
12#include "platform.h"
13
14#if SCUDO_LINUX
15
16#include "common.h"
17#include "mem_map_base.h"
18
19namespace scudo {
20
21class MemMapLinux final : public MemMapBase<MemMapLinux> {
22public:
23 constexpr MemMapLinux() = default;
24 MemMapLinux(uptr Base, uptr Capacity)
25 : MapBase(Base), MapCapacity(Capacity) {}
26
27 // Impls for base functions.
28 bool mapImpl(uptr Addr, uptr Size, const char *Name, uptr Flags = 0);
29 void unmapImpl(uptr Addr, uptr Size);
30 bool remapImpl(uptr Addr, uptr Size, const char *Name, uptr Flags = 0);
31 void setMemoryPermissionImpl(uptr Addr, uptr Size, uptr Flags);
32 void releasePagesToOSImpl(uptr From, uptr Size) {
33 return releaseAndZeroPagesToOSImpl(From, Size);
34 }
35 void releaseAndZeroPagesToOSImpl(uptr From, uptr Size);
36 uptr getBaseImpl() { return MapBase; }
37 uptr getCapacityImpl() { return MapCapacity; }
38 s64 getResidentPagesImpl(uptr From, uptr Size);
39
40private:
41 uptr MapBase = 0;
42 uptr MapCapacity = 0;
43};
44
45// This will be deprecated when every allocator has been supported by each
46// platform's `MemMap` implementation.
47class ReservedMemoryLinux final
48 : public ReservedMemory<ReservedMemoryLinux, MemMapLinux> {
49public:
50 // The following two are the Impls for function in `MemMapBase`.
51 uptr getBaseImpl() { return MapBase; }
52 uptr getCapacityImpl() { return MapCapacity; }
53
54 // These threes are specific to `ReservedMemory`.
55 bool createImpl(uptr Addr, uptr Size, const char *Name, uptr Flags);
56 void releaseImpl();
57 MemMapT dispatchImpl(uptr Addr, uptr Size);
58
59private:
60 uptr MapBase = 0;
61 uptr MapCapacity = 0;
62};
63
64} // namespace scudo
65
66#endif // SCUDO_LINUX
67
68#endif // SCUDO_MEM_MAP_LINUX_H_
69