summaryrefslogtreecommitdiff
path: root/Kernel/VM/Region.h
AgeCommit message (Collapse)Author
2020-01-01Kernel: Share code between Region::map() and Region::remap_page()Andreas Kling
These were doing mostly the same things, so let's just share the code.
2019-12-29Kernel+SystemMonitor: Expose amount of per-process dirty private memoryAndreas Kling
Dirty private memory is all memory in non-inode-backed mappings that's process-private, meaning it's not shared with any other process. This patch exposes that number via SystemMonitor, giving us an idea of how much memory each process is responsible for all on its own.
2019-12-25Kernel: Clean up Region access bit setters a littleAndreas Kling
2019-12-19Kernel: Rename vmo => vmobject everywhereAndreas Kling
2019-12-18Kernel: Add a specific-page variant of Region::commit()Andreas Kling
2019-12-15Kernel+SystemMonitor: Prevent userspace access to process ELF imageAndreas Kling
Every process keeps its own ELF executable mapped in memory in case we need to do symbol lookup (for backtraces, etc.) Until now, it was mapped in a way that made it accessible to the program, despite the program not having mapped it itself. I don't really see a need for userspace to have access to this right now, so let's lock things down a little bit. This patch makes it inaccessible to userspace and exposes that fact through /proc/PID/vm (per-region "user_accessible" flag.)
2019-12-15Kernel+SystemMonitor: Expose the number of set CoW bits in each RegionAndreas Kling
This number tells us how many more pages in a given region will trigger a CoW fault if written to.
2019-12-02Kernel: Crash on memory access in non-readable regionsAndreas Kling
This patch makes it possible to make memory regions non-readable. This is enforced using the "present" bit in the page tables. A process that hits an not-present page fault in a non-readable region will be crashed.
2019-12-02Kernel: Fix bug where mprotect() would ignore setting PROT_WRITEAndreas Kling
A typo in Region::set_writable() caused us to update the readable flag rather than the writable flag.
2019-11-24Kernel: Mark mmap()-created regions with a special bitAndreas Kling
Then only allow regions with that bit to be manipulated via munmap() and mprotect(). This prevents messing with non-mmap()ed regions in a process's address space (stacks, shared buffers, ...)
2019-11-17Kernel: Implement some basic stack pointer validationAndreas Kling
VM regions can now be marked as stack regions, which is then validated on syscall, and on page fault. If a thread is caught with its stack pointer pointing into anything that's *not* a Region with its stack bit set, we'll crash the whole process with SIGSTKFLT. Userspace must now allocate custom stacks by using mmap() with the new MAP_STACK flag. This mechanism was first introduced in OpenBSD, and now we have it too, yay! :^)
2019-11-04Kernel: Move page fault handling from MemoryManager to RegionAndreas Kling
After the page fault handler has found the region in which the fault occurred, do the rest of the work in the region itself. This patch also makes all fault types consistently crash the process if a new page is needed but we're all out of pages.
2019-11-04Kernel: Don't expose a region's page directory to the outside worldAndreas Kling
Now that region manages its own mapping/unmapping, there's no need for the outside world to be able to grab at its page directory.
2019-11-04Kernel: Remove Region API's for setting/unsetting the page directoryAndreas Kling
This is done implicitly by mapping or unmapping the region.
2019-11-04Kernel: Fix weird Region constructor that took nullable RefPtr<Inode>Andreas Kling
It's never valid to construct a Region with a null Inode pointer using this constructor, so just take a NonnullRefPtr<Inode> instead.
2019-11-03Kernel: Teach Region how to remap itselfAndreas Kling
Now remapping (i.e flushing kernel metadata to the CPU page tables) is done by simply calling Region::remap().
2019-11-03Kernel: Regions should be mapped into a PageDirectory, not a ProcessAndreas Kling
This patch changes the parameter to Region::map() to be a PageDirectory since that matches how we think about the memory model: Regions are views onto VMObjects, and are mapped into PageDirectories. Each Process has a PageDirectory. The kernel also has a PageDirectory.
2019-11-03Kernel: Move region map/unmap operations into the Region classAndreas Kling
The more Region can take care of itself, the better.
2019-11-03Kernel: Move page remapping into Region::remap_page(index)Andreas Kling
Let Region deal with this, instead of everyone calling MemoryManager.
2019-10-01Kernel: Defer creation of Region CoW bitmaps until they're neededAndreas Kling
Instead of allocating and populating a Copy-on-Write bitmap for each Region up front, wait until we actually clone the Region for sharing with another process. In most cases, we never need any CoW bits and we save ourselves a lot of kmalloc() memory and time.
2019-10-01Kernel: Fix munmap() bad splitting of already-split RegionsAndreas Kling
When splitting an Region that's already the result of an earlier split, we have to take the Region's offset-in-VMObject into account since it may be non-zero.
2019-09-27Kernel: Make Region single-owner instead of ref-countedAndreas Kling
This simplifies the ownership model and makes Region easier to reason about. Userspace Regions are now primarily kept by Process::m_regions. Kernel Regions are kept in various OwnPtr<Regions>'s. Regions now only ever get unmapped when they are destroyed.
2019-09-16Kernel: Add a simple slab allocator for small allocationsAndreas Kling
This is a freelist allocator with static size classes that works as a complement to the generic kmalloc(). It's a lot faster than kmalloc() since allocation just means popping from the freelist. It's also significantly more compact when there are a lot of objects smaller than the minimum kmalloc chunk size (32 bytes.) This patch enables it for the Region and PhysicalPage classes. In the PhysicalPage (8 bytes) case, it's a huge improvement since we no longer waste 75% of the storage allocated. There are also a number of ways this can be improved, so let's keep working on it going forward.
2019-09-06AK: Rename <AK/AKString.h> to <AK/String.h>Andreas Kling
This was a workaround to be able to build on case-insensitive file systems where it might get confused about <string.h> vs <String.h>. Let's just not support building that way, so String.h can have an objectively nicer name. :^)
2019-09-04Kernel: Rename "vmo" to "vmobject" everywhereAndreas Kling
2019-08-29Kernel: Add some convenient getters to RegionAndreas Kling
Add getters for the underlying Range, the access bits, and also add contains(Range) which just wraps m_range.contains().
2019-08-26Kernel: Never forcibly page in entire executablesAndreas Kling
We were doing this for the initial kernel-spawned userspace process(es) to work around instability in the page fault handler. Now that the page fault handler is more robust, we can stop worrying about this. Specifically, the page fault handler was previous not able to handle getting a page fault in anything but the currently executing task's page directory.
2019-08-08Kernel: Put all Regions on InlineLinkedLists (separated by user/kernel)Andreas Kling
Remove the global hash tables and replace them with InlineLinkedLists. This significantly reduces the kernel heap pressure from doing many small mmap()'s.
2019-07-19Kernel: Track user accessibility per Region.Andreas Kling
Region now has is_user_accessible(), which informs the memory manager how to map these pages. Previously, we were just passing a "bool user_allowed" to various functions and I'm not at all sure that any of that was correct. All the Region constructors are now hidden, and you must go through one of these helpers to construct a region: - Region::create_user_accessible(...) - Region::create_kernel_only(...) That ensures that we don't accidentally create a Region without specifying user accessibility. :^)
2019-07-11Kernel: Remove use of copy_ref() in favor of regular RefPtr copies.Andreas Kling
This is obviously more readable. If we ever run into a situation where ref count churn is actually causing trouble in the future, we can deal with it then. For now, let's keep it simple. :^)
2019-07-03AK: Rename the common integer typedefs to make it obvious what they are.Andreas Kling
These types can be picked up by including <AK/Types.h>: * u8, u16, u32, u64 (unsigned) * i8, i16, i32, i64 (signed)
2019-06-21AK: Rename RetainPtr => RefPtr and Retained => NonnullRefPtr.Andreas Kling
2019-06-21AK: Rename Retainable => RefCounted.Andreas Kling
(And various related renames that go along with it.)
2019-06-07Kernel: Tweak some String&& => const String&.Andreas Kling
String&& is just not very practical. Also return const String& when the returned string is a member variable. The call site is free to make a copy if he wants, but otherwise we can avoid the retain count churn.
2019-06-07Meta: Tweak .clang-format to not wrap braces after enums.Andreas Kling
2019-06-07Kernel: Rename LinearAddress => VirtualAddress.Andreas Kling
2019-06-07Kernel: Run clang-format on everything.Andreas Kling
2019-05-30Kernel: Make the Process allocate_region* API's understand "int prot".Andreas Kling
Instead of having to inspect 'prot' at every call site, make the Process API's take care of that so we can just pass it through.
2019-05-28Add clang-format fileRobin Burchell
Also run it across the whole tree to get everything using the One True Style. We don't yet run this in an automated fashion as it's a little slow, but there is a snippet to do so in makeall.sh.
2019-05-17Kernel: Let Region keep a Range internally.Andreas Kling
2019-05-14Kernel: Encapsulate the Region's COW map a bit better.Andreas Kling
2019-05-02Kernel: Remove unused Region::is_bitmap().Andreas Kling
2019-04-14AK: Improve smart pointer ergonomics a bit.Andreas Kling
2019-04-03Kernel: Move VM-related files into Kernel/VM/.Andreas Kling
Also break MemoryManager.{cpp,h} into one file per class.