aboutsummaryrefslogtreecommitdiff
path: root/src/core/hle/kernel/vm_manager.cpp
AgeCommit message (Collapse)Author
2020-04-17kernel: Remove old VMManager class.bunnei
2020-02-05kernel: transfer_memory: Properly reserve and reset memory region.bunnei
2020-01-18core/memory: Create a special MapMemoryRegion for physical memory.Markus Wick
This allows us to create a fastmem arena within the memory.cpp helpers.
2020-01-18core/hle: Simplify PhysicalMemory usage in vm_manager.Markus Wick
2019-11-26core/memory: Migrate over memory mapping functions to the new Memory classLioncash
Migrates all of the direct mapping facilities over to the new memory class. In the process, this also obsoletes the need for memory_setup.h, so we can remove it entirely from the project.
2019-11-12kernel: Resolve sign conversion warningsLioncash
Uncovered a bug within Thread's SetCoreAndAffinityMask() where an unsigned variable (ideal_core) was being compared against "< 0", which would always be a false condition. We can also get rid of an unused function (GetNextProcessorId) which contained a sign mismatch warning.
2019-09-04kernel/vm_manager: Move variables closer to usage spots in ↵Lioncash
MapPhysicalMemory/UnmapPhysicalMemory Narrows the scope of variables down to where they're only necessary.
2019-08-29kernel/vm_manager: Correct behavior in failure case of UnmapPhysicalMemory()Lioncash
If an unmapping operation fails, we shouldn't be decrementing the amount of memory mapped and returning that the operation was successful. We should actually be returning the error code in this case.
2019-08-29kernel/vm_manager: Reserve memory ahead of time for slow path in ↵Lioncash
MergeAdjacentVMA Avoids potentially expensive (depending on the size of the memory block) allocations by reserving the necessary memory before performing both insertions. This avoids scenarios where the second insert may cause a reallocation to occur.
2019-08-29kernel/vm_manager: std::move shared_ptr instance in MergeAdjacentVMALioncash
Avoids an unnecessary atomic reference count increment and decrement.
2019-08-29kernel/vm_manager: Deduplicate iterator creation in MergeAdjacentVMALioncash
Avoids needing to read the same long sequence of code in both code paths. Also makes it slightly nicer to read and debug, as the locals will be able to be shown in the debugger.
2019-08-29kernel/vm_manager: Simplify some std::vector constructor callsLioncash
Same behavior, one less magic constant to read.
2019-08-29kernel/vm_manager: Simplify some assertion messagesLioncash
Assertions already log out the function name, so there's no need to manually include the function name in the assertion strings.
2019-07-19VM_Manager: Align allocated memory to 256bytesFernando Sahmkow
This commit ensures that all backing memory allocated for the Guest CPU is aligned to 256 bytes. This due to how gpu memory works and the heavy constraints it has in the alignment of physical memory.
2019-07-14Merge pull request #2690 from SciresM/physmem_fixesFernando Sahmkow
Implement MapPhysicalMemory/UnmapPhysicalMemory
2019-07-11Remove unicorn mappings/unmappingsMichael Scire
2019-07-11core/arm: Remove obsolete Unicorn memory mappingLioncash
This was initially necessary when AArch64 JIT emulation was in its infancy and all memory-related instructions weren't implemented. Given the JIT now has all of these facilities implemented, we can remove these functions from the CPU interface.
2019-07-08Prevent merging of device mapped memory blocks.Michael Scire
This sets the DeviceMapped attribute for GPU-mapped memory blocks, and prevents merging device mapped blocks. This prevents memory mapped from the gpu from having its backing address changed by block coalesce.
2019-07-07physmem: add helpers, cleanup logic.Michael Scire
2019-07-07address review commentaryMichael Scire
2019-07-07Implement MapPhysicalMemory/UnmapPhysicalMemoryMichael Scire
This implements svcMapPhysicalMemory/svcUnmapPhysicalMemory for Yuzu, which can be used to map memory at a desired address by games since 3.0.0. It also properly parses SystemResourceSize from NPDM, and makes information available via svcGetInfo. This is needed for games like Super Smash Bros. and Diablo 3 -- this PR's implementation does not run into the "ASCII reads" issue mentioned in the comments of #2626, which was caused by the following bugs in Yuzu's memory management that this PR also addresses: * Yuzu's memory coalescing does not properly merge blocks. This results in a polluted address space/svcQueryMemory results that would be impossible to replicate on hardware, which can lead to game code making the wrong assumptions about memory layout. * This implements better merging for AllocatedMemoryBlocks. * Yuzu's implementation of svcMirrorMemory unprotected the entire virtual memory range containing the range being mirrored. This could lead to games attempting to map data at that unprotected range/attempting to access that range after yuzu improperly unmapped it. * This PR fixes it by simply calling ReprotectRange instead of Reprotect.
2019-07-06kernel/vm_manager: Rename 'new map' to 'stack'Lioncash
Provides a more accurate name for the memory region and also disambiguates between the map and new map regions of memory, making it easier to understand.
2019-07-05kernel/vm_manager: Handle stack/TLS IO region placement betterLioncash
Handles the placement of the stack a little nicer compared to the previous code, which was off in a few ways. e.g. The stack (new map) region, shouldn't be the width of the entire address space if the size of the region calculation ends up being zero. It should be placed at the same location as the TLS IO region and also have the same size. In the event the TLS IO region contains a size of zero, we should also be doing the same thing. This fixes our memory layout a little bit and also resolves some cases where assertions can trigger due to the memory layout being incorrect.
2019-07-03kernel/vm_manager: Add overload of FindFreeRegion() that operates on a boundaryLioncash
This will be necessary for making our TLS slot management slightly more straightforward. This can also be utilized for other purposes in the future. We can implement the existing simpler overload in terms of this one anyways, we just pass the beginning and end of the ASLR region as the boundaries.
2019-06-12kernel/vm_manager: Remove redundant Reset call in destructorLioncash
This is performing more work than would otherwise be necessary during VMManager's destruction. All we actually want to occur in this scenario is for any allocated memory to be freed, which will happen automatically as the VMManager instance goes out of scope. Anything else being done is simply unnecessary work.
2019-06-09kernel/svc: Amend naming for TotalMemoryUsage in svcGetInfo()Lioncash
Disambiguates and makes the name a little more consistent with TotalPhysicalMemoryUsed.
2019-04-16kernel/vm_manager: Remove usages of global system accessorsLioncash
Makes the dependency on the system instance explicit within VMManager's interface.
2019-04-12kernel/svc: Implement svcUnmapProcessCodeMemoryLioncash
Essentially performs the inverse of svcMapProcessCodeMemory. This unmaps the aliasing region first, then restores the general traits of the aliased memory. What this entails, is: - Restoring Read/Write permissions to the VMA. - Restoring its memory state to reflect it as a general heap memory region. - Clearing the memory attributes on the region.
2019-04-12kernel/svc: Implement svcMapProcessCodeMemoryLioncash
This is utilized for mapping code modules into memory. Notably, the ldr service would call this in order to map objects into memory.
2019-03-24kernel/vm_manager: Handle shrinking of the heap size within SetHeapSize()Lioncash
One behavior that we weren't handling properly in our heap allocation process was the ability for the heap to be shrunk down in size if a larger size was previously requested. This adds the basic behavior to do so and also gets rid of HeapFree, as it's no longer necessary now that we have allocations and deallocations going through the same API function. While we're at it, fully document the behavior that this function performs.
2019-03-24kernel/vm_manager: Rename HeapAllocate to SetHeapSizeLioncash
Makes it more obvious that this function is intending to stand in for the actual supervisor call itself, and not acting as a general heap allocation function. Also the following change will merge the freeing behavior of HeapFree into this function, so leaving it as HeapAllocate would be misleading.
2019-03-24kernel/vm_manager: Handle case of identical calls to HeapAllocateLioncash
In cases where HeapAllocate is called with the same size of the current heap, we can simply do nothing and return successfully. This avoids doing work where we otherwise don't have to. This is also what the kernel itself does in this scenario.
2019-03-24kernel/vm_manager: Remove unnecessary heap_used data memberLioncash
This isn't required anymore, as all the kernel ever queries is the size of the current heap, not the total usage of it.
2019-03-24kernel/vm_manager: Tidy up heap allocation codeLioncash
Another holdover from citra that can be tossed out is the notion of the heap needing to be allocated in different addresses. On the switch, the base address of the heap will always be managed by the memory allocator in the kernel, so this doesn't need to be specified in the function's interface itself. The heap on the switch is always allocated with read/write permissions, so we don't need to add specifying the memory permissions as part of the heap allocation itself either. This also corrects the error code returned from within the function. If the size of the heap is larger than the entire heap region, then the kernel will report an out of memory condition.
2019-03-21kernel/vm_manager: Rename CodeStatic/CodeMutable to Code and CodeData ↵Lioncash
respectively Makes it more evident that one is for actual code and one is for actual data. Mutable and static are less than ideal terms here, because read-only data is technically not mutable, but we were mapping it with that label.
2019-03-16core: Move PageTable struct into Common.bunnei
2019-03-04vm_manager: Use range helpers in HeapAlloc() and HeapFree()Lioncash
Significantly tidies up two guard conditionals.
2019-03-04vm_manager: Provide address range checking functions for other memory regionsLioncash
Makes the interface uniform when it comes to checking various memory regions.
2019-03-04svc: Migrate address range checking functions to VMManagerLioncash
Provides a bit of a more proper interface for these functions.
2018-12-26kernel/vm_manager: Reset region attributes when unmapping a VMALioncash
Like the other members related to memory regions, the attributes need to be reset back to their defaults as well.
2018-12-19vm_manager: Add member function for setting memory attributes across an ↵Lioncash
address range This puts the backing functionality for svcSetMemoryAttribute in place, which will be utilized in a following change.
2018-12-19vm_manager: Add member function for checking a memory range adheres to ↵Lioncash
certain attributes, permissions and states
2018-12-15vm_manager: Rename meminfo_state to stateLioncash
This is shorter and more concise. This also removes the now-innaccurate comment, as it's not returned wholesale to svcQueryMemory anymore.
2018-12-15vm_manager: Add backing functionality for memory attributesLioncash
Adds the barebones enumeration constants and functions in place to handle memory attributes, while also essentially leaving the attribute itself non-functional.
2018-12-12vm_manager: Amend the returned values for invalid memory queries in ↵Lioncash
QueryMemory() The kernel returns a memory info instance with the base address set to the end of the address space, and the size of said block as 0 - address_space_end, it doesn't set both of said members to zero.
2018-12-12vm_manager: Migrate memory querying to the VMManager interfaceLioncash
Gets rid of the need to directly access the managed VMAs outside of the memory manager itself just for querying memory.
2018-12-12vm_manager: Amend MemoryState enum membersLioncash
Amends the MemoryState enum to use the same values like the actual kernel does. Also provides the necessary operators to operate on them. This will be necessary in the future for implementing svcSetMemoryAttribute, as memory block state is checked before applying the attribute.
2018-12-06vm_manager: Make vma_map privateLioncash
This was only ever public so that code could check whether or not a handle was valid or not. Instead of exposing the object directly and allowing external code to potentially mess with the map contents, we just provide a member function that allows checking whether or not a handle is valid. This makes all member variables of the VMManager class private except for the page table.
2018-11-17ldr_ro: Add error check for memory allocation failureZach Hilman
2018-11-13vm_manager: Unstub GetTotalHeapUsage()Lioncash
Now that we've moved all of the heap-related stuff to the VMManager class, we can unstub this function, as the necessary members are visible now.