diff options
26 files changed, 414 insertions, 379 deletions
diff --git a/src/common/file_util.cpp b/src/common/file_util.cpp index 1bc291cf9..b8dd92b65 100644 --- a/src/common/file_util.cpp +++ b/src/common/file_util.cpp | |||
| @@ -826,7 +826,7 @@ std::string_view GetPathWithoutTop(std::string_view path) { | |||
| 826 | } | 826 | } |
| 827 | 827 | ||
| 828 | while (path[0] == '\\' || path[0] == '/') { | 828 | while (path[0] == '\\' || path[0] == '/') { |
| 829 | path.remove_suffix(1); | 829 | path.remove_prefix(1); |
| 830 | if (path.empty()) { | 830 | if (path.empty()) { |
| 831 | return path; | 831 | return path; |
| 832 | } | 832 | } |
| @@ -870,6 +870,15 @@ std::string_view RemoveTrailingSlash(std::string_view path) { | |||
| 870 | return path; | 870 | return path; |
| 871 | } | 871 | } |
| 872 | 872 | ||
| 873 | std::string SanitizePath(std::string_view path_) { | ||
| 874 | std::string path(path_); | ||
| 875 | std::replace(path.begin(), path.end(), '\\', '/'); | ||
| 876 | path.erase(std::unique(path.begin(), path.end(), | ||
| 877 | [](char c1, char c2) { return c1 == '/' && c2 == '/'; }), | ||
| 878 | path.end()); | ||
| 879 | return std::string(RemoveTrailingSlash(path)); | ||
| 880 | } | ||
| 881 | |||
| 873 | IOFile::IOFile() {} | 882 | IOFile::IOFile() {} |
| 874 | 883 | ||
| 875 | IOFile::IOFile(const std::string& filename, const char openmode[], int flags) { | 884 | IOFile::IOFile(const std::string& filename, const char openmode[], int flags) { |
diff --git a/src/common/file_util.h b/src/common/file_util.h index abfa79eae..bc9272d89 100644 --- a/src/common/file_util.h +++ b/src/common/file_util.h | |||
| @@ -178,6 +178,9 @@ std::vector<T> SliceVector(const std::vector<T>& vector, size_t first, size_t la | |||
| 178 | return std::vector<T>(vector.begin() + first, vector.begin() + first + last); | 178 | return std::vector<T>(vector.begin() + first, vector.begin() + first + last); |
| 179 | } | 179 | } |
| 180 | 180 | ||
| 181 | // Removes trailing slash, makes all '\\' into '/', and removes duplicate '/'. | ||
| 182 | std::string SanitizePath(std::string_view path); | ||
| 183 | |||
| 181 | // simple wrapper for cstdlib file functions to | 184 | // simple wrapper for cstdlib file functions to |
| 182 | // hopefully will make error checking easier | 185 | // hopefully will make error checking easier |
| 183 | // and make forgetting an fclose() harder | 186 | // and make forgetting an fclose() harder |
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 27a5de7fd..6b6efbc00 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt | |||
| @@ -12,6 +12,8 @@ add_library(core STATIC | |||
| 12 | core_timing.h | 12 | core_timing.h |
| 13 | file_sys/content_archive.cpp | 13 | file_sys/content_archive.cpp |
| 14 | file_sys/content_archive.h | 14 | file_sys/content_archive.h |
| 15 | file_sys/control_metadata.cpp | ||
| 16 | file_sys/control_metadata.h | ||
| 15 | file_sys/directory.h | 17 | file_sys/directory.h |
| 16 | file_sys/errors.h | 18 | file_sys/errors.h |
| 17 | file_sys/mode.h | 19 | file_sys/mode.h |
| @@ -38,8 +40,6 @@ add_library(core STATIC | |||
| 38 | frontend/input.h | 40 | frontend/input.h |
| 39 | gdbstub/gdbstub.cpp | 41 | gdbstub/gdbstub.cpp |
| 40 | gdbstub/gdbstub.h | 42 | gdbstub/gdbstub.h |
| 41 | hle/config_mem.cpp | ||
| 42 | hle/config_mem.h | ||
| 43 | hle/ipc.h | 43 | hle/ipc.h |
| 44 | hle/ipc_helpers.h | 44 | hle/ipc_helpers.h |
| 45 | hle/kernel/address_arbiter.cpp | 45 | hle/kernel/address_arbiter.cpp |
| @@ -249,8 +249,6 @@ add_library(core STATIC | |||
| 249 | hle/service/vi/vi_s.h | 249 | hle/service/vi/vi_s.h |
| 250 | hle/service/vi/vi_u.cpp | 250 | hle/service/vi/vi_u.cpp |
| 251 | hle/service/vi/vi_u.h | 251 | hle/service/vi/vi_u.h |
| 252 | hle/shared_page.cpp | ||
| 253 | hle/shared_page.h | ||
| 254 | hw/hw.cpp | 252 | hw/hw.cpp |
| 255 | hw/hw.h | 253 | hw/hw.h |
| 256 | hw/lcd.cpp | 254 | hw/lcd.cpp |
diff --git a/src/core/arm/dynarmic/arm_dynarmic.cpp b/src/core/arm/dynarmic/arm_dynarmic.cpp index 83c09db2b..d23adb28a 100644 --- a/src/core/arm/dynarmic/arm_dynarmic.cpp +++ b/src/core/arm/dynarmic/arm_dynarmic.cpp | |||
| @@ -257,7 +257,7 @@ void ARM_Dynarmic::PageTableChanged() { | |||
| 257 | DynarmicExclusiveMonitor::DynarmicExclusiveMonitor(size_t core_count) : monitor(core_count) {} | 257 | DynarmicExclusiveMonitor::DynarmicExclusiveMonitor(size_t core_count) : monitor(core_count) {} |
| 258 | DynarmicExclusiveMonitor::~DynarmicExclusiveMonitor() = default; | 258 | DynarmicExclusiveMonitor::~DynarmicExclusiveMonitor() = default; |
| 259 | 259 | ||
| 260 | void DynarmicExclusiveMonitor::SetExclusive(size_t core_index, u64 addr) { | 260 | void DynarmicExclusiveMonitor::SetExclusive(size_t core_index, VAddr addr) { |
| 261 | // Size doesn't actually matter. | 261 | // Size doesn't actually matter. |
| 262 | monitor.Mark(core_index, addr, 16); | 262 | monitor.Mark(core_index, addr, 16); |
| 263 | } | 263 | } |
| @@ -266,28 +266,27 @@ void DynarmicExclusiveMonitor::ClearExclusive() { | |||
| 266 | monitor.Clear(); | 266 | monitor.Clear(); |
| 267 | } | 267 | } |
| 268 | 268 | ||
| 269 | bool DynarmicExclusiveMonitor::ExclusiveWrite8(size_t core_index, u64 vaddr, u8 value) { | 269 | bool DynarmicExclusiveMonitor::ExclusiveWrite8(size_t core_index, VAddr vaddr, u8 value) { |
| 270 | return monitor.DoExclusiveOperation(core_index, vaddr, 1, | 270 | return monitor.DoExclusiveOperation(core_index, vaddr, 1, |
| 271 | [&] { Memory::Write8(vaddr, value); }); | 271 | [&] { Memory::Write8(vaddr, value); }); |
| 272 | } | 272 | } |
| 273 | 273 | ||
| 274 | bool DynarmicExclusiveMonitor::ExclusiveWrite16(size_t core_index, u64 vaddr, u16 value) { | 274 | bool DynarmicExclusiveMonitor::ExclusiveWrite16(size_t core_index, VAddr vaddr, u16 value) { |
| 275 | return monitor.DoExclusiveOperation(core_index, vaddr, 2, | 275 | return monitor.DoExclusiveOperation(core_index, vaddr, 2, |
| 276 | [&] { Memory::Write16(vaddr, value); }); | 276 | [&] { Memory::Write16(vaddr, value); }); |
| 277 | } | 277 | } |
| 278 | 278 | ||
| 279 | bool DynarmicExclusiveMonitor::ExclusiveWrite32(size_t core_index, u64 vaddr, u32 value) { | 279 | bool DynarmicExclusiveMonitor::ExclusiveWrite32(size_t core_index, VAddr vaddr, u32 value) { |
| 280 | return monitor.DoExclusiveOperation(core_index, vaddr, 4, | 280 | return monitor.DoExclusiveOperation(core_index, vaddr, 4, |
| 281 | [&] { Memory::Write32(vaddr, value); }); | 281 | [&] { Memory::Write32(vaddr, value); }); |
| 282 | } | 282 | } |
| 283 | 283 | ||
| 284 | bool DynarmicExclusiveMonitor::ExclusiveWrite64(size_t core_index, u64 vaddr, u64 value) { | 284 | bool DynarmicExclusiveMonitor::ExclusiveWrite64(size_t core_index, VAddr vaddr, u64 value) { |
| 285 | return monitor.DoExclusiveOperation(core_index, vaddr, 8, | 285 | return monitor.DoExclusiveOperation(core_index, vaddr, 8, |
| 286 | [&] { Memory::Write64(vaddr, value); }); | 286 | [&] { Memory::Write64(vaddr, value); }); |
| 287 | } | 287 | } |
| 288 | 288 | ||
| 289 | bool DynarmicExclusiveMonitor::ExclusiveWrite128(size_t core_index, u64 vaddr, | 289 | bool DynarmicExclusiveMonitor::ExclusiveWrite128(size_t core_index, VAddr vaddr, u128 value) { |
| 290 | std::array<std::uint64_t, 2> value) { | ||
| 291 | return monitor.DoExclusiveOperation(core_index, vaddr, 16, [&] { | 290 | return monitor.DoExclusiveOperation(core_index, vaddr, 16, [&] { |
| 292 | Memory::Write64(vaddr, value[0]); | 291 | Memory::Write64(vaddr, value[0]); |
| 293 | Memory::Write64(vaddr, value[1]); | 292 | Memory::Write64(vaddr, value[1]); |
diff --git a/src/core/arm/dynarmic/arm_dynarmic.h b/src/core/arm/dynarmic/arm_dynarmic.h index 0fa8b417c..350f61fd2 100644 --- a/src/core/arm/dynarmic/arm_dynarmic.h +++ b/src/core/arm/dynarmic/arm_dynarmic.h | |||
| @@ -68,15 +68,14 @@ public: | |||
| 68 | explicit DynarmicExclusiveMonitor(size_t core_count); | 68 | explicit DynarmicExclusiveMonitor(size_t core_count); |
| 69 | ~DynarmicExclusiveMonitor(); | 69 | ~DynarmicExclusiveMonitor(); |
| 70 | 70 | ||
| 71 | void SetExclusive(size_t core_index, u64 addr) override; | 71 | void SetExclusive(size_t core_index, VAddr addr) override; |
| 72 | void ClearExclusive() override; | 72 | void ClearExclusive() override; |
| 73 | 73 | ||
| 74 | bool ExclusiveWrite8(size_t core_index, u64 vaddr, u8 value) override; | 74 | bool ExclusiveWrite8(size_t core_index, VAddr vaddr, u8 value) override; |
| 75 | bool ExclusiveWrite16(size_t core_index, u64 vaddr, u16 value) override; | 75 | bool ExclusiveWrite16(size_t core_index, VAddr vaddr, u16 value) override; |
| 76 | bool ExclusiveWrite32(size_t core_index, u64 vaddr, u32 value) override; | 76 | bool ExclusiveWrite32(size_t core_index, VAddr vaddr, u32 value) override; |
| 77 | bool ExclusiveWrite64(size_t core_index, u64 vaddr, u64 value) override; | 77 | bool ExclusiveWrite64(size_t core_index, VAddr vaddr, u64 value) override; |
| 78 | bool ExclusiveWrite128(size_t core_index, u64 vaddr, | 78 | bool ExclusiveWrite128(size_t core_index, VAddr vaddr, u128 value) override; |
| 79 | std::array<std::uint64_t, 2> value) override; | ||
| 80 | 79 | ||
| 81 | private: | 80 | private: |
| 82 | friend class ARM_Dynarmic; | 81 | friend class ARM_Dynarmic; |
diff --git a/src/core/arm/exclusive_monitor.h b/src/core/arm/exclusive_monitor.h index acfcdb94c..13671ed7a 100644 --- a/src/core/arm/exclusive_monitor.h +++ b/src/core/arm/exclusive_monitor.h | |||
| @@ -4,20 +4,18 @@ | |||
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <array> | ||
| 8 | #include "common/common_types.h" | 7 | #include "common/common_types.h" |
| 9 | 8 | ||
| 10 | class ExclusiveMonitor { | 9 | class ExclusiveMonitor { |
| 11 | public: | 10 | public: |
| 12 | virtual ~ExclusiveMonitor(); | 11 | virtual ~ExclusiveMonitor(); |
| 13 | 12 | ||
| 14 | virtual void SetExclusive(size_t core_index, u64 addr) = 0; | 13 | virtual void SetExclusive(size_t core_index, VAddr addr) = 0; |
| 15 | virtual void ClearExclusive() = 0; | 14 | virtual void ClearExclusive() = 0; |
| 16 | 15 | ||
| 17 | virtual bool ExclusiveWrite8(size_t core_index, u64 vaddr, u8 value) = 0; | 16 | virtual bool ExclusiveWrite8(size_t core_index, VAddr vaddr, u8 value) = 0; |
| 18 | virtual bool ExclusiveWrite16(size_t core_index, u64 vaddr, u16 value) = 0; | 17 | virtual bool ExclusiveWrite16(size_t core_index, VAddr vaddr, u16 value) = 0; |
| 19 | virtual bool ExclusiveWrite32(size_t core_index, u64 vaddr, u32 value) = 0; | 18 | virtual bool ExclusiveWrite32(size_t core_index, VAddr vaddr, u32 value) = 0; |
| 20 | virtual bool ExclusiveWrite64(size_t core_index, u64 vaddr, u64 value) = 0; | 19 | virtual bool ExclusiveWrite64(size_t core_index, VAddr vaddr, u64 value) = 0; |
| 21 | virtual bool ExclusiveWrite128(size_t core_index, u64 vaddr, | 20 | virtual bool ExclusiveWrite128(size_t core_index, VAddr vaddr, u128 value) = 0; |
| 22 | std::array<std::uint64_t, 2> value) = 0; | ||
| 23 | }; | 21 | }; |
diff --git a/src/core/file_sys/control_metadata.cpp b/src/core/file_sys/control_metadata.cpp new file mode 100644 index 000000000..3ddc9f162 --- /dev/null +++ b/src/core/file_sys/control_metadata.cpp | |||
| @@ -0,0 +1,42 @@ | |||
| 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 "common/string_util.h" | ||
| 6 | #include "common/swap.h" | ||
| 7 | #include "core/file_sys/control_metadata.h" | ||
| 8 | |||
| 9 | namespace FileSys { | ||
| 10 | |||
| 11 | std::string LanguageEntry::GetApplicationName() const { | ||
| 12 | return Common::StringFromFixedZeroTerminatedBuffer(application_name.data(), 0x200); | ||
| 13 | } | ||
| 14 | |||
| 15 | std::string LanguageEntry::GetDeveloperName() const { | ||
| 16 | return Common::StringFromFixedZeroTerminatedBuffer(developer_name.data(), 0x100); | ||
| 17 | } | ||
| 18 | |||
| 19 | NACP::NACP(VirtualFile file_) : file(std::move(file_)), raw(std::make_unique<RawNACP>()) { | ||
| 20 | file->ReadObject(raw.get()); | ||
| 21 | } | ||
| 22 | |||
| 23 | const LanguageEntry& NACP::GetLanguageEntry(Language language) const { | ||
| 24 | return raw->language_entries.at(static_cast<u8>(language)); | ||
| 25 | } | ||
| 26 | |||
| 27 | std::string NACP::GetApplicationName(Language language) const { | ||
| 28 | return GetLanguageEntry(language).GetApplicationName(); | ||
| 29 | } | ||
| 30 | |||
| 31 | std::string NACP::GetDeveloperName(Language language) const { | ||
| 32 | return GetLanguageEntry(language).GetDeveloperName(); | ||
| 33 | } | ||
| 34 | |||
| 35 | u64 NACP::GetTitleId() const { | ||
| 36 | return raw->title_id; | ||
| 37 | } | ||
| 38 | |||
| 39 | std::string NACP::GetVersionString() const { | ||
| 40 | return Common::StringFromFixedZeroTerminatedBuffer(raw->version_string.data(), 0x10); | ||
| 41 | } | ||
| 42 | } // namespace FileSys | ||
diff --git a/src/core/file_sys/control_metadata.h b/src/core/file_sys/control_metadata.h new file mode 100644 index 000000000..cc3b745f7 --- /dev/null +++ b/src/core/file_sys/control_metadata.h | |||
| @@ -0,0 +1,81 @@ | |||
| 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 <array> | ||
| 8 | #include <memory> | ||
| 9 | #include <string> | ||
| 10 | #include "common/common_funcs.h" | ||
| 11 | #include "core/file_sys/vfs.h" | ||
| 12 | |||
| 13 | namespace FileSys { | ||
| 14 | |||
| 15 | // A localized entry containing strings within the NACP. | ||
| 16 | // One for each language of type Language. | ||
| 17 | struct LanguageEntry { | ||
| 18 | std::array<char, 0x200> application_name; | ||
| 19 | std::array<char, 0x100> developer_name; | ||
| 20 | |||
| 21 | std::string GetApplicationName() const; | ||
| 22 | std::string GetDeveloperName() const; | ||
| 23 | }; | ||
| 24 | static_assert(sizeof(LanguageEntry) == 0x300, "LanguageEntry has incorrect size."); | ||
| 25 | |||
| 26 | // The raw file format of a NACP file. | ||
| 27 | struct RawNACP { | ||
| 28 | std::array<LanguageEntry, 16> language_entries; | ||
| 29 | INSERT_PADDING_BYTES(0x38); | ||
| 30 | u64_le title_id; | ||
| 31 | INSERT_PADDING_BYTES(0x20); | ||
| 32 | std::array<char, 0x10> version_string; | ||
| 33 | u64_le dlc_base_title_id; | ||
| 34 | u64_le title_id_2; | ||
| 35 | INSERT_PADDING_BYTES(0x28); | ||
| 36 | u64_le product_code; | ||
| 37 | u64_le title_id_3; | ||
| 38 | std::array<u64_le, 0x7> title_id_array; | ||
| 39 | INSERT_PADDING_BYTES(0x8); | ||
| 40 | u64_le title_id_update; | ||
| 41 | std::array<u8, 0x40> bcat_passphrase; | ||
| 42 | INSERT_PADDING_BYTES(0xEC0); | ||
| 43 | }; | ||
| 44 | static_assert(sizeof(RawNACP) == 0x4000, "RawNACP has incorrect size."); | ||
| 45 | |||
| 46 | // A language on the NX. These are for names and icons. | ||
| 47 | enum class Language : u8 { | ||
| 48 | AmericanEnglish = 0, | ||
| 49 | BritishEnglish = 1, | ||
| 50 | Japanese = 2, | ||
| 51 | French = 3, | ||
| 52 | German = 4, | ||
| 53 | LatinAmericanSpanish = 5, | ||
| 54 | Spanish = 6, | ||
| 55 | Italian = 7, | ||
| 56 | Dutch = 8, | ||
| 57 | CanadianFrench = 9, | ||
| 58 | Portugese = 10, | ||
| 59 | Russian = 11, | ||
| 60 | Korean = 12, | ||
| 61 | Taiwanese = 13, | ||
| 62 | Chinese = 14, | ||
| 63 | }; | ||
| 64 | |||
| 65 | // A class representing the format used by NX metadata files, typically named Control.nacp. | ||
| 66 | // These store application name, dev name, title id, and other miscellaneous data. | ||
| 67 | class NACP { | ||
| 68 | public: | ||
| 69 | explicit NACP(VirtualFile file); | ||
| 70 | const LanguageEntry& GetLanguageEntry(Language language = Language::AmericanEnglish) const; | ||
| 71 | std::string GetApplicationName(Language language = Language::AmericanEnglish) const; | ||
| 72 | std::string GetDeveloperName(Language language = Language::AmericanEnglish) const; | ||
| 73 | u64 GetTitleId() const; | ||
| 74 | std::string GetVersionString() const; | ||
| 75 | |||
| 76 | private: | ||
| 77 | VirtualFile file; | ||
| 78 | std::unique_ptr<RawNACP> raw; | ||
| 79 | }; | ||
| 80 | |||
| 81 | } // namespace FileSys | ||
diff --git a/src/core/file_sys/mode.h b/src/core/file_sys/mode.h index b4363152a..c95205668 100644 --- a/src/core/file_sys/mode.h +++ b/src/core/file_sys/mode.h | |||
| @@ -11,7 +11,13 @@ namespace FileSys { | |||
| 11 | enum class Mode : u32 { | 11 | enum class Mode : u32 { |
| 12 | Read = 1, | 12 | Read = 1, |
| 13 | Write = 2, | 13 | Write = 2, |
| 14 | ReadWrite = 3, | ||
| 14 | Append = 4, | 15 | Append = 4, |
| 16 | WriteAppend = 6, | ||
| 15 | }; | 17 | }; |
| 16 | 18 | ||
| 19 | inline u32 operator&(Mode lhs, Mode rhs) { | ||
| 20 | return static_cast<u32>(lhs) & static_cast<u32>(rhs); | ||
| 21 | } | ||
| 22 | |||
| 17 | } // namespace FileSys | 23 | } // namespace FileSys |
diff --git a/src/core/file_sys/vfs_real.cpp b/src/core/file_sys/vfs_real.cpp index 095fec77e..9ce2e1efa 100644 --- a/src/core/file_sys/vfs_real.cpp +++ b/src/core/file_sys/vfs_real.cpp | |||
| @@ -13,24 +13,31 @@ | |||
| 13 | 13 | ||
| 14 | namespace FileSys { | 14 | namespace FileSys { |
| 15 | 15 | ||
| 16 | static std::string PermissionsToCharArray(Mode perms) { | 16 | static std::string ModeFlagsToString(Mode mode) { |
| 17 | std::string out; | 17 | std::string mode_str; |
| 18 | switch (perms) { | 18 | |
| 19 | case Mode::Read: | 19 | // Calculate the correct open mode for the file. |
| 20 | out += "r"; | 20 | if (mode & Mode::Read && mode & Mode::Write) { |
| 21 | break; | 21 | if (mode & Mode::Append) |
| 22 | case Mode::Write: | 22 | mode_str = "a+"; |
| 23 | out += "r+"; | 23 | else |
| 24 | break; | 24 | mode_str = "r+"; |
| 25 | case Mode::Append: | 25 | } else { |
| 26 | out += "a"; | 26 | if (mode & Mode::Read) |
| 27 | break; | 27 | mode_str = "r"; |
| 28 | else if (mode & Mode::Append) | ||
| 29 | mode_str = "a"; | ||
| 30 | else if (mode & Mode::Write) | ||
| 31 | mode_str = "w"; | ||
| 28 | } | 32 | } |
| 29 | return out + "b"; | 33 | |
| 34 | mode_str += "b"; | ||
| 35 | |||
| 36 | return mode_str; | ||
| 30 | } | 37 | } |
| 31 | 38 | ||
| 32 | RealVfsFile::RealVfsFile(const std::string& path_, Mode perms_) | 39 | RealVfsFile::RealVfsFile(const std::string& path_, Mode perms_) |
| 33 | : backing(path_, PermissionsToCharArray(perms_).c_str()), path(path_), | 40 | : backing(path_, ModeFlagsToString(perms_).c_str()), path(path_), |
| 34 | parent_path(FileUtil::GetParentPath(path_)), | 41 | parent_path(FileUtil::GetParentPath(path_)), |
| 35 | path_components(FileUtil::SplitPathComponents(path_)), | 42 | path_components(FileUtil::SplitPathComponents(path_)), |
| 36 | parent_components(FileUtil::SliceVector(path_components, 0, path_components.size() - 1)), | 43 | parent_components(FileUtil::SliceVector(path_components, 0, path_components.size() - 1)), |
| @@ -53,11 +60,11 @@ std::shared_ptr<VfsDirectory> RealVfsFile::GetContainingDirectory() const { | |||
| 53 | } | 60 | } |
| 54 | 61 | ||
| 55 | bool RealVfsFile::IsWritable() const { | 62 | bool RealVfsFile::IsWritable() const { |
| 56 | return perms == Mode::Append || perms == Mode::Write; | 63 | return (perms & Mode::WriteAppend) != 0; |
| 57 | } | 64 | } |
| 58 | 65 | ||
| 59 | bool RealVfsFile::IsReadable() const { | 66 | bool RealVfsFile::IsReadable() const { |
| 60 | return perms == Mode::Read || perms == Mode::Write; | 67 | return (perms & Mode::ReadWrite) != 0; |
| 61 | } | 68 | } |
| 62 | 69 | ||
| 63 | size_t RealVfsFile::Read(u8* data, size_t length, size_t offset) const { | 70 | size_t RealVfsFile::Read(u8* data, size_t length, size_t offset) const { |
| @@ -79,7 +86,7 @@ bool RealVfsFile::Rename(std::string_view name) { | |||
| 79 | path = (parent_path + DIR_SEP).append(name); | 86 | path = (parent_path + DIR_SEP).append(name); |
| 80 | path_components = parent_components; | 87 | path_components = parent_components; |
| 81 | path_components.push_back(std::move(name_str)); | 88 | path_components.push_back(std::move(name_str)); |
| 82 | backing = FileUtil::IOFile(path, PermissionsToCharArray(perms).c_str()); | 89 | backing = FileUtil::IOFile(path, ModeFlagsToString(perms).c_str()); |
| 83 | 90 | ||
| 84 | return out; | 91 | return out; |
| 85 | } | 92 | } |
| @@ -93,7 +100,7 @@ RealVfsDirectory::RealVfsDirectory(const std::string& path_, Mode perms_) | |||
| 93 | path_components(FileUtil::SplitPathComponents(path)), | 100 | path_components(FileUtil::SplitPathComponents(path)), |
| 94 | parent_components(FileUtil::SliceVector(path_components, 0, path_components.size() - 1)), | 101 | parent_components(FileUtil::SliceVector(path_components, 0, path_components.size() - 1)), |
| 95 | perms(perms_) { | 102 | perms(perms_) { |
| 96 | if (!FileUtil::Exists(path) && (perms == Mode::Write || perms == Mode::Append)) | 103 | if (!FileUtil::Exists(path) && perms & Mode::WriteAppend) |
| 97 | FileUtil::CreateDir(path); | 104 | FileUtil::CreateDir(path); |
| 98 | 105 | ||
| 99 | if (perms == Mode::Append) | 106 | if (perms == Mode::Append) |
| @@ -120,11 +127,11 @@ std::vector<std::shared_ptr<VfsDirectory>> RealVfsDirectory::GetSubdirectories() | |||
| 120 | } | 127 | } |
| 121 | 128 | ||
| 122 | bool RealVfsDirectory::IsWritable() const { | 129 | bool RealVfsDirectory::IsWritable() const { |
| 123 | return perms == Mode::Write || perms == Mode::Append; | 130 | return (perms & Mode::WriteAppend) != 0; |
| 124 | } | 131 | } |
| 125 | 132 | ||
| 126 | bool RealVfsDirectory::IsReadable() const { | 133 | bool RealVfsDirectory::IsReadable() const { |
| 127 | return perms == Mode::Read || perms == Mode::Write; | 134 | return (perms & Mode::ReadWrite) != 0; |
| 128 | } | 135 | } |
| 129 | 136 | ||
| 130 | std::string RealVfsDirectory::GetName() const { | 137 | std::string RealVfsDirectory::GetName() const { |
diff --git a/src/core/hle/config_mem.cpp b/src/core/hle/config_mem.cpp deleted file mode 100644 index 038af7909..000000000 --- a/src/core/hle/config_mem.cpp +++ /dev/null | |||
| @@ -1,31 +0,0 @@ | |||
| 1 | // Copyright 2014 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include <cstring> | ||
| 6 | #include "core/hle/config_mem.h" | ||
| 7 | |||
| 8 | //////////////////////////////////////////////////////////////////////////////////////////////////// | ||
| 9 | |||
| 10 | namespace ConfigMem { | ||
| 11 | |||
| 12 | ConfigMemDef config_mem; | ||
| 13 | |||
| 14 | void Init() { | ||
| 15 | std::memset(&config_mem, 0, sizeof(config_mem)); | ||
| 16 | |||
| 17 | // Values extracted from firmware 11.2.0-35E | ||
| 18 | config_mem.kernel_version_min = 0x34; | ||
| 19 | config_mem.kernel_version_maj = 0x2; | ||
| 20 | config_mem.ns_tid = 0x0004013000008002; | ||
| 21 | config_mem.sys_core_ver = 0x2; | ||
| 22 | config_mem.unit_info = 0x1; // Bit 0 set for Retail | ||
| 23 | config_mem.prev_firm = 0x1; | ||
| 24 | config_mem.ctr_sdk_ver = 0x0000F297; | ||
| 25 | config_mem.firm_version_min = 0x34; | ||
| 26 | config_mem.firm_version_maj = 0x2; | ||
| 27 | config_mem.firm_sys_core_ver = 0x2; | ||
| 28 | config_mem.firm_ctr_sdk_ver = 0x0000F297; | ||
| 29 | } | ||
| 30 | |||
| 31 | } // namespace ConfigMem | ||
diff --git a/src/core/hle/config_mem.h b/src/core/hle/config_mem.h deleted file mode 100644 index 1840d1760..000000000 --- a/src/core/hle/config_mem.h +++ /dev/null | |||
| @@ -1,56 +0,0 @@ | |||
| 1 | // Copyright 2014 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | // Configuration memory stores various hardware/kernel configuration settings. This memory page is | ||
| 8 | // read-only for ARM11 processes. I'm guessing this would normally be written to by the firmware/ | ||
| 9 | // bootrom. Because we're not emulating this, and essentially just "stubbing" the functionality, I'm | ||
| 10 | // putting this as a subset of HLE for now. | ||
| 11 | |||
| 12 | #include "common/common_funcs.h" | ||
| 13 | #include "common/common_types.h" | ||
| 14 | #include "common/swap.h" | ||
| 15 | #include "core/memory.h" | ||
| 16 | |||
| 17 | //////////////////////////////////////////////////////////////////////////////////////////////////// | ||
| 18 | |||
| 19 | namespace ConfigMem { | ||
| 20 | |||
| 21 | struct ConfigMemDef { | ||
| 22 | u8 kernel_unk; // 0 | ||
| 23 | u8 kernel_version_rev; // 1 | ||
| 24 | u8 kernel_version_min; // 2 | ||
| 25 | u8 kernel_version_maj; // 3 | ||
| 26 | u32_le update_flag; // 4 | ||
| 27 | u64_le ns_tid; // 8 | ||
| 28 | u32_le sys_core_ver; // 10 | ||
| 29 | u8 unit_info; // 14 | ||
| 30 | u8 boot_firm; // 15 | ||
| 31 | u8 prev_firm; // 16 | ||
| 32 | INSERT_PADDING_BYTES(0x1); // 17 | ||
| 33 | u32_le ctr_sdk_ver; // 18 | ||
| 34 | INSERT_PADDING_BYTES(0x30 - 0x1C); // 1C | ||
| 35 | u32_le app_mem_type; // 30 | ||
| 36 | INSERT_PADDING_BYTES(0x40 - 0x34); // 34 | ||
| 37 | u32_le app_mem_alloc; // 40 | ||
| 38 | u32_le sys_mem_alloc; // 44 | ||
| 39 | u32_le base_mem_alloc; // 48 | ||
| 40 | INSERT_PADDING_BYTES(0x60 - 0x4C); // 4C | ||
| 41 | u8 firm_unk; // 60 | ||
| 42 | u8 firm_version_rev; // 61 | ||
| 43 | u8 firm_version_min; // 62 | ||
| 44 | u8 firm_version_maj; // 63 | ||
| 45 | u32_le firm_sys_core_ver; // 64 | ||
| 46 | u32_le firm_ctr_sdk_ver; // 68 | ||
| 47 | INSERT_PADDING_BYTES(0x1000 - 0x6C); // 6C | ||
| 48 | }; | ||
| 49 | static_assert(sizeof(ConfigMemDef) == Memory::CONFIG_MEMORY_SIZE, | ||
| 50 | "Config Memory structure size is wrong"); | ||
| 51 | |||
| 52 | extern ConfigMemDef config_mem; | ||
| 53 | |||
| 54 | void Init(); | ||
| 55 | |||
| 56 | } // namespace ConfigMem | ||
diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp index b325b879b..1beb98566 100644 --- a/src/core/hle/kernel/kernel.cpp +++ b/src/core/hle/kernel/kernel.cpp | |||
| @@ -2,7 +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 | #include "core/hle/config_mem.h" | ||
| 6 | #include "core/hle/kernel/handle_table.h" | 5 | #include "core/hle/kernel/handle_table.h" |
| 7 | #include "core/hle/kernel/kernel.h" | 6 | #include "core/hle/kernel/kernel.h" |
| 8 | #include "core/hle/kernel/memory.h" | 7 | #include "core/hle/kernel/memory.h" |
| @@ -11,7 +10,6 @@ | |||
| 11 | #include "core/hle/kernel/resource_limit.h" | 10 | #include "core/hle/kernel/resource_limit.h" |
| 12 | #include "core/hle/kernel/thread.h" | 11 | #include "core/hle/kernel/thread.h" |
| 13 | #include "core/hle/kernel/timer.h" | 12 | #include "core/hle/kernel/timer.h" |
| 14 | #include "core/hle/shared_page.h" | ||
| 15 | 13 | ||
| 16 | namespace Kernel { | 14 | namespace Kernel { |
| 17 | 15 | ||
| @@ -19,9 +17,6 @@ unsigned int Object::next_object_id; | |||
| 19 | 17 | ||
| 20 | /// Initialize the kernel | 18 | /// Initialize the kernel |
| 21 | void Init(u32 system_mode) { | 19 | void Init(u32 system_mode) { |
| 22 | ConfigMem::Init(); | ||
| 23 | SharedPage::Init(); | ||
| 24 | |||
| 25 | Kernel::MemoryInit(system_mode); | 20 | Kernel::MemoryInit(system_mode); |
| 26 | 21 | ||
| 27 | Kernel::ResourceLimitsInit(); | 22 | Kernel::ResourceLimitsInit(); |
diff --git a/src/core/hle/kernel/memory.cpp b/src/core/hle/kernel/memory.cpp index d2600cdd7..94eac677c 100644 --- a/src/core/hle/kernel/memory.cpp +++ b/src/core/hle/kernel/memory.cpp | |||
| @@ -11,11 +11,9 @@ | |||
| 11 | #include "common/assert.h" | 11 | #include "common/assert.h" |
| 12 | #include "common/common_types.h" | 12 | #include "common/common_types.h" |
| 13 | #include "common/logging/log.h" | 13 | #include "common/logging/log.h" |
| 14 | #include "core/hle/config_mem.h" | ||
| 15 | #include "core/hle/kernel/memory.h" | 14 | #include "core/hle/kernel/memory.h" |
| 16 | #include "core/hle/kernel/vm_manager.h" | 15 | #include "core/hle/kernel/vm_manager.h" |
| 17 | #include "core/hle/result.h" | 16 | #include "core/hle/result.h" |
| 18 | #include "core/hle/shared_page.h" | ||
| 19 | #include "core/memory.h" | 17 | #include "core/memory.h" |
| 20 | #include "core/memory_setup.h" | 18 | #include "core/memory_setup.h" |
| 21 | 19 | ||
| @@ -63,14 +61,6 @@ void MemoryInit(u32 mem_type) { | |||
| 63 | 61 | ||
| 64 | // We must've allocated the entire FCRAM by the end | 62 | // We must've allocated the entire FCRAM by the end |
| 65 | ASSERT(base == Memory::FCRAM_SIZE); | 63 | ASSERT(base == Memory::FCRAM_SIZE); |
| 66 | |||
| 67 | using ConfigMem::config_mem; | ||
| 68 | config_mem.app_mem_type = mem_type; | ||
| 69 | // app_mem_malloc does not always match the configured size for memory_region[0]: in case the | ||
| 70 | // n3DS type override is in effect it reports the size the game expects, not the real one. | ||
| 71 | config_mem.app_mem_alloc = memory_region_sizes[mem_type][0]; | ||
| 72 | config_mem.sys_mem_alloc = static_cast<u32_le>(memory_regions[1].size); | ||
| 73 | config_mem.base_mem_alloc = static_cast<u32_le>(memory_regions[2].size); | ||
| 74 | } | 64 | } |
| 75 | 65 | ||
| 76 | void MemoryShutdown() { | 66 | void MemoryShutdown() { |
diff --git a/src/core/hle/kernel/wait_object.cpp b/src/core/hle/kernel/wait_object.cpp index eb3c92e66..23af346d0 100644 --- a/src/core/hle/kernel/wait_object.cpp +++ b/src/core/hle/kernel/wait_object.cpp | |||
| @@ -5,7 +5,6 @@ | |||
| 5 | #include <algorithm> | 5 | #include <algorithm> |
| 6 | #include "common/assert.h" | 6 | #include "common/assert.h" |
| 7 | #include "common/logging/log.h" | 7 | #include "common/logging/log.h" |
| 8 | #include "core/hle/config_mem.h" | ||
| 9 | #include "core/hle/kernel/errors.h" | 8 | #include "core/hle/kernel/errors.h" |
| 10 | #include "core/hle/kernel/kernel.h" | 9 | #include "core/hle/kernel/kernel.h" |
| 11 | #include "core/hle/kernel/memory.h" | 10 | #include "core/hle/kernel/memory.h" |
| @@ -13,7 +12,6 @@ | |||
| 13 | #include "core/hle/kernel/resource_limit.h" | 12 | #include "core/hle/kernel/resource_limit.h" |
| 14 | #include "core/hle/kernel/thread.h" | 13 | #include "core/hle/kernel/thread.h" |
| 15 | #include "core/hle/kernel/timer.h" | 14 | #include "core/hle/kernel/timer.h" |
| 16 | #include "core/hle/shared_page.h" | ||
| 17 | 15 | ||
| 18 | namespace Kernel { | 16 | namespace Kernel { |
| 19 | 17 | ||
diff --git a/src/core/hle/service/filesystem/filesystem.cpp b/src/core/hle/service/filesystem/filesystem.cpp index dbfe06cbc..fdd2fda18 100644 --- a/src/core/hle/service/filesystem/filesystem.cpp +++ b/src/core/hle/service/filesystem/filesystem.cpp | |||
| @@ -24,7 +24,8 @@ namespace Service::FileSystem { | |||
| 24 | constexpr u64 EMULATED_SD_REPORTED_SIZE = 32000000000; | 24 | constexpr u64 EMULATED_SD_REPORTED_SIZE = 32000000000; |
| 25 | 25 | ||
| 26 | static FileSys::VirtualDir GetDirectoryRelativeWrapped(FileSys::VirtualDir base, | 26 | static FileSys::VirtualDir GetDirectoryRelativeWrapped(FileSys::VirtualDir base, |
| 27 | std::string_view dir_name) { | 27 | std::string_view dir_name_) { |
| 28 | std::string dir_name(FileUtil::SanitizePath(dir_name_)); | ||
| 28 | if (dir_name.empty() || dir_name == "." || dir_name == "/" || dir_name == "\\") | 29 | if (dir_name.empty() || dir_name == "." || dir_name == "/" || dir_name == "\\") |
| 29 | return base; | 30 | return base; |
| 30 | 31 | ||
| @@ -38,7 +39,8 @@ std::string VfsDirectoryServiceWrapper::GetName() const { | |||
| 38 | return backing->GetName(); | 39 | return backing->GetName(); |
| 39 | } | 40 | } |
| 40 | 41 | ||
| 41 | ResultCode VfsDirectoryServiceWrapper::CreateFile(const std::string& path, u64 size) const { | 42 | ResultCode VfsDirectoryServiceWrapper::CreateFile(const std::string& path_, u64 size) const { |
| 43 | std::string path(FileUtil::SanitizePath(path_)); | ||
| 42 | auto dir = GetDirectoryRelativeWrapped(backing, FileUtil::GetParentPath(path)); | 44 | auto dir = GetDirectoryRelativeWrapped(backing, FileUtil::GetParentPath(path)); |
| 43 | auto file = dir->CreateFile(FileUtil::GetFilename(path)); | 45 | auto file = dir->CreateFile(FileUtil::GetFilename(path)); |
| 44 | if (file == nullptr) { | 46 | if (file == nullptr) { |
| @@ -52,7 +54,8 @@ ResultCode VfsDirectoryServiceWrapper::CreateFile(const std::string& path, u64 s | |||
| 52 | return RESULT_SUCCESS; | 54 | return RESULT_SUCCESS; |
| 53 | } | 55 | } |
| 54 | 56 | ||
| 55 | ResultCode VfsDirectoryServiceWrapper::DeleteFile(const std::string& path) const { | 57 | ResultCode VfsDirectoryServiceWrapper::DeleteFile(const std::string& path_) const { |
| 58 | std::string path(FileUtil::SanitizePath(path_)); | ||
| 56 | auto dir = GetDirectoryRelativeWrapped(backing, FileUtil::GetParentPath(path)); | 59 | auto dir = GetDirectoryRelativeWrapped(backing, FileUtil::GetParentPath(path)); |
| 57 | if (path == "/" || path == "\\") { | 60 | if (path == "/" || path == "\\") { |
| 58 | // TODO(DarkLordZach): Why do games call this and what should it do? Works as is but... | 61 | // TODO(DarkLordZach): Why do games call this and what should it do? Works as is but... |
| @@ -60,14 +63,15 @@ ResultCode VfsDirectoryServiceWrapper::DeleteFile(const std::string& path) const | |||
| 60 | } | 63 | } |
| 61 | if (dir->GetFile(FileUtil::GetFilename(path)) == nullptr) | 64 | if (dir->GetFile(FileUtil::GetFilename(path)) == nullptr) |
| 62 | return FileSys::ERROR_PATH_NOT_FOUND; | 65 | return FileSys::ERROR_PATH_NOT_FOUND; |
| 63 | if (!backing->DeleteFile(FileUtil::GetFilename(path))) { | 66 | if (!dir->DeleteFile(FileUtil::GetFilename(path))) { |
| 64 | // TODO(DarkLordZach): Find a better error code for this | 67 | // TODO(DarkLordZach): Find a better error code for this |
| 65 | return ResultCode(-1); | 68 | return ResultCode(-1); |
| 66 | } | 69 | } |
| 67 | return RESULT_SUCCESS; | 70 | return RESULT_SUCCESS; |
| 68 | } | 71 | } |
| 69 | 72 | ||
| 70 | ResultCode VfsDirectoryServiceWrapper::CreateDirectory(const std::string& path) const { | 73 | ResultCode VfsDirectoryServiceWrapper::CreateDirectory(const std::string& path_) const { |
| 74 | std::string path(FileUtil::SanitizePath(path_)); | ||
| 71 | auto dir = GetDirectoryRelativeWrapped(backing, FileUtil::GetParentPath(path)); | 75 | auto dir = GetDirectoryRelativeWrapped(backing, FileUtil::GetParentPath(path)); |
| 72 | if (dir == nullptr && FileUtil::GetFilename(FileUtil::GetParentPath(path)).empty()) | 76 | if (dir == nullptr && FileUtil::GetFilename(FileUtil::GetParentPath(path)).empty()) |
| 73 | dir = backing; | 77 | dir = backing; |
| @@ -79,7 +83,8 @@ ResultCode VfsDirectoryServiceWrapper::CreateDirectory(const std::string& path) | |||
| 79 | return RESULT_SUCCESS; | 83 | return RESULT_SUCCESS; |
| 80 | } | 84 | } |
| 81 | 85 | ||
| 82 | ResultCode VfsDirectoryServiceWrapper::DeleteDirectory(const std::string& path) const { | 86 | ResultCode VfsDirectoryServiceWrapper::DeleteDirectory(const std::string& path_) const { |
| 87 | std::string path(FileUtil::SanitizePath(path_)); | ||
| 83 | auto dir = GetDirectoryRelativeWrapped(backing, FileUtil::GetParentPath(path)); | 88 | auto dir = GetDirectoryRelativeWrapped(backing, FileUtil::GetParentPath(path)); |
| 84 | if (!dir->DeleteSubdirectory(FileUtil::GetFilename(path))) { | 89 | if (!dir->DeleteSubdirectory(FileUtil::GetFilename(path))) { |
| 85 | // TODO(DarkLordZach): Find a better error code for this | 90 | // TODO(DarkLordZach): Find a better error code for this |
| @@ -88,7 +93,8 @@ ResultCode VfsDirectoryServiceWrapper::DeleteDirectory(const std::string& path) | |||
| 88 | return RESULT_SUCCESS; | 93 | return RESULT_SUCCESS; |
| 89 | } | 94 | } |
| 90 | 95 | ||
| 91 | ResultCode VfsDirectoryServiceWrapper::DeleteDirectoryRecursively(const std::string& path) const { | 96 | ResultCode VfsDirectoryServiceWrapper::DeleteDirectoryRecursively(const std::string& path_) const { |
| 97 | std::string path(FileUtil::SanitizePath(path_)); | ||
| 92 | auto dir = GetDirectoryRelativeWrapped(backing, FileUtil::GetParentPath(path)); | 98 | auto dir = GetDirectoryRelativeWrapped(backing, FileUtil::GetParentPath(path)); |
| 93 | if (!dir->DeleteSubdirectoryRecursive(FileUtil::GetFilename(path))) { | 99 | if (!dir->DeleteSubdirectoryRecursive(FileUtil::GetFilename(path))) { |
| 94 | // TODO(DarkLordZach): Find a better error code for this | 100 | // TODO(DarkLordZach): Find a better error code for this |
| @@ -97,8 +103,10 @@ ResultCode VfsDirectoryServiceWrapper::DeleteDirectoryRecursively(const std::str | |||
| 97 | return RESULT_SUCCESS; | 103 | return RESULT_SUCCESS; |
| 98 | } | 104 | } |
| 99 | 105 | ||
| 100 | ResultCode VfsDirectoryServiceWrapper::RenameFile(const std::string& src_path, | 106 | ResultCode VfsDirectoryServiceWrapper::RenameFile(const std::string& src_path_, |
| 101 | const std::string& dest_path) const { | 107 | const std::string& dest_path_) const { |
| 108 | std::string src_path(FileUtil::SanitizePath(src_path_)); | ||
| 109 | std::string dest_path(FileUtil::SanitizePath(dest_path_)); | ||
| 102 | auto src = backing->GetFileRelative(src_path); | 110 | auto src = backing->GetFileRelative(src_path); |
| 103 | if (FileUtil::GetParentPath(src_path) == FileUtil::GetParentPath(dest_path)) { | 111 | if (FileUtil::GetParentPath(src_path) == FileUtil::GetParentPath(dest_path)) { |
| 104 | // Use more-optimized vfs implementation rename. | 112 | // Use more-optimized vfs implementation rename. |
| @@ -130,8 +138,10 @@ ResultCode VfsDirectoryServiceWrapper::RenameFile(const std::string& src_path, | |||
| 130 | return RESULT_SUCCESS; | 138 | return RESULT_SUCCESS; |
| 131 | } | 139 | } |
| 132 | 140 | ||
| 133 | ResultCode VfsDirectoryServiceWrapper::RenameDirectory(const std::string& src_path, | 141 | ResultCode VfsDirectoryServiceWrapper::RenameDirectory(const std::string& src_path_, |
| 134 | const std::string& dest_path) const { | 142 | const std::string& dest_path_) const { |
| 143 | std::string src_path(FileUtil::SanitizePath(src_path_)); | ||
| 144 | std::string dest_path(FileUtil::SanitizePath(dest_path_)); | ||
| 135 | auto src = GetDirectoryRelativeWrapped(backing, src_path); | 145 | auto src = GetDirectoryRelativeWrapped(backing, src_path); |
| 136 | if (FileUtil::GetParentPath(src_path) == FileUtil::GetParentPath(dest_path)) { | 146 | if (FileUtil::GetParentPath(src_path) == FileUtil::GetParentPath(dest_path)) { |
| 137 | // Use more-optimized vfs implementation rename. | 147 | // Use more-optimized vfs implementation rename. |
| @@ -154,8 +164,9 @@ ResultCode VfsDirectoryServiceWrapper::RenameDirectory(const std::string& src_pa | |||
| 154 | return ResultCode(-1); | 164 | return ResultCode(-1); |
| 155 | } | 165 | } |
| 156 | 166 | ||
| 157 | ResultVal<FileSys::VirtualFile> VfsDirectoryServiceWrapper::OpenFile(const std::string& path, | 167 | ResultVal<FileSys::VirtualFile> VfsDirectoryServiceWrapper::OpenFile(const std::string& path_, |
| 158 | FileSys::Mode mode) const { | 168 | FileSys::Mode mode) const { |
| 169 | std::string path(FileUtil::SanitizePath(path_)); | ||
| 159 | auto npath = path; | 170 | auto npath = path; |
| 160 | while (npath.size() > 0 && (npath[0] == '/' || npath[0] == '\\')) | 171 | while (npath.size() > 0 && (npath[0] == '/' || npath[0] == '\\')) |
| 161 | npath = npath.substr(1); | 172 | npath = npath.substr(1); |
| @@ -171,7 +182,8 @@ ResultVal<FileSys::VirtualFile> VfsDirectoryServiceWrapper::OpenFile(const std:: | |||
| 171 | return MakeResult<FileSys::VirtualFile>(file); | 182 | return MakeResult<FileSys::VirtualFile>(file); |
| 172 | } | 183 | } |
| 173 | 184 | ||
| 174 | ResultVal<FileSys::VirtualDir> VfsDirectoryServiceWrapper::OpenDirectory(const std::string& path) { | 185 | ResultVal<FileSys::VirtualDir> VfsDirectoryServiceWrapper::OpenDirectory(const std::string& path_) { |
| 186 | std::string path(FileUtil::SanitizePath(path_)); | ||
| 175 | auto dir = GetDirectoryRelativeWrapped(backing, path); | 187 | auto dir = GetDirectoryRelativeWrapped(backing, path); |
| 176 | if (dir == nullptr) { | 188 | if (dir == nullptr) { |
| 177 | // TODO(DarkLordZach): Find a better error code for this | 189 | // TODO(DarkLordZach): Find a better error code for this |
| @@ -188,7 +200,8 @@ u64 VfsDirectoryServiceWrapper::GetFreeSpaceSize() const { | |||
| 188 | } | 200 | } |
| 189 | 201 | ||
| 190 | ResultVal<FileSys::EntryType> VfsDirectoryServiceWrapper::GetEntryType( | 202 | ResultVal<FileSys::EntryType> VfsDirectoryServiceWrapper::GetEntryType( |
| 191 | const std::string& path) const { | 203 | const std::string& path_) const { |
| 204 | std::string path(FileUtil::SanitizePath(path_)); | ||
| 192 | auto dir = GetDirectoryRelativeWrapped(backing, FileUtil::GetParentPath(path)); | 205 | auto dir = GetDirectoryRelativeWrapped(backing, FileUtil::GetParentPath(path)); |
| 193 | if (dir == nullptr) | 206 | if (dir == nullptr) |
| 194 | return FileSys::ERROR_PATH_NOT_FOUND; | 207 | return FileSys::ERROR_PATH_NOT_FOUND; |
| @@ -272,9 +285,9 @@ void RegisterFileSystems() { | |||
| 272 | sdmc_factory = nullptr; | 285 | sdmc_factory = nullptr; |
| 273 | 286 | ||
| 274 | auto nand_directory = std::make_shared<FileSys::RealVfsDirectory>( | 287 | auto nand_directory = std::make_shared<FileSys::RealVfsDirectory>( |
| 275 | FileUtil::GetUserPath(FileUtil::UserPath::NANDDir), FileSys::Mode::Write); | 288 | FileUtil::GetUserPath(FileUtil::UserPath::NANDDir), FileSys::Mode::ReadWrite); |
| 276 | auto sd_directory = std::make_shared<FileSys::RealVfsDirectory>( | 289 | auto sd_directory = std::make_shared<FileSys::RealVfsDirectory>( |
| 277 | FileUtil::GetUserPath(FileUtil::UserPath::SDMCDir), FileSys::Mode::Write); | 290 | FileUtil::GetUserPath(FileUtil::UserPath::SDMCDir), FileSys::Mode::ReadWrite); |
| 278 | 291 | ||
| 279 | auto savedata = std::make_unique<FileSys::SaveDataFactory>(std::move(nand_directory)); | 292 | auto savedata = std::make_unique<FileSys::SaveDataFactory>(std::move(nand_directory)); |
| 280 | save_data_factory = std::move(savedata); | 293 | save_data_factory = std::move(savedata); |
diff --git a/src/core/hle/service/set/set.cpp b/src/core/hle/service/set/set.cpp index 4195c9067..1651f6122 100644 --- a/src/core/hle/service/set/set.cpp +++ b/src/core/hle/service/set/set.cpp | |||
| @@ -45,6 +45,8 @@ void SET::GetAvailableLanguageCodeCount(Kernel::HLERequestContext& ctx) { | |||
| 45 | IPC::ResponseBuilder rb{ctx, 3}; | 45 | IPC::ResponseBuilder rb{ctx, 3}; |
| 46 | rb.Push(RESULT_SUCCESS); | 46 | rb.Push(RESULT_SUCCESS); |
| 47 | rb.Push(static_cast<u32>(available_language_codes.size())); | 47 | rb.Push(static_cast<u32>(available_language_codes.size())); |
| 48 | |||
| 49 | LOG_DEBUG(Service_SET, "called"); | ||
| 48 | } | 50 | } |
| 49 | 51 | ||
| 50 | SET::SET() : ServiceFramework("set") { | 52 | SET::SET() : ServiceFramework("set") { |
diff --git a/src/core/hle/service/vi/vi.cpp b/src/core/hle/service/vi/vi.cpp index 3a69b85f9..993f1e65a 100644 --- a/src/core/hle/service/vi/vi.cpp +++ b/src/core/hle/service/vi/vi.cpp | |||
| @@ -5,6 +5,8 @@ | |||
| 5 | #include <algorithm> | 5 | #include <algorithm> |
| 6 | #include <array> | 6 | #include <array> |
| 7 | #include <memory> | 7 | #include <memory> |
| 8 | #include <type_traits> | ||
| 9 | #include <utility> | ||
| 8 | #include <boost/optional.hpp> | 10 | #include <boost/optional.hpp> |
| 9 | #include "common/alignment.h" | 11 | #include "common/alignment.h" |
| 10 | #include "common/math_util.h" | 12 | #include "common/math_util.h" |
| @@ -43,7 +45,9 @@ public: | |||
| 43 | 45 | ||
| 44 | template <typename T> | 46 | template <typename T> |
| 45 | T Read() { | 47 | T Read() { |
| 48 | static_assert(std::is_trivially_copyable_v<T>, "T must be trivially copyable."); | ||
| 46 | ASSERT(read_index + sizeof(T) <= buffer.size()); | 49 | ASSERT(read_index + sizeof(T) <= buffer.size()); |
| 50 | |||
| 47 | T val; | 51 | T val; |
| 48 | std::memcpy(&val, buffer.data() + read_index, sizeof(T)); | 52 | std::memcpy(&val, buffer.data() + read_index, sizeof(T)); |
| 49 | read_index += sizeof(T); | 53 | read_index += sizeof(T); |
| @@ -53,7 +57,9 @@ public: | |||
| 53 | 57 | ||
| 54 | template <typename T> | 58 | template <typename T> |
| 55 | T ReadUnaligned() { | 59 | T ReadUnaligned() { |
| 60 | static_assert(std::is_trivially_copyable_v<T>, "T must be trivially copyable."); | ||
| 56 | ASSERT(read_index + sizeof(T) <= buffer.size()); | 61 | ASSERT(read_index + sizeof(T) <= buffer.size()); |
| 62 | |||
| 57 | T val; | 63 | T val; |
| 58 | std::memcpy(&val, buffer.data() + read_index, sizeof(T)); | 64 | std::memcpy(&val, buffer.data() + read_index, sizeof(T)); |
| 59 | read_index += sizeof(T); | 65 | read_index += sizeof(T); |
| @@ -87,8 +93,12 @@ public: | |||
| 87 | 93 | ||
| 88 | template <typename T> | 94 | template <typename T> |
| 89 | void Write(const T& val) { | 95 | void Write(const T& val) { |
| 90 | if (buffer.size() < write_index + sizeof(T)) | 96 | static_assert(std::is_trivially_copyable_v<T>, "T must be trivially copyable."); |
| 97 | |||
| 98 | if (buffer.size() < write_index + sizeof(T)) { | ||
| 91 | buffer.resize(buffer.size() + sizeof(T) + DefaultBufferSize); | 99 | buffer.resize(buffer.size() + sizeof(T) + DefaultBufferSize); |
| 100 | } | ||
| 101 | |||
| 92 | std::memcpy(buffer.data() + write_index, &val, sizeof(T)); | 102 | std::memcpy(buffer.data() + write_index, &val, sizeof(T)); |
| 93 | write_index += sizeof(T); | 103 | write_index += sizeof(T); |
| 94 | write_index = Common::AlignUp(write_index, 4); | 104 | write_index = Common::AlignUp(write_index, 4); |
| @@ -96,7 +106,9 @@ public: | |||
| 96 | 106 | ||
| 97 | template <typename T> | 107 | template <typename T> |
| 98 | void WriteObject(const T& val) { | 108 | void WriteObject(const T& val) { |
| 99 | u32_le size = static_cast<u32>(sizeof(val)); | 109 | static_assert(std::is_trivially_copyable_v<T>, "T must be trivially copyable."); |
| 110 | |||
| 111 | const u32_le size = static_cast<u32>(sizeof(val)); | ||
| 100 | Write(size); | 112 | Write(size); |
| 101 | // TODO(Subv): Support file descriptors. | 113 | // TODO(Subv): Support file descriptors. |
| 102 | Write<u32_le>(0); // Fd count. | 114 | Write<u32_le>(0); // Fd count. |
| @@ -176,7 +188,7 @@ private: | |||
| 176 | 188 | ||
| 177 | class IGBPConnectRequestParcel : public Parcel { | 189 | class IGBPConnectRequestParcel : public Parcel { |
| 178 | public: | 190 | public: |
| 179 | explicit IGBPConnectRequestParcel(const std::vector<u8>& buffer) : Parcel(buffer) { | 191 | explicit IGBPConnectRequestParcel(std::vector<u8> buffer) : Parcel(std::move(buffer)) { |
| 180 | Deserialize(); | 192 | Deserialize(); |
| 181 | } | 193 | } |
| 182 | ~IGBPConnectRequestParcel() override = default; | 194 | ~IGBPConnectRequestParcel() override = default; |
| @@ -223,8 +235,8 @@ private: | |||
| 223 | 235 | ||
| 224 | class IGBPSetPreallocatedBufferRequestParcel : public Parcel { | 236 | class IGBPSetPreallocatedBufferRequestParcel : public Parcel { |
| 225 | public: | 237 | public: |
| 226 | explicit IGBPSetPreallocatedBufferRequestParcel(const std::vector<u8>& buffer) | 238 | explicit IGBPSetPreallocatedBufferRequestParcel(std::vector<u8> buffer) |
| 227 | : Parcel(buffer) { | 239 | : Parcel(std::move(buffer)) { |
| 228 | Deserialize(); | 240 | Deserialize(); |
| 229 | } | 241 | } |
| 230 | ~IGBPSetPreallocatedBufferRequestParcel() override = default; | 242 | ~IGBPSetPreallocatedBufferRequestParcel() override = default; |
| @@ -256,7 +268,7 @@ protected: | |||
| 256 | 268 | ||
| 257 | class IGBPDequeueBufferRequestParcel : public Parcel { | 269 | class IGBPDequeueBufferRequestParcel : public Parcel { |
| 258 | public: | 270 | public: |
| 259 | explicit IGBPDequeueBufferRequestParcel(const std::vector<u8>& buffer) : Parcel(buffer) { | 271 | explicit IGBPDequeueBufferRequestParcel(std::vector<u8> buffer) : Parcel(std::move(buffer)) { |
| 260 | Deserialize(); | 272 | Deserialize(); |
| 261 | } | 273 | } |
| 262 | ~IGBPDequeueBufferRequestParcel() override = default; | 274 | ~IGBPDequeueBufferRequestParcel() override = default; |
| @@ -307,7 +319,7 @@ protected: | |||
| 307 | 319 | ||
| 308 | class IGBPRequestBufferRequestParcel : public Parcel { | 320 | class IGBPRequestBufferRequestParcel : public Parcel { |
| 309 | public: | 321 | public: |
| 310 | explicit IGBPRequestBufferRequestParcel(const std::vector<u8>& buffer) : Parcel(buffer) { | 322 | explicit IGBPRequestBufferRequestParcel(std::vector<u8> buffer) : Parcel(std::move(buffer)) { |
| 311 | Deserialize(); | 323 | Deserialize(); |
| 312 | } | 324 | } |
| 313 | ~IGBPRequestBufferRequestParcel() override = default; | 325 | ~IGBPRequestBufferRequestParcel() override = default; |
| @@ -322,8 +334,7 @@ public: | |||
| 322 | 334 | ||
| 323 | class IGBPRequestBufferResponseParcel : public Parcel { | 335 | class IGBPRequestBufferResponseParcel : public Parcel { |
| 324 | public: | 336 | public: |
| 325 | explicit IGBPRequestBufferResponseParcel(NVFlinger::IGBPBuffer buffer) | 337 | explicit IGBPRequestBufferResponseParcel(NVFlinger::IGBPBuffer buffer) : buffer(buffer) {} |
| 326 | : Parcel(), buffer(buffer) {} | ||
| 327 | ~IGBPRequestBufferResponseParcel() override = default; | 338 | ~IGBPRequestBufferResponseParcel() override = default; |
| 328 | 339 | ||
| 329 | protected: | 340 | protected: |
| @@ -340,7 +351,7 @@ protected: | |||
| 340 | 351 | ||
| 341 | class IGBPQueueBufferRequestParcel : public Parcel { | 352 | class IGBPQueueBufferRequestParcel : public Parcel { |
| 342 | public: | 353 | public: |
| 343 | explicit IGBPQueueBufferRequestParcel(const std::vector<u8>& buffer) : Parcel(buffer) { | 354 | explicit IGBPQueueBufferRequestParcel(std::vector<u8> buffer) : Parcel(std::move(buffer)) { |
| 344 | Deserialize(); | 355 | Deserialize(); |
| 345 | } | 356 | } |
| 346 | ~IGBPQueueBufferRequestParcel() override = default; | 357 | ~IGBPQueueBufferRequestParcel() override = default; |
| @@ -409,7 +420,7 @@ private: | |||
| 409 | 420 | ||
| 410 | class IGBPQueryRequestParcel : public Parcel { | 421 | class IGBPQueryRequestParcel : public Parcel { |
| 411 | public: | 422 | public: |
| 412 | explicit IGBPQueryRequestParcel(const std::vector<u8>& buffer) : Parcel(buffer) { | 423 | explicit IGBPQueryRequestParcel(std::vector<u8> buffer) : Parcel(std::move(buffer)) { |
| 413 | Deserialize(); | 424 | Deserialize(); |
| 414 | } | 425 | } |
| 415 | ~IGBPQueryRequestParcel() override = default; | 426 | ~IGBPQueryRequestParcel() override = default; |
diff --git a/src/core/hle/shared_page.cpp b/src/core/hle/shared_page.cpp deleted file mode 100644 index 9ed8ab249..000000000 --- a/src/core/hle/shared_page.cpp +++ /dev/null | |||
| @@ -1,86 +0,0 @@ | |||
| 1 | // Copyright 2015 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include <chrono> | ||
| 6 | #include <cstring> | ||
| 7 | #include <ctime> | ||
| 8 | #include "core/core_timing.h" | ||
| 9 | #include "core/hle/shared_page.h" | ||
| 10 | |||
| 11 | //////////////////////////////////////////////////////////////////////////////////////////////////// | ||
| 12 | |||
| 13 | namespace SharedPage { | ||
| 14 | |||
| 15 | SharedPageDef shared_page; | ||
| 16 | |||
| 17 | static CoreTiming::EventType* update_time_event; | ||
| 18 | |||
| 19 | /// Gets system time in 3DS format. The epoch is Jan 1900, and the unit is millisecond. | ||
| 20 | static u64 GetSystemTime() { | ||
| 21 | auto now = std::chrono::system_clock::now(); | ||
| 22 | |||
| 23 | // 3DS system does't allow user to set a time before Jan 1 2000, | ||
| 24 | // so we use it as an auxiliary epoch to calculate the console time. | ||
| 25 | std::tm epoch_tm; | ||
| 26 | epoch_tm.tm_sec = 0; | ||
| 27 | epoch_tm.tm_min = 0; | ||
| 28 | epoch_tm.tm_hour = 0; | ||
| 29 | epoch_tm.tm_mday = 1; | ||
| 30 | epoch_tm.tm_mon = 0; | ||
| 31 | epoch_tm.tm_year = 100; | ||
| 32 | epoch_tm.tm_isdst = 0; | ||
| 33 | auto epoch = std::chrono::system_clock::from_time_t(std::mktime(&epoch_tm)); | ||
| 34 | |||
| 35 | // 3DS console time uses Jan 1 1900 as internal epoch, | ||
| 36 | // so we use the milliseconds between 1900 and 2000 as base console time | ||
| 37 | u64 console_time = 3155673600000ULL; | ||
| 38 | |||
| 39 | // Only when system time is after 2000, we set it as 3DS system time | ||
| 40 | if (now > epoch) { | ||
| 41 | console_time += std::chrono::duration_cast<std::chrono::milliseconds>(now - epoch).count(); | ||
| 42 | } | ||
| 43 | |||
| 44 | // If the system time is in daylight saving, we give an additional hour to console time | ||
| 45 | std::time_t now_time_t = std::chrono::system_clock::to_time_t(now); | ||
| 46 | std::tm* now_tm = std::localtime(&now_time_t); | ||
| 47 | if (now_tm && now_tm->tm_isdst > 0) | ||
| 48 | console_time += 60 * 60 * 1000; | ||
| 49 | |||
| 50 | return console_time; | ||
| 51 | } | ||
| 52 | |||
| 53 | static void UpdateTimeCallback(u64 userdata, int cycles_late) { | ||
| 54 | DateTime& date_time = | ||
| 55 | shared_page.date_time_counter % 2 ? shared_page.date_time_0 : shared_page.date_time_1; | ||
| 56 | |||
| 57 | date_time.date_time = GetSystemTime(); | ||
| 58 | date_time.update_tick = CoreTiming::GetTicks(); | ||
| 59 | date_time.tick_to_second_coefficient = CoreTiming::BASE_CLOCK_RATE; | ||
| 60 | date_time.tick_offset = 0; | ||
| 61 | |||
| 62 | ++shared_page.date_time_counter; | ||
| 63 | |||
| 64 | // system time is updated hourly | ||
| 65 | CoreTiming::ScheduleEvent(CoreTiming::msToCycles(60 * 60 * 1000) - cycles_late, | ||
| 66 | update_time_event); | ||
| 67 | } | ||
| 68 | |||
| 69 | void Init() { | ||
| 70 | std::memset(&shared_page, 0, sizeof(shared_page)); | ||
| 71 | |||
| 72 | shared_page.running_hw = 0x1; // product | ||
| 73 | |||
| 74 | // Some games wait until this value becomes 0x1, before asking running_hw | ||
| 75 | shared_page.unknown_value = 0x1; | ||
| 76 | |||
| 77 | // Set to a completely full battery | ||
| 78 | shared_page.battery_state.is_adapter_connected.Assign(1); | ||
| 79 | shared_page.battery_state.is_charging.Assign(1); | ||
| 80 | |||
| 81 | update_time_event = | ||
| 82 | CoreTiming::RegisterEvent("SharedPage::UpdateTimeCallback", UpdateTimeCallback); | ||
| 83 | CoreTiming::ScheduleEvent(0, update_time_event); | ||
| 84 | } | ||
| 85 | |||
| 86 | } // namespace SharedPage | ||
diff --git a/src/core/hle/shared_page.h b/src/core/hle/shared_page.h deleted file mode 100644 index a58259888..000000000 --- a/src/core/hle/shared_page.h +++ /dev/null | |||
| @@ -1,69 +0,0 @@ | |||
| 1 | // Copyright 2015 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | /** | ||
| 8 | * The shared page stores various runtime configuration settings. This memory page is | ||
| 9 | * read-only for user processes (there is a bit in the header that grants the process | ||
| 10 | * write access, according to 3dbrew; this is not emulated) | ||
| 11 | */ | ||
| 12 | |||
| 13 | #include "common/bit_field.h" | ||
| 14 | #include "common/common_funcs.h" | ||
| 15 | #include "common/common_types.h" | ||
| 16 | #include "common/swap.h" | ||
| 17 | #include "core/memory.h" | ||
| 18 | |||
| 19 | //////////////////////////////////////////////////////////////////////////////////////////////////// | ||
| 20 | |||
| 21 | namespace SharedPage { | ||
| 22 | |||
| 23 | // See http://3dbrew.org/wiki/Configuration_Memory#Shared_Memory_Page_For_ARM11_Processes | ||
| 24 | |||
| 25 | struct DateTime { | ||
| 26 | u64_le date_time; // 0 | ||
| 27 | u64_le update_tick; // 8 | ||
| 28 | u64_le tick_to_second_coefficient; // 10 | ||
| 29 | u64_le tick_offset; // 18 | ||
| 30 | }; | ||
| 31 | static_assert(sizeof(DateTime) == 0x20, "Datetime size is wrong"); | ||
| 32 | |||
| 33 | union BatteryState { | ||
| 34 | u8 raw; | ||
| 35 | BitField<0, 1, u8> is_adapter_connected; | ||
| 36 | BitField<1, 1, u8> is_charging; | ||
| 37 | BitField<2, 3, u8> charge_level; | ||
| 38 | }; | ||
| 39 | |||
| 40 | struct SharedPageDef { | ||
| 41 | // Most of these names are taken from the 3dbrew page linked above. | ||
| 42 | u32_le date_time_counter; // 0 | ||
| 43 | u8 running_hw; // 4 | ||
| 44 | /// "Microcontroller hardware info" | ||
| 45 | u8 mcu_hw_info; // 5 | ||
| 46 | INSERT_PADDING_BYTES(0x20 - 0x6); // 6 | ||
| 47 | DateTime date_time_0; // 20 | ||
| 48 | DateTime date_time_1; // 40 | ||
| 49 | u8 wifi_macaddr[6]; // 60 | ||
| 50 | u8 wifi_link_level; // 66 | ||
| 51 | u8 wifi_unknown2; // 67 | ||
| 52 | INSERT_PADDING_BYTES(0x80 - 0x68); // 68 | ||
| 53 | float_le sliderstate_3d; // 80 | ||
| 54 | u8 ledstate_3d; // 84 | ||
| 55 | BatteryState battery_state; // 85 | ||
| 56 | u8 unknown_value; // 86 | ||
| 57 | INSERT_PADDING_BYTES(0xA0 - 0x87); // 87 | ||
| 58 | u64_le menu_title_id; // A0 | ||
| 59 | u64_le active_menu_title_id; // A8 | ||
| 60 | INSERT_PADDING_BYTES(0x1000 - 0xB0); // B0 | ||
| 61 | }; | ||
| 62 | static_assert(sizeof(SharedPageDef) == Memory::SHARED_PAGE_SIZE, | ||
| 63 | "Shared page structure size is wrong"); | ||
| 64 | |||
| 65 | extern SharedPageDef shared_page; | ||
| 66 | |||
| 67 | void Init(); | ||
| 68 | |||
| 69 | } // namespace SharedPage | ||
diff --git a/src/core/loader/linker.cpp b/src/core/loader/linker.cpp index 769516b6f..57ca8c3ee 100644 --- a/src/core/loader/linker.cpp +++ b/src/core/loader/linker.cpp | |||
| @@ -49,8 +49,7 @@ struct Elf64_Sym { | |||
| 49 | static_assert(sizeof(Elf64_Sym) == 0x18, "Elf64_Sym has incorrect size."); | 49 | static_assert(sizeof(Elf64_Sym) == 0x18, "Elf64_Sym has incorrect size."); |
| 50 | 50 | ||
| 51 | void Linker::WriteRelocations(std::vector<u8>& program_image, const std::vector<Symbol>& symbols, | 51 | void Linker::WriteRelocations(std::vector<u8>& program_image, const std::vector<Symbol>& symbols, |
| 52 | u64 relocation_offset, u64 size, bool is_jump_relocation, | 52 | u64 relocation_offset, u64 size, VAddr load_base) { |
| 53 | VAddr load_base) { | ||
| 54 | for (u64 i = 0; i < size; i += sizeof(Elf64_Rela)) { | 53 | for (u64 i = 0; i < size; i += sizeof(Elf64_Rela)) { |
| 55 | Elf64_Rela rela; | 54 | Elf64_Rela rela; |
| 56 | std::memcpy(&rela, &program_image[relocation_offset + i], sizeof(Elf64_Rela)); | 55 | std::memcpy(&rela, &program_image[relocation_offset + i], sizeof(Elf64_Rela)); |
| @@ -124,12 +123,11 @@ void Linker::Relocate(std::vector<u8>& program_image, u32 dynamic_section_offset | |||
| 124 | } | 123 | } |
| 125 | 124 | ||
| 126 | if (dynamic.find(DT_RELA) != dynamic.end()) { | 125 | if (dynamic.find(DT_RELA) != dynamic.end()) { |
| 127 | WriteRelocations(program_image, symbols, dynamic[DT_RELA], dynamic[DT_RELASZ], false, | 126 | WriteRelocations(program_image, symbols, dynamic[DT_RELA], dynamic[DT_RELASZ], load_base); |
| 128 | load_base); | ||
| 129 | } | 127 | } |
| 130 | 128 | ||
| 131 | if (dynamic.find(DT_JMPREL) != dynamic.end()) { | 129 | if (dynamic.find(DT_JMPREL) != dynamic.end()) { |
| 132 | WriteRelocations(program_image, symbols, dynamic[DT_JMPREL], dynamic[DT_PLTRELSZ], true, | 130 | WriteRelocations(program_image, symbols, dynamic[DT_JMPREL], dynamic[DT_PLTRELSZ], |
| 133 | load_base); | 131 | load_base); |
| 134 | } | 132 | } |
| 135 | } | 133 | } |
diff --git a/src/core/loader/linker.h b/src/core/loader/linker.h index c09d382c1..107625837 100644 --- a/src/core/loader/linker.h +++ b/src/core/loader/linker.h | |||
| @@ -24,8 +24,7 @@ protected: | |||
| 24 | }; | 24 | }; |
| 25 | 25 | ||
| 26 | void WriteRelocations(std::vector<u8>& program_image, const std::vector<Symbol>& symbols, | 26 | void WriteRelocations(std::vector<u8>& program_image, const std::vector<Symbol>& symbols, |
| 27 | u64 relocation_offset, u64 size, bool is_jump_relocation, | 27 | u64 relocation_offset, u64 size, VAddr load_base); |
| 28 | VAddr load_base); | ||
| 29 | void Relocate(std::vector<u8>& program_image, u32 dynamic_section_offset, VAddr load_base); | 28 | void Relocate(std::vector<u8>& program_image, u32 dynamic_section_offset, VAddr load_base); |
| 30 | 29 | ||
| 31 | void ResolveImports(); | 30 | void ResolveImports(); |
diff --git a/src/core/loader/loader.cpp b/src/core/loader/loader.cpp index 4cbd9e285..cbc4177c6 100644 --- a/src/core/loader/loader.cpp +++ b/src/core/loader/loader.cpp | |||
| @@ -42,7 +42,7 @@ FileType IdentifyFile(FileSys::VirtualFile file) { | |||
| 42 | } | 42 | } |
| 43 | 43 | ||
| 44 | FileType IdentifyFile(const std::string& file_name) { | 44 | FileType IdentifyFile(const std::string& file_name) { |
| 45 | return IdentifyFile(FileSys::VirtualFile(std::make_shared<FileSys::RealVfsFile>(file_name))); | 45 | return IdentifyFile(std::make_shared<FileSys::RealVfsFile>(file_name)); |
| 46 | } | 46 | } |
| 47 | 47 | ||
| 48 | FileType GuessFromFilename(const std::string& name) { | 48 | FileType GuessFromFilename(const std::string& name) { |
diff --git a/src/core/loader/nro.cpp b/src/core/loader/nro.cpp index c020399f2..7d3ec2a76 100644 --- a/src/core/loader/nro.cpp +++ b/src/core/loader/nro.cpp | |||
| @@ -6,10 +6,13 @@ | |||
| 6 | #include <vector> | 6 | #include <vector> |
| 7 | 7 | ||
| 8 | #include "common/common_funcs.h" | 8 | #include "common/common_funcs.h" |
| 9 | #include "common/common_types.h" | ||
| 9 | #include "common/file_util.h" | 10 | #include "common/file_util.h" |
| 10 | #include "common/logging/log.h" | 11 | #include "common/logging/log.h" |
| 11 | #include "common/swap.h" | 12 | #include "common/swap.h" |
| 12 | #include "core/core.h" | 13 | #include "core/core.h" |
| 14 | #include "core/file_sys/control_metadata.h" | ||
| 15 | #include "core/file_sys/vfs_offset.h" | ||
| 13 | #include "core/gdbstub/gdbstub.h" | 16 | #include "core/gdbstub/gdbstub.h" |
| 14 | #include "core/hle/kernel/process.h" | 17 | #include "core/hle/kernel/process.h" |
| 15 | #include "core/hle/kernel/resource_limit.h" | 18 | #include "core/hle/kernel/resource_limit.h" |
| @@ -49,7 +52,62 @@ struct ModHeader { | |||
| 49 | }; | 52 | }; |
| 50 | static_assert(sizeof(ModHeader) == 0x1c, "ModHeader has incorrect size."); | 53 | static_assert(sizeof(ModHeader) == 0x1c, "ModHeader has incorrect size."); |
| 51 | 54 | ||
| 52 | AppLoader_NRO::AppLoader_NRO(FileSys::VirtualFile file) : AppLoader(std::move(file)) {} | 55 | struct AssetSection { |
| 56 | u64_le offset; | ||
| 57 | u64_le size; | ||
| 58 | }; | ||
| 59 | static_assert(sizeof(AssetSection) == 0x10, "AssetSection has incorrect size."); | ||
| 60 | |||
| 61 | struct AssetHeader { | ||
| 62 | u32_le magic; | ||
| 63 | u32_le format_version; | ||
| 64 | AssetSection icon; | ||
| 65 | AssetSection nacp; | ||
| 66 | AssetSection romfs; | ||
| 67 | }; | ||
| 68 | static_assert(sizeof(AssetHeader) == 0x38, "AssetHeader has incorrect size."); | ||
| 69 | |||
| 70 | AppLoader_NRO::AppLoader_NRO(FileSys::VirtualFile file) : AppLoader(file) { | ||
| 71 | NroHeader nro_header{}; | ||
| 72 | if (file->ReadObject(&nro_header) != sizeof(NroHeader)) { | ||
| 73 | return; | ||
| 74 | } | ||
| 75 | |||
| 76 | if (file->GetSize() >= nro_header.file_size + sizeof(AssetHeader)) { | ||
| 77 | const u64 offset = nro_header.file_size; | ||
| 78 | AssetHeader asset_header{}; | ||
| 79 | if (file->ReadObject(&asset_header, offset) != sizeof(AssetHeader)) { | ||
| 80 | return; | ||
| 81 | } | ||
| 82 | |||
| 83 | if (asset_header.format_version != 0) { | ||
| 84 | LOG_WARNING(Loader, | ||
| 85 | "NRO Asset Header has format {}, currently supported format is 0. If " | ||
| 86 | "strange glitches occur with metadata, check NRO assets.", | ||
| 87 | asset_header.format_version); | ||
| 88 | } | ||
| 89 | |||
| 90 | if (asset_header.magic != Common::MakeMagic('A', 'S', 'E', 'T')) { | ||
| 91 | return; | ||
| 92 | } | ||
| 93 | |||
| 94 | if (asset_header.nacp.size > 0) { | ||
| 95 | nacp = std::make_unique<FileSys::NACP>(std::make_shared<FileSys::OffsetVfsFile>( | ||
| 96 | file, asset_header.nacp.size, offset + asset_header.nacp.offset, "Control.nacp")); | ||
| 97 | } | ||
| 98 | |||
| 99 | if (asset_header.romfs.size > 0) { | ||
| 100 | romfs = std::make_shared<FileSys::OffsetVfsFile>( | ||
| 101 | file, asset_header.romfs.size, offset + asset_header.romfs.offset, "game.romfs"); | ||
| 102 | } | ||
| 103 | |||
| 104 | if (asset_header.icon.size > 0) { | ||
| 105 | icon_data = file->ReadBytes(asset_header.icon.size, offset + asset_header.icon.offset); | ||
| 106 | } | ||
| 107 | } | ||
| 108 | } | ||
| 109 | |||
| 110 | AppLoader_NRO::~AppLoader_NRO() = default; | ||
| 53 | 111 | ||
| 54 | FileType AppLoader_NRO::IdentifyType(const FileSys::VirtualFile& file) { | 112 | FileType AppLoader_NRO::IdentifyType(const FileSys::VirtualFile& file) { |
| 55 | // Read NSO header | 113 | // Read NSO header |
| @@ -80,8 +138,9 @@ bool AppLoader_NRO::LoadNro(FileSys::VirtualFile file, VAddr load_base) { | |||
| 80 | // Build program image | 138 | // Build program image |
| 81 | Kernel::SharedPtr<Kernel::CodeSet> codeset = Kernel::CodeSet::Create(""); | 139 | Kernel::SharedPtr<Kernel::CodeSet> codeset = Kernel::CodeSet::Create(""); |
| 82 | std::vector<u8> program_image = file->ReadBytes(PageAlignSize(nro_header.file_size)); | 140 | std::vector<u8> program_image = file->ReadBytes(PageAlignSize(nro_header.file_size)); |
| 83 | if (program_image.size() != PageAlignSize(nro_header.file_size)) | 141 | if (program_image.size() != PageAlignSize(nro_header.file_size)) { |
| 84 | return {}; | 142 | return {}; |
| 143 | } | ||
| 85 | 144 | ||
| 86 | for (std::size_t i = 0; i < nro_header.segments.size(); ++i) { | 145 | for (std::size_t i = 0; i < nro_header.segments.size(); ++i) { |
| 87 | codeset->segments[i].addr = nro_header.segments[i].offset; | 146 | codeset->segments[i].addr = nro_header.segments[i].offset; |
| @@ -136,4 +195,39 @@ ResultStatus AppLoader_NRO::Load(Kernel::SharedPtr<Kernel::Process>& process) { | |||
| 136 | return ResultStatus::Success; | 195 | return ResultStatus::Success; |
| 137 | } | 196 | } |
| 138 | 197 | ||
| 198 | ResultStatus AppLoader_NRO::ReadIcon(std::vector<u8>& buffer) { | ||
| 199 | if (icon_data.empty()) { | ||
| 200 | return ResultStatus::ErrorNotUsed; | ||
| 201 | } | ||
| 202 | |||
| 203 | buffer = icon_data; | ||
| 204 | return ResultStatus::Success; | ||
| 205 | } | ||
| 206 | |||
| 207 | ResultStatus AppLoader_NRO::ReadProgramId(u64& out_program_id) { | ||
| 208 | if (nacp == nullptr) { | ||
| 209 | return ResultStatus::ErrorNotUsed; | ||
| 210 | } | ||
| 211 | |||
| 212 | out_program_id = nacp->GetTitleId(); | ||
| 213 | return ResultStatus::Success; | ||
| 214 | } | ||
| 215 | |||
| 216 | ResultStatus AppLoader_NRO::ReadRomFS(FileSys::VirtualFile& dir) { | ||
| 217 | if (romfs == nullptr) { | ||
| 218 | return ResultStatus::ErrorNotUsed; | ||
| 219 | } | ||
| 220 | |||
| 221 | dir = romfs; | ||
| 222 | return ResultStatus::Success; | ||
| 223 | } | ||
| 224 | |||
| 225 | ResultStatus AppLoader_NRO::ReadTitle(std::string& title) { | ||
| 226 | if (nacp == nullptr) { | ||
| 227 | return ResultStatus::ErrorNotUsed; | ||
| 228 | } | ||
| 229 | |||
| 230 | title = nacp->GetApplicationName(); | ||
| 231 | return ResultStatus::Success; | ||
| 232 | } | ||
| 139 | } // namespace Loader | 233 | } // namespace Loader |
diff --git a/src/core/loader/nro.h b/src/core/loader/nro.h index 2c03d06bb..04a0f497e 100644 --- a/src/core/loader/nro.h +++ b/src/core/loader/nro.h | |||
| @@ -10,12 +10,17 @@ | |||
| 10 | #include "core/loader/linker.h" | 10 | #include "core/loader/linker.h" |
| 11 | #include "core/loader/loader.h" | 11 | #include "core/loader/loader.h" |
| 12 | 12 | ||
| 13 | namespace FileSys { | ||
| 14 | class NACP; | ||
| 15 | } | ||
| 16 | |||
| 13 | namespace Loader { | 17 | namespace Loader { |
| 14 | 18 | ||
| 15 | /// Loads an NRO file | 19 | /// Loads an NRO file |
| 16 | class AppLoader_NRO final : public AppLoader, Linker { | 20 | class AppLoader_NRO final : public AppLoader, Linker { |
| 17 | public: | 21 | public: |
| 18 | AppLoader_NRO(FileSys::VirtualFile file); | 22 | explicit AppLoader_NRO(FileSys::VirtualFile file); |
| 23 | ~AppLoader_NRO() override; | ||
| 19 | 24 | ||
| 20 | /** | 25 | /** |
| 21 | * Returns the type of the file | 26 | * Returns the type of the file |
| @@ -30,8 +35,17 @@ public: | |||
| 30 | 35 | ||
| 31 | ResultStatus Load(Kernel::SharedPtr<Kernel::Process>& process) override; | 36 | ResultStatus Load(Kernel::SharedPtr<Kernel::Process>& process) override; |
| 32 | 37 | ||
| 38 | ResultStatus ReadIcon(std::vector<u8>& buffer) override; | ||
| 39 | ResultStatus ReadProgramId(u64& out_program_id) override; | ||
| 40 | ResultStatus ReadRomFS(FileSys::VirtualFile& dir) override; | ||
| 41 | ResultStatus ReadTitle(std::string& title) override; | ||
| 42 | |||
| 33 | private: | 43 | private: |
| 34 | bool LoadNro(FileSys::VirtualFile file, VAddr load_base); | 44 | bool LoadNro(FileSys::VirtualFile file, VAddr load_base); |
| 45 | |||
| 46 | std::vector<u8> icon_data; | ||
| 47 | std::unique_ptr<FileSys::NACP> nacp; | ||
| 48 | FileSys::VirtualFile romfs; | ||
| 35 | }; | 49 | }; |
| 36 | 50 | ||
| 37 | } // namespace Loader | 51 | } // namespace Loader |
diff --git a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp index ba827181b..acf067050 100644 --- a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp +++ b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp | |||
| @@ -6,6 +6,9 @@ | |||
| 6 | #include <set> | 6 | #include <set> |
| 7 | #include <string> | 7 | #include <string> |
| 8 | #include <string_view> | 8 | #include <string_view> |
| 9 | |||
| 10 | #include <fmt/format.h> | ||
| 11 | |||
| 9 | #include "common/assert.h" | 12 | #include "common/assert.h" |
| 10 | #include "common/common_types.h" | 13 | #include "common/common_types.h" |
| 11 | #include "video_core/engines/shader_bytecode.h" | 14 | #include "video_core/engines/shader_bytecode.h" |
| @@ -485,6 +488,12 @@ private: | |||
| 485 | */ | 488 | */ |
| 486 | void SetRegister(const Register& reg, u64 elem, const std::string& value, | 489 | void SetRegister(const Register& reg, u64 elem, const std::string& value, |
| 487 | u64 dest_num_components, u64 value_num_components, u64 dest_elem) { | 490 | u64 dest_num_components, u64 value_num_components, u64 dest_elem) { |
| 491 | if (reg == Register::ZeroIndex) { | ||
| 492 | LOG_CRITICAL(HW_GPU, "Cannot set Register::ZeroIndex"); | ||
| 493 | UNREACHABLE(); | ||
| 494 | return; | ||
| 495 | } | ||
| 496 | |||
| 488 | std::string dest = GetRegister(reg, static_cast<u32>(dest_elem)); | 497 | std::string dest = GetRegister(reg, static_cast<u32>(dest_elem)); |
| 489 | if (dest_num_components > 1) { | 498 | if (dest_num_components > 1) { |
| 490 | dest += GetSwizzle(elem); | 499 | dest += GetSwizzle(elem); |
| @@ -747,6 +756,38 @@ private: | |||
| 747 | } | 756 | } |
| 748 | } | 757 | } |
| 749 | 758 | ||
| 759 | void WriteTexsInstruction(const Instruction& instr, const std::string& coord, | ||
| 760 | const std::string& texture) { | ||
| 761 | // Add an extra scope and declare the texture coords inside to prevent | ||
| 762 | // overwriting them in case they are used as outputs of the texs instruction. | ||
| 763 | shader.AddLine('{'); | ||
| 764 | ++shader.scope; | ||
| 765 | shader.AddLine(coord); | ||
| 766 | |||
| 767 | // TEXS has two destination registers. RG goes into gpr0+0 and gpr0+1, and BA | ||
| 768 | // goes into gpr28+0 and gpr28+1 | ||
| 769 | size_t texs_offset{}; | ||
| 770 | |||
| 771 | for (const auto& dest : {instr.gpr0.Value(), instr.gpr28.Value()}) { | ||
| 772 | for (unsigned elem = 0; elem < 2; ++elem) { | ||
| 773 | if (!instr.texs.IsComponentEnabled(elem)) { | ||
| 774 | // Skip disabled components | ||
| 775 | continue; | ||
| 776 | } | ||
| 777 | regs.SetRegisterToFloat(dest, elem + texs_offset, texture, 1, 4, false, elem); | ||
| 778 | } | ||
| 779 | |||
| 780 | if (!instr.texs.HasTwoDestinations()) { | ||
| 781 | // Skip the second destination | ||
| 782 | break; | ||
| 783 | } | ||
| 784 | |||
| 785 | texs_offset += 2; | ||
| 786 | } | ||
| 787 | --shader.scope; | ||
| 788 | shader.AddLine('}'); | ||
| 789 | } | ||
| 790 | |||
| 750 | /** | 791 | /** |
| 751 | * Compiles a single instruction from Tegra to GLSL. | 792 | * Compiles a single instruction from Tegra to GLSL. |
| 752 | * @param offset the offset of the Tegra shader instruction. | 793 | * @param offset the offset of the Tegra shader instruction. |
| @@ -769,7 +810,8 @@ private: | |||
| 769 | return offset + 1; | 810 | return offset + 1; |
| 770 | } | 811 | } |
| 771 | 812 | ||
| 772 | shader.AddLine("// " + std::to_string(offset) + ": " + opcode->GetName()); | 813 | shader.AddLine("// " + std::to_string(offset) + ": " + opcode->GetName() + " (" + |
| 814 | std::to_string(instr.value) + ')'); | ||
| 773 | 815 | ||
| 774 | using Tegra::Shader::Pred; | 816 | using Tegra::Shader::Pred; |
| 775 | ASSERT_MSG(instr.pred.full_pred != Pred::NeverExecute, | 817 | ASSERT_MSG(instr.pred.full_pred != Pred::NeverExecute, |
| @@ -1345,36 +1387,18 @@ private: | |||
| 1345 | const std::string op_b = regs.GetRegisterAsFloat(instr.gpr20); | 1387 | const std::string op_b = regs.GetRegisterAsFloat(instr.gpr20); |
| 1346 | const std::string sampler = GetSampler(instr.sampler); | 1388 | const std::string sampler = GetSampler(instr.sampler); |
| 1347 | const std::string coord = "vec2 coords = vec2(" + op_a + ", " + op_b + ");"; | 1389 | const std::string coord = "vec2 coords = vec2(" + op_a + ", " + op_b + ");"; |
| 1348 | // Add an extra scope and declare the texture coords inside to prevent | ||
| 1349 | // overwriting them in case they are used as outputs of the texs instruction. | ||
| 1350 | shader.AddLine("{"); | ||
| 1351 | ++shader.scope; | ||
| 1352 | shader.AddLine(coord); | ||
| 1353 | const std::string texture = "texture(" + sampler + ", coords)"; | ||
| 1354 | |||
| 1355 | // TEXS has two destination registers. RG goes into gpr0+0 and gpr0+1, and BA | ||
| 1356 | // goes into gpr28+0 and gpr28+1 | ||
| 1357 | size_t texs_offset{}; | ||
| 1358 | |||
| 1359 | for (const auto& dest : {instr.gpr0.Value(), instr.gpr28.Value()}) { | ||
| 1360 | for (unsigned elem = 0; elem < 2; ++elem) { | ||
| 1361 | if (!instr.texs.IsComponentEnabled(elem)) { | ||
| 1362 | // Skip disabled components | ||
| 1363 | continue; | ||
| 1364 | } | ||
| 1365 | regs.SetRegisterToFloat(dest, elem + texs_offset, texture, 1, 4, false, | ||
| 1366 | elem); | ||
| 1367 | } | ||
| 1368 | 1390 | ||
| 1369 | if (!instr.texs.HasTwoDestinations()) { | 1391 | const std::string texture = "texture(" + sampler + ", coords)"; |
| 1370 | // Skip the second destination | 1392 | WriteTexsInstruction(instr, coord, texture); |
| 1371 | break; | 1393 | break; |
| 1372 | } | 1394 | } |
| 1373 | 1395 | case OpCode::Id::TLDS: { | |
| 1374 | texs_offset += 2; | 1396 | const std::string op_a = regs.GetRegisterAsInteger(instr.gpr8); |
| 1375 | } | 1397 | const std::string op_b = regs.GetRegisterAsInteger(instr.gpr20); |
| 1376 | --shader.scope; | 1398 | const std::string sampler = GetSampler(instr.sampler); |
| 1377 | shader.AddLine("}"); | 1399 | const std::string coord = "ivec2 coords = ivec2(" + op_a + ", " + op_b + ");"; |
| 1400 | const std::string texture = "texelFetch(" + sampler + ", coords, 0)"; | ||
| 1401 | WriteTexsInstruction(instr, coord, texture); | ||
| 1378 | break; | 1402 | break; |
| 1379 | } | 1403 | } |
| 1380 | default: { | 1404 | default: { |
| @@ -1774,11 +1798,8 @@ private: | |||
| 1774 | }; // namespace Decompiler | 1798 | }; // namespace Decompiler |
| 1775 | 1799 | ||
| 1776 | std::string GetCommonDeclarations() { | 1800 | std::string GetCommonDeclarations() { |
| 1777 | std::string declarations; | 1801 | return fmt::format("#define MAX_CONSTBUFFER_ELEMENTS {}\n", |
| 1778 | declarations += "#define MAX_CONSTBUFFER_ELEMENTS " + | 1802 | RasterizerOpenGL::MaxConstbufferSize / sizeof(GLvec4)); |
| 1779 | std::to_string(RasterizerOpenGL::MaxConstbufferSize / (sizeof(GLvec4))); | ||
| 1780 | declarations += '\n'; | ||
| 1781 | return declarations; | ||
| 1782 | } | 1803 | } |
| 1783 | 1804 | ||
| 1784 | boost::optional<ProgramResult> DecompileProgram(const ProgramCode& program_code, u32 main_offset, | 1805 | boost::optional<ProgramResult> DecompileProgram(const ProgramCode& program_code, u32 main_offset, |