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
39private:
40 uptr MapBase = 0;
41 uptr MapCapacity = 0;
42};
43
44// This will be deprecated when every allocator has been supported by each
45// platform's `MemMap` implementation.
46class ReservedMemoryLinux final
47 : public ReservedMemory<ReservedMemoryLinux, MemMapLinux> {
48public:
49 // The following two are the Impls for function in `MemMapBase`.
50 uptr getBaseImpl() { return MapBase; }
51 uptr getCapacityImpl() { return MapCapacity; }
52
53 // These threes are specific to `ReservedMemory`.
54 bool createImpl(uptr Addr, uptr Size, const char *Name, uptr Flags);
55 void releaseImpl();
56 MemMapT dispatchImpl(uptr Addr, uptr Size);
57
58private:
59 uptr MapBase = 0;
60 uptr MapCapacity = 0;
61};
62
63} // namespace scudo
64
65#endif // SCUDO_LINUX
66
67#endif // SCUDO_MEM_MAP_LINUX_H_
68