Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
virtual_memory.h
Go to the documentation of this file.
1// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
2// for details. All rights reserved. Use of this source code is governed by a
3// BSD-style license that can be found in the LICENSE file.
4
5#ifndef RUNTIME_BIN_VIRTUAL_MEMORY_H_
6#define RUNTIME_BIN_VIRTUAL_MEMORY_H_
7
9#include "platform/globals.h"
10
11namespace dart {
12namespace bin {
13
15 public:
23
24 // The reserved memory is unmapped on destruction.
26
27 void release() {
28 address_ = nullptr;
29 size_ = 0;
30 }
31
32 uword start() const { return reinterpret_cast<uword>(address_); }
33 uword end() const { return reinterpret_cast<uword>(address_) + size_; }
34 void* address() const { return address_; }
35 intptr_t size() const { return size_; }
36
37 // Changes the protection of the virtual memory area.
38 static void Protect(void* address, intptr_t size, Protection mode);
39 void Protect(Protection mode) { return Protect(address(), size(), mode); }
40
41 // Reserves and commits a virtual memory segment with size. If a segment of
42 // the requested size cannot be allocated, nullptr is returned.
43 static VirtualMemory* Allocate(intptr_t size,
44 bool is_executable,
45 const char* name);
46
47 static void Init() { page_size_ = CalculatePageSize(); }
48
49 // Returns the cached page size. Use only if Init() has been called.
50 static intptr_t PageSize() {
51 ASSERT(page_size_ != 0);
52 return page_size_;
53 }
54
55 private:
56 static intptr_t CalculatePageSize();
57
58 // These constructors are only used internally when reserving new virtual
59 // spaces. They do not reserve any virtual address space on their own.
60 VirtualMemory(void* address, size_t size) : address_(address), size_(size) {}
61
62 void* address_;
63 size_t size_;
64
65 static uword page_size_;
66
68};
69
70} // namespace bin
71} // namespace dart
72
73#endif // RUNTIME_BIN_VIRTUAL_MEMORY_H_
void Protect(Protection mode)
static VirtualMemory * Allocate(intptr_t size, bool is_executable, const char *name)
static void Protect(void *address, intptr_t size, Protection mode)
static intptr_t PageSize()
#define ASSERT(E)
const char *const name
uintptr_t uword
Definition globals.h:501
#define DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName)
Definition globals.h:593