mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 23:50:19 +00:00
Kernel: Let Region keep a Range internally.
This commit is contained in:
parent
4a6fcfbacf
commit
87b54a82c7
Notes:
sideshowbarker
2024-07-19 14:05:18 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/87b54a82c77
5 changed files with 26 additions and 26 deletions
|
@ -79,7 +79,7 @@ Region* Process::allocate_region(LinearAddress laddr, size_t size, String&& name
|
|||
else
|
||||
range = m_range_allocator.allocate_specific(laddr, size);
|
||||
|
||||
m_regions.append(adopt(*new Region(range.base(), range.size(), move(name), is_readable, is_writable)));
|
||||
m_regions.append(adopt(*new Region(range, move(name), is_readable, is_writable)));
|
||||
MM.map_region(*this, *m_regions.last());
|
||||
if (commit)
|
||||
m_regions.last()->commit();
|
||||
|
@ -97,7 +97,7 @@ Region* Process::allocate_file_backed_region(LinearAddress laddr, size_t size, R
|
|||
else
|
||||
range = m_range_allocator.allocate_specific(laddr, size);
|
||||
|
||||
m_regions.append(adopt(*new Region(range.base(), range.size(), move(inode), move(name), is_readable, is_writable)));
|
||||
m_regions.append(adopt(*new Region(range, move(inode), move(name), is_readable, is_writable)));
|
||||
MM.map_region(*this, *m_regions.last());
|
||||
return m_regions.last().ptr();
|
||||
}
|
||||
|
@ -115,7 +115,7 @@ Region* Process::allocate_region_with_vmo(LinearAddress laddr, size_t size, Reta
|
|||
|
||||
offset_in_vmo &= PAGE_MASK;
|
||||
size = ceil_div(size, PAGE_SIZE) * PAGE_SIZE;
|
||||
m_regions.append(adopt(*new Region(range.base(), range.size(), move(vmo), offset_in_vmo, move(name), is_readable, is_writable)));
|
||||
m_regions.append(adopt(*new Region(range, move(vmo), offset_in_vmo, move(name), is_readable, is_writable)));
|
||||
MM.map_region(*this, *m_regions.last());
|
||||
return m_regions.last().ptr();
|
||||
}
|
||||
|
|
|
@ -404,7 +404,7 @@ RetainPtr<Region> MemoryManager::allocate_kernel_region(size_t size, String&& na
|
|||
ASSERT(!(size % PAGE_SIZE));
|
||||
auto range = m_range_allocator.allocate_anywhere(size);
|
||||
ASSERT(range.is_valid());
|
||||
auto region = adopt(*new Region(range.base(), range.size(), move(name), true, true, false));
|
||||
auto region = adopt(*new Region(range, move(name), true, true, false));
|
||||
MM.map_region_at_address(*m_kernel_page_directory, *region, range.base(), false);
|
||||
// FIXME: It would be cool if these could zero-fill on demand instead.
|
||||
region->commit();
|
||||
|
|
|
@ -17,6 +17,8 @@ public:
|
|||
size_t size() const { return m_size; }
|
||||
bool is_valid() const { return !m_base.is_null(); }
|
||||
|
||||
bool contains(LinearAddress laddr) const { return laddr >= base() && laddr < end(); }
|
||||
|
||||
LinearAddress end() const { return m_base.offset(m_size); }
|
||||
|
||||
bool operator==(const Range& other) const
|
||||
|
|
|
@ -4,10 +4,9 @@
|
|||
#include <Kernel/Process.h>
|
||||
#include <Kernel/Thread.h>
|
||||
|
||||
Region::Region(LinearAddress a, size_t s, String&& n, bool r, bool w, bool cow)
|
||||
: m_laddr(a)
|
||||
, m_size(s)
|
||||
, m_vmo(VMObject::create_anonymous(s))
|
||||
Region::Region(const Range& range, String&& n, bool r, bool w, bool cow)
|
||||
: m_range(range)
|
||||
, m_vmo(VMObject::create_anonymous(size()))
|
||||
, m_name(move(n))
|
||||
, m_readable(r)
|
||||
, m_writable(w)
|
||||
|
@ -17,9 +16,8 @@ Region::Region(LinearAddress a, size_t s, String&& n, bool r, bool w, bool cow)
|
|||
MM.register_region(*this);
|
||||
}
|
||||
|
||||
Region::Region(LinearAddress a, size_t s, RetainPtr<Inode>&& inode, String&& n, bool r, bool w)
|
||||
: m_laddr(a)
|
||||
, m_size(s)
|
||||
Region::Region(const Range& range, RetainPtr<Inode>&& inode, String&& n, bool r, bool w)
|
||||
: m_range(range)
|
||||
, m_vmo(VMObject::create_file_backed(move(inode)))
|
||||
, m_name(move(n))
|
||||
, m_readable(r)
|
||||
|
@ -29,9 +27,8 @@ Region::Region(LinearAddress a, size_t s, RetainPtr<Inode>&& inode, String&& n,
|
|||
MM.register_region(*this);
|
||||
}
|
||||
|
||||
Region::Region(LinearAddress a, size_t s, Retained<VMObject>&& vmo, size_t offset_in_vmo, String&& n, bool r, bool w, bool cow)
|
||||
: m_laddr(a)
|
||||
, m_size(s)
|
||||
Region::Region(const Range& range, Retained<VMObject>&& vmo, size_t offset_in_vmo, String&& n, bool r, bool w, bool cow)
|
||||
: m_range(range)
|
||||
, m_offset_in_vmo(offset_in_vmo)
|
||||
, m_vmo(move(vmo))
|
||||
, m_name(move(n))
|
||||
|
@ -83,7 +80,7 @@ Retained<Region> Region::clone()
|
|||
laddr().get());
|
||||
#endif
|
||||
// Create a new region backed by the same VMObject.
|
||||
return adopt(*new Region(laddr(), size(), m_vmo.copy_ref(), m_offset_in_vmo, String(m_name), m_readable, m_writable));
|
||||
return adopt(*new Region(m_range, m_vmo.copy_ref(), m_offset_in_vmo, String(m_name), m_readable, m_writable));
|
||||
}
|
||||
|
||||
#ifdef MM_DEBUG
|
||||
|
@ -96,7 +93,7 @@ Retained<Region> Region::clone()
|
|||
// Set up a COW region. The parent (this) region becomes COW as well!
|
||||
m_cow_map.fill(true);
|
||||
MM.remap_region(current->process().page_directory(), *this);
|
||||
return adopt(*new Region(laddr(), size(), m_vmo->clone(), m_offset_in_vmo, String(m_name), m_readable, m_writable, true));
|
||||
return adopt(*new Region(m_range, m_vmo->clone(), m_offset_in_vmo, String(m_name), m_readable, m_writable, true));
|
||||
}
|
||||
|
||||
int Region::commit()
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include <AK/AKString.h>
|
||||
#include <AK/Bitmap.h>
|
||||
#include <Kernel/VM/PageDirectory.h>
|
||||
#include <Kernel/VM/RangeAllocator.h>
|
||||
|
||||
class Inode;
|
||||
class VMObject;
|
||||
|
@ -10,13 +11,13 @@ class VMObject;
|
|||
class Region : public Retainable<Region> {
|
||||
friend class MemoryManager;
|
||||
public:
|
||||
Region(LinearAddress, size_t, String&&, bool r, bool w, bool cow = false);
|
||||
Region(LinearAddress, size_t, Retained<VMObject>&&, size_t offset_in_vmo, String&&, bool r, bool w, bool cow = false);
|
||||
Region(LinearAddress, size_t, RetainPtr<Inode>&&, String&&, bool r, bool w);
|
||||
Region(const Range&, String&&, bool r, bool w, bool cow = false);
|
||||
Region(const Range&, Retained<VMObject>&&, size_t offset_in_vmo, String&&, bool r, bool w, bool cow = false);
|
||||
Region(const Range&, RetainPtr<Inode>&&, String&&, bool r, bool w);
|
||||
~Region();
|
||||
|
||||
LinearAddress laddr() const { return m_laddr; }
|
||||
size_t size() const { return m_size; }
|
||||
LinearAddress laddr() const { return m_range.base(); }
|
||||
size_t size() const { return m_range.size(); }
|
||||
bool is_readable() const { return m_readable; }
|
||||
bool is_writable() const { return m_writable; }
|
||||
String name() const { return m_name; }
|
||||
|
@ -30,14 +31,15 @@ public:
|
|||
void set_shared(bool shared) { m_shared = shared; }
|
||||
|
||||
Retained<Region> clone();
|
||||
|
||||
bool contains(LinearAddress laddr) const
|
||||
{
|
||||
return laddr >= m_laddr && laddr < m_laddr.offset(size());
|
||||
return m_range.contains(laddr);
|
||||
}
|
||||
|
||||
unsigned page_index_from_address(LinearAddress laddr) const
|
||||
{
|
||||
return (laddr - m_laddr).get() / PAGE_SIZE;
|
||||
return (laddr - m_range.base()).get() / PAGE_SIZE;
|
||||
}
|
||||
|
||||
size_t first_page_index() const
|
||||
|
@ -52,7 +54,7 @@ public:
|
|||
|
||||
size_t page_count() const
|
||||
{
|
||||
return m_size / PAGE_SIZE;
|
||||
return size() / PAGE_SIZE;
|
||||
}
|
||||
|
||||
bool page_in();
|
||||
|
@ -82,8 +84,7 @@ public:
|
|||
|
||||
private:
|
||||
RetainPtr<PageDirectory> m_page_directory;
|
||||
LinearAddress m_laddr;
|
||||
size_t m_size { 0 };
|
||||
Range m_range;
|
||||
size_t m_offset_in_vmo { 0 };
|
||||
Retained<VMObject> m_vmo;
|
||||
String m_name;
|
||||
|
|
Loading…
Reference in a new issue