diff options
| author | 2022-10-14 22:55:51 -0700 | |
|---|---|---|
| committer | 2022-10-18 19:13:35 -0700 | |
| commit | 829e82e264504696ce1d0ae9421a53d16bf104ea (patch) | |
| tree | ce5c5f35eec6c801c51d7ff6242cbd42ad2d84f8 | |
| parent | core: Partially persist emulation state across game boots. (diff) | |
| download | yuzu-829e82e264504696ce1d0ae9421a53d16bf104ea.tar.gz yuzu-829e82e264504696ce1d0ae9421a53d16bf104ea.tar.xz yuzu-829e82e264504696ce1d0ae9421a53d16bf104ea.zip | |
core: hle: kernel: Use result macros for new/changed code.
Diffstat (limited to '')
| -rw-r--r-- | src/core/hle/kernel/k_dynamic_page_manager.h | 2 | ||||
| -rw-r--r-- | src/core/hle/kernel/k_memory_block_manager.cpp | 2 | ||||
| -rw-r--r-- | src/core/hle/kernel/k_memory_block_manager.h | 2 | ||||
| -rw-r--r-- | src/core/hle/kernel/k_page_table.cpp | 111 | ||||
| -rw-r--r-- | src/core/hle/kernel/k_page_table.h | 19 | ||||
| -rw-r--r-- | src/core/hle/kernel/k_process.cpp | 42 | ||||
| -rw-r--r-- | src/core/hle/kernel/k_process.h | 16 | ||||
| -rw-r--r-- | src/core/hle/kernel/k_thread.cpp | 41 | ||||
| -rw-r--r-- | src/core/hle/result.h | 3 |
9 files changed, 110 insertions, 128 deletions
diff --git a/src/core/hle/kernel/k_dynamic_page_manager.h b/src/core/hle/kernel/k_dynamic_page_manager.h index 88d53776a..9076c8fa3 100644 --- a/src/core/hle/kernel/k_dynamic_page_manager.h +++ b/src/core/hle/kernel/k_dynamic_page_manager.h | |||
| @@ -65,7 +65,7 @@ public: | |||
| 65 | m_page_bitmap.SetBit(i); | 65 | m_page_bitmap.SetBit(i); |
| 66 | } | 66 | } |
| 67 | 67 | ||
| 68 | return ResultSuccess; | 68 | R_SUCCEED(); |
| 69 | } | 69 | } |
| 70 | 70 | ||
| 71 | VAddr GetAddress() const { | 71 | VAddr GetAddress() const { |
diff --git a/src/core/hle/kernel/k_memory_block_manager.cpp b/src/core/hle/kernel/k_memory_block_manager.cpp index c908af75a..cf4c1e371 100644 --- a/src/core/hle/kernel/k_memory_block_manager.cpp +++ b/src/core/hle/kernel/k_memory_block_manager.cpp | |||
| @@ -23,7 +23,7 @@ Result KMemoryBlockManager::Initialize(VAddr st, VAddr nd, KMemoryBlockSlabManag | |||
| 23 | KMemoryState::Free, KMemoryPermission::None, KMemoryAttribute::None); | 23 | KMemoryState::Free, KMemoryPermission::None, KMemoryAttribute::None); |
| 24 | m_memory_block_tree.insert(*start_block); | 24 | m_memory_block_tree.insert(*start_block); |
| 25 | 25 | ||
| 26 | return ResultSuccess; | 26 | R_SUCCEED(); |
| 27 | } | 27 | } |
| 28 | 28 | ||
| 29 | void KMemoryBlockManager::Finalize(KMemoryBlockSlabManager* slab_manager, | 29 | void KMemoryBlockManager::Finalize(KMemoryBlockSlabManager* slab_manager, |
diff --git a/src/core/hle/kernel/k_memory_block_manager.h b/src/core/hle/kernel/k_memory_block_manager.h index b4ee4e319..9b5873883 100644 --- a/src/core/hle/kernel/k_memory_block_manager.h +++ b/src/core/hle/kernel/k_memory_block_manager.h | |||
| @@ -35,7 +35,7 @@ private: | |||
| 35 | R_UNLESS(m_blocks[m_index + i] != nullptr, ResultOutOfResource); | 35 | R_UNLESS(m_blocks[m_index + i] != nullptr, ResultOutOfResource); |
| 36 | } | 36 | } |
| 37 | 37 | ||
| 38 | return ResultSuccess; | 38 | R_SUCCEED(); |
| 39 | } | 39 | } |
| 40 | 40 | ||
| 41 | public: | 41 | public: |
diff --git a/src/core/hle/kernel/k_page_table.cpp b/src/core/hle/kernel/k_page_table.cpp index 22098c056..307e491cb 100644 --- a/src/core/hle/kernel/k_page_table.cpp +++ b/src/core/hle/kernel/k_page_table.cpp | |||
| @@ -128,12 +128,9 @@ Result KPageTable::InitializeForProcess(FileSys::ProgramAddressSpaceType as_type | |||
| 128 | alloc_start = process_code_end; | 128 | alloc_start = process_code_end; |
| 129 | alloc_size = end - process_code_end; | 129 | alloc_size = end - process_code_end; |
| 130 | } | 130 | } |
| 131 | const size_t needed_size{ | 131 | const size_t needed_size = |
| 132 | (alias_region_size + heap_region_size + stack_region_size + kernel_map_region_size)}; | 132 | (alias_region_size + heap_region_size + stack_region_size + kernel_map_region_size); |
| 133 | if (alloc_size < needed_size) { | 133 | R_UNLESS(alloc_size >= needed_size, ResultOutOfMemory); |
| 134 | ASSERT(false); | ||
| 135 | return ResultOutOfMemory; | ||
| 136 | } | ||
| 137 | 134 | ||
| 138 | const size_t remaining_size{alloc_size - needed_size}; | 135 | const size_t remaining_size{alloc_size - needed_size}; |
| 139 | 136 | ||
| @@ -259,8 +256,9 @@ Result KPageTable::InitializeForProcess(FileSys::ProgramAddressSpaceType as_type | |||
| 259 | m_page_table_impl = std::make_unique<Common::PageTable>(); | 256 | m_page_table_impl = std::make_unique<Common::PageTable>(); |
| 260 | m_page_table_impl->Resize(m_address_space_width, PageBits); | 257 | m_page_table_impl->Resize(m_address_space_width, PageBits); |
| 261 | 258 | ||
| 262 | return m_memory_block_manager.Initialize(m_address_space_start, m_address_space_end, | 259 | // Initialize our memory block manager. |
| 263 | m_memory_block_slab_manager); | 260 | R_RETURN(m_memory_block_manager.Initialize(m_address_space_start, m_address_space_end, |
| 261 | m_memory_block_slab_manager)); | ||
| 264 | } | 262 | } |
| 265 | 263 | ||
| 266 | void KPageTable::Finalize() { | 264 | void KPageTable::Finalize() { |
| @@ -306,7 +304,7 @@ Result KPageTable::MapProcessCode(VAddr addr, size_t num_pages, KMemoryState sta | |||
| 306 | KMemoryAttribute::None, KMemoryBlockDisableMergeAttribute::Normal, | 304 | KMemoryAttribute::None, KMemoryBlockDisableMergeAttribute::Normal, |
| 307 | KMemoryBlockDisableMergeAttribute::None); | 305 | KMemoryBlockDisableMergeAttribute::None); |
| 308 | 306 | ||
| 309 | return ResultSuccess; | 307 | R_SUCCEED(); |
| 310 | } | 308 | } |
| 311 | 309 | ||
| 312 | Result KPageTable::MapCodeMemory(VAddr dst_address, VAddr src_address, size_t size) { | 310 | Result KPageTable::MapCodeMemory(VAddr dst_address, VAddr src_address, size_t size) { |
| @@ -385,7 +383,7 @@ Result KPageTable::MapCodeMemory(VAddr dst_address, VAddr src_address, size_t si | |||
| 385 | KMemoryBlockDisableMergeAttribute::None); | 383 | KMemoryBlockDisableMergeAttribute::None); |
| 386 | } | 384 | } |
| 387 | 385 | ||
| 388 | return ResultSuccess; | 386 | R_SUCCEED(); |
| 389 | } | 387 | } |
| 390 | 388 | ||
| 391 | Result KPageTable::UnmapCodeMemory(VAddr dst_address, VAddr src_address, size_t size, | 389 | Result KPageTable::UnmapCodeMemory(VAddr dst_address, VAddr src_address, size_t size, |
| @@ -487,7 +485,7 @@ Result KPageTable::UnmapCodeMemory(VAddr dst_address, VAddr src_address, size_t | |||
| 487 | reprotected_pages = true; | 485 | reprotected_pages = true; |
| 488 | } | 486 | } |
| 489 | 487 | ||
| 490 | return ResultSuccess; | 488 | R_SUCCEED(); |
| 491 | } | 489 | } |
| 492 | 490 | ||
| 493 | VAddr KPageTable::FindFreeArea(VAddr region_start, size_t region_num_pages, size_t num_pages, | 491 | VAddr KPageTable::FindFreeArea(VAddr region_start, size_t region_num_pages, size_t num_pages, |
| @@ -558,7 +556,7 @@ Result KPageTable::MakePageGroup(KPageGroup& pg, VAddr addr, size_t num_pages) { | |||
| 558 | R_UNLESS(IsHeapPhysicalAddress(memory_layout, cur_addr), ResultInvalidCurrentMemory); | 556 | R_UNLESS(IsHeapPhysicalAddress(memory_layout, cur_addr), ResultInvalidCurrentMemory); |
| 559 | R_TRY(pg.AddBlock(cur_addr, cur_pages)); | 557 | R_TRY(pg.AddBlock(cur_addr, cur_pages)); |
| 560 | 558 | ||
| 561 | return ResultSuccess; | 559 | R_SUCCEED(); |
| 562 | } | 560 | } |
| 563 | 561 | ||
| 564 | bool KPageTable::IsValidPageGroup(const KPageGroup& pg_ll, VAddr addr, size_t num_pages) { | 562 | bool KPageTable::IsValidPageGroup(const KPageGroup& pg_ll, VAddr addr, size_t num_pages) { |
| @@ -685,7 +683,7 @@ Result KPageTable::UnmapProcessMemory(VAddr dst_addr, size_t size, KPageTable& s | |||
| 685 | 683 | ||
| 686 | m_system.InvalidateCpuInstructionCaches(); | 684 | m_system.InvalidateCpuInstructionCaches(); |
| 687 | 685 | ||
| 688 | return ResultSuccess; | 686 | R_SUCCEED(); |
| 689 | } | 687 | } |
| 690 | 688 | ||
| 691 | Result KPageTable::MapPhysicalMemory(VAddr address, size_t size) { | 689 | Result KPageTable::MapPhysicalMemory(VAddr address, size_t size) { |
| @@ -933,7 +931,7 @@ Result KPageTable::MapPhysicalMemory(VAddr address, size_t size) { | |||
| 933 | // Cancel our guard. | 931 | // Cancel our guard. |
| 934 | unmap_guard.Cancel(); | 932 | unmap_guard.Cancel(); |
| 935 | 933 | ||
| 936 | return ResultSuccess; | 934 | R_SUCCEED(); |
| 937 | } | 935 | } |
| 938 | } | 936 | } |
| 939 | } | 937 | } |
| @@ -1176,7 +1174,7 @@ Result KPageTable::UnmapPhysicalMemory(VAddr address, size_t size) { | |||
| 1176 | // We succeeded. | 1174 | // We succeeded. |
| 1177 | remap_guard.Cancel(); | 1175 | remap_guard.Cancel(); |
| 1178 | 1176 | ||
| 1179 | return ResultSuccess; | 1177 | R_SUCCEED(); |
| 1180 | } | 1178 | } |
| 1181 | 1179 | ||
| 1182 | Result KPageTable::MapMemory(VAddr dst_address, VAddr src_address, size_t size) { | 1180 | Result KPageTable::MapMemory(VAddr dst_address, VAddr src_address, size_t size) { |
| @@ -1243,7 +1241,7 @@ Result KPageTable::MapMemory(VAddr dst_address, VAddr src_address, size_t size) | |||
| 1243 | KMemoryAttribute::None, KMemoryBlockDisableMergeAttribute::Normal, | 1241 | KMemoryAttribute::None, KMemoryBlockDisableMergeAttribute::Normal, |
| 1244 | KMemoryBlockDisableMergeAttribute::None); | 1242 | KMemoryBlockDisableMergeAttribute::None); |
| 1245 | 1243 | ||
| 1246 | return ResultSuccess; | 1244 | R_SUCCEED(); |
| 1247 | } | 1245 | } |
| 1248 | 1246 | ||
| 1249 | Result KPageTable::UnmapMemory(VAddr dst_address, VAddr src_address, size_t size) { | 1247 | Result KPageTable::UnmapMemory(VAddr dst_address, VAddr src_address, size_t size) { |
| @@ -1288,9 +1286,7 @@ Result KPageTable::UnmapMemory(VAddr dst_address, VAddr src_address, size_t size | |||
| 1288 | AddRegionToPages(src_address, num_pages, src_pages); | 1286 | AddRegionToPages(src_address, num_pages, src_pages); |
| 1289 | AddRegionToPages(dst_address, num_pages, dst_pages); | 1287 | AddRegionToPages(dst_address, num_pages, dst_pages); |
| 1290 | 1288 | ||
| 1291 | if (!dst_pages.IsEqual(src_pages)) { | 1289 | R_UNLESS(dst_pages.IsEqual(src_pages), ResultInvalidMemoryRegion); |
| 1292 | return ResultInvalidMemoryRegion; | ||
| 1293 | } | ||
| 1294 | 1290 | ||
| 1295 | { | 1291 | { |
| 1296 | auto block_guard = detail::ScopeExit([&] { MapPages(dst_address, dst_pages, dst_perm); }); | 1292 | auto block_guard = detail::ScopeExit([&] { MapPages(dst_address, dst_pages, dst_perm); }); |
| @@ -1312,7 +1308,7 @@ Result KPageTable::UnmapMemory(VAddr dst_address, VAddr src_address, size_t size | |||
| 1312 | KMemoryAttribute::None, KMemoryBlockDisableMergeAttribute::None, | 1308 | KMemoryAttribute::None, KMemoryBlockDisableMergeAttribute::None, |
| 1313 | KMemoryBlockDisableMergeAttribute::Normal); | 1309 | KMemoryBlockDisableMergeAttribute::Normal); |
| 1314 | 1310 | ||
| 1315 | return ResultSuccess; | 1311 | R_SUCCEED(); |
| 1316 | } | 1312 | } |
| 1317 | 1313 | ||
| 1318 | Result KPageTable::MapPages(VAddr addr, const KPageGroup& page_linked_list, | 1314 | Result KPageTable::MapPages(VAddr addr, const KPageGroup& page_linked_list, |
| @@ -1330,13 +1326,13 @@ Result KPageTable::MapPages(VAddr addr, const KPageGroup& page_linked_list, | |||
| 1330 | ASSERT(Operate(addr, num_pages, KMemoryPermission::None, OperationType::Unmap) | 1326 | ASSERT(Operate(addr, num_pages, KMemoryPermission::None, OperationType::Unmap) |
| 1331 | .IsSuccess()); | 1327 | .IsSuccess()); |
| 1332 | 1328 | ||
| 1333 | return result; | 1329 | R_RETURN(result); |
| 1334 | } | 1330 | } |
| 1335 | 1331 | ||
| 1336 | cur_addr += node.GetNumPages() * PageSize; | 1332 | cur_addr += node.GetNumPages() * PageSize; |
| 1337 | } | 1333 | } |
| 1338 | 1334 | ||
| 1339 | return ResultSuccess; | 1335 | R_SUCCEED(); |
| 1340 | } | 1336 | } |
| 1341 | 1337 | ||
| 1342 | Result KPageTable::MapPages(VAddr address, KPageGroup& page_linked_list, KMemoryState state, | 1338 | Result KPageTable::MapPages(VAddr address, KPageGroup& page_linked_list, KMemoryState state, |
| @@ -1367,7 +1363,7 @@ Result KPageTable::MapPages(VAddr address, KPageGroup& page_linked_list, KMemory | |||
| 1367 | KMemoryAttribute::None, KMemoryBlockDisableMergeAttribute::Normal, | 1363 | KMemoryAttribute::None, KMemoryBlockDisableMergeAttribute::Normal, |
| 1368 | KMemoryBlockDisableMergeAttribute::None); | 1364 | KMemoryBlockDisableMergeAttribute::None); |
| 1369 | 1365 | ||
| 1370 | return ResultSuccess; | 1366 | R_SUCCEED(); |
| 1371 | } | 1367 | } |
| 1372 | 1368 | ||
| 1373 | Result KPageTable::MapPages(VAddr* out_addr, size_t num_pages, size_t alignment, PAddr phys_addr, | 1369 | Result KPageTable::MapPages(VAddr* out_addr, size_t num_pages, size_t alignment, PAddr phys_addr, |
| @@ -1413,7 +1409,7 @@ Result KPageTable::MapPages(VAddr* out_addr, size_t num_pages, size_t alignment, | |||
| 1413 | 1409 | ||
| 1414 | // We successfully mapped the pages. | 1410 | // We successfully mapped the pages. |
| 1415 | *out_addr = addr; | 1411 | *out_addr = addr; |
| 1416 | return ResultSuccess; | 1412 | R_SUCCEED(); |
| 1417 | } | 1413 | } |
| 1418 | 1414 | ||
| 1419 | Result KPageTable::UnmapPages(VAddr addr, const KPageGroup& page_linked_list) { | 1415 | Result KPageTable::UnmapPages(VAddr addr, const KPageGroup& page_linked_list) { |
| @@ -1425,13 +1421,13 @@ Result KPageTable::UnmapPages(VAddr addr, const KPageGroup& page_linked_list) { | |||
| 1425 | if (const auto result{Operate(cur_addr, node.GetNumPages(), KMemoryPermission::None, | 1421 | if (const auto result{Operate(cur_addr, node.GetNumPages(), KMemoryPermission::None, |
| 1426 | OperationType::Unmap)}; | 1422 | OperationType::Unmap)}; |
| 1427 | result.IsError()) { | 1423 | result.IsError()) { |
| 1428 | return result; | 1424 | R_RETURN(result); |
| 1429 | } | 1425 | } |
| 1430 | 1426 | ||
| 1431 | cur_addr += node.GetNumPages() * PageSize; | 1427 | cur_addr += node.GetNumPages() * PageSize; |
| 1432 | } | 1428 | } |
| 1433 | 1429 | ||
| 1434 | return ResultSuccess; | 1430 | R_SUCCEED(); |
| 1435 | } | 1431 | } |
| 1436 | 1432 | ||
| 1437 | Result KPageTable::UnmapPages(VAddr address, KPageGroup& page_linked_list, KMemoryState state) { | 1433 | Result KPageTable::UnmapPages(VAddr address, KPageGroup& page_linked_list, KMemoryState state) { |
| @@ -1465,7 +1461,7 @@ Result KPageTable::UnmapPages(VAddr address, KPageGroup& page_linked_list, KMemo | |||
| 1465 | KMemoryBlockDisableMergeAttribute::None, | 1461 | KMemoryBlockDisableMergeAttribute::None, |
| 1466 | KMemoryBlockDisableMergeAttribute::Normal); | 1462 | KMemoryBlockDisableMergeAttribute::Normal); |
| 1467 | 1463 | ||
| 1468 | return ResultSuccess; | 1464 | R_SUCCEED(); |
| 1469 | } | 1465 | } |
| 1470 | 1466 | ||
| 1471 | Result KPageTable::UnmapPages(VAddr address, size_t num_pages, KMemoryState state) { | 1467 | Result KPageTable::UnmapPages(VAddr address, size_t num_pages, KMemoryState state) { |
| @@ -1498,7 +1494,7 @@ Result KPageTable::UnmapPages(VAddr address, size_t num_pages, KMemoryState stat | |||
| 1498 | KMemoryBlockDisableMergeAttribute::None, | 1494 | KMemoryBlockDisableMergeAttribute::None, |
| 1499 | KMemoryBlockDisableMergeAttribute::Normal); | 1495 | KMemoryBlockDisableMergeAttribute::Normal); |
| 1500 | 1496 | ||
| 1501 | return ResultSuccess; | 1497 | R_SUCCEED(); |
| 1502 | } | 1498 | } |
| 1503 | 1499 | ||
| 1504 | Result KPageTable::MakeAndOpenPageGroup(KPageGroup* out, VAddr address, size_t num_pages, | 1500 | Result KPageTable::MakeAndOpenPageGroup(KPageGroup* out, VAddr address, size_t num_pages, |
| @@ -1523,7 +1519,7 @@ Result KPageTable::MakeAndOpenPageGroup(KPageGroup* out, VAddr address, size_t n | |||
| 1523 | // Create a new page group for the region. | 1519 | // Create a new page group for the region. |
| 1524 | R_TRY(this->MakePageGroup(*out, address, num_pages)); | 1520 | R_TRY(this->MakePageGroup(*out, address, num_pages)); |
| 1525 | 1521 | ||
| 1526 | return ResultSuccess; | 1522 | R_SUCCEED(); |
| 1527 | } | 1523 | } |
| 1528 | 1524 | ||
| 1529 | Result KPageTable::SetProcessMemoryPermission(VAddr addr, size_t size, | 1525 | Result KPageTable::SetProcessMemoryPermission(VAddr addr, size_t size, |
| @@ -1589,7 +1585,7 @@ Result KPageTable::SetProcessMemoryPermission(VAddr addr, size_t size, | |||
| 1589 | m_system.InvalidateCpuInstructionCacheRange(addr, size); | 1585 | m_system.InvalidateCpuInstructionCacheRange(addr, size); |
| 1590 | } | 1586 | } |
| 1591 | 1587 | ||
| 1592 | return ResultSuccess; | 1588 | R_SUCCEED(); |
| 1593 | } | 1589 | } |
| 1594 | 1590 | ||
| 1595 | KMemoryInfo KPageTable::QueryInfoImpl(VAddr addr) { | 1591 | KMemoryInfo KPageTable::QueryInfoImpl(VAddr addr) { |
| @@ -1653,7 +1649,7 @@ Result KPageTable::SetMemoryPermission(VAddr addr, size_t size, Svc::MemoryPermi | |||
| 1653 | KMemoryAttribute::None, KMemoryBlockDisableMergeAttribute::None, | 1649 | KMemoryAttribute::None, KMemoryBlockDisableMergeAttribute::None, |
| 1654 | KMemoryBlockDisableMergeAttribute::None); | 1650 | KMemoryBlockDisableMergeAttribute::None); |
| 1655 | 1651 | ||
| 1656 | return ResultSuccess; | 1652 | R_SUCCEED(); |
| 1657 | } | 1653 | } |
| 1658 | 1654 | ||
| 1659 | Result KPageTable::SetMemoryAttribute(VAddr addr, size_t size, u32 mask, u32 attr) { | 1655 | Result KPageTable::SetMemoryAttribute(VAddr addr, size_t size, u32 mask, u32 attr) { |
| @@ -1696,7 +1692,7 @@ Result KPageTable::SetMemoryAttribute(VAddr addr, size_t size, u32 mask, u32 att | |||
| 1696 | new_attr, KMemoryBlockDisableMergeAttribute::None, | 1692 | new_attr, KMemoryBlockDisableMergeAttribute::None, |
| 1697 | KMemoryBlockDisableMergeAttribute::None); | 1693 | KMemoryBlockDisableMergeAttribute::None); |
| 1698 | 1694 | ||
| 1699 | return ResultSuccess; | 1695 | R_SUCCEED(); |
| 1700 | } | 1696 | } |
| 1701 | 1697 | ||
| 1702 | Result KPageTable::SetMaxHeapSize(size_t size) { | 1698 | Result KPageTable::SetMaxHeapSize(size_t size) { |
| @@ -1708,7 +1704,7 @@ Result KPageTable::SetMaxHeapSize(size_t size) { | |||
| 1708 | 1704 | ||
| 1709 | m_max_heap_size = size; | 1705 | m_max_heap_size = size; |
| 1710 | 1706 | ||
| 1711 | return ResultSuccess; | 1707 | R_SUCCEED(); |
| 1712 | } | 1708 | } |
| 1713 | 1709 | ||
| 1714 | Result KPageTable::SetHeapSize(VAddr* out, size_t size) { | 1710 | Result KPageTable::SetHeapSize(VAddr* out, size_t size) { |
| @@ -1769,11 +1765,11 @@ Result KPageTable::SetHeapSize(VAddr* out, size_t size) { | |||
| 1769 | 1765 | ||
| 1770 | // Set the output. | 1766 | // Set the output. |
| 1771 | *out = m_heap_region_start; | 1767 | *out = m_heap_region_start; |
| 1772 | return ResultSuccess; | 1768 | R_SUCCEED(); |
| 1773 | } else if (size == GetHeapSize()) { | 1769 | } else if (size == GetHeapSize()) { |
| 1774 | // The size requested is exactly the current size. | 1770 | // The size requested is exactly the current size. |
| 1775 | *out = m_heap_region_start; | 1771 | *out = m_heap_region_start; |
| 1776 | return ResultSuccess; | 1772 | R_SUCCEED(); |
| 1777 | } else { | 1773 | } else { |
| 1778 | // We have to allocate memory. Determine how much to allocate and where while the table | 1774 | // We have to allocate memory. Determine how much to allocate and where while the table |
| 1779 | // is locked. | 1775 | // is locked. |
| @@ -1847,7 +1843,7 @@ Result KPageTable::SetHeapSize(VAddr* out, size_t size) { | |||
| 1847 | 1843 | ||
| 1848 | // Set the output. | 1844 | // Set the output. |
| 1849 | *out = m_heap_region_start; | 1845 | *out = m_heap_region_start; |
| 1850 | return ResultSuccess; | 1846 | R_SUCCEED(); |
| 1851 | } | 1847 | } |
| 1852 | } | 1848 | } |
| 1853 | 1849 | ||
| @@ -1857,19 +1853,12 @@ ResultVal<VAddr> KPageTable::AllocateAndMapMemory(size_t needed_num_pages, size_ | |||
| 1857 | KMemoryPermission perm, PAddr map_addr) { | 1853 | KMemoryPermission perm, PAddr map_addr) { |
| 1858 | KScopedLightLock lk(m_general_lock); | 1854 | KScopedLightLock lk(m_general_lock); |
| 1859 | 1855 | ||
| 1860 | if (!CanContain(region_start, region_num_pages * PageSize, state)) { | 1856 | R_UNLESS(CanContain(region_start, region_num_pages * PageSize, state), |
| 1861 | return ResultInvalidCurrentMemory; | 1857 | ResultInvalidCurrentMemory); |
| 1862 | } | 1858 | R_UNLESS(region_num_pages > needed_num_pages, ResultOutOfMemory); |
| 1863 | |||
| 1864 | if (region_num_pages <= needed_num_pages) { | ||
| 1865 | return ResultOutOfMemory; | ||
| 1866 | } | ||
| 1867 | |||
| 1868 | const VAddr addr{ | 1859 | const VAddr addr{ |
| 1869 | AllocateVirtualMemory(region_start, region_num_pages, needed_num_pages, align)}; | 1860 | AllocateVirtualMemory(region_start, region_num_pages, needed_num_pages, align)}; |
| 1870 | if (!addr) { | 1861 | R_UNLESS(addr, ResultOutOfMemory); |
| 1871 | return ResultOutOfMemory; | ||
| 1872 | } | ||
| 1873 | 1862 | ||
| 1874 | // Create an update allocator. | 1863 | // Create an update allocator. |
| 1875 | Result allocator_result{ResultSuccess}; | 1864 | Result allocator_result{ResultSuccess}; |
| @@ -1922,7 +1911,7 @@ Result KPageTable::LockForMapDeviceAddressSpace(VAddr address, size_t size, KMem | |||
| 1922 | m_memory_block_manager.UpdateLock(std::addressof(allocator), address, num_pages, | 1911 | m_memory_block_manager.UpdateLock(std::addressof(allocator), address, num_pages, |
| 1923 | &KMemoryBlock::ShareToDevice, KMemoryPermission::None); | 1912 | &KMemoryBlock::ShareToDevice, KMemoryPermission::None); |
| 1924 | 1913 | ||
| 1925 | return ResultSuccess; | 1914 | R_SUCCEED(); |
| 1926 | } | 1915 | } |
| 1927 | 1916 | ||
| 1928 | Result KPageTable::LockForUnmapDeviceAddressSpace(VAddr address, size_t size) { | 1917 | Result KPageTable::LockForUnmapDeviceAddressSpace(VAddr address, size_t size) { |
| @@ -1956,7 +1945,7 @@ Result KPageTable::LockForUnmapDeviceAddressSpace(VAddr address, size_t size) { | |||
| 1956 | m_memory_block_manager.UpdateLock(std::addressof(allocator), address, num_pages, lock_func, | 1945 | m_memory_block_manager.UpdateLock(std::addressof(allocator), address, num_pages, lock_func, |
| 1957 | KMemoryPermission::None); | 1946 | KMemoryPermission::None); |
| 1958 | 1947 | ||
| 1959 | return ResultSuccess; | 1948 | R_SUCCEED(); |
| 1960 | } | 1949 | } |
| 1961 | 1950 | ||
| 1962 | Result KPageTable::UnlockForDeviceAddressSpace(VAddr address, size_t size) { | 1951 | Result KPageTable::UnlockForDeviceAddressSpace(VAddr address, size_t size) { |
| @@ -1984,24 +1973,24 @@ Result KPageTable::UnlockForDeviceAddressSpace(VAddr address, size_t size) { | |||
| 1984 | m_memory_block_manager.UpdateLock(std::addressof(allocator), address, num_pages, | 1973 | m_memory_block_manager.UpdateLock(std::addressof(allocator), address, num_pages, |
| 1985 | &KMemoryBlock::UnshareToDevice, KMemoryPermission::None); | 1974 | &KMemoryBlock::UnshareToDevice, KMemoryPermission::None); |
| 1986 | 1975 | ||
| 1987 | return ResultSuccess; | 1976 | R_SUCCEED(); |
| 1988 | } | 1977 | } |
| 1989 | 1978 | ||
| 1990 | Result KPageTable::LockForCodeMemory(KPageGroup* out, VAddr addr, size_t size) { | 1979 | Result KPageTable::LockForCodeMemory(KPageGroup* out, VAddr addr, size_t size) { |
| 1991 | return this->LockMemoryAndOpen( | 1980 | R_RETURN(this->LockMemoryAndOpen( |
| 1992 | out, nullptr, addr, size, KMemoryState::FlagCanCodeMemory, KMemoryState::FlagCanCodeMemory, | 1981 | out, nullptr, addr, size, KMemoryState::FlagCanCodeMemory, KMemoryState::FlagCanCodeMemory, |
| 1993 | KMemoryPermission::All, KMemoryPermission::UserReadWrite, KMemoryAttribute::All, | 1982 | KMemoryPermission::All, KMemoryPermission::UserReadWrite, KMemoryAttribute::All, |
| 1994 | KMemoryAttribute::None, | 1983 | KMemoryAttribute::None, |
| 1995 | static_cast<KMemoryPermission>(KMemoryPermission::NotMapped | | 1984 | static_cast<KMemoryPermission>(KMemoryPermission::NotMapped | |
| 1996 | KMemoryPermission::KernelReadWrite), | 1985 | KMemoryPermission::KernelReadWrite), |
| 1997 | KMemoryAttribute::Locked); | 1986 | KMemoryAttribute::Locked)); |
| 1998 | } | 1987 | } |
| 1999 | 1988 | ||
| 2000 | Result KPageTable::UnlockForCodeMemory(VAddr addr, size_t size, const KPageGroup& pg) { | 1989 | Result KPageTable::UnlockForCodeMemory(VAddr addr, size_t size, const KPageGroup& pg) { |
| 2001 | return this->UnlockMemory( | 1990 | R_RETURN(this->UnlockMemory( |
| 2002 | addr, size, KMemoryState::FlagCanCodeMemory, KMemoryState::FlagCanCodeMemory, | 1991 | addr, size, KMemoryState::FlagCanCodeMemory, KMemoryState::FlagCanCodeMemory, |
| 2003 | KMemoryPermission::None, KMemoryPermission::None, KMemoryAttribute::All, | 1992 | KMemoryPermission::None, KMemoryPermission::None, KMemoryAttribute::All, |
| 2004 | KMemoryAttribute::Locked, KMemoryPermission::UserReadWrite, KMemoryAttribute::Locked, &pg); | 1993 | KMemoryAttribute::Locked, KMemoryPermission::UserReadWrite, KMemoryAttribute::Locked, &pg)); |
| 2005 | } | 1994 | } |
| 2006 | 1995 | ||
| 2007 | bool KPageTable::IsRegionContiguous(VAddr addr, u64 size) const { | 1996 | bool KPageTable::IsRegionContiguous(VAddr addr, u64 size) const { |
| @@ -2056,7 +2045,7 @@ Result KPageTable::Operate(VAddr addr, size_t num_pages, const KPageGroup& page_ | |||
| 2056 | addr += size; | 2045 | addr += size; |
| 2057 | } | 2046 | } |
| 2058 | 2047 | ||
| 2059 | return ResultSuccess; | 2048 | R_SUCCEED(); |
| 2060 | } | 2049 | } |
| 2061 | 2050 | ||
| 2062 | Result KPageTable::Operate(VAddr addr, size_t num_pages, KMemoryPermission perm, | 2051 | Result KPageTable::Operate(VAddr addr, size_t num_pages, KMemoryPermission perm, |
| @@ -2083,7 +2072,7 @@ Result KPageTable::Operate(VAddr addr, size_t num_pages, KMemoryPermission perm, | |||
| 2083 | default: | 2072 | default: |
| 2084 | ASSERT(false); | 2073 | ASSERT(false); |
| 2085 | } | 2074 | } |
| 2086 | return ResultSuccess; | 2075 | R_SUCCEED(); |
| 2087 | } | 2076 | } |
| 2088 | 2077 | ||
| 2089 | VAddr KPageTable::GetRegionAddress(KMemoryState state) const { | 2078 | VAddr KPageTable::GetRegionAddress(KMemoryState state) const { |
| @@ -2211,7 +2200,7 @@ Result KPageTable::CheckMemoryState(const KMemoryInfo& info, KMemoryState state_ | |||
| 2211 | R_UNLESS((info.m_permission & perm_mask) == perm, ResultInvalidCurrentMemory); | 2200 | R_UNLESS((info.m_permission & perm_mask) == perm, ResultInvalidCurrentMemory); |
| 2212 | R_UNLESS((info.m_attribute & attr_mask) == attr, ResultInvalidCurrentMemory); | 2201 | R_UNLESS((info.m_attribute & attr_mask) == attr, ResultInvalidCurrentMemory); |
| 2213 | 2202 | ||
| 2214 | return ResultSuccess; | 2203 | R_SUCCEED(); |
| 2215 | } | 2204 | } |
| 2216 | 2205 | ||
| 2217 | Result KPageTable::CheckMemoryStateContiguous(size_t* out_blocks_needed, VAddr addr, size_t size, | 2206 | Result KPageTable::CheckMemoryStateContiguous(size_t* out_blocks_needed, VAddr addr, size_t size, |
| @@ -2253,7 +2242,7 @@ Result KPageTable::CheckMemoryStateContiguous(size_t* out_blocks_needed, VAddr a | |||
| 2253 | *out_blocks_needed = blocks_for_start_align + blocks_for_end_align; | 2242 | *out_blocks_needed = blocks_for_start_align + blocks_for_end_align; |
| 2254 | } | 2243 | } |
| 2255 | 2244 | ||
| 2256 | return ResultSuccess; | 2245 | R_SUCCEED(); |
| 2257 | } | 2246 | } |
| 2258 | 2247 | ||
| 2259 | Result KPageTable::CheckMemoryState(KMemoryState* out_state, KMemoryPermission* out_perm, | 2248 | Result KPageTable::CheckMemoryState(KMemoryState* out_state, KMemoryPermission* out_perm, |
| @@ -2315,7 +2304,7 @@ Result KPageTable::CheckMemoryState(KMemoryState* out_state, KMemoryPermission* | |||
| 2315 | if (out_blocks_needed != nullptr) { | 2304 | if (out_blocks_needed != nullptr) { |
| 2316 | *out_blocks_needed = blocks_for_start_align + blocks_for_end_align; | 2305 | *out_blocks_needed = blocks_for_start_align + blocks_for_end_align; |
| 2317 | } | 2306 | } |
| 2318 | return ResultSuccess; | 2307 | R_SUCCEED(); |
| 2319 | } | 2308 | } |
| 2320 | 2309 | ||
| 2321 | Result KPageTable::LockMemoryAndOpen(KPageGroup* out_pg, PAddr* out_paddr, VAddr addr, size_t size, | 2310 | Result KPageTable::LockMemoryAndOpen(KPageGroup* out_pg, PAddr* out_paddr, VAddr addr, size_t size, |
| @@ -2381,7 +2370,7 @@ Result KPageTable::LockMemoryAndOpen(KPageGroup* out_pg, PAddr* out_paddr, VAddr | |||
| 2381 | new_attr, KMemoryBlockDisableMergeAttribute::Locked, | 2370 | new_attr, KMemoryBlockDisableMergeAttribute::Locked, |
| 2382 | KMemoryBlockDisableMergeAttribute::None); | 2371 | KMemoryBlockDisableMergeAttribute::None); |
| 2383 | 2372 | ||
| 2384 | return ResultSuccess; | 2373 | R_SUCCEED(); |
| 2385 | } | 2374 | } |
| 2386 | 2375 | ||
| 2387 | Result KPageTable::UnlockMemory(VAddr addr, size_t size, KMemoryState state_mask, | 2376 | Result KPageTable::UnlockMemory(VAddr addr, size_t size, KMemoryState state_mask, |
| @@ -2436,7 +2425,7 @@ Result KPageTable::UnlockMemory(VAddr addr, size_t size, KMemoryState state_mask | |||
| 2436 | new_attr, KMemoryBlockDisableMergeAttribute::None, | 2425 | new_attr, KMemoryBlockDisableMergeAttribute::None, |
| 2437 | KMemoryBlockDisableMergeAttribute::Locked); | 2426 | KMemoryBlockDisableMergeAttribute::Locked); |
| 2438 | 2427 | ||
| 2439 | return ResultSuccess; | 2428 | R_SUCCEED(); |
| 2440 | } | 2429 | } |
| 2441 | 2430 | ||
| 2442 | } // namespace Kernel | 2431 | } // namespace Kernel |
diff --git a/src/core/hle/kernel/k_page_table.h b/src/core/hle/kernel/k_page_table.h index 1811d3e2d..c6aeacd96 100644 --- a/src/core/hle/kernel/k_page_table.h +++ b/src/core/hle/kernel/k_page_table.h | |||
| @@ -57,9 +57,9 @@ public: | |||
| 57 | KMemoryPermission perm); | 57 | KMemoryPermission perm); |
| 58 | Result MapPages(VAddr* out_addr, size_t num_pages, size_t alignment, PAddr phys_addr, | 58 | Result MapPages(VAddr* out_addr, size_t num_pages, size_t alignment, PAddr phys_addr, |
| 59 | KMemoryState state, KMemoryPermission perm) { | 59 | KMemoryState state, KMemoryPermission perm) { |
| 60 | return this->MapPages(out_addr, num_pages, alignment, phys_addr, true, | 60 | R_RETURN(this->MapPages(out_addr, num_pages, alignment, phys_addr, true, |
| 61 | this->GetRegionAddress(state), this->GetRegionSize(state) / PageSize, | 61 | this->GetRegionAddress(state), |
| 62 | state, perm); | 62 | this->GetRegionSize(state) / PageSize, state, perm)); |
| 63 | } | 63 | } |
| 64 | Result UnmapPages(VAddr addr, KPageGroup& page_linked_list, KMemoryState state); | 64 | Result UnmapPages(VAddr addr, KPageGroup& page_linked_list, KMemoryState state); |
| 65 | Result UnmapPages(VAddr address, size_t num_pages, KMemoryState state); | 65 | Result UnmapPages(VAddr address, size_t num_pages, KMemoryState state); |
| @@ -137,8 +137,8 @@ private: | |||
| 137 | KMemoryState state, KMemoryPermission perm_mask, | 137 | KMemoryState state, KMemoryPermission perm_mask, |
| 138 | KMemoryPermission perm, KMemoryAttribute attr_mask, | 138 | KMemoryPermission perm, KMemoryAttribute attr_mask, |
| 139 | KMemoryAttribute attr) const { | 139 | KMemoryAttribute attr) const { |
| 140 | return this->CheckMemoryStateContiguous(nullptr, addr, size, state_mask, state, perm_mask, | 140 | R_RETURN(this->CheckMemoryStateContiguous(nullptr, addr, size, state_mask, state, perm_mask, |
| 141 | perm, attr_mask, attr); | 141 | perm, attr_mask, attr)); |
| 142 | } | 142 | } |
| 143 | 143 | ||
| 144 | Result CheckMemoryState(const KMemoryInfo& info, KMemoryState state_mask, KMemoryState state, | 144 | Result CheckMemoryState(const KMemoryInfo& info, KMemoryState state_mask, KMemoryState state, |
| @@ -155,15 +155,16 @@ private: | |||
| 155 | KMemoryPermission perm_mask, KMemoryPermission perm, | 155 | KMemoryPermission perm_mask, KMemoryPermission perm, |
| 156 | KMemoryAttribute attr_mask, KMemoryAttribute attr, | 156 | KMemoryAttribute attr_mask, KMemoryAttribute attr, |
| 157 | KMemoryAttribute ignore_attr = DefaultMemoryIgnoreAttr) const { | 157 | KMemoryAttribute ignore_attr = DefaultMemoryIgnoreAttr) const { |
| 158 | return CheckMemoryState(nullptr, nullptr, nullptr, out_blocks_needed, addr, size, | 158 | R_RETURN(CheckMemoryState(nullptr, nullptr, nullptr, out_blocks_needed, addr, size, |
| 159 | state_mask, state, perm_mask, perm, attr_mask, attr, ignore_attr); | 159 | state_mask, state, perm_mask, perm, attr_mask, attr, |
| 160 | ignore_attr)); | ||
| 160 | } | 161 | } |
| 161 | Result CheckMemoryState(VAddr addr, size_t size, KMemoryState state_mask, KMemoryState state, | 162 | Result CheckMemoryState(VAddr addr, size_t size, KMemoryState state_mask, KMemoryState state, |
| 162 | KMemoryPermission perm_mask, KMemoryPermission perm, | 163 | KMemoryPermission perm_mask, KMemoryPermission perm, |
| 163 | KMemoryAttribute attr_mask, KMemoryAttribute attr, | 164 | KMemoryAttribute attr_mask, KMemoryAttribute attr, |
| 164 | KMemoryAttribute ignore_attr = DefaultMemoryIgnoreAttr) const { | 165 | KMemoryAttribute ignore_attr = DefaultMemoryIgnoreAttr) const { |
| 165 | return this->CheckMemoryState(nullptr, addr, size, state_mask, state, perm_mask, perm, | 166 | R_RETURN(this->CheckMemoryState(nullptr, addr, size, state_mask, state, perm_mask, perm, |
| 166 | attr_mask, attr, ignore_attr); | 167 | attr_mask, attr, ignore_attr)); |
| 167 | } | 168 | } |
| 168 | 169 | ||
| 169 | Result LockMemoryAndOpen(KPageGroup* out_pg, PAddr* out_paddr, VAddr addr, size_t size, | 170 | Result LockMemoryAndOpen(KPageGroup* out_pg, PAddr* out_paddr, VAddr addr, size_t size, |
diff --git a/src/core/hle/kernel/k_process.cpp b/src/core/hle/kernel/k_process.cpp index 1a0aec56a..8c3495e5a 100644 --- a/src/core/hle/kernel/k_process.cpp +++ b/src/core/hle/kernel/k_process.cpp | |||
| @@ -98,7 +98,7 @@ Result KProcess::Initialize(KProcess* process, Core::System& system, std::string | |||
| 98 | // Open a reference to the resource limit. | 98 | // Open a reference to the resource limit. |
| 99 | process->resource_limit->Open(); | 99 | process->resource_limit->Open(); |
| 100 | 100 | ||
| 101 | return ResultSuccess; | 101 | R_SUCCEED(); |
| 102 | } | 102 | } |
| 103 | 103 | ||
| 104 | void KProcess::DoWorkerTaskImpl() { | 104 | void KProcess::DoWorkerTaskImpl() { |
| @@ -246,7 +246,7 @@ Result KProcess::AddSharedMemory(KSharedMemory* shmem, [[maybe_unused]] VAddr ad | |||
| 246 | shmem->Open(); | 246 | shmem->Open(); |
| 247 | shemen_info->Open(); | 247 | shemen_info->Open(); |
| 248 | 248 | ||
| 249 | return ResultSuccess; | 249 | R_SUCCEED(); |
| 250 | } | 250 | } |
| 251 | 251 | ||
| 252 | void KProcess::RemoveSharedMemory(KSharedMemory* shmem, [[maybe_unused]] VAddr address, | 252 | void KProcess::RemoveSharedMemory(KSharedMemory* shmem, [[maybe_unused]] VAddr address, |
| @@ -296,7 +296,7 @@ Result KProcess::Reset() { | |||
| 296 | 296 | ||
| 297 | // Clear signaled. | 297 | // Clear signaled. |
| 298 | is_signaled = false; | 298 | is_signaled = false; |
| 299 | return ResultSuccess; | 299 | R_SUCCEED(); |
| 300 | } | 300 | } |
| 301 | 301 | ||
| 302 | Result KProcess::SetActivity(ProcessActivity activity) { | 302 | Result KProcess::SetActivity(ProcessActivity activity) { |
| @@ -312,9 +312,7 @@ Result KProcess::SetActivity(ProcessActivity activity) { | |||
| 312 | // Either pause or resume. | 312 | // Either pause or resume. |
| 313 | if (activity == ProcessActivity::Paused) { | 313 | if (activity == ProcessActivity::Paused) { |
| 314 | // Verify that we're not suspended. | 314 | // Verify that we're not suspended. |
| 315 | if (is_suspended) { | 315 | R_UNLESS(!is_suspended, ResultInvalidState); |
| 316 | return ResultInvalidState; | ||
| 317 | } | ||
| 318 | 316 | ||
| 319 | // Suspend all threads. | 317 | // Suspend all threads. |
| 320 | for (auto* thread : GetThreadList()) { | 318 | for (auto* thread : GetThreadList()) { |
| @@ -327,9 +325,7 @@ Result KProcess::SetActivity(ProcessActivity activity) { | |||
| 327 | ASSERT(activity == ProcessActivity::Runnable); | 325 | ASSERT(activity == ProcessActivity::Runnable); |
| 328 | 326 | ||
| 329 | // Verify that we're suspended. | 327 | // Verify that we're suspended. |
| 330 | if (!is_suspended) { | 328 | R_UNLESS(is_suspended, ResultInvalidState); |
| 331 | return ResultInvalidState; | ||
| 332 | } | ||
| 333 | 329 | ||
| 334 | // Resume all threads. | 330 | // Resume all threads. |
| 335 | for (auto* thread : GetThreadList()) { | 331 | for (auto* thread : GetThreadList()) { |
| @@ -340,7 +336,7 @@ Result KProcess::SetActivity(ProcessActivity activity) { | |||
| 340 | SetSuspended(false); | 336 | SetSuspended(false); |
| 341 | } | 337 | } |
| 342 | 338 | ||
| 343 | return ResultSuccess; | 339 | R_SUCCEED(); |
| 344 | } | 340 | } |
| 345 | 341 | ||
| 346 | Result KProcess::LoadFromMetadata(const FileSys::ProgramMetadata& metadata, std::size_t code_size) { | 342 | Result KProcess::LoadFromMetadata(const FileSys::ProgramMetadata& metadata, std::size_t code_size) { |
| @@ -358,14 +354,14 @@ Result KProcess::LoadFromMetadata(const FileSys::ProgramMetadata& metadata, std: | |||
| 358 | if (!memory_reservation.Succeeded()) { | 354 | if (!memory_reservation.Succeeded()) { |
| 359 | LOG_ERROR(Kernel, "Could not reserve process memory requirements of size {:X} bytes", | 355 | LOG_ERROR(Kernel, "Could not reserve process memory requirements of size {:X} bytes", |
| 360 | code_size + system_resource_size); | 356 | code_size + system_resource_size); |
| 361 | return ResultLimitReached; | 357 | R_RETURN(ResultLimitReached); |
| 362 | } | 358 | } |
| 363 | // Initialize proces address space | 359 | // Initialize proces address space |
| 364 | if (const Result result{page_table.InitializeForProcess( | 360 | if (const Result result{page_table.InitializeForProcess( |
| 365 | metadata.GetAddressSpaceType(), false, 0x8000000, code_size, | 361 | metadata.GetAddressSpaceType(), false, 0x8000000, code_size, |
| 366 | &kernel.GetApplicationMemoryBlockManager(), KMemoryManager::Pool::Application)}; | 362 | &kernel.GetApplicationMemoryBlockManager(), KMemoryManager::Pool::Application)}; |
| 367 | result.IsError()) { | 363 | result.IsError()) { |
| 368 | return result; | 364 | R_RETURN(result); |
| 369 | } | 365 | } |
| 370 | 366 | ||
| 371 | // Map process code region | 367 | // Map process code region |
| @@ -373,7 +369,7 @@ Result KProcess::LoadFromMetadata(const FileSys::ProgramMetadata& metadata, std: | |||
| 373 | code_size / PageSize, KMemoryState::Code, | 369 | code_size / PageSize, KMemoryState::Code, |
| 374 | KMemoryPermission::None)}; | 370 | KMemoryPermission::None)}; |
| 375 | result.IsError()) { | 371 | result.IsError()) { |
| 376 | return result; | 372 | R_RETURN(result); |
| 377 | } | 373 | } |
| 378 | 374 | ||
| 379 | // Initialize process capabilities | 375 | // Initialize process capabilities |
| @@ -381,7 +377,7 @@ Result KProcess::LoadFromMetadata(const FileSys::ProgramMetadata& metadata, std: | |||
| 381 | if (const Result result{ | 377 | if (const Result result{ |
| 382 | capabilities.InitializeForUserProcess(caps.data(), caps.size(), page_table)}; | 378 | capabilities.InitializeForUserProcess(caps.data(), caps.size(), page_table)}; |
| 383 | result.IsError()) { | 379 | result.IsError()) { |
| 384 | return result; | 380 | R_RETURN(result); |
| 385 | } | 381 | } |
| 386 | 382 | ||
| 387 | // Set memory usage capacity | 383 | // Set memory usage capacity |
| @@ -405,7 +401,7 @@ Result KProcess::LoadFromMetadata(const FileSys::ProgramMetadata& metadata, std: | |||
| 405 | R_TRY(this->CreateThreadLocalRegion(std::addressof(plr_address))); | 401 | R_TRY(this->CreateThreadLocalRegion(std::addressof(plr_address))); |
| 406 | memory_reservation.Commit(); | 402 | memory_reservation.Commit(); |
| 407 | 403 | ||
| 408 | return handle_table.Initialize(capabilities.GetHandleTableSize()); | 404 | R_RETURN(handle_table.Initialize(capabilities.GetHandleTableSize())); |
| 409 | } | 405 | } |
| 410 | 406 | ||
| 411 | void KProcess::Run(s32 main_thread_priority, u64 stack_size) { | 407 | void KProcess::Run(s32 main_thread_priority, u64 stack_size) { |
| @@ -504,7 +500,7 @@ Result KProcess::CreateThreadLocalRegion(VAddr* out) { | |||
| 504 | } | 500 | } |
| 505 | 501 | ||
| 506 | *out = tlr; | 502 | *out = tlr; |
| 507 | return ResultSuccess; | 503 | R_SUCCEED(); |
| 508 | } | 504 | } |
| 509 | } | 505 | } |
| 510 | 506 | ||
| @@ -533,7 +529,7 @@ Result KProcess::CreateThreadLocalRegion(VAddr* out) { | |||
| 533 | // We succeeded! | 529 | // We succeeded! |
| 534 | tlp_guard.Cancel(); | 530 | tlp_guard.Cancel(); |
| 535 | *out = tlr; | 531 | *out = tlr; |
| 536 | return ResultSuccess; | 532 | R_SUCCEED(); |
| 537 | } | 533 | } |
| 538 | 534 | ||
| 539 | Result KProcess::DeleteThreadLocalRegion(VAddr addr) { | 535 | Result KProcess::DeleteThreadLocalRegion(VAddr addr) { |
| @@ -581,7 +577,7 @@ Result KProcess::DeleteThreadLocalRegion(VAddr addr) { | |||
| 581 | KThreadLocalPage::Free(kernel, page_to_free); | 577 | KThreadLocalPage::Free(kernel, page_to_free); |
| 582 | } | 578 | } |
| 583 | 579 | ||
| 584 | return ResultSuccess; | 580 | R_SUCCEED(); |
| 585 | } | 581 | } |
| 586 | 582 | ||
| 587 | bool KProcess::InsertWatchpoint(Core::System& system, VAddr addr, u64 size, | 583 | bool KProcess::InsertWatchpoint(Core::System& system, VAddr addr, u64 size, |
| @@ -682,15 +678,7 @@ Result KProcess::AllocateMainThreadStack(std::size_t stack_size) { | |||
| 682 | 678 | ||
| 683 | main_thread_stack_top += main_thread_stack_size; | 679 | main_thread_stack_top += main_thread_stack_size; |
| 684 | 680 | ||
| 685 | return ResultSuccess; | 681 | R_SUCCEED(); |
| 686 | } | ||
| 687 | |||
| 688 | void KProcess::FinalizeHandleTable() { | ||
| 689 | // Finalize the table. | ||
| 690 | handle_table.Finalize(); | ||
| 691 | |||
| 692 | // Note that the table is finalized. | ||
| 693 | is_handle_table_initialized = false; | ||
| 694 | } | 682 | } |
| 695 | 683 | ||
| 696 | } // namespace Kernel | 684 | } // namespace Kernel |
diff --git a/src/core/hle/kernel/k_process.h b/src/core/hle/kernel/k_process.h index fcc2897f9..788faec1d 100644 --- a/src/core/hle/kernel/k_process.h +++ b/src/core/hle/kernel/k_process.h | |||
| @@ -138,16 +138,16 @@ public: | |||
| 138 | } | 138 | } |
| 139 | 139 | ||
| 140 | Result WaitConditionVariable(VAddr address, u64 cv_key, u32 tag, s64 ns) { | 140 | Result WaitConditionVariable(VAddr address, u64 cv_key, u32 tag, s64 ns) { |
| 141 | return condition_var.Wait(address, cv_key, tag, ns); | 141 | R_RETURN(condition_var.Wait(address, cv_key, tag, ns)); |
| 142 | } | 142 | } |
| 143 | 143 | ||
| 144 | Result SignalAddressArbiter(VAddr address, Svc::SignalType signal_type, s32 value, s32 count) { | 144 | Result SignalAddressArbiter(VAddr address, Svc::SignalType signal_type, s32 value, s32 count) { |
| 145 | return address_arbiter.SignalToAddress(address, signal_type, value, count); | 145 | R_RETURN(address_arbiter.SignalToAddress(address, signal_type, value, count)); |
| 146 | } | 146 | } |
| 147 | 147 | ||
| 148 | Result WaitAddressArbiter(VAddr address, Svc::ArbitrationType arb_type, s32 value, | 148 | Result WaitAddressArbiter(VAddr address, Svc::ArbitrationType arb_type, s32 value, |
| 149 | s64 timeout) { | 149 | s64 timeout) { |
| 150 | return address_arbiter.WaitForAddress(address, arb_type, value, timeout); | 150 | R_RETURN(address_arbiter.WaitForAddress(address, arb_type, value, timeout)); |
| 151 | } | 151 | } |
| 152 | 152 | ||
| 153 | VAddr GetProcessLocalRegionAddress() const { | 153 | VAddr GetProcessLocalRegionAddress() const { |
| @@ -407,13 +407,19 @@ private: | |||
| 407 | pinned_threads[core_id] = nullptr; | 407 | pinned_threads[core_id] = nullptr; |
| 408 | } | 408 | } |
| 409 | 409 | ||
| 410 | void FinalizeHandleTable() { | ||
| 411 | // Finalize the table. | ||
| 412 | handle_table.Finalize(); | ||
| 413 | |||
| 414 | // Note that the table is finalized. | ||
| 415 | is_handle_table_initialized = false; | ||
| 416 | } | ||
| 417 | |||
| 410 | void ChangeState(State new_state); | 418 | void ChangeState(State new_state); |
| 411 | 419 | ||
| 412 | /// Allocates the main thread stack for the process, given the stack size in bytes. | 420 | /// Allocates the main thread stack for the process, given the stack size in bytes. |
| 413 | Result AllocateMainThreadStack(std::size_t stack_size); | 421 | Result AllocateMainThreadStack(std::size_t stack_size); |
| 414 | 422 | ||
| 415 | void FinalizeHandleTable(); | ||
| 416 | |||
| 417 | /// Memory manager for this process | 423 | /// Memory manager for this process |
| 418 | KPageTable page_table; | 424 | KPageTable page_table; |
| 419 | 425 | ||
diff --git a/src/core/hle/kernel/k_thread.cpp b/src/core/hle/kernel/k_thread.cpp index 89b32d509..b7bfcdce3 100644 --- a/src/core/hle/kernel/k_thread.cpp +++ b/src/core/hle/kernel/k_thread.cpp | |||
| @@ -245,7 +245,7 @@ Result KThread::Initialize(KThreadFunction func, uintptr_t arg, VAddr user_stack | |||
| 245 | } | 245 | } |
| 246 | } | 246 | } |
| 247 | 247 | ||
| 248 | return ResultSuccess; | 248 | R_SUCCEED(); |
| 249 | } | 249 | } |
| 250 | 250 | ||
| 251 | Result KThread::InitializeThread(KThread* thread, KThreadFunction func, uintptr_t arg, | 251 | Result KThread::InitializeThread(KThread* thread, KThreadFunction func, uintptr_t arg, |
| @@ -258,7 +258,7 @@ Result KThread::InitializeThread(KThread* thread, KThreadFunction func, uintptr_ | |||
| 258 | thread->host_context = std::make_shared<Common::Fiber>(std::move(init_func)); | 258 | thread->host_context = std::make_shared<Common::Fiber>(std::move(init_func)); |
| 259 | thread->is_single_core = !Settings::values.use_multi_core.GetValue(); | 259 | thread->is_single_core = !Settings::values.use_multi_core.GetValue(); |
| 260 | 260 | ||
| 261 | return ResultSuccess; | 261 | R_SUCCEED(); |
| 262 | } | 262 | } |
| 263 | 263 | ||
| 264 | Result KThread::InitializeDummyThread(KThread* thread) { | 264 | Result KThread::InitializeDummyThread(KThread* thread) { |
| @@ -268,31 +268,32 @@ Result KThread::InitializeDummyThread(KThread* thread) { | |||
| 268 | // Initialize emulation parameters. | 268 | // Initialize emulation parameters. |
| 269 | thread->stack_parameters.disable_count = 0; | 269 | thread->stack_parameters.disable_count = 0; |
| 270 | 270 | ||
| 271 | return ResultSuccess; | 271 | R_SUCCEED(); |
| 272 | } | 272 | } |
| 273 | 273 | ||
| 274 | Result KThread::InitializeMainThread(Core::System& system, KThread* thread, s32 virt_core) { | 274 | Result KThread::InitializeMainThread(Core::System& system, KThread* thread, s32 virt_core) { |
| 275 | return InitializeThread(thread, {}, {}, {}, IdleThreadPriority, virt_core, {}, ThreadType::Main, | 275 | R_RETURN(InitializeThread(thread, {}, {}, {}, IdleThreadPriority, virt_core, {}, |
| 276 | system.GetCpuManager().GetGuestActivateFunc()); | 276 | ThreadType::Main, system.GetCpuManager().GetGuestActivateFunc())); |
| 277 | } | 277 | } |
| 278 | 278 | ||
| 279 | Result KThread::InitializeIdleThread(Core::System& system, KThread* thread, s32 virt_core) { | 279 | Result KThread::InitializeIdleThread(Core::System& system, KThread* thread, s32 virt_core) { |
| 280 | return InitializeThread(thread, {}, {}, {}, IdleThreadPriority, virt_core, {}, ThreadType::Main, | 280 | R_RETURN(InitializeThread(thread, {}, {}, {}, IdleThreadPriority, virt_core, {}, |
| 281 | system.GetCpuManager().GetIdleThreadStartFunc()); | 281 | ThreadType::Main, system.GetCpuManager().GetIdleThreadStartFunc())); |
| 282 | } | 282 | } |
| 283 | 283 | ||
| 284 | Result KThread::InitializeHighPriorityThread(Core::System& system, KThread* thread, | 284 | Result KThread::InitializeHighPriorityThread(Core::System& system, KThread* thread, |
| 285 | KThreadFunction func, uintptr_t arg, s32 virt_core) { | 285 | KThreadFunction func, uintptr_t arg, s32 virt_core) { |
| 286 | return InitializeThread(thread, func, arg, {}, {}, virt_core, nullptr, ThreadType::HighPriority, | 286 | R_RETURN(InitializeThread(thread, func, arg, {}, {}, virt_core, nullptr, |
| 287 | system.GetCpuManager().GetShutdownThreadStartFunc()); | 287 | ThreadType::HighPriority, |
| 288 | system.GetCpuManager().GetShutdownThreadStartFunc())); | ||
| 288 | } | 289 | } |
| 289 | 290 | ||
| 290 | Result KThread::InitializeUserThread(Core::System& system, KThread* thread, KThreadFunction func, | 291 | Result KThread::InitializeUserThread(Core::System& system, KThread* thread, KThreadFunction func, |
| 291 | uintptr_t arg, VAddr user_stack_top, s32 prio, s32 virt_core, | 292 | uintptr_t arg, VAddr user_stack_top, s32 prio, s32 virt_core, |
| 292 | KProcess* owner) { | 293 | KProcess* owner) { |
| 293 | system.Kernel().GlobalSchedulerContext().AddThread(thread); | 294 | system.Kernel().GlobalSchedulerContext().AddThread(thread); |
| 294 | return InitializeThread(thread, func, arg, user_stack_top, prio, virt_core, owner, | 295 | R_RETURN(InitializeThread(thread, func, arg, user_stack_top, prio, virt_core, owner, |
| 295 | ThreadType::User, system.GetCpuManager().GetGuestThreadFunc()); | 296 | ThreadType::User, system.GetCpuManager().GetGuestThreadFunc())); |
| 296 | } | 297 | } |
| 297 | 298 | ||
| 298 | void KThread::PostDestroy(uintptr_t arg) { | 299 | void KThread::PostDestroy(uintptr_t arg) { |
| @@ -542,7 +543,7 @@ Result KThread::GetCoreMask(s32* out_ideal_core, u64* out_affinity_mask) { | |||
| 542 | *out_ideal_core = virtual_ideal_core_id; | 543 | *out_ideal_core = virtual_ideal_core_id; |
| 543 | *out_affinity_mask = virtual_affinity_mask; | 544 | *out_affinity_mask = virtual_affinity_mask; |
| 544 | 545 | ||
| 545 | return ResultSuccess; | 546 | R_SUCCEED(); |
| 546 | } | 547 | } |
| 547 | 548 | ||
| 548 | Result KThread::GetPhysicalCoreMask(s32* out_ideal_core, u64* out_affinity_mask) { | 549 | Result KThread::GetPhysicalCoreMask(s32* out_ideal_core, u64* out_affinity_mask) { |
| @@ -558,7 +559,7 @@ Result KThread::GetPhysicalCoreMask(s32* out_ideal_core, u64* out_affinity_mask) | |||
| 558 | *out_affinity_mask = original_physical_affinity_mask.GetAffinityMask(); | 559 | *out_affinity_mask = original_physical_affinity_mask.GetAffinityMask(); |
| 559 | } | 560 | } |
| 560 | 561 | ||
| 561 | return ResultSuccess; | 562 | R_SUCCEED(); |
| 562 | } | 563 | } |
| 563 | 564 | ||
| 564 | Result KThread::SetCoreMask(s32 core_id_, u64 v_affinity_mask) { | 565 | Result KThread::SetCoreMask(s32 core_id_, u64 v_affinity_mask) { |
| @@ -670,7 +671,7 @@ Result KThread::SetCoreMask(s32 core_id_, u64 v_affinity_mask) { | |||
| 670 | } while (retry_update); | 671 | } while (retry_update); |
| 671 | } | 672 | } |
| 672 | 673 | ||
| 673 | return ResultSuccess; | 674 | R_SUCCEED(); |
| 674 | } | 675 | } |
| 675 | 676 | ||
| 676 | void KThread::SetBasePriority(s32 value) { | 677 | void KThread::SetBasePriority(s32 value) { |
| @@ -843,7 +844,7 @@ Result KThread::SetActivity(Svc::ThreadActivity activity) { | |||
| 843 | } while (thread_is_current); | 844 | } while (thread_is_current); |
| 844 | } | 845 | } |
| 845 | 846 | ||
| 846 | return ResultSuccess; | 847 | R_SUCCEED(); |
| 847 | } | 848 | } |
| 848 | 849 | ||
| 849 | Result KThread::GetThreadContext3(std::vector<u8>& out) { | 850 | Result KThread::GetThreadContext3(std::vector<u8>& out) { |
| @@ -878,7 +879,7 @@ Result KThread::GetThreadContext3(std::vector<u8>& out) { | |||
| 878 | } | 879 | } |
| 879 | } | 880 | } |
| 880 | 881 | ||
| 881 | return ResultSuccess; | 882 | R_SUCCEED(); |
| 882 | } | 883 | } |
| 883 | 884 | ||
| 884 | void KThread::AddWaiterImpl(KThread* thread) { | 885 | void KThread::AddWaiterImpl(KThread* thread) { |
| @@ -1042,7 +1043,7 @@ Result KThread::Run() { | |||
| 1042 | // Set our state and finish. | 1043 | // Set our state and finish. |
| 1043 | SetState(ThreadState::Runnable); | 1044 | SetState(ThreadState::Runnable); |
| 1044 | 1045 | ||
| 1045 | return ResultSuccess; | 1046 | R_SUCCEED(); |
| 1046 | } | 1047 | } |
| 1047 | } | 1048 | } |
| 1048 | 1049 | ||
| @@ -1089,7 +1090,7 @@ Result KThread::Terminate() { | |||
| 1089 | Svc::WaitInfinite)); | 1090 | Svc::WaitInfinite)); |
| 1090 | } | 1091 | } |
| 1091 | 1092 | ||
| 1092 | return ResultSuccess; | 1093 | R_SUCCEED(); |
| 1093 | } | 1094 | } |
| 1094 | 1095 | ||
| 1095 | ThreadState KThread::RequestTerminate() { | 1096 | ThreadState KThread::RequestTerminate() { |
| @@ -1162,7 +1163,7 @@ Result KThread::Sleep(s64 timeout) { | |||
| 1162 | // Check if the thread should terminate. | 1163 | // Check if the thread should terminate. |
| 1163 | if (this->IsTerminationRequested()) { | 1164 | if (this->IsTerminationRequested()) { |
| 1164 | slp.CancelSleep(); | 1165 | slp.CancelSleep(); |
| 1165 | return ResultTerminationRequested; | 1166 | R_THROW(ResultTerminationRequested); |
| 1166 | } | 1167 | } |
| 1167 | 1168 | ||
| 1168 | // Wait for the sleep to end. | 1169 | // Wait for the sleep to end. |
| @@ -1170,7 +1171,7 @@ Result KThread::Sleep(s64 timeout) { | |||
| 1170 | SetWaitReasonForDebugging(ThreadWaitReasonForDebugging::Sleep); | 1171 | SetWaitReasonForDebugging(ThreadWaitReasonForDebugging::Sleep); |
| 1171 | } | 1172 | } |
| 1172 | 1173 | ||
| 1173 | return ResultSuccess; | 1174 | R_SUCCEED(); |
| 1174 | } | 1175 | } |
| 1175 | 1176 | ||
| 1176 | void KThread::IfDummyThreadTryWait() { | 1177 | void KThread::IfDummyThreadTryWait() { |
diff --git a/src/core/hle/result.h b/src/core/hle/result.h index d714dea38..ef4b2d417 100644 --- a/src/core/hle/result.h +++ b/src/core/hle/result.h | |||
| @@ -470,9 +470,6 @@ constexpr inline Result __TmpCurrentResultReference = ResultSuccess; | |||
| 470 | #define R_UNLESS(expr, res) \ | 470 | #define R_UNLESS(expr, res) \ |
| 471 | { \ | 471 | { \ |
| 472 | if (!(expr)) { \ | 472 | if (!(expr)) { \ |
| 473 | if (res.IsError()) { \ | ||
| 474 | LOG_ERROR(Kernel, "Failed with result: {}", res.raw); \ | ||
| 475 | } \ | ||
| 476 | R_THROW(res); \ | 473 | R_THROW(res); \ |
| 477 | } \ | 474 | } \ |
| 478 | } | 475 | } |