summaryrefslogtreecommitdiff
path: root/Kernel
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-02-05 06:43:33 +0100
committerAndreas Kling <awesomekling@gmail.com>2019-02-05 06:43:33 +0100
commita258d6507a9d4c7ec7bd951fd51d16e67fc2b561 (patch)
tree1792527c5a0e0d4e411e47d90e41551de31e76e9 /Kernel
parent612c02307e9d721e8939da46e361aeb7dbdb3e0c (diff)
downloadserenity-a258d6507a9d4c7ec7bd951fd51d16e67fc2b561.zip
mmap all the font files!
Font now uses the same in-memory format as the font files we have on disk. This allows us to simply mmap() the font files and not use any additional memory for them. Very cool! :^) Hacking on this exposed a bug in file-backed VMObjects where the first client to instantiate a VMObject for a specific inode also got to decide its size. Since file-backed VMObjects always have the same size as the underlying file, this made no sense, so I removed the ability to even set a size in that case.
Diffstat (limited to 'Kernel')
-rw-r--r--Kernel/MemoryManager.cpp31
-rw-r--r--Kernel/MemoryManager.h4
-rw-r--r--Kernel/Process.cpp2
-rw-r--r--Kernel/Process.h1
-rw-r--r--Kernel/i386.h10
5 files changed, 28 insertions, 20 deletions
diff --git a/Kernel/MemoryManager.cpp b/Kernel/MemoryManager.cpp
index 81b8842087..ad087917a1 100644
--- a/Kernel/MemoryManager.cpp
+++ b/Kernel/MemoryManager.cpp
@@ -304,15 +304,12 @@ bool MemoryManager::page_in_from_inode(Region& region, unsigned page_index_in_re
auto& vmo_page = vmo.physical_pages()[region.first_page_index() + page_index_in_region];
- bool interrupts_were_enabled = are_interrupts_enabled();
-
- if (!interrupts_were_enabled)
- sti();
+ // FIXME: Maybe this should have a separate class like InterruptFlagSaver?
+ InterruptDisabler disabler;
+ disabler.temporarily_sti();
LOCKER(vmo.m_paging_lock);
-
- if (!interrupts_were_enabled)
- cli();
+ disabler.temporarily_cli();
if (!vmo_page.is_null()) {
kprintf("MM: page_in_from_inode() but page already present. Fine with me!\n");
@@ -321,9 +318,9 @@ bool MemoryManager::page_in_from_inode(Region& region, unsigned page_index_in_re
}
#ifdef MM_DEBUG
- dbgprintf("MM: page_in_from_inode ready to read from inode, will write to L%x!\n", dest_ptr);
+ dbgprintf("MM: page_in_from_inode ready to read from inode\n");
#endif
- sti(); // Oh god here we go...
+ disabler.temporarily_sti();
byte page_buffer[PAGE_SIZE];
auto& inode = *vmo.inode();
auto nread = inode.read_bytes(vmo.inode_offset() + ((region.first_page_index() + page_index_in_region) * PAGE_SIZE), PAGE_SIZE, page_buffer, nullptr);
@@ -335,7 +332,7 @@ bool MemoryManager::page_in_from_inode(Region& region, unsigned page_index_in_re
// If we read less than a page, zero out the rest to avoid leaking uninitialized data.
memset(page_buffer + nread, 0, PAGE_SIZE - nread);
}
- cli();
+ disabler.temporarily_cli();
vmo_page = allocate_physical_page(ShouldZeroFill::No);
if (vmo_page.is_null()) {
kprintf("MM: page_in_from_inode was unable to allocate a physical page\n");
@@ -610,7 +607,7 @@ Region::Region(LinearAddress a, size_t s, String&& n, bool r, bool w, bool cow)
Region::Region(LinearAddress a, size_t s, RetainPtr<Inode>&& inode, String&& n, bool r, bool w)
: m_laddr(a)
, m_size(s)
- , m_vmo(VMObject::create_file_backed(move(inode), s))
+ , m_vmo(VMObject::create_file_backed(move(inode)))
, m_name(move(n))
, m_readable(r)
, m_writable(w)
@@ -661,13 +658,12 @@ void PhysicalPage::return_to_freelist()
#endif
}
-RetainPtr<VMObject> VMObject::create_file_backed(RetainPtr<Inode>&& inode, size_t size)
+RetainPtr<VMObject> VMObject::create_file_backed(RetainPtr<Inode>&& inode)
{
InterruptDisabler disabler;
if (inode->vmo())
return static_cast<VMObject*>(inode->vmo());
- size = ceil_div(size, PAGE_SIZE) * PAGE_SIZE;
- auto vmo = adopt(*new VMObject(move(inode), size));
+ auto vmo = adopt(*new VMObject(move(inode)));
vmo->inode()->set_vmo(vmo.ptr());
return vmo;
}
@@ -720,10 +716,11 @@ VMObject::VMObject(PhysicalAddress paddr, size_t size)
}
-VMObject::VMObject(RetainPtr<Inode>&& inode, size_t size)
- : m_size(size)
- , m_inode(move(inode))
+VMObject::VMObject(RetainPtr<Inode>&& inode)
+ : m_inode(move(inode))
{
+ ASSERT(m_inode);
+ m_size = ceil_div(m_inode->size(), PAGE_SIZE) * PAGE_SIZE;
m_physical_pages.resize(page_count());
MM.register_vmo(*this);
}
diff --git a/Kernel/MemoryManager.h b/Kernel/MemoryManager.h
index c2473efa76..098e27e938 100644
--- a/Kernel/MemoryManager.h
+++ b/Kernel/MemoryManager.h
@@ -79,7 +79,7 @@ private:
class VMObject : public Retainable<VMObject> {
friend class MemoryManager;
public:
- static RetainPtr<VMObject> create_file_backed(RetainPtr<Inode>&&, size_t);
+ static RetainPtr<VMObject> create_file_backed(RetainPtr<Inode>&&);
static RetainPtr<VMObject> create_anonymous(size_t);
static RetainPtr<VMObject> create_framebuffer_wrapper(PhysicalAddress, size_t);
RetainPtr<VMObject> clone();
@@ -99,7 +99,7 @@ public:
Vector<RetainPtr<PhysicalPage>>& physical_pages() { return m_physical_pages; }
private:
- VMObject(RetainPtr<Inode>&&, size_t);
+ VMObject(RetainPtr<Inode>&&);
explicit VMObject(VMObject&);
explicit VMObject(size_t);
VMObject(PhysicalAddress, size_t);
diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp
index c609e36044..f7672988c7 100644
--- a/Kernel/Process.cpp
+++ b/Kernel/Process.cpp
@@ -325,7 +325,7 @@ int Process::do_exec(const String& path, Vector<String>&& arguments, Vector<Stri
#endif
ProcessPagingScope paging_scope(*this);
- auto vmo = VMObject::create_file_backed(descriptor->inode(), descriptor->metadata().size);
+ auto vmo = VMObject::create_file_backed(descriptor->inode());
vmo->set_name(descriptor->absolute_path());
RetainPtr<Region> region = allocate_region_with_vmo(LinearAddress(), descriptor->metadata().size, vmo.copy_ref(), 0, "helper", true, false);
diff --git a/Kernel/Process.h b/Kernel/Process.h
index ca4d68d689..08c535d59d 100644
--- a/Kernel/Process.h
+++ b/Kernel/Process.h
@@ -52,6 +52,7 @@ class Process : public InlineLinkedListNode<Process>, public Weakable<Process> {
friend class InlineLinkedListNode<Process>;
friend class WSWindowManager; // FIXME: Make a better API for allocate_region().
friend class GraphicsBitmap; // FIXME: Make a better API for allocate_region().
+ friend class Font; //FIXME: This is beyond gross.
public:
static Process* create_kernel_process(String&& name, void (*entry)());
static Process* create_user_process(const String& path, uid_t, gid_t, pid_t ppid, int& error, Vector<String>&& arguments = Vector<String>(), Vector<String>&& environment = Vector<String>(), TTY* = nullptr);
diff --git a/Kernel/i386.h b/Kernel/i386.h
index ad25551f41..23a84e0ab9 100644
--- a/Kernel/i386.h
+++ b/Kernel/i386.h
@@ -120,6 +120,16 @@ public:
sti();
}
+ void temporarily_cli()
+ {
+ cli();
+ }
+
+ void temporarily_sti()
+ {
+ sti();
+ }
+
private:
dword m_flags;
};