diff options
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/common_funcs.h | 4 | ||||
-rw-r--r-- | src/common/common_paths.h | 1 | ||||
-rw-r--r-- | src/common/file_util.cpp | 14 | ||||
-rw-r--r-- | src/common/file_util.h | 3 | ||||
-rw-r--r-- | src/common/logging/backend.cpp | 16 | ||||
-rw-r--r-- | src/common/logging/log.h | 16 | ||||
-rw-r--r-- | src/common/logging/text_formatter.h | 1 | ||||
-rw-r--r-- | src/common/math_util.h | 10 | ||||
-rw-r--r-- | src/common/string_util.cpp | 8 | ||||
-rw-r--r-- | src/common/swap.h | 2 | ||||
-rw-r--r-- | src/common/threadsafe_queue.h | 32 | ||||
-rw-r--r-- | src/common/timer.cpp | 95 | ||||
-rw-r--r-- | src/common/timer.h | 17 |
13 files changed, 124 insertions, 95 deletions
diff --git a/src/common/common_funcs.h b/src/common/common_funcs.h index 93f1c0044..8b0d34da6 100644 --- a/src/common/common_funcs.h +++ b/src/common/common_funcs.h @@ -6,7 +6,7 @@ #include <string> -#if !defined(ARCHITECTURE_x86_64) && !defined(ARCHITECTURE_ARM) +#if !defined(ARCHITECTURE_x86_64) #include <cstdlib> // for exit #endif #include "common/common_types.h" @@ -32,8 +32,6 @@ #ifdef ARCHITECTURE_x86_64 #define Crash() __asm__ __volatile__("int $3") -#elif defined(ARCHITECTURE_ARM) -#define Crash() __asm__ __volatile__("trap") #else #define Crash() exit(1) #endif diff --git a/src/common/common_paths.h b/src/common/common_paths.h index 6799a357a..df2ce80b1 100644 --- a/src/common/common_paths.h +++ b/src/common/common_paths.h @@ -32,6 +32,7 @@ #define SDMC_DIR "sdmc" #define NAND_DIR "nand" #define SYSDATA_DIR "sysdata" +#define KEYS_DIR "keys" #define LOG_DIR "log" // Filenames diff --git a/src/common/file_util.cpp b/src/common/file_util.cpp index b8dd92b65..7aeda737f 100644 --- a/src/common/file_util.cpp +++ b/src/common/file_util.cpp @@ -706,6 +706,7 @@ const std::string& GetUserPath(UserPath path, const std::string& new_path) { paths.emplace(UserPath::SDMCDir, user_path + SDMC_DIR DIR_SEP); paths.emplace(UserPath::NANDDir, user_path + NAND_DIR DIR_SEP); paths.emplace(UserPath::SysDataDir, user_path + SYSDATA_DIR DIR_SEP); + paths.emplace(UserPath::KeysDir, user_path + KEYS_DIR DIR_SEP); // TODO: Put the logs in a better location for each OS paths.emplace(UserPath::LogDir, user_path + LOG_DIR DIR_SEP); } @@ -736,6 +737,19 @@ const std::string& GetUserPath(UserPath path, const std::string& new_path) { return paths[path]; } +std::string GetHactoolConfigurationPath() { +#ifdef _WIN32 + PWSTR pw_local_path = nullptr; + if (SHGetKnownFolderPath(FOLDERID_Profile, 0, nullptr, &pw_local_path) != S_OK) + return ""; + std::string local_path = Common::UTF16ToUTF8(pw_local_path); + CoTaskMemFree(pw_local_path); + return local_path + "\\.switch"; +#else + return GetHomeDirectory() + "/.switch"; +#endif +} + size_t WriteStringToFile(bool text_file, const std::string& str, const char* filename) { return FileUtil::IOFile(filename, text_file ? "w" : "wb").WriteBytes(str.data(), str.size()); } diff --git a/src/common/file_util.h b/src/common/file_util.h index bc9272d89..28697d527 100644 --- a/src/common/file_util.h +++ b/src/common/file_util.h @@ -23,6 +23,7 @@ namespace FileUtil { enum class UserPath { CacheDir, ConfigDir, + KeysDir, LogDir, NANDDir, RootDir, @@ -125,6 +126,8 @@ bool SetCurrentDir(const std::string& directory); // directory. To be used in "multi-user" mode (that is, installed). const std::string& GetUserPath(UserPath path, const std::string& new_path = ""); +std::string GetHactoolConfigurationPath(); + // Returns the path to where the sys file are std::string GetSysDirectory(); diff --git a/src/common/logging/backend.cpp b/src/common/logging/backend.cpp index ad9edbcdf..355abd682 100644 --- a/src/common/logging/backend.cpp +++ b/src/common/logging/backend.cpp @@ -168,26 +168,41 @@ void FileBackend::Write(const Entry& entry) { SUB(Service, AM) \ SUB(Service, AOC) \ SUB(Service, APM) \ + SUB(Service, ARP) \ SUB(Service, BCAT) \ + SUB(Service, BPC) \ + SUB(Service, BTM) \ + SUB(Service, Capture) \ SUB(Service, Fatal) \ + SUB(Service, FGM) \ SUB(Service, Friend) \ SUB(Service, FS) \ SUB(Service, HID) \ + SUB(Service, LBL) \ SUB(Service, LDN) \ SUB(Service, LM) \ + SUB(Service, Migration) \ + SUB(Service, Mii) \ SUB(Service, MM) \ + SUB(Service, NCM) \ + SUB(Service, NFC) \ SUB(Service, NFP) \ SUB(Service, NIFM) \ SUB(Service, NS) \ SUB(Service, NVDRV) \ + SUB(Service, PCIE) \ SUB(Service, PCTL) \ + SUB(Service, PCV) \ SUB(Service, PREPO) \ + SUB(Service, PSC) \ SUB(Service, SET) \ SUB(Service, SM) \ SUB(Service, SPL) \ SUB(Service, SSL) \ SUB(Service, Time) \ + SUB(Service, USB) \ SUB(Service, VI) \ + SUB(Service, WLAN) \ CLS(HW) \ SUB(HW, Memory) \ SUB(HW, LCD) \ @@ -204,6 +219,7 @@ void FileBackend::Write(const Entry& entry) { CLS(Input) \ CLS(Network) \ CLS(Loader) \ + CLS(Crypto) \ CLS(WebService) // GetClassName is a macro defined by Windows.h, grrr... diff --git a/src/common/logging/log.h b/src/common/logging/log.h index ad3cbf5d1..a889ebefa 100644 --- a/src/common/logging/log.h +++ b/src/common/logging/log.h @@ -54,27 +54,42 @@ enum class Class : ClassType { Service_AM, ///< The AM (Applet manager) service Service_AOC, ///< The AOC (AddOn Content) service Service_APM, ///< The APM (Performance) service + Service_ARP, ///< The ARP service Service_Audio, ///< The Audio (Audio control) service Service_BCAT, ///< The BCAT service + Service_BPC, ///< The BPC service + Service_BTM, ///< The BTM service + Service_Capture, ///< The capture service Service_Fatal, ///< The Fatal service + Service_FGM, ///< The FGM service Service_Friend, ///< The friend service Service_FS, ///< The FS (Filesystem) service Service_HID, ///< The HID (Human interface device) service + Service_LBL, ///< The LBL (LCD backlight) service Service_LDN, ///< The LDN (Local domain network) service Service_LM, ///< The LM (Logger) service + Service_Migration, ///< The migration service + Service_Mii, ///< The Mii service Service_MM, ///< The MM (Multimedia) service + Service_NCM, ///< The NCM service + Service_NFC, ///< The NFC (Near-field communication) service Service_NFP, ///< The NFP service Service_NIFM, ///< The NIFM (Network interface) service Service_NS, ///< The NS services Service_NVDRV, ///< The NVDRV (Nvidia driver) service + Service_PCIE, ///< The PCIe service Service_PCTL, ///< The PCTL (Parental control) service + Service_PCV, ///< The PCV service Service_PREPO, ///< The PREPO (Play report) service + Service_PSC, ///< The PSC service Service_SET, ///< The SET (Settings) service Service_SM, ///< The SM (Service manager) service Service_SPL, ///< The SPL service Service_SSL, ///< The SSL service Service_Time, ///< The time service + Service_USB, ///< The USB (Universal Serial Bus) service Service_VI, ///< The VI (Video interface) service + Service_WLAN, ///< The WLAN (Wireless local area network) service HW, ///< Low-level hardware emulation HW_Memory, ///< Memory-map and address translation HW_LCD, ///< LCD register emulation @@ -89,6 +104,7 @@ enum class Class : ClassType { Audio_DSP, ///< The HLE implementation of the DSP Audio_Sink, ///< Emulator audio output backend Loader, ///< ROM loader + Crypto, ///< Cryptographic engine/functions Input, ///< Input emulation Network, ///< Network emulation WebService, ///< Interface to yuzu Web Services diff --git a/src/common/logging/text_formatter.h b/src/common/logging/text_formatter.h index c587faefb..9609cec7c 100644 --- a/src/common/logging/text_formatter.h +++ b/src/common/logging/text_formatter.h @@ -5,6 +5,7 @@ #pragma once #include <cstddef> +#include <string> namespace Log { diff --git a/src/common/math_util.h b/src/common/math_util.h index c6a83c953..343cdd902 100644 --- a/src/common/math_util.h +++ b/src/common/math_util.h @@ -19,12 +19,12 @@ inline bool IntervalsIntersect(unsigned start0, unsigned length0, unsigned start template <class T> struct Rectangle { - T left; - T top; - T right; - T bottom; + T left{}; + T top{}; + T right{}; + T bottom{}; - Rectangle() {} + Rectangle() = default; Rectangle(T left, T top, T right, T bottom) : left(left), top(top), right(right), bottom(bottom) {} diff --git a/src/common/string_util.cpp b/src/common/string_util.cpp index 1f0456aee..0ca663032 100644 --- a/src/common/string_util.cpp +++ b/src/common/string_util.cpp @@ -2,12 +2,12 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. +#include <algorithm> #include <cctype> #include <cerrno> #include <cstdio> #include <cstdlib> #include <cstring> -#include <boost/range/algorithm/transform.hpp> #include "common/common_paths.h" #include "common/logging/log.h" #include "common/string_util.h" @@ -24,13 +24,15 @@ namespace Common { /// Make a string lowercase std::string ToLower(std::string str) { - boost::transform(str, str.begin(), ::tolower); + std::transform(str.begin(), str.end(), str.begin(), + [](unsigned char c) { return std::tolower(c); }); return str; } /// Make a string uppercase std::string ToUpper(std::string str) { - boost::transform(str, str.begin(), ::toupper); + std::transform(str.begin(), str.end(), str.begin(), + [](unsigned char c) { return std::toupper(c); }); return str; } diff --git a/src/common/swap.h b/src/common/swap.h index fc7af4280..32af0b6ac 100644 --- a/src/common/swap.h +++ b/src/common/swap.h @@ -69,7 +69,7 @@ inline u32 swap32(u32 _data) { inline u64 swap64(u64 _data) { return _byteswap_uint64(_data); } -#elif ARCHITECTURE_ARM +#elif defined(ARCHITECTURE_ARM) && (__ARM_ARCH >= 6) inline u16 swap16(u16 _data) { u32 data = _data; __asm__("rev16 %0, %1\n" : "=l"(data) : "l"(data)); diff --git a/src/common/threadsafe_queue.h b/src/common/threadsafe_queue.h index a0c731e8c..edf13bc49 100644 --- a/src/common/threadsafe_queue.h +++ b/src/common/threadsafe_queue.h @@ -33,9 +33,11 @@ public: bool Empty() const { return !read_ptr->next.load(); } + T& Front() const { return read_ptr->current; } + template <typename Arg> void Push(Arg&& t) { // create the element, add it to the queue @@ -108,15 +110,41 @@ private: // single reader, multiple writer queue template <typename T, bool NeedSize = true> -class MPSCQueue : public SPSCQueue<T, NeedSize> { +class MPSCQueue { public: + u32 Size() const { + return spsc_queue.Size(); + } + + bool Empty() const { + return spsc_queue.Empty(); + } + + T& Front() const { + return spsc_queue.Front(); + } + template <typename Arg> void Push(Arg&& t) { std::lock_guard<std::mutex> lock(write_lock); - SPSCQueue<T, NeedSize>::Push(t); + spsc_queue.Push(t); + } + + void Pop() { + return spsc_queue.Pop(); + } + + bool Pop(T& t) { + return spsc_queue.Pop(t); + } + + // not thread-safe + void Clear() { + spsc_queue.Clear(); } private: + SPSCQueue<T, NeedSize> spsc_queue; std::mutex write_lock; }; } // namespace Common diff --git a/src/common/timer.cpp b/src/common/timer.cpp index f0c5b1a43..2dc15e434 100644 --- a/src/common/timer.cpp +++ b/src/common/timer.cpp @@ -3,31 +3,16 @@ // Refer to the license.txt file included. #include <ctime> - #include <fmt/format.h> - -#ifdef _WIN32 -#include <windows.h> -// windows.h needs to be included before other windows headers -#include <mmsystem.h> -#include <sys/timeb.h> -#else -#include <sys/time.h> -#endif #include "common/common_types.h" #include "common/string_util.h" #include "common/timer.h" namespace Common { -u32 Timer::GetTimeMs() { -#ifdef _WIN32 - return timeGetTime(); -#else - struct timeval t; - (void)gettimeofday(&t, nullptr); - return ((u32)(t.tv_sec * 1000 + t.tv_usec / 1000)); -#endif +std::chrono::milliseconds Timer::GetTimeMs() { + return std::chrono::duration_cast<std::chrono::milliseconds>( + std::chrono::system_clock::now().time_since_epoch()); } // -------------------------------------------- @@ -63,7 +48,7 @@ void Timer::Update() { // ------------------------------------- // Get the number of milliseconds since the last Update() -u64 Timer::GetTimeDifference() { +std::chrono::milliseconds Timer::GetTimeDifference() { return GetTimeMs() - m_LastTime; } @@ -74,11 +59,11 @@ void Timer::AddTimeDifference() { } // Get the time elapsed since the Start() -u64 Timer::GetTimeElapsed() { +std::chrono::milliseconds Timer::GetTimeElapsed() { // If we have not started yet, return 1 (because then I don't // have to change the FPS calculation in CoreRerecording.cpp . - if (m_StartTime == 0) - return 1; + if (m_StartTime.count() == 0) + return std::chrono::milliseconds(1); // Return the final timer time if the timer is stopped if (!m_Running) @@ -90,49 +75,34 @@ u64 Timer::GetTimeElapsed() { // Get the formatted time elapsed since the Start() std::string Timer::GetTimeElapsedFormatted() const { // If we have not started yet, return zero - if (m_StartTime == 0) + if (m_StartTime.count() == 0) return "00:00:00:000"; // The number of milliseconds since the start. // Use a different value if the timer is stopped. - u64 Milliseconds; + std::chrono::milliseconds Milliseconds; if (m_Running) Milliseconds = GetTimeMs() - m_StartTime; else Milliseconds = m_LastTime - m_StartTime; // Seconds - u32 Seconds = (u32)(Milliseconds / 1000); + std::chrono::seconds Seconds = std::chrono::duration_cast<std::chrono::seconds>(Milliseconds); // Minutes - u32 Minutes = Seconds / 60; + std::chrono::minutes Minutes = std::chrono::duration_cast<std::chrono::minutes>(Milliseconds); // Hours - u32 Hours = Minutes / 60; + std::chrono::hours Hours = std::chrono::duration_cast<std::chrono::hours>(Milliseconds); - std::string TmpStr = fmt::format("{:02}:{:02}:{:02}:{:03}", Hours, Minutes % 60, Seconds % 60, - Milliseconds % 1000); + std::string TmpStr = fmt::format("{:02}:{:02}:{:02}:{:03}", Hours.count(), Minutes.count() % 60, + Seconds.count() % 60, Milliseconds.count() % 1000); return TmpStr; } -// Get current time -void Timer::IncreaseResolution() { -#ifdef _WIN32 - timeBeginPeriod(1); -#endif -} - -void Timer::RestoreResolution() { -#ifdef _WIN32 - timeEndPeriod(1); -#endif -} - // Get the number of seconds since January 1 1970 -u64 Timer::GetTimeSinceJan1970() { - time_t ltime; - time(<ime); - return ((u64)ltime); +std::chrono::seconds Timer::GetTimeSinceJan1970() { + return std::chrono::duration_cast<std::chrono::seconds>(GetTimeMs()); } -u64 Timer::GetLocalTimeSinceJan1970() { +std::chrono::seconds Timer::GetLocalTimeSinceJan1970() { time_t sysTime, tzDiff, tzDST; struct tm* gmTime; @@ -149,7 +119,7 @@ u64 Timer::GetLocalTimeSinceJan1970() { gmTime = gmtime(&sysTime); tzDiff = sysTime - mktime(gmTime); - return (u64)(sysTime + tzDiff + tzDST); + return std::chrono::seconds(sysTime + tzDiff + tzDST); } // Return the current time formatted as Minutes:Seconds:Milliseconds @@ -164,30 +134,16 @@ std::string Timer::GetTimeFormatted() { strftime(tmp, 6, "%M:%S", gmTime); -// Now tack on the milliseconds -#ifdef _WIN32 - struct timeb tp; - (void)::ftime(&tp); - return fmt::format("{}:{:03}", tmp, tp.millitm); -#else - struct timeval t; - (void)gettimeofday(&t, nullptr); - return fmt::format("{}:{:03}", tmp, static_cast<int>(t.tv_usec / 1000)); -#endif + u64 milliseconds = static_cast<u64>(GetTimeMs().count()) % 1000; + return fmt::format("{}:{:03}", tmp, milliseconds); } // Returns a timestamp with decimals for precise time comparisons // ---------------- double Timer::GetDoubleTime() { -#ifdef _WIN32 - struct timeb tp; - (void)::ftime(&tp); -#else - struct timeval t; - (void)gettimeofday(&t, nullptr); -#endif // Get continuous timestamp - u64 TmpSeconds = Common::Timer::GetTimeSinceJan1970(); + u64 TmpSeconds = static_cast<u64>(Common::Timer::GetTimeSinceJan1970().count()); + double ms = static_cast<u64>(GetTimeMs().count()) % 1000; // Remove a few years. We only really want enough seconds to make // sure that we are detecting actual actions, perhaps 60 seconds is @@ -196,12 +152,7 @@ double Timer::GetDoubleTime() { TmpSeconds = TmpSeconds - (38 * 365 * 24 * 60 * 60); // Make a smaller integer that fits in the double - u32 Seconds = (u32)TmpSeconds; -#ifdef _WIN32 - double ms = tp.millitm / 1000.0 / 1000.0; -#else - double ms = t.tv_usec / 1000000.0; -#endif + u32 Seconds = static_cast<u32>(TmpSeconds); double TmpTime = Seconds + ms; return TmpTime; diff --git a/src/common/timer.h b/src/common/timer.h index 78d37426b..27b521baa 100644 --- a/src/common/timer.h +++ b/src/common/timer.h @@ -4,6 +4,7 @@ #pragma once +#include <chrono> #include <string> #include "common/common_types.h" @@ -18,24 +19,22 @@ public: // The time difference is always returned in milliseconds, regardless of alternative internal // representation - u64 GetTimeDifference(); + std::chrono::milliseconds GetTimeDifference(); void AddTimeDifference(); - static void IncreaseResolution(); - static void RestoreResolution(); - static u64 GetTimeSinceJan1970(); - static u64 GetLocalTimeSinceJan1970(); + static std::chrono::seconds GetTimeSinceJan1970(); + static std::chrono::seconds GetLocalTimeSinceJan1970(); static double GetDoubleTime(); static std::string GetTimeFormatted(); std::string GetTimeElapsedFormatted() const; - u64 GetTimeElapsed(); + std::chrono::milliseconds GetTimeElapsed(); - static u32 GetTimeMs(); + static std::chrono::milliseconds GetTimeMs(); private: - u64 m_LastTime; - u64 m_StartTime; + std::chrono::milliseconds m_LastTime; + std::chrono::milliseconds m_StartTime; bool m_Running; }; |