summaryrefslogtreecommitdiff
path: root/Kernel/VM/Space.cpp
AgeCommit message (Collapse)Author
2021-08-06Kernel: Rename Kernel/VM/ to Kernel/Memory/Andreas Kling
This directory isn't just about virtual memory, it's about all kinds of memory management.
2021-08-06Kernel: Simplify PageDirectory allocation failureAndreas Kling
This patch gets rid of the "valid" bit in PageDirectory since it was only used to communicate an allocation failure during construction. We now do all the work in the static factory functions instead of in the constructor, which allows us to simply return nullptr instead of an "invalid" PageDirectory.
2021-07-30Kernel: Unmapping a non-mapped region with munmap() should be a no-opAndreas Kling
Not a regression per se from 0fcb9efd86da4c15a1aee87503348c5bee875c51 since we were crashing before that which is obviously worse.
2021-07-30Kernel: Return an error when unmap finds no intersecting regionBrian Gianforcaro
We currently always crash if a user attempts to unmap a range that does not intersect with an existing region, no matter the size. This happens because we will never explicitly check to see if the search for intersecting regions found anything, instead loop over the results, which might be an empty vector. We then attempt to deallocate the requested range from the `RangeAllocator` unconditionally, which will be invalid if the specified range is not managed by the RangeAllocator. We will assert validating m_total_range.contains(..) the range we are requesting to deallocate. This fix to this is straight forward, error out if we weren't able to find any intersections. You can get stress-ng to attempt this pattern with the following arguments, which will attempt to unmap 0x0 through some large offset: ``` stress-ng --vm-segv 1 ``` Fixes: #8483 Co-authored-by: Federico Guerinoni <guerinoni.federico@gmail.com>
2021-07-27Kernel: Improve some comments in SpaceAndreas Kling
Remove bogus FIXME's and improve some comments.
2021-07-27Kernel: Rename Space::create => Space::try_create()Andreas Kling
2021-07-25Kernel: Remove unnecessary weak pointer from Region to owning ProcessAndreas Kling
This was previously used for a single debug logging statement during memory purging. There are no remaining users of this weak pointer, so let's get rid of it.
2021-07-25Kernel: Make purgeable memory a VMObject level concept (again)Andreas Kling
This patch changes the semantics of purgeable memory. - AnonymousVMObject now has a "purgeable" flag. It can only be set when constructing the object. (Previously, all anonymous memory was effectively purgeable.) - AnonymousVMObject now has a "volatile" flag. It covers the entire range of physical pages. (Previously, we tracked ranges of volatile pages, effectively making it a page-level concept.) - Non-volatile objects maintain a physical page reservation via the committed pages mechanism, to ensure full coverage for page faults. - When an object is made volatile, it relinquishes any unused committed pages immediately. If later made non-volatile again, we then attempt to make a new committed pages reservation. If this fails, we return ENOMEM to userspace. mmap() now creates purgeable objects if passed the MAP_PURGEABLE option together with MAP_ANONYMOUS. anon_create() memory is always purgeable.
2021-07-22Kernel: Make sure crash dumps are properly aligned on x86_64Gunnar Beutner
2021-07-22Everywhere: Prefix hexadecimal numbers with 0xGunnar Beutner
Depending on the values it might be difficult to figure out whether a value is decimal or hexadecimal. So let's make this more obvious. Also this allows copying and pasting those numbers into GNOME calculator and probably also other apps which auto-detect the base.
2021-07-17Kernel: Remove double RedBlackTree lookup in VM/Space region removalBrian Gianforcaro
We should never request a regions removal that we don't currently own. We currently assert this everywhere else by all callers. Instead lets just push the assert down into the RedBlackTree removal and assume that we will always successfully remove the region.
2021-07-15Kernel: Handle OOM when adding memory regions to Spaces :^)Idan Horowitz
2021-07-11Kernel: Make Region splitting OOM-safeAndreas Kling
Region allocation failures during splitting are now propagated all the way out to where we can return ENOMEM for them.
2021-07-11Kernel: Make Region::try_create_user_accessible() OOM-safeAndreas Kling
Previously we would simply assume that Region allocation always succeeded. There is still one such assumption when splitting user regions inside a Space. That will be dealt with in a separate commit.
2021-07-11Kernel: Rename various *VMObject::create*() => try_create()Andreas Kling
try_*() implies that it can fail (and they all return RefPtr with nullptr signalling failure.)
2021-06-24Everywhere: Use nothrow new with `adopt_{ref,own}_if_nonnull`Daniel Bertalan
This commit converts naked `new`s to `AK::try_make` and `AK::try_create` wherever possible. If the called constructor is private, this can not be done, so we instead now use the standard-defined and compiler-agnostic `new (nothrow)`.
2021-06-12AK: Rename Vector::append(Vector) => Vector::extend(Vector)Andreas Kling
Let's make it a bit more clear when we're appending the elements from one vector to the end of another vector.
2021-05-29Everywhere: Sort out superfluous QuickSort.h importsBen Wiederhake
They were sorta unneeded. :^)
2021-05-29Kernel: Move sys$munmap functionality into a helper methodGunnar Beutner
2021-05-29Kernel: Make Space::create API OOM safeBrian Gianforcaro
2021-05-28Kernel: Use KString for Region namesAndreas Kling
Replace the AK::String used for Region::m_name with a KString. This seems beneficial across the board, but as a specific data point, it reduces time spent in sys$set_mmap_name() by ~50% on test-js. :^)
2021-04-22Everything: Move to SPDX license identifiers in all files.Brian Gianforcaro
SPDX License Identifiers are a more compact / standardized way of representing file license information. See: https://spdx.dev/resources/use/#identifiers This was done with the `ambr` search and replace tool. ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
2021-04-12Kernel: Replace process' regions vector with a Red Black treeIdan Horowitz
This should provide some speed up, as currently searches for regions containing a given address were performed in O(n) complexity, while this container allows us to do those in O(logn).
2021-04-12Kernel: Remove old region from process' regions vector before splittingIdan Horowitz
This does not affect functionality right now, but it means that the regions vector will now never have any overlapping regions, which will allow the use of balance binary search trees instead of a vector in the future. (since they require keys to be exclusive)
2021-03-13Kernel: Implement helper to find multiple Regions in a RangeHendiadyoin1
2021-02-23Everywhere: Rename ASSERT => VERIFYAndreas Kling
(...and ASSERT_NOT_REACHED => VERIFY_NOT_REACHED) Since all of these checks are done in release builds as well, let's rename them to VERIFY to prevent confusion, as everyone is used to assertions being compiled out in release. We can introduce a new ASSERT macro that is specifically for debug checks, but I'm doing this wholesale conversion first since we've accumulated thousands of these already, and it's not immediately obvious which ones are suitable for ASSERT.
2021-02-14Kernel: Assert if rounding-up-to-page-size would wrap around to 0Andreas Kling
If we try to align a number above 0xfffff000 to the next multiple of the page size (4 KiB), it would wrap around to 0. This is most likely never what we want, so let's assert if that happens.
2021-02-14Kernel: Remove user/kernel flags from RegionAndreas Kling
Now that we no longer need to support the signal trampolines being user-accessible inside the kernel memory range, we can get rid of the "kernel" and "user-accessible" flags on Region and simply use the address of the region to determine whether it's kernel or user. This also tightens the page table mapping code, since it can now set user-accessibility based solely on the virtual address of a page.
2021-02-12Kernel: Move region dumps from dmesg to debug logAndreas Kling
Also fix a broken format string caught by the new format string checks.
2021-02-08Kernel: Always hold space lock while calculating memory statisticsAndreas Kling
And put the locker at the top of the functions for clarity.
2021-02-08Kernel: Move memory statistics helpers from Process to SpaceAndreas Kling
2021-02-08Kernel: Factor address space management out of the Process classAndreas Kling
This patch adds Space, a class representing a process's address space. - Each Process has a Space. - The Space owns the PageDirectory and all Regions in the Process. This allows us to reorganize sys$execve() so that it constructs and populates a new Space fully before committing to it. Previously, we would construct the new address space while still running in the old one, and encountering an error meant we had to do tedious and error-prone rollback. Those problems are now gone, replaced by what's hopefully a set of much smaller problems and missing cleanups. :^)