From e088a2f4144520dfade114a599968134b74885d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Mon, 2 Jul 2018 16:26:03 +0200 Subject: [PATCH] stratosphere: In-class initialize members Same thing, less code, less boilerplate. --- .../creport/source/creport_code_info.hpp | 6 ++--- .../creport/source/creport_crash_report.hpp | 21 ++++++++---------- .../creport/source/creport_thread_info.hpp | 22 ++++++++----------- .../fs_mitm/source/fsmitm_romfsbuild.hpp | 16 +++++++------- .../fs_mitm/source/fsmitm_service.hpp | 6 ++--- stratosphere/loader/source/ldr_map.hpp | 11 +++++----- stratosphere/loader/source/ldr_ro_service.hpp | 7 +++--- stratosphere/sm/source/sm_user_service.hpp | 7 +++--- 8 files changed, 42 insertions(+), 54 deletions(-) diff --git a/stratosphere/creport/source/creport_code_info.hpp b/stratosphere/creport/source/creport_code_info.hpp index 3f1527d2a..f10834f3d 100644 --- a/stratosphere/creport/source/creport_code_info.hpp +++ b/stratosphere/creport/source/creport_code_info.hpp @@ -14,11 +14,9 @@ struct CodeInfo { class CodeList { private: static const size_t max_code_count = 0x10; - u32 code_count; + u32 code_count = 0; CodeInfo code_infos[max_code_count]; - public: - CodeList() : code_count(0) { } - + public: void ReadCodeRegionsFromProcess(Handle debug_handle, u64 pc, u64 lr); void SaveToFile(FILE *f_report); private: diff --git a/stratosphere/creport/source/creport_crash_report.hpp b/stratosphere/creport/source/creport_crash_report.hpp index 3e59a88dd..d93ba0bcc 100644 --- a/stratosphere/creport/source/creport_crash_report.hpp +++ b/stratosphere/creport/source/creport_crash_report.hpp @@ -23,30 +23,27 @@ enum class CrashReportResult : Result { class CrashReport { private: - Handle debug_handle; + Handle debug_handle = INVALID_HANDLE; bool has_extra_info; - Result result; + Result result = static_cast(CrashReportResult::IncompleteReport); /* Attach Process Info. */ - AttachProcessInfo process_info; - u64 dying_message_address; - u64 dying_message_size; - u8 dying_message[0x1000]; + AttachProcessInfo process_info{}; + u64 dying_message_address = 0; + u64 dying_message_size = 0; + u8 dying_message[0x1000]{}; static_assert(sizeof(dying_message) == 0x1000, "Incorrect definition for dying message!"); /* Exception Info. */ - ExceptionInfo exception_info; + ExceptionInfo exception_info{}; ThreadInfo crashed_thread_info; /* Extra Info. */ CodeList code_list; ThreadList thread_list; - public: - CrashReport() : debug_handle(INVALID_HANDLE), result((Result)CrashReportResult::IncompleteReport), process_info{0}, dying_message_address(0), - dying_message_size(0), dying_message{0}, exception_info({}) { } - + public: void BuildReport(u64 pid, bool has_extra_info); void SaveReport(); @@ -98,4 +95,4 @@ class CrashReport { void EnsureReportDirectories(); bool GetCurrentTime(u64 *out); -}; \ No newline at end of file +}; diff --git a/stratosphere/creport/source/creport_thread_info.hpp b/stratosphere/creport/source/creport_thread_info.hpp index ad90250ec..6af698d4b 100644 --- a/stratosphere/creport/source/creport_thread_info.hpp +++ b/stratosphere/creport/source/creport_thread_info.hpp @@ -31,15 +31,13 @@ static_assert(sizeof(DebugThreadContext) == 0x320, "Incorrect DebugThreadContext class ThreadInfo { private: - DebugThreadContext context; - u64 thread_id; - u64 stack_top; - u64 stack_bottom; - u64 stack_trace[0x20]; - u32 stack_trace_size; - public: - ThreadInfo() : context{0}, thread_id(0), stack_top(0), stack_bottom(0), stack_trace{0}, stack_trace_size(0) { } - + DebugThreadContext context{}; + u64 thread_id = 0; + u64 stack_top = 0; + u64 stack_bottom = 0; + u64 stack_trace[0x20]{}; + u32 stack_trace_size = 0; + public: u64 GetPC() { return context.pc; } u64 GetLR() { return context.lr; } u64 GetId() { return thread_id; } @@ -54,11 +52,9 @@ class ThreadInfo { class ThreadList { private: static const size_t max_thread_count = 0x60; - u32 thread_count; + u32 thread_count = 0; ThreadInfo thread_infos[max_thread_count]; - public: - ThreadList() : thread_count(0) { } - + public: void SaveToFile(FILE *f_report); void DumpBinary(FILE *f_bin, u64 crashed_id); void ReadThreadsFromProcess(Handle debug_handle, bool is_64_bit); diff --git a/stratosphere/fs_mitm/source/fsmitm_romfsbuild.hpp b/stratosphere/fs_mitm/source/fsmitm_romfsbuild.hpp index 004bf5426..6cadf1b72 100644 --- a/stratosphere/fs_mitm/source/fsmitm_romfsbuild.hpp +++ b/stratosphere/fs_mitm/source/fsmitm_romfsbuild.hpp @@ -174,13 +174,13 @@ class RomFSBuildContext { RomFSBuildDirectoryContext *root; std::map directories; std::map files; - u64 num_dirs; - u64 num_files; - u64 dir_table_size; - u64 file_table_size; - u64 dir_hash_table_size; - u64 file_hash_table_size; - u64 file_partition_size; + u64 num_dirs = 0; + u64 num_files = 0; + u64 dir_table_size = 0; + u64 file_table_size = 0; + u64 dir_hash_table_size = 0; + u64 file_hash_table_size = 0; + u64 file_partition_size = 0; FsDirectoryEntry dir_entry; RomFSDataSource cur_source_type; @@ -191,7 +191,7 @@ class RomFSBuildContext { bool AddDirectory(RomFSBuildDirectoryContext *parent_dir_ctx, RomFSBuildDirectoryContext *dir_ctx, RomFSBuildDirectoryContext **out_dir_ctx); bool AddFile(RomFSBuildDirectoryContext *parent_dir_ctx, RomFSBuildFileContext *file_ctx); public: - RomFSBuildContext(u64 tid) : title_id(tid), num_dirs(0), num_files(0), dir_table_size(0), file_table_size(0), dir_hash_table_size(0), file_hash_table_size(0), file_partition_size(0) { + RomFSBuildContext(u64 tid) : title_id(tid) { this->root = new RomFSBuildDirectoryContext({0}); this->root->path = new char[1]; this->root->path[0] = '\x00'; diff --git a/stratosphere/fs_mitm/source/fsmitm_service.hpp b/stratosphere/fs_mitm/source/fsmitm_service.hpp index 6fcf5b6b3..6e565f69d 100644 --- a/stratosphere/fs_mitm/source/fsmitm_service.hpp +++ b/stratosphere/fs_mitm/source/fsmitm_service.hpp @@ -12,11 +12,11 @@ enum class FspSrvCmd { class FsMitMService : public IMitMServiceObject { private: - bool has_initialized; - u64 init_pid; + bool has_initialized = false; + u64 init_pid = 0; std::shared_ptr romfs_storage; public: - FsMitMService(Service *s) : IMitMServiceObject(s), has_initialized(false), init_pid(0) { + FsMitMService(Service *s) : IMitMServiceObject(s) { /* ... */ } diff --git a/stratosphere/loader/source/ldr_map.hpp b/stratosphere/loader/source/ldr_map.hpp index ba52e5dcb..1b8c0a986 100644 --- a/stratosphere/loader/source/ldr_map.hpp +++ b/stratosphere/loader/source/ldr_map.hpp @@ -27,12 +27,11 @@ class MapUtils { class AutoCloseMap { private: - void *mapped_address; - u64 base_address; - u64 size; - Handle process_handle; + void *mapped_address = nullptr; + u64 base_address = 0; + u64 size = 0; + Handle process_handle = 0; public: - AutoCloseMap() : mapped_address(0), base_address(0), size(0), process_handle(0) { }; ~AutoCloseMap() { Close(); } @@ -154,4 +153,4 @@ struct MappedCodeMemory { } *this = (const MappedCodeMemory){0}; } -}; \ No newline at end of file +}; diff --git a/stratosphere/loader/source/ldr_ro_service.hpp b/stratosphere/loader/source/ldr_ro_service.hpp index 1082c4a8c..aea97ba40 100644 --- a/stratosphere/loader/source/ldr_ro_service.hpp +++ b/stratosphere/loader/source/ldr_ro_service.hpp @@ -13,11 +13,10 @@ enum RoServiceCmd { }; class RelocatableObjectsService final : public IServiceObject { - Handle process_handle; - u64 process_id; - bool has_initialized; + Handle process_handle = 0; + u64 process_id = U64_MAX; + bool has_initialized = false; public: - RelocatableObjectsService() : process_handle(0), process_id(U64_MAX), has_initialized(false) { } ~RelocatableObjectsService() { Registration::CloseRoService(this, this->process_handle); if (this->has_initialized) { diff --git a/stratosphere/sm/source/sm_user_service.hpp b/stratosphere/sm/source/sm_user_service.hpp index 976ad464f..424fe9968 100644 --- a/stratosphere/sm/source/sm_user_service.hpp +++ b/stratosphere/sm/source/sm_user_service.hpp @@ -14,12 +14,11 @@ enum UserServiceCmd { }; class UserService final : public IServiceObject { - u64 pid; - bool has_initialized; - u64 deferred_service; + u64 pid = U64_MAX; + bool has_initialized = false; + u64 deferred_service = 0; public: - UserService() : pid(U64_MAX), has_initialized(false), deferred_service(0) { } Result dispatch(IpcParsedCommand &r, IpcCommand &out_c, u64 cmd_id, u8 *pointer_buffer, size_t pointer_buffer_size) override; Result handle_deferred() override;