diff options
Diffstat (limited to 'src/core')
77 files changed, 1692 insertions, 435 deletions
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 4755ec822..64fdf38cd 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt | |||
| @@ -156,6 +156,8 @@ add_library(core STATIC | |||
| 156 | hle/service/am/omm.h | 156 | hle/service/am/omm.h |
| 157 | hle/service/am/spsm.cpp | 157 | hle/service/am/spsm.cpp |
| 158 | hle/service/am/spsm.h | 158 | hle/service/am/spsm.h |
| 159 | hle/service/am/tcap.cpp | ||
| 160 | hle/service/am/tcap.h | ||
| 159 | hle/service/aoc/aoc_u.cpp | 161 | hle/service/aoc/aoc_u.cpp |
| 160 | hle/service/aoc/aoc_u.h | 162 | hle/service/aoc/aoc_u.h |
| 161 | hle/service/apm/apm.cpp | 163 | hle/service/apm/apm.cpp |
| @@ -280,6 +282,8 @@ add_library(core STATIC | |||
| 280 | hle/service/nifm/nifm.h | 282 | hle/service/nifm/nifm.h |
| 281 | hle/service/nim/nim.cpp | 283 | hle/service/nim/nim.cpp |
| 282 | hle/service/nim/nim.h | 284 | hle/service/nim/nim.h |
| 285 | hle/service/npns/npns.cpp | ||
| 286 | hle/service/npns/npns.h | ||
| 283 | hle/service/ns/ns.cpp | 287 | hle/service/ns/ns.cpp |
| 284 | hle/service/ns/ns.h | 288 | hle/service/ns/ns.h |
| 285 | hle/service/ns/pl_u.cpp | 289 | hle/service/ns/pl_u.cpp |
| @@ -327,6 +331,8 @@ add_library(core STATIC | |||
| 327 | hle/service/prepo/prepo.h | 331 | hle/service/prepo/prepo.h |
| 328 | hle/service/psc/psc.cpp | 332 | hle/service/psc/psc.cpp |
| 329 | hle/service/psc/psc.h | 333 | hle/service/psc/psc.h |
| 334 | hle/service/ptm/psm.cpp | ||
| 335 | hle/service/ptm/psm.h | ||
| 330 | hle/service/service.cpp | 336 | hle/service/service.cpp |
| 331 | hle/service/service.h | 337 | hle/service/service.h |
| 332 | hle/service/set/set.cpp | 338 | hle/service/set/set.cpp |
diff --git a/src/core/crypto/key_manager.cpp b/src/core/crypto/key_manager.cpp index fd0786068..fefc3c747 100644 --- a/src/core/crypto/key_manager.cpp +++ b/src/core/crypto/key_manager.cpp | |||
| @@ -713,7 +713,6 @@ void KeyManager::DeriveBase() { | |||
| 713 | 713 | ||
| 714 | const auto sbk = GetKey(S128KeyType::SecureBoot); | 714 | const auto sbk = GetKey(S128KeyType::SecureBoot); |
| 715 | const auto tsec = GetKey(S128KeyType::TSEC); | 715 | const auto tsec = GetKey(S128KeyType::TSEC); |
| 716 | const auto master_source = GetKey(S128KeyType::Source, static_cast<u64>(SourceKeyType::Master)); | ||
| 717 | 716 | ||
| 718 | for (size_t i = 0; i < revisions.size(); ++i) { | 717 | for (size_t i = 0; i < revisions.size(); ++i) { |
| 719 | if (!revisions[i]) | 718 | if (!revisions[i]) |
diff --git a/src/core/crypto/partition_data_manager.cpp b/src/core/crypto/partition_data_manager.cpp index 25cee1f3a..ed0775444 100644 --- a/src/core/crypto/partition_data_manager.cpp +++ b/src/core/crypto/partition_data_manager.cpp | |||
| @@ -516,7 +516,8 @@ void PartitionDataManager::DecryptPackage2(const std::array<Key128, 0x20>& packa | |||
| 516 | out.insert(out.end(), rodata.begin(), rodata.end()); | 516 | out.insert(out.end(), rodata.begin(), rodata.end()); |
| 517 | out.insert(out.end(), data.begin(), data.end()); | 517 | out.insert(out.end(), data.begin(), data.end()); |
| 518 | 518 | ||
| 519 | offset += sizeof(KIPHeader) + out.size(); | 519 | offset += sizeof(KIPHeader) + kip.sections[0].size_compressed + |
| 520 | kip.sections[1].size_compressed + kip.sections[2].size_compressed; | ||
| 520 | 521 | ||
| 521 | if (name == "FS") | 522 | if (name == "FS") |
| 522 | package2_fs[static_cast<size_t>(type)] = std::move(out); | 523 | package2_fs[static_cast<size_t>(type)] = std::move(out); |
diff --git a/src/core/file_sys/ips_layer.cpp b/src/core/file_sys/ips_layer.cpp index 554eae9bc..999939d5a 100644 --- a/src/core/file_sys/ips_layer.cpp +++ b/src/core/file_sys/ips_layer.cpp | |||
| @@ -99,7 +99,7 @@ VirtualFile PatchIPS(const VirtualFile& in, const VirtualFile& ips) { | |||
| 99 | u16 rle_size{}; | 99 | u16 rle_size{}; |
| 100 | if (ips->ReadObject(&rle_size, offset) != sizeof(u16)) | 100 | if (ips->ReadObject(&rle_size, offset) != sizeof(u16)) |
| 101 | return nullptr; | 101 | return nullptr; |
| 102 | rle_size = Common::swap16(data_size); | 102 | rle_size = Common::swap16(rle_size); |
| 103 | offset += sizeof(u16); | 103 | offset += sizeof(u16); |
| 104 | 104 | ||
| 105 | const auto data = ips->ReadByte(offset++); | 105 | const auto data = ips->ReadByte(offset++); |
diff --git a/src/core/file_sys/patch_manager.cpp b/src/core/file_sys/patch_manager.cpp index 0117cb0bf..1f4928562 100644 --- a/src/core/file_sys/patch_manager.cpp +++ b/src/core/file_sys/patch_manager.cpp | |||
| @@ -168,7 +168,8 @@ bool PatchManager::HasNSOPatch(const std::array<u8, 32>& build_id_) const { | |||
| 168 | 168 | ||
| 169 | static void ApplyLayeredFS(VirtualFile& romfs, u64 title_id, ContentRecordType type) { | 169 | static void ApplyLayeredFS(VirtualFile& romfs, u64 title_id, ContentRecordType type) { |
| 170 | const auto load_dir = Service::FileSystem::GetModificationLoadRoot(title_id); | 170 | const auto load_dir = Service::FileSystem::GetModificationLoadRoot(title_id); |
| 171 | if (type != ContentRecordType::Program || load_dir == nullptr || load_dir->GetSize() <= 0) { | 171 | if ((type != ContentRecordType::Program && type != ContentRecordType::Data) || |
| 172 | load_dir == nullptr || load_dir->GetSize() <= 0) { | ||
| 172 | return; | 173 | return; |
| 173 | } | 174 | } |
| 174 | 175 | ||
| @@ -218,7 +219,7 @@ VirtualFile PatchManager::PatchRomFS(VirtualFile romfs, u64 ivfc_offset, Content | |||
| 218 | title_id, static_cast<u8>(type)) | 219 | title_id, static_cast<u8>(type)) |
| 219 | .c_str(); | 220 | .c_str(); |
| 220 | 221 | ||
| 221 | if (type == ContentRecordType::Program) | 222 | if (type == ContentRecordType::Program || type == ContentRecordType::Data) |
| 222 | LOG_INFO(Loader, log_string); | 223 | LOG_INFO(Loader, log_string); |
| 223 | else | 224 | else |
| 224 | LOG_DEBUG(Loader, log_string); | 225 | LOG_DEBUG(Loader, log_string); |
diff --git a/src/core/file_sys/registered_cache.cpp b/src/core/file_sys/registered_cache.cpp index 1febb398e..29b100414 100644 --- a/src/core/file_sys/registered_cache.cpp +++ b/src/core/file_sys/registered_cache.cpp | |||
| @@ -2,6 +2,7 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <algorithm> | ||
| 5 | #include <regex> | 6 | #include <regex> |
| 6 | #include <mbedtls/sha256.h> | 7 | #include <mbedtls/sha256.h> |
| 7 | #include "common/assert.h" | 8 | #include "common/assert.h" |
| @@ -30,6 +31,14 @@ bool operator<(const RegisteredCacheEntry& lhs, const RegisteredCacheEntry& rhs) | |||
| 30 | return (lhs.title_id < rhs.title_id) || (lhs.title_id == rhs.title_id && lhs.type < rhs.type); | 31 | return (lhs.title_id < rhs.title_id) || (lhs.title_id == rhs.title_id && lhs.type < rhs.type); |
| 31 | } | 32 | } |
| 32 | 33 | ||
| 34 | bool operator==(const RegisteredCacheEntry& lhs, const RegisteredCacheEntry& rhs) { | ||
| 35 | return std::tie(lhs.title_id, lhs.type) == std::tie(rhs.title_id, rhs.type); | ||
| 36 | } | ||
| 37 | |||
| 38 | bool operator!=(const RegisteredCacheEntry& lhs, const RegisteredCacheEntry& rhs) { | ||
| 39 | return !operator==(lhs, rhs); | ||
| 40 | } | ||
| 41 | |||
| 33 | static bool FollowsTwoDigitDirFormat(std::string_view name) { | 42 | static bool FollowsTwoDigitDirFormat(std::string_view name) { |
| 34 | static const std::regex two_digit_regex("000000[0-9A-F]{2}", std::regex_constants::ECMAScript | | 43 | static const std::regex two_digit_regex("000000[0-9A-F]{2}", std::regex_constants::ECMAScript | |
| 35 | std::regex_constants::icase); | 44 | std::regex_constants::icase); |
| @@ -593,6 +602,9 @@ std::vector<RegisteredCacheEntry> RegisteredCacheUnion::ListEntries() const { | |||
| 593 | }, | 602 | }, |
| 594 | [](const CNMT& c, const ContentRecord& r) { return true; }); | 603 | [](const CNMT& c, const ContentRecord& r) { return true; }); |
| 595 | } | 604 | } |
| 605 | |||
| 606 | std::sort(out.begin(), out.end()); | ||
| 607 | out.erase(std::unique(out.begin(), out.end()), out.end()); | ||
| 596 | return out; | 608 | return out; |
| 597 | } | 609 | } |
| 598 | 610 | ||
| @@ -616,6 +628,9 @@ std::vector<RegisteredCacheEntry> RegisteredCacheUnion::ListEntriesFilter( | |||
| 616 | return true; | 628 | return true; |
| 617 | }); | 629 | }); |
| 618 | } | 630 | } |
| 631 | |||
| 632 | std::sort(out.begin(), out.end()); | ||
| 633 | out.erase(std::unique(out.begin(), out.end()), out.end()); | ||
| 619 | return out; | 634 | return out; |
| 620 | } | 635 | } |
| 621 | } // namespace FileSys | 636 | } // namespace FileSys |
diff --git a/src/core/file_sys/registered_cache.h b/src/core/file_sys/registered_cache.h index 5ddacba47..5beceffb3 100644 --- a/src/core/file_sys/registered_cache.h +++ b/src/core/file_sys/registered_cache.h | |||
| @@ -50,6 +50,10 @@ constexpr u64 GetUpdateTitleID(u64 base_title_id) { | |||
| 50 | // boost flat_map requires operator< for O(log(n)) lookups. | 50 | // boost flat_map requires operator< for O(log(n)) lookups. |
| 51 | bool operator<(const RegisteredCacheEntry& lhs, const RegisteredCacheEntry& rhs); | 51 | bool operator<(const RegisteredCacheEntry& lhs, const RegisteredCacheEntry& rhs); |
| 52 | 52 | ||
| 53 | // std unique requires operator== to identify duplicates. | ||
| 54 | bool operator==(const RegisteredCacheEntry& lhs, const RegisteredCacheEntry& rhs); | ||
| 55 | bool operator!=(const RegisteredCacheEntry& lhs, const RegisteredCacheEntry& rhs); | ||
| 56 | |||
| 53 | /* | 57 | /* |
| 54 | * A class that catalogues NCAs in the registered directory structure. | 58 | * A class that catalogues NCAs in the registered directory structure. |
| 55 | * Nintendo's registered format follows this structure: | 59 | * Nintendo's registered format follows this structure: |
| @@ -60,8 +64,8 @@ bool operator<(const RegisteredCacheEntry& lhs, const RegisteredCacheEntry& rhs) | |||
| 60 | * | 00 | 64 | * | 00 |
| 61 | * | 01 <- Actual content split along 4GB boundaries. (optional) | 65 | * | 01 <- Actual content split along 4GB boundaries. (optional) |
| 62 | * | 66 | * |
| 63 | * (This impl also supports substituting the nca dir for an nca file, as that's more convenient when | 67 | * (This impl also supports substituting the nca dir for an nca file, as that's more convenient |
| 64 | * 4GB splitting can be ignored.) | 68 | * when 4GB splitting can be ignored.) |
| 65 | */ | 69 | */ |
| 66 | class RegisteredCache { | 70 | class RegisteredCache { |
| 67 | friend class RegisteredCacheUnion; | 71 | friend class RegisteredCacheUnion; |
diff --git a/src/core/file_sys/vfs.cpp b/src/core/file_sys/vfs.cpp index bfe50da73..3824c74e0 100644 --- a/src/core/file_sys/vfs.cpp +++ b/src/core/file_sys/vfs.cpp | |||
| @@ -472,10 +472,14 @@ bool VfsRawCopy(const VirtualFile& src, const VirtualFile& dest, std::size_t blo | |||
| 472 | std::vector<u8> temp(std::min(block_size, src->GetSize())); | 472 | std::vector<u8> temp(std::min(block_size, src->GetSize())); |
| 473 | for (std::size_t i = 0; i < src->GetSize(); i += block_size) { | 473 | for (std::size_t i = 0; i < src->GetSize(); i += block_size) { |
| 474 | const auto read = std::min(block_size, src->GetSize() - i); | 474 | const auto read = std::min(block_size, src->GetSize() - i); |
| 475 | const auto block = src->Read(temp.data(), read, i); | ||
| 476 | 475 | ||
| 477 | if (dest->Write(temp.data(), read, i) != read) | 476 | if (src->Read(temp.data(), read, i) != read) { |
| 478 | return false; | 477 | return false; |
| 478 | } | ||
| 479 | |||
| 480 | if (dest->Write(temp.data(), read, i) != read) { | ||
| 481 | return false; | ||
| 482 | } | ||
| 479 | } | 483 | } |
| 480 | 484 | ||
| 481 | return true; | 485 | return true; |
diff --git a/src/core/hle/ipc.h b/src/core/hle/ipc.h index 419f45896..ed84197b3 100644 --- a/src/core/hle/ipc.h +++ b/src/core/hle/ipc.h | |||
| @@ -14,11 +14,6 @@ namespace IPC { | |||
| 14 | /// Size of the command buffer area, in 32-bit words. | 14 | /// Size of the command buffer area, in 32-bit words. |
| 15 | constexpr std::size_t COMMAND_BUFFER_LENGTH = 0x100 / sizeof(u32); | 15 | constexpr std::size_t COMMAND_BUFFER_LENGTH = 0x100 / sizeof(u32); |
| 16 | 16 | ||
| 17 | // These errors are commonly returned by invalid IPC translations, so alias them here for | ||
| 18 | // convenience. | ||
| 19 | // TODO(yuriks): These will probably go away once translation is implemented inside the kernel. | ||
| 20 | constexpr auto ERR_INVALID_HANDLE = Kernel::ERR_INVALID_HANDLE_OS; | ||
| 21 | |||
| 22 | enum class ControlCommand : u32 { | 17 | enum class ControlCommand : u32 { |
| 23 | ConvertSessionToDomain = 0, | 18 | ConvertSessionToDomain = 0, |
| 24 | ConvertDomainToSession = 1, | 19 | ConvertDomainToSession = 1, |
diff --git a/src/core/hle/kernel/errors.h b/src/core/hle/kernel/errors.h index 885259618..ee698c8a7 100644 --- a/src/core/hle/kernel/errors.h +++ b/src/core/hle/kernel/errors.h | |||
| @@ -10,11 +10,6 @@ namespace Kernel { | |||
| 10 | 10 | ||
| 11 | namespace ErrCodes { | 11 | namespace ErrCodes { |
| 12 | enum { | 12 | enum { |
| 13 | // TODO(Subv): Remove these 3DS OS error codes. | ||
| 14 | SessionClosedByRemote = 26, | ||
| 15 | NoPendingSessions = 35, | ||
| 16 | InvalidBufferDescriptor = 48, | ||
| 17 | |||
| 18 | // Confirmed Switch OS error codes | 13 | // Confirmed Switch OS error codes |
| 19 | MaxConnectionsReached = 7, | 14 | MaxConnectionsReached = 7, |
| 20 | InvalidSize = 101, | 15 | InvalidSize = 101, |
| @@ -26,6 +21,7 @@ enum { | |||
| 26 | InvalidThreadPriority = 112, | 21 | InvalidThreadPriority = 112, |
| 27 | InvalidProcessorId = 113, | 22 | InvalidProcessorId = 113, |
| 28 | InvalidHandle = 114, | 23 | InvalidHandle = 114, |
| 24 | InvalidPointer = 115, | ||
| 29 | InvalidCombination = 116, | 25 | InvalidCombination = 116, |
| 30 | Timeout = 117, | 26 | Timeout = 117, |
| 31 | SynchronizationCanceled = 118, | 27 | SynchronizationCanceled = 118, |
| @@ -33,6 +29,7 @@ enum { | |||
| 33 | InvalidEnumValue = 120, | 29 | InvalidEnumValue = 120, |
| 34 | NoSuchEntry = 121, | 30 | NoSuchEntry = 121, |
| 35 | AlreadyRegistered = 122, | 31 | AlreadyRegistered = 122, |
| 32 | SessionClosed = 123, | ||
| 36 | InvalidState = 125, | 33 | InvalidState = 125, |
| 37 | ResourceLimitExceeded = 132, | 34 | ResourceLimitExceeded = 132, |
| 38 | }; | 35 | }; |
| @@ -41,18 +38,14 @@ enum { | |||
| 41 | // WARNING: The kernel is quite inconsistent in it's usage of errors code. Make sure to always | 38 | // WARNING: The kernel is quite inconsistent in it's usage of errors code. Make sure to always |
| 42 | // double check that the code matches before re-using the constant. | 39 | // double check that the code matches before re-using the constant. |
| 43 | 40 | ||
| 44 | // TODO(bunnei): Replace -1 with correct errors for Switch OS | ||
| 45 | constexpr ResultCode ERR_HANDLE_TABLE_FULL(ErrorModule::Kernel, ErrCodes::HandleTableFull); | 41 | constexpr ResultCode ERR_HANDLE_TABLE_FULL(ErrorModule::Kernel, ErrCodes::HandleTableFull); |
| 46 | constexpr ResultCode ERR_SESSION_CLOSED_BY_REMOTE(-1); | 42 | constexpr ResultCode ERR_SESSION_CLOSED_BY_REMOTE(ErrorModule::Kernel, ErrCodes::SessionClosed); |
| 47 | constexpr ResultCode ERR_PORT_NAME_TOO_LONG(ErrorModule::Kernel, ErrCodes::TooLarge); | 43 | constexpr ResultCode ERR_PORT_NAME_TOO_LONG(ErrorModule::Kernel, ErrCodes::TooLarge); |
| 48 | constexpr ResultCode ERR_MAX_CONNECTIONS_REACHED(ErrorModule::Kernel, | 44 | constexpr ResultCode ERR_MAX_CONNECTIONS_REACHED(ErrorModule::Kernel, |
| 49 | ErrCodes::MaxConnectionsReached); | 45 | ErrCodes::MaxConnectionsReached); |
| 50 | constexpr ResultCode ERR_INVALID_ENUM_VALUE(ErrorModule::Kernel, ErrCodes::InvalidEnumValue); | 46 | constexpr ResultCode ERR_INVALID_ENUM_VALUE(ErrorModule::Kernel, ErrCodes::InvalidEnumValue); |
| 51 | constexpr ResultCode ERR_INVALID_ENUM_VALUE_FND(-1); | ||
| 52 | constexpr ResultCode ERR_INVALID_COMBINATION(-1); | ||
| 53 | constexpr ResultCode ERR_INVALID_COMBINATION_KERNEL(ErrorModule::Kernel, | 47 | constexpr ResultCode ERR_INVALID_COMBINATION_KERNEL(ErrorModule::Kernel, |
| 54 | ErrCodes::InvalidCombination); | 48 | ErrCodes::InvalidCombination); |
| 55 | constexpr ResultCode ERR_OUT_OF_MEMORY(-1); | ||
| 56 | constexpr ResultCode ERR_INVALID_ADDRESS(ErrorModule::Kernel, ErrCodes::InvalidAddress); | 49 | constexpr ResultCode ERR_INVALID_ADDRESS(ErrorModule::Kernel, ErrCodes::InvalidAddress); |
| 57 | constexpr ResultCode ERR_INVALID_ADDRESS_STATE(ErrorModule::Kernel, ErrCodes::InvalidMemoryState); | 50 | constexpr ResultCode ERR_INVALID_ADDRESS_STATE(ErrorModule::Kernel, ErrCodes::InvalidMemoryState); |
| 58 | constexpr ResultCode ERR_INVALID_MEMORY_PERMISSIONS(ErrorModule::Kernel, | 51 | constexpr ResultCode ERR_INVALID_MEMORY_PERMISSIONS(ErrorModule::Kernel, |
| @@ -65,14 +58,8 @@ constexpr ResultCode ERR_ALREADY_REGISTERED(ErrorModule::Kernel, ErrCodes::Alrea | |||
| 65 | constexpr ResultCode ERR_INVALID_STATE(ErrorModule::Kernel, ErrCodes::InvalidState); | 58 | constexpr ResultCode ERR_INVALID_STATE(ErrorModule::Kernel, ErrCodes::InvalidState); |
| 66 | constexpr ResultCode ERR_INVALID_THREAD_PRIORITY(ErrorModule::Kernel, | 59 | constexpr ResultCode ERR_INVALID_THREAD_PRIORITY(ErrorModule::Kernel, |
| 67 | ErrCodes::InvalidThreadPriority); | 60 | ErrCodes::InvalidThreadPriority); |
| 68 | constexpr ResultCode ERR_INVALID_POINTER(-1); | 61 | constexpr ResultCode ERR_INVALID_POINTER(ErrorModule::Kernel, ErrCodes::InvalidPointer); |
| 69 | constexpr ResultCode ERR_INVALID_OBJECT_ADDR(-1); | ||
| 70 | constexpr ResultCode ERR_NOT_AUTHORIZED(-1); | ||
| 71 | /// Alternate code returned instead of ERR_INVALID_HANDLE in some code paths. | ||
| 72 | constexpr ResultCode ERR_INVALID_HANDLE_OS(-1); | ||
| 73 | constexpr ResultCode ERR_NOT_FOUND(ErrorModule::Kernel, ErrCodes::NoSuchEntry); | 62 | constexpr ResultCode ERR_NOT_FOUND(ErrorModule::Kernel, ErrCodes::NoSuchEntry); |
| 74 | constexpr ResultCode RESULT_TIMEOUT(ErrorModule::Kernel, ErrCodes::Timeout); | 63 | constexpr ResultCode RESULT_TIMEOUT(ErrorModule::Kernel, ErrCodes::Timeout); |
| 75 | /// Returned when Accept() is called on a port with no sessions to be accepted. | ||
| 76 | constexpr ResultCode ERR_NO_PENDING_SESSIONS(-1); | ||
| 77 | 64 | ||
| 78 | } // namespace Kernel | 65 | } // namespace Kernel |
diff --git a/src/core/hle/kernel/hle_ipc.cpp b/src/core/hle/kernel/hle_ipc.cpp index edad5f1b1..68d5376cb 100644 --- a/src/core/hle/kernel/hle_ipc.cpp +++ b/src/core/hle/kernel/hle_ipc.cpp | |||
| @@ -77,7 +77,8 @@ HLERequestContext::HLERequestContext(SharedPtr<Kernel::ServerSession> server_ses | |||
| 77 | 77 | ||
| 78 | HLERequestContext::~HLERequestContext() = default; | 78 | HLERequestContext::~HLERequestContext() = default; |
| 79 | 79 | ||
| 80 | void HLERequestContext::ParseCommandBuffer(u32_le* src_cmdbuf, bool incoming) { | 80 | void HLERequestContext::ParseCommandBuffer(const HandleTable& handle_table, u32_le* src_cmdbuf, |
| 81 | bool incoming) { | ||
| 81 | IPC::RequestParser rp(src_cmdbuf); | 82 | IPC::RequestParser rp(src_cmdbuf); |
| 82 | command_header = std::make_shared<IPC::CommandHeader>(rp.PopRaw<IPC::CommandHeader>()); | 83 | command_header = std::make_shared<IPC::CommandHeader>(rp.PopRaw<IPC::CommandHeader>()); |
| 83 | 84 | ||
| @@ -94,8 +95,6 @@ void HLERequestContext::ParseCommandBuffer(u32_le* src_cmdbuf, bool incoming) { | |||
| 94 | rp.Skip(2, false); | 95 | rp.Skip(2, false); |
| 95 | } | 96 | } |
| 96 | if (incoming) { | 97 | if (incoming) { |
| 97 | auto& handle_table = Core::System::GetInstance().Kernel().HandleTable(); | ||
| 98 | |||
| 99 | // Populate the object lists with the data in the IPC request. | 98 | // Populate the object lists with the data in the IPC request. |
| 100 | for (u32 handle = 0; handle < handle_descriptor_header->num_handles_to_copy; ++handle) { | 99 | for (u32 handle = 0; handle < handle_descriptor_header->num_handles_to_copy; ++handle) { |
| 101 | copy_objects.push_back(handle_table.GetGeneric(rp.Pop<Handle>())); | 100 | copy_objects.push_back(handle_table.GetGeneric(rp.Pop<Handle>())); |
| @@ -189,10 +188,9 @@ void HLERequestContext::ParseCommandBuffer(u32_le* src_cmdbuf, bool incoming) { | |||
| 189 | rp.Skip(1, false); // The command is actually an u64, but we don't use the high part. | 188 | rp.Skip(1, false); // The command is actually an u64, but we don't use the high part. |
| 190 | } | 189 | } |
| 191 | 190 | ||
| 192 | ResultCode HLERequestContext::PopulateFromIncomingCommandBuffer(u32_le* src_cmdbuf, | 191 | ResultCode HLERequestContext::PopulateFromIncomingCommandBuffer(const HandleTable& handle_table, |
| 193 | Process& src_process, | 192 | u32_le* src_cmdbuf) { |
| 194 | HandleTable& src_table) { | 193 | ParseCommandBuffer(handle_table, src_cmdbuf, true); |
| 195 | ParseCommandBuffer(src_cmdbuf, true); | ||
| 196 | if (command_header->type == IPC::CommandType::Close) { | 194 | if (command_header->type == IPC::CommandType::Close) { |
| 197 | // Close does not populate the rest of the IPC header | 195 | // Close does not populate the rest of the IPC header |
| 198 | return RESULT_SUCCESS; | 196 | return RESULT_SUCCESS; |
| @@ -207,14 +205,17 @@ ResultCode HLERequestContext::PopulateFromIncomingCommandBuffer(u32_le* src_cmdb | |||
| 207 | return RESULT_SUCCESS; | 205 | return RESULT_SUCCESS; |
| 208 | } | 206 | } |
| 209 | 207 | ||
| 210 | ResultCode HLERequestContext::WriteToOutgoingCommandBuffer(const Thread& thread) { | 208 | ResultCode HLERequestContext::WriteToOutgoingCommandBuffer(Thread& thread) { |
| 209 | auto& owner_process = *thread.GetOwnerProcess(); | ||
| 210 | auto& handle_table = owner_process.GetHandleTable(); | ||
| 211 | |||
| 211 | std::array<u32, IPC::COMMAND_BUFFER_LENGTH> dst_cmdbuf; | 212 | std::array<u32, IPC::COMMAND_BUFFER_LENGTH> dst_cmdbuf; |
| 212 | Memory::ReadBlock(*thread.GetOwnerProcess(), thread.GetTLSAddress(), dst_cmdbuf.data(), | 213 | Memory::ReadBlock(owner_process, thread.GetTLSAddress(), dst_cmdbuf.data(), |
| 213 | dst_cmdbuf.size() * sizeof(u32)); | 214 | dst_cmdbuf.size() * sizeof(u32)); |
| 214 | 215 | ||
| 215 | // The header was already built in the internal command buffer. Attempt to parse it to verify | 216 | // The header was already built in the internal command buffer. Attempt to parse it to verify |
| 216 | // the integrity and then copy it over to the target command buffer. | 217 | // the integrity and then copy it over to the target command buffer. |
| 217 | ParseCommandBuffer(cmd_buf.data(), false); | 218 | ParseCommandBuffer(handle_table, cmd_buf.data(), false); |
| 218 | 219 | ||
| 219 | // The data_size already includes the payload header, the padding and the domain header. | 220 | // The data_size already includes the payload header, the padding and the domain header. |
| 220 | std::size_t size = data_payload_offset + command_header->data_size - | 221 | std::size_t size = data_payload_offset + command_header->data_size - |
| @@ -236,8 +237,6 @@ ResultCode HLERequestContext::WriteToOutgoingCommandBuffer(const Thread& thread) | |||
| 236 | ASSERT(copy_objects.size() == handle_descriptor_header->num_handles_to_copy); | 237 | ASSERT(copy_objects.size() == handle_descriptor_header->num_handles_to_copy); |
| 237 | ASSERT(move_objects.size() == handle_descriptor_header->num_handles_to_move); | 238 | ASSERT(move_objects.size() == handle_descriptor_header->num_handles_to_move); |
| 238 | 239 | ||
| 239 | auto& handle_table = Core::System::GetInstance().Kernel().HandleTable(); | ||
| 240 | |||
| 241 | // We don't make a distinction between copy and move handles when translating since HLE | 240 | // We don't make a distinction between copy and move handles when translating since HLE |
| 242 | // services don't deal with handles directly. However, the guest applications might check | 241 | // services don't deal with handles directly. However, the guest applications might check |
| 243 | // for specific values in each of these descriptors. | 242 | // for specific values in each of these descriptors. |
| @@ -268,7 +267,7 @@ ResultCode HLERequestContext::WriteToOutgoingCommandBuffer(const Thread& thread) | |||
| 268 | } | 267 | } |
| 269 | 268 | ||
| 270 | // Copy the translated command buffer back into the thread's command buffer area. | 269 | // Copy the translated command buffer back into the thread's command buffer area. |
| 271 | Memory::WriteBlock(*thread.GetOwnerProcess(), thread.GetTLSAddress(), dst_cmdbuf.data(), | 270 | Memory::WriteBlock(owner_process, thread.GetTLSAddress(), dst_cmdbuf.data(), |
| 272 | dst_cmdbuf.size() * sizeof(u32)); | 271 | dst_cmdbuf.size() * sizeof(u32)); |
| 273 | 272 | ||
| 274 | return RESULT_SUCCESS; | 273 | return RESULT_SUCCESS; |
diff --git a/src/core/hle/kernel/hle_ipc.h b/src/core/hle/kernel/hle_ipc.h index 894479ee0..f01491daa 100644 --- a/src/core/hle/kernel/hle_ipc.h +++ b/src/core/hle/kernel/hle_ipc.h | |||
| @@ -24,10 +24,10 @@ class ServiceFrameworkBase; | |||
| 24 | namespace Kernel { | 24 | namespace Kernel { |
| 25 | 25 | ||
| 26 | class Domain; | 26 | class Domain; |
| 27 | class Event; | ||
| 27 | class HandleTable; | 28 | class HandleTable; |
| 28 | class HLERequestContext; | 29 | class HLERequestContext; |
| 29 | class Process; | 30 | class Process; |
| 30 | class Event; | ||
| 31 | 31 | ||
| 32 | /** | 32 | /** |
| 33 | * Interface implemented by HLE Session handlers. | 33 | * Interface implemented by HLE Session handlers. |
| @@ -126,13 +126,12 @@ public: | |||
| 126 | u64 timeout, WakeupCallback&& callback, | 126 | u64 timeout, WakeupCallback&& callback, |
| 127 | Kernel::SharedPtr<Kernel::Event> event = nullptr); | 127 | Kernel::SharedPtr<Kernel::Event> event = nullptr); |
| 128 | 128 | ||
| 129 | void ParseCommandBuffer(u32_le* src_cmdbuf, bool incoming); | ||
| 130 | |||
| 131 | /// Populates this context with data from the requesting process/thread. | 129 | /// Populates this context with data from the requesting process/thread. |
| 132 | ResultCode PopulateFromIncomingCommandBuffer(u32_le* src_cmdbuf, Process& src_process, | 130 | ResultCode PopulateFromIncomingCommandBuffer(const HandleTable& handle_table, |
| 133 | HandleTable& src_table); | 131 | u32_le* src_cmdbuf); |
| 132 | |||
| 134 | /// Writes data from this context back to the requesting process/thread. | 133 | /// Writes data from this context back to the requesting process/thread. |
| 135 | ResultCode WriteToOutgoingCommandBuffer(const Thread& thread); | 134 | ResultCode WriteToOutgoingCommandBuffer(Thread& thread); |
| 136 | 135 | ||
| 137 | u32_le GetCommand() const { | 136 | u32_le GetCommand() const { |
| 138 | return command; | 137 | return command; |
| @@ -255,6 +254,8 @@ public: | |||
| 255 | std::string Description() const; | 254 | std::string Description() const; |
| 256 | 255 | ||
| 257 | private: | 256 | private: |
| 257 | void ParseCommandBuffer(const HandleTable& handle_table, u32_le* src_cmdbuf, bool incoming); | ||
| 258 | |||
| 258 | std::array<u32, IPC::COMMAND_BUFFER_LENGTH> cmd_buf; | 259 | std::array<u32, IPC::COMMAND_BUFFER_LENGTH> cmd_buf; |
| 259 | SharedPtr<Kernel::ServerSession> server_session; | 260 | SharedPtr<Kernel::ServerSession> server_session; |
| 260 | // TODO(yuriks): Check common usage of this and optimize size accordingly | 261 | // TODO(yuriks): Check common usage of this and optimize size accordingly |
diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp index bd680adfe..4b6b32dd5 100644 --- a/src/core/hle/kernel/kernel.cpp +++ b/src/core/hle/kernel/kernel.cpp | |||
| @@ -118,7 +118,6 @@ struct KernelCore::Impl { | |||
| 118 | process_list.clear(); | 118 | process_list.clear(); |
| 119 | current_process = nullptr; | 119 | current_process = nullptr; |
| 120 | 120 | ||
| 121 | handle_table.Clear(); | ||
| 122 | resource_limits.fill(nullptr); | 121 | resource_limits.fill(nullptr); |
| 123 | 122 | ||
| 124 | thread_wakeup_callback_handle_table.Clear(); | 123 | thread_wakeup_callback_handle_table.Clear(); |
| @@ -209,7 +208,6 @@ struct KernelCore::Impl { | |||
| 209 | std::vector<SharedPtr<Process>> process_list; | 208 | std::vector<SharedPtr<Process>> process_list; |
| 210 | Process* current_process = nullptr; | 209 | Process* current_process = nullptr; |
| 211 | 210 | ||
| 212 | Kernel::HandleTable handle_table; | ||
| 213 | std::array<SharedPtr<ResourceLimit>, 4> resource_limits; | 211 | std::array<SharedPtr<ResourceLimit>, 4> resource_limits; |
| 214 | 212 | ||
| 215 | /// The event type of the generic timer callback event | 213 | /// The event type of the generic timer callback event |
| @@ -241,14 +239,6 @@ void KernelCore::Shutdown() { | |||
| 241 | impl->Shutdown(); | 239 | impl->Shutdown(); |
| 242 | } | 240 | } |
| 243 | 241 | ||
| 244 | Kernel::HandleTable& KernelCore::HandleTable() { | ||
| 245 | return impl->handle_table; | ||
| 246 | } | ||
| 247 | |||
| 248 | const Kernel::HandleTable& KernelCore::HandleTable() const { | ||
| 249 | return impl->handle_table; | ||
| 250 | } | ||
| 251 | |||
| 252 | SharedPtr<ResourceLimit> KernelCore::ResourceLimitForCategory( | 242 | SharedPtr<ResourceLimit> KernelCore::ResourceLimitForCategory( |
| 253 | ResourceLimitCategory category) const { | 243 | ResourceLimitCategory category) const { |
| 254 | return impl->resource_limits.at(static_cast<std::size_t>(category)); | 244 | return impl->resource_limits.at(static_cast<std::size_t>(category)); |
diff --git a/src/core/hle/kernel/kernel.h b/src/core/hle/kernel/kernel.h index 41554821f..7f822d524 100644 --- a/src/core/hle/kernel/kernel.h +++ b/src/core/hle/kernel/kernel.h | |||
| @@ -47,12 +47,6 @@ public: | |||
| 47 | /// Clears all resources in use by the kernel instance. | 47 | /// Clears all resources in use by the kernel instance. |
| 48 | void Shutdown(); | 48 | void Shutdown(); |
| 49 | 49 | ||
| 50 | /// Provides a reference to the handle table. | ||
| 51 | Kernel::HandleTable& HandleTable(); | ||
| 52 | |||
| 53 | /// Provides a const reference to the handle table. | ||
| 54 | const Kernel::HandleTable& HandleTable() const; | ||
| 55 | |||
| 56 | /// Retrieves a shared pointer to a ResourceLimit identified by the given category. | 50 | /// Retrieves a shared pointer to a ResourceLimit identified by the given category. |
| 57 | SharedPtr<ResourceLimit> ResourceLimitForCategory(ResourceLimitCategory category) const; | 51 | SharedPtr<ResourceLimit> ResourceLimitForCategory(ResourceLimitCategory category) const; |
| 58 | 52 | ||
diff --git a/src/core/hle/kernel/process.cpp b/src/core/hle/kernel/process.cpp index 073dd5a7d..420218d59 100644 --- a/src/core/hle/kernel/process.cpp +++ b/src/core/hle/kernel/process.cpp | |||
| @@ -232,6 +232,12 @@ void Process::LoadModule(CodeSet module_, VAddr base_addr) { | |||
| 232 | MapSegment(module_.CodeSegment(), VMAPermission::ReadExecute, MemoryState::CodeStatic); | 232 | MapSegment(module_.CodeSegment(), VMAPermission::ReadExecute, MemoryState::CodeStatic); |
| 233 | MapSegment(module_.RODataSegment(), VMAPermission::Read, MemoryState::CodeMutable); | 233 | MapSegment(module_.RODataSegment(), VMAPermission::Read, MemoryState::CodeMutable); |
| 234 | MapSegment(module_.DataSegment(), VMAPermission::ReadWrite, MemoryState::CodeMutable); | 234 | MapSegment(module_.DataSegment(), VMAPermission::ReadWrite, MemoryState::CodeMutable); |
| 235 | |||
| 236 | // Clear instruction cache in CPU JIT | ||
| 237 | Core::System::GetInstance().ArmInterface(0).ClearInstructionCache(); | ||
| 238 | Core::System::GetInstance().ArmInterface(1).ClearInstructionCache(); | ||
| 239 | Core::System::GetInstance().ArmInterface(2).ClearInstructionCache(); | ||
| 240 | Core::System::GetInstance().ArmInterface(3).ClearInstructionCache(); | ||
| 235 | } | 241 | } |
| 236 | 242 | ||
| 237 | ResultVal<VAddr> Process::HeapAllocate(VAddr target, u64 size, VMAPermission perms) { | 243 | ResultVal<VAddr> Process::HeapAllocate(VAddr target, u64 size, VMAPermission perms) { |
diff --git a/src/core/hle/kernel/process.h b/src/core/hle/kernel/process.h index f2816943a..148478488 100644 --- a/src/core/hle/kernel/process.h +++ b/src/core/hle/kernel/process.h | |||
| @@ -13,6 +13,7 @@ | |||
| 13 | #include <boost/container/static_vector.hpp> | 13 | #include <boost/container/static_vector.hpp> |
| 14 | #include "common/bit_field.h" | 14 | #include "common/bit_field.h" |
| 15 | #include "common/common_types.h" | 15 | #include "common/common_types.h" |
| 16 | #include "core/hle/kernel/handle_table.h" | ||
| 16 | #include "core/hle/kernel/object.h" | 17 | #include "core/hle/kernel/object.h" |
| 17 | #include "core/hle/kernel/thread.h" | 18 | #include "core/hle/kernel/thread.h" |
| 18 | #include "core/hle/kernel/vm_manager.h" | 19 | #include "core/hle/kernel/vm_manager.h" |
| @@ -142,6 +143,16 @@ public: | |||
| 142 | return vm_manager; | 143 | return vm_manager; |
| 143 | } | 144 | } |
| 144 | 145 | ||
| 146 | /// Gets a reference to the process' handle table. | ||
| 147 | HandleTable& GetHandleTable() { | ||
| 148 | return handle_table; | ||
| 149 | } | ||
| 150 | |||
| 151 | /// Gets a const reference to the process' handle table. | ||
| 152 | const HandleTable& GetHandleTable() const { | ||
| 153 | return handle_table; | ||
| 154 | } | ||
| 155 | |||
| 145 | /// Gets the current status of the process | 156 | /// Gets the current status of the process |
| 146 | ProcessStatus GetStatus() const { | 157 | ProcessStatus GetStatus() const { |
| 147 | return status; | 158 | return status; |
| @@ -294,6 +305,9 @@ private: | |||
| 294 | /// specified by metadata provided to the process during loading. | 305 | /// specified by metadata provided to the process during loading. |
| 295 | bool is_64bit_process = true; | 306 | bool is_64bit_process = true; |
| 296 | 307 | ||
| 308 | /// Per-process handle table for storing created object handles in. | ||
| 309 | HandleTable handle_table; | ||
| 310 | |||
| 297 | std::string name; | 311 | std::string name; |
| 298 | }; | 312 | }; |
| 299 | 313 | ||
diff --git a/src/core/hle/kernel/server_port.cpp b/src/core/hle/kernel/server_port.cpp index 3792e3e18..d6ceeb2da 100644 --- a/src/core/hle/kernel/server_port.cpp +++ b/src/core/hle/kernel/server_port.cpp | |||
| @@ -18,7 +18,7 @@ ServerPort::~ServerPort() = default; | |||
| 18 | 18 | ||
| 19 | ResultVal<SharedPtr<ServerSession>> ServerPort::Accept() { | 19 | ResultVal<SharedPtr<ServerSession>> ServerPort::Accept() { |
| 20 | if (pending_sessions.empty()) { | 20 | if (pending_sessions.empty()) { |
| 21 | return ERR_NO_PENDING_SESSIONS; | 21 | return ERR_NOT_FOUND; |
| 22 | } | 22 | } |
| 23 | 23 | ||
| 24 | auto session = std::move(pending_sessions.back()); | 24 | auto session = std::move(pending_sessions.back()); |
| @@ -28,7 +28,7 @@ ResultVal<SharedPtr<ServerSession>> ServerPort::Accept() { | |||
| 28 | 28 | ||
| 29 | bool ServerPort::ShouldWait(Thread* thread) const { | 29 | bool ServerPort::ShouldWait(Thread* thread) const { |
| 30 | // If there are no pending sessions, we wait until a new one is added. | 30 | // If there are no pending sessions, we wait until a new one is added. |
| 31 | return pending_sessions.size() == 0; | 31 | return pending_sessions.empty(); |
| 32 | } | 32 | } |
| 33 | 33 | ||
| 34 | void ServerPort::Acquire(Thread* thread) { | 34 | void ServerPort::Acquire(Thread* thread) { |
diff --git a/src/core/hle/kernel/server_session.cpp b/src/core/hle/kernel/server_session.cpp index 1ece691c7..5fc320403 100644 --- a/src/core/hle/kernel/server_session.cpp +++ b/src/core/hle/kernel/server_session.cpp | |||
| @@ -107,8 +107,7 @@ ResultCode ServerSession::HandleSyncRequest(SharedPtr<Thread> thread) { | |||
| 107 | // similar. | 107 | // similar. |
| 108 | Kernel::HLERequestContext context(this); | 108 | Kernel::HLERequestContext context(this); |
| 109 | u32* cmd_buf = (u32*)Memory::GetPointer(thread->GetTLSAddress()); | 109 | u32* cmd_buf = (u32*)Memory::GetPointer(thread->GetTLSAddress()); |
| 110 | context.PopulateFromIncomingCommandBuffer(cmd_buf, *Core::CurrentProcess(), | 110 | context.PopulateFromIncomingCommandBuffer(kernel.CurrentProcess()->GetHandleTable(), cmd_buf); |
| 111 | kernel.HandleTable()); | ||
| 112 | 111 | ||
| 113 | ResultCode result = RESULT_SUCCESS; | 112 | ResultCode result = RESULT_SUCCESS; |
| 114 | // If the session has been converted to a domain, handle the domain request | 113 | // If the session has been converted to a domain, handle the domain request |
diff --git a/src/core/hle/kernel/shared_memory.cpp b/src/core/hle/kernel/shared_memory.cpp index d061e6155..a016a86b6 100644 --- a/src/core/hle/kernel/shared_memory.cpp +++ b/src/core/hle/kernel/shared_memory.cpp | |||
| @@ -80,20 +80,19 @@ SharedPtr<SharedMemory> SharedMemory::CreateForApplet( | |||
| 80 | 80 | ||
| 81 | ResultCode SharedMemory::Map(Process* target_process, VAddr address, MemoryPermission permissions, | 81 | ResultCode SharedMemory::Map(Process* target_process, VAddr address, MemoryPermission permissions, |
| 82 | MemoryPermission other_permissions) { | 82 | MemoryPermission other_permissions) { |
| 83 | 83 | const MemoryPermission own_other_permissions = | |
| 84 | MemoryPermission own_other_permissions = | ||
| 85 | target_process == owner_process ? this->permissions : this->other_permissions; | 84 | target_process == owner_process ? this->permissions : this->other_permissions; |
| 86 | 85 | ||
| 87 | // Automatically allocated memory blocks can only be mapped with other_permissions = DontCare | 86 | // Automatically allocated memory blocks can only be mapped with other_permissions = DontCare |
| 88 | if (base_address == 0 && other_permissions != MemoryPermission::DontCare) { | 87 | if (base_address == 0 && other_permissions != MemoryPermission::DontCare) { |
| 89 | return ERR_INVALID_COMBINATION; | 88 | return ERR_INVALID_MEMORY_PERMISSIONS; |
| 90 | } | 89 | } |
| 91 | 90 | ||
| 92 | // Error out if the requested permissions don't match what the creator process allows. | 91 | // Error out if the requested permissions don't match what the creator process allows. |
| 93 | if (static_cast<u32>(permissions) & ~static_cast<u32>(own_other_permissions)) { | 92 | if (static_cast<u32>(permissions) & ~static_cast<u32>(own_other_permissions)) { |
| 94 | LOG_ERROR(Kernel, "cannot map id={}, address=0x{:X} name={}, permissions don't match", | 93 | LOG_ERROR(Kernel, "cannot map id={}, address=0x{:X} name={}, permissions don't match", |
| 95 | GetObjectId(), address, name); | 94 | GetObjectId(), address, name); |
| 96 | return ERR_INVALID_COMBINATION; | 95 | return ERR_INVALID_MEMORY_PERMISSIONS; |
| 97 | } | 96 | } |
| 98 | 97 | ||
| 99 | // Error out if the provided permissions are not compatible with what the creator process needs. | 98 | // Error out if the provided permissions are not compatible with what the creator process needs. |
diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp index d3c9d50b5..a5302d924 100644 --- a/src/core/hle/kernel/svc.cpp +++ b/src/core/hle/kernel/svc.cpp | |||
| @@ -189,14 +189,15 @@ static ResultCode ConnectToNamedPort(Handle* out_handle, VAddr port_name_address | |||
| 189 | CASCADE_RESULT(client_session, client_port->Connect()); | 189 | CASCADE_RESULT(client_session, client_port->Connect()); |
| 190 | 190 | ||
| 191 | // Return the client session | 191 | // Return the client session |
| 192 | CASCADE_RESULT(*out_handle, kernel.HandleTable().Create(client_session)); | 192 | auto& handle_table = Core::CurrentProcess()->GetHandleTable(); |
| 193 | CASCADE_RESULT(*out_handle, handle_table.Create(client_session)); | ||
| 193 | return RESULT_SUCCESS; | 194 | return RESULT_SUCCESS; |
| 194 | } | 195 | } |
| 195 | 196 | ||
| 196 | /// Makes a blocking IPC call to an OS service. | 197 | /// Makes a blocking IPC call to an OS service. |
| 197 | static ResultCode SendSyncRequest(Handle handle) { | 198 | static ResultCode SendSyncRequest(Handle handle) { |
| 198 | auto& kernel = Core::System::GetInstance().Kernel(); | 199 | const auto& handle_table = Core::CurrentProcess()->GetHandleTable(); |
| 199 | SharedPtr<ClientSession> session = kernel.HandleTable().Get<ClientSession>(handle); | 200 | SharedPtr<ClientSession> session = handle_table.Get<ClientSession>(handle); |
| 200 | if (!session) { | 201 | if (!session) { |
| 201 | LOG_ERROR(Kernel_SVC, "called with invalid handle=0x{:08X}", handle); | 202 | LOG_ERROR(Kernel_SVC, "called with invalid handle=0x{:08X}", handle); |
| 202 | return ERR_INVALID_HANDLE; | 203 | return ERR_INVALID_HANDLE; |
| @@ -215,8 +216,8 @@ static ResultCode SendSyncRequest(Handle handle) { | |||
| 215 | static ResultCode GetThreadId(u32* thread_id, Handle thread_handle) { | 216 | static ResultCode GetThreadId(u32* thread_id, Handle thread_handle) { |
| 216 | LOG_TRACE(Kernel_SVC, "called thread=0x{:08X}", thread_handle); | 217 | LOG_TRACE(Kernel_SVC, "called thread=0x{:08X}", thread_handle); |
| 217 | 218 | ||
| 218 | auto& kernel = Core::System::GetInstance().Kernel(); | 219 | const auto& handle_table = Core::CurrentProcess()->GetHandleTable(); |
| 219 | const SharedPtr<Thread> thread = kernel.HandleTable().Get<Thread>(thread_handle); | 220 | const SharedPtr<Thread> thread = handle_table.Get<Thread>(thread_handle); |
| 220 | if (!thread) { | 221 | if (!thread) { |
| 221 | return ERR_INVALID_HANDLE; | 222 | return ERR_INVALID_HANDLE; |
| 222 | } | 223 | } |
| @@ -229,8 +230,8 @@ static ResultCode GetThreadId(u32* thread_id, Handle thread_handle) { | |||
| 229 | static ResultCode GetProcessId(u32* process_id, Handle process_handle) { | 230 | static ResultCode GetProcessId(u32* process_id, Handle process_handle) { |
| 230 | LOG_TRACE(Kernel_SVC, "called process=0x{:08X}", process_handle); | 231 | LOG_TRACE(Kernel_SVC, "called process=0x{:08X}", process_handle); |
| 231 | 232 | ||
| 232 | auto& kernel = Core::System::GetInstance().Kernel(); | 233 | const auto& handle_table = Core::CurrentProcess()->GetHandleTable(); |
| 233 | const SharedPtr<Process> process = kernel.HandleTable().Get<Process>(process_handle); | 234 | const SharedPtr<Process> process = handle_table.Get<Process>(process_handle); |
| 234 | if (!process) { | 235 | if (!process) { |
| 235 | return ERR_INVALID_HANDLE; | 236 | return ERR_INVALID_HANDLE; |
| 236 | } | 237 | } |
| @@ -273,11 +274,11 @@ static ResultCode WaitSynchronization(Handle* index, VAddr handles_address, u64 | |||
| 273 | 274 | ||
| 274 | using ObjectPtr = Thread::ThreadWaitObjects::value_type; | 275 | using ObjectPtr = Thread::ThreadWaitObjects::value_type; |
| 275 | Thread::ThreadWaitObjects objects(handle_count); | 276 | Thread::ThreadWaitObjects objects(handle_count); |
| 276 | auto& kernel = Core::System::GetInstance().Kernel(); | 277 | const auto& handle_table = Core::CurrentProcess()->GetHandleTable(); |
| 277 | 278 | ||
| 278 | for (u64 i = 0; i < handle_count; ++i) { | 279 | for (u64 i = 0; i < handle_count; ++i) { |
| 279 | const Handle handle = Memory::Read32(handles_address + i * sizeof(Handle)); | 280 | const Handle handle = Memory::Read32(handles_address + i * sizeof(Handle)); |
| 280 | const auto object = kernel.HandleTable().Get<WaitObject>(handle); | 281 | const auto object = handle_table.Get<WaitObject>(handle); |
| 281 | 282 | ||
| 282 | if (object == nullptr) { | 283 | if (object == nullptr) { |
| 283 | return ERR_INVALID_HANDLE; | 284 | return ERR_INVALID_HANDLE; |
| @@ -325,8 +326,8 @@ static ResultCode WaitSynchronization(Handle* index, VAddr handles_address, u64 | |||
| 325 | static ResultCode CancelSynchronization(Handle thread_handle) { | 326 | static ResultCode CancelSynchronization(Handle thread_handle) { |
| 326 | LOG_TRACE(Kernel_SVC, "called thread=0x{:X}", thread_handle); | 327 | LOG_TRACE(Kernel_SVC, "called thread=0x{:X}", thread_handle); |
| 327 | 328 | ||
| 328 | auto& kernel = Core::System::GetInstance().Kernel(); | 329 | const auto& handle_table = Core::CurrentProcess()->GetHandleTable(); |
| 329 | const SharedPtr<Thread> thread = kernel.HandleTable().Get<Thread>(thread_handle); | 330 | const SharedPtr<Thread> thread = handle_table.Get<Thread>(thread_handle); |
| 330 | if (!thread) { | 331 | if (!thread) { |
| 331 | return ERR_INVALID_HANDLE; | 332 | return ERR_INVALID_HANDLE; |
| 332 | } | 333 | } |
| @@ -354,7 +355,7 @@ static ResultCode ArbitrateLock(Handle holding_thread_handle, VAddr mutex_addr, | |||
| 354 | return ERR_INVALID_ADDRESS; | 355 | return ERR_INVALID_ADDRESS; |
| 355 | } | 356 | } |
| 356 | 357 | ||
| 357 | auto& handle_table = Core::System::GetInstance().Kernel().HandleTable(); | 358 | auto& handle_table = Core::CurrentProcess()->GetHandleTable(); |
| 358 | return Mutex::TryAcquire(handle_table, mutex_addr, holding_thread_handle, | 359 | return Mutex::TryAcquire(handle_table, mutex_addr, holding_thread_handle, |
| 359 | requesting_thread_handle); | 360 | requesting_thread_handle); |
| 360 | } | 361 | } |
| @@ -374,9 +375,19 @@ static ResultCode ArbitrateUnlock(VAddr mutex_addr) { | |||
| 374 | return Mutex::Release(mutex_addr); | 375 | return Mutex::Release(mutex_addr); |
| 375 | } | 376 | } |
| 376 | 377 | ||
| 378 | enum class BreakType : u32 { | ||
| 379 | Panic = 0, | ||
| 380 | AssertionFailed = 1, | ||
| 381 | PreNROLoad = 3, | ||
| 382 | PostNROLoad = 4, | ||
| 383 | PreNROUnload = 5, | ||
| 384 | PostNROUnload = 6, | ||
| 385 | }; | ||
| 386 | |||
| 377 | struct BreakReason { | 387 | struct BreakReason { |
| 378 | union { | 388 | union { |
| 379 | u32 raw; | 389 | u32 raw; |
| 390 | BitField<0, 30, BreakType> break_type; | ||
| 380 | BitField<31, 1, u32> signal_debugger; | 391 | BitField<31, 1, u32> signal_debugger; |
| 381 | }; | 392 | }; |
| 382 | }; | 393 | }; |
| @@ -384,12 +395,48 @@ struct BreakReason { | |||
| 384 | /// Break program execution | 395 | /// Break program execution |
| 385 | static void Break(u32 reason, u64 info1, u64 info2) { | 396 | static void Break(u32 reason, u64 info1, u64 info2) { |
| 386 | BreakReason break_reason{reason}; | 397 | BreakReason break_reason{reason}; |
| 387 | if (break_reason.signal_debugger) { | 398 | |
| 388 | LOG_ERROR( | 399 | switch (break_reason.break_type) { |
| 400 | case BreakType::Panic: | ||
| 401 | LOG_CRITICAL(Debug_Emulated, "Signalling debugger, PANIC! info1=0x{:016X}, info2=0x{:016X}", | ||
| 402 | info1, info2); | ||
| 403 | break; | ||
| 404 | case BreakType::AssertionFailed: | ||
| 405 | LOG_CRITICAL(Debug_Emulated, | ||
| 406 | "Signalling debugger, Assertion failed! info1=0x{:016X}, info2=0x{:016X}", | ||
| 407 | info1, info2); | ||
| 408 | break; | ||
| 409 | case BreakType::PreNROLoad: | ||
| 410 | LOG_WARNING( | ||
| 389 | Debug_Emulated, | 411 | Debug_Emulated, |
| 390 | "Emulated program broke execution! reason=0x{:016X}, info1=0x{:016X}, info2=0x{:016X}", | 412 | "Signalling debugger, Attempting to load an NRO at 0x{:016X} with size 0x{:016X}", |
| 391 | reason, info1, info2); | 413 | info1, info2); |
| 392 | } else { | 414 | break; |
| 415 | case BreakType::PostNROLoad: | ||
| 416 | LOG_WARNING(Debug_Emulated, | ||
| 417 | "Signalling debugger, Loaded an NRO at 0x{:016X} with size 0x{:016X}", info1, | ||
| 418 | info2); | ||
| 419 | break; | ||
| 420 | case BreakType::PreNROUnload: | ||
| 421 | LOG_WARNING( | ||
| 422 | Debug_Emulated, | ||
| 423 | "Signalling debugger, Attempting to unload an NRO at 0x{:016X} with size 0x{:016X}", | ||
| 424 | info1, info2); | ||
| 425 | break; | ||
| 426 | case BreakType::PostNROUnload: | ||
| 427 | LOG_WARNING(Debug_Emulated, | ||
| 428 | "Signalling debugger, Unloaded an NRO at 0x{:016X} with size 0x{:016X}", info1, | ||
| 429 | info2); | ||
| 430 | break; | ||
| 431 | default: | ||
| 432 | LOG_WARNING( | ||
| 433 | Debug_Emulated, | ||
| 434 | "Signalling debugger, Unknown break reason {}, info1=0x{:016X}, info2=0x{:016X}", | ||
| 435 | static_cast<u32>(break_reason.break_type.Value()), info1, info2); | ||
| 436 | break; | ||
| 437 | } | ||
| 438 | |||
| 439 | if (!break_reason.signal_debugger) { | ||
| 393 | LOG_CRITICAL( | 440 | LOG_CRITICAL( |
| 394 | Debug_Emulated, | 441 | Debug_Emulated, |
| 395 | "Emulated program broke execution! reason=0x{:016X}, info1=0x{:016X}, info2=0x{:016X}", | 442 | "Emulated program broke execution! reason=0x{:016X}, info1=0x{:016X}, info2=0x{:016X}", |
| @@ -499,13 +546,12 @@ static ResultCode SetThreadActivity(Handle handle, u32 unknown) { | |||
| 499 | static ResultCode GetThreadContext(VAddr thread_context, Handle handle) { | 546 | static ResultCode GetThreadContext(VAddr thread_context, Handle handle) { |
| 500 | LOG_DEBUG(Kernel_SVC, "called, context=0x{:08X}, thread=0x{:X}", thread_context, handle); | 547 | LOG_DEBUG(Kernel_SVC, "called, context=0x{:08X}, thread=0x{:X}", thread_context, handle); |
| 501 | 548 | ||
| 502 | auto& kernel = Core::System::GetInstance().Kernel(); | 549 | const auto* current_process = Core::CurrentProcess(); |
| 503 | const SharedPtr<Thread> thread = kernel.HandleTable().Get<Thread>(handle); | 550 | const SharedPtr<Thread> thread = current_process->GetHandleTable().Get<Thread>(handle); |
| 504 | if (!thread) { | 551 | if (!thread) { |
| 505 | return ERR_INVALID_HANDLE; | 552 | return ERR_INVALID_HANDLE; |
| 506 | } | 553 | } |
| 507 | 554 | ||
| 508 | const auto* current_process = Core::CurrentProcess(); | ||
| 509 | if (thread->GetOwnerProcess() != current_process) { | 555 | if (thread->GetOwnerProcess() != current_process) { |
| 510 | return ERR_INVALID_HANDLE; | 556 | return ERR_INVALID_HANDLE; |
| 511 | } | 557 | } |
| @@ -531,10 +577,11 @@ static ResultCode GetThreadContext(VAddr thread_context, Handle handle) { | |||
| 531 | 577 | ||
| 532 | /// Gets the priority for the specified thread | 578 | /// Gets the priority for the specified thread |
| 533 | static ResultCode GetThreadPriority(u32* priority, Handle handle) { | 579 | static ResultCode GetThreadPriority(u32* priority, Handle handle) { |
| 534 | auto& kernel = Core::System::GetInstance().Kernel(); | 580 | const auto& handle_table = Core::CurrentProcess()->GetHandleTable(); |
| 535 | const SharedPtr<Thread> thread = kernel.HandleTable().Get<Thread>(handle); | 581 | const SharedPtr<Thread> thread = handle_table.Get<Thread>(handle); |
| 536 | if (!thread) | 582 | if (!thread) { |
| 537 | return ERR_INVALID_HANDLE; | 583 | return ERR_INVALID_HANDLE; |
| 584 | } | ||
| 538 | 585 | ||
| 539 | *priority = thread->GetPriority(); | 586 | *priority = thread->GetPriority(); |
| 540 | return RESULT_SUCCESS; | 587 | return RESULT_SUCCESS; |
| @@ -546,16 +593,18 @@ static ResultCode SetThreadPriority(Handle handle, u32 priority) { | |||
| 546 | return ERR_INVALID_THREAD_PRIORITY; | 593 | return ERR_INVALID_THREAD_PRIORITY; |
| 547 | } | 594 | } |
| 548 | 595 | ||
| 549 | auto& kernel = Core::System::GetInstance().Kernel(); | 596 | const auto* const current_process = Core::CurrentProcess(); |
| 550 | SharedPtr<Thread> thread = kernel.HandleTable().Get<Thread>(handle); | ||
| 551 | if (!thread) | ||
| 552 | return ERR_INVALID_HANDLE; | ||
| 553 | 597 | ||
| 554 | // Note: The kernel uses the current process's resource limit instead of | 598 | // Note: The kernel uses the current process's resource limit instead of |
| 555 | // the one from the thread owner's resource limit. | 599 | // the one from the thread owner's resource limit. |
| 556 | const ResourceLimit& resource_limit = Core::CurrentProcess()->GetResourceLimit(); | 600 | const ResourceLimit& resource_limit = current_process->GetResourceLimit(); |
| 557 | if (resource_limit.GetMaxResourceValue(ResourceType::Priority) > priority) { | 601 | if (resource_limit.GetMaxResourceValue(ResourceType::Priority) > priority) { |
| 558 | return ERR_NOT_AUTHORIZED; | 602 | return ERR_INVALID_THREAD_PRIORITY; |
| 603 | } | ||
| 604 | |||
| 605 | SharedPtr<Thread> thread = current_process->GetHandleTable().Get<Thread>(handle); | ||
| 606 | if (!thread) { | ||
| 607 | return ERR_INVALID_HANDLE; | ||
| 559 | } | 608 | } |
| 560 | 609 | ||
| 561 | thread->SetPriority(priority); | 610 | thread->SetPriority(priority); |
| @@ -584,6 +633,10 @@ static ResultCode MapSharedMemory(Handle shared_memory_handle, VAddr addr, u64 s | |||
| 584 | return ERR_INVALID_SIZE; | 633 | return ERR_INVALID_SIZE; |
| 585 | } | 634 | } |
| 586 | 635 | ||
| 636 | if (!IsValidAddressRange(addr, size)) { | ||
| 637 | return ERR_INVALID_ADDRESS_STATE; | ||
| 638 | } | ||
| 639 | |||
| 587 | const auto permissions_type = static_cast<MemoryPermission>(permissions); | 640 | const auto permissions_type = static_cast<MemoryPermission>(permissions); |
| 588 | if (permissions_type != MemoryPermission::Read && | 641 | if (permissions_type != MemoryPermission::Read && |
| 589 | permissions_type != MemoryPermission::ReadWrite) { | 642 | permissions_type != MemoryPermission::ReadWrite) { |
| @@ -591,14 +644,18 @@ static ResultCode MapSharedMemory(Handle shared_memory_handle, VAddr addr, u64 s | |||
| 591 | return ERR_INVALID_MEMORY_PERMISSIONS; | 644 | return ERR_INVALID_MEMORY_PERMISSIONS; |
| 592 | } | 645 | } |
| 593 | 646 | ||
| 594 | auto& kernel = Core::System::GetInstance().Kernel(); | 647 | auto* const current_process = Core::CurrentProcess(); |
| 595 | auto shared_memory = kernel.HandleTable().Get<SharedMemory>(shared_memory_handle); | 648 | auto shared_memory = current_process->GetHandleTable().Get<SharedMemory>(shared_memory_handle); |
| 596 | if (!shared_memory) { | 649 | if (!shared_memory) { |
| 597 | return ERR_INVALID_HANDLE; | 650 | return ERR_INVALID_HANDLE; |
| 598 | } | 651 | } |
| 599 | 652 | ||
| 600 | return shared_memory->Map(Core::CurrentProcess(), addr, permissions_type, | 653 | const auto& vm_manager = current_process->VMManager(); |
| 601 | MemoryPermission::DontCare); | 654 | if (!vm_manager.IsWithinASLRRegion(addr, size)) { |
| 655 | return ERR_INVALID_MEMORY_RANGE; | ||
| 656 | } | ||
| 657 | |||
| 658 | return shared_memory->Map(current_process, addr, permissions_type, MemoryPermission::DontCare); | ||
| 602 | } | 659 | } |
| 603 | 660 | ||
| 604 | static ResultCode UnmapSharedMemory(Handle shared_memory_handle, VAddr addr, u64 size) { | 661 | static ResultCode UnmapSharedMemory(Handle shared_memory_handle, VAddr addr, u64 size) { |
| @@ -613,24 +670,35 @@ static ResultCode UnmapSharedMemory(Handle shared_memory_handle, VAddr addr, u64 | |||
| 613 | return ERR_INVALID_SIZE; | 670 | return ERR_INVALID_SIZE; |
| 614 | } | 671 | } |
| 615 | 672 | ||
| 616 | auto& kernel = Core::System::GetInstance().Kernel(); | 673 | if (!IsValidAddressRange(addr, size)) { |
| 617 | auto shared_memory = kernel.HandleTable().Get<SharedMemory>(shared_memory_handle); | 674 | return ERR_INVALID_ADDRESS_STATE; |
| 675 | } | ||
| 676 | |||
| 677 | auto* const current_process = Core::CurrentProcess(); | ||
| 678 | auto shared_memory = current_process->GetHandleTable().Get<SharedMemory>(shared_memory_handle); | ||
| 679 | if (!shared_memory) { | ||
| 680 | return ERR_INVALID_HANDLE; | ||
| 681 | } | ||
| 682 | |||
| 683 | const auto& vm_manager = current_process->VMManager(); | ||
| 684 | if (!vm_manager.IsWithinASLRRegion(addr, size)) { | ||
| 685 | return ERR_INVALID_MEMORY_RANGE; | ||
| 686 | } | ||
| 618 | 687 | ||
| 619 | return shared_memory->Unmap(Core::CurrentProcess(), addr); | 688 | return shared_memory->Unmap(current_process, addr); |
| 620 | } | 689 | } |
| 621 | 690 | ||
| 622 | /// Query process memory | 691 | /// Query process memory |
| 623 | static ResultCode QueryProcessMemory(MemoryInfo* memory_info, PageInfo* /*page_info*/, | 692 | static ResultCode QueryProcessMemory(MemoryInfo* memory_info, PageInfo* /*page_info*/, |
| 624 | Handle process_handle, u64 addr) { | 693 | Handle process_handle, u64 addr) { |
| 625 | 694 | const auto& handle_table = Core::CurrentProcess()->GetHandleTable(); | |
| 626 | auto& kernel = Core::System::GetInstance().Kernel(); | 695 | SharedPtr<Process> process = handle_table.Get<Process>(process_handle); |
| 627 | SharedPtr<Process> process = kernel.HandleTable().Get<Process>(process_handle); | ||
| 628 | if (!process) { | 696 | if (!process) { |
| 629 | return ERR_INVALID_HANDLE; | 697 | return ERR_INVALID_HANDLE; |
| 630 | } | 698 | } |
| 631 | auto vma = process->VMManager().FindVMA(addr); | 699 | auto vma = process->VMManager().FindVMA(addr); |
| 632 | memory_info->attributes = 0; | 700 | memory_info->attributes = 0; |
| 633 | if (vma == Core::CurrentProcess()->VMManager().vma_map.end()) { | 701 | if (vma == process->VMManager().vma_map.end()) { |
| 634 | memory_info->base_address = 0; | 702 | memory_info->base_address = 0; |
| 635 | memory_info->permission = static_cast<u32>(VMAPermission::None); | 703 | memory_info->permission = static_cast<u32>(VMAPermission::None); |
| 636 | memory_info->size = 0; | 704 | memory_info->size = 0; |
| @@ -671,20 +739,19 @@ static void ExitProcess() { | |||
| 671 | /// Creates a new thread | 739 | /// Creates a new thread |
| 672 | static ResultCode CreateThread(Handle* out_handle, VAddr entry_point, u64 arg, VAddr stack_top, | 740 | static ResultCode CreateThread(Handle* out_handle, VAddr entry_point, u64 arg, VAddr stack_top, |
| 673 | u32 priority, s32 processor_id) { | 741 | u32 priority, s32 processor_id) { |
| 674 | std::string name = fmt::format("thread-{:X}", entry_point); | ||
| 675 | |||
| 676 | if (priority > THREADPRIO_LOWEST) { | 742 | if (priority > THREADPRIO_LOWEST) { |
| 677 | return ERR_INVALID_THREAD_PRIORITY; | 743 | return ERR_INVALID_THREAD_PRIORITY; |
| 678 | } | 744 | } |
| 679 | 745 | ||
| 680 | const ResourceLimit& resource_limit = Core::CurrentProcess()->GetResourceLimit(); | 746 | auto* const current_process = Core::CurrentProcess(); |
| 747 | const ResourceLimit& resource_limit = current_process->GetResourceLimit(); | ||
| 681 | if (resource_limit.GetMaxResourceValue(ResourceType::Priority) > priority) { | 748 | if (resource_limit.GetMaxResourceValue(ResourceType::Priority) > priority) { |
| 682 | return ERR_NOT_AUTHORIZED; | 749 | return ERR_INVALID_THREAD_PRIORITY; |
| 683 | } | 750 | } |
| 684 | 751 | ||
| 685 | if (processor_id == THREADPROCESSORID_DEFAULT) { | 752 | if (processor_id == THREADPROCESSORID_DEFAULT) { |
| 686 | // Set the target CPU to the one specified in the process' exheader. | 753 | // Set the target CPU to the one specified in the process' exheader. |
| 687 | processor_id = Core::CurrentProcess()->GetDefaultProcessorID(); | 754 | processor_id = current_process->GetDefaultProcessorID(); |
| 688 | ASSERT(processor_id != THREADPROCESSORID_DEFAULT); | 755 | ASSERT(processor_id != THREADPROCESSORID_DEFAULT); |
| 689 | } | 756 | } |
| 690 | 757 | ||
| @@ -699,11 +766,13 @@ static ResultCode CreateThread(Handle* out_handle, VAddr entry_point, u64 arg, V | |||
| 699 | return ERR_INVALID_PROCESSOR_ID; | 766 | return ERR_INVALID_PROCESSOR_ID; |
| 700 | } | 767 | } |
| 701 | 768 | ||
| 769 | const std::string name = fmt::format("thread-{:X}", entry_point); | ||
| 702 | auto& kernel = Core::System::GetInstance().Kernel(); | 770 | auto& kernel = Core::System::GetInstance().Kernel(); |
| 703 | CASCADE_RESULT(SharedPtr<Thread> thread, | 771 | CASCADE_RESULT(SharedPtr<Thread> thread, |
| 704 | Thread::Create(kernel, name, entry_point, priority, arg, processor_id, stack_top, | 772 | Thread::Create(kernel, name, entry_point, priority, arg, processor_id, stack_top, |
| 705 | *Core::CurrentProcess())); | 773 | *current_process)); |
| 706 | const auto new_guest_handle = kernel.HandleTable().Create(thread); | 774 | |
| 775 | const auto new_guest_handle = current_process->GetHandleTable().Create(thread); | ||
| 707 | if (new_guest_handle.Failed()) { | 776 | if (new_guest_handle.Failed()) { |
| 708 | return new_guest_handle.Code(); | 777 | return new_guest_handle.Code(); |
| 709 | } | 778 | } |
| @@ -724,8 +793,8 @@ static ResultCode CreateThread(Handle* out_handle, VAddr entry_point, u64 arg, V | |||
| 724 | static ResultCode StartThread(Handle thread_handle) { | 793 | static ResultCode StartThread(Handle thread_handle) { |
| 725 | LOG_TRACE(Kernel_SVC, "called thread=0x{:08X}", thread_handle); | 794 | LOG_TRACE(Kernel_SVC, "called thread=0x{:08X}", thread_handle); |
| 726 | 795 | ||
| 727 | auto& kernel = Core::System::GetInstance().Kernel(); | 796 | const auto& handle_table = Core::CurrentProcess()->GetHandleTable(); |
| 728 | const SharedPtr<Thread> thread = kernel.HandleTable().Get<Thread>(thread_handle); | 797 | const SharedPtr<Thread> thread = handle_table.Get<Thread>(thread_handle); |
| 729 | if (!thread) { | 798 | if (!thread) { |
| 730 | return ERR_INVALID_HANDLE; | 799 | return ERR_INVALID_HANDLE; |
| 731 | } | 800 | } |
| @@ -772,8 +841,8 @@ static ResultCode WaitProcessWideKeyAtomic(VAddr mutex_addr, VAddr condition_var | |||
| 772 | "called mutex_addr={:X}, condition_variable_addr={:X}, thread_handle=0x{:08X}, timeout={}", | 841 | "called mutex_addr={:X}, condition_variable_addr={:X}, thread_handle=0x{:08X}, timeout={}", |
| 773 | mutex_addr, condition_variable_addr, thread_handle, nano_seconds); | 842 | mutex_addr, condition_variable_addr, thread_handle, nano_seconds); |
| 774 | 843 | ||
| 775 | auto& kernel = Core::System::GetInstance().Kernel(); | 844 | const auto& handle_table = Core::CurrentProcess()->GetHandleTable(); |
| 776 | SharedPtr<Thread> thread = kernel.HandleTable().Get<Thread>(thread_handle); | 845 | SharedPtr<Thread> thread = handle_table.Get<Thread>(thread_handle); |
| 777 | ASSERT(thread); | 846 | ASSERT(thread); |
| 778 | 847 | ||
| 779 | CASCADE_CODE(Mutex::Release(mutex_addr)); | 848 | CASCADE_CODE(Mutex::Release(mutex_addr)); |
| @@ -884,9 +953,9 @@ static ResultCode SignalProcessWideKey(VAddr condition_variable_addr, s32 target | |||
| 884 | mutex_val | Mutex::MutexHasWaitersFlag)); | 953 | mutex_val | Mutex::MutexHasWaitersFlag)); |
| 885 | 954 | ||
| 886 | // The mutex is already owned by some other thread, make this thread wait on it. | 955 | // The mutex is already owned by some other thread, make this thread wait on it. |
| 887 | auto& kernel = Core::System::GetInstance().Kernel(); | 956 | const Handle owner_handle = static_cast<Handle>(mutex_val & Mutex::MutexOwnerMask); |
| 888 | Handle owner_handle = static_cast<Handle>(mutex_val & Mutex::MutexOwnerMask); | 957 | const auto& handle_table = Core::CurrentProcess()->GetHandleTable(); |
| 889 | auto owner = kernel.HandleTable().Get<Thread>(owner_handle); | 958 | auto owner = handle_table.Get<Thread>(owner_handle); |
| 890 | ASSERT(owner); | 959 | ASSERT(owner); |
| 891 | ASSERT(thread->GetStatus() == ThreadStatus::WaitMutex); | 960 | ASSERT(thread->GetStatus() == ThreadStatus::WaitMutex); |
| 892 | thread->InvalidateWakeupCallback(); | 961 | thread->InvalidateWakeupCallback(); |
| @@ -965,16 +1034,16 @@ static u64 GetSystemTick() { | |||
| 965 | static ResultCode CloseHandle(Handle handle) { | 1034 | static ResultCode CloseHandle(Handle handle) { |
| 966 | LOG_TRACE(Kernel_SVC, "Closing handle 0x{:08X}", handle); | 1035 | LOG_TRACE(Kernel_SVC, "Closing handle 0x{:08X}", handle); |
| 967 | 1036 | ||
| 968 | auto& kernel = Core::System::GetInstance().Kernel(); | 1037 | auto& handle_table = Core::CurrentProcess()->GetHandleTable(); |
| 969 | return kernel.HandleTable().Close(handle); | 1038 | return handle_table.Close(handle); |
| 970 | } | 1039 | } |
| 971 | 1040 | ||
| 972 | /// Reset an event | 1041 | /// Reset an event |
| 973 | static ResultCode ResetSignal(Handle handle) { | 1042 | static ResultCode ResetSignal(Handle handle) { |
| 974 | LOG_WARNING(Kernel_SVC, "(STUBBED) called handle 0x{:08X}", handle); | 1043 | LOG_WARNING(Kernel_SVC, "(STUBBED) called handle 0x{:08X}", handle); |
| 975 | 1044 | ||
| 976 | auto& kernel = Core::System::GetInstance().Kernel(); | 1045 | const auto& handle_table = Core::CurrentProcess()->GetHandleTable(); |
| 977 | auto event = kernel.HandleTable().Get<Event>(handle); | 1046 | auto event = handle_table.Get<Event>(handle); |
| 978 | 1047 | ||
| 979 | ASSERT(event != nullptr); | 1048 | ASSERT(event != nullptr); |
| 980 | 1049 | ||
| @@ -993,8 +1062,8 @@ static ResultCode CreateTransferMemory(Handle* handle, VAddr addr, u64 size, u32 | |||
| 993 | static ResultCode GetThreadCoreMask(Handle thread_handle, u32* core, u64* mask) { | 1062 | static ResultCode GetThreadCoreMask(Handle thread_handle, u32* core, u64* mask) { |
| 994 | LOG_TRACE(Kernel_SVC, "called, handle=0x{:08X}", thread_handle); | 1063 | LOG_TRACE(Kernel_SVC, "called, handle=0x{:08X}", thread_handle); |
| 995 | 1064 | ||
| 996 | auto& kernel = Core::System::GetInstance().Kernel(); | 1065 | const auto& handle_table = Core::CurrentProcess()->GetHandleTable(); |
| 997 | const SharedPtr<Thread> thread = kernel.HandleTable().Get<Thread>(thread_handle); | 1066 | const SharedPtr<Thread> thread = handle_table.Get<Thread>(thread_handle); |
| 998 | if (!thread) { | 1067 | if (!thread) { |
| 999 | return ERR_INVALID_HANDLE; | 1068 | return ERR_INVALID_HANDLE; |
| 1000 | } | 1069 | } |
| @@ -1009,8 +1078,8 @@ static ResultCode SetThreadCoreMask(Handle thread_handle, u32 core, u64 mask) { | |||
| 1009 | LOG_DEBUG(Kernel_SVC, "called, handle=0x{:08X}, mask=0x{:16X}, core=0x{:X}", thread_handle, | 1078 | LOG_DEBUG(Kernel_SVC, "called, handle=0x{:08X}, mask=0x{:16X}, core=0x{:X}", thread_handle, |
| 1010 | mask, core); | 1079 | mask, core); |
| 1011 | 1080 | ||
| 1012 | auto& kernel = Core::System::GetInstance().Kernel(); | 1081 | const auto& handle_table = Core::CurrentProcess()->GetHandleTable(); |
| 1013 | const SharedPtr<Thread> thread = kernel.HandleTable().Get<Thread>(thread_handle); | 1082 | const SharedPtr<Thread> thread = handle_table.Get<Thread>(thread_handle); |
| 1014 | if (!thread) { | 1083 | if (!thread) { |
| 1015 | return ERR_INVALID_HANDLE; | 1084 | return ERR_INVALID_HANDLE; |
| 1016 | } | 1085 | } |
| @@ -1071,7 +1140,7 @@ static ResultCode CreateSharedMemory(Handle* handle, u64 size, u32 local_permiss | |||
| 1071 | } | 1140 | } |
| 1072 | 1141 | ||
| 1073 | auto& kernel = Core::System::GetInstance().Kernel(); | 1142 | auto& kernel = Core::System::GetInstance().Kernel(); |
| 1074 | auto& handle_table = kernel.HandleTable(); | 1143 | auto& handle_table = Core::CurrentProcess()->GetHandleTable(); |
| 1075 | auto shared_mem_handle = | 1144 | auto shared_mem_handle = |
| 1076 | SharedMemory::Create(kernel, handle_table.Get<Process>(KernelHandle::CurrentProcess), size, | 1145 | SharedMemory::Create(kernel, handle_table.Get<Process>(KernelHandle::CurrentProcess), size, |
| 1077 | local_perms, remote_perms); | 1146 | local_perms, remote_perms); |
| @@ -1083,10 +1152,12 @@ static ResultCode CreateSharedMemory(Handle* handle, u64 size, u32 local_permiss | |||
| 1083 | static ResultCode ClearEvent(Handle handle) { | 1152 | static ResultCode ClearEvent(Handle handle) { |
| 1084 | LOG_TRACE(Kernel_SVC, "called, event=0x{:08X}", handle); | 1153 | LOG_TRACE(Kernel_SVC, "called, event=0x{:08X}", handle); |
| 1085 | 1154 | ||
| 1086 | auto& kernel = Core::System::GetInstance().Kernel(); | 1155 | const auto& handle_table = Core::CurrentProcess()->GetHandleTable(); |
| 1087 | SharedPtr<Event> evt = kernel.HandleTable().Get<Event>(handle); | 1156 | SharedPtr<Event> evt = handle_table.Get<Event>(handle); |
| 1088 | if (evt == nullptr) | 1157 | if (evt == nullptr) { |
| 1089 | return ERR_INVALID_HANDLE; | 1158 | return ERR_INVALID_HANDLE; |
| 1159 | } | ||
| 1160 | |||
| 1090 | evt->Clear(); | 1161 | evt->Clear(); |
| 1091 | return RESULT_SUCCESS; | 1162 | return RESULT_SUCCESS; |
| 1092 | } | 1163 | } |
| @@ -1099,8 +1170,8 @@ static ResultCode GetProcessInfo(u64* out, Handle process_handle, u32 type) { | |||
| 1099 | Status, | 1170 | Status, |
| 1100 | }; | 1171 | }; |
| 1101 | 1172 | ||
| 1102 | const auto& kernel = Core::System::GetInstance().Kernel(); | 1173 | const auto& handle_table = Core::CurrentProcess()->GetHandleTable(); |
| 1103 | const auto process = kernel.HandleTable().Get<Process>(process_handle); | 1174 | const auto process = handle_table.Get<Process>(process_handle); |
| 1104 | if (!process) { | 1175 | if (!process) { |
| 1105 | return ERR_INVALID_HANDLE; | 1176 | return ERR_INVALID_HANDLE; |
| 1106 | } | 1177 | } |
diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp index 35ec98c1a..59bc9e0af 100644 --- a/src/core/hle/kernel/thread.cpp +++ b/src/core/hle/kernel/thread.cpp | |||
| @@ -266,7 +266,7 @@ SharedPtr<Thread> SetupMainThread(KernelCore& kernel, VAddr entry_point, u32 pri | |||
| 266 | SharedPtr<Thread> thread = std::move(thread_res).Unwrap(); | 266 | SharedPtr<Thread> thread = std::move(thread_res).Unwrap(); |
| 267 | 267 | ||
| 268 | // Register 1 must be a handle to the main thread | 268 | // Register 1 must be a handle to the main thread |
| 269 | const Handle guest_handle = kernel.HandleTable().Create(thread).Unwrap(); | 269 | const Handle guest_handle = owner_process.GetHandleTable().Create(thread).Unwrap(); |
| 270 | thread->SetGuestHandle(guest_handle); | 270 | thread->SetGuestHandle(guest_handle); |
| 271 | thread->GetContext().cpu_registers[1] = guest_handle; | 271 | thread->GetContext().cpu_registers[1] = guest_handle; |
| 272 | 272 | ||
diff --git a/src/core/hle/kernel/vm_manager.cpp b/src/core/hle/kernel/vm_manager.cpp index 1e28ccbda..1a92c8f70 100644 --- a/src/core/hle/kernel/vm_manager.cpp +++ b/src/core/hle/kernel/vm_manager.cpp | |||
| @@ -143,6 +143,26 @@ ResultVal<VMManager::VMAHandle> VMManager::MapBackingMemory(VAddr target, u8* me | |||
| 143 | return MakeResult<VMAHandle>(MergeAdjacent(vma_handle)); | 143 | return MakeResult<VMAHandle>(MergeAdjacent(vma_handle)); |
| 144 | } | 144 | } |
| 145 | 145 | ||
| 146 | ResultVal<VAddr> VMManager::FindFreeRegion(u64 size) const { | ||
| 147 | // Find the first Free VMA. | ||
| 148 | const VAddr base = GetASLRRegionBaseAddress(); | ||
| 149 | const VMAHandle vma_handle = std::find_if(vma_map.begin(), vma_map.end(), [&](const auto& vma) { | ||
| 150 | if (vma.second.type != VMAType::Free) | ||
| 151 | return false; | ||
| 152 | |||
| 153 | const VAddr vma_end = vma.second.base + vma.second.size; | ||
| 154 | return vma_end > base && vma_end >= base + size; | ||
| 155 | }); | ||
| 156 | |||
| 157 | if (vma_handle == vma_map.end()) { | ||
| 158 | // TODO(Subv): Find the correct error code here. | ||
| 159 | return ResultCode(-1); | ||
| 160 | } | ||
| 161 | |||
| 162 | const VAddr target = std::max(base, vma_handle->second.base); | ||
| 163 | return MakeResult<VAddr>(target); | ||
| 164 | } | ||
| 165 | |||
| 146 | ResultVal<VMManager::VMAHandle> VMManager::MapMMIO(VAddr target, PAddr paddr, u64 size, | 166 | ResultVal<VMManager::VMAHandle> VMManager::MapMMIO(VAddr target, PAddr paddr, u64 size, |
| 147 | MemoryState state, | 167 | MemoryState state, |
| 148 | Memory::MemoryHookPointer mmio_handler) { | 168 | Memory::MemoryHookPointer mmio_handler) { |
| @@ -507,6 +527,26 @@ u64 VMManager::GetASLRRegionSize() const { | |||
| 507 | return aslr_region_end - aslr_region_base; | 527 | return aslr_region_end - aslr_region_base; |
| 508 | } | 528 | } |
| 509 | 529 | ||
| 530 | bool VMManager::IsWithinASLRRegion(VAddr begin, u64 size) const { | ||
| 531 | const VAddr range_end = begin + size; | ||
| 532 | const VAddr aslr_start = GetASLRRegionBaseAddress(); | ||
| 533 | const VAddr aslr_end = GetASLRRegionEndAddress(); | ||
| 534 | |||
| 535 | if (aslr_start > begin || begin > range_end || range_end - 1 > aslr_end - 1) { | ||
| 536 | return false; | ||
| 537 | } | ||
| 538 | |||
| 539 | if (range_end > heap_region_base && heap_region_end > begin) { | ||
| 540 | return false; | ||
| 541 | } | ||
| 542 | |||
| 543 | if (range_end > map_region_base && map_region_end > begin) { | ||
| 544 | return false; | ||
| 545 | } | ||
| 546 | |||
| 547 | return true; | ||
| 548 | } | ||
| 549 | |||
| 510 | VAddr VMManager::GetCodeRegionBaseAddress() const { | 550 | VAddr VMManager::GetCodeRegionBaseAddress() const { |
| 511 | return code_region_base; | 551 | return code_region_base; |
| 512 | } | 552 | } |
diff --git a/src/core/hle/kernel/vm_manager.h b/src/core/hle/kernel/vm_manager.h index 4accde6b3..2447cbb8f 100644 --- a/src/core/hle/kernel/vm_manager.h +++ b/src/core/hle/kernel/vm_manager.h | |||
| @@ -158,6 +158,14 @@ public: | |||
| 158 | ResultVal<VMAHandle> MapBackingMemory(VAddr target, u8* memory, u64 size, MemoryState state); | 158 | ResultVal<VMAHandle> MapBackingMemory(VAddr target, u8* memory, u64 size, MemoryState state); |
| 159 | 159 | ||
| 160 | /** | 160 | /** |
| 161 | * Finds the first free address that can hold a region of the desired size. | ||
| 162 | * | ||
| 163 | * @param size Size of the desired region. | ||
| 164 | * @return The found free address. | ||
| 165 | */ | ||
| 166 | ResultVal<VAddr> FindFreeRegion(u64 size) const; | ||
| 167 | |||
| 168 | /** | ||
| 161 | * Maps a memory-mapped IO region at a given address. | 169 | * Maps a memory-mapped IO region at a given address. |
| 162 | * | 170 | * |
| 163 | * @param target The guest address to start the mapping at. | 171 | * @param target The guest address to start the mapping at. |
| @@ -211,6 +219,9 @@ public: | |||
| 211 | /// Gets the end address of the ASLR region. | 219 | /// Gets the end address of the ASLR region. |
| 212 | VAddr GetASLRRegionEndAddress() const; | 220 | VAddr GetASLRRegionEndAddress() const; |
| 213 | 221 | ||
| 222 | /// Determines whether or not the specified address range is within the ASLR region. | ||
| 223 | bool IsWithinASLRRegion(VAddr address, u64 size) const; | ||
| 224 | |||
| 214 | /// Gets the size of the ASLR region | 225 | /// Gets the size of the ASLR region |
| 215 | u64 GetASLRRegionSize() const; | 226 | u64 GetASLRRegionSize() const; |
| 216 | 227 | ||
diff --git a/src/core/hle/service/acc/acc.cpp b/src/core/hle/service/acc/acc.cpp index e61748ca3..c6437a671 100644 --- a/src/core/hle/service/acc/acc.cpp +++ b/src/core/hle/service/acc/acc.cpp | |||
| @@ -2,9 +2,13 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <algorithm> | ||
| 5 | #include <array> | 6 | #include <array> |
| 7 | #include "common/common_paths.h" | ||
| 6 | #include "common/common_types.h" | 8 | #include "common/common_types.h" |
| 9 | #include "common/file_util.h" | ||
| 7 | #include "common/logging/log.h" | 10 | #include "common/logging/log.h" |
| 11 | #include "common/string_util.h" | ||
| 8 | #include "common/swap.h" | 12 | #include "common/swap.h" |
| 9 | #include "core/core_timing.h" | 13 | #include "core/core_timing.h" |
| 10 | #include "core/hle/ipc_helpers.h" | 14 | #include "core/hle/ipc_helpers.h" |
| @@ -16,6 +20,7 @@ | |||
| 16 | #include "core/hle/service/acc/profile_manager.h" | 20 | #include "core/hle/service/acc/profile_manager.h" |
| 17 | 21 | ||
| 18 | namespace Service::Account { | 22 | namespace Service::Account { |
| 23 | |||
| 19 | // TODO: RE this structure | 24 | // TODO: RE this structure |
| 20 | struct UserData { | 25 | struct UserData { |
| 21 | INSERT_PADDING_WORDS(1); | 26 | INSERT_PADDING_WORDS(1); |
| @@ -27,6 +32,29 @@ struct UserData { | |||
| 27 | }; | 32 | }; |
| 28 | static_assert(sizeof(UserData) == 0x80, "UserData structure has incorrect size"); | 33 | static_assert(sizeof(UserData) == 0x80, "UserData structure has incorrect size"); |
| 29 | 34 | ||
| 35 | // Smallest JPEG https://github.com/mathiasbynens/small/blob/master/jpeg.jpg | ||
| 36 | // used as a backup should the one on disk not exist | ||
| 37 | constexpr u32 backup_jpeg_size = 107; | ||
| 38 | constexpr std::array<u8, backup_jpeg_size> backup_jpeg{{ | ||
| 39 | 0xff, 0xd8, 0xff, 0xdb, 0x00, 0x43, 0x00, 0x03, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x02, 0x02, | ||
| 40 | 0x02, 0x03, 0x03, 0x03, 0x03, 0x04, 0x06, 0x04, 0x04, 0x04, 0x04, 0x04, 0x08, 0x06, 0x06, 0x05, | ||
| 41 | 0x06, 0x09, 0x08, 0x0a, 0x0a, 0x09, 0x08, 0x09, 0x09, 0x0a, 0x0c, 0x0f, 0x0c, 0x0a, 0x0b, 0x0e, | ||
| 42 | 0x0b, 0x09, 0x09, 0x0d, 0x11, 0x0d, 0x0e, 0x0f, 0x10, 0x10, 0x11, 0x10, 0x0a, 0x0c, 0x12, 0x13, | ||
| 43 | 0x12, 0x10, 0x13, 0x0f, 0x10, 0x10, 0x10, 0xff, 0xc9, 0x00, 0x0b, 0x08, 0x00, 0x01, 0x00, 0x01, | ||
| 44 | 0x01, 0x01, 0x11, 0x00, 0xff, 0xcc, 0x00, 0x06, 0x00, 0x10, 0x10, 0x05, 0xff, 0xda, 0x00, 0x08, | ||
| 45 | 0x01, 0x01, 0x00, 0x00, 0x3f, 0x00, 0xd2, 0xcf, 0x20, 0xff, 0xd9, | ||
| 46 | }}; | ||
| 47 | |||
| 48 | static std::string GetImagePath(UUID uuid) { | ||
| 49 | return FileUtil::GetUserPath(FileUtil::UserPath::NANDDir) + | ||
| 50 | "/system/save/8000000000000010/su/avators/" + uuid.FormatSwitch() + ".jpg"; | ||
| 51 | } | ||
| 52 | |||
| 53 | static constexpr u32 SanitizeJPEGSize(std::size_t size) { | ||
| 54 | constexpr std::size_t max_jpeg_image_size = 0x20000; | ||
| 55 | return static_cast<u32>(std::min(size, max_jpeg_image_size)); | ||
| 56 | } | ||
| 57 | |||
| 30 | class IProfile final : public ServiceFramework<IProfile> { | 58 | class IProfile final : public ServiceFramework<IProfile> { |
| 31 | public: | 59 | public: |
| 32 | explicit IProfile(UUID user_id, ProfileManager& profile_manager) | 60 | explicit IProfile(UUID user_id, ProfileManager& profile_manager) |
| @@ -73,32 +101,42 @@ private: | |||
| 73 | } | 101 | } |
| 74 | 102 | ||
| 75 | void LoadImage(Kernel::HLERequestContext& ctx) { | 103 | void LoadImage(Kernel::HLERequestContext& ctx) { |
| 76 | LOG_WARNING(Service_ACC, "(STUBBED) called"); | 104 | LOG_DEBUG(Service_ACC, "called"); |
| 77 | // smallest jpeg https://github.com/mathiasbynens/small/blob/master/jpeg.jpg | 105 | |
| 78 | // TODO(mailwl): load actual profile image from disk, width 256px, max size 0x20000 | ||
| 79 | constexpr u32 jpeg_size = 107; | ||
| 80 | static constexpr std::array<u8, jpeg_size> jpeg{ | ||
| 81 | 0xff, 0xd8, 0xff, 0xdb, 0x00, 0x43, 0x00, 0x03, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, | ||
| 82 | 0x02, 0x02, 0x02, 0x03, 0x03, 0x03, 0x03, 0x04, 0x06, 0x04, 0x04, 0x04, 0x04, 0x04, | ||
| 83 | 0x08, 0x06, 0x06, 0x05, 0x06, 0x09, 0x08, 0x0a, 0x0a, 0x09, 0x08, 0x09, 0x09, 0x0a, | ||
| 84 | 0x0c, 0x0f, 0x0c, 0x0a, 0x0b, 0x0e, 0x0b, 0x09, 0x09, 0x0d, 0x11, 0x0d, 0x0e, 0x0f, | ||
| 85 | 0x10, 0x10, 0x11, 0x10, 0x0a, 0x0c, 0x12, 0x13, 0x12, 0x10, 0x13, 0x0f, 0x10, 0x10, | ||
| 86 | 0x10, 0xff, 0xc9, 0x00, 0x0b, 0x08, 0x00, 0x01, 0x00, 0x01, 0x01, 0x01, 0x11, 0x00, | ||
| 87 | 0xff, 0xcc, 0x00, 0x06, 0x00, 0x10, 0x10, 0x05, 0xff, 0xda, 0x00, 0x08, 0x01, 0x01, | ||
| 88 | 0x00, 0x00, 0x3f, 0x00, 0xd2, 0xcf, 0x20, 0xff, 0xd9, | ||
| 89 | }; | ||
| 90 | ctx.WriteBuffer(jpeg); | ||
| 91 | IPC::ResponseBuilder rb{ctx, 3}; | 106 | IPC::ResponseBuilder rb{ctx, 3}; |
| 92 | rb.Push(RESULT_SUCCESS); | 107 | rb.Push(RESULT_SUCCESS); |
| 93 | rb.Push<u32>(jpeg_size); | 108 | |
| 109 | const FileUtil::IOFile image(GetImagePath(user_id), "rb"); | ||
| 110 | if (!image.IsOpen()) { | ||
| 111 | LOG_WARNING(Service_ACC, | ||
| 112 | "Failed to load user provided image! Falling back to built-in backup..."); | ||
| 113 | ctx.WriteBuffer(backup_jpeg); | ||
| 114 | rb.Push<u32>(backup_jpeg_size); | ||
| 115 | return; | ||
| 116 | } | ||
| 117 | |||
| 118 | const u32 size = SanitizeJPEGSize(image.GetSize()); | ||
| 119 | std::vector<u8> buffer(size); | ||
| 120 | image.ReadBytes(buffer.data(), buffer.size()); | ||
| 121 | |||
| 122 | ctx.WriteBuffer(buffer.data(), buffer.size()); | ||
| 123 | rb.Push<u32>(size); | ||
| 94 | } | 124 | } |
| 95 | 125 | ||
| 96 | void GetImageSize(Kernel::HLERequestContext& ctx) { | 126 | void GetImageSize(Kernel::HLERequestContext& ctx) { |
| 97 | LOG_WARNING(Service_ACC, "(STUBBED) called"); | 127 | LOG_DEBUG(Service_ACC, "called"); |
| 98 | constexpr u32 jpeg_size = 107; | ||
| 99 | IPC::ResponseBuilder rb{ctx, 3}; | 128 | IPC::ResponseBuilder rb{ctx, 3}; |
| 100 | rb.Push(RESULT_SUCCESS); | 129 | rb.Push(RESULT_SUCCESS); |
| 101 | rb.Push<u32>(jpeg_size); | 130 | |
| 131 | const FileUtil::IOFile image(GetImagePath(user_id), "rb"); | ||
| 132 | |||
| 133 | if (!image.IsOpen()) { | ||
| 134 | LOG_WARNING(Service_ACC, | ||
| 135 | "Failed to load user provided image! Falling back to built-in backup..."); | ||
| 136 | rb.Push<u32>(backup_jpeg_size); | ||
| 137 | } else { | ||
| 138 | rb.Push<u32>(SanitizeJPEGSize(image.GetSize())); | ||
| 139 | } | ||
| 102 | } | 140 | } |
| 103 | 141 | ||
| 104 | const ProfileManager& profile_manager; | 142 | const ProfileManager& profile_manager; |
diff --git a/src/core/hle/service/acc/profile_manager.cpp b/src/core/hle/service/acc/profile_manager.cpp index bcb3475db..3cac1b4ff 100644 --- a/src/core/hle/service/acc/profile_manager.cpp +++ b/src/core/hle/service/acc/profile_manager.cpp | |||
| @@ -3,41 +3,66 @@ | |||
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <random> | 5 | #include <random> |
| 6 | #include <boost/optional.hpp> | 6 | |
| 7 | #include "common/file_util.h" | ||
| 7 | #include "core/hle/service/acc/profile_manager.h" | 8 | #include "core/hle/service/acc/profile_manager.h" |
| 8 | #include "core/settings.h" | 9 | #include "core/settings.h" |
| 9 | 10 | ||
| 10 | namespace Service::Account { | 11 | namespace Service::Account { |
| 12 | |||
| 13 | struct UserRaw { | ||
| 14 | UUID uuid; | ||
| 15 | UUID uuid2; | ||
| 16 | u64 timestamp; | ||
| 17 | ProfileUsername username; | ||
| 18 | INSERT_PADDING_BYTES(0x80); | ||
| 19 | }; | ||
| 20 | static_assert(sizeof(UserRaw) == 0xC8, "UserRaw has incorrect size."); | ||
| 21 | |||
| 22 | struct ProfileDataRaw { | ||
| 23 | INSERT_PADDING_BYTES(0x10); | ||
| 24 | std::array<UserRaw, MAX_USERS> users; | ||
| 25 | }; | ||
| 26 | static_assert(sizeof(ProfileDataRaw) == 0x650, "ProfileDataRaw has incorrect size."); | ||
| 27 | |||
| 11 | // TODO(ogniK): Get actual error codes | 28 | // TODO(ogniK): Get actual error codes |
| 12 | constexpr ResultCode ERROR_TOO_MANY_USERS(ErrorModule::Account, -1); | 29 | constexpr ResultCode ERROR_TOO_MANY_USERS(ErrorModule::Account, -1); |
| 13 | constexpr ResultCode ERROR_USER_ALREADY_EXISTS(ErrorModule::Account, -2); | 30 | constexpr ResultCode ERROR_USER_ALREADY_EXISTS(ErrorModule::Account, -2); |
| 14 | constexpr ResultCode ERROR_ARGUMENT_IS_NULL(ErrorModule::Account, 20); | 31 | constexpr ResultCode ERROR_ARGUMENT_IS_NULL(ErrorModule::Account, 20); |
| 15 | 32 | ||
| 16 | const UUID& UUID::Generate() { | 33 | constexpr char ACC_SAVE_AVATORS_BASE_PATH[] = "/system/save/8000000000000010/su/avators/"; |
| 34 | |||
| 35 | UUID UUID::Generate() { | ||
| 17 | std::random_device device; | 36 | std::random_device device; |
| 18 | std::mt19937 gen(device()); | 37 | std::mt19937 gen(device()); |
| 19 | std::uniform_int_distribution<u64> distribution(1, std::numeric_limits<u64>::max()); | 38 | std::uniform_int_distribution<u64> distribution(1, std::numeric_limits<u64>::max()); |
| 20 | uuid[0] = distribution(gen); | 39 | return UUID{distribution(gen), distribution(gen)}; |
| 21 | uuid[1] = distribution(gen); | ||
| 22 | return *this; | ||
| 23 | } | 40 | } |
| 24 | 41 | ||
| 25 | ProfileManager::ProfileManager() { | 42 | ProfileManager::ProfileManager() { |
| 26 | // TODO(ogniK): Create the default user we have for now until loading/saving users is added | 43 | ParseUserSaveFile(); |
| 27 | auto user_uuid = UUID{1, 0}; | 44 | |
| 28 | ASSERT(CreateNewUser(user_uuid, Settings::values.username).IsSuccess()); | 45 | if (user_count == 0) |
| 29 | OpenUser(user_uuid); | 46 | CreateNewUser(UUID::Generate(), "yuzu"); |
| 47 | |||
| 48 | auto current = std::clamp<int>(Settings::values.current_user, 0, MAX_USERS - 1); | ||
| 49 | if (UserExistsIndex(current)) | ||
| 50 | current = 0; | ||
| 51 | |||
| 52 | OpenUser(*GetUser(current)); | ||
| 30 | } | 53 | } |
| 31 | 54 | ||
| 32 | ProfileManager::~ProfileManager() = default; | 55 | ProfileManager::~ProfileManager() { |
| 56 | WriteUserSaveFile(); | ||
| 57 | } | ||
| 33 | 58 | ||
| 34 | /// After a users creation it needs to be "registered" to the system. AddToProfiles handles the | 59 | /// After a users creation it needs to be "registered" to the system. AddToProfiles handles the |
| 35 | /// internal management of the users profiles | 60 | /// internal management of the users profiles |
| 36 | boost::optional<std::size_t> ProfileManager::AddToProfiles(const ProfileInfo& user) { | 61 | std::optional<std::size_t> ProfileManager::AddToProfiles(const ProfileInfo& profile) { |
| 37 | if (user_count >= MAX_USERS) { | 62 | if (user_count >= MAX_USERS) { |
| 38 | return boost::none; | 63 | return {}; |
| 39 | } | 64 | } |
| 40 | profiles[user_count] = user; | 65 | profiles[user_count] = profile; |
| 41 | return user_count++; | 66 | return user_count++; |
| 42 | } | 67 | } |
| 43 | 68 | ||
| @@ -56,7 +81,7 @@ bool ProfileManager::RemoveProfileAtIndex(std::size_t index) { | |||
| 56 | 81 | ||
| 57 | /// Helper function to register a user to the system | 82 | /// Helper function to register a user to the system |
| 58 | ResultCode ProfileManager::AddUser(const ProfileInfo& user) { | 83 | ResultCode ProfileManager::AddUser(const ProfileInfo& user) { |
| 59 | if (AddToProfiles(user) == boost::none) { | 84 | if (!AddToProfiles(user)) { |
| 60 | return ERROR_TOO_MANY_USERS; | 85 | return ERROR_TOO_MANY_USERS; |
| 61 | } | 86 | } |
| 62 | return RESULT_SUCCESS; | 87 | return RESULT_SUCCESS; |
| @@ -101,31 +126,40 @@ ResultCode ProfileManager::CreateNewUser(UUID uuid, const std::string& username) | |||
| 101 | return CreateNewUser(uuid, username_output); | 126 | return CreateNewUser(uuid, username_output); |
| 102 | } | 127 | } |
| 103 | 128 | ||
| 129 | std::optional<UUID> ProfileManager::GetUser(std::size_t index) const { | ||
| 130 | if (index >= MAX_USERS) { | ||
| 131 | return {}; | ||
| 132 | } | ||
| 133 | |||
| 134 | return profiles[index].user_uuid; | ||
| 135 | } | ||
| 136 | |||
| 104 | /// Returns a users profile index based on their user id. | 137 | /// Returns a users profile index based on their user id. |
| 105 | boost::optional<std::size_t> ProfileManager::GetUserIndex(const UUID& uuid) const { | 138 | std::optional<std::size_t> ProfileManager::GetUserIndex(const UUID& uuid) const { |
| 106 | if (!uuid) { | 139 | if (!uuid) { |
| 107 | return boost::none; | 140 | return {}; |
| 108 | } | 141 | } |
| 109 | auto iter = std::find_if(profiles.begin(), profiles.end(), | 142 | |
| 110 | [&uuid](const ProfileInfo& p) { return p.user_uuid == uuid; }); | 143 | const auto iter = std::find_if(profiles.begin(), profiles.end(), |
| 144 | [&uuid](const ProfileInfo& p) { return p.user_uuid == uuid; }); | ||
| 111 | if (iter == profiles.end()) { | 145 | if (iter == profiles.end()) { |
| 112 | return boost::none; | 146 | return {}; |
| 113 | } | 147 | } |
| 148 | |||
| 114 | return static_cast<std::size_t>(std::distance(profiles.begin(), iter)); | 149 | return static_cast<std::size_t>(std::distance(profiles.begin(), iter)); |
| 115 | } | 150 | } |
| 116 | 151 | ||
| 117 | /// Returns a users profile index based on their profile | 152 | /// Returns a users profile index based on their profile |
| 118 | boost::optional<std::size_t> ProfileManager::GetUserIndex(const ProfileInfo& user) const { | 153 | std::optional<std::size_t> ProfileManager::GetUserIndex(const ProfileInfo& user) const { |
| 119 | return GetUserIndex(user.user_uuid); | 154 | return GetUserIndex(user.user_uuid); |
| 120 | } | 155 | } |
| 121 | 156 | ||
| 122 | /// Returns the data structure used by the switch when GetProfileBase is called on acc:* | 157 | /// Returns the data structure used by the switch when GetProfileBase is called on acc:* |
| 123 | bool ProfileManager::GetProfileBase(boost::optional<std::size_t> index, | 158 | bool ProfileManager::GetProfileBase(std::optional<std::size_t> index, ProfileBase& profile) const { |
| 124 | ProfileBase& profile) const { | 159 | if (!index || index >= MAX_USERS) { |
| 125 | if (index == boost::none || index >= MAX_USERS) { | ||
| 126 | return false; | 160 | return false; |
| 127 | } | 161 | } |
| 128 | const auto& prof_info = profiles[index.get()]; | 162 | const auto& prof_info = profiles[*index]; |
| 129 | profile.user_uuid = prof_info.user_uuid; | 163 | profile.user_uuid = prof_info.user_uuid; |
| 130 | profile.username = prof_info.username; | 164 | profile.username = prof_info.username; |
| 131 | profile.timestamp = prof_info.creation_time; | 165 | profile.timestamp = prof_info.creation_time; |
| @@ -134,7 +168,7 @@ bool ProfileManager::GetProfileBase(boost::optional<std::size_t> index, | |||
| 134 | 168 | ||
| 135 | /// Returns the data structure used by the switch when GetProfileBase is called on acc:* | 169 | /// Returns the data structure used by the switch when GetProfileBase is called on acc:* |
| 136 | bool ProfileManager::GetProfileBase(UUID uuid, ProfileBase& profile) const { | 170 | bool ProfileManager::GetProfileBase(UUID uuid, ProfileBase& profile) const { |
| 137 | auto idx = GetUserIndex(uuid); | 171 | const auto idx = GetUserIndex(uuid); |
| 138 | return GetProfileBase(idx, profile); | 172 | return GetProfileBase(idx, profile); |
| 139 | } | 173 | } |
| 140 | 174 | ||
| @@ -161,26 +195,34 @@ std::size_t ProfileManager::GetOpenUserCount() const { | |||
| 161 | 195 | ||
| 162 | /// Checks if a user id exists in our profile manager | 196 | /// Checks if a user id exists in our profile manager |
| 163 | bool ProfileManager::UserExists(UUID uuid) const { | 197 | bool ProfileManager::UserExists(UUID uuid) const { |
| 164 | return (GetUserIndex(uuid) != boost::none); | 198 | return GetUserIndex(uuid) != std::nullopt; |
| 199 | } | ||
| 200 | |||
| 201 | bool ProfileManager::UserExistsIndex(std::size_t index) const { | ||
| 202 | if (index >= MAX_USERS) | ||
| 203 | return false; | ||
| 204 | return profiles[index].user_uuid.uuid != INVALID_UUID; | ||
| 165 | } | 205 | } |
| 166 | 206 | ||
| 167 | /// Opens a specific user | 207 | /// Opens a specific user |
| 168 | void ProfileManager::OpenUser(UUID uuid) { | 208 | void ProfileManager::OpenUser(UUID uuid) { |
| 169 | auto idx = GetUserIndex(uuid); | 209 | const auto idx = GetUserIndex(uuid); |
| 170 | if (idx == boost::none) { | 210 | if (!idx) { |
| 171 | return; | 211 | return; |
| 172 | } | 212 | } |
| 173 | profiles[idx.get()].is_open = true; | 213 | |
| 214 | profiles[*idx].is_open = true; | ||
| 174 | last_opened_user = uuid; | 215 | last_opened_user = uuid; |
| 175 | } | 216 | } |
| 176 | 217 | ||
| 177 | /// Closes a specific user | 218 | /// Closes a specific user |
| 178 | void ProfileManager::CloseUser(UUID uuid) { | 219 | void ProfileManager::CloseUser(UUID uuid) { |
| 179 | auto idx = GetUserIndex(uuid); | 220 | const auto idx = GetUserIndex(uuid); |
| 180 | if (idx == boost::none) { | 221 | if (!idx) { |
| 181 | return; | 222 | return; |
| 182 | } | 223 | } |
| 183 | profiles[idx.get()].is_open = false; | 224 | |
| 225 | profiles[*idx].is_open = false; | ||
| 184 | } | 226 | } |
| 185 | 227 | ||
| 186 | /// Gets all valid user ids on the system | 228 | /// Gets all valid user ids on the system |
| @@ -210,10 +252,10 @@ UUID ProfileManager::GetLastOpenedUser() const { | |||
| 210 | } | 252 | } |
| 211 | 253 | ||
| 212 | /// Return the users profile base and the unknown arbitary data. | 254 | /// Return the users profile base and the unknown arbitary data. |
| 213 | bool ProfileManager::GetProfileBaseAndData(boost::optional<std::size_t> index, ProfileBase& profile, | 255 | bool ProfileManager::GetProfileBaseAndData(std::optional<std::size_t> index, ProfileBase& profile, |
| 214 | ProfileData& data) const { | 256 | ProfileData& data) const { |
| 215 | if (GetProfileBase(index, profile)) { | 257 | if (GetProfileBase(index, profile)) { |
| 216 | data = profiles[index.get()].data; | 258 | data = profiles[*index].data; |
| 217 | return true; | 259 | return true; |
| 218 | } | 260 | } |
| 219 | return false; | 261 | return false; |
| @@ -222,7 +264,7 @@ bool ProfileManager::GetProfileBaseAndData(boost::optional<std::size_t> index, P | |||
| 222 | /// Return the users profile base and the unknown arbitary data. | 264 | /// Return the users profile base and the unknown arbitary data. |
| 223 | bool ProfileManager::GetProfileBaseAndData(UUID uuid, ProfileBase& profile, | 265 | bool ProfileManager::GetProfileBaseAndData(UUID uuid, ProfileBase& profile, |
| 224 | ProfileData& data) const { | 266 | ProfileData& data) const { |
| 225 | auto idx = GetUserIndex(uuid); | 267 | const auto idx = GetUserIndex(uuid); |
| 226 | return GetProfileBaseAndData(idx, profile, data); | 268 | return GetProfileBaseAndData(idx, profile, data); |
| 227 | } | 269 | } |
| 228 | 270 | ||
| @@ -239,4 +281,96 @@ bool ProfileManager::CanSystemRegisterUser() const { | |||
| 239 | // emulate qlaunch. Update this to dynamically change. | 281 | // emulate qlaunch. Update this to dynamically change. |
| 240 | } | 282 | } |
| 241 | 283 | ||
| 284 | bool ProfileManager::RemoveUser(UUID uuid) { | ||
| 285 | const auto index = GetUserIndex(uuid); | ||
| 286 | if (!index) { | ||
| 287 | return false; | ||
| 288 | } | ||
| 289 | |||
| 290 | profiles[*index] = ProfileInfo{}; | ||
| 291 | std::stable_partition(profiles.begin(), profiles.end(), | ||
| 292 | [](const ProfileInfo& profile) { return profile.user_uuid; }); | ||
| 293 | return true; | ||
| 294 | } | ||
| 295 | |||
| 296 | bool ProfileManager::SetProfileBase(UUID uuid, const ProfileBase& profile_new) { | ||
| 297 | const auto index = GetUserIndex(uuid); | ||
| 298 | if (!index || profile_new.user_uuid == UUID(INVALID_UUID)) { | ||
| 299 | return false; | ||
| 300 | } | ||
| 301 | |||
| 302 | auto& profile = profiles[*index]; | ||
| 303 | profile.user_uuid = profile_new.user_uuid; | ||
| 304 | profile.username = profile_new.username; | ||
| 305 | profile.creation_time = profile_new.timestamp; | ||
| 306 | |||
| 307 | return true; | ||
| 308 | } | ||
| 309 | |||
| 310 | void ProfileManager::ParseUserSaveFile() { | ||
| 311 | FileUtil::IOFile save(FileUtil::GetUserPath(FileUtil::UserPath::NANDDir) + | ||
| 312 | ACC_SAVE_AVATORS_BASE_PATH + "profiles.dat", | ||
| 313 | "rb"); | ||
| 314 | |||
| 315 | if (!save.IsOpen()) { | ||
| 316 | LOG_WARNING(Service_ACC, "Failed to load profile data from save data... Generating new " | ||
| 317 | "user 'yuzu' with random UUID."); | ||
| 318 | return; | ||
| 319 | } | ||
| 320 | |||
| 321 | ProfileDataRaw data; | ||
| 322 | if (save.ReadBytes(&data, sizeof(ProfileDataRaw)) != sizeof(ProfileDataRaw)) { | ||
| 323 | LOG_WARNING(Service_ACC, "profiles.dat is smaller than expected... Generating new user " | ||
| 324 | "'yuzu' with random UUID."); | ||
| 325 | return; | ||
| 326 | } | ||
| 327 | |||
| 328 | for (std::size_t i = 0; i < MAX_USERS; ++i) { | ||
| 329 | const auto& user = data.users[i]; | ||
| 330 | |||
| 331 | if (user.uuid != UUID(INVALID_UUID)) | ||
| 332 | AddUser({user.uuid, user.username, user.timestamp, {}, false}); | ||
| 333 | } | ||
| 334 | |||
| 335 | std::stable_partition(profiles.begin(), profiles.end(), | ||
| 336 | [](const ProfileInfo& profile) { return profile.user_uuid; }); | ||
| 337 | } | ||
| 338 | |||
| 339 | void ProfileManager::WriteUserSaveFile() { | ||
| 340 | ProfileDataRaw raw{}; | ||
| 341 | |||
| 342 | for (std::size_t i = 0; i < MAX_USERS; ++i) { | ||
| 343 | raw.users[i].username = profiles[i].username; | ||
| 344 | raw.users[i].uuid2 = profiles[i].user_uuid; | ||
| 345 | raw.users[i].uuid = profiles[i].user_uuid; | ||
| 346 | raw.users[i].timestamp = profiles[i].creation_time; | ||
| 347 | } | ||
| 348 | |||
| 349 | const auto raw_path = | ||
| 350 | FileUtil::GetUserPath(FileUtil::UserPath::NANDDir) + "/system/save/8000000000000010"; | ||
| 351 | if (FileUtil::Exists(raw_path) && !FileUtil::IsDirectory(raw_path)) | ||
| 352 | FileUtil::Delete(raw_path); | ||
| 353 | |||
| 354 | const auto path = FileUtil::GetUserPath(FileUtil::UserPath::NANDDir) + | ||
| 355 | ACC_SAVE_AVATORS_BASE_PATH + "profiles.dat"; | ||
| 356 | |||
| 357 | if (!FileUtil::CreateFullPath(path)) { | ||
| 358 | LOG_WARNING(Service_ACC, "Failed to create full path of profiles.dat. Create the directory " | ||
| 359 | "nand/system/save/8000000000000010/su/avators to mitigate this " | ||
| 360 | "issue."); | ||
| 361 | return; | ||
| 362 | } | ||
| 363 | |||
| 364 | FileUtil::IOFile save(path, "wb"); | ||
| 365 | |||
| 366 | if (!save.IsOpen()) { | ||
| 367 | LOG_WARNING(Service_ACC, "Failed to write save data to file... No changes to user data " | ||
| 368 | "made in current session will be saved."); | ||
| 369 | return; | ||
| 370 | } | ||
| 371 | |||
| 372 | save.Resize(sizeof(ProfileDataRaw)); | ||
| 373 | save.WriteBytes(&raw, sizeof(ProfileDataRaw)); | ||
| 374 | } | ||
| 375 | |||
| 242 | }; // namespace Service::Account | 376 | }; // namespace Service::Account |
diff --git a/src/core/hle/service/acc/profile_manager.h b/src/core/hle/service/acc/profile_manager.h index bffd4cf4d..1cd2e51b2 100644 --- a/src/core/hle/service/acc/profile_manager.h +++ b/src/core/hle/service/acc/profile_manager.h | |||
| @@ -5,8 +5,8 @@ | |||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <array> | 7 | #include <array> |
| 8 | #include <optional> | ||
| 8 | 9 | ||
| 9 | #include "boost/optional.hpp" | ||
| 10 | #include "common/common_types.h" | 10 | #include "common/common_types.h" |
| 11 | #include "common/swap.h" | 11 | #include "common/swap.h" |
| 12 | #include "core/hle/result.h" | 12 | #include "core/hle/result.h" |
| @@ -36,7 +36,7 @@ struct UUID { | |||
| 36 | } | 36 | } |
| 37 | 37 | ||
| 38 | // TODO(ogniK): Properly generate uuids based on RFC-4122 | 38 | // TODO(ogniK): Properly generate uuids based on RFC-4122 |
| 39 | const UUID& Generate(); | 39 | static UUID Generate(); |
| 40 | 40 | ||
| 41 | // Set the UUID to {0,0} to be considered an invalid user | 41 | // Set the UUID to {0,0} to be considered an invalid user |
| 42 | void Invalidate() { | 42 | void Invalidate() { |
| @@ -45,6 +45,15 @@ struct UUID { | |||
| 45 | std::string Format() const { | 45 | std::string Format() const { |
| 46 | return fmt::format("0x{:016X}{:016X}", uuid[1], uuid[0]); | 46 | return fmt::format("0x{:016X}{:016X}", uuid[1], uuid[0]); |
| 47 | } | 47 | } |
| 48 | |||
| 49 | std::string FormatSwitch() const { | ||
| 50 | std::array<u8, 16> s{}; | ||
| 51 | std::memcpy(s.data(), uuid.data(), sizeof(u128)); | ||
| 52 | return fmt::format("{:02x}{:02x}{:02x}{:02x}-{:02x}{:02x}-{:02x}{:02x}-{:02x}{:02x}-{:02x}{" | ||
| 53 | ":02x}{:02x}{:02x}{:02x}{:02x}", | ||
| 54 | s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7], s[8], s[9], s[10], s[11], | ||
| 55 | s[12], s[13], s[14], s[15]); | ||
| 56 | } | ||
| 48 | }; | 57 | }; |
| 49 | static_assert(sizeof(UUID) == 16, "UUID is an invalid size!"); | 58 | static_assert(sizeof(UUID) == 16, "UUID is an invalid size!"); |
| 50 | 59 | ||
| @@ -81,18 +90,19 @@ static_assert(sizeof(ProfileBase) == 0x38, "ProfileBase is an invalid size"); | |||
| 81 | /// objects | 90 | /// objects |
| 82 | class ProfileManager { | 91 | class ProfileManager { |
| 83 | public: | 92 | public: |
| 84 | ProfileManager(); // TODO(ogniK): Load from system save | 93 | ProfileManager(); |
| 85 | ~ProfileManager(); | 94 | ~ProfileManager(); |
| 86 | 95 | ||
| 87 | ResultCode AddUser(const ProfileInfo& user); | 96 | ResultCode AddUser(const ProfileInfo& user); |
| 88 | ResultCode CreateNewUser(UUID uuid, const ProfileUsername& username); | 97 | ResultCode CreateNewUser(UUID uuid, const ProfileUsername& username); |
| 89 | ResultCode CreateNewUser(UUID uuid, const std::string& username); | 98 | ResultCode CreateNewUser(UUID uuid, const std::string& username); |
| 90 | boost::optional<std::size_t> GetUserIndex(const UUID& uuid) const; | 99 | std::optional<UUID> GetUser(std::size_t index) const; |
| 91 | boost::optional<std::size_t> GetUserIndex(const ProfileInfo& user) const; | 100 | std::optional<std::size_t> GetUserIndex(const UUID& uuid) const; |
| 92 | bool GetProfileBase(boost::optional<std::size_t> index, ProfileBase& profile) const; | 101 | std::optional<std::size_t> GetUserIndex(const ProfileInfo& user) const; |
| 102 | bool GetProfileBase(std::optional<std::size_t> index, ProfileBase& profile) const; | ||
| 93 | bool GetProfileBase(UUID uuid, ProfileBase& profile) const; | 103 | bool GetProfileBase(UUID uuid, ProfileBase& profile) const; |
| 94 | bool GetProfileBase(const ProfileInfo& user, ProfileBase& profile) const; | 104 | bool GetProfileBase(const ProfileInfo& user, ProfileBase& profile) const; |
| 95 | bool GetProfileBaseAndData(boost::optional<std::size_t> index, ProfileBase& profile, | 105 | bool GetProfileBaseAndData(std::optional<std::size_t> index, ProfileBase& profile, |
| 96 | ProfileData& data) const; | 106 | ProfileData& data) const; |
| 97 | bool GetProfileBaseAndData(UUID uuid, ProfileBase& profile, ProfileData& data) const; | 107 | bool GetProfileBaseAndData(UUID uuid, ProfileBase& profile, ProfileData& data) const; |
| 98 | bool GetProfileBaseAndData(const ProfileInfo& user, ProfileBase& profile, | 108 | bool GetProfileBaseAndData(const ProfileInfo& user, ProfileBase& profile, |
| @@ -100,6 +110,7 @@ public: | |||
| 100 | std::size_t GetUserCount() const; | 110 | std::size_t GetUserCount() const; |
| 101 | std::size_t GetOpenUserCount() const; | 111 | std::size_t GetOpenUserCount() const; |
| 102 | bool UserExists(UUID uuid) const; | 112 | bool UserExists(UUID uuid) const; |
| 113 | bool UserExistsIndex(std::size_t index) const; | ||
| 103 | void OpenUser(UUID uuid); | 114 | void OpenUser(UUID uuid); |
| 104 | void CloseUser(UUID uuid); | 115 | void CloseUser(UUID uuid); |
| 105 | UserIDArray GetOpenUsers() const; | 116 | UserIDArray GetOpenUsers() const; |
| @@ -108,11 +119,17 @@ public: | |||
| 108 | 119 | ||
| 109 | bool CanSystemRegisterUser() const; | 120 | bool CanSystemRegisterUser() const; |
| 110 | 121 | ||
| 122 | bool RemoveUser(UUID uuid); | ||
| 123 | bool SetProfileBase(UUID uuid, const ProfileBase& profile_new); | ||
| 124 | |||
| 111 | private: | 125 | private: |
| 126 | void ParseUserSaveFile(); | ||
| 127 | void WriteUserSaveFile(); | ||
| 128 | std::optional<std::size_t> AddToProfiles(const ProfileInfo& profile); | ||
| 129 | bool RemoveProfileAtIndex(std::size_t index); | ||
| 130 | |||
| 112 | std::array<ProfileInfo, MAX_USERS> profiles{}; | 131 | std::array<ProfileInfo, MAX_USERS> profiles{}; |
| 113 | std::size_t user_count = 0; | 132 | std::size_t user_count = 0; |
| 114 | boost::optional<std::size_t> AddToProfiles(const ProfileInfo& profile); | ||
| 115 | bool RemoveProfileAtIndex(std::size_t index); | ||
| 116 | UUID last_opened_user{INVALID_UUID}; | 133 | UUID last_opened_user{INVALID_UUID}; |
| 117 | }; | 134 | }; |
| 118 | 135 | ||
diff --git a/src/core/hle/service/am/am.cpp b/src/core/hle/service/am/am.cpp index 4d1f83170..59aafd616 100644 --- a/src/core/hle/service/am/am.cpp +++ b/src/core/hle/service/am/am.cpp | |||
| @@ -4,17 +4,20 @@ | |||
| 4 | 4 | ||
| 5 | #include <array> | 5 | #include <array> |
| 6 | #include <cinttypes> | 6 | #include <cinttypes> |
| 7 | #include <cstring> | ||
| 7 | #include <stack> | 8 | #include <stack> |
| 8 | #include "core/core.h" | 9 | #include "core/core.h" |
| 9 | #include "core/hle/ipc_helpers.h" | 10 | #include "core/hle/ipc_helpers.h" |
| 10 | #include "core/hle/kernel/event.h" | 11 | #include "core/hle/kernel/event.h" |
| 11 | #include "core/hle/kernel/process.h" | 12 | #include "core/hle/kernel/process.h" |
| 13 | #include "core/hle/service/acc/profile_manager.h" | ||
| 12 | #include "core/hle/service/am/am.h" | 14 | #include "core/hle/service/am/am.h" |
| 13 | #include "core/hle/service/am/applet_ae.h" | 15 | #include "core/hle/service/am/applet_ae.h" |
| 14 | #include "core/hle/service/am/applet_oe.h" | 16 | #include "core/hle/service/am/applet_oe.h" |
| 15 | #include "core/hle/service/am/idle.h" | 17 | #include "core/hle/service/am/idle.h" |
| 16 | #include "core/hle/service/am/omm.h" | 18 | #include "core/hle/service/am/omm.h" |
| 17 | #include "core/hle/service/am/spsm.h" | 19 | #include "core/hle/service/am/spsm.h" |
| 20 | #include "core/hle/service/am/tcap.h" | ||
| 18 | #include "core/hle/service/apm/apm.h" | 21 | #include "core/hle/service/apm/apm.h" |
| 19 | #include "core/hle/service/filesystem/filesystem.h" | 22 | #include "core/hle/service/filesystem/filesystem.h" |
| 20 | #include "core/hle/service/nvflinger/nvflinger.h" | 23 | #include "core/hle/service/nvflinger/nvflinger.h" |
| @@ -25,14 +28,29 @@ | |||
| 25 | 28 | ||
| 26 | namespace Service::AM { | 29 | namespace Service::AM { |
| 27 | 30 | ||
| 31 | constexpr u32 POP_LAUNCH_PARAMETER_MAGIC = 0xC79497CA; | ||
| 32 | |||
| 33 | struct LaunchParameters { | ||
| 34 | u32_le magic; | ||
| 35 | u32_le is_account_selected; | ||
| 36 | u128 current_user; | ||
| 37 | INSERT_PADDING_BYTES(0x70); | ||
| 38 | }; | ||
| 39 | static_assert(sizeof(LaunchParameters) == 0x88); | ||
| 40 | |||
| 28 | IWindowController::IWindowController() : ServiceFramework("IWindowController") { | 41 | IWindowController::IWindowController() : ServiceFramework("IWindowController") { |
| 42 | // clang-format off | ||
| 29 | static const FunctionInfo functions[] = { | 43 | static const FunctionInfo functions[] = { |
| 30 | {0, nullptr, "CreateWindow"}, | 44 | {0, nullptr, "CreateWindow"}, |
| 31 | {1, &IWindowController::GetAppletResourceUserId, "GetAppletResourceUserId"}, | 45 | {1, &IWindowController::GetAppletResourceUserId, "GetAppletResourceUserId"}, |
| 32 | {10, &IWindowController::AcquireForegroundRights, "AcquireForegroundRights"}, | 46 | {10, &IWindowController::AcquireForegroundRights, "AcquireForegroundRights"}, |
| 33 | {11, nullptr, "ReleaseForegroundRights"}, | 47 | {11, nullptr, "ReleaseForegroundRights"}, |
| 34 | {12, nullptr, "RejectToChangeIntoBackground"}, | 48 | {12, nullptr, "RejectToChangeIntoBackground"}, |
| 49 | {20, nullptr, "SetAppletWindowVisibility"}, | ||
| 50 | {21, nullptr, "SetAppletGpuTimeSlice"}, | ||
| 35 | }; | 51 | }; |
| 52 | // clang-format on | ||
| 53 | |||
| 36 | RegisterHandlers(functions); | 54 | RegisterHandlers(functions); |
| 37 | } | 55 | } |
| 38 | 56 | ||
| @@ -87,6 +105,7 @@ void IAudioController::GetLibraryAppletExpectedMasterVolume(Kernel::HLERequestCo | |||
| 87 | } | 105 | } |
| 88 | 106 | ||
| 89 | IDisplayController::IDisplayController() : ServiceFramework("IDisplayController") { | 107 | IDisplayController::IDisplayController() : ServiceFramework("IDisplayController") { |
| 108 | // clang-format off | ||
| 90 | static const FunctionInfo functions[] = { | 109 | static const FunctionInfo functions[] = { |
| 91 | {0, nullptr, "GetLastForegroundCaptureImage"}, | 110 | {0, nullptr, "GetLastForegroundCaptureImage"}, |
| 92 | {1, nullptr, "UpdateLastForegroundCaptureImage"}, | 111 | {1, nullptr, "UpdateLastForegroundCaptureImage"}, |
| @@ -117,7 +136,11 @@ IDisplayController::IDisplayController() : ServiceFramework("IDisplayController" | |||
| 117 | {25, nullptr, "ReleaseLastForegroundCaptureSharedBuffer"}, | 136 | {25, nullptr, "ReleaseLastForegroundCaptureSharedBuffer"}, |
| 118 | {26, nullptr, "AcquireCallerAppletCaptureSharedBuffer"}, | 137 | {26, nullptr, "AcquireCallerAppletCaptureSharedBuffer"}, |
| 119 | {27, nullptr, "ReleaseCallerAppletCaptureSharedBuffer"}, | 138 | {27, nullptr, "ReleaseCallerAppletCaptureSharedBuffer"}, |
| 139 | // 6.0.0+ | ||
| 140 | {28, nullptr, "TakeScreenShotOfOwnLayerEx"}, | ||
| 120 | }; | 141 | }; |
| 142 | // clang-format on | ||
| 143 | |||
| 121 | RegisterHandlers(functions); | 144 | RegisterHandlers(functions); |
| 122 | } | 145 | } |
| 123 | 146 | ||
| @@ -128,6 +151,7 @@ IDebugFunctions::~IDebugFunctions() = default; | |||
| 128 | 151 | ||
| 129 | ISelfController::ISelfController(std::shared_ptr<NVFlinger::NVFlinger> nvflinger) | 152 | ISelfController::ISelfController(std::shared_ptr<NVFlinger::NVFlinger> nvflinger) |
| 130 | : ServiceFramework("ISelfController"), nvflinger(std::move(nvflinger)) { | 153 | : ServiceFramework("ISelfController"), nvflinger(std::move(nvflinger)) { |
| 154 | // clang-format off | ||
| 131 | static const FunctionInfo functions[] = { | 155 | static const FunctionInfo functions[] = { |
| 132 | {0, nullptr, "Exit"}, | 156 | {0, nullptr, "Exit"}, |
| 133 | {1, &ISelfController::LockExit, "LockExit"}, | 157 | {1, &ISelfController::LockExit, "LockExit"}, |
| @@ -136,10 +160,8 @@ ISelfController::ISelfController(std::shared_ptr<NVFlinger::NVFlinger> nvflinger | |||
| 136 | {4, nullptr, "LeaveFatalSection"}, | 160 | {4, nullptr, "LeaveFatalSection"}, |
| 137 | {9, &ISelfController::GetLibraryAppletLaunchableEvent, "GetLibraryAppletLaunchableEvent"}, | 161 | {9, &ISelfController::GetLibraryAppletLaunchableEvent, "GetLibraryAppletLaunchableEvent"}, |
| 138 | {10, &ISelfController::SetScreenShotPermission, "SetScreenShotPermission"}, | 162 | {10, &ISelfController::SetScreenShotPermission, "SetScreenShotPermission"}, |
| 139 | {11, &ISelfController::SetOperationModeChangedNotification, | 163 | {11, &ISelfController::SetOperationModeChangedNotification, "SetOperationModeChangedNotification"}, |
| 140 | "SetOperationModeChangedNotification"}, | 164 | {12, &ISelfController::SetPerformanceModeChangedNotification, "SetPerformanceModeChangedNotification"}, |
| 141 | {12, &ISelfController::SetPerformanceModeChangedNotification, | ||
| 142 | "SetPerformanceModeChangedNotification"}, | ||
| 143 | {13, &ISelfController::SetFocusHandlingMode, "SetFocusHandlingMode"}, | 165 | {13, &ISelfController::SetFocusHandlingMode, "SetFocusHandlingMode"}, |
| 144 | {14, &ISelfController::SetRestartMessageEnabled, "SetRestartMessageEnabled"}, | 166 | {14, &ISelfController::SetRestartMessageEnabled, "SetRestartMessageEnabled"}, |
| 145 | {15, nullptr, "SetScreenShotAppletIdentityInfo"}, | 167 | {15, nullptr, "SetScreenShotAppletIdentityInfo"}, |
| @@ -165,7 +187,12 @@ ISelfController::ISelfController(std::shared_ptr<NVFlinger::NVFlinger> nvflinger | |||
| 165 | {69, nullptr, "IsAutoSleepDisabled"}, | 187 | {69, nullptr, "IsAutoSleepDisabled"}, |
| 166 | {70, nullptr, "ReportMultimediaError"}, | 188 | {70, nullptr, "ReportMultimediaError"}, |
| 167 | {80, nullptr, "SetWirelessPriorityMode"}, | 189 | {80, nullptr, "SetWirelessPriorityMode"}, |
| 190 | {90, nullptr, "GetAccumulatedSuspendedTickValue"}, | ||
| 191 | {91, nullptr, "GetAccumulatedSuspendedTickChangedEvent"}, | ||
| 192 | {1000, nullptr, "GetDebugStorageChannel"}, | ||
| 168 | }; | 193 | }; |
| 194 | // clang-format on | ||
| 195 | |||
| 169 | RegisterHandlers(functions); | 196 | RegisterHandlers(functions); |
| 170 | 197 | ||
| 171 | auto& kernel = Core::System::GetInstance().Kernel(); | 198 | auto& kernel = Core::System::GetInstance().Kernel(); |
| @@ -312,6 +339,7 @@ void ISelfController::GetIdleTimeDetectionExtension(Kernel::HLERequestContext& c | |||
| 312 | } | 339 | } |
| 313 | 340 | ||
| 314 | ICommonStateGetter::ICommonStateGetter() : ServiceFramework("ICommonStateGetter") { | 341 | ICommonStateGetter::ICommonStateGetter() : ServiceFramework("ICommonStateGetter") { |
| 342 | // clang-format off | ||
| 315 | static const FunctionInfo functions[] = { | 343 | static const FunctionInfo functions[] = { |
| 316 | {0, &ICommonStateGetter::GetEventHandle, "GetEventHandle"}, | 344 | {0, &ICommonStateGetter::GetEventHandle, "GetEventHandle"}, |
| 317 | {1, &ICommonStateGetter::ReceiveMessage, "ReceiveMessage"}, | 345 | {1, &ICommonStateGetter::ReceiveMessage, "ReceiveMessage"}, |
| @@ -336,11 +364,12 @@ ICommonStateGetter::ICommonStateGetter() : ServiceFramework("ICommonStateGetter" | |||
| 336 | {52, nullptr, "SwitchLcdBacklight"}, | 364 | {52, nullptr, "SwitchLcdBacklight"}, |
| 337 | {55, nullptr, "IsInControllerFirmwareUpdateSection"}, | 365 | {55, nullptr, "IsInControllerFirmwareUpdateSection"}, |
| 338 | {60, &ICommonStateGetter::GetDefaultDisplayResolution, "GetDefaultDisplayResolution"}, | 366 | {60, &ICommonStateGetter::GetDefaultDisplayResolution, "GetDefaultDisplayResolution"}, |
| 339 | {61, &ICommonStateGetter::GetDefaultDisplayResolutionChangeEvent, | 367 | {61, &ICommonStateGetter::GetDefaultDisplayResolutionChangeEvent, "GetDefaultDisplayResolutionChangeEvent"}, |
| 340 | "GetDefaultDisplayResolutionChangeEvent"}, | ||
| 341 | {62, nullptr, "GetHdcpAuthenticationState"}, | 368 | {62, nullptr, "GetHdcpAuthenticationState"}, |
| 342 | {63, nullptr, "GetHdcpAuthenticationStateChangeEvent"}, | 369 | {63, nullptr, "GetHdcpAuthenticationStateChangeEvent"}, |
| 343 | }; | 370 | }; |
| 371 | // clang-format on | ||
| 372 | |||
| 344 | RegisterHandlers(functions); | 373 | RegisterHandlers(functions); |
| 345 | 374 | ||
| 346 | auto& kernel = Core::System::GetInstance().Kernel(); | 375 | auto& kernel = Core::System::GetInstance().Kernel(); |
| @@ -432,11 +461,14 @@ class IStorageAccessor final : public ServiceFramework<IStorageAccessor> { | |||
| 432 | public: | 461 | public: |
| 433 | explicit IStorageAccessor(std::vector<u8> buffer) | 462 | explicit IStorageAccessor(std::vector<u8> buffer) |
| 434 | : ServiceFramework("IStorageAccessor"), buffer(std::move(buffer)) { | 463 | : ServiceFramework("IStorageAccessor"), buffer(std::move(buffer)) { |
| 464 | // clang-format off | ||
| 435 | static const FunctionInfo functions[] = { | 465 | static const FunctionInfo functions[] = { |
| 436 | {0, &IStorageAccessor::GetSize, "GetSize"}, | 466 | {0, &IStorageAccessor::GetSize, "GetSize"}, |
| 437 | {10, &IStorageAccessor::Write, "Write"}, | 467 | {10, &IStorageAccessor::Write, "Write"}, |
| 438 | {11, &IStorageAccessor::Read, "Read"}, | 468 | {11, &IStorageAccessor::Read, "Read"}, |
| 439 | }; | 469 | }; |
| 470 | // clang-format on | ||
| 471 | |||
| 440 | RegisterHandlers(functions); | 472 | RegisterHandlers(functions); |
| 441 | } | 473 | } |
| 442 | 474 | ||
| @@ -489,10 +521,13 @@ class IStorage final : public ServiceFramework<IStorage> { | |||
| 489 | public: | 521 | public: |
| 490 | explicit IStorage(std::vector<u8> buffer) | 522 | explicit IStorage(std::vector<u8> buffer) |
| 491 | : ServiceFramework("IStorage"), buffer(std::move(buffer)) { | 523 | : ServiceFramework("IStorage"), buffer(std::move(buffer)) { |
| 524 | // clang-format off | ||
| 492 | static const FunctionInfo functions[] = { | 525 | static const FunctionInfo functions[] = { |
| 493 | {0, &IStorage::Open, "Open"}, | 526 | {0, &IStorage::Open, "Open"}, |
| 494 | {1, nullptr, "OpenTransferStorage"}, | 527 | {1, nullptr, "OpenTransferStorage"}, |
| 495 | }; | 528 | }; |
| 529 | // clang-format on | ||
| 530 | |||
| 496 | RegisterHandlers(functions); | 531 | RegisterHandlers(functions); |
| 497 | } | 532 | } |
| 498 | 533 | ||
| @@ -512,6 +547,7 @@ private: | |||
| 512 | class ILibraryAppletAccessor final : public ServiceFramework<ILibraryAppletAccessor> { | 547 | class ILibraryAppletAccessor final : public ServiceFramework<ILibraryAppletAccessor> { |
| 513 | public: | 548 | public: |
| 514 | explicit ILibraryAppletAccessor() : ServiceFramework("ILibraryAppletAccessor") { | 549 | explicit ILibraryAppletAccessor() : ServiceFramework("ILibraryAppletAccessor") { |
| 550 | // clang-format off | ||
| 515 | static const FunctionInfo functions[] = { | 551 | static const FunctionInfo functions[] = { |
| 516 | {0, &ILibraryAppletAccessor::GetAppletStateChangedEvent, "GetAppletStateChangedEvent"}, | 552 | {0, &ILibraryAppletAccessor::GetAppletStateChangedEvent, "GetAppletStateChangedEvent"}, |
| 517 | {1, nullptr, "IsCompleted"}, | 553 | {1, nullptr, "IsCompleted"}, |
| @@ -532,6 +568,8 @@ public: | |||
| 532 | {150, nullptr, "RequestForAppletToGetForeground"}, | 568 | {150, nullptr, "RequestForAppletToGetForeground"}, |
| 533 | {160, nullptr, "GetIndirectLayerConsumerHandle"}, | 569 | {160, nullptr, "GetIndirectLayerConsumerHandle"}, |
| 534 | }; | 570 | }; |
| 571 | // clang-format on | ||
| 572 | |||
| 535 | RegisterHandlers(functions); | 573 | RegisterHandlers(functions); |
| 536 | 574 | ||
| 537 | auto& kernel = Core::System::GetInstance().Kernel(); | 575 | auto& kernel = Core::System::GetInstance().Kernel(); |
| @@ -624,13 +662,13 @@ void ILibraryAppletCreator::CreateStorage(Kernel::HLERequestContext& ctx) { | |||
| 624 | } | 662 | } |
| 625 | 663 | ||
| 626 | IApplicationFunctions::IApplicationFunctions() : ServiceFramework("IApplicationFunctions") { | 664 | IApplicationFunctions::IApplicationFunctions() : ServiceFramework("IApplicationFunctions") { |
| 665 | // clang-format off | ||
| 627 | static const FunctionInfo functions[] = { | 666 | static const FunctionInfo functions[] = { |
| 628 | {1, &IApplicationFunctions::PopLaunchParameter, "PopLaunchParameter"}, | 667 | {1, &IApplicationFunctions::PopLaunchParameter, "PopLaunchParameter"}, |
| 629 | {10, nullptr, "CreateApplicationAndPushAndRequestToStart"}, | 668 | {10, nullptr, "CreateApplicationAndPushAndRequestToStart"}, |
| 630 | {11, nullptr, "CreateApplicationAndPushAndRequestToStartForQuest"}, | 669 | {11, nullptr, "CreateApplicationAndPushAndRequestToStartForQuest"}, |
| 631 | {12, nullptr, "CreateApplicationAndRequestToStart"}, | 670 | {12, nullptr, "CreateApplicationAndRequestToStart"}, |
| 632 | {13, &IApplicationFunctions::CreateApplicationAndRequestToStartForQuest, | 671 | {13, &IApplicationFunctions::CreateApplicationAndRequestToStartForQuest, "CreateApplicationAndRequestToStartForQuest"}, |
| 633 | "CreateApplicationAndRequestToStartForQuest"}, | ||
| 634 | {20, &IApplicationFunctions::EnsureSaveData, "EnsureSaveData"}, | 672 | {20, &IApplicationFunctions::EnsureSaveData, "EnsureSaveData"}, |
| 635 | {21, &IApplicationFunctions::GetDesiredLanguage, "GetDesiredLanguage"}, | 673 | {21, &IApplicationFunctions::GetDesiredLanguage, "GetDesiredLanguage"}, |
| 636 | {22, &IApplicationFunctions::SetTerminateResult, "SetTerminateResult"}, | 674 | {22, &IApplicationFunctions::SetTerminateResult, "SetTerminateResult"}, |
| @@ -638,10 +676,8 @@ IApplicationFunctions::IApplicationFunctions() : ServiceFramework("IApplicationF | |||
| 638 | {24, nullptr, "GetLaunchStorageInfoForDebug"}, | 676 | {24, nullptr, "GetLaunchStorageInfoForDebug"}, |
| 639 | {25, nullptr, "ExtendSaveData"}, | 677 | {25, nullptr, "ExtendSaveData"}, |
| 640 | {26, nullptr, "GetSaveDataSize"}, | 678 | {26, nullptr, "GetSaveDataSize"}, |
| 641 | {30, &IApplicationFunctions::BeginBlockingHomeButtonShortAndLongPressed, | 679 | {30, &IApplicationFunctions::BeginBlockingHomeButtonShortAndLongPressed, "BeginBlockingHomeButtonShortAndLongPressed"}, |
| 642 | "BeginBlockingHomeButtonShortAndLongPressed"}, | 680 | {31, &IApplicationFunctions::EndBlockingHomeButtonShortAndLongPressed, "EndBlockingHomeButtonShortAndLongPressed"}, |
| 643 | {31, &IApplicationFunctions::EndBlockingHomeButtonShortAndLongPressed, | ||
| 644 | "EndBlockingHomeButtonShortAndLongPressed"}, | ||
| 645 | {32, &IApplicationFunctions::BeginBlockingHomeButton, "BeginBlockingHomeButton"}, | 681 | {32, &IApplicationFunctions::BeginBlockingHomeButton, "BeginBlockingHomeButton"}, |
| 646 | {33, &IApplicationFunctions::EndBlockingHomeButton, "EndBlockingHomeButton"}, | 682 | {33, &IApplicationFunctions::EndBlockingHomeButton, "EndBlockingHomeButton"}, |
| 647 | {40, &IApplicationFunctions::NotifyRunning, "NotifyRunning"}, | 683 | {40, &IApplicationFunctions::NotifyRunning, "NotifyRunning"}, |
| @@ -666,6 +702,8 @@ IApplicationFunctions::IApplicationFunctions() : ServiceFramework("IApplicationF | |||
| 666 | {1000, nullptr, "CreateMovieMaker"}, | 702 | {1000, nullptr, "CreateMovieMaker"}, |
| 667 | {1001, nullptr, "PrepareForJit"}, | 703 | {1001, nullptr, "PrepareForJit"}, |
| 668 | }; | 704 | }; |
| 705 | // clang-format on | ||
| 706 | |||
| 669 | RegisterHandlers(functions); | 707 | RegisterHandlers(functions); |
| 670 | } | 708 | } |
| 671 | 709 | ||
| @@ -698,20 +736,23 @@ void IApplicationFunctions::EndBlockingHomeButton(Kernel::HLERequestContext& ctx | |||
| 698 | } | 736 | } |
| 699 | 737 | ||
| 700 | void IApplicationFunctions::PopLaunchParameter(Kernel::HLERequestContext& ctx) { | 738 | void IApplicationFunctions::PopLaunchParameter(Kernel::HLERequestContext& ctx) { |
| 701 | constexpr std::array<u8, 0x88> data{{ | 739 | LaunchParameters params{}; |
| 702 | 0xca, 0x97, 0x94, 0xc7, // Magic | 740 | |
| 703 | 1, 0, 0, 0, // IsAccountSelected (bool) | 741 | params.magic = POP_LAUNCH_PARAMETER_MAGIC; |
| 704 | 1, 0, 0, 0, // User Id (word 0) | 742 | params.is_account_selected = 1; |
| 705 | 0, 0, 0, 0, // User Id (word 1) | ||
| 706 | 0, 0, 0, 0, // User Id (word 2) | ||
| 707 | 0, 0, 0, 0 // User Id (word 3) | ||
| 708 | }}; | ||
| 709 | 743 | ||
| 710 | std::vector<u8> buffer(data.begin(), data.end()); | 744 | Account::ProfileManager profile_manager{}; |
| 745 | const auto uuid = profile_manager.GetUser(Settings::values.current_user); | ||
| 746 | ASSERT(uuid != std::nullopt); | ||
| 747 | params.current_user = uuid->uuid; | ||
| 711 | 748 | ||
| 712 | IPC::ResponseBuilder rb{ctx, 2, 0, 1}; | 749 | IPC::ResponseBuilder rb{ctx, 2, 0, 1}; |
| 713 | 750 | ||
| 714 | rb.Push(RESULT_SUCCESS); | 751 | rb.Push(RESULT_SUCCESS); |
| 752 | |||
| 753 | std::vector<u8> buffer(sizeof(LaunchParameters)); | ||
| 754 | std::memcpy(buffer.data(), ¶ms, buffer.size()); | ||
| 755 | |||
| 715 | rb.PushIpcInterface<AM::IStorage>(buffer); | 756 | rb.PushIpcInterface<AM::IStorage>(buffer); |
| 716 | 757 | ||
| 717 | LOG_DEBUG(Service_AM, "called"); | 758 | LOG_DEBUG(Service_AM, "called"); |
| @@ -804,9 +845,11 @@ void InstallInterfaces(SM::ServiceManager& service_manager, | |||
| 804 | std::make_shared<IdleSys>()->InstallAsService(service_manager); | 845 | std::make_shared<IdleSys>()->InstallAsService(service_manager); |
| 805 | std::make_shared<OMM>()->InstallAsService(service_manager); | 846 | std::make_shared<OMM>()->InstallAsService(service_manager); |
| 806 | std::make_shared<SPSM>()->InstallAsService(service_manager); | 847 | std::make_shared<SPSM>()->InstallAsService(service_manager); |
| 848 | std::make_shared<TCAP>()->InstallAsService(service_manager); | ||
| 807 | } | 849 | } |
| 808 | 850 | ||
| 809 | IHomeMenuFunctions::IHomeMenuFunctions() : ServiceFramework("IHomeMenuFunctions") { | 851 | IHomeMenuFunctions::IHomeMenuFunctions() : ServiceFramework("IHomeMenuFunctions") { |
| 852 | // clang-format off | ||
| 810 | static const FunctionInfo functions[] = { | 853 | static const FunctionInfo functions[] = { |
| 811 | {10, &IHomeMenuFunctions::RequestToGetForeground, "RequestToGetForeground"}, | 854 | {10, &IHomeMenuFunctions::RequestToGetForeground, "RequestToGetForeground"}, |
| 812 | {11, nullptr, "LockForeground"}, | 855 | {11, nullptr, "LockForeground"}, |
| @@ -815,7 +858,10 @@ IHomeMenuFunctions::IHomeMenuFunctions() : ServiceFramework("IHomeMenuFunctions" | |||
| 815 | {21, nullptr, "GetPopFromGeneralChannelEvent"}, | 858 | {21, nullptr, "GetPopFromGeneralChannelEvent"}, |
| 816 | {30, nullptr, "GetHomeButtonWriterLockAccessor"}, | 859 | {30, nullptr, "GetHomeButtonWriterLockAccessor"}, |
| 817 | {31, nullptr, "GetWriterLockAccessorEx"}, | 860 | {31, nullptr, "GetWriterLockAccessorEx"}, |
| 861 | {100, nullptr, "PopRequestLaunchApplicationForDebug"}, | ||
| 818 | }; | 862 | }; |
| 863 | // clang-format on | ||
| 864 | |||
| 819 | RegisterHandlers(functions); | 865 | RegisterHandlers(functions); |
| 820 | } | 866 | } |
| 821 | 867 | ||
| @@ -828,6 +874,7 @@ void IHomeMenuFunctions::RequestToGetForeground(Kernel::HLERequestContext& ctx) | |||
| 828 | } | 874 | } |
| 829 | 875 | ||
| 830 | IGlobalStateController::IGlobalStateController() : ServiceFramework("IGlobalStateController") { | 876 | IGlobalStateController::IGlobalStateController() : ServiceFramework("IGlobalStateController") { |
| 877 | // clang-format off | ||
| 831 | static const FunctionInfo functions[] = { | 878 | static const FunctionInfo functions[] = { |
| 832 | {0, nullptr, "RequestToEnterSleep"}, | 879 | {0, nullptr, "RequestToEnterSleep"}, |
| 833 | {1, nullptr, "EnterSleep"}, | 880 | {1, nullptr, "EnterSleep"}, |
| @@ -841,18 +888,23 @@ IGlobalStateController::IGlobalStateController() : ServiceFramework("IGlobalStat | |||
| 841 | {14, nullptr, "ShouldSleepOnBoot"}, | 888 | {14, nullptr, "ShouldSleepOnBoot"}, |
| 842 | {15, nullptr, "GetHdcpAuthenticationFailedEvent"}, | 889 | {15, nullptr, "GetHdcpAuthenticationFailedEvent"}, |
| 843 | }; | 890 | }; |
| 891 | // clang-format on | ||
| 892 | |||
| 844 | RegisterHandlers(functions); | 893 | RegisterHandlers(functions); |
| 845 | } | 894 | } |
| 846 | 895 | ||
| 847 | IGlobalStateController::~IGlobalStateController() = default; | 896 | IGlobalStateController::~IGlobalStateController() = default; |
| 848 | 897 | ||
| 849 | IApplicationCreator::IApplicationCreator() : ServiceFramework("IApplicationCreator") { | 898 | IApplicationCreator::IApplicationCreator() : ServiceFramework("IApplicationCreator") { |
| 899 | // clang-format off | ||
| 850 | static const FunctionInfo functions[] = { | 900 | static const FunctionInfo functions[] = { |
| 851 | {0, nullptr, "CreateApplication"}, | 901 | {0, nullptr, "CreateApplication"}, |
| 852 | {1, nullptr, "PopLaunchRequestedApplication"}, | 902 | {1, nullptr, "PopLaunchRequestedApplication"}, |
| 853 | {10, nullptr, "CreateSystemApplication"}, | 903 | {10, nullptr, "CreateSystemApplication"}, |
| 854 | {100, nullptr, "PopFloatingApplicationForDevelopment"}, | 904 | {100, nullptr, "PopFloatingApplicationForDevelopment"}, |
| 855 | }; | 905 | }; |
| 906 | // clang-format on | ||
| 907 | |||
| 856 | RegisterHandlers(functions); | 908 | RegisterHandlers(functions); |
| 857 | } | 909 | } |
| 858 | 910 | ||
| @@ -860,6 +912,7 @@ IApplicationCreator::~IApplicationCreator() = default; | |||
| 860 | 912 | ||
| 861 | IProcessWindingController::IProcessWindingController() | 913 | IProcessWindingController::IProcessWindingController() |
| 862 | : ServiceFramework("IProcessWindingController") { | 914 | : ServiceFramework("IProcessWindingController") { |
| 915 | // clang-format off | ||
| 863 | static const FunctionInfo functions[] = { | 916 | static const FunctionInfo functions[] = { |
| 864 | {0, nullptr, "GetLaunchReason"}, | 917 | {0, nullptr, "GetLaunchReason"}, |
| 865 | {11, nullptr, "OpenCallingLibraryApplet"}, | 918 | {11, nullptr, "OpenCallingLibraryApplet"}, |
| @@ -870,6 +923,8 @@ IProcessWindingController::IProcessWindingController() | |||
| 870 | {40, nullptr, "ReserveToStartAndWaitAndUnwindThis"}, | 923 | {40, nullptr, "ReserveToStartAndWaitAndUnwindThis"}, |
| 871 | {41, nullptr, "ReserveToStartAndWait"}, | 924 | {41, nullptr, "ReserveToStartAndWait"}, |
| 872 | }; | 925 | }; |
| 926 | // clang-format on | ||
| 927 | |||
| 873 | RegisterHandlers(functions); | 928 | RegisterHandlers(functions); |
| 874 | } | 929 | } |
| 875 | 930 | ||
diff --git a/src/core/hle/service/am/applet_ae.cpp b/src/core/hle/service/am/applet_ae.cpp index 4296c255e..68ea778e8 100644 --- a/src/core/hle/service/am/applet_ae.cpp +++ b/src/core/hle/service/am/applet_ae.cpp | |||
| @@ -211,6 +211,7 @@ void AppletAE::OpenLibraryAppletProxyOld(Kernel::HLERequestContext& ctx) { | |||
| 211 | 211 | ||
| 212 | AppletAE::AppletAE(std::shared_ptr<NVFlinger::NVFlinger> nvflinger) | 212 | AppletAE::AppletAE(std::shared_ptr<NVFlinger::NVFlinger> nvflinger) |
| 213 | : ServiceFramework("appletAE"), nvflinger(std::move(nvflinger)) { | 213 | : ServiceFramework("appletAE"), nvflinger(std::move(nvflinger)) { |
| 214 | // clang-format off | ||
| 214 | static const FunctionInfo functions[] = { | 215 | static const FunctionInfo functions[] = { |
| 215 | {100, &AppletAE::OpenSystemAppletProxy, "OpenSystemAppletProxy"}, | 216 | {100, &AppletAE::OpenSystemAppletProxy, "OpenSystemAppletProxy"}, |
| 216 | {200, &AppletAE::OpenLibraryAppletProxyOld, "OpenLibraryAppletProxyOld"}, | 217 | {200, &AppletAE::OpenLibraryAppletProxyOld, "OpenLibraryAppletProxyOld"}, |
| @@ -218,7 +219,10 @@ AppletAE::AppletAE(std::shared_ptr<NVFlinger::NVFlinger> nvflinger) | |||
| 218 | {300, nullptr, "OpenOverlayAppletProxy"}, | 219 | {300, nullptr, "OpenOverlayAppletProxy"}, |
| 219 | {350, nullptr, "OpenSystemApplicationProxy"}, | 220 | {350, nullptr, "OpenSystemApplicationProxy"}, |
| 220 | {400, nullptr, "CreateSelfLibraryAppletCreatorForDevelop"}, | 221 | {400, nullptr, "CreateSelfLibraryAppletCreatorForDevelop"}, |
| 222 | {401, nullptr, "GetSystemAppletControllerForDebug"}, | ||
| 221 | }; | 223 | }; |
| 224 | // clang-format on | ||
| 225 | |||
| 222 | RegisterHandlers(functions); | 226 | RegisterHandlers(functions); |
| 223 | } | 227 | } |
| 224 | 228 | ||
diff --git a/src/core/hle/service/am/applet_oe.cpp b/src/core/hle/service/am/applet_oe.cpp index e45cf6e20..60717afd9 100644 --- a/src/core/hle/service/am/applet_oe.cpp +++ b/src/core/hle/service/am/applet_oe.cpp | |||
| @@ -14,6 +14,7 @@ class IApplicationProxy final : public ServiceFramework<IApplicationProxy> { | |||
| 14 | public: | 14 | public: |
| 15 | explicit IApplicationProxy(std::shared_ptr<NVFlinger::NVFlinger> nvflinger) | 15 | explicit IApplicationProxy(std::shared_ptr<NVFlinger::NVFlinger> nvflinger) |
| 16 | : ServiceFramework("IApplicationProxy"), nvflinger(std::move(nvflinger)) { | 16 | : ServiceFramework("IApplicationProxy"), nvflinger(std::move(nvflinger)) { |
| 17 | // clang-format off | ||
| 17 | static const FunctionInfo functions[] = { | 18 | static const FunctionInfo functions[] = { |
| 18 | {0, &IApplicationProxy::GetCommonStateGetter, "GetCommonStateGetter"}, | 19 | {0, &IApplicationProxy::GetCommonStateGetter, "GetCommonStateGetter"}, |
| 19 | {1, &IApplicationProxy::GetSelfController, "GetSelfController"}, | 20 | {1, &IApplicationProxy::GetSelfController, "GetSelfController"}, |
| @@ -25,6 +26,8 @@ public: | |||
| 25 | {20, &IApplicationProxy::GetApplicationFunctions, "GetApplicationFunctions"}, | 26 | {20, &IApplicationProxy::GetApplicationFunctions, "GetApplicationFunctions"}, |
| 26 | {1000, &IApplicationProxy::GetDebugFunctions, "GetDebugFunctions"}, | 27 | {1000, &IApplicationProxy::GetDebugFunctions, "GetDebugFunctions"}, |
| 27 | }; | 28 | }; |
| 29 | // clang-format on | ||
| 30 | |||
| 28 | RegisterHandlers(functions); | 31 | RegisterHandlers(functions); |
| 29 | } | 32 | } |
| 30 | 33 | ||
diff --git a/src/core/hle/service/am/idle.cpp b/src/core/hle/service/am/idle.cpp index 0e3088bc8..f814fe2c0 100644 --- a/src/core/hle/service/am/idle.cpp +++ b/src/core/hle/service/am/idle.cpp | |||
| @@ -12,9 +12,9 @@ IdleSys::IdleSys() : ServiceFramework{"idle:sys"} { | |||
| 12 | {0, nullptr, "GetAutoPowerDownEvent"}, | 12 | {0, nullptr, "GetAutoPowerDownEvent"}, |
| 13 | {1, nullptr, "Unknown1"}, | 13 | {1, nullptr, "Unknown1"}, |
| 14 | {2, nullptr, "Unknown2"}, | 14 | {2, nullptr, "Unknown2"}, |
| 15 | {3, nullptr, "Unknown3"}, | 15 | {3, nullptr, "SetHandlingContext"}, |
| 16 | {4, nullptr, "Unknown4"}, | 16 | {4, nullptr, "LoadAndApplySettings"}, |
| 17 | {5, nullptr, "Unknown5"}, | 17 | {5, nullptr, "ReportUserIsActive"}, |
| 18 | }; | 18 | }; |
| 19 | // clang-format on | 19 | // clang-format on |
| 20 | 20 | ||
diff --git a/src/core/hle/service/am/omm.cpp b/src/core/hle/service/am/omm.cpp index 1c37f849f..6ab3fb906 100644 --- a/src/core/hle/service/am/omm.cpp +++ b/src/core/hle/service/am/omm.cpp | |||
| @@ -17,22 +17,24 @@ OMM::OMM() : ServiceFramework{"omm"} { | |||
| 17 | {5, nullptr, "GetCradleStatus"}, | 17 | {5, nullptr, "GetCradleStatus"}, |
| 18 | {6, nullptr, "FadeInDisplay"}, | 18 | {6, nullptr, "FadeInDisplay"}, |
| 19 | {7, nullptr, "FadeOutDisplay"}, | 19 | {7, nullptr, "FadeOutDisplay"}, |
| 20 | {8, nullptr, "Unknown1"}, | 20 | {8, nullptr, "GetCradleFwVersion"}, |
| 21 | {9, nullptr, "Unknown2"}, | 21 | {9, nullptr, "NotifyCecSettingsChanged"}, |
| 22 | {10, nullptr, "Unknown3"}, | 22 | {10, nullptr, "SetOperationModePolicy"}, |
| 23 | {11, nullptr, "Unknown4"}, | 23 | {11, nullptr, "GetDefaultDisplayResolution"}, |
| 24 | {12, nullptr, "Unknown5"}, | 24 | {12, nullptr, "GetDefaultDisplayResolutionChangeEvent"}, |
| 25 | {13, nullptr, "Unknown6"}, | 25 | {13, nullptr, "UpdateDefaultDisplayResolution"}, |
| 26 | {14, nullptr, "Unknown7"}, | 26 | {14, nullptr, "ShouldSleepOnBoot"}, |
| 27 | {15, nullptr, "Unknown8"}, | 27 | {15, nullptr, "NotifyHdcpApplicationExecutionStarted"}, |
| 28 | {16, nullptr, "Unknown9"}, | 28 | {16, nullptr, "NotifyHdcpApplicationExecutionFinished"}, |
| 29 | {17, nullptr, "Unknown10"}, | 29 | {17, nullptr, "NotifyHdcpApplicationDrawingStarted"}, |
| 30 | {18, nullptr, "Unknown11"}, | 30 | {18, nullptr, "NotifyHdcpApplicationDrawingFinished"}, |
| 31 | {19, nullptr, "Unknown12"}, | 31 | {19, nullptr, "GetHdcpAuthenticationFailedEvent"}, |
| 32 | {20, nullptr, "Unknown13"}, | 32 | {20, nullptr, "GetHdcpAuthenticationFailedEmulationEnabled"}, |
| 33 | {21, nullptr, "Unknown14"}, | 33 | {21, nullptr, "SetHdcpAuthenticationFailedEmulation"}, |
| 34 | {22, nullptr, "Unknown15"}, | 34 | {22, nullptr, "GetHdcpStateChangeEvent"}, |
| 35 | {23, nullptr, "Unknown16"}, | 35 | {23, nullptr, "GetHdcpState"}, |
| 36 | {24, nullptr, "ShowCardUpdateProcessing"}, | ||
| 37 | {25, nullptr, "SetApplicationCecSettingsAndNotifyChanged"}, | ||
| 36 | }; | 38 | }; |
| 37 | // clang-format on | 39 | // clang-format on |
| 38 | 40 | ||
diff --git a/src/core/hle/service/am/tcap.cpp b/src/core/hle/service/am/tcap.cpp new file mode 100644 index 000000000..a75cbdda8 --- /dev/null +++ b/src/core/hle/service/am/tcap.cpp | |||
| @@ -0,0 +1,23 @@ | |||
| 1 | // Copyright 2018 yuzu emulator team | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include "core/hle/service/am/tcap.h" | ||
| 6 | |||
| 7 | namespace Service::AM { | ||
| 8 | |||
| 9 | TCAP::TCAP() : ServiceFramework{"tcap"} { | ||
| 10 | // clang-format off | ||
| 11 | static const FunctionInfo functions[] = { | ||
| 12 | {0, nullptr, "GetContinuousHighSkinTemperatureEvent"}, | ||
| 13 | {1, nullptr, "SetOperationMode"}, | ||
| 14 | {2, nullptr, "LoadAndApplySettings"}, | ||
| 15 | }; | ||
| 16 | // clang-format on | ||
| 17 | |||
| 18 | RegisterHandlers(functions); | ||
| 19 | } | ||
| 20 | |||
| 21 | TCAP::~TCAP() = default; | ||
| 22 | |||
| 23 | } // namespace Service::AM | ||
diff --git a/src/core/hle/service/am/tcap.h b/src/core/hle/service/am/tcap.h new file mode 100644 index 000000000..2021b55d1 --- /dev/null +++ b/src/core/hle/service/am/tcap.h | |||
| @@ -0,0 +1,17 @@ | |||
| 1 | // Copyright 2018 yuzu emulator team | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include "core/hle/service/service.h" | ||
| 8 | |||
| 9 | namespace Service::AM { | ||
| 10 | |||
| 11 | class TCAP final : public ServiceFramework<TCAP> { | ||
| 12 | public: | ||
| 13 | explicit TCAP(); | ||
| 14 | ~TCAP() override; | ||
| 15 | }; | ||
| 16 | |||
| 17 | } // namespace Service::AM | ||
diff --git a/src/core/hle/service/aoc/aoc_u.cpp b/src/core/hle/service/aoc/aoc_u.cpp index 518161bf7..54305cf05 100644 --- a/src/core/hle/service/aoc/aoc_u.cpp +++ b/src/core/hle/service/aoc/aoc_u.cpp | |||
| @@ -13,6 +13,7 @@ | |||
| 13 | #include "core/file_sys/patch_manager.h" | 13 | #include "core/file_sys/patch_manager.h" |
| 14 | #include "core/file_sys/registered_cache.h" | 14 | #include "core/file_sys/registered_cache.h" |
| 15 | #include "core/hle/ipc_helpers.h" | 15 | #include "core/hle/ipc_helpers.h" |
| 16 | #include "core/hle/kernel/event.h" | ||
| 16 | #include "core/hle/kernel/process.h" | 17 | #include "core/hle/kernel/process.h" |
| 17 | #include "core/hle/service/aoc/aoc_u.h" | 18 | #include "core/hle/service/aoc/aoc_u.h" |
| 18 | #include "core/hle/service/filesystem/filesystem.h" | 19 | #include "core/hle/service/filesystem/filesystem.h" |
| @@ -23,8 +24,8 @@ namespace Service::AOC { | |||
| 23 | constexpr u64 DLC_BASE_TITLE_ID_MASK = 0xFFFFFFFFFFFFE000; | 24 | constexpr u64 DLC_BASE_TITLE_ID_MASK = 0xFFFFFFFFFFFFE000; |
| 24 | constexpr u64 DLC_BASE_TO_AOC_ID = 0x1000; | 25 | constexpr u64 DLC_BASE_TO_AOC_ID = 0x1000; |
| 25 | 26 | ||
| 26 | static bool CheckAOCTitleIDMatchesBase(u64 base, u64 aoc) { | 27 | static bool CheckAOCTitleIDMatchesBase(u64 title_id, u64 base) { |
| 27 | return (aoc & DLC_BASE_TITLE_ID_MASK) == base; | 28 | return (title_id & DLC_BASE_TITLE_ID_MASK) == base; |
| 28 | } | 29 | } |
| 29 | 30 | ||
| 30 | static std::vector<u64> AccumulateAOCTitleIDs() { | 31 | static std::vector<u64> AccumulateAOCTitleIDs() { |
| @@ -55,9 +56,13 @@ AOC_U::AOC_U() : ServiceFramework("aoc:u"), add_on_content(AccumulateAOCTitleIDs | |||
| 55 | {5, &AOC_U::GetAddOnContentBaseId, "GetAddOnContentBaseId"}, | 56 | {5, &AOC_U::GetAddOnContentBaseId, "GetAddOnContentBaseId"}, |
| 56 | {6, nullptr, "PrepareAddOnContentByApplicationId"}, | 57 | {6, nullptr, "PrepareAddOnContentByApplicationId"}, |
| 57 | {7, &AOC_U::PrepareAddOnContent, "PrepareAddOnContent"}, | 58 | {7, &AOC_U::PrepareAddOnContent, "PrepareAddOnContent"}, |
| 58 | {8, nullptr, "GetAddOnContentListChangedEvent"}, | 59 | {8, &AOC_U::GetAddOnContentListChangedEvent, "GetAddOnContentListChangedEvent"}, |
| 59 | }; | 60 | }; |
| 60 | RegisterHandlers(functions); | 61 | RegisterHandlers(functions); |
| 62 | |||
| 63 | auto& kernel = Core::System::GetInstance().Kernel(); | ||
| 64 | aoc_change_event = Kernel::Event::Create(kernel, Kernel::ResetType::Sticky, | ||
| 65 | "GetAddOnContentListChanged:Event"); | ||
| 61 | } | 66 | } |
| 62 | 67 | ||
| 63 | AOC_U::~AOC_U() = default; | 68 | AOC_U::~AOC_U() = default; |
| @@ -69,7 +74,7 @@ void AOC_U::CountAddOnContent(Kernel::HLERequestContext& ctx) { | |||
| 69 | const auto current = Core::System::GetInstance().CurrentProcess()->GetTitleID(); | 74 | const auto current = Core::System::GetInstance().CurrentProcess()->GetTitleID(); |
| 70 | rb.Push<u32>(static_cast<u32>( | 75 | rb.Push<u32>(static_cast<u32>( |
| 71 | std::count_if(add_on_content.begin(), add_on_content.end(), | 76 | std::count_if(add_on_content.begin(), add_on_content.end(), |
| 72 | [¤t](u64 tid) { return (tid & DLC_BASE_TITLE_ID_MASK) == current; }))); | 77 | [current](u64 tid) { return CheckAOCTitleIDMatchesBase(tid, current); }))); |
| 73 | } | 78 | } |
| 74 | 79 | ||
| 75 | void AOC_U::ListAddOnContent(Kernel::HLERequestContext& ctx) { | 80 | void AOC_U::ListAddOnContent(Kernel::HLERequestContext& ctx) { |
| @@ -130,6 +135,14 @@ void AOC_U::PrepareAddOnContent(Kernel::HLERequestContext& ctx) { | |||
| 130 | rb.Push(RESULT_SUCCESS); | 135 | rb.Push(RESULT_SUCCESS); |
| 131 | } | 136 | } |
| 132 | 137 | ||
| 138 | void AOC_U::GetAddOnContentListChangedEvent(Kernel::HLERequestContext& ctx) { | ||
| 139 | LOG_WARNING(Service_AOC, "(STUBBED) called"); | ||
| 140 | |||
| 141 | IPC::ResponseBuilder rb{ctx, 2, 1}; | ||
| 142 | rb.Push(RESULT_SUCCESS); | ||
| 143 | rb.PushCopyObjects(aoc_change_event); | ||
| 144 | } | ||
| 145 | |||
| 133 | void InstallInterfaces(SM::ServiceManager& service_manager) { | 146 | void InstallInterfaces(SM::ServiceManager& service_manager) { |
| 134 | std::make_shared<AOC_U>()->InstallAsService(service_manager); | 147 | std::make_shared<AOC_U>()->InstallAsService(service_manager); |
| 135 | } | 148 | } |
diff --git a/src/core/hle/service/aoc/aoc_u.h b/src/core/hle/service/aoc/aoc_u.h index b3c7cab7a..68d94fdaa 100644 --- a/src/core/hle/service/aoc/aoc_u.h +++ b/src/core/hle/service/aoc/aoc_u.h | |||
| @@ -18,8 +18,10 @@ private: | |||
| 18 | void ListAddOnContent(Kernel::HLERequestContext& ctx); | 18 | void ListAddOnContent(Kernel::HLERequestContext& ctx); |
| 19 | void GetAddOnContentBaseId(Kernel::HLERequestContext& ctx); | 19 | void GetAddOnContentBaseId(Kernel::HLERequestContext& ctx); |
| 20 | void PrepareAddOnContent(Kernel::HLERequestContext& ctx); | 20 | void PrepareAddOnContent(Kernel::HLERequestContext& ctx); |
| 21 | void GetAddOnContentListChangedEvent(Kernel::HLERequestContext& ctx); | ||
| 21 | 22 | ||
| 22 | std::vector<u64> add_on_content; | 23 | std::vector<u64> add_on_content; |
| 24 | Kernel::SharedPtr<Kernel::Event> aoc_change_event; | ||
| 23 | }; | 25 | }; |
| 24 | 26 | ||
| 25 | /// Registers all AOC services with the specified service manager. | 27 | /// Registers all AOC services with the specified service manager. |
diff --git a/src/core/hle/service/audio/audren_u.cpp b/src/core/hle/service/audio/audren_u.cpp index 6073f4ecd..fac6785a5 100644 --- a/src/core/hle/service/audio/audren_u.cpp +++ b/src/core/hle/service/audio/audren_u.cpp | |||
| @@ -22,20 +22,22 @@ class IAudioRenderer final : public ServiceFramework<IAudioRenderer> { | |||
| 22 | public: | 22 | public: |
| 23 | explicit IAudioRenderer(AudioCore::AudioRendererParameter audren_params) | 23 | explicit IAudioRenderer(AudioCore::AudioRendererParameter audren_params) |
| 24 | : ServiceFramework("IAudioRenderer") { | 24 | : ServiceFramework("IAudioRenderer") { |
| 25 | // clang-format off | ||
| 25 | static const FunctionInfo functions[] = { | 26 | static const FunctionInfo functions[] = { |
| 26 | {0, &IAudioRenderer::GetAudioRendererSampleRate, "GetAudioRendererSampleRate"}, | 27 | {0, &IAudioRenderer::GetSampleRate, "GetSampleRate"}, |
| 27 | {1, &IAudioRenderer::GetAudioRendererSampleCount, "GetAudioRendererSampleCount"}, | 28 | {1, &IAudioRenderer::GetSampleCount, "GetSampleCount"}, |
| 28 | {2, &IAudioRenderer::GetAudioRendererMixBufferCount, "GetAudioRendererMixBufferCount"}, | 29 | {2, &IAudioRenderer::GetMixBufferCount, "GetMixBufferCount"}, |
| 29 | {3, &IAudioRenderer::GetAudioRendererState, "GetAudioRendererState"}, | 30 | {3, &IAudioRenderer::GetState, "GetState"}, |
| 30 | {4, &IAudioRenderer::RequestUpdateAudioRenderer, "RequestUpdateAudioRenderer"}, | 31 | {4, &IAudioRenderer::RequestUpdate, "RequestUpdate"}, |
| 31 | {5, &IAudioRenderer::StartAudioRenderer, "StartAudioRenderer"}, | 32 | {5, &IAudioRenderer::Start, "Start"}, |
| 32 | {6, &IAudioRenderer::StopAudioRenderer, "StopAudioRenderer"}, | 33 | {6, &IAudioRenderer::Stop, "Stop"}, |
| 33 | {7, &IAudioRenderer::QuerySystemEvent, "QuerySystemEvent"}, | 34 | {7, &IAudioRenderer::QuerySystemEvent, "QuerySystemEvent"}, |
| 34 | {8, nullptr, "SetAudioRendererRenderingTimeLimit"}, | 35 | {8, nullptr, "SetRenderingTimeLimit"}, |
| 35 | {9, nullptr, "GetAudioRendererRenderingTimeLimit"}, | 36 | {9, nullptr, "GetRenderingTimeLimit"}, |
| 36 | {10, nullptr, "RequestUpdateAudioRendererAuto"}, | 37 | {10, nullptr, "RequestUpdateAuto"}, |
| 37 | {11, nullptr, "ExecuteAudioRendererRendering"}, | 38 | {11, nullptr, "ExecuteAudioRendererRendering"}, |
| 38 | }; | 39 | }; |
| 40 | // clang-format on | ||
| 39 | RegisterHandlers(functions); | 41 | RegisterHandlers(functions); |
| 40 | 42 | ||
| 41 | auto& kernel = Core::System::GetInstance().Kernel(); | 43 | auto& kernel = Core::System::GetInstance().Kernel(); |
| @@ -49,42 +51,42 @@ private: | |||
| 49 | system_event->Signal(); | 51 | system_event->Signal(); |
| 50 | } | 52 | } |
| 51 | 53 | ||
| 52 | void GetAudioRendererSampleRate(Kernel::HLERequestContext& ctx) { | 54 | void GetSampleRate(Kernel::HLERequestContext& ctx) { |
| 53 | IPC::ResponseBuilder rb{ctx, 3}; | 55 | IPC::ResponseBuilder rb{ctx, 3}; |
| 54 | rb.Push(RESULT_SUCCESS); | 56 | rb.Push(RESULT_SUCCESS); |
| 55 | rb.Push<u32>(renderer->GetSampleRate()); | 57 | rb.Push<u32>(renderer->GetSampleRate()); |
| 56 | LOG_DEBUG(Service_Audio, "called"); | 58 | LOG_DEBUG(Service_Audio, "called"); |
| 57 | } | 59 | } |
| 58 | 60 | ||
| 59 | void GetAudioRendererSampleCount(Kernel::HLERequestContext& ctx) { | 61 | void GetSampleCount(Kernel::HLERequestContext& ctx) { |
| 60 | IPC::ResponseBuilder rb{ctx, 3}; | 62 | IPC::ResponseBuilder rb{ctx, 3}; |
| 61 | rb.Push(RESULT_SUCCESS); | 63 | rb.Push(RESULT_SUCCESS); |
| 62 | rb.Push<u32>(renderer->GetSampleCount()); | 64 | rb.Push<u32>(renderer->GetSampleCount()); |
| 63 | LOG_DEBUG(Service_Audio, "called"); | 65 | LOG_DEBUG(Service_Audio, "called"); |
| 64 | } | 66 | } |
| 65 | 67 | ||
| 66 | void GetAudioRendererState(Kernel::HLERequestContext& ctx) { | 68 | void GetState(Kernel::HLERequestContext& ctx) { |
| 67 | IPC::ResponseBuilder rb{ctx, 3}; | 69 | IPC::ResponseBuilder rb{ctx, 3}; |
| 68 | rb.Push(RESULT_SUCCESS); | 70 | rb.Push(RESULT_SUCCESS); |
| 69 | rb.Push<u32>(static_cast<u32>(renderer->GetStreamState())); | 71 | rb.Push<u32>(static_cast<u32>(renderer->GetStreamState())); |
| 70 | LOG_DEBUG(Service_Audio, "called"); | 72 | LOG_DEBUG(Service_Audio, "called"); |
| 71 | } | 73 | } |
| 72 | 74 | ||
| 73 | void GetAudioRendererMixBufferCount(Kernel::HLERequestContext& ctx) { | 75 | void GetMixBufferCount(Kernel::HLERequestContext& ctx) { |
| 74 | IPC::ResponseBuilder rb{ctx, 3}; | 76 | IPC::ResponseBuilder rb{ctx, 3}; |
| 75 | rb.Push(RESULT_SUCCESS); | 77 | rb.Push(RESULT_SUCCESS); |
| 76 | rb.Push<u32>(renderer->GetMixBufferCount()); | 78 | rb.Push<u32>(renderer->GetMixBufferCount()); |
| 77 | LOG_DEBUG(Service_Audio, "called"); | 79 | LOG_DEBUG(Service_Audio, "called"); |
| 78 | } | 80 | } |
| 79 | 81 | ||
| 80 | void RequestUpdateAudioRenderer(Kernel::HLERequestContext& ctx) { | 82 | void RequestUpdate(Kernel::HLERequestContext& ctx) { |
| 81 | ctx.WriteBuffer(renderer->UpdateAudioRenderer(ctx.ReadBuffer())); | 83 | ctx.WriteBuffer(renderer->UpdateAudioRenderer(ctx.ReadBuffer())); |
| 82 | IPC::ResponseBuilder rb{ctx, 2}; | 84 | IPC::ResponseBuilder rb{ctx, 2}; |
| 83 | rb.Push(RESULT_SUCCESS); | 85 | rb.Push(RESULT_SUCCESS); |
| 84 | LOG_WARNING(Service_Audio, "(STUBBED) called"); | 86 | LOG_WARNING(Service_Audio, "(STUBBED) called"); |
| 85 | } | 87 | } |
| 86 | 88 | ||
| 87 | void StartAudioRenderer(Kernel::HLERequestContext& ctx) { | 89 | void Start(Kernel::HLERequestContext& ctx) { |
| 88 | IPC::ResponseBuilder rb{ctx, 2}; | 90 | IPC::ResponseBuilder rb{ctx, 2}; |
| 89 | 91 | ||
| 90 | rb.Push(RESULT_SUCCESS); | 92 | rb.Push(RESULT_SUCCESS); |
| @@ -92,7 +94,7 @@ private: | |||
| 92 | LOG_WARNING(Service_Audio, "(STUBBED) called"); | 94 | LOG_WARNING(Service_Audio, "(STUBBED) called"); |
| 93 | } | 95 | } |
| 94 | 96 | ||
| 95 | void StopAudioRenderer(Kernel::HLERequestContext& ctx) { | 97 | void Stop(Kernel::HLERequestContext& ctx) { |
| 96 | IPC::ResponseBuilder rb{ctx, 2}; | 98 | IPC::ResponseBuilder rb{ctx, 2}; |
| 97 | 99 | ||
| 98 | rb.Push(RESULT_SUCCESS); | 100 | rb.Push(RESULT_SUCCESS); |
| @@ -129,6 +131,7 @@ public: | |||
| 129 | {10, &IAudioDevice::GetActiveAudioDeviceName, "GetActiveAudioDeviceNameAuto"}, | 131 | {10, &IAudioDevice::GetActiveAudioDeviceName, "GetActiveAudioDeviceNameAuto"}, |
| 130 | {11, nullptr, "QueryAudioDeviceInputEvent"}, | 132 | {11, nullptr, "QueryAudioDeviceInputEvent"}, |
| 131 | {12, nullptr, "QueryAudioDeviceOutputEvent"}, | 133 | {12, nullptr, "QueryAudioDeviceOutputEvent"}, |
| 134 | {13, nullptr, "GetAudioSystemMasterVolumeSetting"}, | ||
| 132 | }; | 135 | }; |
| 133 | RegisterHandlers(functions); | 136 | RegisterHandlers(functions); |
| 134 | 137 | ||
diff --git a/src/core/hle/service/es/es.cpp b/src/core/hle/service/es/es.cpp index d40f18565..6701cb913 100644 --- a/src/core/hle/service/es/es.cpp +++ b/src/core/hle/service/es/es.cpp | |||
| @@ -9,6 +9,7 @@ namespace Service::ES { | |||
| 9 | class ETicket final : public ServiceFramework<ETicket> { | 9 | class ETicket final : public ServiceFramework<ETicket> { |
| 10 | public: | 10 | public: |
| 11 | explicit ETicket() : ServiceFramework{"es"} { | 11 | explicit ETicket() : ServiceFramework{"es"} { |
| 12 | // clang-format off | ||
| 12 | static const FunctionInfo functions[] = { | 13 | static const FunctionInfo functions[] = { |
| 13 | {1, nullptr, "ImportTicket"}, | 14 | {1, nullptr, "ImportTicket"}, |
| 14 | {2, nullptr, "ImportTicketCertificateSet"}, | 15 | {2, nullptr, "ImportTicketCertificateSet"}, |
| @@ -37,15 +38,18 @@ public: | |||
| 37 | {25, nullptr, "DeletePrepurchaseRecord"}, | 38 | {25, nullptr, "DeletePrepurchaseRecord"}, |
| 38 | {26, nullptr, "DeleteAllPrepurchaseRecord"}, | 39 | {26, nullptr, "DeleteAllPrepurchaseRecord"}, |
| 39 | {27, nullptr, "CountPrepurchaseRecord"}, | 40 | {27, nullptr, "CountPrepurchaseRecord"}, |
| 40 | {28, nullptr, "ListPrepurchaseRecord"}, | 41 | {28, nullptr, "ListPrepurchaseRecordRightsIds"}, |
| 41 | {29, nullptr, "ListPrepurchaseRecordInfo"}, | 42 | {29, nullptr, "ListPrepurchaseRecordInfo"}, |
| 42 | {30, nullptr, "Unknown1"}, | 43 | {30, nullptr, "CountTicket"}, |
| 43 | {31, nullptr, "Unknown2"}, | 44 | {31, nullptr, "ListTicketRightsIds"}, |
| 44 | {32, nullptr, "Unknown3"}, | 45 | {32, nullptr, "CountPrepurchaseRecordEx"}, |
| 45 | {33, nullptr, "Unknown4"}, | 46 | {33, nullptr, "ListPrepurchaseRecordRightsIdsEx"}, |
| 46 | {34, nullptr, "Unknown5"}, | 47 | {34, nullptr, "GetEncryptedTicketSize"}, |
| 47 | {35, nullptr, "Unknown6"}, | 48 | {35, nullptr, "GetEncryptedTicketData"}, |
| 49 | {36, nullptr, "DeleteAllInactiveELicenseRequiredPersonalizedTicket"}, | ||
| 50 | {503, nullptr, "GetTitleKey"}, | ||
| 48 | }; | 51 | }; |
| 52 | // clang-format on | ||
| 49 | RegisterHandlers(functions); | 53 | RegisterHandlers(functions); |
| 50 | } | 54 | } |
| 51 | }; | 55 | }; |
diff --git a/src/core/hle/service/filesystem/fsp_srv.cpp b/src/core/hle/service/filesystem/fsp_srv.cpp index d5dced429..c87721c39 100644 --- a/src/core/hle/service/filesystem/fsp_srv.cpp +++ b/src/core/hle/service/filesystem/fsp_srv.cpp | |||
| @@ -17,6 +17,7 @@ | |||
| 17 | #include "core/file_sys/errors.h" | 17 | #include "core/file_sys/errors.h" |
| 18 | #include "core/file_sys/mode.h" | 18 | #include "core/file_sys/mode.h" |
| 19 | #include "core/file_sys/nca_metadata.h" | 19 | #include "core/file_sys/nca_metadata.h" |
| 20 | #include "core/file_sys/patch_manager.h" | ||
| 20 | #include "core/file_sys/savedata_factory.h" | 21 | #include "core/file_sys/savedata_factory.h" |
| 21 | #include "core/file_sys/vfs.h" | 22 | #include "core/file_sys/vfs.h" |
| 22 | #include "core/hle/ipc_helpers.h" | 23 | #include "core/hle/ipc_helpers.h" |
| @@ -630,6 +631,7 @@ void FSP_SRV::OpenDataStorageByDataId(Kernel::HLERequestContext& ctx) { | |||
| 630 | static_cast<u8>(storage_id), unknown, title_id); | 631 | static_cast<u8>(storage_id), unknown, title_id); |
| 631 | 632 | ||
| 632 | auto data = OpenRomFS(title_id, storage_id, FileSys::ContentRecordType::Data); | 633 | auto data = OpenRomFS(title_id, storage_id, FileSys::ContentRecordType::Data); |
| 634 | |||
| 633 | if (data.Failed()) { | 635 | if (data.Failed()) { |
| 634 | // TODO(DarkLordZach): Find the right error code to use here | 636 | // TODO(DarkLordZach): Find the right error code to use here |
| 635 | LOG_ERROR(Service_FS, | 637 | LOG_ERROR(Service_FS, |
| @@ -640,7 +642,9 @@ void FSP_SRV::OpenDataStorageByDataId(Kernel::HLERequestContext& ctx) { | |||
| 640 | return; | 642 | return; |
| 641 | } | 643 | } |
| 642 | 644 | ||
| 643 | IStorage storage(std::move(data.Unwrap())); | 645 | FileSys::PatchManager pm{title_id}; |
| 646 | |||
| 647 | IStorage storage(pm.PatchRomFS(std::move(data.Unwrap()), 0, FileSys::ContentRecordType::Data)); | ||
| 644 | 648 | ||
| 645 | IPC::ResponseBuilder rb{ctx, 2, 0, 1}; | 649 | IPC::ResponseBuilder rb{ctx, 2, 0, 1}; |
| 646 | rb.Push(RESULT_SUCCESS); | 650 | rb.Push(RESULT_SUCCESS); |
diff --git a/src/core/hle/service/hid/controllers/controller_base.cpp b/src/core/hle/service/hid/controllers/controller_base.cpp index 1625e9c3d..0993a7815 100644 --- a/src/core/hle/service/hid/controllers/controller_base.cpp +++ b/src/core/hle/service/hid/controllers/controller_base.cpp | |||
| @@ -5,6 +5,8 @@ | |||
| 5 | #include "core/hle/service/hid/controllers/controller_base.h" | 5 | #include "core/hle/service/hid/controllers/controller_base.h" |
| 6 | 6 | ||
| 7 | namespace Service::HID { | 7 | namespace Service::HID { |
| 8 | |||
| 9 | ControllerBase::ControllerBase() = default; | ||
| 8 | ControllerBase::~ControllerBase() = default; | 10 | ControllerBase::~ControllerBase() = default; |
| 9 | 11 | ||
| 10 | void ControllerBase::ActivateController() { | 12 | void ControllerBase::ActivateController() { |
diff --git a/src/core/hle/service/hid/controllers/controller_base.h b/src/core/hle/service/hid/controllers/controller_base.h index fa98e2354..f0e092b1b 100644 --- a/src/core/hle/service/hid/controllers/controller_base.h +++ b/src/core/hle/service/hid/controllers/controller_base.h | |||
| @@ -10,8 +10,8 @@ | |||
| 10 | namespace Service::HID { | 10 | namespace Service::HID { |
| 11 | class ControllerBase { | 11 | class ControllerBase { |
| 12 | public: | 12 | public: |
| 13 | ControllerBase() = default; | 13 | ControllerBase(); |
| 14 | virtual ~ControllerBase() = 0; | 14 | virtual ~ControllerBase(); |
| 15 | 15 | ||
| 16 | // Called when the controller is initialized | 16 | // Called when the controller is initialized |
| 17 | virtual void OnInit() = 0; | 17 | virtual void OnInit() = 0; |
diff --git a/src/core/hle/service/hid/controllers/debug_pad.cpp b/src/core/hle/service/hid/controllers/debug_pad.cpp index 6f8ef6e3f..3d100763f 100644 --- a/src/core/hle/service/hid/controllers/debug_pad.cpp +++ b/src/core/hle/service/hid/controllers/debug_pad.cpp | |||
| @@ -4,13 +4,13 @@ | |||
| 4 | 4 | ||
| 5 | #include <cstring> | 5 | #include <cstring> |
| 6 | #include "common/common_types.h" | 6 | #include "common/common_types.h" |
| 7 | #include "common/swap.h" | ||
| 8 | #include "core/core_timing.h" | 7 | #include "core/core_timing.h" |
| 9 | #include "core/hle/service/hid/controllers/debug_pad.h" | 8 | #include "core/hle/service/hid/controllers/debug_pad.h" |
| 10 | 9 | ||
| 11 | namespace Service::HID { | 10 | namespace Service::HID { |
| 12 | 11 | ||
| 13 | Controller_DebugPad::Controller_DebugPad() = default; | 12 | Controller_DebugPad::Controller_DebugPad() = default; |
| 13 | Controller_DebugPad::~Controller_DebugPad() = default; | ||
| 14 | 14 | ||
| 15 | void Controller_DebugPad::OnInit() {} | 15 | void Controller_DebugPad::OnInit() {} |
| 16 | 16 | ||
diff --git a/src/core/hle/service/hid/controllers/debug_pad.h b/src/core/hle/service/hid/controllers/debug_pad.h index e35675fa1..62b4f2682 100644 --- a/src/core/hle/service/hid/controllers/debug_pad.h +++ b/src/core/hle/service/hid/controllers/debug_pad.h | |||
| @@ -14,6 +14,7 @@ namespace Service::HID { | |||
| 14 | class Controller_DebugPad final : public ControllerBase { | 14 | class Controller_DebugPad final : public ControllerBase { |
| 15 | public: | 15 | public: |
| 16 | Controller_DebugPad(); | 16 | Controller_DebugPad(); |
| 17 | ~Controller_DebugPad() override; | ||
| 17 | 18 | ||
| 18 | // Called when the controller is initialized | 19 | // Called when the controller is initialized |
| 19 | void OnInit() override; | 20 | void OnInit() override; |
diff --git a/src/core/hle/service/hid/controllers/gesture.cpp b/src/core/hle/service/hid/controllers/gesture.cpp index b473b9e2b..898572277 100644 --- a/src/core/hle/service/hid/controllers/gesture.cpp +++ b/src/core/hle/service/hid/controllers/gesture.cpp | |||
| @@ -4,7 +4,6 @@ | |||
| 4 | 4 | ||
| 5 | #include <cstring> | 5 | #include <cstring> |
| 6 | #include "common/common_types.h" | 6 | #include "common/common_types.h" |
| 7 | #include "common/swap.h" | ||
| 8 | #include "core/core_timing.h" | 7 | #include "core/core_timing.h" |
| 9 | #include "core/hle/service/hid/controllers/gesture.h" | 8 | #include "core/hle/service/hid/controllers/gesture.h" |
| 10 | 9 | ||
| @@ -12,6 +11,7 @@ namespace Service::HID { | |||
| 12 | constexpr std::size_t SHARED_MEMORY_OFFSET = 0x3BA00; | 11 | constexpr std::size_t SHARED_MEMORY_OFFSET = 0x3BA00; |
| 13 | 12 | ||
| 14 | Controller_Gesture::Controller_Gesture() = default; | 13 | Controller_Gesture::Controller_Gesture() = default; |
| 14 | Controller_Gesture::~Controller_Gesture() = default; | ||
| 15 | 15 | ||
| 16 | void Controller_Gesture::OnInit() {} | 16 | void Controller_Gesture::OnInit() {} |
| 17 | 17 | ||
diff --git a/src/core/hle/service/hid/controllers/gesture.h b/src/core/hle/service/hid/controllers/gesture.h index 0ced50dfd..1056ffbcd 100644 --- a/src/core/hle/service/hid/controllers/gesture.h +++ b/src/core/hle/service/hid/controllers/gesture.h | |||
| @@ -13,6 +13,7 @@ namespace Service::HID { | |||
| 13 | class Controller_Gesture final : public ControllerBase { | 13 | class Controller_Gesture final : public ControllerBase { |
| 14 | public: | 14 | public: |
| 15 | Controller_Gesture(); | 15 | Controller_Gesture(); |
| 16 | ~Controller_Gesture() override; | ||
| 16 | 17 | ||
| 17 | // Called when the controller is initialized | 18 | // Called when the controller is initialized |
| 18 | void OnInit() override; | 19 | void OnInit() override; |
diff --git a/src/core/hle/service/hid/controllers/keyboard.cpp b/src/core/hle/service/hid/controllers/keyboard.cpp index 089c02ac4..ccfbce9ac 100644 --- a/src/core/hle/service/hid/controllers/keyboard.cpp +++ b/src/core/hle/service/hid/controllers/keyboard.cpp | |||
| @@ -4,7 +4,6 @@ | |||
| 4 | 4 | ||
| 5 | #include <cstring> | 5 | #include <cstring> |
| 6 | #include "common/common_types.h" | 6 | #include "common/common_types.h" |
| 7 | #include "common/swap.h" | ||
| 8 | #include "core/core_timing.h" | 7 | #include "core/core_timing.h" |
| 9 | #include "core/hle/service/hid/controllers/keyboard.h" | 8 | #include "core/hle/service/hid/controllers/keyboard.h" |
| 10 | 9 | ||
| @@ -12,6 +11,7 @@ namespace Service::HID { | |||
| 12 | constexpr std::size_t SHARED_MEMORY_OFFSET = 0x3800; | 11 | constexpr std::size_t SHARED_MEMORY_OFFSET = 0x3800; |
| 13 | 12 | ||
| 14 | Controller_Keyboard::Controller_Keyboard() = default; | 13 | Controller_Keyboard::Controller_Keyboard() = default; |
| 14 | Controller_Keyboard::~Controller_Keyboard() = default; | ||
| 15 | 15 | ||
| 16 | void Controller_Keyboard::OnInit() {} | 16 | void Controller_Keyboard::OnInit() {} |
| 17 | 17 | ||
diff --git a/src/core/hle/service/hid/controllers/keyboard.h b/src/core/hle/service/hid/controllers/keyboard.h index 778e14f7e..493e68fce 100644 --- a/src/core/hle/service/hid/controllers/keyboard.h +++ b/src/core/hle/service/hid/controllers/keyboard.h | |||
| @@ -14,6 +14,7 @@ namespace Service::HID { | |||
| 14 | class Controller_Keyboard final : public ControllerBase { | 14 | class Controller_Keyboard final : public ControllerBase { |
| 15 | public: | 15 | public: |
| 16 | Controller_Keyboard(); | 16 | Controller_Keyboard(); |
| 17 | ~Controller_Keyboard() override; | ||
| 17 | 18 | ||
| 18 | // Called when the controller is initialized | 19 | // Called when the controller is initialized |
| 19 | void OnInit() override; | 20 | void OnInit() override; |
diff --git a/src/core/hle/service/hid/controllers/mouse.cpp b/src/core/hle/service/hid/controllers/mouse.cpp index 78e9b5e9e..4e246a57d 100644 --- a/src/core/hle/service/hid/controllers/mouse.cpp +++ b/src/core/hle/service/hid/controllers/mouse.cpp | |||
| @@ -4,7 +4,6 @@ | |||
| 4 | 4 | ||
| 5 | #include <cstring> | 5 | #include <cstring> |
| 6 | #include "common/common_types.h" | 6 | #include "common/common_types.h" |
| 7 | #include "common/swap.h" | ||
| 8 | #include "core/core_timing.h" | 7 | #include "core/core_timing.h" |
| 9 | #include "core/hle/service/hid/controllers/mouse.h" | 8 | #include "core/hle/service/hid/controllers/mouse.h" |
| 10 | 9 | ||
| @@ -12,6 +11,7 @@ namespace Service::HID { | |||
| 12 | constexpr std::size_t SHARED_MEMORY_OFFSET = 0x3400; | 11 | constexpr std::size_t SHARED_MEMORY_OFFSET = 0x3400; |
| 13 | 12 | ||
| 14 | Controller_Mouse::Controller_Mouse() = default; | 13 | Controller_Mouse::Controller_Mouse() = default; |
| 14 | Controller_Mouse::~Controller_Mouse() = default; | ||
| 15 | 15 | ||
| 16 | void Controller_Mouse::OnInit() {} | 16 | void Controller_Mouse::OnInit() {} |
| 17 | 17 | ||
diff --git a/src/core/hle/service/hid/controllers/mouse.h b/src/core/hle/service/hid/controllers/mouse.h index 05358a4f5..543b0b71f 100644 --- a/src/core/hle/service/hid/controllers/mouse.h +++ b/src/core/hle/service/hid/controllers/mouse.h | |||
| @@ -13,6 +13,7 @@ namespace Service::HID { | |||
| 13 | class Controller_Mouse final : public ControllerBase { | 13 | class Controller_Mouse final : public ControllerBase { |
| 14 | public: | 14 | public: |
| 15 | Controller_Mouse(); | 15 | Controller_Mouse(); |
| 16 | ~Controller_Mouse() override; | ||
| 16 | 17 | ||
| 17 | // Called when the controller is initialized | 18 | // Called when the controller is initialized |
| 18 | void OnInit() override; | 19 | void OnInit() override; |
diff --git a/src/core/hle/service/hid/controllers/npad.cpp b/src/core/hle/service/hid/controllers/npad.cpp index d17e64b2a..4b4d1324f 100644 --- a/src/core/hle/service/hid/controllers/npad.cpp +++ b/src/core/hle/service/hid/controllers/npad.cpp | |||
| @@ -2,8 +2,6 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <algorithm> | 5 | #include <algorithm> |
| 8 | #include <array> | 6 | #include <array> |
| 9 | #include <cstring> | 7 | #include <cstring> |
| @@ -11,7 +9,6 @@ | |||
| 11 | #include "common/bit_field.h" | 9 | #include "common/bit_field.h" |
| 12 | #include "common/common_types.h" | 10 | #include "common/common_types.h" |
| 13 | #include "common/logging/log.h" | 11 | #include "common/logging/log.h" |
| 14 | #include "common/swap.h" | ||
| 15 | #include "core/core.h" | 12 | #include "core/core.h" |
| 16 | #include "core/core_timing.h" | 13 | #include "core/core_timing.h" |
| 17 | #include "core/frontend/input.h" | 14 | #include "core/frontend/input.h" |
| @@ -20,6 +17,7 @@ | |||
| 20 | #include "core/settings.h" | 17 | #include "core/settings.h" |
| 21 | 18 | ||
| 22 | namespace Service::HID { | 19 | namespace Service::HID { |
| 20 | |||
| 23 | constexpr u32 JOYCON_BODY_NEON_RED = 0xFF3C28; | 21 | constexpr u32 JOYCON_BODY_NEON_RED = 0xFF3C28; |
| 24 | constexpr u32 JOYCON_BUTTONS_NEON_RED = 0x1E0A0A; | 22 | constexpr u32 JOYCON_BUTTONS_NEON_RED = 0x1E0A0A; |
| 25 | constexpr u32 JOYCON_BODY_NEON_BLUE = 0x0AB9E6; | 23 | constexpr u32 JOYCON_BODY_NEON_BLUE = 0x0AB9E6; |
| @@ -28,9 +26,22 @@ constexpr s32 HID_JOYSTICK_MAX = 0x7fff; | |||
| 28 | constexpr s32 HID_JOYSTICK_MIN = -0x7fff; | 26 | constexpr s32 HID_JOYSTICK_MIN = -0x7fff; |
| 29 | constexpr std::size_t NPAD_OFFSET = 0x9A00; | 27 | constexpr std::size_t NPAD_OFFSET = 0x9A00; |
| 30 | constexpr u32 BATTERY_FULL = 2; | 28 | constexpr u32 BATTERY_FULL = 2; |
| 31 | enum class JoystickId : std::size_t { Joystick_Left, Joystick_Right }; | 29 | constexpr u32 NPAD_HANDHELD = 32; |
| 30 | constexpr u32 NPAD_UNKNOWN = 16; // TODO(ogniK): What is this? | ||
| 31 | constexpr u32 MAX_NPAD_ID = 7; | ||
| 32 | constexpr Controller_NPad::NPadControllerType PREFERRED_CONTROLLER = | ||
| 33 | Controller_NPad::NPadControllerType::JoyDual; | ||
| 34 | constexpr std::array<u32, 10> npad_id_list{ | ||
| 35 | 0, 1, 2, 3, 4, 5, 6, 7, 32, 16, | ||
| 36 | }; | ||
| 37 | |||
| 38 | enum class JoystickId : std::size_t { | ||
| 39 | Joystick_Left, | ||
| 40 | Joystick_Right, | ||
| 41 | }; | ||
| 32 | 42 | ||
| 33 | Controller_NPad::Controller_NPad() = default; | 43 | Controller_NPad::Controller_NPad() = default; |
| 44 | Controller_NPad::~Controller_NPad() = default; | ||
| 34 | 45 | ||
| 35 | void Controller_NPad::InitNewlyAddedControler(std::size_t controller_idx) { | 46 | void Controller_NPad::InitNewlyAddedControler(std::size_t controller_idx) { |
| 36 | const auto controller_type = connected_controllers[controller_idx].type; | 47 | const auto controller_type = connected_controllers[controller_idx].type; |
| @@ -97,9 +108,10 @@ void Controller_NPad::OnInit() { | |||
| 97 | styleset_changed_event = | 108 | styleset_changed_event = |
| 98 | Kernel::Event::Create(kernel, Kernel::ResetType::OneShot, "npad:NpadStyleSetChanged"); | 109 | Kernel::Event::Create(kernel, Kernel::ResetType::OneShot, "npad:NpadStyleSetChanged"); |
| 99 | 110 | ||
| 100 | if (!IsControllerActivated()) | 111 | if (!IsControllerActivated()) { |
| 101 | return; | 112 | return; |
| 102 | std::size_t controller{}; | 113 | } |
| 114 | |||
| 103 | if (style.raw == 0) { | 115 | if (style.raw == 0) { |
| 104 | // We want to support all controllers | 116 | // We want to support all controllers |
| 105 | style.handheld.Assign(1); | 117 | style.handheld.Assign(1); |
| @@ -114,7 +126,7 @@ void Controller_NPad::OnInit() { | |||
| 114 | supported_npad_id_types.resize(npad_id_list.size()); | 126 | supported_npad_id_types.resize(npad_id_list.size()); |
| 115 | std::memcpy(supported_npad_id_types.data(), npad_id_list.data(), | 127 | std::memcpy(supported_npad_id_types.data(), npad_id_list.data(), |
| 116 | npad_id_list.size() * sizeof(u32)); | 128 | npad_id_list.size() * sizeof(u32)); |
| 117 | AddNewController(NPadControllerType::JoyDual); | 129 | AddNewController(PREFERRED_CONTROLLER); |
| 118 | } | 130 | } |
| 119 | } | 131 | } |
| 120 | 132 | ||
| @@ -211,6 +223,51 @@ void Controller_NPad::OnUpdate(u8* data, std::size_t data_len) { | |||
| 211 | rstick_entry.x = static_cast<s32>(stick_r_x_f * HID_JOYSTICK_MAX); | 223 | rstick_entry.x = static_cast<s32>(stick_r_x_f * HID_JOYSTICK_MAX); |
| 212 | rstick_entry.y = static_cast<s32>(stick_r_y_f * HID_JOYSTICK_MAX); | 224 | rstick_entry.y = static_cast<s32>(stick_r_y_f * HID_JOYSTICK_MAX); |
| 213 | 225 | ||
| 226 | if (controller_type == NPadControllerType::JoyLeft || | ||
| 227 | controller_type == NPadControllerType::JoyRight) { | ||
| 228 | if (npad.properties.is_horizontal) { | ||
| 229 | ControllerPadState state{}; | ||
| 230 | AnalogPosition temp_lstick_entry{}; | ||
| 231 | AnalogPosition temp_rstick_entry{}; | ||
| 232 | if (controller_type == NPadControllerType::JoyLeft) { | ||
| 233 | state.d_down.Assign(pad_state.d_left.Value()); | ||
| 234 | state.d_left.Assign(pad_state.d_up.Value()); | ||
| 235 | state.d_right.Assign(pad_state.d_down.Value()); | ||
| 236 | state.d_up.Assign(pad_state.d_right.Value()); | ||
| 237 | state.l.Assign(pad_state.l.Value() | pad_state.sl.Value()); | ||
| 238 | state.r.Assign(pad_state.r.Value() | pad_state.sr.Value()); | ||
| 239 | |||
| 240 | state.zl.Assign(pad_state.zl.Value()); | ||
| 241 | state.plus.Assign(pad_state.minus.Value()); | ||
| 242 | |||
| 243 | temp_lstick_entry = lstick_entry; | ||
| 244 | temp_rstick_entry = rstick_entry; | ||
| 245 | std::swap(temp_lstick_entry.x, temp_lstick_entry.y); | ||
| 246 | std::swap(temp_rstick_entry.x, temp_rstick_entry.y); | ||
| 247 | temp_lstick_entry.y *= -1; | ||
| 248 | } else if (controller_type == NPadControllerType::JoyRight) { | ||
| 249 | state.x.Assign(pad_state.a.Value()); | ||
| 250 | state.a.Assign(pad_state.b.Value()); | ||
| 251 | state.b.Assign(pad_state.y.Value()); | ||
| 252 | state.y.Assign(pad_state.b.Value()); | ||
| 253 | |||
| 254 | state.l.Assign(pad_state.l.Value() | pad_state.sl.Value()); | ||
| 255 | state.r.Assign(pad_state.r.Value() | pad_state.sr.Value()); | ||
| 256 | state.zr.Assign(pad_state.zr.Value()); | ||
| 257 | state.plus.Assign(pad_state.plus.Value()); | ||
| 258 | |||
| 259 | temp_lstick_entry = lstick_entry; | ||
| 260 | temp_rstick_entry = rstick_entry; | ||
| 261 | std::swap(temp_lstick_entry.x, temp_lstick_entry.y); | ||
| 262 | std::swap(temp_rstick_entry.x, temp_rstick_entry.y); | ||
| 263 | temp_rstick_entry.x *= -1; | ||
| 264 | } | ||
| 265 | pad_state.raw = state.raw; | ||
| 266 | lstick_entry = temp_lstick_entry; | ||
| 267 | rstick_entry = temp_rstick_entry; | ||
| 268 | } | ||
| 269 | } | ||
| 270 | |||
| 214 | auto& main_controller = | 271 | auto& main_controller = |
| 215 | npad.main_controller_states.npad[npad.main_controller_states.common.last_entry_index]; | 272 | npad.main_controller_states.npad[npad.main_controller_states.common.last_entry_index]; |
| 216 | auto& handheld_entry = | 273 | auto& handheld_entry = |
| @@ -313,9 +370,19 @@ void Controller_NPad::SetSupportedNPadIdTypes(u8* data, std::size_t length) { | |||
| 313 | supported_npad_id_types.clear(); | 370 | supported_npad_id_types.clear(); |
| 314 | supported_npad_id_types.resize(length / sizeof(u32)); | 371 | supported_npad_id_types.resize(length / sizeof(u32)); |
| 315 | std::memcpy(supported_npad_id_types.data(), data, length); | 372 | std::memcpy(supported_npad_id_types.data(), data, length); |
| 373 | for (std::size_t i = 0; i < connected_controllers.size(); i++) { | ||
| 374 | auto& controller = connected_controllers[i]; | ||
| 375 | if (!controller.is_connected) { | ||
| 376 | continue; | ||
| 377 | } | ||
| 378 | if (!IsControllerSupported(PREFERRED_CONTROLLER)) { | ||
| 379 | controller.type = DecideBestController(PREFERRED_CONTROLLER); | ||
| 380 | InitNewlyAddedControler(i); | ||
| 381 | } | ||
| 382 | } | ||
| 316 | } | 383 | } |
| 317 | 384 | ||
| 318 | const void Controller_NPad::GetSupportedNpadIdTypes(u32* data, std::size_t max_length) { | 385 | void Controller_NPad::GetSupportedNpadIdTypes(u32* data, std::size_t max_length) { |
| 319 | ASSERT(max_length < supported_npad_id_types.size()); | 386 | ASSERT(max_length < supported_npad_id_types.size()); |
| 320 | std::memcpy(data, supported_npad_id_types.data(), supported_npad_id_types.size()); | 387 | std::memcpy(data, supported_npad_id_types.data(), supported_npad_id_types.size()); |
| 321 | } | 388 | } |
| @@ -344,11 +411,11 @@ void Controller_NPad::VibrateController(const std::vector<u32>& controller_ids, | |||
| 344 | for (std::size_t i = 0; i < controller_ids.size(); i++) { | 411 | for (std::size_t i = 0; i < controller_ids.size(); i++) { |
| 345 | std::size_t controller_pos = i; | 412 | std::size_t controller_pos = i; |
| 346 | // Handheld controller conversion | 413 | // Handheld controller conversion |
| 347 | if (controller_pos == 32) { | 414 | if (controller_pos == NPAD_HANDHELD) { |
| 348 | controller_pos = 8; | 415 | controller_pos = 8; |
| 349 | } | 416 | } |
| 350 | // Unknown controller conversion | 417 | // Unknown controller conversion |
| 351 | if (controller_pos == 16) { | 418 | if (controller_pos == NPAD_UNKNOWN) { |
| 352 | controller_pos = 9; | 419 | controller_pos = 9; |
| 353 | } | 420 | } |
| 354 | if (connected_controllers[controller_pos].is_connected) { | 421 | if (connected_controllers[controller_pos].is_connected) { |
| @@ -426,4 +493,128 @@ Controller_NPad::LedPattern Controller_NPad::GetLedPattern(u32 npad_id) { | |||
| 426 | void Controller_NPad::SetVibrationEnabled(bool can_vibrate) { | 493 | void Controller_NPad::SetVibrationEnabled(bool can_vibrate) { |
| 427 | can_controllers_vibrate = can_vibrate; | 494 | can_controllers_vibrate = can_vibrate; |
| 428 | } | 495 | } |
| 496 | |||
| 497 | bool Controller_NPad::IsControllerSupported(NPadControllerType controller) const { | ||
| 498 | const bool support_handheld = | ||
| 499 | std::find(supported_npad_id_types.begin(), supported_npad_id_types.end(), NPAD_HANDHELD) != | ||
| 500 | supported_npad_id_types.end(); | ||
| 501 | if (controller == NPadControllerType::Handheld) { | ||
| 502 | // Handheld is not even a supported type, lets stop here | ||
| 503 | if (!support_handheld) { | ||
| 504 | return false; | ||
| 505 | } | ||
| 506 | // Handheld should not be supported in docked mode | ||
| 507 | if (Settings::values.use_docked_mode) { | ||
| 508 | return false; | ||
| 509 | } | ||
| 510 | |||
| 511 | return true; | ||
| 512 | } | ||
| 513 | if (std::any_of(supported_npad_id_types.begin(), supported_npad_id_types.end(), | ||
| 514 | [](u32 npad_id) { return npad_id <= MAX_NPAD_ID; })) { | ||
| 515 | switch (controller) { | ||
| 516 | case NPadControllerType::ProController: | ||
| 517 | return style.pro_controller; | ||
| 518 | case NPadControllerType::JoyDual: | ||
| 519 | return style.joycon_dual; | ||
| 520 | case NPadControllerType::JoyLeft: | ||
| 521 | return style.joycon_left; | ||
| 522 | case NPadControllerType::JoyRight: | ||
| 523 | return style.joycon_right; | ||
| 524 | case NPadControllerType::Pokeball: | ||
| 525 | return style.pokeball; | ||
| 526 | default: | ||
| 527 | return false; | ||
| 528 | } | ||
| 529 | } | ||
| 530 | return false; | ||
| 531 | } | ||
| 532 | |||
| 533 | Controller_NPad::NPadControllerType Controller_NPad::DecideBestController( | ||
| 534 | NPadControllerType priority) const { | ||
| 535 | if (IsControllerSupported(priority)) { | ||
| 536 | return priority; | ||
| 537 | } | ||
| 538 | const auto is_docked = Settings::values.use_docked_mode; | ||
| 539 | if (is_docked && priority == NPadControllerType::Handheld) { | ||
| 540 | priority = NPadControllerType::JoyDual; | ||
| 541 | if (IsControllerSupported(priority)) { | ||
| 542 | return priority; | ||
| 543 | } | ||
| 544 | } | ||
| 545 | std::vector<NPadControllerType> priority_list; | ||
| 546 | switch (priority) { | ||
| 547 | case NPadControllerType::ProController: | ||
| 548 | priority_list.push_back(NPadControllerType::JoyDual); | ||
| 549 | if (!is_docked) { | ||
| 550 | priority_list.push_back(NPadControllerType::Handheld); | ||
| 551 | } | ||
| 552 | priority_list.push_back(NPadControllerType::JoyLeft); | ||
| 553 | priority_list.push_back(NPadControllerType::JoyRight); | ||
| 554 | priority_list.push_back(NPadControllerType::Pokeball); | ||
| 555 | break; | ||
| 556 | case NPadControllerType::Handheld: | ||
| 557 | priority_list.push_back(NPadControllerType::JoyDual); | ||
| 558 | priority_list.push_back(NPadControllerType::ProController); | ||
| 559 | priority_list.push_back(NPadControllerType::JoyLeft); | ||
| 560 | priority_list.push_back(NPadControllerType::JoyRight); | ||
| 561 | priority_list.push_back(NPadControllerType::Pokeball); | ||
| 562 | break; | ||
| 563 | case NPadControllerType::JoyDual: | ||
| 564 | if (!is_docked) { | ||
| 565 | priority_list.push_back(NPadControllerType::Handheld); | ||
| 566 | } | ||
| 567 | priority_list.push_back(NPadControllerType::ProController); | ||
| 568 | priority_list.push_back(NPadControllerType::JoyLeft); | ||
| 569 | priority_list.push_back(NPadControllerType::JoyRight); | ||
| 570 | priority_list.push_back(NPadControllerType::Pokeball); | ||
| 571 | break; | ||
| 572 | case NPadControllerType::JoyLeft: | ||
| 573 | priority_list.push_back(NPadControllerType::JoyRight); | ||
| 574 | priority_list.push_back(NPadControllerType::JoyDual); | ||
| 575 | if (!is_docked) { | ||
| 576 | priority_list.push_back(NPadControllerType::Handheld); | ||
| 577 | } | ||
| 578 | priority_list.push_back(NPadControllerType::ProController); | ||
| 579 | priority_list.push_back(NPadControllerType::Pokeball); | ||
| 580 | break; | ||
| 581 | case NPadControllerType::JoyRight: | ||
| 582 | priority_list.push_back(NPadControllerType::JoyLeft); | ||
| 583 | priority_list.push_back(NPadControllerType::JoyDual); | ||
| 584 | if (!is_docked) { | ||
| 585 | priority_list.push_back(NPadControllerType::Handheld); | ||
| 586 | } | ||
| 587 | priority_list.push_back(NPadControllerType::ProController); | ||
| 588 | priority_list.push_back(NPadControllerType::Pokeball); | ||
| 589 | break; | ||
| 590 | case NPadControllerType::Pokeball: | ||
| 591 | priority_list.push_back(NPadControllerType::JoyLeft); | ||
| 592 | priority_list.push_back(NPadControllerType::JoyRight); | ||
| 593 | priority_list.push_back(NPadControllerType::JoyDual); | ||
| 594 | if (!is_docked) { | ||
| 595 | priority_list.push_back(NPadControllerType::Handheld); | ||
| 596 | } | ||
| 597 | priority_list.push_back(NPadControllerType::ProController); | ||
| 598 | break; | ||
| 599 | default: | ||
| 600 | priority_list.push_back(NPadControllerType::JoyDual); | ||
| 601 | if (!is_docked) { | ||
| 602 | priority_list.push_back(NPadControllerType::Handheld); | ||
| 603 | } | ||
| 604 | priority_list.push_back(NPadControllerType::ProController); | ||
| 605 | priority_list.push_back(NPadControllerType::JoyLeft); | ||
| 606 | priority_list.push_back(NPadControllerType::JoyRight); | ||
| 607 | priority_list.push_back(NPadControllerType::JoyDual); | ||
| 608 | } | ||
| 609 | |||
| 610 | const auto iter = std::find_if(priority_list.begin(), priority_list.end(), | ||
| 611 | [this](auto type) { return IsControllerSupported(type); }); | ||
| 612 | if (iter == priority_list.end()) { | ||
| 613 | UNIMPLEMENTED_MSG("Could not find supported controller!"); | ||
| 614 | return priority; | ||
| 615 | } | ||
| 616 | |||
| 617 | return *iter; | ||
| 618 | } | ||
| 619 | |||
| 429 | } // namespace Service::HID | 620 | } // namespace Service::HID |
diff --git a/src/core/hle/service/hid/controllers/npad.h b/src/core/hle/service/hid/controllers/npad.h index 9d07d258d..ac86985ff 100644 --- a/src/core/hle/service/hid/controllers/npad.h +++ b/src/core/hle/service/hid/controllers/npad.h | |||
| @@ -15,6 +15,7 @@ namespace Service::HID { | |||
| 15 | class Controller_NPad final : public ControllerBase { | 15 | class Controller_NPad final : public ControllerBase { |
| 16 | public: | 16 | public: |
| 17 | Controller_NPad(); | 17 | Controller_NPad(); |
| 18 | ~Controller_NPad() override; | ||
| 18 | 19 | ||
| 19 | // Called when the controller is initialized | 20 | // Called when the controller is initialized |
| 20 | void OnInit() override; | 21 | void OnInit() override; |
| @@ -77,7 +78,7 @@ public: | |||
| 77 | position1.Assign(light2); | 78 | position1.Assign(light2); |
| 78 | position1.Assign(light3); | 79 | position1.Assign(light3); |
| 79 | position1.Assign(light4); | 80 | position1.Assign(light4); |
| 80 | }; | 81 | } |
| 81 | union { | 82 | union { |
| 82 | u64 raw{}; | 83 | u64 raw{}; |
| 83 | BitField<0, 1, u64> position1; | 84 | BitField<0, 1, u64> position1; |
| @@ -91,7 +92,7 @@ public: | |||
| 91 | NPadType GetSupportedStyleSet() const; | 92 | NPadType GetSupportedStyleSet() const; |
| 92 | 93 | ||
| 93 | void SetSupportedNPadIdTypes(u8* data, std::size_t length); | 94 | void SetSupportedNPadIdTypes(u8* data, std::size_t length); |
| 94 | const void GetSupportedNpadIdTypes(u32* data, std::size_t max_length); | 95 | void GetSupportedNpadIdTypes(u32* data, std::size_t max_length); |
| 95 | std::size_t GetSupportedNPadIdTypesSize() const; | 96 | std::size_t GetSupportedNPadIdTypesSize() const; |
| 96 | 97 | ||
| 97 | void SetHoldType(NpadHoldType joy_hold_type); | 98 | void SetHoldType(NpadHoldType joy_hold_type); |
| @@ -277,12 +278,12 @@ private: | |||
| 277 | std::vector<u32> supported_npad_id_types{}; | 278 | std::vector<u32> supported_npad_id_types{}; |
| 278 | NpadHoldType hold_type{NpadHoldType::Vertical}; | 279 | NpadHoldType hold_type{NpadHoldType::Vertical}; |
| 279 | Kernel::SharedPtr<Kernel::Event> styleset_changed_event; | 280 | Kernel::SharedPtr<Kernel::Event> styleset_changed_event; |
| 280 | std::size_t dump_idx{}; | ||
| 281 | Vibration last_processed_vibration{}; | 281 | Vibration last_processed_vibration{}; |
| 282 | static constexpr std::array<u32, 10> npad_id_list{0, 1, 2, 3, 4, 5, 6, 7, 32, 16}; | ||
| 283 | std::array<ControllerHolder, 10> connected_controllers{}; | 282 | std::array<ControllerHolder, 10> connected_controllers{}; |
| 284 | bool can_controllers_vibrate{true}; | 283 | bool can_controllers_vibrate{true}; |
| 285 | 284 | ||
| 286 | void InitNewlyAddedControler(std::size_t controller_idx); | 285 | void InitNewlyAddedControler(std::size_t controller_idx); |
| 286 | bool IsControllerSupported(NPadControllerType controller) const; | ||
| 287 | NPadControllerType DecideBestController(NPadControllerType priority) const; | ||
| 287 | }; | 288 | }; |
| 288 | } // namespace Service::HID | 289 | } // namespace Service::HID |
diff --git a/src/core/hle/service/hid/controllers/stubbed.cpp b/src/core/hle/service/hid/controllers/stubbed.cpp index 3a13d5991..02fcfadd9 100644 --- a/src/core/hle/service/hid/controllers/stubbed.cpp +++ b/src/core/hle/service/hid/controllers/stubbed.cpp | |||
| @@ -4,13 +4,13 @@ | |||
| 4 | 4 | ||
| 5 | #include <cstring> | 5 | #include <cstring> |
| 6 | #include "common/common_types.h" | 6 | #include "common/common_types.h" |
| 7 | #include "common/swap.h" | ||
| 8 | #include "core/core_timing.h" | 7 | #include "core/core_timing.h" |
| 9 | #include "core/hle/service/hid/controllers/stubbed.h" | 8 | #include "core/hle/service/hid/controllers/stubbed.h" |
| 10 | 9 | ||
| 11 | namespace Service::HID { | 10 | namespace Service::HID { |
| 12 | 11 | ||
| 13 | Controller_Stubbed::Controller_Stubbed() = default; | 12 | Controller_Stubbed::Controller_Stubbed() = default; |
| 13 | Controller_Stubbed::~Controller_Stubbed() = default; | ||
| 14 | 14 | ||
| 15 | void Controller_Stubbed::OnInit() {} | 15 | void Controller_Stubbed::OnInit() {} |
| 16 | 16 | ||
diff --git a/src/core/hle/service/hid/controllers/stubbed.h b/src/core/hle/service/hid/controllers/stubbed.h index 9c1b57f83..4a21c643e 100644 --- a/src/core/hle/service/hid/controllers/stubbed.h +++ b/src/core/hle/service/hid/controllers/stubbed.h | |||
| @@ -11,6 +11,7 @@ namespace Service::HID { | |||
| 11 | class Controller_Stubbed final : public ControllerBase { | 11 | class Controller_Stubbed final : public ControllerBase { |
| 12 | public: | 12 | public: |
| 13 | Controller_Stubbed(); | 13 | Controller_Stubbed(); |
| 14 | ~Controller_Stubbed() override; | ||
| 14 | 15 | ||
| 15 | // Called when the controller is initialized | 16 | // Called when the controller is initialized |
| 16 | void OnInit() override; | 17 | void OnInit() override; |
diff --git a/src/core/hle/service/hid/controllers/touchscreen.cpp b/src/core/hle/service/hid/controllers/touchscreen.cpp index e97f84ea1..43efef803 100644 --- a/src/core/hle/service/hid/controllers/touchscreen.cpp +++ b/src/core/hle/service/hid/controllers/touchscreen.cpp | |||
| @@ -4,7 +4,6 @@ | |||
| 4 | 4 | ||
| 5 | #include <cstring> | 5 | #include <cstring> |
| 6 | #include "common/common_types.h" | 6 | #include "common/common_types.h" |
| 7 | #include "common/swap.h" | ||
| 8 | #include "core/core_timing.h" | 7 | #include "core/core_timing.h" |
| 9 | #include "core/frontend/emu_window.h" | 8 | #include "core/frontend/emu_window.h" |
| 10 | #include "core/frontend/input.h" | 9 | #include "core/frontend/input.h" |
| @@ -15,6 +14,7 @@ namespace Service::HID { | |||
| 15 | constexpr std::size_t SHARED_MEMORY_OFFSET = 0x400; | 14 | constexpr std::size_t SHARED_MEMORY_OFFSET = 0x400; |
| 16 | 15 | ||
| 17 | Controller_Touchscreen::Controller_Touchscreen() = default; | 16 | Controller_Touchscreen::Controller_Touchscreen() = default; |
| 17 | Controller_Touchscreen::~Controller_Touchscreen() = default; | ||
| 18 | 18 | ||
| 19 | void Controller_Touchscreen::OnInit() {} | 19 | void Controller_Touchscreen::OnInit() {} |
| 20 | 20 | ||
diff --git a/src/core/hle/service/hid/controllers/touchscreen.h b/src/core/hle/service/hid/controllers/touchscreen.h index 1d97b6c2a..e5db6e6ba 100644 --- a/src/core/hle/service/hid/controllers/touchscreen.h +++ b/src/core/hle/service/hid/controllers/touchscreen.h | |||
| @@ -14,6 +14,7 @@ namespace Service::HID { | |||
| 14 | class Controller_Touchscreen final : public ControllerBase { | 14 | class Controller_Touchscreen final : public ControllerBase { |
| 15 | public: | 15 | public: |
| 16 | Controller_Touchscreen(); | 16 | Controller_Touchscreen(); |
| 17 | ~Controller_Touchscreen() override; | ||
| 17 | 18 | ||
| 18 | // Called when the controller is initialized | 19 | // Called when the controller is initialized |
| 19 | void OnInit() override; | 20 | void OnInit() override; |
diff --git a/src/core/hle/service/hid/controllers/xpad.cpp b/src/core/hle/service/hid/controllers/xpad.cpp index df0b48451..cd397c70b 100644 --- a/src/core/hle/service/hid/controllers/xpad.cpp +++ b/src/core/hle/service/hid/controllers/xpad.cpp | |||
| @@ -4,7 +4,6 @@ | |||
| 4 | 4 | ||
| 5 | #include <cstring> | 5 | #include <cstring> |
| 6 | #include "common/common_types.h" | 6 | #include "common/common_types.h" |
| 7 | #include "common/swap.h" | ||
| 8 | #include "core/core_timing.h" | 7 | #include "core/core_timing.h" |
| 9 | #include "core/hle/service/hid/controllers/xpad.h" | 8 | #include "core/hle/service/hid/controllers/xpad.h" |
| 10 | 9 | ||
| @@ -12,6 +11,7 @@ namespace Service::HID { | |||
| 12 | constexpr std::size_t SHARED_MEMORY_OFFSET = 0x3C00; | 11 | constexpr std::size_t SHARED_MEMORY_OFFSET = 0x3C00; |
| 13 | 12 | ||
| 14 | Controller_XPad::Controller_XPad() = default; | 13 | Controller_XPad::Controller_XPad() = default; |
| 14 | Controller_XPad::~Controller_XPad() = default; | ||
| 15 | 15 | ||
| 16 | void Controller_XPad::OnInit() {} | 16 | void Controller_XPad::OnInit() {} |
| 17 | 17 | ||
diff --git a/src/core/hle/service/hid/controllers/xpad.h b/src/core/hle/service/hid/controllers/xpad.h index e2007183d..ff836989f 100644 --- a/src/core/hle/service/hid/controllers/xpad.h +++ b/src/core/hle/service/hid/controllers/xpad.h | |||
| @@ -7,13 +7,13 @@ | |||
| 7 | #include "common/common_funcs.h" | 7 | #include "common/common_funcs.h" |
| 8 | #include "common/common_types.h" | 8 | #include "common/common_types.h" |
| 9 | #include "common/swap.h" | 9 | #include "common/swap.h" |
| 10 | #include "core/frontend/input.h" | ||
| 11 | #include "core/hle/service/hid/controllers/controller_base.h" | 10 | #include "core/hle/service/hid/controllers/controller_base.h" |
| 12 | 11 | ||
| 13 | namespace Service::HID { | 12 | namespace Service::HID { |
| 14 | class Controller_XPad final : public ControllerBase { | 13 | class Controller_XPad final : public ControllerBase { |
| 15 | public: | 14 | public: |
| 16 | Controller_XPad(); | 15 | Controller_XPad(); |
| 16 | ~Controller_XPad() override; | ||
| 17 | 17 | ||
| 18 | // Called when the controller is initialized | 18 | // Called when the controller is initialized |
| 19 | void OnInit() override; | 19 | void OnInit() override; |
diff --git a/src/core/hle/service/hid/hid.cpp b/src/core/hle/service/hid/hid.cpp index 8aca0f197..a9aa9ec78 100644 --- a/src/core/hle/service/hid/hid.cpp +++ b/src/core/hle/service/hid/hid.cpp | |||
| @@ -177,6 +177,7 @@ public: | |||
| 177 | {11, &Hid::ActivateTouchScreen, "ActivateTouchScreen"}, | 177 | {11, &Hid::ActivateTouchScreen, "ActivateTouchScreen"}, |
| 178 | {21, &Hid::ActivateMouse, "ActivateMouse"}, | 178 | {21, &Hid::ActivateMouse, "ActivateMouse"}, |
| 179 | {31, &Hid::ActivateKeyboard, "ActivateKeyboard"}, | 179 | {31, &Hid::ActivateKeyboard, "ActivateKeyboard"}, |
| 180 | {32, nullptr, "SendKeyboardLockKeyEvent"}, | ||
| 180 | {40, nullptr, "AcquireXpadIdEventHandle"}, | 181 | {40, nullptr, "AcquireXpadIdEventHandle"}, |
| 181 | {41, nullptr, "ReleaseXpadIdEventHandle"}, | 182 | {41, nullptr, "ReleaseXpadIdEventHandle"}, |
| 182 | {51, &Hid::ActivateXpad, "ActivateXpad"}, | 183 | {51, &Hid::ActivateXpad, "ActivateXpad"}, |
| @@ -207,6 +208,7 @@ public: | |||
| 207 | {80, nullptr, "GetGyroscopeZeroDriftMode"}, | 208 | {80, nullptr, "GetGyroscopeZeroDriftMode"}, |
| 208 | {81, nullptr, "ResetGyroscopeZeroDriftMode"}, | 209 | {81, nullptr, "ResetGyroscopeZeroDriftMode"}, |
| 209 | {82, &Hid::IsSixAxisSensorAtRest, "IsSixAxisSensorAtRest"}, | 210 | {82, &Hid::IsSixAxisSensorAtRest, "IsSixAxisSensorAtRest"}, |
| 211 | {83, nullptr, "IsFirmwareUpdateAvailableForSixAxisSensor"}, | ||
| 210 | {91, &Hid::ActivateGesture, "ActivateGesture"}, | 212 | {91, &Hid::ActivateGesture, "ActivateGesture"}, |
| 211 | {100, &Hid::SetSupportedNpadStyleSet, "SetSupportedNpadStyleSet"}, | 213 | {100, &Hid::SetSupportedNpadStyleSet, "SetSupportedNpadStyleSet"}, |
| 212 | {101, &Hid::GetSupportedNpadStyleSet, "GetSupportedNpadStyleSet"}, | 214 | {101, &Hid::GetSupportedNpadStyleSet, "GetSupportedNpadStyleSet"}, |
| @@ -252,6 +254,7 @@ public: | |||
| 252 | {307, nullptr, "FinalizeSevenSixAxisSensor"}, | 254 | {307, nullptr, "FinalizeSevenSixAxisSensor"}, |
| 253 | {308, nullptr, "SetSevenSixAxisSensorFusionStrength"}, | 255 | {308, nullptr, "SetSevenSixAxisSensorFusionStrength"}, |
| 254 | {309, nullptr, "GetSevenSixAxisSensorFusionStrength"}, | 256 | {309, nullptr, "GetSevenSixAxisSensorFusionStrength"}, |
| 257 | {310, nullptr, "ResetSevenSixAxisSensorTimestamp"}, | ||
| 255 | {400, nullptr, "IsUsbFullKeyControllerEnabled"}, | 258 | {400, nullptr, "IsUsbFullKeyControllerEnabled"}, |
| 256 | {401, nullptr, "EnableUsbFullKeyController"}, | 259 | {401, nullptr, "EnableUsbFullKeyController"}, |
| 257 | {402, nullptr, "IsUsbFullKeyControllerConnected"}, | 260 | {402, nullptr, "IsUsbFullKeyControllerConnected"}, |
| @@ -267,12 +270,24 @@ public: | |||
| 267 | {505, nullptr, "SetPalmaFrModeType"}, | 270 | {505, nullptr, "SetPalmaFrModeType"}, |
| 268 | {506, nullptr, "ReadPalmaStep"}, | 271 | {506, nullptr, "ReadPalmaStep"}, |
| 269 | {507, nullptr, "EnablePalmaStep"}, | 272 | {507, nullptr, "EnablePalmaStep"}, |
| 270 | {508, nullptr, "SuspendPalmaStep"}, | 273 | {508, nullptr, "ResetPalmaStep"}, |
| 271 | {509, nullptr, "ResetPalmaStep"}, | 274 | {509, nullptr, "ReadPalmaApplicationSection"}, |
| 272 | {510, nullptr, "ReadPalmaApplicationSection"}, | 275 | {510, nullptr, "WritePalmaApplicationSection"}, |
| 273 | {511, nullptr, "WritePalmaApplicationSection"}, | 276 | {511, nullptr, "ReadPalmaUniqueCode"}, |
| 274 | {512, nullptr, "ReadPalmaUniqueCode"}, | 277 | {512, nullptr, "SetPalmaUniqueCodeInvalid"}, |
| 275 | {513, nullptr, "SetPalmaUniqueCodeInvalid"}, | 278 | {513, nullptr, "WritePalmaActivityEntry"}, |
| 279 | {514, nullptr, "WritePalmaRgbLedPatternEntry"}, | ||
| 280 | {515, nullptr, "WritePalmaWaveEntry"}, | ||
| 281 | {516, nullptr, "SetPalmaDataBaseIdentificationVersion"}, | ||
| 282 | {517, nullptr, "GetPalmaDataBaseIdentificationVersion"}, | ||
| 283 | {518, nullptr, "SuspendPalmaFeature"}, | ||
| 284 | {519, nullptr, "GetPalmaOperationResult"}, | ||
| 285 | {520, nullptr, "ReadPalmaPlayLog"}, | ||
| 286 | {521, nullptr, "ResetPalmaPlayLog"}, | ||
| 287 | {522, nullptr, "SetIsPalmaAllConnectable"}, | ||
| 288 | {523, nullptr, "SetIsPalmaPairedConnectable"}, | ||
| 289 | {524, nullptr, "PairPalma"}, | ||
| 290 | {525, nullptr, "SetPalmaBoostMode"}, | ||
| 276 | {1000, nullptr, "SetNpadCommunicationMode"}, | 291 | {1000, nullptr, "SetNpadCommunicationMode"}, |
| 277 | {1001, nullptr, "GetNpadCommunicationMode"}, | 292 | {1001, nullptr, "GetNpadCommunicationMode"}, |
| 278 | }; | 293 | }; |
| @@ -620,6 +635,7 @@ public: | |||
| 620 | {140, nullptr, "DeactivateConsoleSixAxisSensor"}, | 635 | {140, nullptr, "DeactivateConsoleSixAxisSensor"}, |
| 621 | {141, nullptr, "GetConsoleSixAxisSensorSamplingFrequency"}, | 636 | {141, nullptr, "GetConsoleSixAxisSensorSamplingFrequency"}, |
| 622 | {142, nullptr, "DeactivateSevenSixAxisSensor"}, | 637 | {142, nullptr, "DeactivateSevenSixAxisSensor"}, |
| 638 | {143, nullptr, "GetConsoleSixAxisSensorCountStates"}, | ||
| 623 | {201, nullptr, "ActivateFirmwareUpdate"}, | 639 | {201, nullptr, "ActivateFirmwareUpdate"}, |
| 624 | {202, nullptr, "DeactivateFirmwareUpdate"}, | 640 | {202, nullptr, "DeactivateFirmwareUpdate"}, |
| 625 | {203, nullptr, "StartFirmwareUpdate"}, | 641 | {203, nullptr, "StartFirmwareUpdate"}, |
| @@ -630,12 +646,23 @@ public: | |||
| 630 | {208, nullptr, "StartFirmwareUpdateForRevert"}, | 646 | {208, nullptr, "StartFirmwareUpdateForRevert"}, |
| 631 | {209, nullptr, "GetAvailableFirmwareVersionForRevert"}, | 647 | {209, nullptr, "GetAvailableFirmwareVersionForRevert"}, |
| 632 | {210, nullptr, "IsFirmwareUpdatingDevice"}, | 648 | {210, nullptr, "IsFirmwareUpdatingDevice"}, |
| 649 | {211, nullptr, "StartFirmwareUpdateIndividual"}, | ||
| 650 | {215, nullptr, "SetUsbFirmwareForceUpdateEnabled"}, | ||
| 651 | {216, nullptr, "SetAllKuinaDevicesToFirmwareUpdateMode"}, | ||
| 633 | {221, nullptr, "UpdateControllerColor"}, | 652 | {221, nullptr, "UpdateControllerColor"}, |
| 634 | {222, nullptr, "ConnectUsbPadsAsync"}, | 653 | {222, nullptr, "ConnectUsbPadsAsync"}, |
| 635 | {223, nullptr, "DisconnectUsbPadsAsync"}, | 654 | {223, nullptr, "DisconnectUsbPadsAsync"}, |
| 636 | {224, nullptr, "UpdateDesignInfo"}, | 655 | {224, nullptr, "UpdateDesignInfo"}, |
| 637 | {225, nullptr, "GetUniquePadDriverState"}, | 656 | {225, nullptr, "GetUniquePadDriverState"}, |
| 638 | {226, nullptr, "GetSixAxisSensorDriverStates"}, | 657 | {226, nullptr, "GetSixAxisSensorDriverStates"}, |
| 658 | {227, nullptr, "GetRxPacketHistory"}, | ||
| 659 | {228, nullptr, "AcquireOperationEventHandle"}, | ||
| 660 | {229, nullptr, "ReadSerialFlash"}, | ||
| 661 | {230, nullptr, "WriteSerialFlash"}, | ||
| 662 | {231, nullptr, "GetOperationResult"}, | ||
| 663 | {232, nullptr, "EnableShipmentMode"}, | ||
| 664 | {233, nullptr, "ClearPairingInfo"}, | ||
| 665 | {234, nullptr, "GetUniquePadDeviceTypeSetInternal"}, | ||
| 639 | {301, nullptr, "GetAbstractedPadHandles"}, | 666 | {301, nullptr, "GetAbstractedPadHandles"}, |
| 640 | {302, nullptr, "GetAbstractedPadState"}, | 667 | {302, nullptr, "GetAbstractedPadState"}, |
| 641 | {303, nullptr, "GetAbstractedPadsState"}, | 668 | {303, nullptr, "GetAbstractedPadsState"}, |
| @@ -643,6 +670,8 @@ public: | |||
| 643 | {322, nullptr, "UnsetAutoPilotVirtualPadState"}, | 670 | {322, nullptr, "UnsetAutoPilotVirtualPadState"}, |
| 644 | {323, nullptr, "UnsetAllAutoPilotVirtualPadState"}, | 671 | {323, nullptr, "UnsetAllAutoPilotVirtualPadState"}, |
| 645 | {350, nullptr, "AddRegisteredDevice"}, | 672 | {350, nullptr, "AddRegisteredDevice"}, |
| 673 | {400, nullptr, "DisableExternalMcuOnNxDevice"}, | ||
| 674 | {401, nullptr, "DisableRailDeviceFiltering"}, | ||
| 646 | }; | 675 | }; |
| 647 | // clang-format on | 676 | // clang-format on |
| 648 | 677 | ||
| @@ -678,7 +707,9 @@ public: | |||
| 678 | {307, nullptr, "GetNpadSystemExtStyle"}, | 707 | {307, nullptr, "GetNpadSystemExtStyle"}, |
| 679 | {308, nullptr, "ApplyNpadSystemCommonPolicyFull"}, | 708 | {308, nullptr, "ApplyNpadSystemCommonPolicyFull"}, |
| 680 | {309, nullptr, "GetNpadFullKeyGripColor"}, | 709 | {309, nullptr, "GetNpadFullKeyGripColor"}, |
| 710 | {310, nullptr, "GetMaskedSupportedNpadStyleSet"}, | ||
| 681 | {311, nullptr, "SetNpadPlayerLedBlinkingDevice"}, | 711 | {311, nullptr, "SetNpadPlayerLedBlinkingDevice"}, |
| 712 | {312, nullptr, "SetSupportedNpadStyleSetAll"}, | ||
| 682 | {321, nullptr, "GetUniquePadsFromNpad"}, | 713 | {321, nullptr, "GetUniquePadsFromNpad"}, |
| 683 | {322, nullptr, "GetIrSensorState"}, | 714 | {322, nullptr, "GetIrSensorState"}, |
| 684 | {323, nullptr, "GetXcdHandleForNpadWithIrSensor"}, | 715 | {323, nullptr, "GetXcdHandleForNpadWithIrSensor"}, |
| @@ -703,6 +734,7 @@ public: | |||
| 703 | {546, nullptr, "AcquireDeviceRegisteredEventForControllerSupport"}, | 734 | {546, nullptr, "AcquireDeviceRegisteredEventForControllerSupport"}, |
| 704 | {547, nullptr, "GetAllowedBluetoothLinksCount"}, | 735 | {547, nullptr, "GetAllowedBluetoothLinksCount"}, |
| 705 | {548, nullptr, "GetRegisteredDevices"}, | 736 | {548, nullptr, "GetRegisteredDevices"}, |
| 737 | {549, nullptr, "GetConnectableRegisteredDevices"}, | ||
| 706 | {700, nullptr, "ActivateUniquePad"}, | 738 | {700, nullptr, "ActivateUniquePad"}, |
| 707 | {702, nullptr, "AcquireUniquePadConnectionEventHandle"}, | 739 | {702, nullptr, "AcquireUniquePadConnectionEventHandle"}, |
| 708 | {703, nullptr, "GetUniquePadIds"}, | 740 | {703, nullptr, "GetUniquePadIds"}, |
| @@ -731,6 +763,7 @@ public: | |||
| 731 | {850, nullptr, "IsUsbFullKeyControllerEnabled"}, | 763 | {850, nullptr, "IsUsbFullKeyControllerEnabled"}, |
| 732 | {851, nullptr, "EnableUsbFullKeyController"}, | 764 | {851, nullptr, "EnableUsbFullKeyController"}, |
| 733 | {852, nullptr, "IsUsbConnected"}, | 765 | {852, nullptr, "IsUsbConnected"}, |
| 766 | {870, nullptr, "IsHandheldButtonPressedOnConsoleMode"}, | ||
| 734 | {900, nullptr, "ActivateInputDetector"}, | 767 | {900, nullptr, "ActivateInputDetector"}, |
| 735 | {901, nullptr, "NotifyInputDetector"}, | 768 | {901, nullptr, "NotifyInputDetector"}, |
| 736 | {1000, nullptr, "InitializeFirmwareUpdate"}, | 769 | {1000, nullptr, "InitializeFirmwareUpdate"}, |
| @@ -750,6 +783,12 @@ public: | |||
| 750 | {1052, nullptr, "CancelSixAxisSensorAccurateUserCalibration"}, | 783 | {1052, nullptr, "CancelSixAxisSensorAccurateUserCalibration"}, |
| 751 | {1053, nullptr, "GetSixAxisSensorAccurateUserCalibrationState"}, | 784 | {1053, nullptr, "GetSixAxisSensorAccurateUserCalibrationState"}, |
| 752 | {1100, nullptr, "GetHidbusSystemServiceObject"}, | 785 | {1100, nullptr, "GetHidbusSystemServiceObject"}, |
| 786 | {1120, nullptr, "SetFirmwareHotfixUpdateSkipEnabled"}, | ||
| 787 | {1130, nullptr, "InitializeUsbFirmwareUpdate"}, | ||
| 788 | {1131, nullptr, "FinalizeUsbFirmwareUpdate"}, | ||
| 789 | {1132, nullptr, "CheckUsbFirmwareUpdateRequired"}, | ||
| 790 | {1133, nullptr, "StartUsbFirmwareUpdate"}, | ||
| 791 | {1134, nullptr, "GetUsbFirmwareUpdateState"}, | ||
| 753 | }; | 792 | }; |
| 754 | // clang-format on | 793 | // clang-format on |
| 755 | 794 | ||
| @@ -788,6 +827,7 @@ public: | |||
| 788 | {11, nullptr, "EnableJoyPollingReceiveMode"}, | 827 | {11, nullptr, "EnableJoyPollingReceiveMode"}, |
| 789 | {12, nullptr, "DisableJoyPollingReceiveMode"}, | 828 | {12, nullptr, "DisableJoyPollingReceiveMode"}, |
| 790 | {13, nullptr, "GetPollingData"}, | 829 | {13, nullptr, "GetPollingData"}, |
| 830 | {14, nullptr, "SetStatusManagerType"}, | ||
| 791 | }; | 831 | }; |
| 792 | // clang-format on | 832 | // clang-format on |
| 793 | 833 | ||
diff --git a/src/core/hle/service/lbl/lbl.cpp b/src/core/hle/service/lbl/lbl.cpp index 7321584e1..164c57e18 100644 --- a/src/core/hle/service/lbl/lbl.cpp +++ b/src/core/hle/service/lbl/lbl.cpp | |||
| @@ -18,35 +18,35 @@ public: | |||
| 18 | explicit LBL() : ServiceFramework{"lbl"} { | 18 | explicit LBL() : ServiceFramework{"lbl"} { |
| 19 | // clang-format off | 19 | // clang-format off |
| 20 | static const FunctionInfo functions[] = { | 20 | static const FunctionInfo functions[] = { |
| 21 | {0, nullptr, "Unknown1"}, | 21 | {0, nullptr, "SaveCurrentSetting"}, |
| 22 | {1, nullptr, "Unknown2"}, | 22 | {1, nullptr, "LoadCurrentSetting"}, |
| 23 | {2, nullptr, "Unknown3"}, | 23 | {2, nullptr, "SetCurrentBrightnessSetting"}, |
| 24 | {3, nullptr, "GetCurrentBacklightLevel"}, | 24 | {3, nullptr, "GetCurrentBrightnessSetting"}, |
| 25 | {4, nullptr, "Unknown4"}, | 25 | {4, nullptr, "ApplyCurrentBrightnessSettingToBacklight"}, |
| 26 | {5, nullptr, "GetAlsComputedBacklightLevel"}, | 26 | {5, nullptr, "GetBrightnessSettingAppliedToBacklight"}, |
| 27 | {6, nullptr, "TurnOffBacklight"}, | 27 | {6, nullptr, "SwitchBacklightOn"}, |
| 28 | {7, nullptr, "TurnOnBacklight"}, | 28 | {7, nullptr, "SwitchBacklightOff"}, |
| 29 | {8, nullptr, "GetBacklightStatus"}, | 29 | {8, nullptr, "GetBacklightSwitchStatus"}, |
| 30 | {9, nullptr, "Unknown5"}, | 30 | {9, nullptr, "EnableDimming"}, |
| 31 | {10, nullptr, "Unknown6"}, | 31 | {10, nullptr, "DisableDimming"}, |
| 32 | {11, nullptr, "Unknown7"}, | 32 | {11, nullptr, "IsDimmingEnabled"}, |
| 33 | {12, nullptr, "Unknown8"}, | 33 | {12, nullptr, "EnableAutoBrightnessControl"}, |
| 34 | {13, nullptr, "Unknown9"}, | 34 | {13, nullptr, "DisableAutoBrightnessControl"}, |
| 35 | {14, nullptr, "Unknown10"}, | 35 | {14, nullptr, "IsAutoBrightnessControlEnabled"}, |
| 36 | {15, nullptr, "GetAutoBrightnessSetting"}, | 36 | {15, nullptr, "SetAmbientLightSensorValue"}, |
| 37 | {16, nullptr, "ReadRawLightSensor"}, | 37 | {16, nullptr, "GetAmbientLightSensorValue"}, |
| 38 | {17, nullptr, "Unknown11"}, | 38 | {17, nullptr, "SetBrightnessReflectionDelayLevel"}, |
| 39 | {18, nullptr, "Unknown12"}, | 39 | {18, nullptr, "GetBrightnessReflectionDelayLevel"}, |
| 40 | {19, nullptr, "Unknown13"}, | 40 | {19, nullptr, "SetCurrentBrightnessMapping"}, |
| 41 | {20, nullptr, "Unknown14"}, | 41 | {20, nullptr, "GetCurrentBrightnessMapping"}, |
| 42 | {21, nullptr, "Unknown15"}, | 42 | {21, nullptr, "SetCurrentAmbientLightSensorMapping"}, |
| 43 | {22, nullptr, "Unknown16"}, | 43 | {22, nullptr, "GetCurrentAmbientLightSensorMapping"}, |
| 44 | {23, nullptr, "Unknown17"}, | 44 | {23, nullptr, "IsAmbientLightSensorAvailable"}, |
| 45 | {24, nullptr, "Unknown18"}, | 45 | {24, nullptr, "SetCurrentBrightnessSettingForVrMode"}, |
| 46 | {25, nullptr, "Unknown19"}, | 46 | {25, nullptr, "GetCurrentBrightnessSettingForVrMode"}, |
| 47 | {26, &LBL::EnableVrMode, "EnableVrMode"}, | 47 | {26, &LBL::EnableVrMode, "EnableVrMode"}, |
| 48 | {27, &LBL::DisableVrMode, "DisableVrMode"}, | 48 | {27, &LBL::DisableVrMode, "DisableVrMode"}, |
| 49 | {28, &LBL::GetVrMode, "GetVrMode"}, | 49 | {28, &LBL::IsVrModeEnabled, "IsVrModeEnabled"}, |
| 50 | }; | 50 | }; |
| 51 | // clang-format on | 51 | // clang-format on |
| 52 | 52 | ||
| @@ -72,7 +72,7 @@ private: | |||
| 72 | LOG_DEBUG(Service_LBL, "called"); | 72 | LOG_DEBUG(Service_LBL, "called"); |
| 73 | } | 73 | } |
| 74 | 74 | ||
| 75 | void GetVrMode(Kernel::HLERequestContext& ctx) { | 75 | void IsVrModeEnabled(Kernel::HLERequestContext& ctx) { |
| 76 | IPC::ResponseBuilder rb{ctx, 3}; | 76 | IPC::ResponseBuilder rb{ctx, 3}; |
| 77 | rb.Push(RESULT_SUCCESS); | 77 | rb.Push(RESULT_SUCCESS); |
| 78 | rb.Push(vr_mode_enabled); | 78 | rb.Push(vr_mode_enabled); |
diff --git a/src/core/hle/service/ldr/ldr.cpp b/src/core/hle/service/ldr/ldr.cpp index ec32faf15..d607d985e 100644 --- a/src/core/hle/service/ldr/ldr.cpp +++ b/src/core/hle/service/ldr/ldr.cpp | |||
| @@ -3,9 +3,13 @@ | |||
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <memory> | 5 | #include <memory> |
| 6 | #include <fmt/format.h> | ||
| 6 | 7 | ||
| 8 | #include "core/hle/ipc_helpers.h" | ||
| 9 | #include "core/hle/kernel/process.h" | ||
| 7 | #include "core/hle/service/ldr/ldr.h" | 10 | #include "core/hle/service/ldr/ldr.h" |
| 8 | #include "core/hle/service/service.h" | 11 | #include "core/hle/service/service.h" |
| 12 | #include "core/loader/nro.h" | ||
| 9 | 13 | ||
| 10 | namespace Service::LDR { | 14 | namespace Service::LDR { |
| 11 | 15 | ||
| @@ -59,16 +63,58 @@ public: | |||
| 59 | explicit RelocatableObject() : ServiceFramework{"ldr:ro"} { | 63 | explicit RelocatableObject() : ServiceFramework{"ldr:ro"} { |
| 60 | // clang-format off | 64 | // clang-format off |
| 61 | static const FunctionInfo functions[] = { | 65 | static const FunctionInfo functions[] = { |
| 62 | {0, nullptr, "LoadNro"}, | 66 | {0, &RelocatableObject::LoadNro, "LoadNro"}, |
| 63 | {1, nullptr, "UnloadNro"}, | 67 | {1, nullptr, "UnloadNro"}, |
| 64 | {2, nullptr, "LoadNrr"}, | 68 | {2, &RelocatableObject::LoadNrr, "LoadNrr"}, |
| 65 | {3, nullptr, "UnloadNrr"}, | 69 | {3, nullptr, "UnloadNrr"}, |
| 66 | {4, nullptr, "Initialize"}, | 70 | {4, &RelocatableObject::Initialize, "Initialize"}, |
| 67 | }; | 71 | }; |
| 68 | // clang-format on | 72 | // clang-format on |
| 69 | 73 | ||
| 70 | RegisterHandlers(functions); | 74 | RegisterHandlers(functions); |
| 71 | } | 75 | } |
| 76 | |||
| 77 | void LoadNrr(Kernel::HLERequestContext& ctx) { | ||
| 78 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 79 | rb.Push(RESULT_SUCCESS); | ||
| 80 | LOG_WARNING(Service_LDR, "(STUBBED) called"); | ||
| 81 | } | ||
| 82 | |||
| 83 | void LoadNro(Kernel::HLERequestContext& ctx) { | ||
| 84 | IPC::RequestParser rp{ctx}; | ||
| 85 | rp.Skip(2, false); | ||
| 86 | const VAddr nro_addr{rp.Pop<VAddr>()}; | ||
| 87 | const u64 nro_size{rp.Pop<u64>()}; | ||
| 88 | const VAddr bss_addr{rp.Pop<VAddr>()}; | ||
| 89 | const u64 bss_size{rp.Pop<u64>()}; | ||
| 90 | |||
| 91 | // Read NRO data from memory | ||
| 92 | std::vector<u8> nro_data(nro_size); | ||
| 93 | Memory::ReadBlock(nro_addr, nro_data.data(), nro_size); | ||
| 94 | |||
| 95 | // Load NRO as new executable module | ||
| 96 | const VAddr addr{*Core::CurrentProcess()->VMManager().FindFreeRegion(nro_size + bss_size)}; | ||
| 97 | Loader::AppLoader_NRO::LoadNro(nro_data, fmt::format("nro-{:08x}", addr), addr); | ||
| 98 | |||
| 99 | // TODO(bunnei): This is an incomplete implementation. It was tested with Super Mario Party. | ||
| 100 | // It is currently missing: | ||
| 101 | // - Signature checks with LoadNRR | ||
| 102 | // - Checking if a module has already been loaded | ||
| 103 | // - Using/validating BSS, etc. params (these are used from NRO header instead) | ||
| 104 | // - Error checking | ||
| 105 | // - ...Probably other things | ||
| 106 | |||
| 107 | IPC::ResponseBuilder rb{ctx, 4}; | ||
| 108 | rb.Push(RESULT_SUCCESS); | ||
| 109 | rb.Push(addr); | ||
| 110 | LOG_WARNING(Service_LDR, "(STUBBED) called"); | ||
| 111 | } | ||
| 112 | |||
| 113 | void Initialize(Kernel::HLERequestContext& ctx) { | ||
| 114 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 115 | rb.Push(RESULT_SUCCESS); | ||
| 116 | LOG_WARNING(Service_LDR, "(STUBBED) called"); | ||
| 117 | } | ||
| 72 | }; | 118 | }; |
| 73 | 119 | ||
| 74 | void InstallInterfaces(SM::ServiceManager& sm) { | 120 | void InstallInterfaces(SM::ServiceManager& sm) { |
diff --git a/src/core/hle/service/nfc/nfc.cpp b/src/core/hle/service/nfc/nfc.cpp index 8fec97db8..30e542542 100644 --- a/src/core/hle/service/nfc/nfc.cpp +++ b/src/core/hle/service/nfc/nfc.cpp | |||
| @@ -10,12 +10,13 @@ | |||
| 10 | #include "core/hle/service/nfc/nfc.h" | 10 | #include "core/hle/service/nfc/nfc.h" |
| 11 | #include "core/hle/service/service.h" | 11 | #include "core/hle/service/service.h" |
| 12 | #include "core/hle/service/sm/sm.h" | 12 | #include "core/hle/service/sm/sm.h" |
| 13 | #include "core/settings.h" | ||
| 13 | 14 | ||
| 14 | namespace Service::NFC { | 15 | namespace Service::NFC { |
| 15 | 16 | ||
| 16 | class IAm final : public ServiceFramework<IAm> { | 17 | class IAm final : public ServiceFramework<IAm> { |
| 17 | public: | 18 | public: |
| 18 | explicit IAm() : ServiceFramework{"IAm"} { | 19 | explicit IAm() : ServiceFramework{"NFC::IAm"} { |
| 19 | // clang-format off | 20 | // clang-format off |
| 20 | static const FunctionInfo functions[] = { | 21 | static const FunctionInfo functions[] = { |
| 21 | {0, nullptr, "Initialize"}, | 22 | {0, nullptr, "Initialize"}, |
| @@ -52,7 +53,7 @@ private: | |||
| 52 | 53 | ||
| 53 | class MFIUser final : public ServiceFramework<MFIUser> { | 54 | class MFIUser final : public ServiceFramework<MFIUser> { |
| 54 | public: | 55 | public: |
| 55 | explicit MFIUser() : ServiceFramework{"IUser"} { | 56 | explicit MFIUser() : ServiceFramework{"NFC::MFIUser"} { |
| 56 | // clang-format off | 57 | // clang-format off |
| 57 | static const FunctionInfo functions[] = { | 58 | static const FunctionInfo functions[] = { |
| 58 | {0, nullptr, "Initialize"}, | 59 | {0, nullptr, "Initialize"}, |
| @@ -100,13 +101,13 @@ private: | |||
| 100 | 101 | ||
| 101 | class IUser final : public ServiceFramework<IUser> { | 102 | class IUser final : public ServiceFramework<IUser> { |
| 102 | public: | 103 | public: |
| 103 | explicit IUser() : ServiceFramework{"IUser"} { | 104 | explicit IUser() : ServiceFramework{"NFC::IUser"} { |
| 104 | // clang-format off | 105 | // clang-format off |
| 105 | static const FunctionInfo functions[] = { | 106 | static const FunctionInfo functions[] = { |
| 106 | {0, nullptr, "Initialize"}, | 107 | {0, &IUser::InitializeOld, "InitializeOld"}, |
| 107 | {1, nullptr, "Finalize"}, | 108 | {1, &IUser::FinalizeOld, "FinalizeOld"}, |
| 108 | {2, nullptr, "GetState"}, | 109 | {2, &IUser::GetStateOld, "GetStateOld"}, |
| 109 | {3, nullptr, "IsNfcEnabled"}, | 110 | {3, &IUser::IsNfcEnabledOld, "IsNfcEnabledOld"}, |
| 110 | {400, nullptr, "Initialize"}, | 111 | {400, nullptr, "Initialize"}, |
| 111 | {401, nullptr, "Finalize"}, | 112 | {401, nullptr, "Finalize"}, |
| 112 | {402, nullptr, "GetState"}, | 113 | {402, nullptr, "GetState"}, |
| @@ -130,11 +131,47 @@ public: | |||
| 130 | 131 | ||
| 131 | RegisterHandlers(functions); | 132 | RegisterHandlers(functions); |
| 132 | } | 133 | } |
| 134 | |||
| 135 | private: | ||
| 136 | enum class NfcStates : u32 { | ||
| 137 | Finalized = 6, | ||
| 138 | }; | ||
| 139 | |||
| 140 | void InitializeOld(Kernel::HLERequestContext& ctx) { | ||
| 141 | IPC::ResponseBuilder rb{ctx, 2, 0}; | ||
| 142 | rb.Push(RESULT_SUCCESS); | ||
| 143 | |||
| 144 | // We don't deal with hardware initialization so we can just stub this. | ||
| 145 | LOG_DEBUG(Service_NFC, "called"); | ||
| 146 | } | ||
| 147 | |||
| 148 | void IsNfcEnabledOld(Kernel::HLERequestContext& ctx) { | ||
| 149 | IPC::ResponseBuilder rb{ctx, 3}; | ||
| 150 | rb.Push(RESULT_SUCCESS); | ||
| 151 | rb.PushRaw<u8>(Settings::values.enable_nfc); | ||
| 152 | |||
| 153 | LOG_DEBUG(Service_NFC, "IsNfcEnabledOld"); | ||
| 154 | } | ||
| 155 | |||
| 156 | void GetStateOld(Kernel::HLERequestContext& ctx) { | ||
| 157 | LOG_WARNING(Service_NFC, "(STUBBED) called"); | ||
| 158 | |||
| 159 | IPC::ResponseBuilder rb{ctx, 3}; | ||
| 160 | rb.Push(RESULT_SUCCESS); | ||
| 161 | rb.PushEnum(NfcStates::Finalized); // TODO(ogniK): Figure out if this matches nfp | ||
| 162 | } | ||
| 163 | |||
| 164 | void FinalizeOld(Kernel::HLERequestContext& ctx) { | ||
| 165 | LOG_WARNING(Service_NFC, "(STUBBED) called"); | ||
| 166 | |||
| 167 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 168 | rb.Push(RESULT_SUCCESS); | ||
| 169 | } | ||
| 133 | }; | 170 | }; |
| 134 | 171 | ||
| 135 | class NFC_U final : public ServiceFramework<NFC_U> { | 172 | class NFC_U final : public ServiceFramework<NFC_U> { |
| 136 | public: | 173 | public: |
| 137 | explicit NFC_U() : ServiceFramework{"nfc:u"} { | 174 | explicit NFC_U() : ServiceFramework{"nfc:user"} { |
| 138 | // clang-format off | 175 | // clang-format off |
| 139 | static const FunctionInfo functions[] = { | 176 | static const FunctionInfo functions[] = { |
| 140 | {0, &NFC_U::CreateUserInterface, "CreateUserInterface"}, | 177 | {0, &NFC_U::CreateUserInterface, "CreateUserInterface"}, |
diff --git a/src/core/hle/service/nfp/nfp.cpp b/src/core/hle/service/nfp/nfp.cpp index 39c0c1e63..c1af878fe 100644 --- a/src/core/hle/service/nfp/nfp.cpp +++ b/src/core/hle/service/nfp/nfp.cpp | |||
| @@ -2,56 +2,67 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <atomic> | ||
| 6 | |||
| 5 | #include "common/logging/log.h" | 7 | #include "common/logging/log.h" |
| 6 | #include "core/core.h" | 8 | #include "core/core.h" |
| 7 | #include "core/hle/ipc_helpers.h" | 9 | #include "core/hle/ipc_helpers.h" |
| 8 | #include "core/hle/kernel/event.h" | 10 | #include "core/hle/kernel/event.h" |
| 11 | #include "core/hle/lock.h" | ||
| 9 | #include "core/hle/service/hid/hid.h" | 12 | #include "core/hle/service/hid/hid.h" |
| 10 | #include "core/hle/service/nfp/nfp.h" | 13 | #include "core/hle/service/nfp/nfp.h" |
| 11 | #include "core/hle/service/nfp/nfp_user.h" | 14 | #include "core/hle/service/nfp/nfp_user.h" |
| 12 | 15 | ||
| 13 | namespace Service::NFP { | 16 | namespace Service::NFP { |
| 14 | 17 | ||
| 18 | namespace ErrCodes { | ||
| 19 | constexpr ResultCode ERR_TAG_FAILED(ErrorModule::NFP, | ||
| 20 | -1); // TODO(ogniK): Find the actual error code | ||
| 21 | } | ||
| 22 | |||
| 15 | Module::Interface::Interface(std::shared_ptr<Module> module, const char* name) | 23 | Module::Interface::Interface(std::shared_ptr<Module> module, const char* name) |
| 16 | : ServiceFramework(name), module(std::move(module)) {} | 24 | : ServiceFramework(name), module(std::move(module)) { |
| 25 | auto& kernel = Core::System::GetInstance().Kernel(); | ||
| 26 | nfc_tag_load = | ||
| 27 | Kernel::Event::Create(kernel, Kernel::ResetType::OneShot, "IUser:NFCTagDetected"); | ||
| 28 | } | ||
| 17 | 29 | ||
| 18 | Module::Interface::~Interface() = default; | 30 | Module::Interface::~Interface() = default; |
| 19 | 31 | ||
| 20 | class IUser final : public ServiceFramework<IUser> { | 32 | class IUser final : public ServiceFramework<IUser> { |
| 21 | public: | 33 | public: |
| 22 | IUser() : ServiceFramework("IUser") { | 34 | IUser(Module::Interface& nfp_interface) |
| 35 | : ServiceFramework("NFP::IUser"), nfp_interface(nfp_interface) { | ||
| 23 | static const FunctionInfo functions[] = { | 36 | static const FunctionInfo functions[] = { |
| 24 | {0, &IUser::Initialize, "Initialize"}, | 37 | {0, &IUser::Initialize, "Initialize"}, |
| 25 | {1, nullptr, "Finalize"}, | 38 | {1, &IUser::Finalize, "Finalize"}, |
| 26 | {2, &IUser::ListDevices, "ListDevices"}, | 39 | {2, &IUser::ListDevices, "ListDevices"}, |
| 27 | {3, nullptr, "StartDetection"}, | 40 | {3, &IUser::StartDetection, "StartDetection"}, |
| 28 | {4, nullptr, "StopDetection"}, | 41 | {4, &IUser::StopDetection, "StopDetection"}, |
| 29 | {5, nullptr, "Mount"}, | 42 | {5, &IUser::Mount, "Mount"}, |
| 30 | {6, nullptr, "Unmount"}, | 43 | {6, &IUser::Unmount, "Unmount"}, |
| 31 | {7, nullptr, "OpenApplicationArea"}, | 44 | {7, &IUser::OpenApplicationArea, "OpenApplicationArea"}, |
| 32 | {8, nullptr, "GetApplicationArea"}, | 45 | {8, &IUser::GetApplicationArea, "GetApplicationArea"}, |
| 33 | {9, nullptr, "SetApplicationArea"}, | 46 | {9, nullptr, "SetApplicationArea"}, |
| 34 | {10, nullptr, "Flush"}, | 47 | {10, nullptr, "Flush"}, |
| 35 | {11, nullptr, "Restore"}, | 48 | {11, nullptr, "Restore"}, |
| 36 | {12, nullptr, "CreateApplicationArea"}, | 49 | {12, nullptr, "CreateApplicationArea"}, |
| 37 | {13, nullptr, "GetTagInfo"}, | 50 | {13, &IUser::GetTagInfo, "GetTagInfo"}, |
| 38 | {14, nullptr, "GetRegisterInfo"}, | 51 | {14, &IUser::GetRegisterInfo, "GetRegisterInfo"}, |
| 39 | {15, nullptr, "GetCommonInfo"}, | 52 | {15, &IUser::GetCommonInfo, "GetCommonInfo"}, |
| 40 | {16, nullptr, "GetModelInfo"}, | 53 | {16, &IUser::GetModelInfo, "GetModelInfo"}, |
| 41 | {17, &IUser::AttachActivateEvent, "AttachActivateEvent"}, | 54 | {17, &IUser::AttachActivateEvent, "AttachActivateEvent"}, |
| 42 | {18, &IUser::AttachDeactivateEvent, "AttachDeactivateEvent"}, | 55 | {18, &IUser::AttachDeactivateEvent, "AttachDeactivateEvent"}, |
| 43 | {19, &IUser::GetState, "GetState"}, | 56 | {19, &IUser::GetState, "GetState"}, |
| 44 | {20, &IUser::GetDeviceState, "GetDeviceState"}, | 57 | {20, &IUser::GetDeviceState, "GetDeviceState"}, |
| 45 | {21, &IUser::GetNpadId, "GetNpadId"}, | 58 | {21, &IUser::GetNpadId, "GetNpadId"}, |
| 46 | {22, nullptr, "GetApplicationArea2"}, | 59 | {22, &IUser::GetApplicationAreaSize, "GetApplicationAreaSize"}, |
| 47 | {23, &IUser::AttachAvailabilityChangeEvent, "AttachAvailabilityChangeEvent"}, | 60 | {23, &IUser::AttachAvailabilityChangeEvent, "AttachAvailabilityChangeEvent"}, |
| 48 | {24, nullptr, "RecreateApplicationArea"}, | 61 | {24, nullptr, "RecreateApplicationArea"}, |
| 49 | }; | 62 | }; |
| 50 | RegisterHandlers(functions); | 63 | RegisterHandlers(functions); |
| 51 | 64 | ||
| 52 | auto& kernel = Core::System::GetInstance().Kernel(); | 65 | auto& kernel = Core::System::GetInstance().Kernel(); |
| 53 | activate_event = | ||
| 54 | Kernel::Event::Create(kernel, Kernel::ResetType::OneShot, "IUser:ActivateEvent"); | ||
| 55 | deactivate_event = | 66 | deactivate_event = |
| 56 | Kernel::Event::Create(kernel, Kernel::ResetType::OneShot, "IUser:DeactivateEvent"); | 67 | Kernel::Event::Create(kernel, Kernel::ResetType::OneShot, "IUser:DeactivateEvent"); |
| 57 | availability_change_event = Kernel::Event::Create(kernel, Kernel::ResetType::OneShot, | 68 | availability_change_event = Kernel::Event::Create(kernel, Kernel::ResetType::OneShot, |
| @@ -59,6 +70,17 @@ public: | |||
| 59 | } | 70 | } |
| 60 | 71 | ||
| 61 | private: | 72 | private: |
| 73 | struct TagInfo { | ||
| 74 | std::array<u8, 10> uuid; | ||
| 75 | u8 uuid_length; // TODO(ogniK): Figure out if this is actual the uuid length or does it | ||
| 76 | // mean something else | ||
| 77 | INSERT_PADDING_BYTES(0x15); | ||
| 78 | u32_le protocol; | ||
| 79 | u32_le tag_type; | ||
| 80 | INSERT_PADDING_BYTES(0x2c); | ||
| 81 | }; | ||
| 82 | static_assert(sizeof(TagInfo) == 0x54, "TagInfo is an invalid size"); | ||
| 83 | |||
| 62 | enum class State : u32 { | 84 | enum class State : u32 { |
| 63 | NonInitialized = 0, | 85 | NonInitialized = 0, |
| 64 | Initialized = 1, | 86 | Initialized = 1, |
| @@ -66,15 +88,40 @@ private: | |||
| 66 | 88 | ||
| 67 | enum class DeviceState : u32 { | 89 | enum class DeviceState : u32 { |
| 68 | Initialized = 0, | 90 | Initialized = 0, |
| 91 | SearchingForTag = 1, | ||
| 92 | TagFound = 2, | ||
| 93 | TagRemoved = 3, | ||
| 94 | TagNearby = 4, | ||
| 95 | Unknown5 = 5, | ||
| 96 | Finalized = 6 | ||
| 97 | }; | ||
| 98 | |||
| 99 | struct CommonInfo { | ||
| 100 | u16_be last_write_year; | ||
| 101 | u8 last_write_month; | ||
| 102 | u8 last_write_day; | ||
| 103 | u16_be write_counter; | ||
| 104 | u16_be version; | ||
| 105 | u32_be application_area_size; | ||
| 106 | INSERT_PADDING_BYTES(0x34); | ||
| 69 | }; | 107 | }; |
| 108 | static_assert(sizeof(CommonInfo) == 0x40, "CommonInfo is an invalid size"); | ||
| 70 | 109 | ||
| 71 | void Initialize(Kernel::HLERequestContext& ctx) { | 110 | void Initialize(Kernel::HLERequestContext& ctx) { |
| 72 | LOG_WARNING(Service_NFP, "(STUBBED) called"); | 111 | IPC::ResponseBuilder rb{ctx, 2, 0}; |
| 112 | rb.Push(RESULT_SUCCESS); | ||
| 73 | 113 | ||
| 74 | state = State::Initialized; | 114 | state = State::Initialized; |
| 75 | 115 | ||
| 76 | IPC::ResponseBuilder rb{ctx, 2}; | 116 | LOG_DEBUG(Service_NFC, "called"); |
| 117 | } | ||
| 118 | |||
| 119 | void GetState(Kernel::HLERequestContext& ctx) { | ||
| 120 | IPC::ResponseBuilder rb{ctx, 3, 0}; | ||
| 77 | rb.Push(RESULT_SUCCESS); | 121 | rb.Push(RESULT_SUCCESS); |
| 122 | rb.PushRaw<u32>(static_cast<u32>(state)); | ||
| 123 | |||
| 124 | LOG_DEBUG(Service_NFC, "called"); | ||
| 78 | } | 125 | } |
| 79 | 126 | ||
| 80 | void ListDevices(Kernel::HLERequestContext& ctx) { | 127 | void ListDevices(Kernel::HLERequestContext& ctx) { |
| @@ -83,80 +130,219 @@ private: | |||
| 83 | 130 | ||
| 84 | ctx.WriteBuffer(&device_handle, sizeof(device_handle)); | 131 | ctx.WriteBuffer(&device_handle, sizeof(device_handle)); |
| 85 | 132 | ||
| 86 | LOG_WARNING(Service_NFP, "(STUBBED) called, array_size={}", array_size); | 133 | LOG_DEBUG(Service_NFP, "called, array_size={}", array_size); |
| 87 | 134 | ||
| 88 | IPC::ResponseBuilder rb{ctx, 3}; | 135 | IPC::ResponseBuilder rb{ctx, 3}; |
| 89 | rb.Push(RESULT_SUCCESS); | 136 | rb.Push(RESULT_SUCCESS); |
| 90 | rb.Push<u32>(0); | 137 | rb.Push<u32>(1); |
| 91 | } | 138 | } |
| 92 | 139 | ||
| 93 | void AttachActivateEvent(Kernel::HLERequestContext& ctx) { | 140 | void GetNpadId(Kernel::HLERequestContext& ctx) { |
| 94 | IPC::RequestParser rp{ctx}; | 141 | IPC::RequestParser rp{ctx}; |
| 95 | const u64 dev_handle = rp.Pop<u64>(); | 142 | const u64 dev_handle = rp.Pop<u64>(); |
| 96 | LOG_WARNING(Service_NFP, "(STUBBED) called, dev_handle=0x{:X}", dev_handle); | 143 | LOG_DEBUG(Service_NFP, "called, dev_handle=0x{:X}", dev_handle); |
| 144 | IPC::ResponseBuilder rb{ctx, 3}; | ||
| 145 | rb.Push(RESULT_SUCCESS); | ||
| 146 | rb.Push<u32>(npad_id); | ||
| 147 | } | ||
| 97 | 148 | ||
| 149 | void AttachActivateEvent(Kernel::HLERequestContext& ctx) { | ||
| 150 | IPC::RequestParser rp{ctx}; | ||
| 151 | const u64 dev_handle = rp.Pop<u64>(); | ||
| 152 | LOG_DEBUG(Service_NFP, "called, dev_handle=0x{:X}", dev_handle); | ||
| 98 | IPC::ResponseBuilder rb{ctx, 2, 1}; | 153 | IPC::ResponseBuilder rb{ctx, 2, 1}; |
| 99 | rb.Push(RESULT_SUCCESS); | 154 | rb.Push(RESULT_SUCCESS); |
| 100 | rb.PushCopyObjects(activate_event); | 155 | rb.PushCopyObjects(nfp_interface.GetNFCEvent()); |
| 156 | has_attached_handle = true; | ||
| 101 | } | 157 | } |
| 102 | 158 | ||
| 103 | void AttachDeactivateEvent(Kernel::HLERequestContext& ctx) { | 159 | void AttachDeactivateEvent(Kernel::HLERequestContext& ctx) { |
| 104 | IPC::RequestParser rp{ctx}; | 160 | IPC::RequestParser rp{ctx}; |
| 105 | const u64 dev_handle = rp.Pop<u64>(); | 161 | const u64 dev_handle = rp.Pop<u64>(); |
| 106 | LOG_WARNING(Service_NFP, "(STUBBED) called, dev_handle=0x{:X}", dev_handle); | 162 | LOG_DEBUG(Service_NFP, "called, dev_handle=0x{:X}", dev_handle); |
| 107 | 163 | ||
| 108 | IPC::ResponseBuilder rb{ctx, 2, 1}; | 164 | IPC::ResponseBuilder rb{ctx, 2, 1}; |
| 109 | rb.Push(RESULT_SUCCESS); | 165 | rb.Push(RESULT_SUCCESS); |
| 110 | rb.PushCopyObjects(deactivate_event); | 166 | rb.PushCopyObjects(deactivate_event); |
| 111 | } | 167 | } |
| 112 | 168 | ||
| 113 | void GetState(Kernel::HLERequestContext& ctx) { | 169 | void StopDetection(Kernel::HLERequestContext& ctx) { |
| 114 | LOG_WARNING(Service_NFP, "(STUBBED) called"); | 170 | LOG_DEBUG(Service_NFP, "called"); |
| 115 | IPC::ResponseBuilder rb{ctx, 3}; | 171 | switch (device_state) { |
| 172 | case DeviceState::TagFound: | ||
| 173 | case DeviceState::TagNearby: | ||
| 174 | deactivate_event->Signal(); | ||
| 175 | device_state = DeviceState::Initialized; | ||
| 176 | break; | ||
| 177 | case DeviceState::SearchingForTag: | ||
| 178 | case DeviceState::TagRemoved: | ||
| 179 | device_state = DeviceState::Initialized; | ||
| 180 | break; | ||
| 181 | } | ||
| 182 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 116 | rb.Push(RESULT_SUCCESS); | 183 | rb.Push(RESULT_SUCCESS); |
| 117 | rb.Push<u32>(static_cast<u32>(state)); | ||
| 118 | } | 184 | } |
| 119 | 185 | ||
| 120 | void GetDeviceState(Kernel::HLERequestContext& ctx) { | 186 | void GetDeviceState(Kernel::HLERequestContext& ctx) { |
| 121 | LOG_WARNING(Service_NFP, "(STUBBED) called"); | 187 | LOG_DEBUG(Service_NFP, "called"); |
| 188 | auto nfc_event = nfp_interface.GetNFCEvent(); | ||
| 189 | if (!nfc_event->ShouldWait(Kernel::GetCurrentThread()) && !has_attached_handle) { | ||
| 190 | device_state = DeviceState::TagFound; | ||
| 191 | nfc_event->Clear(); | ||
| 192 | } | ||
| 193 | |||
| 122 | IPC::ResponseBuilder rb{ctx, 3}; | 194 | IPC::ResponseBuilder rb{ctx, 3}; |
| 123 | rb.Push(RESULT_SUCCESS); | 195 | rb.Push(RESULT_SUCCESS); |
| 124 | rb.Push<u32>(static_cast<u32>(device_state)); | 196 | rb.Push<u32>(static_cast<u32>(device_state)); |
| 125 | } | 197 | } |
| 126 | 198 | ||
| 127 | void GetNpadId(Kernel::HLERequestContext& ctx) { | 199 | void StartDetection(Kernel::HLERequestContext& ctx) { |
| 128 | IPC::RequestParser rp{ctx}; | 200 | LOG_DEBUG(Service_NFP, "called"); |
| 129 | const u64 dev_handle = rp.Pop<u64>(); | 201 | |
| 130 | LOG_WARNING(Service_NFP, "(STUBBED) called, dev_handle=0x{:X}", dev_handle); | 202 | if (device_state == DeviceState::Initialized || device_state == DeviceState::TagRemoved) { |
| 131 | IPC::ResponseBuilder rb{ctx, 3}; | 203 | device_state = DeviceState::SearchingForTag; |
| 204 | } | ||
| 205 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 206 | rb.Push(RESULT_SUCCESS); | ||
| 207 | } | ||
| 208 | |||
| 209 | void GetTagInfo(Kernel::HLERequestContext& ctx) { | ||
| 210 | LOG_DEBUG(Service_NFP, "called"); | ||
| 211 | |||
| 212 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 213 | auto amiibo = nfp_interface.GetAmiiboBuffer(); | ||
| 214 | TagInfo tag_info{}; | ||
| 215 | std::memcpy(tag_info.uuid.data(), amiibo.uuid.data(), sizeof(tag_info.uuid.size())); | ||
| 216 | tag_info.uuid_length = static_cast<u8>(tag_info.uuid.size()); | ||
| 217 | |||
| 218 | tag_info.protocol = 1; // TODO(ogniK): Figure out actual values | ||
| 219 | tag_info.tag_type = 2; | ||
| 220 | ctx.WriteBuffer(&tag_info, sizeof(TagInfo)); | ||
| 221 | rb.Push(RESULT_SUCCESS); | ||
| 222 | } | ||
| 223 | |||
| 224 | void Mount(Kernel::HLERequestContext& ctx) { | ||
| 225 | LOG_DEBUG(Service_NFP, "called"); | ||
| 226 | |||
| 227 | device_state = DeviceState::TagNearby; | ||
| 228 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 229 | rb.Push(RESULT_SUCCESS); | ||
| 230 | } | ||
| 231 | |||
| 232 | void GetModelInfo(Kernel::HLERequestContext& ctx) { | ||
| 233 | LOG_DEBUG(Service_NFP, "called"); | ||
| 234 | |||
| 235 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 236 | auto amiibo = nfp_interface.GetAmiiboBuffer(); | ||
| 237 | ctx.WriteBuffer(&amiibo.model_info, sizeof(amiibo.model_info)); | ||
| 238 | rb.Push(RESULT_SUCCESS); | ||
| 239 | } | ||
| 240 | |||
| 241 | void Unmount(Kernel::HLERequestContext& ctx) { | ||
| 242 | LOG_DEBUG(Service_NFP, "called"); | ||
| 243 | |||
| 244 | device_state = DeviceState::TagFound; | ||
| 245 | |||
| 246 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 247 | rb.Push(RESULT_SUCCESS); | ||
| 248 | } | ||
| 249 | |||
| 250 | void Finalize(Kernel::HLERequestContext& ctx) { | ||
| 251 | LOG_DEBUG(Service_NFP, "called"); | ||
| 252 | |||
| 253 | device_state = DeviceState::Finalized; | ||
| 254 | |||
| 255 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 132 | rb.Push(RESULT_SUCCESS); | 256 | rb.Push(RESULT_SUCCESS); |
| 133 | rb.Push<u32>(npad_id); | ||
| 134 | } | 257 | } |
| 135 | 258 | ||
| 136 | void AttachAvailabilityChangeEvent(Kernel::HLERequestContext& ctx) { | 259 | void AttachAvailabilityChangeEvent(Kernel::HLERequestContext& ctx) { |
| 137 | IPC::RequestParser rp{ctx}; | 260 | LOG_WARNING(Service_NFP, "(STUBBED) called"); |
| 138 | const u64 dev_handle = rp.Pop<u64>(); | ||
| 139 | LOG_WARNING(Service_NFP, "(STUBBED) called, dev_handle=0x{:X}", dev_handle); | ||
| 140 | 261 | ||
| 141 | IPC::ResponseBuilder rb{ctx, 2, 1}; | 262 | IPC::ResponseBuilder rb{ctx, 2, 1}; |
| 142 | rb.Push(RESULT_SUCCESS); | 263 | rb.Push(RESULT_SUCCESS); |
| 143 | rb.PushCopyObjects(availability_change_event); | 264 | rb.PushCopyObjects(availability_change_event); |
| 144 | } | 265 | } |
| 145 | 266 | ||
| 146 | const u64 device_handle{0xDEAD}; | 267 | void GetRegisterInfo(Kernel::HLERequestContext& ctx) { |
| 147 | const u32 npad_id{0}; // This is the first player controller id | 268 | LOG_WARNING(Service_NFP, "(STUBBED) called"); |
| 269 | |||
| 270 | // TODO(ogniK): Pull Mii and owner data from amiibo | ||
| 271 | |||
| 272 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 273 | rb.Push(RESULT_SUCCESS); | ||
| 274 | } | ||
| 275 | |||
| 276 | void GetCommonInfo(Kernel::HLERequestContext& ctx) { | ||
| 277 | LOG_WARNING(Service_NFP, "(STUBBED) called"); | ||
| 278 | |||
| 279 | // TODO(ogniK): Pull common information from amiibo | ||
| 280 | |||
| 281 | CommonInfo common_info{}; | ||
| 282 | common_info.application_area_size = 0; | ||
| 283 | ctx.WriteBuffer(&common_info, sizeof(CommonInfo)); | ||
| 284 | |||
| 285 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 286 | rb.Push(RESULT_SUCCESS); | ||
| 287 | } | ||
| 288 | |||
| 289 | void OpenApplicationArea(Kernel::HLERequestContext& ctx) { | ||
| 290 | LOG_DEBUG(Service_NFP, "called"); | ||
| 291 | // We don't need to worry about this since we can just open the file | ||
| 292 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 293 | rb.Push(RESULT_SUCCESS); | ||
| 294 | } | ||
| 295 | |||
| 296 | void GetApplicationAreaSize(Kernel::HLERequestContext& ctx) { | ||
| 297 | LOG_WARNING(Service_NFP, "(STUBBED) called"); | ||
| 298 | // We don't need to worry about this since we can just open the file | ||
| 299 | IPC::ResponseBuilder rb{ctx, 3}; | ||
| 300 | rb.Push(RESULT_SUCCESS); | ||
| 301 | rb.PushRaw<u32>(0); // This is from the GetCommonInfo stub | ||
| 302 | } | ||
| 303 | |||
| 304 | void GetApplicationArea(Kernel::HLERequestContext& ctx) { | ||
| 305 | LOG_WARNING(Service_NFP, "(STUBBED) called"); | ||
| 306 | |||
| 307 | // TODO(ogniK): Pull application area from amiibo | ||
| 308 | |||
| 309 | IPC::ResponseBuilder rb{ctx, 3}; | ||
| 310 | rb.Push(RESULT_SUCCESS); | ||
| 311 | rb.PushRaw<u32>(0); // This is from the GetCommonInfo stub | ||
| 312 | } | ||
| 313 | |||
| 314 | bool has_attached_handle{}; | ||
| 315 | const u64 device_handle{Common::MakeMagic('Y', 'U', 'Z', 'U')}; | ||
| 316 | const u32 npad_id{0}; // Player 1 controller | ||
| 148 | State state{State::NonInitialized}; | 317 | State state{State::NonInitialized}; |
| 149 | DeviceState device_state{DeviceState::Initialized}; | 318 | DeviceState device_state{DeviceState::Initialized}; |
| 150 | Kernel::SharedPtr<Kernel::Event> activate_event; | ||
| 151 | Kernel::SharedPtr<Kernel::Event> deactivate_event; | 319 | Kernel::SharedPtr<Kernel::Event> deactivate_event; |
| 152 | Kernel::SharedPtr<Kernel::Event> availability_change_event; | 320 | Kernel::SharedPtr<Kernel::Event> availability_change_event; |
| 321 | const Module::Interface& nfp_interface; | ||
| 153 | }; | 322 | }; |
| 154 | 323 | ||
| 155 | void Module::Interface::CreateUserInterface(Kernel::HLERequestContext& ctx) { | 324 | void Module::Interface::CreateUserInterface(Kernel::HLERequestContext& ctx) { |
| 156 | LOG_DEBUG(Service_NFP, "called"); | 325 | LOG_DEBUG(Service_NFP, "called"); |
| 157 | IPC::ResponseBuilder rb{ctx, 2, 0, 1}; | 326 | IPC::ResponseBuilder rb{ctx, 2, 0, 1}; |
| 158 | rb.Push(RESULT_SUCCESS); | 327 | rb.Push(RESULT_SUCCESS); |
| 159 | rb.PushIpcInterface<IUser>(); | 328 | rb.PushIpcInterface<IUser>(*this); |
| 329 | } | ||
| 330 | |||
| 331 | bool Module::Interface::LoadAmiibo(const std::vector<u8>& buffer) { | ||
| 332 | std::lock_guard<std::recursive_mutex> lock(HLE::g_hle_lock); | ||
| 333 | if (buffer.size() < sizeof(AmiiboFile)) { | ||
| 334 | return false; | ||
| 335 | } | ||
| 336 | |||
| 337 | std::memcpy(&amiibo, buffer.data(), sizeof(amiibo)); | ||
| 338 | nfc_tag_load->Signal(); | ||
| 339 | return true; | ||
| 340 | } | ||
| 341 | const Kernel::SharedPtr<Kernel::Event>& Module::Interface::GetNFCEvent() const { | ||
| 342 | return nfc_tag_load; | ||
| 343 | } | ||
| 344 | const Module::Interface::AmiiboFile& Module::Interface::GetAmiiboBuffer() const { | ||
| 345 | return amiibo; | ||
| 160 | } | 346 | } |
| 161 | 347 | ||
| 162 | void InstallInterfaces(SM::ServiceManager& service_manager) { | 348 | void InstallInterfaces(SM::ServiceManager& service_manager) { |
diff --git a/src/core/hle/service/nfp/nfp.h b/src/core/hle/service/nfp/nfp.h index 77df343c4..5c0ae8a54 100644 --- a/src/core/hle/service/nfp/nfp.h +++ b/src/core/hle/service/nfp/nfp.h | |||
| @@ -4,6 +4,9 @@ | |||
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <array> | ||
| 8 | #include <vector> | ||
| 9 | #include "core/hle/kernel/event.h" | ||
| 7 | #include "core/hle/service/service.h" | 10 | #include "core/hle/service/service.h" |
| 8 | 11 | ||
| 9 | namespace Service::NFP { | 12 | namespace Service::NFP { |
| @@ -15,7 +18,27 @@ public: | |||
| 15 | explicit Interface(std::shared_ptr<Module> module, const char* name); | 18 | explicit Interface(std::shared_ptr<Module> module, const char* name); |
| 16 | ~Interface() override; | 19 | ~Interface() override; |
| 17 | 20 | ||
| 21 | struct ModelInfo { | ||
| 22 | std::array<u8, 0x8> amiibo_identification_block; | ||
| 23 | INSERT_PADDING_BYTES(0x38); | ||
| 24 | }; | ||
| 25 | static_assert(sizeof(ModelInfo) == 0x40, "ModelInfo is an invalid size"); | ||
| 26 | |||
| 27 | struct AmiiboFile { | ||
| 28 | std::array<u8, 10> uuid; | ||
| 29 | INSERT_PADDING_BYTES(0x4a); | ||
| 30 | ModelInfo model_info; | ||
| 31 | }; | ||
| 32 | static_assert(sizeof(AmiiboFile) == 0x94, "AmiiboFile is an invalid size"); | ||
| 33 | |||
| 18 | void CreateUserInterface(Kernel::HLERequestContext& ctx); | 34 | void CreateUserInterface(Kernel::HLERequestContext& ctx); |
| 35 | bool LoadAmiibo(const std::vector<u8>& buffer); | ||
| 36 | const Kernel::SharedPtr<Kernel::Event>& GetNFCEvent() const; | ||
| 37 | const AmiiboFile& GetAmiiboBuffer() const; | ||
| 38 | |||
| 39 | private: | ||
| 40 | Kernel::SharedPtr<Kernel::Event> nfc_tag_load{}; | ||
| 41 | AmiiboFile amiibo{}; | ||
| 19 | 42 | ||
| 20 | protected: | 43 | protected: |
| 21 | std::shared_ptr<Module> module; | 44 | std::shared_ptr<Module> module; |
diff --git a/src/core/hle/service/nifm/nifm.cpp b/src/core/hle/service/nifm/nifm.cpp index 10611ed6a..75dcd94a3 100644 --- a/src/core/hle/service/nifm/nifm.cpp +++ b/src/core/hle/service/nifm/nifm.cpp | |||
| @@ -219,6 +219,7 @@ IGeneralService::IGeneralService() : ServiceFramework("IGeneralService") { | |||
| 219 | {35, nullptr, "GetScanData"}, | 219 | {35, nullptr, "GetScanData"}, |
| 220 | {36, nullptr, "GetCurrentAccessPoint"}, | 220 | {36, nullptr, "GetCurrentAccessPoint"}, |
| 221 | {37, nullptr, "Shutdown"}, | 221 | {37, nullptr, "Shutdown"}, |
| 222 | {38, nullptr, "GetAllowedChannels"}, | ||
| 222 | }; | 223 | }; |
| 223 | RegisterHandlers(functions); | 224 | RegisterHandlers(functions); |
| 224 | } | 225 | } |
diff --git a/src/core/hle/service/nim/nim.cpp b/src/core/hle/service/nim/nim.cpp index 261ad539c..18091c9bb 100644 --- a/src/core/hle/service/nim/nim.cpp +++ b/src/core/hle/service/nim/nim.cpp | |||
| @@ -71,6 +71,22 @@ public: | |||
| 71 | } | 71 | } |
| 72 | }; | 72 | }; |
| 73 | 73 | ||
| 74 | class NIM_ECA final : public ServiceFramework<NIM_ECA> { | ||
| 75 | public: | ||
| 76 | explicit NIM_ECA() : ServiceFramework{"nim:eca"} { | ||
| 77 | // clang-format off | ||
| 78 | static const FunctionInfo functions[] = { | ||
| 79 | {0, nullptr, "CreateServerInterface"}, | ||
| 80 | {1, nullptr, "RefreshDebugAvailability"}, | ||
| 81 | {2, nullptr, "ClearDebugResponse"}, | ||
| 82 | {3, nullptr, "RegisterDebugResponse"}, | ||
| 83 | }; | ||
| 84 | // clang-format on | ||
| 85 | |||
| 86 | RegisterHandlers(functions); | ||
| 87 | } | ||
| 88 | }; | ||
| 89 | |||
| 74 | class NIM_SHP final : public ServiceFramework<NIM_SHP> { | 90 | class NIM_SHP final : public ServiceFramework<NIM_SHP> { |
| 75 | public: | 91 | public: |
| 76 | explicit NIM_SHP() : ServiceFramework{"nim:shp"} { | 92 | explicit NIM_SHP() : ServiceFramework{"nim:shp"} { |
| @@ -214,6 +230,7 @@ private: | |||
| 214 | 230 | ||
| 215 | void InstallInterfaces(SM::ServiceManager& sm) { | 231 | void InstallInterfaces(SM::ServiceManager& sm) { |
| 216 | std::make_shared<NIM>()->InstallAsService(sm); | 232 | std::make_shared<NIM>()->InstallAsService(sm); |
| 233 | std::make_shared<NIM_ECA>()->InstallAsService(sm); | ||
| 217 | std::make_shared<NIM_SHP>()->InstallAsService(sm); | 234 | std::make_shared<NIM_SHP>()->InstallAsService(sm); |
| 218 | std::make_shared<NTC>()->InstallAsService(sm); | 235 | std::make_shared<NTC>()->InstallAsService(sm); |
| 219 | } | 236 | } |
diff --git a/src/core/hle/service/npns/npns.cpp b/src/core/hle/service/npns/npns.cpp new file mode 100644 index 000000000..ccb6f9da9 --- /dev/null +++ b/src/core/hle/service/npns/npns.cpp | |||
| @@ -0,0 +1,88 @@ | |||
| 1 | // Copyright 2018 yuzu emulator team | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include <memory> | ||
| 6 | |||
| 7 | #include "core/hle/service/npns/npns.h" | ||
| 8 | #include "core/hle/service/service.h" | ||
| 9 | #include "core/hle/service/sm/sm.h" | ||
| 10 | |||
| 11 | namespace Service::NPNS { | ||
| 12 | |||
| 13 | class NPNS_S final : public ServiceFramework<NPNS_S> { | ||
| 14 | public: | ||
| 15 | explicit NPNS_S() : ServiceFramework{"npns:s"} { | ||
| 16 | // clang-format off | ||
| 17 | static const FunctionInfo functions[] = { | ||
| 18 | {1, nullptr, "ListenAll"}, | ||
| 19 | {2, nullptr, "ListenTo"}, | ||
| 20 | {3, nullptr, "Receive"}, | ||
| 21 | {4, nullptr, "ReceiveRaw"}, | ||
| 22 | {5, nullptr, "GetReceiveEvent"}, | ||
| 23 | {6, nullptr, "ListenUndelivered"}, | ||
| 24 | {7, nullptr, "GetStateChangeEVent"}, | ||
| 25 | {11, nullptr, "SubscribeTopic"}, | ||
| 26 | {12, nullptr, "UnsubscribeTopic"}, | ||
| 27 | {13, nullptr, "QueryIsTopicExist"}, | ||
| 28 | {21, nullptr, "CreateToken"}, | ||
| 29 | {22, nullptr, "CreateTokenWithApplicationId"}, | ||
| 30 | {23, nullptr, "DestroyToken"}, | ||
| 31 | {24, nullptr, "DestroyTokenWithApplicationId"}, | ||
| 32 | {25, nullptr, "QueryIsTokenValid"}, | ||
| 33 | {31, nullptr, "UploadTokenToBaaS"}, | ||
| 34 | {32, nullptr, "DestroyTokenForBaaS"}, | ||
| 35 | {33, nullptr, "CreateTokenForBaaS"}, | ||
| 36 | {34, nullptr, "SetBaaSDeviceAccountIdList"}, | ||
| 37 | {101, nullptr, "Suspend"}, | ||
| 38 | {102, nullptr, "Resume"}, | ||
| 39 | {103, nullptr, "GetState"}, | ||
| 40 | {104, nullptr, "GetStatistics"}, | ||
| 41 | {105, nullptr, "GetPlayReportRequestEvent"}, | ||
| 42 | {111, nullptr, "GetJid"}, | ||
| 43 | {112, nullptr, "CreateJid"}, | ||
| 44 | {113, nullptr, "DestroyJid"}, | ||
| 45 | {114, nullptr, "AttachJid"}, | ||
| 46 | {115, nullptr, "DetachJid"}, | ||
| 47 | {201, nullptr, "RequestChangeStateForceTimed"}, | ||
| 48 | {102, nullptr, "RequestChangeStateForceAsync"}, | ||
| 49 | }; | ||
| 50 | // clang-format on | ||
| 51 | |||
| 52 | RegisterHandlers(functions); | ||
| 53 | } | ||
| 54 | }; | ||
| 55 | |||
| 56 | class NPNS_U final : public ServiceFramework<NPNS_U> { | ||
| 57 | public: | ||
| 58 | explicit NPNS_U() : ServiceFramework{"npns:u"} { | ||
| 59 | // clang-format off | ||
| 60 | static const FunctionInfo functions[] = { | ||
| 61 | {1, nullptr, "ListenAll"}, | ||
| 62 | {2, nullptr, "ListenTo"}, | ||
| 63 | {3, nullptr, "Receive"}, | ||
| 64 | {4, nullptr, "ReceiveRaw"}, | ||
| 65 | {5, nullptr, "GetReceiveEvent"}, | ||
| 66 | {7, nullptr, "GetStateChangeEVent"}, | ||
| 67 | {21, nullptr, "CreateToken"}, | ||
| 68 | {23, nullptr, "DestroyToken"}, | ||
| 69 | {25, nullptr, "QueryIsTokenValid"}, | ||
| 70 | {26, nullptr, "ListenToMyApplicationId"}, | ||
| 71 | {101, nullptr, "Suspend"}, | ||
| 72 | {102, nullptr, "Resume"}, | ||
| 73 | {103, nullptr, "GetState"}, | ||
| 74 | {104, nullptr, "GetStatistics"}, | ||
| 75 | {111, nullptr, "GetJid"}, | ||
| 76 | }; | ||
| 77 | // clang-format on | ||
| 78 | |||
| 79 | RegisterHandlers(functions); | ||
| 80 | } | ||
| 81 | }; | ||
| 82 | |||
| 83 | void InstallInterfaces(SM::ServiceManager& sm) { | ||
| 84 | std::make_shared<NPNS_S>()->InstallAsService(sm); | ||
| 85 | std::make_shared<NPNS_U>()->InstallAsService(sm); | ||
| 86 | } | ||
| 87 | |||
| 88 | } // namespace Service::NPNS | ||
diff --git a/src/core/hle/service/npns/npns.h b/src/core/hle/service/npns/npns.h new file mode 100644 index 000000000..861cd3e48 --- /dev/null +++ b/src/core/hle/service/npns/npns.h | |||
| @@ -0,0 +1,15 @@ | |||
| 1 | // Copyright 2018 yuzu emulator team | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | namespace Service::SM { | ||
| 8 | class ServiceManager; | ||
| 9 | } | ||
| 10 | |||
| 11 | namespace Service::NPNS { | ||
| 12 | |||
| 13 | void InstallInterfaces(SM::ServiceManager& sm); | ||
| 14 | |||
| 15 | } // namespace Service::NPNS | ||
diff --git a/src/core/hle/service/ns/ns.cpp b/src/core/hle/service/ns/ns.cpp index 98017267c..07c1381fe 100644 --- a/src/core/hle/service/ns/ns.cpp +++ b/src/core/hle/service/ns/ns.cpp | |||
| @@ -93,13 +93,23 @@ public: | |||
| 93 | {86, nullptr, "EnableApplicationCrashReport"}, | 93 | {86, nullptr, "EnableApplicationCrashReport"}, |
| 94 | {87, nullptr, "IsApplicationCrashReportEnabled"}, | 94 | {87, nullptr, "IsApplicationCrashReportEnabled"}, |
| 95 | {90, nullptr, "BoostSystemMemoryResourceLimit"}, | 95 | {90, nullptr, "BoostSystemMemoryResourceLimit"}, |
| 96 | {91, nullptr, "Unknown1"}, | ||
| 97 | {92, nullptr, "Unknown2"}, | ||
| 98 | {93, nullptr, "GetMainApplicationProgramIndex"}, | ||
| 99 | {94, nullptr, "LaunchApplication2"}, | ||
| 100 | {95, nullptr, "GetApplicationLaunchInfo"}, | ||
| 101 | {96, nullptr, "AcquireApplicationLaunchInfo"}, | ||
| 102 | {97, nullptr, "GetMainApplicationProgramIndex2"}, | ||
| 103 | {98, nullptr, "EnableApplicationAllThreadDumpOnCrash"}, | ||
| 96 | {100, nullptr, "ResetToFactorySettings"}, | 104 | {100, nullptr, "ResetToFactorySettings"}, |
| 97 | {101, nullptr, "ResetToFactorySettingsWithoutUserSaveData"}, | 105 | {101, nullptr, "ResetToFactorySettingsWithoutUserSaveData"}, |
| 98 | {102, nullptr, "ResetToFactorySettingsForRefurbishment"}, | 106 | {102, nullptr, "ResetToFactorySettingsForRefurbishment"}, |
| 99 | {200, nullptr, "CalculateUserSaveDataStatistics"}, | 107 | {200, nullptr, "CalculateUserSaveDataStatistics"}, |
| 100 | {201, nullptr, "DeleteUserSaveDataAll"}, | 108 | {201, nullptr, "DeleteUserSaveDataAll"}, |
| 101 | {210, nullptr, "DeleteUserSystemSaveData"}, | 109 | {210, nullptr, "DeleteUserSystemSaveData"}, |
| 110 | {211, nullptr, "DeleteSaveData"}, | ||
| 102 | {220, nullptr, "UnregisterNetworkServiceAccount"}, | 111 | {220, nullptr, "UnregisterNetworkServiceAccount"}, |
| 112 | {221, nullptr, "UnregisterNetworkServiceAccountWithUserSaveDataDeletion"}, | ||
| 103 | {300, nullptr, "GetApplicationShellEvent"}, | 113 | {300, nullptr, "GetApplicationShellEvent"}, |
| 104 | {301, nullptr, "PopApplicationShellEventInfo"}, | 114 | {301, nullptr, "PopApplicationShellEventInfo"}, |
| 105 | {302, nullptr, "LaunchLibraryApplet"}, | 115 | {302, nullptr, "LaunchLibraryApplet"}, |
| @@ -114,6 +124,7 @@ public: | |||
| 114 | {403, nullptr, "GetMaxApplicationControlCacheCount"}, | 124 | {403, nullptr, "GetMaxApplicationControlCacheCount"}, |
| 115 | {404, nullptr, "InvalidateApplicationControlCache"}, | 125 | {404, nullptr, "InvalidateApplicationControlCache"}, |
| 116 | {405, nullptr, "ListApplicationControlCacheEntryInfo"}, | 126 | {405, nullptr, "ListApplicationControlCacheEntryInfo"}, |
| 127 | {406, nullptr, "GetApplicationControlProperty"}, | ||
| 117 | {502, nullptr, "RequestCheckGameCardRegistration"}, | 128 | {502, nullptr, "RequestCheckGameCardRegistration"}, |
| 118 | {503, nullptr, "RequestGameCardRegistrationGoldPoint"}, | 129 | {503, nullptr, "RequestGameCardRegistrationGoldPoint"}, |
| 119 | {504, nullptr, "RequestRegisterGameCard"}, | 130 | {504, nullptr, "RequestRegisterGameCard"}, |
| @@ -129,6 +140,7 @@ public: | |||
| 129 | {604, nullptr, "RegisterContentsExternalKey"}, | 140 | {604, nullptr, "RegisterContentsExternalKey"}, |
| 130 | {605, nullptr, "ListApplicationContentMetaStatusWithRightsCheck"}, | 141 | {605, nullptr, "ListApplicationContentMetaStatusWithRightsCheck"}, |
| 131 | {606, nullptr, "GetContentMetaStorage"}, | 142 | {606, nullptr, "GetContentMetaStorage"}, |
| 143 | {607, nullptr, "ListAvailableAddOnContent"}, | ||
| 132 | {700, nullptr, "PushDownloadTaskList"}, | 144 | {700, nullptr, "PushDownloadTaskList"}, |
| 133 | {701, nullptr, "ClearTaskStatusList"}, | 145 | {701, nullptr, "ClearTaskStatusList"}, |
| 134 | {702, nullptr, "RequestDownloadTaskList"}, | 146 | {702, nullptr, "RequestDownloadTaskList"}, |
| @@ -148,6 +160,9 @@ public: | |||
| 148 | {907, nullptr, "WithdrawApplicationUpdateRequest"}, | 160 | {907, nullptr, "WithdrawApplicationUpdateRequest"}, |
| 149 | {908, nullptr, "ListApplicationRecordInstalledContentMeta"}, | 161 | {908, nullptr, "ListApplicationRecordInstalledContentMeta"}, |
| 150 | {909, nullptr, "WithdrawCleanupAddOnContentsWithNoRightsRecommendation"}, | 162 | {909, nullptr, "WithdrawCleanupAddOnContentsWithNoRightsRecommendation"}, |
| 163 | {910, nullptr, "Unknown3"}, | ||
| 164 | {911, nullptr, "SetPreInstalledApplication"}, | ||
| 165 | {912, nullptr, "ClearPreInstalledApplicationFlag"}, | ||
| 151 | {1000, nullptr, "RequestVerifyApplicationDeprecated"}, | 166 | {1000, nullptr, "RequestVerifyApplicationDeprecated"}, |
| 152 | {1001, nullptr, "CorruptApplicationForDebug"}, | 167 | {1001, nullptr, "CorruptApplicationForDebug"}, |
| 153 | {1002, nullptr, "RequestVerifyAddOnContentsRights"}, | 168 | {1002, nullptr, "RequestVerifyAddOnContentsRights"}, |
| @@ -162,6 +177,8 @@ public: | |||
| 162 | {1305, nullptr, "TryDeleteRunningApplicationEntity"}, | 177 | {1305, nullptr, "TryDeleteRunningApplicationEntity"}, |
| 163 | {1306, nullptr, "TryDeleteRunningApplicationCompletely"}, | 178 | {1306, nullptr, "TryDeleteRunningApplicationCompletely"}, |
| 164 | {1307, nullptr, "TryDeleteRunningApplicationContentEntities"}, | 179 | {1307, nullptr, "TryDeleteRunningApplicationContentEntities"}, |
| 180 | {1308, nullptr, "DeleteApplicationCompletelyForDebug"}, | ||
| 181 | {1309, nullptr, "CleanupUnavailableAddOnContents"}, | ||
| 165 | {1400, nullptr, "PrepareShutdown"}, | 182 | {1400, nullptr, "PrepareShutdown"}, |
| 166 | {1500, nullptr, "FormatSdCard"}, | 183 | {1500, nullptr, "FormatSdCard"}, |
| 167 | {1501, nullptr, "NeedsSystemUpdateToFormatSdCard"}, | 184 | {1501, nullptr, "NeedsSystemUpdateToFormatSdCard"}, |
| @@ -199,6 +216,28 @@ public: | |||
| 199 | {2015, nullptr, "CompareSystemDeliveryInfo"}, | 216 | {2015, nullptr, "CompareSystemDeliveryInfo"}, |
| 200 | {2016, nullptr, "ListNotCommittedContentMeta"}, | 217 | {2016, nullptr, "ListNotCommittedContentMeta"}, |
| 201 | {2017, nullptr, "CreateDownloadTask"}, | 218 | {2017, nullptr, "CreateDownloadTask"}, |
| 219 | {2018, nullptr, "Unknown4"}, | ||
| 220 | {2050, nullptr, "Unknown5"}, | ||
| 221 | {2100, nullptr, "Unknown6"}, | ||
| 222 | {2101, nullptr, "Unknown7"}, | ||
| 223 | {2150, nullptr, "CreateRightsEnvironment"}, | ||
| 224 | {2151, nullptr, "DestroyRightsEnvironment"}, | ||
| 225 | {2152, nullptr, "ActivateRightsEnvironment"}, | ||
| 226 | {2153, nullptr, "DeactivateRightsEnvironment"}, | ||
| 227 | {2154, nullptr, "ForceActivateRightsContextForExit"}, | ||
| 228 | {2160, nullptr, "AddTargetApplicationToRightsEnvironment"}, | ||
| 229 | {2161, nullptr, "SetUsersToRightsEnvironment"}, | ||
| 230 | {2170, nullptr, "GetRightsEnvironmentStatus"}, | ||
| 231 | {2171, nullptr, "GetRightsEnvironmentStatusChangedEvent"}, | ||
| 232 | {2180, nullptr, "RequestExtendRightsInRightsEnvironment"}, | ||
| 233 | {2181, nullptr, "GetLastResultOfExtendRightsInRightsEnvironment"}, | ||
| 234 | {2182, nullptr, "SetActiveRightsContextUsingStateToRightsEnvironment"}, | ||
| 235 | {2190, nullptr, "GetRightsEnvironmentHandleForApplication"}, | ||
| 236 | {2199, nullptr, "GetRightsEnvironmentCountForDebug"}, | ||
| 237 | {2200, nullptr, "Unknown8"}, | ||
| 238 | {2201, nullptr, "Unknown9"}, | ||
| 239 | {2250, nullptr, "Unknown10"}, | ||
| 240 | {2300, nullptr, "Unknown11"}, | ||
| 202 | }; | 241 | }; |
| 203 | // clang-format on | 242 | // clang-format on |
| 204 | 243 | ||
| @@ -348,12 +387,15 @@ public: | |||
| 348 | {0, nullptr, "LaunchProgram"}, | 387 | {0, nullptr, "LaunchProgram"}, |
| 349 | {1, nullptr, "TerminateProcess"}, | 388 | {1, nullptr, "TerminateProcess"}, |
| 350 | {2, nullptr, "TerminateProgram"}, | 389 | {2, nullptr, "TerminateProgram"}, |
| 351 | {3, nullptr, "GetShellEventHandle"}, | 390 | {4, nullptr, "GetShellEventHandle"}, |
| 352 | {4, nullptr, "GetShellEventInfo"}, | 391 | {5, nullptr, "GetShellEventInfo"}, |
| 353 | {5, nullptr, "TerminateApplication"}, | 392 | {6, nullptr, "TerminateApplication"}, |
| 354 | {6, nullptr, "PrepareLaunchProgramFromHost"}, | 393 | {7, nullptr, "PrepareLaunchProgramFromHost"}, |
| 355 | {7, nullptr, "LaunchApplication"}, | 394 | {8, nullptr, "LaunchApplication"}, |
| 356 | {8, nullptr, "LaunchApplicationWithStorageId"}, | 395 | {9, nullptr, "LaunchApplicationWithStorageId"}, |
| 396 | {10, nullptr, "TerminateApplication2"}, | ||
| 397 | {11, nullptr, "GetRunningApplicationProcessId"}, | ||
| 398 | {12, nullptr, "SetCurrentApplicationRightsEnvironmentCanBeActive"}, | ||
| 357 | }; | 399 | }; |
| 358 | // clang-format on | 400 | // clang-format on |
| 359 | 401 | ||
| @@ -388,6 +430,7 @@ public: | |||
| 388 | {19, nullptr, "GetReceivedEulaDataSize"}, | 430 | {19, nullptr, "GetReceivedEulaDataSize"}, |
| 389 | {20, nullptr, "GetReceivedEulaData"}, | 431 | {20, nullptr, "GetReceivedEulaData"}, |
| 390 | {21, nullptr, "SetupToReceiveSystemUpdate"}, | 432 | {21, nullptr, "SetupToReceiveSystemUpdate"}, |
| 433 | {22, nullptr, "RequestCheckLatestUpdateIncludesRebootlessUpdate"}, | ||
| 391 | }; | 434 | }; |
| 392 | // clang-format on | 435 | // clang-format on |
| 393 | 436 | ||
diff --git a/src/core/hle/service/prepo/prepo.cpp b/src/core/hle/service/prepo/prepo.cpp index 6a9eccfb5..e4fcee9f8 100644 --- a/src/core/hle/service/prepo/prepo.cpp +++ b/src/core/hle/service/prepo/prepo.cpp | |||
| @@ -14,20 +14,24 @@ public: | |||
| 14 | explicit PlayReport(const char* name) : ServiceFramework{name} { | 14 | explicit PlayReport(const char* name) : ServiceFramework{name} { |
| 15 | // clang-format off | 15 | // clang-format off |
| 16 | static const FunctionInfo functions[] = { | 16 | static const FunctionInfo functions[] = { |
| 17 | {10100, nullptr, "SaveReport"}, | 17 | {10100, nullptr, "SaveReportOld"}, |
| 18 | {10101, &PlayReport::SaveReportWithUser, "SaveReportWithUser"}, | 18 | {10101, &PlayReport::SaveReportWithUserOld, "SaveReportWithUserOld"}, |
| 19 | {10102, nullptr, "SaveReport"}, | ||
| 20 | {10103, nullptr, "SaveReportWithUser"}, | ||
| 19 | {10200, nullptr, "RequestImmediateTransmission"}, | 21 | {10200, nullptr, "RequestImmediateTransmission"}, |
| 20 | {10300, nullptr, "GetTransmissionStatus"}, | 22 | {10300, nullptr, "GetTransmissionStatus"}, |
| 21 | {20100, nullptr, "SaveSystemReport"}, | 23 | {20100, nullptr, "SaveSystemReport"}, |
| 22 | {20200, nullptr, "SetOperationMode"}, | ||
| 23 | {20101, nullptr, "SaveSystemReportWithUser"}, | 24 | {20101, nullptr, "SaveSystemReportWithUser"}, |
| 25 | {20200, nullptr, "SetOperationMode"}, | ||
| 24 | {30100, nullptr, "ClearStorage"}, | 26 | {30100, nullptr, "ClearStorage"}, |
| 27 | {30200, nullptr, "ClearStatistics"}, | ||
| 28 | {30300, nullptr, "GetStorageUsage"}, | ||
| 29 | {30400, nullptr, "GetStatistics"}, | ||
| 30 | {30401, nullptr, "GetThroughputHistory"}, | ||
| 31 | {30500, nullptr, "GetLastUploadError"}, | ||
| 25 | {40100, nullptr, "IsUserAgreementCheckEnabled"}, | 32 | {40100, nullptr, "IsUserAgreementCheckEnabled"}, |
| 26 | {40101, nullptr, "SetUserAgreementCheckEnabled"}, | 33 | {40101, nullptr, "SetUserAgreementCheckEnabled"}, |
| 27 | {90100, nullptr, "GetStorageUsage"}, | 34 | {90100, nullptr, "ReadAllReportFiles"}, |
| 28 | {90200, nullptr, "GetStatistics"}, | ||
| 29 | {90201, nullptr, "GetThroughputHistory"}, | ||
| 30 | {90300, nullptr, "GetLastUploadError"}, | ||
| 31 | }; | 35 | }; |
| 32 | // clang-format on | 36 | // clang-format on |
| 33 | 37 | ||
| @@ -35,7 +39,7 @@ public: | |||
| 35 | } | 39 | } |
| 36 | 40 | ||
| 37 | private: | 41 | private: |
| 38 | void SaveReportWithUser(Kernel::HLERequestContext& ctx) { | 42 | void SaveReportWithUserOld(Kernel::HLERequestContext& ctx) { |
| 39 | // TODO(ogniK): Do we want to add play report? | 43 | // TODO(ogniK): Do we want to add play report? |
| 40 | LOG_WARNING(Service_PREPO, "(STUBBED) called"); | 44 | LOG_WARNING(Service_PREPO, "(STUBBED) called"); |
| 41 | 45 | ||
| @@ -46,6 +50,7 @@ private: | |||
| 46 | 50 | ||
| 47 | void InstallInterfaces(SM::ServiceManager& service_manager) { | 51 | void InstallInterfaces(SM::ServiceManager& service_manager) { |
| 48 | std::make_shared<PlayReport>("prepo:a")->InstallAsService(service_manager); | 52 | std::make_shared<PlayReport>("prepo:a")->InstallAsService(service_manager); |
| 53 | std::make_shared<PlayReport>("prepo:a2")->InstallAsService(service_manager); | ||
| 49 | std::make_shared<PlayReport>("prepo:m")->InstallAsService(service_manager); | 54 | std::make_shared<PlayReport>("prepo:m")->InstallAsService(service_manager); |
| 50 | std::make_shared<PlayReport>("prepo:s")->InstallAsService(service_manager); | 55 | std::make_shared<PlayReport>("prepo:s")->InstallAsService(service_manager); |
| 51 | std::make_shared<PlayReport>("prepo:u")->InstallAsService(service_manager); | 56 | std::make_shared<PlayReport>("prepo:u")->InstallAsService(service_manager); |
diff --git a/src/core/hle/service/ptm/psm.cpp b/src/core/hle/service/ptm/psm.cpp new file mode 100644 index 000000000..c2d5fda94 --- /dev/null +++ b/src/core/hle/service/ptm/psm.cpp | |||
| @@ -0,0 +1,71 @@ | |||
| 1 | // Copyright 2018 yuzu emulator team | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include <memory> | ||
| 6 | |||
| 7 | #include "common/logging/log.h" | ||
| 8 | #include "core/hle/ipc_helpers.h" | ||
| 9 | #include "core/hle/service/ptm/psm.h" | ||
| 10 | #include "core/hle/service/service.h" | ||
| 11 | #include "core/hle/service/sm/sm.h" | ||
| 12 | |||
| 13 | namespace Service::PSM { | ||
| 14 | |||
| 15 | constexpr u32 BATTERY_FULLY_CHARGED = 100; // 100% Full | ||
| 16 | constexpr u32 BATTERY_CURRENTLY_CHARGING = 1; // Plugged into an official dock | ||
| 17 | |||
| 18 | class PSM final : public ServiceFramework<PSM> { | ||
| 19 | public: | ||
| 20 | explicit PSM() : ServiceFramework{"psm"} { | ||
| 21 | // clang-format off | ||
| 22 | static const FunctionInfo functions[] = { | ||
| 23 | {0, &PSM::GetBatteryChargePercentage, "GetBatteryChargePercentage"}, | ||
| 24 | {1, &PSM::GetChargerType, "GetChargerType"}, | ||
| 25 | {2, nullptr, "EnableBatteryCharging"}, | ||
| 26 | {3, nullptr, "DisableBatteryCharging"}, | ||
| 27 | {4, nullptr, "IsBatteryChargingEnabled"}, | ||
| 28 | {5, nullptr, "AcquireControllerPowerSupply"}, | ||
| 29 | {6, nullptr, "ReleaseControllerPowerSupply"}, | ||
| 30 | {7, nullptr, "OpenSession"}, | ||
| 31 | {8, nullptr, "EnableEnoughPowerChargeEmulation"}, | ||
| 32 | {9, nullptr, "DisableEnoughPowerChargeEmulation"}, | ||
| 33 | {10, nullptr, "EnableFastBatteryCharging"}, | ||
| 34 | {11, nullptr, "DisableFastBatteryCharging"}, | ||
| 35 | {12, nullptr, "GetBatteryVoltageState"}, | ||
| 36 | {13, nullptr, "GetRawBatteryChargePercentage"}, | ||
| 37 | {14, nullptr, "IsEnoughPowerSupplied"}, | ||
| 38 | {15, nullptr, "GetBatteryAgePercentage"}, | ||
| 39 | {16, nullptr, "GetBatteryChargeInfoEvent"}, | ||
| 40 | {17, nullptr, "GetBatteryChargeInfoFields"}, | ||
| 41 | }; | ||
| 42 | // clang-format on | ||
| 43 | |||
| 44 | RegisterHandlers(functions); | ||
| 45 | } | ||
| 46 | |||
| 47 | ~PSM() override = default; | ||
| 48 | |||
| 49 | private: | ||
| 50 | void GetBatteryChargePercentage(Kernel::HLERequestContext& ctx) { | ||
| 51 | LOG_WARNING(Service_PSM, "(STUBBED) called"); | ||
| 52 | |||
| 53 | IPC::ResponseBuilder rb{ctx, 3}; | ||
| 54 | rb.Push(RESULT_SUCCESS); | ||
| 55 | rb.Push<u32>(BATTERY_FULLY_CHARGED); | ||
| 56 | } | ||
| 57 | |||
| 58 | void GetChargerType(Kernel::HLERequestContext& ctx) { | ||
| 59 | LOG_WARNING(Service_PSM, "(STUBBED) called"); | ||
| 60 | |||
| 61 | IPC::ResponseBuilder rb{ctx, 3}; | ||
| 62 | rb.Push(RESULT_SUCCESS); | ||
| 63 | rb.Push<u32>(BATTERY_CURRENTLY_CHARGING); | ||
| 64 | } | ||
| 65 | }; | ||
| 66 | |||
| 67 | void InstallInterfaces(SM::ServiceManager& sm) { | ||
| 68 | std::make_shared<PSM>()->InstallAsService(sm); | ||
| 69 | } | ||
| 70 | |||
| 71 | } // namespace Service::PSM | ||
diff --git a/src/core/hle/service/ptm/psm.h b/src/core/hle/service/ptm/psm.h new file mode 100644 index 000000000..a286793ae --- /dev/null +++ b/src/core/hle/service/ptm/psm.h | |||
| @@ -0,0 +1,15 @@ | |||
| 1 | // Copyright 2018 yuzu emulator team | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | namespace Service::SM { | ||
| 8 | class ServiceManager; | ||
| 9 | } | ||
| 10 | |||
| 11 | namespace Service::PSM { | ||
| 12 | |||
| 13 | void InstallInterfaces(SM::ServiceManager& sm); | ||
| 14 | |||
| 15 | } // namespace Service::PSM | ||
diff --git a/src/core/hle/service/service.cpp b/src/core/hle/service/service.cpp index a225cb4cb..a4cf45267 100644 --- a/src/core/hle/service/service.cpp +++ b/src/core/hle/service/service.cpp | |||
| @@ -22,7 +22,7 @@ | |||
| 22 | #include "core/hle/service/apm/apm.h" | 22 | #include "core/hle/service/apm/apm.h" |
| 23 | #include "core/hle/service/arp/arp.h" | 23 | #include "core/hle/service/arp/arp.h" |
| 24 | #include "core/hle/service/audio/audio.h" | 24 | #include "core/hle/service/audio/audio.h" |
| 25 | #include "core/hle/service/bcat/bcat.h" | 25 | #include "core/hle/service/bcat/module.h" |
| 26 | #include "core/hle/service/bpc/bpc.h" | 26 | #include "core/hle/service/bpc/bpc.h" |
| 27 | #include "core/hle/service/btdrv/btdrv.h" | 27 | #include "core/hle/service/btdrv/btdrv.h" |
| 28 | #include "core/hle/service/btm/btm.h" | 28 | #include "core/hle/service/btm/btm.h" |
| @@ -48,15 +48,17 @@ | |||
| 48 | #include "core/hle/service/nfp/nfp.h" | 48 | #include "core/hle/service/nfp/nfp.h" |
| 49 | #include "core/hle/service/nifm/nifm.h" | 49 | #include "core/hle/service/nifm/nifm.h" |
| 50 | #include "core/hle/service/nim/nim.h" | 50 | #include "core/hle/service/nim/nim.h" |
| 51 | #include "core/hle/service/npns/npns.h" | ||
| 51 | #include "core/hle/service/ns/ns.h" | 52 | #include "core/hle/service/ns/ns.h" |
| 52 | #include "core/hle/service/nvdrv/nvdrv.h" | 53 | #include "core/hle/service/nvdrv/nvdrv.h" |
| 53 | #include "core/hle/service/nvflinger/nvflinger.h" | 54 | #include "core/hle/service/nvflinger/nvflinger.h" |
| 54 | #include "core/hle/service/pcie/pcie.h" | 55 | #include "core/hle/service/pcie/pcie.h" |
| 55 | #include "core/hle/service/pctl/pctl.h" | 56 | #include "core/hle/service/pctl/module.h" |
| 56 | #include "core/hle/service/pcv/pcv.h" | 57 | #include "core/hle/service/pcv/pcv.h" |
| 57 | #include "core/hle/service/pm/pm.h" | 58 | #include "core/hle/service/pm/pm.h" |
| 58 | #include "core/hle/service/prepo/prepo.h" | 59 | #include "core/hle/service/prepo/prepo.h" |
| 59 | #include "core/hle/service/psc/psc.h" | 60 | #include "core/hle/service/psc/psc.h" |
| 61 | #include "core/hle/service/ptm/psm.h" | ||
| 60 | #include "core/hle/service/service.h" | 62 | #include "core/hle/service/service.h" |
| 61 | #include "core/hle/service/set/settings.h" | 63 | #include "core/hle/service/set/settings.h" |
| 62 | #include "core/hle/service/sm/sm.h" | 64 | #include "core/hle/service/sm/sm.h" |
| @@ -236,6 +238,7 @@ void Init(std::shared_ptr<SM::ServiceManager>& sm, FileSys::VfsFilesystem& vfs) | |||
| 236 | NFP::InstallInterfaces(*sm); | 238 | NFP::InstallInterfaces(*sm); |
| 237 | NIFM::InstallInterfaces(*sm); | 239 | NIFM::InstallInterfaces(*sm); |
| 238 | NIM::InstallInterfaces(*sm); | 240 | NIM::InstallInterfaces(*sm); |
| 241 | NPNS::InstallInterfaces(*sm); | ||
| 239 | NS::InstallInterfaces(*sm); | 242 | NS::InstallInterfaces(*sm); |
| 240 | Nvidia::InstallInterfaces(*sm, *nv_flinger); | 243 | Nvidia::InstallInterfaces(*sm, *nv_flinger); |
| 241 | PCIe::InstallInterfaces(*sm); | 244 | PCIe::InstallInterfaces(*sm); |
| @@ -244,6 +247,7 @@ void Init(std::shared_ptr<SM::ServiceManager>& sm, FileSys::VfsFilesystem& vfs) | |||
| 244 | PlayReport::InstallInterfaces(*sm); | 247 | PlayReport::InstallInterfaces(*sm); |
| 245 | PM::InstallInterfaces(*sm); | 248 | PM::InstallInterfaces(*sm); |
| 246 | PSC::InstallInterfaces(*sm); | 249 | PSC::InstallInterfaces(*sm); |
| 250 | PSM::InstallInterfaces(*sm); | ||
| 247 | Set::InstallInterfaces(*sm); | 251 | Set::InstallInterfaces(*sm); |
| 248 | Sockets::InstallInterfaces(*sm); | 252 | Sockets::InstallInterfaces(*sm); |
| 249 | SPL::InstallInterfaces(*sm); | 253 | SPL::InstallInterfaces(*sm); |
diff --git a/src/core/hle/service/set/set_cal.cpp b/src/core/hle/service/set/set_cal.cpp index 5af356d10..34654bb07 100644 --- a/src/core/hle/service/set/set_cal.cpp +++ b/src/core/hle/service/set/set_cal.cpp | |||
| @@ -39,7 +39,8 @@ SET_CAL::SET_CAL() : ServiceFramework("set:cal") { | |||
| 39 | {29, nullptr, "GetAmiiboEcqvBlsKey"}, | 39 | {29, nullptr, "GetAmiiboEcqvBlsKey"}, |
| 40 | {30, nullptr, "GetAmiiboEcqvBlsCertificate"}, | 40 | {30, nullptr, "GetAmiiboEcqvBlsCertificate"}, |
| 41 | {31, nullptr, "GetAmiiboEcqvBlsRootCertificate"}, | 41 | {31, nullptr, "GetAmiiboEcqvBlsRootCertificate"}, |
| 42 | {32, nullptr, "GetUnknownId"}, | 42 | {32, nullptr, "GetUsbTypeCPowerSourceCircuitVersion"}, |
| 43 | {33, nullptr, "GetBatteryVersion"}, | ||
| 43 | }; | 44 | }; |
| 44 | RegisterHandlers(functions); | 45 | RegisterHandlers(functions); |
| 45 | } | 46 | } |
diff --git a/src/core/hle/service/usb/usb.cpp b/src/core/hle/service/usb/usb.cpp index e7fb5a419..c489da071 100644 --- a/src/core/hle/service/usb/usb.cpp +++ b/src/core/hle/service/usb/usb.cpp | |||
| @@ -67,15 +67,15 @@ public: | |||
| 67 | explicit IClientEpSession() : ServiceFramework{"IClientEpSession"} { | 67 | explicit IClientEpSession() : ServiceFramework{"IClientEpSession"} { |
| 68 | // clang-format off | 68 | // clang-format off |
| 69 | static const FunctionInfo functions[] = { | 69 | static const FunctionInfo functions[] = { |
| 70 | {0, nullptr, "Unknown1"}, | 70 | {0, nullptr, "Open"}, |
| 71 | {1, nullptr, "Unknown2"}, | 71 | {1, nullptr, "Close"}, |
| 72 | {2, nullptr, "Unknown3"}, | 72 | {2, nullptr, "Unknown1"}, |
| 73 | {3, nullptr, "Unknown4"}, | 73 | {3, nullptr, "Populate"}, |
| 74 | {4, nullptr, "PostBufferAsync"}, | 74 | {4, nullptr, "PostBufferAsync"}, |
| 75 | {5, nullptr, "Unknown5"}, | 75 | {5, nullptr, "GetXferReport"}, |
| 76 | {6, nullptr, "Unknown6"}, | 76 | {6, nullptr, "Unknown2"}, |
| 77 | {7, nullptr, "Unknown7"}, | 77 | {7, nullptr, "Unknown3"}, |
| 78 | {8, nullptr, "Unknown8"}, | 78 | {8, nullptr, "Unknown4"}, |
| 79 | }; | 79 | }; |
| 80 | // clang-format on | 80 | // clang-format on |
| 81 | 81 | ||
| @@ -89,15 +89,15 @@ public: | |||
| 89 | // clang-format off | 89 | // clang-format off |
| 90 | static const FunctionInfo functions[] = { | 90 | static const FunctionInfo functions[] = { |
| 91 | {0, nullptr, "Unknown1"}, | 91 | {0, nullptr, "Unknown1"}, |
| 92 | {1, nullptr, "Unknown2"}, | 92 | {1, nullptr, "SetInterface"}, |
| 93 | {2, nullptr, "Unknown3"}, | 93 | {2, nullptr, "GetInterface"}, |
| 94 | {3, nullptr, "Unknown4"}, | 94 | {3, nullptr, "GetAlternateInterface"}, |
| 95 | {4, nullptr, "Unknown5"}, | 95 | {4, nullptr, "GetCurrentFrame"}, |
| 96 | {5, nullptr, "CtrlXferAsync"}, | 96 | {5, nullptr, "CtrlXferAsync"}, |
| 97 | {6, nullptr, "Unknown6"}, | 97 | {6, nullptr, "Unknown2"}, |
| 98 | {7, nullptr, "GetCtrlXferReport"}, | 98 | {7, nullptr, "GetCtrlXferReport"}, |
| 99 | {8, nullptr, "Unknown7"}, | 99 | {8, nullptr, "ResetDevice"}, |
| 100 | {9, nullptr, "GetClientEpSession"}, | 100 | {9, nullptr, "OpenUsbEp"}, |
| 101 | }; | 101 | }; |
| 102 | // clang-format on | 102 | // clang-format on |
| 103 | 103 | ||
| @@ -111,13 +111,14 @@ public: | |||
| 111 | // clang-format off | 111 | // clang-format off |
| 112 | static const FunctionInfo functions[] = { | 112 | static const FunctionInfo functions[] = { |
| 113 | {0, nullptr, "BindClientProcess"}, | 113 | {0, nullptr, "BindClientProcess"}, |
| 114 | {1, nullptr, "Unknown1"}, | 114 | {1, nullptr, "QueryAllInterfaces"}, |
| 115 | {2, nullptr, "Unknown2"}, | 115 | {2, nullptr, "QueryAvailableInterfaces"}, |
| 116 | {3, nullptr, "Unknown3"}, | 116 | {3, nullptr, "QueryAcquiredInterfaces"}, |
| 117 | {4, nullptr, "Unknown4"}, | 117 | {4, nullptr, "CreateInterfaceAvailableEvent"}, |
| 118 | {5, nullptr, "Unknown5"}, | 118 | {5, nullptr, "DestroyInterfaceAvailableEvent"}, |
| 119 | {6, nullptr, "GetInterfaceStateChangeEvent"}, | 119 | {6, nullptr, "GetInterfaceStateChangeEvent"}, |
| 120 | {7, nullptr, "GetClientIfSession"}, | 120 | {7, nullptr, "AcquireUsbIf"}, |
| 121 | {8, nullptr, "Unknown1"}, | ||
| 121 | }; | 122 | }; |
| 122 | // clang-format on | 123 | // clang-format on |
| 123 | 124 | ||
diff --git a/src/core/loader/nro.cpp b/src/core/loader/nro.cpp index 243b499f2..bc8e402a8 100644 --- a/src/core/loader/nro.cpp +++ b/src/core/loader/nro.cpp | |||
| @@ -127,18 +127,23 @@ static constexpr u32 PageAlignSize(u32 size) { | |||
| 127 | return (size + Memory::PAGE_MASK) & ~Memory::PAGE_MASK; | 127 | return (size + Memory::PAGE_MASK) & ~Memory::PAGE_MASK; |
| 128 | } | 128 | } |
| 129 | 129 | ||
| 130 | bool AppLoader_NRO::LoadNro(const FileSys::VfsFile& file, VAddr load_base) { | 130 | /*static*/ bool AppLoader_NRO::LoadNro(const std::vector<u8>& data, const std::string& name, |
| 131 | // Read NSO header | 131 | VAddr load_base) { |
| 132 | NroHeader nro_header{}; | 132 | |
| 133 | if (sizeof(NroHeader) != file.ReadObject(&nro_header)) { | 133 | if (data.size() < sizeof(NroHeader)) { |
| 134 | return {}; | 134 | return {}; |
| 135 | } | 135 | } |
| 136 | |||
| 137 | // Read NSO header | ||
| 138 | NroHeader nro_header{}; | ||
| 139 | std::memcpy(&nro_header, data.data(), sizeof(NroHeader)); | ||
| 136 | if (nro_header.magic != Common::MakeMagic('N', 'R', 'O', '0')) { | 140 | if (nro_header.magic != Common::MakeMagic('N', 'R', 'O', '0')) { |
| 137 | return {}; | 141 | return {}; |
| 138 | } | 142 | } |
| 139 | 143 | ||
| 140 | // Build program image | 144 | // Build program image |
| 141 | std::vector<u8> program_image = file.ReadBytes(PageAlignSize(nro_header.file_size)); | 145 | std::vector<u8> program_image(PageAlignSize(nro_header.file_size)); |
| 146 | std::memcpy(program_image.data(), data.data(), program_image.size()); | ||
| 142 | if (program_image.size() != PageAlignSize(nro_header.file_size)) { | 147 | if (program_image.size() != PageAlignSize(nro_header.file_size)) { |
| 143 | return {}; | 148 | return {}; |
| 144 | } | 149 | } |
| @@ -182,11 +187,15 @@ bool AppLoader_NRO::LoadNro(const FileSys::VfsFile& file, VAddr load_base) { | |||
| 182 | Core::CurrentProcess()->LoadModule(std::move(codeset), load_base); | 187 | Core::CurrentProcess()->LoadModule(std::move(codeset), load_base); |
| 183 | 188 | ||
| 184 | // Register module with GDBStub | 189 | // Register module with GDBStub |
| 185 | GDBStub::RegisterModule(file.GetName(), load_base, load_base); | 190 | GDBStub::RegisterModule(name, load_base, load_base); |
| 186 | 191 | ||
| 187 | return true; | 192 | return true; |
| 188 | } | 193 | } |
| 189 | 194 | ||
| 195 | bool AppLoader_NRO::LoadNro(const FileSys::VfsFile& file, VAddr load_base) { | ||
| 196 | return AppLoader_NRO::LoadNro(file.ReadAllBytes(), file.GetName(), load_base); | ||
| 197 | } | ||
| 198 | |||
| 190 | ResultStatus AppLoader_NRO::Load(Kernel::Process& process) { | 199 | ResultStatus AppLoader_NRO::Load(Kernel::Process& process) { |
| 191 | if (is_loaded) { | 200 | if (is_loaded) { |
| 192 | return ResultStatus::ErrorAlreadyLoaded; | 201 | return ResultStatus::ErrorAlreadyLoaded; |
diff --git a/src/core/loader/nro.h b/src/core/loader/nro.h index 50ee5a78a..3e6959302 100644 --- a/src/core/loader/nro.h +++ b/src/core/loader/nro.h | |||
| @@ -5,6 +5,7 @@ | |||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <string> | 7 | #include <string> |
| 8 | #include <vector> | ||
| 8 | #include "common/common_types.h" | 9 | #include "common/common_types.h" |
| 9 | #include "core/loader/linker.h" | 10 | #include "core/loader/linker.h" |
| 10 | #include "core/loader/loader.h" | 11 | #include "core/loader/loader.h" |
| @@ -40,6 +41,8 @@ public: | |||
| 40 | ResultStatus ReadTitle(std::string& title) override; | 41 | ResultStatus ReadTitle(std::string& title) override; |
| 41 | bool IsRomFSUpdatable() const override; | 42 | bool IsRomFSUpdatable() const override; |
| 42 | 43 | ||
| 44 | static bool LoadNro(const std::vector<u8>& data, const std::string& name, VAddr load_base); | ||
| 45 | |||
| 43 | private: | 46 | private: |
| 44 | bool LoadNro(const FileSys::VfsFile& file, VAddr load_base); | 47 | bool LoadNro(const FileSys::VfsFile& file, VAddr load_base); |
| 45 | 48 | ||
diff --git a/src/core/perf_stats.cpp b/src/core/perf_stats.cpp index 7d95816fe..c716a462b 100644 --- a/src/core/perf_stats.cpp +++ b/src/core/perf_stats.cpp | |||
| @@ -74,10 +74,6 @@ double PerfStats::GetLastFrameTimeScale() { | |||
| 74 | } | 74 | } |
| 75 | 75 | ||
| 76 | void FrameLimiter::DoFrameLimiting(microseconds current_system_time_us) { | 76 | void FrameLimiter::DoFrameLimiting(microseconds current_system_time_us) { |
| 77 | // Max lag caused by slow frames. Can be adjusted to compensate for too many slow frames. Higher | ||
| 78 | // values increase the time needed to recover and limit framerate again after spikes. | ||
| 79 | constexpr microseconds MAX_LAG_TIME_US = 25000us; | ||
| 80 | |||
| 81 | if (!Settings::values.use_frame_limit) { | 77 | if (!Settings::values.use_frame_limit) { |
| 82 | return; | 78 | return; |
| 83 | } | 79 | } |
diff --git a/src/core/settings.h b/src/core/settings.h index 8f2da01c8..b5aeff29b 100644 --- a/src/core/settings.h +++ b/src/core/settings.h | |||
| @@ -113,7 +113,8 @@ static const std::array<const char*, NumAnalogs> mapping = {{ | |||
| 113 | struct Values { | 113 | struct Values { |
| 114 | // System | 114 | // System |
| 115 | bool use_docked_mode; | 115 | bool use_docked_mode; |
| 116 | std::string username; | 116 | bool enable_nfc; |
| 117 | int current_user; | ||
| 117 | int language_index; | 118 | int language_index; |
| 118 | 119 | ||
| 119 | // Controls | 120 | // Controls |