summaryrefslogtreecommitdiff
path: root/Kernel/Memory/AddressSpace.cpp
AgeCommit message (Collapse)Author
2023-04-06Kernel: Store a pointer to the owner process in PageDirectoryIdan Horowitz
This replaces the previous owning address space pointer. This commit should not change any of the existing functionality, but it lays down the groundwork needed to let us properly access the region table under the address space spinlock during page fault handling.
2022-12-28Kernel: Remove i686 supportLiav A
2022-12-16Kernel/Memory: Add option to annotate region mapping as immutableLiav A
We add this basic functionality to the Kernel so Userspace can request a particular virtual memory mapping to be immutable. This will be useful later on in the DynamicLoader code. The annotation of a particular Kernel Region as immutable implies that the following restrictions apply, so these features are prohibited: - Changing the region's protection bits - Unmapping the region - Annotating the region with other virtual memory flags - Applying further memory advises on the region - Changing the region name - Re-mapping the region
2022-08-24Kernel: Don't wrap AddressSpace's RegionTree in SpinlockProtectedAndreas Kling
Now that AddressSpace itself is always SpinlockProtected, we don't need to also wrap the RegionTree. Whoever has the AddressSpace locked is free to poke around its tree.
2022-08-24Kernel: Make file-backed memory regions remember description permissionsAndreas Kling
This allows sys$mprotect() to honor the original readable & writable flags of the open file description as they were at the point we did the original sys$mmap(). IIUC, this is what Dr. POSIX wants us to do: https://pubs.opengroup.org/onlinepubs/9699919799/functions/mprotect.html Also, remove the bogus and racy "W^X" checking we did against mappings based on their current inode metadata. If we want to do this, we can do it properly. For now, it was not only racy, but also did blocking I/O while holding a spinlock.
2022-08-24Kernel: Don't hog the MM lock while unmapping regionsAndreas Kling
We were holding the MM lock across all of the region unmapping code. This was previously necessary since the quickmaps used during unmapping required holding the MM lock. Now that it's no longer necessary, we can leave the MM lock alone here.
2022-08-24Kernel: Wrap RegionTree objects in SpinlockProtectedAndreas Kling
This makes locking them much more straightforward, and we can remove a bunch of confusing use of AddressSpace::m_lock. That lock will also be converted to use of SpinlockProtected in a subsequent patch.
2022-08-20Kernel: Make self-contained locking smart pointers their own classesAndreas Kling
Until now, our kernel has reimplemented a number of AK classes to provide automatic internal locking: - RefPtr - NonnullRefPtr - WeakPtr - Weakable This patch renames the Kernel classes so that they can coexist with the original AK classes: - RefPtr => LockRefPtr - NonnullRefPtr => NonnullLockRefPtr - WeakPtr => LockWeakPtr - Weakable => LockWeakable The goal here is to eventually get rid of the Lock* classes in favor of using external locking.
2022-08-19Kernel/Memory: Use scope guard to remove a region if we failed to map itLiav A
2022-08-18Kernel: Don't require MM lock for Region::set_page_directory()Andreas Kling
The MM lock is not required for this, it's just a simple ref-counted pointer assignment.
2022-08-15Kernel: Remove regions from the region tree after failing to map themIdan Horowitz
At the point at which we try to map the Region it was already added to the Process region tree, so we have to make sure to remove it before freeing it in the mapping failure path, otherwise the tree will contain a dangling pointer to the free'd instance.
2022-07-15Kernel: Add some inline capacity to find_regions_intersectingHendiadyoin1
This should avoid some allocations during simple cases of munmap, mprotect and msync, where you usually don't have a lot of regions anyway
2022-06-21Kernel: Decrease the amount of address space offset randomizationTim Schumacher
This is basically unchanged since the beginning of 2020, which is a year before we had proper ASLR. Now that we have a proper ASLR implementation, we can turn this down a bit, as it is no longer our only protection against predictable dynamic loader addresses, and it actually obstructs the default loading address of x86_64 quite frequently.
2022-04-05Kernel: Add RegionTree::find_region_containing(address or range)Andreas Kling
Let's encapsulate looking up regions so clients don't have to dig into RegionTree internals.
2022-04-05Kernel: Add RegionTree::remove(Region&)Andreas Kling
This allows clients to remove a region from the tree without reaching into the RegionTree internals.
2022-04-05Kernel: Take the RegionTree spinlock when inspecting tree from outsideAndreas Kling
This patch adds RegionTree::get_lock() which exposes the internal lock inside RegionTree. We can then lock it from the outside when doing lookups or traversal. This solution is not very beautiful, we should find a way to protect this data with SpinlockProtected or something similar. This is a stopgap patch to try and fix the currently flaky CI.
2022-04-05Kernel: Remove unused ShouldDeallocateVirtualRange parametersAndreas Kling
Since there is no separate virtual range allocator anymore, this is no longer used for anything.
2022-04-04Kernel: Use the InstrusiveRedBlackTree::begin_from(V&) APIIdan Horowitz
This let's us skip an O(logn) tree traversal.
2022-04-03Kernel: Unbreak ASLR in the new RegionTree worldAndreas Kling
Functions that allocate and/or place a Region now take a parameter that tells it whether to randomize unspecified addresses.
2022-04-03Kernel: Make VM allocation atomic for userspace regionsAndreas Kling
This patch move AddressSpace (the per-process memory manager) to using the new atomic "place" APIs in RegionTree as well, just like we did for MemoryManager in the previous commit. This required updating quite a few places where VM allocation and actually committing a Region object to the AddressSpace were separated by other code. All you have to do now is call into AddressSpace once and it'll take care of everything for you.
2022-04-03Kernel: Add Memory::RegionTree to share code between AddressSpace and MMAndreas Kling
RegionTree holds an IntrusiveRedBlackTree of Region objects and vends a set of APIs for allocating memory ranges. It's used by AddressSpace at the moment, and will be used by MM soon.
2022-04-03Kernel: Use AddressSpace region tree for range allocationAndreas Kling
This patch stops using VirtualRangeAllocator in AddressSpace and instead looks for holes in the region tree when allocating VM space. There are many benefits: - VirtualRangeAllocator is non-intrusive and would call kmalloc/kfree when used. This new solution is allocation-free. This was a source of unpleasant MM/kmalloc deadlocks. - We consolidate authority on what the address space looks like in a single place. Previously, we had both the range allocator *and* the region tree both being used to determine if an address was valid. Now there is only the region tree. - Deallocation of VM when splitting regions is no longer complicated, as we don't need to keep two separate trees in sync.
2022-04-03Kernel: Store AddressSpace memory regions in an IntrusiveRedBlackTreeAndreas Kling
This means we never need to allocate when inserting/removing regions from the address space.
2022-04-02Kernel: Make AddressSpace.cpp compile on aarch64James Mintram
2022-04-01Everywhere: Run clang-formatIdan Horowitz
2022-03-17Kernel: Use default constructors/destructorsLenny Maiorani
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#cother-other-default-operation-rules "The compiler is more likely to get the default semantics right and you cannot implement these functions better than the compiler."
2022-02-11Kernel: Set up Regions before adding them to a Process's AddressSpaceIdan Horowitz
This reduces the amount of time in which not fully-initialized Regions are present inside an AddressSpace's region tree.
2022-02-11Kernel: Make AnonymousVMObject COW-Bitmap allocation OOM-fallibleIdan Horowitz
2022-01-30Kernel: Release page directory and MM locks sooner in space finalizationAndreas Kling
We don't need to hold these locks when tearing down the region tree. Release them as soon as unmapping is finished.
2022-01-30Kernel: Remove unnecessary includes from Thread.hAndreas Kling
...and deal with the fallout by adding missing includes everywhere.
2022-01-26Kernel: Make AddressSpace::find_regions_intersecting OOM-fallibleIdan Horowitz
2022-01-26Kernel: Make AddressSpace::amount_clean_inode() OOM-fallibleIdan Horowitz
2022-01-15Kernel: Don't bother with page tables for PROT_NONE mappingsAndreas Kling
When mapping or unmapping completely inaccessible memory regions, we don't need to update the page tables at all. This saves a bunch of time in some situations, most notably during dynamic linking, where we make a large VM reservation and immediately throw it away. :^)
2022-01-15Kernel: Remove old "region lookup cache" optimizationAndreas Kling
This optimization was added when region lookup was O(n), before we had the O(log n) RedBlackTree. Let's remove it to simplify the code, as we have no evidence that it remains valuable.
2022-01-13Kernel: Don't flush TLB after creating brand-new mappingsAndreas Kling
The CPU will not cache TLB entries for non-present mappings, so we can simply skip flushing the TLB after creating entirely new mappings.
2022-01-12Kernel: Don't release/relock spinlocks repeatedly during space teardownAndreas Kling
Grab the page directory and MM locks once at the start of address space teardown, then hold onto them across all the region unmapping work.
2022-01-12Kernel: Do less unnecessary work when tearing down process address spaceAndreas Kling
When deleting an entire AddressSpace, we don't need to do TLB flushes at all (since the entire page directory is going away anyway). We also don't need to deallocate VM ranges one by one, since the entire VM range allocator will be deleted anyway.
2022-01-09Kernel: Add implied auto qualifiers in MemoryHendiadyoin1
2021-12-28Kernel: Propagate overflow errors from Memory::page_round_upGuilherme Goncalves
Fixes #11402.
2021-12-05Kernel: Cast unused smart-pointer return value to voidSam Atkins
2021-11-18AK: Make RedBlackTree::try_insert() return ErrorOr<void> instead of boolAndreas Kling
2021-11-10AK: Make Vector::try_* functions return ErrorOr<void>Andreas Kling
Instead of signalling allocation failure with a bool return value (false), we now use ErrorOr<void> and return ENOMEM as appropriate. This allows us to use TRY() and MUST() with Vector. :^)
2021-11-08Kernel: Replace KResult and KResultOr<T> with Error and ErrorOr<T>Andreas Kling
We now use AK::Error and AK::ErrorOr<T> in both kernel and userspace! This was a slightly tedious refactoring that took a long time, so it's not unlikely that some bugs crept in. Nevertheless, it does pass basic functionality testing, and it's just real nice to finally see the same pattern in all contexts. :^)
2021-09-16Kernel: Fetch range once for each iteration of find_regions_intersectingBrian Gianforcaro
pvs-studio flagged this as a potential optimization.
2021-09-06Kernel: Make KString factories return KResultOr + use TRY() everywhereAndreas Kling
There are a number of places that don't have an error propagation path right now, so I've added FIXME's about that.
2021-09-06Kernel: Make Memory::Region::map() return KResultAndreas Kling
..and use TRY() at the call sites to propagate errors. :^)
2021-09-06Kernel: Make AddressSpace::add_region() return KResultOr<Region*>Andreas Kling
This allows us to use TRY() in a few places.
2021-09-06Kernel: Use TRY() some more in Memory::AddressSpaceAndreas Kling
2021-09-06Kernel: Make VirtualRangeAllocator return KResultOr<VirtualRange>Andreas Kling
This achieves two things: - The allocator can report more specific errors - Callers can (and now do) use TRY() :^)
2021-09-05Kernel: Tidy up Memory::AddressSpace constructionAndreas Kling
- Return KResultOr<T> in places - Propagate errors - Use TRY()