summaryrefslogtreecommitdiff
path: root/Kernel/MemoryManager.cpp
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2018-10-22 15:42:39 +0200
committerAndreas Kling <awesomekling@gmail.com>2018-10-22 15:43:02 +0200
commitb824f156197d8f2552442ecf0c8073ff28308941 (patch)
treea69fcf864f51668dbfca80a23089508b9f250793 /Kernel/MemoryManager.cpp
parentbefeabd8fe47e6d33b0e5648d7db8dbff5eb280e (diff)
downloadserenity-b824f156197d8f2552442ecf0c8073ff28308941.zip
Launching an arbitrary ELF executable from disk works! :^)
This is so cool! It's a bit messy now with two Task constructors, but eventually they should fold into a single constructor somehow.
Diffstat (limited to 'Kernel/MemoryManager.cpp')
-rw-r--r--Kernel/MemoryManager.cpp29
1 files changed, 18 insertions, 11 deletions
diff --git a/Kernel/MemoryManager.cpp b/Kernel/MemoryManager.cpp
index 1d85aca254..019242a741 100644
--- a/Kernel/MemoryManager.cpp
+++ b/Kernel/MemoryManager.cpp
@@ -161,20 +161,27 @@ bool MemoryManager::unmapRegionsForTask(Task& task)
return true;
}
+bool MemoryManager::mapRegion(Task& task, Task::Region& region)
+{
+ auto& zone = *region.zone;
+ for (size_t i = 0; i < zone.m_pages.size(); ++i) {
+ auto laddr = region.linearAddress.offset(i * PAGE_SIZE);
+ auto pte = ensurePTE(laddr);
+ pte.setPhysicalPageBase(zone.m_pages[i].get());
+ pte.setPresent(true);
+ pte.setWritable(true);
+ pte.setUserAllowed(!task.isRing0());
+
+ //kprintf("MM: >> Mapped L%x => P%x <<\n", laddr, zone.m_pages[i].get());
+ }
+ return true;
+}
+
bool MemoryManager::mapRegionsForTask(Task& task)
{
for (auto& region : task.m_regions) {
- auto& zone = *region->zone;
- for (size_t i = 0; i < zone.m_pages.size(); ++i) {
- auto laddr = region->linearAddress.offset(i * PAGE_SIZE);
- auto pte = ensurePTE(laddr);
- pte.setPhysicalPageBase(zone.m_pages[i].get());
- pte.setPresent(true);
- pte.setWritable(true);
- pte.setUserAllowed(!task.isRing0());
-
- //kprintf("MM: >> Mapped L%x => P%x <<\n", laddr, zone.m_pages[i].get());
- }
+ if (!mapRegion(task, *region))
+ return false;
}
return true;
}