From 0aca202ae936d3fccbab34f36d9246e0598849a5 Mon Sep 17 00:00:00 2001 From: bunnei Date: Mon, 16 Jun 2014 18:03:13 -0400 Subject: Loader: Moved elf and loader modules to a "loader" subdirectory. --- src/core/loader/loader.h | 54 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/core/loader/loader.h (limited to 'src/core/loader/loader.h') diff --git a/src/core/loader/loader.h b/src/core/loader/loader.h new file mode 100644 index 000000000..9d4aaa874 --- /dev/null +++ b/src/core/loader/loader.h @@ -0,0 +1,54 @@ +// Copyright 2014 Citra Emulator Project +// Licensed under GPLv2 +// Refer to the license.txt file included. + +#pragma once + +#include "common/common.h" + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +namespace Loader { + +enum FileType { + FILETYPE_ERROR, + + FILETYPE_CTR_CCI, + FILETYPE_CTR_CIA, + FILETYPE_CTR_CXI, + FILETYPE_CTR_ELF, + FILETYPE_CTR_BIN, + + FILETYPE_LAUNCHER_DAT, + + FILETYPE_DIRECTORY_CXI, + + FILETYPE_UNKNOWN_BIN, + FILETYPE_UNKNOWN_ELF, + + FILETYPE_ARCHIVE_RAR, + FILETYPE_ARCHIVE_ZIP, + + FILETYPE_NORMAL_DIRECTORY, + + FILETYPE_UNKNOWN +}; + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/** + * Identifies the type of a bootable file + * @param filename String filename of bootable file + * @return FileType of file + */ +FileType IdentifyFile(std::string &filename); + +/** + * Identifies and loads a bootable file + * @param filename String filename of bootable file + * @param error_string Point to string to put error message if an error has occurred + * @return True on success, otherwise false + */ +bool LoadFile(std::string &filename, std::string *error_string); + +} // namespace -- cgit v1.2.3 From 13bdaa6c609a8718d4ce6ca3ce5f1e16f4d7c600 Mon Sep 17 00:00:00 2001 From: bunnei Date: Mon, 16 Jun 2014 23:18:10 -0400 Subject: Loader: Cleaned up and removed unused code, refactored ELF namespace. --- src/core/loader/loader.h | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) (limited to 'src/core/loader/loader.h') diff --git a/src/core/loader/loader.h b/src/core/loader/loader.h index 9d4aaa874..979003553 100644 --- a/src/core/loader/loader.h +++ b/src/core/loader/loader.h @@ -7,6 +7,7 @@ #include "common/common.h" //////////////////////////////////////////////////////////////////////////////////////////////////// +// Loader namespace namespace Loader { @@ -19,23 +20,9 @@ enum FileType { FILETYPE_CTR_ELF, FILETYPE_CTR_BIN, - FILETYPE_LAUNCHER_DAT, - - FILETYPE_DIRECTORY_CXI, - - FILETYPE_UNKNOWN_BIN, - FILETYPE_UNKNOWN_ELF, - - FILETYPE_ARCHIVE_RAR, - FILETYPE_ARCHIVE_ZIP, - - FILETYPE_NORMAL_DIRECTORY, - FILETYPE_UNKNOWN }; -//////////////////////////////////////////////////////////////////////////////////////////////////// - /** * Identifies the type of a bootable file * @param filename String filename of bootable file -- cgit v1.2.3 From 7889cafc76ac99b8509fa3cd1558a09f8a7e5f91 Mon Sep 17 00:00:00 2001 From: bunnei Date: Wed, 18 Jun 2014 18:58:09 -0400 Subject: Loader: Implemented AppLoader interface for abstracting application loading. - Various cleanups/refactorings to Loader, ELF, and NCCH modules. - Added AppLoader interface to ELF and NCCH. - Updated Qt/GLFW frontends to check AppLoader ResultStatus. NCCH: Removed extra qualification typos. Loader: Removed unnecessary #include's. NCCH: Improved readability of memcmp statements. NCCH: Added missing space. Elf: Removed unnecessary usage of unique_ptr. Loader: Removed unnecessary usage of unique_ptr. --- src/core/loader/loader.h | 103 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 91 insertions(+), 12 deletions(-) (limited to 'src/core/loader/loader.h') diff --git a/src/core/loader/loader.h b/src/core/loader/loader.h index 979003553..42caa29e6 100644 --- a/src/core/loader/loader.h +++ b/src/core/loader/loader.h @@ -4,6 +4,8 @@ #pragma once +#include + #include "common/common.h" //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -11,16 +13,94 @@ namespace Loader { -enum FileType { - FILETYPE_ERROR, +/// File types supported by CTR +enum class FileType { + Error, + Unknown, + CCI, + CXI, + CIA, + ELF, +}; + +/// Return type for functions in Loader namespace +enum class ResultStatus { + Success, + Error, + ErrorInvalidFormat, + ErrorNotImplemented, + ErrorNotLoaded, + ErrorAlreadyLoaded, +}; + +/// Interface for loading an application +class AppLoader : NonCopyable { +public: + AppLoader() { } + virtual ~AppLoader() { } + + /** + * Load the application + * @return ResultStatus result of function + */ + virtual const ResultStatus Load() = 0; + + /** + * Get the code (typically .code section) of the application + * @param error ResultStatus result of function + * @return Reference to code buffer + */ + virtual const std::vector& GetCode(ResultStatus& error) const { + error = ResultStatus::ErrorNotImplemented; + return code; + } + + /** + * Get the icon (typically .icon section) of the application + * @param error ResultStatus result of function + * @return Reference to icon buffer + */ + virtual const std::vector& GetIcon(ResultStatus& error) const { + error = ResultStatus::ErrorNotImplemented; + return icon; + } + + /** + * Get the banner (typically .banner section) of the application + * @param error ResultStatus result of function + * @return Reference to banner buffer + */ + virtual const std::vector& GetBanner(ResultStatus& error) const { + error = ResultStatus::ErrorNotImplemented; + return banner; + } + + /** + * Get the logo (typically .logo section) of the application + * @param error ResultStatus result of function + * @return Reference to logo buffer + */ + virtual const std::vector& GetLogo(ResultStatus& error) const { + error = ResultStatus::ErrorNotImplemented; + return logo; + } - FILETYPE_CTR_CCI, - FILETYPE_CTR_CIA, - FILETYPE_CTR_CXI, - FILETYPE_CTR_ELF, - FILETYPE_CTR_BIN, + /** + * Get the RomFs archive of the application + * @param error ResultStatus result of function + * @return Reference to RomFs archive buffer + */ + virtual const std::vector& GetRomFs(ResultStatus error) const { + error = ResultStatus::ErrorNotImplemented; + return romfs; + } - FILETYPE_UNKNOWN +protected: + std::vector code; ///< ExeFS .code section + std::vector icon; ///< ExeFS .icon section + std::vector banner; ///< ExeFS .banner section + std::vector logo; ///< ExeFS .logo section + std::vector romfs; ///< RomFs archive }; /** @@ -28,14 +108,13 @@ enum FileType { * @param filename String filename of bootable file * @return FileType of file */ -FileType IdentifyFile(std::string &filename); +const FileType IdentifyFile(const std::string &filename); /** * Identifies and loads a bootable file * @param filename String filename of bootable file - * @param error_string Point to string to put error message if an error has occurred - * @return True on success, otherwise false + * @return ResultStatus result of function */ -bool LoadFile(std::string &filename, std::string *error_string); +const ResultStatus LoadFile(std::string& filename); } // namespace -- cgit v1.2.3 From 3da2bc6830e05d943c4d131a3167c2df25bff344 Mon Sep 17 00:00:00 2001 From: bunnei Date: Wed, 18 Jun 2014 23:53:22 -0400 Subject: NCCH: Fixes reduce unnecessary logging and load logo/banner/etc. sections correctly. Loader: Added ErrorNotUsed ReturnStatus type to specify when something is not used. --- src/core/loader/loader.h | 1 + 1 file changed, 1 insertion(+) (limited to 'src/core/loader/loader.h') diff --git a/src/core/loader/loader.h b/src/core/loader/loader.h index 42caa29e6..38b3d4c99 100644 --- a/src/core/loader/loader.h +++ b/src/core/loader/loader.h @@ -30,6 +30,7 @@ enum class ResultStatus { ErrorInvalidFormat, ErrorNotImplemented, ErrorNotLoaded, + ErrorNotUsed, ErrorAlreadyLoaded, }; -- cgit v1.2.3 From 62b444cd17c17e6f8009d87609b620bcb51b43bd Mon Sep 17 00:00:00 2001 From: bunnei Date: Thu, 19 Jun 2014 17:46:05 -0400 Subject: Loader: Refactored use of const. --- src/core/loader/loader.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/core/loader/loader.h') diff --git a/src/core/loader/loader.h b/src/core/loader/loader.h index 38b3d4c99..002af1f60 100644 --- a/src/core/loader/loader.h +++ b/src/core/loader/loader.h @@ -44,7 +44,7 @@ public: * Load the application * @return ResultStatus result of function */ - virtual const ResultStatus Load() = 0; + virtual ResultStatus Load() = 0; /** * Get the code (typically .code section) of the application @@ -109,13 +109,13 @@ protected: * @param filename String filename of bootable file * @return FileType of file */ -const FileType IdentifyFile(const std::string &filename); +FileType IdentifyFile(const std::string &filename); /** * Identifies and loads a bootable file * @param filename String filename of bootable file * @return ResultStatus result of function */ -const ResultStatus LoadFile(std::string& filename); +ResultStatus LoadFile(const std::string& filename); } // namespace -- cgit v1.2.3 From a7f1c544909ee1034356666e04bea3a4b4609a95 Mon Sep 17 00:00:00 2001 From: bunnei Date: Sun, 22 Jun 2014 15:40:21 -0400 Subject: Loader: Refactored loading functions to only read data from binary if called. NCCH: Updated LoadExec to use Memory::WriteBlock function to load binary code. --- src/core/loader/loader.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/core/loader/loader.h') diff --git a/src/core/loader/loader.h b/src/core/loader/loader.h index 002af1f60..95f16fcb1 100644 --- a/src/core/loader/loader.h +++ b/src/core/loader/loader.h @@ -51,37 +51,37 @@ public: * @param error ResultStatus result of function * @return Reference to code buffer */ - virtual const std::vector& GetCode(ResultStatus& error) const { + virtual const std::vector& ReadCode(ResultStatus& error) const { error = ResultStatus::ErrorNotImplemented; return code; } /** - * Get the icon (typically .icon section) of the application + * Get the icon (typically icon section) of the application * @param error ResultStatus result of function * @return Reference to icon buffer */ - virtual const std::vector& GetIcon(ResultStatus& error) const { + virtual const std::vector& ReadIcon(ResultStatus& error) const { error = ResultStatus::ErrorNotImplemented; return icon; } /** - * Get the banner (typically .banner section) of the application + * Get the banner (typically banner section) of the application * @param error ResultStatus result of function * @return Reference to banner buffer */ - virtual const std::vector& GetBanner(ResultStatus& error) const { + virtual const std::vector& ReadBanner(ResultStatus& error) const { error = ResultStatus::ErrorNotImplemented; return banner; } /** - * Get the logo (typically .logo section) of the application + * Get the logo (typically logo section) of the application * @param error ResultStatus result of function * @return Reference to logo buffer */ - virtual const std::vector& GetLogo(ResultStatus& error) const { + virtual const std::vector& ReadLogo(ResultStatus& error) const { error = ResultStatus::ErrorNotImplemented; return logo; } @@ -91,7 +91,7 @@ public: * @param error ResultStatus result of function * @return Reference to RomFs archive buffer */ - virtual const std::vector& GetRomFs(ResultStatus error) const { + virtual const std::vector& ReadRomFS(ResultStatus& error) const { error = ResultStatus::ErrorNotImplemented; return romfs; } -- cgit v1.2.3