The Pedigree Project  0.1
include/pedigree/kernel/processor/VirtualAddressSpace.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_VIRTUALADDRESSSPACE_H
21 #define KERNEL_PROCESSOR_VIRTUALADDRESSSPACE_H
22 
23 #include "pedigree/kernel/compiler.h"
24 #include "pedigree/kernel/processor/types.h"
25 
38 {
39  public:
41  friend class Debugger;
42 
43  class Stack;
44 
47  static const size_t KernelMode = 0x01;
49  static const size_t Write = 0x02;
52  static const size_t Execute = 0x04;
54  static const size_t WriteThrough = 0x08;
56  static const size_t CacheDisable = 0x10;
58  static const size_t CopyOnWrite = 0x20;
60  static const size_t Swapped = 0x40;
63  static const size_t MemoryCoherent = 0x80;
65  static const size_t Guarded = 0x100;
67  static const size_t Shared = 0x200;
69  static const size_t WriteCombine = 0x400;
71  static const size_t Accessed = 0x800;
73  static const size_t Dirty = 0x1000;
75  static const size_t ClearDirty = 0x2000;
76 
80 
86  virtual void *expandHeap(ssize_t incr, size_t flags);
87 
91  virtual bool isAddressValid(void *virtualAddress) = 0;
97  virtual bool isMapped(void *virtualAddress) = 0;
98 
108  virtual bool
109  map(physical_uintptr_t physicalAddress, void *virtualAddress,
110  size_t flags) = 0;
118  virtual bool mapHuge(
119  physical_uintptr_t physAddress, void *virtualAddress, size_t count,
120  size_t flags);
127  virtual void getMapping(
128  void *virtualAddress, physical_uintptr_t &physicalAddress,
129  size_t &flags) = 0;
134  virtual void setFlags(void *virtualAddress, size_t newFlags) = 0;
139  virtual void unmap(void *virtualAddress) = 0;
140 
143  virtual Stack *allocateStack() = 0;
145  virtual Stack *allocateStack(size_t stackSz)
146  {
147  // Default implementation just ignores the stack size.
148  return allocateStack();
149  }
151  virtual void freeStack(Stack *pStack) = 0;
152 
156  static VirtualAddressSpace *create();
157 
163  virtual VirtualAddressSpace *clone(bool copyOnWrite = true) = 0;
164 
168  virtual void revertToKernelAddressSpace() = 0;
169 
171  inline virtual ~VirtualAddressSpace()
172  {
173  }
174 
176  void setHeap(void *heap, void *heapEnd)
177  {
178  m_Heap = heap;
179  m_HeapEnd = heapEnd;
180  }
181 
184  virtual bool memIsInKernelHeap(void *pMem) = 0;
185 
188  virtual bool memIsInHeap(void *pMem) = 0;
189 
191  virtual void *getEndOfHeap() = 0;
192 
194  virtual uintptr_t getKernelStart() const = 0;
195 
197  virtual uintptr_t getUserStart() const = 0;
198 
200  virtual uintptr_t getUserReservedStart() const = 0;
201 
203  virtual uintptr_t getDynamicLinkerAddress() const = 0;
204 
206  virtual uintptr_t getKernelHeapStart() const = 0;
207 
209  virtual uintptr_t getKernelHeapEnd() const = 0;
210 
212  virtual uintptr_t getKernelCacheStart() const = 0;
213 
215  virtual uintptr_t getKernelCacheEnd() const = 0;
216 
218  virtual uintptr_t getKernelEventBlockStart() const = 0;
219 
221  virtual uintptr_t getKernelModulesStart() const = 0;
222 
224  virtual uintptr_t getKernelModulesEnd() const = 0;
225 
233  virtual uintptr_t getDynamicStart() const
234  {
235  return 0;
236  }
238  virtual uintptr_t getDynamicEnd() const
239  {
240  return 0;
241  }
242 
244  virtual uintptr_t getGlobalInfoBlock() const
245  {
246  return 0;
247  }
248 
250  void *m_Heap;
252  void *m_HeapEnd;
254  static physical_uintptr_t m_ZeroPage;
255 
257  class Stack
258  {
259  public:
260  Stack(void *top, size_t size) : m_Top(top), m_Size(size)
261  {
262  }
263 
264  void *getTop() const
265  {
266  return m_Top;
267  }
268 
269  size_t getSize() const
270  {
271  return m_Size;
272  }
273 
274  operator void *() const
275  {
276  return m_Top;
277  }
278 
279  private:
280  void *m_Top;
281  size_t m_Size;
282  };
283 
284  protected:
286  inline VirtualAddressSpace(void *Heap) : m_Heap(Heap), m_HeapEnd(Heap)
287  {
288  }
289 
290  private:
299 
303  void rollbackHeapExpansion(void *virtualAddress, size_t pageCount);
304 };
305 
308 #endif
virtual void unmap(void *virtualAddress)=0
virtual uintptr_t getKernelEventBlockStart() const =0
virtual bool isAddressValid(void *virtualAddress)=0
virtual bool memIsInHeap(void *pMem)=0
virtual void getMapping(void *virtualAddress, physical_uintptr_t &physicalAddress, size_t &flags)=0
VirtualAddressSpace & operator=(const VirtualAddressSpace &)
virtual uintptr_t getKernelModulesEnd() const =0
virtual uintptr_t getUserStart() const =0
virtual void setFlags(void *virtualAddress, size_t newFlags)=0
virtual uintptr_t getKernelHeapEnd() const =0
virtual uintptr_t getDynamicLinkerAddress() const =0
virtual bool isMapped(void *virtualAddress)=0
virtual bool map(physical_uintptr_t physicalAddress, void *virtualAddress, size_t flags)=0
virtual uintptr_t getUserReservedStart() const =0
static EXPORTED_PUBLIC VirtualAddressSpace & getKernelAddressSpace()
virtual Stack * allocateStack()=0
virtual uintptr_t getKernelStart() const =0
virtual void freeStack(Stack *pStack)=0
static VirtualAddressSpace * create()
uintptr_t physicalAddress(physical_uintptr_t address) PURE
Definition: utils.h:38
virtual bool memIsInKernelHeap(void *pMem)=0
void rollbackHeapExpansion(void *virtualAddress, size_t pageCount)
virtual uintptr_t getKernelCacheEnd() const =0
virtual uintptr_t getKernelHeapStart() const =0
virtual uintptr_t getKernelCacheStart() const =0
virtual void revertToKernelAddressSpace()=0
virtual void * getEndOfHeap()=0
virtual void * expandHeap(ssize_t incr, size_t flags)
virtual bool mapHuge(physical_uintptr_t physAddress, void *virtualAddress, size_t count, size_t flags)
virtual VirtualAddressSpace * clone(bool copyOnWrite=true)=0
virtual uintptr_t getKernelModulesStart() const =0