VirtualAddress.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #pragma once
  2. #include <AK/Types.h>
  3. class VirtualAddress {
  4. public:
  5. VirtualAddress() {}
  6. explicit VirtualAddress(u32 address)
  7. : m_address(address)
  8. {
  9. }
  10. bool is_null() const { return m_address == 0; }
  11. bool is_page_aligned() const { return (m_address & 0xfff) == 0; }
  12. VirtualAddress offset(u32 o) const { return VirtualAddress(m_address + o); }
  13. u32 get() const { return m_address; }
  14. void set(u32 address) { m_address = address; }
  15. void mask(u32 m) { m_address &= m; }
  16. bool operator<=(const VirtualAddress& other) const { return m_address <= other.m_address; }
  17. bool operator>=(const VirtualAddress& other) const { return m_address >= other.m_address; }
  18. bool operator>(const VirtualAddress& other) const { return m_address > other.m_address; }
  19. bool operator<(const VirtualAddress& other) const { return m_address < other.m_address; }
  20. bool operator==(const VirtualAddress& other) const { return m_address == other.m_address; }
  21. bool operator!=(const VirtualAddress& other) const { return m_address != other.m_address; }
  22. u8* as_ptr() { return reinterpret_cast<u8*>(m_address); }
  23. const u8* as_ptr() const { return reinterpret_cast<const u8*>(m_address); }
  24. VirtualAddress page_base() const { return VirtualAddress(m_address & 0xfffff000); }
  25. private:
  26. u32 m_address { 0 };
  27. };
  28. inline VirtualAddress operator-(const VirtualAddress& a, const VirtualAddress& b)
  29. {
  30. return VirtualAddress(a.get() - b.get());
  31. }