mirror of
https://github.com/yuzu-emu/yuzu.git
synced 2024-07-04 23:31:19 +01:00
vm_manager: Amend MemoryState enum members
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.
This commit is contained in:
parent
3b1043c58a
commit
366985ca92
5 changed files with 111 additions and 28 deletions
|
@ -150,7 +150,7 @@ void Process::Run(VAddr entry_point, s32 main_thread_priority, u32 stack_size) {
|
||||||
vm_manager
|
vm_manager
|
||||||
.MapMemoryBlock(vm_manager.GetTLSIORegionEndAddress() - stack_size,
|
.MapMemoryBlock(vm_manager.GetTLSIORegionEndAddress() - stack_size,
|
||||||
std::make_shared<std::vector<u8>>(stack_size, 0), 0, stack_size,
|
std::make_shared<std::vector<u8>>(stack_size, 0), 0, stack_size,
|
||||||
MemoryState::Mapped)
|
MemoryState::Stack)
|
||||||
.Unwrap();
|
.Unwrap();
|
||||||
|
|
||||||
vm_manager.LogLayout();
|
vm_manager.LogLayout();
|
||||||
|
|
|
@ -262,8 +262,7 @@ public:
|
||||||
ResultVal<VAddr> HeapAllocate(VAddr target, u64 size, VMAPermission perms);
|
ResultVal<VAddr> HeapAllocate(VAddr target, u64 size, VMAPermission perms);
|
||||||
ResultCode HeapFree(VAddr target, u32 size);
|
ResultCode HeapFree(VAddr target, u32 size);
|
||||||
|
|
||||||
ResultCode MirrorMemory(VAddr dst_addr, VAddr src_addr, u64 size,
|
ResultCode MirrorMemory(VAddr dst_addr, VAddr src_addr, u64 size, MemoryState state);
|
||||||
MemoryState state = MemoryState::Mapped);
|
|
||||||
|
|
||||||
ResultCode UnmapMemory(VAddr dst_addr, VAddr src_addr, u64 size);
|
ResultCode UnmapMemory(VAddr dst_addr, VAddr src_addr, u64 size);
|
||||||
|
|
||||||
|
|
|
@ -273,7 +273,7 @@ static ResultCode MapMemory(VAddr dst_addr, VAddr src_addr, u64 size) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
return current_process->MirrorMemory(dst_addr, src_addr, size);
|
return current_process->MirrorMemory(dst_addr, src_addr, size, MemoryState::Stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Unmaps a region that was previously mapped with svcMapMemory
|
/// Unmaps a region that was previously mapped with svcMapMemory
|
||||||
|
@ -1086,7 +1086,7 @@ static ResultCode QueryProcessMemory(MemoryInfo* memory_info, PageInfo* /*page_i
|
||||||
memory_info->base_address = vma->second.base;
|
memory_info->base_address = vma->second.base;
|
||||||
memory_info->permission = static_cast<u32>(vma->second.permissions);
|
memory_info->permission = static_cast<u32>(vma->second.permissions);
|
||||||
memory_info->size = vma->second.size;
|
memory_info->size = vma->second.size;
|
||||||
memory_info->type = static_cast<u32>(vma->second.meminfo_state);
|
memory_info->type = ToSvcMemoryState(vma->second.meminfo_state);
|
||||||
} else {
|
} else {
|
||||||
memory_info->base_address = 0;
|
memory_info->base_address = 0;
|
||||||
memory_info->permission = static_cast<u32>(VMAPermission::None);
|
memory_info->permission = static_cast<u32>(VMAPermission::None);
|
||||||
|
|
|
@ -25,14 +25,14 @@ static const char* GetMemoryStateName(MemoryState state) {
|
||||||
"CodeMutable", "Heap",
|
"CodeMutable", "Heap",
|
||||||
"Shared", "Unknown1",
|
"Shared", "Unknown1",
|
||||||
"ModuleCodeStatic", "ModuleCodeMutable",
|
"ModuleCodeStatic", "ModuleCodeMutable",
|
||||||
"IpcBuffer0", "Mapped",
|
"IpcBuffer0", "Stack",
|
||||||
"ThreadLocal", "TransferMemoryIsolated",
|
"ThreadLocal", "TransferMemoryIsolated",
|
||||||
"TransferMemory", "ProcessMemory",
|
"TransferMemory", "ProcessMemory",
|
||||||
"Unknown2", "IpcBuffer1",
|
"Unknown2", "IpcBuffer1",
|
||||||
"IpcBuffer3", "KernelStack",
|
"IpcBuffer3", "KernelStack",
|
||||||
};
|
};
|
||||||
|
|
||||||
return names[static_cast<int>(state)];
|
return names[ToSvcMemoryState(state)];
|
||||||
}
|
}
|
||||||
|
|
||||||
bool VirtualMemoryArea::CanBeMergedWith(const VirtualMemoryArea& next) const {
|
bool VirtualMemoryArea::CanBeMergedWith(const VirtualMemoryArea& next) const {
|
||||||
|
|
|
@ -43,27 +43,112 @@ enum class VMAPermission : u8 {
|
||||||
ReadWriteExecute = Read | Write | Execute,
|
ReadWriteExecute = Read | Write | Execute,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Set of values returned in MemoryInfo.state by svcQueryMemory.
|
// clang-format off
|
||||||
|
/// Represents memory states and any relevant flags, as used by the kernel.
|
||||||
|
/// svcQueryMemory interprets these by masking away all but the first eight
|
||||||
|
/// bits when storing memory state into a MemoryInfo instance.
|
||||||
enum class MemoryState : u32 {
|
enum class MemoryState : u32 {
|
||||||
Unmapped = 0x0,
|
Mask = 0xFF,
|
||||||
Io = 0x1,
|
FlagProtect = 1U << 8,
|
||||||
Normal = 0x2,
|
FlagDebug = 1U << 9,
|
||||||
CodeStatic = 0x3,
|
FlagIPC0 = 1U << 10,
|
||||||
CodeMutable = 0x4,
|
FlagIPC3 = 1U << 11,
|
||||||
Heap = 0x5,
|
FlagIPC1 = 1U << 12,
|
||||||
Shared = 0x6,
|
FlagMapped = 1U << 13,
|
||||||
ModuleCodeStatic = 0x8,
|
FlagCode = 1U << 14,
|
||||||
ModuleCodeMutable = 0x9,
|
FlagAlias = 1U << 15,
|
||||||
IpcBuffer0 = 0xA,
|
FlagModule = 1U << 16,
|
||||||
Mapped = 0xB,
|
FlagTransfer = 1U << 17,
|
||||||
ThreadLocal = 0xC,
|
FlagQueryPhysicalAddressAllowed = 1U << 18,
|
||||||
TransferMemoryIsolated = 0xD,
|
FlagSharedDevice = 1U << 19,
|
||||||
TransferMemory = 0xE,
|
FlagSharedDeviceAligned = 1U << 20,
|
||||||
ProcessMemory = 0xF,
|
FlagIPCBuffer = 1U << 21,
|
||||||
IpcBuffer1 = 0x11,
|
FlagMemoryPoolAllocated = 1U << 22,
|
||||||
IpcBuffer3 = 0x12,
|
FlagMapProcess = 1U << 23,
|
||||||
KernelStack = 0x13,
|
FlagUncached = 1U << 24,
|
||||||
|
FlagCodeMemory = 1U << 25,
|
||||||
|
|
||||||
|
// Convenience flag sets to reduce repetition
|
||||||
|
IPCFlags = FlagIPC0 | FlagIPC3 | FlagIPC1,
|
||||||
|
|
||||||
|
CodeFlags = FlagDebug | IPCFlags | FlagMapped | FlagCode | FlagQueryPhysicalAddressAllowed |
|
||||||
|
FlagSharedDevice | FlagSharedDeviceAligned | FlagMemoryPoolAllocated,
|
||||||
|
|
||||||
|
DataFlags = FlagProtect | IPCFlags | FlagMapped | FlagAlias | FlagTransfer |
|
||||||
|
FlagQueryPhysicalAddressAllowed | FlagSharedDevice | FlagSharedDeviceAligned |
|
||||||
|
FlagMemoryPoolAllocated | FlagIPCBuffer | FlagUncached,
|
||||||
|
|
||||||
|
Unmapped = 0x00,
|
||||||
|
Io = 0x01 | FlagMapped,
|
||||||
|
Normal = 0x02 | FlagMapped | FlagQueryPhysicalAddressAllowed,
|
||||||
|
CodeStatic = 0x03 | CodeFlags | FlagMapProcess,
|
||||||
|
CodeMutable = 0x04 | CodeFlags | FlagMapProcess | FlagCodeMemory,
|
||||||
|
Heap = 0x05 | DataFlags | FlagCodeMemory,
|
||||||
|
Shared = 0x06 | FlagMapped | FlagMemoryPoolAllocated,
|
||||||
|
ModuleCodeStatic = 0x08 | CodeFlags | FlagModule | FlagMapProcess,
|
||||||
|
ModuleCodeMutable = 0x09 | DataFlags | FlagModule | FlagMapProcess | FlagCodeMemory,
|
||||||
|
|
||||||
|
IpcBuffer0 = 0x0A | FlagMapped | FlagQueryPhysicalAddressAllowed | FlagMemoryPoolAllocated |
|
||||||
|
IPCFlags | FlagSharedDevice | FlagSharedDeviceAligned,
|
||||||
|
|
||||||
|
Stack = 0x0B | FlagMapped | IPCFlags | FlagQueryPhysicalAddressAllowed |
|
||||||
|
FlagSharedDevice | FlagSharedDeviceAligned | FlagMemoryPoolAllocated,
|
||||||
|
|
||||||
|
ThreadLocal = 0x0C | FlagMapped | FlagMemoryPoolAllocated,
|
||||||
|
|
||||||
|
TransferMemoryIsolated = 0x0D | IPCFlags | FlagMapped | FlagQueryPhysicalAddressAllowed |
|
||||||
|
FlagSharedDevice | FlagSharedDeviceAligned | FlagMemoryPoolAllocated |
|
||||||
|
FlagUncached,
|
||||||
|
|
||||||
|
TransferMemory = 0x0E | FlagIPC3 | FlagIPC1 | FlagMapped | FlagQueryPhysicalAddressAllowed |
|
||||||
|
FlagSharedDevice | FlagSharedDeviceAligned | FlagMemoryPoolAllocated,
|
||||||
|
|
||||||
|
ProcessMemory = 0x0F | FlagIPC3 | FlagIPC1 | FlagMapped | FlagMemoryPoolAllocated,
|
||||||
|
|
||||||
|
IpcBuffer1 = 0x11 | FlagIPC3 | FlagIPC1 | FlagMapped | FlagQueryPhysicalAddressAllowed |
|
||||||
|
FlagSharedDevice | FlagSharedDeviceAligned | FlagMemoryPoolAllocated,
|
||||||
|
|
||||||
|
IpcBuffer3 = 0x12 | FlagIPC3 | FlagMapped | FlagQueryPhysicalAddressAllowed |
|
||||||
|
FlagSharedDeviceAligned | FlagMemoryPoolAllocated,
|
||||||
|
|
||||||
|
KernelStack = 0x13 | FlagMapped,
|
||||||
};
|
};
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
|
constexpr MemoryState operator|(MemoryState lhs, MemoryState rhs) {
|
||||||
|
return static_cast<MemoryState>(u32(lhs) | u32(rhs));
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr MemoryState operator&(MemoryState lhs, MemoryState rhs) {
|
||||||
|
return static_cast<MemoryState>(u32(lhs) & u32(rhs));
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr MemoryState operator^(MemoryState lhs, MemoryState rhs) {
|
||||||
|
return static_cast<MemoryState>(u32(lhs) ^ u32(rhs));
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr MemoryState operator~(MemoryState lhs) {
|
||||||
|
return static_cast<MemoryState>(~u32(lhs));
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr MemoryState& operator|=(MemoryState& lhs, MemoryState rhs) {
|
||||||
|
lhs = lhs | rhs;
|
||||||
|
return lhs;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr MemoryState& operator&=(MemoryState& lhs, MemoryState rhs) {
|
||||||
|
lhs = lhs & rhs;
|
||||||
|
return lhs;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr MemoryState& operator^=(MemoryState& lhs, MemoryState rhs) {
|
||||||
|
lhs = lhs ^ rhs;
|
||||||
|
return lhs;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr u32 ToSvcMemoryState(MemoryState state) {
|
||||||
|
return static_cast<u32>(state & MemoryState::Mask);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a VMA in an address space. A VMA is a contiguous region of virtual addressing space
|
* Represents a VMA in an address space. A VMA is a contiguous region of virtual addressing space
|
||||||
|
@ -186,8 +271,7 @@ public:
|
||||||
ResultVal<VAddr> HeapAllocate(VAddr target, u64 size, VMAPermission perms);
|
ResultVal<VAddr> HeapAllocate(VAddr target, u64 size, VMAPermission perms);
|
||||||
ResultCode HeapFree(VAddr target, u64 size);
|
ResultCode HeapFree(VAddr target, u64 size);
|
||||||
|
|
||||||
ResultCode MirrorMemory(VAddr dst_addr, VAddr src_addr, u64 size,
|
ResultCode MirrorMemory(VAddr dst_addr, VAddr src_addr, u64 size, MemoryState state);
|
||||||
MemoryState state = MemoryState::Mapped);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Scans all VMAs and updates the page table range of any that use the given vector as backing
|
* Scans all VMAs and updates the page table range of any that use the given vector as backing
|
||||||
|
|
Loading…
Reference in a new issue