FreeNOS
MemoryContext.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2015 Niek Linnenbank
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef __LIBARCH_MEMORYCONTEXT_H
19#define __LIBARCH_MEMORYCONTEXT_H
20
21#include <Types.h>
22#include <Macros.h>
23#include <BitOperations.h>
24#include <Callback.h>
25#include "Memory.h"
26#include "MemoryMap.h"
27
29class SplitAllocator;
30
43{
44 public:
45
59
67
71 virtual ~MemoryContext();
72
78 static MemoryContext * getCurrent();
79
85 virtual Result initialize() = 0;
86
96 virtual Result activate(bool initializeMMU = false) = 0;
97
107 virtual Result map(Address virt, Address phys, Memory::Access access) = 0;
108
119 virtual Result unmap(Address virt) = 0;
120
129 virtual Result lookup(Address virt, Address *phys) const = 0;
130
139 virtual Result access(Address virt, Memory::Access *access) const = 0;
140
149
157 virtual Result mapRangeSparse(Memory::Range *range);
158
166 virtual Result unmapRange(Memory::Range *range);
167
175 virtual Result release(Address virt);
176
184 virtual Result releaseRange(Memory::Range *range) = 0;
185
198 virtual Result releaseSection(const Memory::Range & range,
199 const bool tablesOnly = false) = 0;
200
214 virtual Result findFree(Size size, MemoryMap::Region region, Address *virt) const;
215
223 virtual void mapRangeSparseCallback(Address *phys);
224
225 protected:
226
229
232
235
238
241
244};
245
251#endif /* __LIBARCH_MEMORYCONTEXT_H */
Abstraction for providing a callback function to a object instance.
Definition Callback.h:50
Virtual memory abstract interface.
enum MemoryContext::Result Result
Result codes.
Result
Result codes.
virtual Result unmap(Address virt)=0
Unmap a virtual address.
virtual Result mapRangeSparse(Memory::Range *range)
Map and allocate a range of sparse (non-contiguous) physical pages to virtual addresses.
MemoryMap * m_map
Virtual memory layout.
virtual Result initialize()=0
Initialize the MemoryContext.
virtual Result releaseSection(const Memory::Range &range, const bool tablesOnly=false)=0
Release memory sections.
virtual void mapRangeSparseCallback(Address *phys)
Callback to provide intermediate Range object during mapRangeSparse()
Size m_numSparsePages
Number of pages allocated via mapRangeSparse Callback.
SplitAllocator * m_alloc
Physical memory allocator.
virtual Result findFree(Size size, MemoryMap::Region region, Address *virt) const
Find unused memory.
virtual Result map(Address virt, Address phys, Memory::Access access)=0
Map a physical page to a virtual address.
virtual Result unmapRange(Memory::Range *range)
Unmaps a range of virtual memory.
virtual Result releaseRange(Memory::Range *range)=0
Release a range of physical memory by its virtual memory pages.
virtual ~MemoryContext()
Destructor.
virtual Result release(Address virt)
Release a memory page mapping.
static MemoryContext * getCurrent()
Get currently active MemoryContext.
Callback< MemoryContext, Address > m_mapRangeSparseCallback
Callback object for mapRangeSparseCallback function.
virtual Result activate(bool initializeMMU=false)=0
Activate the MemoryContext.
static MemoryContext * m_current
The currently active MemoryContext.
Memory::Range * m_savedRange
Saved range input for use in the mapRangeSparse Callback.
virtual Result mapRangeContiguous(Memory::Range *range)
Map a range of contiguous physical pages to virtual addresses.
virtual Result access(Address virt, Memory::Access *access) const =0
Get Access flags for a virtual address.
virtual Result lookup(Address virt, Address *phys) const =0
Translate virtual address to physical address.
Describes virtual memory map layout.
Definition MemoryMap.h:39
Region
Memory regions.
Definition MemoryMap.h:53
Allocator which separates kernel mapped memory at virtual and physical addresses.
unsigned long Address
A memory address.
Definition Types.h:131
unsigned int Size
Any sane size indicator cannot go negative.
Definition Types.h:128
Access
Memory access flags.
Definition Memory.h:39
Memory range.
Definition Memory.h:56