diff options
| author | 2020-04-23 18:05:09 -0400 | |
|---|---|---|
| committer | 2020-04-23 18:12:04 -0400 | |
| commit | 4730347f8e4e158aafb821f69fba0a7cb94fdb2a (patch) | |
| tree | e26ef42c5d2b041f9888be8fd0e1db381adee80e | |
| parent | Merge pull request #3768 from H27CK/cmd-title-fmt (diff) | |
| download | yuzu-4730347f8e4e158aafb821f69fba0a7cb94fdb2a.tar.gz yuzu-4730347f8e4e158aafb821f69fba0a7cb94fdb2a.tar.xz yuzu-4730347f8e4e158aafb821f69fba0a7cb94fdb2a.zip | |
svc: Re-add MapProcessCodeMemory/UnmapProcessCodeMemory
These were lost in the re-implementation of the virtual memory manager.
Diffstat (limited to '')
| -rw-r--r-- | src/core/hle/kernel/svc.cpp | 140 |
1 files changed, 138 insertions, 2 deletions
diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp index 4134acf65..17c7e9433 100644 --- a/src/core/hle/kernel/svc.cpp +++ b/src/core/hle/kernel/svc.cpp | |||
| @@ -1229,6 +1229,142 @@ static ResultCode QueryMemory32(Core::System& system, u32 memory_info_address, | |||
| 1229 | return QueryMemory(system, memory_info_address, page_info_address, query_address); | 1229 | return QueryMemory(system, memory_info_address, page_info_address, query_address); |
| 1230 | } | 1230 | } |
| 1231 | 1231 | ||
| 1232 | static ResultCode MapProcessCodeMemory(Core::System& system, Handle process_handle, u64 dst_address, | ||
| 1233 | u64 src_address, u64 size) { | ||
| 1234 | LOG_DEBUG(Kernel_SVC, | ||
| 1235 | "called. process_handle=0x{:08X}, dst_address=0x{:016X}, " | ||
| 1236 | "src_address=0x{:016X}, size=0x{:016X}", | ||
| 1237 | process_handle, dst_address, src_address, size); | ||
| 1238 | |||
| 1239 | if (!Common::Is4KBAligned(src_address)) { | ||
| 1240 | LOG_ERROR(Kernel_SVC, "src_address is not page-aligned (src_address=0x{:016X}).", | ||
| 1241 | src_address); | ||
| 1242 | return ERR_INVALID_ADDRESS; | ||
| 1243 | } | ||
| 1244 | |||
| 1245 | if (!Common::Is4KBAligned(dst_address)) { | ||
| 1246 | LOG_ERROR(Kernel_SVC, "dst_address is not page-aligned (dst_address=0x{:016X}).", | ||
| 1247 | dst_address); | ||
| 1248 | return ERR_INVALID_ADDRESS; | ||
| 1249 | } | ||
| 1250 | |||
| 1251 | if (size == 0 || !Common::Is4KBAligned(size)) { | ||
| 1252 | LOG_ERROR(Kernel_SVC, "Size is zero or not page-aligned (size=0x{:016X})", size); | ||
| 1253 | return ERR_INVALID_SIZE; | ||
| 1254 | } | ||
| 1255 | |||
| 1256 | if (!IsValidAddressRange(dst_address, size)) { | ||
| 1257 | LOG_ERROR(Kernel_SVC, | ||
| 1258 | "Destination address range overflows the address space (dst_address=0x{:016X}, " | ||
| 1259 | "size=0x{:016X}).", | ||
| 1260 | dst_address, size); | ||
| 1261 | return ERR_INVALID_ADDRESS_STATE; | ||
| 1262 | } | ||
| 1263 | |||
| 1264 | if (!IsValidAddressRange(src_address, size)) { | ||
| 1265 | LOG_ERROR(Kernel_SVC, | ||
| 1266 | "Source address range overflows the address space (src_address=0x{:016X}, " | ||
| 1267 | "size=0x{:016X}).", | ||
| 1268 | src_address, size); | ||
| 1269 | return ERR_INVALID_ADDRESS_STATE; | ||
| 1270 | } | ||
| 1271 | |||
| 1272 | const auto& handle_table = system.Kernel().CurrentProcess()->GetHandleTable(); | ||
| 1273 | auto process = handle_table.Get<Process>(process_handle); | ||
| 1274 | if (!process) { | ||
| 1275 | LOG_ERROR(Kernel_SVC, "Invalid process handle specified (handle=0x{:08X}).", | ||
| 1276 | process_handle); | ||
| 1277 | return ERR_INVALID_HANDLE; | ||
| 1278 | } | ||
| 1279 | |||
| 1280 | auto& page_table = process->PageTable(); | ||
| 1281 | if (!page_table.IsInsideAddressSpace(src_address, size)) { | ||
| 1282 | LOG_ERROR(Kernel_SVC, | ||
| 1283 | "Source address range is not within the address space (src_address=0x{:016X}, " | ||
| 1284 | "size=0x{:016X}).", | ||
| 1285 | src_address, size); | ||
| 1286 | return ERR_INVALID_ADDRESS_STATE; | ||
| 1287 | } | ||
| 1288 | |||
| 1289 | if (!page_table.IsInsideASLRRegion(dst_address, size)) { | ||
| 1290 | LOG_ERROR(Kernel_SVC, | ||
| 1291 | "Destination address range is not within the ASLR region (dst_address=0x{:016X}, " | ||
| 1292 | "size=0x{:016X}).", | ||
| 1293 | dst_address, size); | ||
| 1294 | return ERR_INVALID_MEMORY_RANGE; | ||
| 1295 | } | ||
| 1296 | |||
| 1297 | return page_table.MapProcessCodeMemory(dst_address, src_address, size); | ||
| 1298 | } | ||
| 1299 | |||
| 1300 | static ResultCode UnmapProcessCodeMemory(Core::System& system, Handle process_handle, | ||
| 1301 | u64 dst_address, u64 src_address, u64 size) { | ||
| 1302 | LOG_DEBUG(Kernel_SVC, | ||
| 1303 | "called. process_handle=0x{:08X}, dst_address=0x{:016X}, src_address=0x{:016X}, " | ||
| 1304 | "size=0x{:016X}", | ||
| 1305 | process_handle, dst_address, src_address, size); | ||
| 1306 | |||
| 1307 | if (!Common::Is4KBAligned(dst_address)) { | ||
| 1308 | LOG_ERROR(Kernel_SVC, "dst_address is not page-aligned (dst_address=0x{:016X}).", | ||
| 1309 | dst_address); | ||
| 1310 | return ERR_INVALID_ADDRESS; | ||
| 1311 | } | ||
| 1312 | |||
| 1313 | if (!Common::Is4KBAligned(src_address)) { | ||
| 1314 | LOG_ERROR(Kernel_SVC, "src_address is not page-aligned (src_address=0x{:016X}).", | ||
| 1315 | src_address); | ||
| 1316 | return ERR_INVALID_ADDRESS; | ||
| 1317 | } | ||
| 1318 | |||
| 1319 | if (size == 0 || Common::Is4KBAligned(size)) { | ||
| 1320 | LOG_ERROR(Kernel_SVC, "Size is zero or not page-aligned (size=0x{:016X}).", size); | ||
| 1321 | return ERR_INVALID_SIZE; | ||
| 1322 | } | ||
| 1323 | |||
| 1324 | if (!IsValidAddressRange(dst_address, size)) { | ||
| 1325 | LOG_ERROR(Kernel_SVC, | ||
| 1326 | "Destination address range overflows the address space (dst_address=0x{:016X}, " | ||
| 1327 | "size=0x{:016X}).", | ||
| 1328 | dst_address, size); | ||
| 1329 | return ERR_INVALID_ADDRESS_STATE; | ||
| 1330 | } | ||
| 1331 | |||
| 1332 | if (!IsValidAddressRange(src_address, size)) { | ||
| 1333 | LOG_ERROR(Kernel_SVC, | ||
| 1334 | "Source address range overflows the address space (src_address=0x{:016X}, " | ||
| 1335 | "size=0x{:016X}).", | ||
| 1336 | src_address, size); | ||
| 1337 | return ERR_INVALID_ADDRESS_STATE; | ||
| 1338 | } | ||
| 1339 | |||
| 1340 | const auto& handle_table = system.Kernel().CurrentProcess()->GetHandleTable(); | ||
| 1341 | auto process = handle_table.Get<Process>(process_handle); | ||
| 1342 | if (!process) { | ||
| 1343 | LOG_ERROR(Kernel_SVC, "Invalid process handle specified (handle=0x{:08X}).", | ||
| 1344 | process_handle); | ||
| 1345 | return ERR_INVALID_HANDLE; | ||
| 1346 | } | ||
| 1347 | |||
| 1348 | auto& page_table = process->PageTable(); | ||
| 1349 | if (!page_table.IsInsideAddressSpace(src_address, size)) { | ||
| 1350 | LOG_ERROR(Kernel_SVC, | ||
| 1351 | "Source address range is not within the address space (src_address=0x{:016X}, " | ||
| 1352 | "size=0x{:016X}).", | ||
| 1353 | src_address, size); | ||
| 1354 | return ERR_INVALID_ADDRESS_STATE; | ||
| 1355 | } | ||
| 1356 | |||
| 1357 | if (!page_table.IsInsideASLRRegion(dst_address, size)) { | ||
| 1358 | LOG_ERROR(Kernel_SVC, | ||
| 1359 | "Destination address range is not within the ASLR region (dst_address=0x{:016X}, " | ||
| 1360 | "size=0x{:016X}).", | ||
| 1361 | dst_address, size); | ||
| 1362 | return ERR_INVALID_MEMORY_RANGE; | ||
| 1363 | } | ||
| 1364 | |||
| 1365 | return page_table.UnmapProcessCodeMemory(dst_address, src_address, size); | ||
| 1366 | } | ||
| 1367 | |||
| 1232 | /// Exits the current process | 1368 | /// Exits the current process |
| 1233 | static void ExitProcess(Core::System& system) { | 1369 | static void ExitProcess(Core::System& system) { |
| 1234 | auto* current_process = system.Kernel().CurrentProcess(); | 1370 | auto* current_process = system.Kernel().CurrentProcess(); |
| @@ -2256,8 +2392,8 @@ static const FunctionDef SVC_Table_64[] = { | |||
| 2256 | {0x74, nullptr, "MapProcessMemory"}, | 2392 | {0x74, nullptr, "MapProcessMemory"}, |
| 2257 | {0x75, nullptr, "UnmapProcessMemory"}, | 2393 | {0x75, nullptr, "UnmapProcessMemory"}, |
| 2258 | {0x76, SvcWrap64<QueryProcessMemory>, "QueryProcessMemory"}, | 2394 | {0x76, SvcWrap64<QueryProcessMemory>, "QueryProcessMemory"}, |
| 2259 | {0x77, nullptr, "MapProcessCodeMemory"}, | 2395 | {0x77, SvcWrap64<MapProcessCodeMemory>, "MapProcessCodeMemory"}, |
| 2260 | {0x78, nullptr, "UnmapProcessCodeMemory"}, | 2396 | {0x78, SvcWrap64<UnmapProcessCodeMemory>, "UnmapProcessCodeMemory"}, |
| 2261 | {0x79, nullptr, "CreateProcess"}, | 2397 | {0x79, nullptr, "CreateProcess"}, |
| 2262 | {0x7A, nullptr, "StartProcess"}, | 2398 | {0x7A, nullptr, "StartProcess"}, |
| 2263 | {0x7B, nullptr, "TerminateProcess"}, | 2399 | {0x7B, nullptr, "TerminateProcess"}, |