The Pedigree Project 0.1
MemoryRegion.h
1/*
2 * Copyright (c) 2008-2014, Pedigree Developers
3 *
4 * Please see the CONTRIB file in the root of the source tree for a full
5 * list of contributors.
6 *
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 */
19
20#ifndef KERNEL_PROCESSOR_MEMORYREGION_H
21#define KERNEL_PROCESSOR_MEMORYREGION_H
22
23#include "pedigree/kernel/compiler.h"
24#include "pedigree/kernel/processor/types.h"
25
35class EXPORTED_PUBLIC MemoryRegion {
40 friend class Arm64PhysicalMemoryManager;
41 friend class Armv7PhysicalMemoryManager;
42
43 public:
45 MemoryRegion(const char* pName);
47 virtual ~MemoryRegion();
48
49 void free();
50
55 void* virtualAddress() const;
59 physical_uintptr_t physicalAddress() const;
62 size_t size() const;
65 const char* name() const;
66
67 operator bool() const;
68
69 bool physicalBoundsCheck(physical_uintptr_t address);
70 template <typename T>
71 T* convertPhysicalPointer(physical_uintptr_t address);
72
73 void setNonRamMemory(bool b);
74 bool getNonRamMemory();
75 void setForced(bool b);
76 bool getForced();
77 void setAnonymous(bool b);
78 bool getAnonymous() const;
79
80 private:
87
93 physical_uintptr_t m_PhysicalAddress;
95 size_t m_Size;
97 const char* m_pName;
98
99 bool m_bNonRamMemory, m_bForced, m_bPageBacked, m_bAnonymous;
100};
101
104template <typename T>
105T* MemoryRegion::convertPhysicalPointer(physical_uintptr_t address) {
106 return reinterpret_cast<T*>(reinterpret_cast<uintptr_t>(m_VirtualAddress) +
107 (address - m_PhysicalAddress));
108}
109
110#endif
Implementation of the PhysicalMemoryManager for common x86.
Special memory entity in the kernel's virtual address space.
void * m_VirtualAddress
const char * m_pName
MemoryRegion & operator=(const MemoryRegion &)
MemoryRegion(const MemoryRegion &)
physical_uintptr_t m_PhysicalAddress
Implementation of the PhysicalMemoryManager for common x86.
uintptr_t physicalAddress(physical_uintptr_t address) PURE
Definition utils.h:39