diff options
| author | 2019-04-12 00:38:54 -0400 | |
|---|---|---|
| committer | 2019-04-12 21:56:03 -0400 | |
| commit | 4d293bb5cbb65d3551dd0d22e92b7065a7ebba14 (patch) | |
| tree | d57782959b51296eef132a721a1b6d0600e8e117 /src/core/hle/kernel/svc.cpp | |
| parent | kernel/svc: Implement svcMapProcessCodeMemory (diff) | |
| download | yuzu-4d293bb5cbb65d3551dd0d22e92b7065a7ebba14.tar.gz yuzu-4d293bb5cbb65d3551dd0d22e92b7065a7ebba14.tar.xz yuzu-4d293bb5cbb65d3551dd0d22e92b7065a7ebba14.zip | |
kernel/svc: Implement svcUnmapProcessCodeMemory
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.
Diffstat (limited to 'src/core/hle/kernel/svc.cpp')
| -rw-r--r-- | src/core/hle/kernel/svc.cpp | 70 |
1 files changed, 69 insertions, 1 deletions
diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp index 0aa2e358e..d48a2203a 100644 --- a/src/core/hle/kernel/svc.cpp +++ b/src/core/hle/kernel/svc.cpp | |||
| @@ -1257,6 +1257,74 @@ static ResultCode MapProcessCodeMemory(Core::System& system, Handle process_hand | |||
| 1257 | return vm_manager.MapCodeMemory(dst_address, src_address, size); | 1257 | return vm_manager.MapCodeMemory(dst_address, src_address, size); |
| 1258 | } | 1258 | } |
| 1259 | 1259 | ||
| 1260 | ResultCode UnmapProcessCodeMemory(Core::System& system, Handle process_handle, u64 dst_address, | ||
| 1261 | u64 src_address, u64 size) { | ||
| 1262 | LOG_DEBUG(Kernel_SVC, | ||
| 1263 | "called. process_handle=0x{:08X}, dst_address=0x{:016X}, src_address=0x{:016X}, " | ||
| 1264 | "size=0x{:016X}", | ||
| 1265 | process_handle, dst_address, src_address, size); | ||
| 1266 | |||
| 1267 | if (!Common::Is4KBAligned(dst_address)) { | ||
| 1268 | LOG_ERROR(Kernel_SVC, "dst_address is not page-aligned (dst_address=0x{:016X}).", | ||
| 1269 | dst_address); | ||
| 1270 | return ERR_INVALID_ADDRESS; | ||
| 1271 | } | ||
| 1272 | |||
| 1273 | if (!Common::Is4KBAligned(src_address)) { | ||
| 1274 | LOG_ERROR(Kernel_SVC, "src_address is not page-aligned (src_address=0x{:016X}).", | ||
| 1275 | src_address); | ||
| 1276 | return ERR_INVALID_ADDRESS; | ||
| 1277 | } | ||
| 1278 | |||
| 1279 | if (size == 0 || Common::Is4KBAligned(size)) { | ||
| 1280 | LOG_ERROR(Kernel_SVC, "Size is zero or not page-aligned (size=0x{:016X}).", size); | ||
| 1281 | return ERR_INVALID_SIZE; | ||
| 1282 | } | ||
| 1283 | |||
| 1284 | if (!IsValidAddressRange(dst_address, size)) { | ||
| 1285 | LOG_ERROR(Kernel_SVC, | ||
| 1286 | "Destination address range overflows the address space (dst_address=0x{:016X}, " | ||
| 1287 | "size=0x{:016X}).", | ||
| 1288 | dst_address, size); | ||
| 1289 | return ERR_INVALID_ADDRESS_STATE; | ||
| 1290 | } | ||
| 1291 | |||
| 1292 | if (!IsValidAddressRange(src_address, size)) { | ||
| 1293 | LOG_ERROR(Kernel_SVC, | ||
| 1294 | "Source address range overflows the address space (src_address=0x{:016X}, " | ||
| 1295 | "size=0x{:016X}).", | ||
| 1296 | src_address, size); | ||
| 1297 | return ERR_INVALID_ADDRESS_STATE; | ||
| 1298 | } | ||
| 1299 | |||
| 1300 | const auto& handle_table = system.Kernel().CurrentProcess()->GetHandleTable(); | ||
| 1301 | auto process = handle_table.Get<Process>(process_handle); | ||
| 1302 | if (!process) { | ||
| 1303 | LOG_ERROR(Kernel_SVC, "Invalid process handle specified (handle=0x{:08X}).", | ||
| 1304 | process_handle); | ||
| 1305 | return ERR_INVALID_HANDLE; | ||
| 1306 | } | ||
| 1307 | |||
| 1308 | auto& vm_manager = process->VMManager(); | ||
| 1309 | if (!vm_manager.IsWithinAddressSpace(src_address, size)) { | ||
| 1310 | LOG_ERROR(Kernel_SVC, | ||
| 1311 | "Source address range is not within the address space (src_address=0x{:016X}, " | ||
| 1312 | "size=0x{:016X}).", | ||
| 1313 | src_address, size); | ||
| 1314 | return ERR_INVALID_ADDRESS_STATE; | ||
| 1315 | } | ||
| 1316 | |||
| 1317 | if (!vm_manager.IsWithinASLRRegion(dst_address, size)) { | ||
| 1318 | LOG_ERROR(Kernel_SVC, | ||
| 1319 | "Destination address range is not within the ASLR region (dst_address=0x{:016X}, " | ||
| 1320 | "size=0x{:016X}).", | ||
| 1321 | dst_address, size); | ||
| 1322 | return ERR_INVALID_MEMORY_RANGE; | ||
| 1323 | } | ||
| 1324 | |||
| 1325 | return vm_manager.UnmapCodeMemory(dst_address, src_address, size); | ||
| 1326 | } | ||
| 1327 | |||
| 1260 | /// Exits the current process | 1328 | /// Exits the current process |
| 1261 | static void ExitProcess(Core::System& system) { | 1329 | static void ExitProcess(Core::System& system) { |
| 1262 | auto* current_process = system.Kernel().CurrentProcess(); | 1330 | auto* current_process = system.Kernel().CurrentProcess(); |
| @@ -2286,7 +2354,7 @@ static const FunctionDef SVC_Table[] = { | |||
| 2286 | {0x75, nullptr, "UnmapProcessMemory"}, | 2354 | {0x75, nullptr, "UnmapProcessMemory"}, |
| 2287 | {0x76, SvcWrap<QueryProcessMemory>, "QueryProcessMemory"}, | 2355 | {0x76, SvcWrap<QueryProcessMemory>, "QueryProcessMemory"}, |
| 2288 | {0x77, SvcWrap<MapProcessCodeMemory>, "MapProcessCodeMemory"}, | 2356 | {0x77, SvcWrap<MapProcessCodeMemory>, "MapProcessCodeMemory"}, |
| 2289 | {0x78, nullptr, "UnmapProcessCodeMemory"}, | 2357 | {0x78, SvcWrap<UnmapProcessCodeMemory>, "UnmapProcessCodeMemory"}, |
| 2290 | {0x79, nullptr, "CreateProcess"}, | 2358 | {0x79, nullptr, "CreateProcess"}, |
| 2291 | {0x7A, nullptr, "StartProcess"}, | 2359 | {0x7A, nullptr, "StartProcess"}, |
| 2292 | {0x7B, nullptr, "TerminateProcess"}, | 2360 | {0x7B, nullptr, "TerminateProcess"}, |