summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core/hle/kernel/process.cpp2
-rw-r--r--src/core/hle/kernel/process.h3
-rw-r--r--src/core/hle/kernel/svc.cpp4
-rw-r--r--src/core/hle/kernel/vm_manager.cpp4
-rw-r--r--src/core/hle/kernel/vm_manager.h126
5 files changed, 111 insertions, 28 deletions
diff --git a/src/core/hle/kernel/process.cpp b/src/core/hle/kernel/process.cpp
index c817fb449..5356a4a3f 100644
--- a/src/core/hle/kernel/process.cpp
+++ b/src/core/hle/kernel/process.cpp
@@ -150,7 +150,7 @@ void Process::Run(VAddr entry_point, s32 main_thread_priority, u32 stack_size) {
150 vm_manager 150 vm_manager
151 .MapMemoryBlock(vm_manager.GetTLSIORegionEndAddress() - stack_size, 151 .MapMemoryBlock(vm_manager.GetTLSIORegionEndAddress() - stack_size,
152 std::make_shared<std::vector<u8>>(stack_size, 0), 0, stack_size, 152 std::make_shared<std::vector<u8>>(stack_size, 0), 0, stack_size,
153 MemoryState::Mapped) 153 MemoryState::Stack)
154 .Unwrap(); 154 .Unwrap();
155 155
156 vm_manager.LogLayout(); 156 vm_manager.LogLayout();
diff --git a/src/core/hle/kernel/process.h b/src/core/hle/kernel/process.h
index bcb9ac4b8..459eedfa6 100644
--- a/src/core/hle/kernel/process.h
+++ b/src/core/hle/kernel/process.h
@@ -262,8 +262,7 @@ public:
262 ResultVal<VAddr> HeapAllocate(VAddr target, u64 size, VMAPermission perms); 262 ResultVal<VAddr> HeapAllocate(VAddr target, u64 size, VMAPermission perms);
263 ResultCode HeapFree(VAddr target, u32 size); 263 ResultCode HeapFree(VAddr target, u32 size);
264 264
265 ResultCode MirrorMemory(VAddr dst_addr, VAddr src_addr, u64 size, 265 ResultCode MirrorMemory(VAddr dst_addr, VAddr src_addr, u64 size, MemoryState state);
266 MemoryState state = MemoryState::Mapped);
267 266
268 ResultCode UnmapMemory(VAddr dst_addr, VAddr src_addr, u64 size); 267 ResultCode UnmapMemory(VAddr dst_addr, VAddr src_addr, u64 size);
269 268
diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp
index f43c7201c..4ae92ff9e 100644
--- a/src/core/hle/kernel/svc.cpp
+++ b/src/core/hle/kernel/svc.cpp
@@ -273,7 +273,7 @@ static ResultCode MapMemory(VAddr dst_addr, VAddr src_addr, u64 size) {
273 return result; 273 return result;
274 } 274 }
275 275
276 return current_process->MirrorMemory(dst_addr, src_addr, size); 276 return current_process->MirrorMemory(dst_addr, src_addr, size, MemoryState::Stack);
277} 277}
278 278
279/// Unmaps a region that was previously mapped with svcMapMemory 279/// Unmaps a region that was previously mapped with svcMapMemory
@@ -1086,7 +1086,7 @@ static ResultCode QueryProcessMemory(MemoryInfo* memory_info, PageInfo* /*page_i
1086 memory_info->base_address = vma->second.base; 1086 memory_info->base_address = vma->second.base;
1087 memory_info->permission = static_cast<u32>(vma->second.permissions); 1087 memory_info->permission = static_cast<u32>(vma->second.permissions);
1088 memory_info->size = vma->second.size; 1088 memory_info->size = vma->second.size;
1089 memory_info->type = static_cast<u32>(vma->second.meminfo_state); 1089 memory_info->type = ToSvcMemoryState(vma->second.meminfo_state);
1090 } else { 1090 } else {
1091 memory_info->base_address = 0; 1091 memory_info->base_address = 0;
1092 memory_info->permission = static_cast<u32>(VMAPermission::None); 1092 memory_info->permission = static_cast<u32>(VMAPermission::None);
diff --git a/src/core/hle/kernel/vm_manager.cpp b/src/core/hle/kernel/vm_manager.cpp
index 6187993ce..e0f204b0b 100644
--- a/src/core/hle/kernel/vm_manager.cpp
+++ b/src/core/hle/kernel/vm_manager.cpp
@@ -25,14 +25,14 @@ static const char* GetMemoryStateName(MemoryState state) {
25 "CodeMutable", "Heap", 25 "CodeMutable", "Heap",
26 "Shared", "Unknown1", 26 "Shared", "Unknown1",
27 "ModuleCodeStatic", "ModuleCodeMutable", 27 "ModuleCodeStatic", "ModuleCodeMutable",
28 "IpcBuffer0", "Mapped", 28 "IpcBuffer0", "Stack",
29 "ThreadLocal", "TransferMemoryIsolated", 29 "ThreadLocal", "TransferMemoryIsolated",
30 "TransferMemory", "ProcessMemory", 30 "TransferMemory", "ProcessMemory",
31 "Unknown2", "IpcBuffer1", 31 "Unknown2", "IpcBuffer1",
32 "IpcBuffer3", "KernelStack", 32 "IpcBuffer3", "KernelStack",
33 }; 33 };
34 34
35 return names[static_cast<int>(state)]; 35 return names[ToSvcMemoryState(state)];
36} 36}
37 37
38bool VirtualMemoryArea::CanBeMergedWith(const VirtualMemoryArea& next) const { 38bool VirtualMemoryArea::CanBeMergedWith(const VirtualMemoryArea& next) const {
diff --git a/src/core/hle/kernel/vm_manager.h b/src/core/hle/kernel/vm_manager.h
index a12419d1e..0a600c23c 100644
--- a/src/core/hle/kernel/vm_manager.h
+++ b/src/core/hle/kernel/vm_manager.h
@@ -43,27 +43,112 @@ enum class VMAPermission : u8 {
43 ReadWriteExecute = Read | Write | Execute, 43 ReadWriteExecute = Read | Write | Execute,
44}; 44};
45 45
46/// Set of values returned in MemoryInfo.state by svcQueryMemory. 46// clang-format off
47/// Represents memory states and any relevant flags, as used by the kernel.
48/// svcQueryMemory interprets these by masking away all but the first eight
49/// bits when storing memory state into a MemoryInfo instance.
47enum class MemoryState : u32 { 50enum class MemoryState : u32 {
48 Unmapped = 0x0, 51 Mask = 0xFF,
49 Io = 0x1, 52 FlagProtect = 1U << 8,
50 Normal = 0x2, 53 FlagDebug = 1U << 9,
51 CodeStatic = 0x3, 54 FlagIPC0 = 1U << 10,
52 CodeMutable = 0x4, 55 FlagIPC3 = 1U << 11,
53 Heap = 0x5, 56 FlagIPC1 = 1U << 12,
54 Shared = 0x6, 57 FlagMapped = 1U << 13,
55 ModuleCodeStatic = 0x8, 58 FlagCode = 1U << 14,
56 ModuleCodeMutable = 0x9, 59 FlagAlias = 1U << 15,
57 IpcBuffer0 = 0xA, 60 FlagModule = 1U << 16,
58 Mapped = 0xB, 61 FlagTransfer = 1U << 17,
59 ThreadLocal = 0xC, 62 FlagQueryPhysicalAddressAllowed = 1U << 18,
60 TransferMemoryIsolated = 0xD, 63 FlagSharedDevice = 1U << 19,
61 TransferMemory = 0xE, 64 FlagSharedDeviceAligned = 1U << 20,
62 ProcessMemory = 0xF, 65 FlagIPCBuffer = 1U << 21,
63 IpcBuffer1 = 0x11, 66 FlagMemoryPoolAllocated = 1U << 22,
64 IpcBuffer3 = 0x12, 67 FlagMapProcess = 1U << 23,
65 KernelStack = 0x13, 68 FlagUncached = 1U << 24,
69 FlagCodeMemory = 1U << 25,
70
71 // Convenience flag sets to reduce repetition
72 IPCFlags = FlagIPC0 | FlagIPC3 | FlagIPC1,
73
74 CodeFlags = FlagDebug | IPCFlags | FlagMapped | FlagCode | FlagQueryPhysicalAddressAllowed |
75 FlagSharedDevice | FlagSharedDeviceAligned | FlagMemoryPoolAllocated,
76
77 DataFlags = FlagProtect | IPCFlags | FlagMapped | FlagAlias | FlagTransfer |
78 FlagQueryPhysicalAddressAllowed | FlagSharedDevice | FlagSharedDeviceAligned |
79 FlagMemoryPoolAllocated | FlagIPCBuffer | FlagUncached,
80
81 Unmapped = 0x00,
82 Io = 0x01 | FlagMapped,
83 Normal = 0x02 | FlagMapped | FlagQueryPhysicalAddressAllowed,
84 CodeStatic = 0x03 | CodeFlags | FlagMapProcess,
85 CodeMutable = 0x04 | CodeFlags | FlagMapProcess | FlagCodeMemory,
86 Heap = 0x05 | DataFlags | FlagCodeMemory,
87 Shared = 0x06 | FlagMapped | FlagMemoryPoolAllocated,
88 ModuleCodeStatic = 0x08 | CodeFlags | FlagModule | FlagMapProcess,
89 ModuleCodeMutable = 0x09 | DataFlags | FlagModule | FlagMapProcess | FlagCodeMemory,
90
91 IpcBuffer0 = 0x0A | FlagMapped | FlagQueryPhysicalAddressAllowed | FlagMemoryPoolAllocated |
92 IPCFlags | FlagSharedDevice | FlagSharedDeviceAligned,
93
94 Stack = 0x0B | FlagMapped | IPCFlags | FlagQueryPhysicalAddressAllowed |
95 FlagSharedDevice | FlagSharedDeviceAligned | FlagMemoryPoolAllocated,
96
97 ThreadLocal = 0x0C | FlagMapped | FlagMemoryPoolAllocated,
98
99 TransferMemoryIsolated = 0x0D | IPCFlags | FlagMapped | FlagQueryPhysicalAddressAllowed |
100 FlagSharedDevice | FlagSharedDeviceAligned | FlagMemoryPoolAllocated |
101 FlagUncached,
102
103 TransferMemory = 0x0E | FlagIPC3 | FlagIPC1 | FlagMapped | FlagQueryPhysicalAddressAllowed |
104 FlagSharedDevice | FlagSharedDeviceAligned | FlagMemoryPoolAllocated,
105
106 ProcessMemory = 0x0F | FlagIPC3 | FlagIPC1 | FlagMapped | FlagMemoryPoolAllocated,
107
108 IpcBuffer1 = 0x11 | FlagIPC3 | FlagIPC1 | FlagMapped | FlagQueryPhysicalAddressAllowed |
109 FlagSharedDevice | FlagSharedDeviceAligned | FlagMemoryPoolAllocated,
110
111 IpcBuffer3 = 0x12 | FlagIPC3 | FlagMapped | FlagQueryPhysicalAddressAllowed |
112 FlagSharedDeviceAligned | FlagMemoryPoolAllocated,
113
114 KernelStack = 0x13 | FlagMapped,
66}; 115};
116// clang-format on
117
118constexpr MemoryState operator|(MemoryState lhs, MemoryState rhs) {
119 return static_cast<MemoryState>(u32(lhs) | u32(rhs));
120}
121
122constexpr MemoryState operator&(MemoryState lhs, MemoryState rhs) {
123 return static_cast<MemoryState>(u32(lhs) & u32(rhs));
124}
125
126constexpr MemoryState operator^(MemoryState lhs, MemoryState rhs) {
127 return static_cast<MemoryState>(u32(lhs) ^ u32(rhs));
128}
129
130constexpr MemoryState operator~(MemoryState lhs) {
131 return static_cast<MemoryState>(~u32(lhs));
132}
133
134constexpr MemoryState& operator|=(MemoryState& lhs, MemoryState rhs) {
135 lhs = lhs | rhs;
136 return lhs;
137}
138
139constexpr MemoryState& operator&=(MemoryState& lhs, MemoryState rhs) {
140 lhs = lhs & rhs;
141 return lhs;
142}
143
144constexpr MemoryState& operator^=(MemoryState& lhs, MemoryState rhs) {
145 lhs = lhs ^ rhs;
146 return lhs;
147}
148
149constexpr u32 ToSvcMemoryState(MemoryState state) {
150 return static_cast<u32>(state & MemoryState::Mask);
151}
67 152
68/** 153/**
69 * Represents a VMA in an address space. A VMA is a contiguous region of virtual addressing space 154 * Represents a VMA in an address space. A VMA is a contiguous region of virtual addressing space
@@ -186,8 +271,7 @@ public:
186 ResultVal<VAddr> HeapAllocate(VAddr target, u64 size, VMAPermission perms); 271 ResultVal<VAddr> HeapAllocate(VAddr target, u64 size, VMAPermission perms);
187 ResultCode HeapFree(VAddr target, u64 size); 272 ResultCode HeapFree(VAddr target, u64 size);
188 273
189 ResultCode MirrorMemory(VAddr dst_addr, VAddr src_addr, u64 size, 274 ResultCode MirrorMemory(VAddr dst_addr, VAddr src_addr, u64 size, MemoryState state);
190 MemoryState state = MemoryState::Mapped);
191 275
192 /** 276 /**
193 * Scans all VMAs and updates the page table range of any that use the given vector as backing 277 * Scans all VMAs and updates the page table range of any that use the given vector as backing