summaryrefslogtreecommitdiff
path: root/Kernel/Memory
AgeCommit message (Collapse)Author
2021-11-18Kernel: Make VirtualRangeAllocator setup functions propagate errorsAndreas Kling
If an internal allocation failure occurs while setting up a new VRA, we'll now propagate the error to our caller instead of panicking.
2021-11-18AK: Make RedBlackTree::try_insert() return ErrorOr<void> instead of boolAndreas Kling
2021-11-17Kernel: Automatically sync shared file mappings when unmappedAndreas Kling
To make sure we don't lose changes, shared file mappings will now be fully synced when they are unmapped, whether explicitly or implicitly (by the program exiting/crashing/etc.) This can incur a lot of work, since we don't keep track of dirty pages, but that's something we can optimize down the road. :^)
2021-11-17Kernel+LibC: Add msync() system callAndreas Kling
This allows userspace to trigger a full (FIXME) flush of a shared file mapping to disk. We iterate over all the mapped pages in the VMObject and write them out to the underlying inode, one by one. This is rather naive, and there's lots of room for improvement. Note that shared file mappings are currently not possible since mmap() returns ENOTSUP for PROT_WRITE+MAP_SHARED. That restriction will be removed in a subsequent commit. :^)
2021-11-17Kernel: Add MemoryManager::copy_physical_page()Andreas Kling
This is a handy helper that copies out the full contents of a physical page into a caller-provided buffer. It uses quickmapping internally (and takes the MM lock for the duration.)
2021-11-17AK: Convert AK::Format formatting helpers to returning ErrorOr<void>Andreas Kling
This isn't a complete conversion to ErrorOr<void>, but a good chunk. The end goal here is to propagate buffer allocation failures to the caller, and allow the use of TRY() with formatting functions.
2021-11-14Kernel: Suppress clang-tidy warning on declaration of s_mm_lockAndrew Kaster
Seems we are declaring this guy as extern RecursiveSpinLock s_mm_lock; in both Thread.h and MemoryManager.h. Smells funny for sure.
2021-11-14Kernel: Mark private members of SharedCommittedCowPages as privateAndrew Kaster
They were marked public, which seems like an obvious typo.
2021-11-14Kernel: Resolve clang-tidy readability-implicit-bool-conversion warningsAndrew Kaster
... In files included from Kernel/Process.cpp and Kernel/Thread.cpp
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-10Everywhere: Remove unused AK/Bitmap includesBen Wiederhake
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-10-26Kernel: Take VMObject lock once in Region::remap_vmobject_page()Andreas Kling
We were taking and releasing the lock repeatedly instead of holding it across the entire remap operation.
2021-10-22Kernel: Fix restrictions in is_allowed_to_mmap_to_userspace functionLiav A
This small change simplifies the function a bit but also fixes a problem with it. Let's take an example to see this: Let's say we have a reserved range between 0xe0000 to 0xfffff (EBDA), then we want to map from the memory device (/dev/mem) the entire EBDA to a program. If a program tries to map more than 131072 bytes, the current logic will work - the start address is 0xe0000, and ofcourse it's below the limit, hence it passes the first two restrictions. Then, the third if statement will fail if we try to mmap more than the said allowed bytes. However, let's take another scenario, where we try to mmap from 0xf0000 - but we try to mmap less than 131072 - but more than 65536. In such case, we again pass the first two if statements, but the third one is passed two, because it doesn't take into account the offseted address from the start of the reserved range (0xe0000). In such case, a user can easily mmap 65535 bytes above 0x100000. This might seem negligible. However, it's still a severe bug that can theoretically be exploited into a info leak or tampering with important kernel structures.
2021-10-15Kernel: Split SmapDisabler so header is platform independentJames Mintram
A new header file has been created in the Arch/ folder while the implementation has been moved into a CPP living in the X86 folder.
2021-10-07Kernel: Use find_largest_not_above in VirtualRangeAllocatorIdan Horowitz
Instead of iterating over the regions in the tree which is O(n), we can just use RedBlackTree's find_largest_not_above method, which is O(logn)
2021-10-02Kernel: Access MemoryManager static functions staticallyBrian Gianforcaro
SonarCloud flagged this "Code Smell", where we are accessing these static methods as if they are instance methods. While it is technically possible, it is very confusing to read when you realize they are static functions.
2021-10-01Kernel: Fix a few typosNico Weber
2021-09-18Kernel/Memory: Add more super pages to satisfy contiguous allocationsLiav A
When testing the RTL8168 driver, it seems we can't allocate super pages anymore. Either we expand the super pages range, or find a solution to dynamically expand the range (or let drivers utilize other ranges).
2021-09-16Kernel: Fetch range once for each iteration of find_regions_intersectingBrian Gianforcaro
pvs-studio flagged this as a potential optimization.
2021-09-11Kernel: Fix off-by-one in Memory::is_user_range() checkAndreas Kling
This function was checking 1 byte after the provided range, which caused it to reject valid userspace ranges that happened to end exactly at the top of the user address space. This fixes a long-standing issue with mysterious Optional errors in Coredump::write_regions(). (It happened when trying to add a memory region at the very top of the address space to a coredump.)
2021-09-10AK+Kernel: Reduce the number of template parameters of IntrusiveRBTreeAli Mohammad Pur
This makes the user-facing type only take the node member pointer, and lets the compiler figure out the other needed types from that.
2021-09-10AK+Everywhere: Reduce the number of template parameters of IntrusiveListAli Mohammad Pur
This makes the user-facing type only take the node member pointer, and lets the compiler figure out the other needed types from that.
2021-09-08Kernel: Use an IntrusiveRedBlackTree for storing the cr3 mappingsIdan Horowitz
This ensures we don't allocate when intializing the PageDirectory.
2021-09-07Kernel: Make UserOrKernelBuffer return KResult from read/write/memsetAndreas Kling
This allows us to simplify a whole bunch of call sites with TRY(). :^)
2021-09-07Kernel: Specify a lock rank for s_mm_lockBrian Gianforcaro
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: Rename ProcessPagingScope => ScopedAddressSpaceSwitcherAndreas Kling
2021-09-06Kernel: Improve API names for switching address spacesAndreas Kling
- enter_space => enter_address_space - enter_process_paging_scope => enter_process_address_space
2021-09-06Kernel: Use KResultOr and TRY() for {Shared,Private}InodeVMObjectAndreas Kling
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 kernel region allocators return KResultOr<NOP<Region>>Andreas Kling
This expands the reach of error propagation greatly throughout the kernel. Sadly, it also exposes the fact that we're allocating (and doing other fallible things) in constructors all over the place. This patch doesn't attempt to address that of course. That's work for our future selves.
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-06Kernel: Use TRY() and adopt_nonnull_ref_or_enomem() in AnonymousVMObjectAndreas Kling
2021-09-06Kernel: Actually share committed CoW pagesAndreas Kling
Due to a double-move mistake, we were always clearing the shared committed CoW pages in the parent when forking.
2021-09-06Kernel: Make MM.commit_user_physical_pages() return KResultOrAndreas Kling
..and use TRY() at call sites. :^)
2021-09-05Kernel: Make all Spinlocks use u8 for storage, remove templateBrian Gianforcaro
The default template argument is only used in one place, and it looks like it was probably just an oversight. The rest of the Kernel code all uses u8 as the type. So lets make that the default and remove the unused template argument, as there doesn't seem to be a reason to allow the size to be customizable.
2021-09-05Kernel: Use TRY() in AnonymousVMObjectAndreas Kling
2021-09-05Kernel: Use TRY() in RegionAndreas Kling
2021-09-05Kernel: Unbreak x86_64 build (PageDirectory)Andreas Kling
2021-09-05Kernel: Tidy up Memory::AddressSpace constructionAndreas Kling
- Return KResultOr<T> in places - Propagate errors - Use TRY()
2021-09-05Kernel: Use TRY() in Memory::AddressSpaceAndreas Kling
2021-09-05AK+Kernel: Move KResult.h to Kernel/API for userspace accesssin-ack
This commit moves the KResult and KResultOr objects to Kernel/API to signify that they may now be freely used by userspace code at points where a syscall-related error result is to be expected. It also exposes KResult and KResultOr to the global namespace to make it nicer to use for userspace code.
2021-09-03Kernel: Don't use {:p} when printing out invalid userspace stack pointerLuke Wilde
`userspace_esp` is a virtual address and thus using `{:p}` on it is invalid and will cause an assertion failure. I ran into this while testing #9772.
2021-09-03AK: Rename create<T> => make_ref_counted<T>Andreas Kling
And also try_create<T> => try_make_ref_counted<T>. A global "create" was a bit much. The new name matches make<T> better, which we've used for making single-owner objects since forever.
2021-08-29Kernel: Rename Spinlock::is_owned_by_current_thread()Andreas Kling
...to is_owned_by_current_processor(). As Tom pointed out, this is much more accurate. :^)
2021-08-29Kernel: {Mutex,Spinlock}::own_lock() => is_locked_by_current_thread()Andreas Kling
Rename these API's to make it more clear what they are checking.
2021-08-25Kernel: Annotate Memory::Region APIs with [[nodiscard]]Brian Gianforcaro
This is an attempt to mitigate callers not observing the result of map or remap.