Merge pull request #9386 from lioncash/init

kernel: Ensure relevant class members are always initialized on construction
This commit is contained in:
liamwhite 2022-12-06 11:26:38 -05:00 committed by GitHub
commit a86af1b776
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 25 additions and 27 deletions

View file

@ -280,18 +280,19 @@ struct KMemoryInfo {
class KMemoryBlock : public Common::IntrusiveRedBlackTreeBaseNode<KMemoryBlock> { class KMemoryBlock : public Common::IntrusiveRedBlackTreeBaseNode<KMemoryBlock> {
private: private:
u16 m_device_disable_merge_left_count; u16 m_device_disable_merge_left_count{};
u16 m_device_disable_merge_right_count; u16 m_device_disable_merge_right_count{};
VAddr m_address; VAddr m_address{};
size_t m_num_pages; size_t m_num_pages{};
KMemoryState m_memory_state; KMemoryState m_memory_state{KMemoryState::None};
u16 m_ipc_lock_count; u16 m_ipc_lock_count{};
u16 m_device_use_count; u16 m_device_use_count{};
u16 m_ipc_disable_merge_count; u16 m_ipc_disable_merge_count{};
KMemoryPermission m_permission; KMemoryPermission m_permission{KMemoryPermission::None};
KMemoryPermission m_original_permission; KMemoryPermission m_original_permission{KMemoryPermission::None};
KMemoryAttribute m_attribute; KMemoryAttribute m_attribute{KMemoryAttribute::None};
KMemoryBlockDisableMergeAttribute m_disable_merge_attribute; KMemoryBlockDisableMergeAttribute m_disable_merge_attribute{
KMemoryBlockDisableMergeAttribute::None};
public: public:
static constexpr int Compare(const KMemoryBlock& lhs, const KMemoryBlock& rhs) { static constexpr int Compare(const KMemoryBlock& lhs, const KMemoryBlock& rhs) {
@ -367,12 +368,8 @@ public:
constexpr KMemoryBlock(VAddr addr, size_t np, KMemoryState ms, KMemoryPermission p, constexpr KMemoryBlock(VAddr addr, size_t np, KMemoryState ms, KMemoryPermission p,
KMemoryAttribute attr) KMemoryAttribute attr)
: Common::IntrusiveRedBlackTreeBaseNode<KMemoryBlock>(), : Common::IntrusiveRedBlackTreeBaseNode<KMemoryBlock>(), m_address(addr), m_num_pages(np),
m_device_disable_merge_left_count(), m_device_disable_merge_right_count(), m_memory_state(ms), m_permission(p), m_attribute(attr) {}
m_address(addr), m_num_pages(np), m_memory_state(ms), m_ipc_lock_count(0),
m_device_use_count(0), m_ipc_disable_merge_count(), m_permission(p),
m_original_permission(KMemoryPermission::None), m_attribute(attr),
m_disable_merge_attribute() {}
constexpr void Initialize(VAddr addr, size_t np, KMemoryState ms, KMemoryPermission p, constexpr void Initialize(VAddr addr, size_t np, KMemoryState ms, KMemoryPermission p,
KMemoryAttribute attr) { KMemoryAttribute attr) {

View file

@ -3,6 +3,7 @@
#pragma once #pragma once
#include <array>
#include <functional> #include <functional>
#include "common/common_funcs.h" #include "common/common_funcs.h"
@ -17,9 +18,9 @@ public:
static constexpr size_t MaxBlocks = 2; static constexpr size_t MaxBlocks = 2;
private: private:
KMemoryBlock* m_blocks[MaxBlocks]; std::array<KMemoryBlock*, MaxBlocks> m_blocks{};
size_t m_index; size_t m_index{MaxBlocks};
KMemoryBlockSlabManager* m_slab_manager; KMemoryBlockSlabManager* m_slab_manager{};
private: private:
Result Initialize(size_t num_blocks) { Result Initialize(size_t num_blocks) {
@ -41,7 +42,7 @@ private:
public: public:
KMemoryBlockManagerUpdateAllocator(Result* out_result, KMemoryBlockSlabManager* sm, KMemoryBlockManagerUpdateAllocator(Result* out_result, KMemoryBlockSlabManager* sm,
size_t num_blocks = MaxBlocks) size_t num_blocks = MaxBlocks)
: m_blocks(), m_index(MaxBlocks), m_slab_manager(sm) { : m_slab_manager(sm) {
*out_result = this->Initialize(num_blocks); *out_result = this->Initialize(num_blocks);
} }

View file

@ -74,7 +74,7 @@ public:
static void PostDestroy([[maybe_unused]] uintptr_t arg) {} static void PostDestroy([[maybe_unused]] uintptr_t arg) {}
private: private:
Core::DeviceMemory* device_memory; Core::DeviceMemory* device_memory{};
KProcess* owner_process{}; KProcess* owner_process{};
KPageGroup page_list; KPageGroup page_list;
Svc::MemoryPermission owner_permission{}; Svc::MemoryPermission owner_permission{};

View file

@ -784,8 +784,8 @@ private:
std::vector<KSynchronizationObject*> wait_objects_for_debugging; std::vector<KSynchronizationObject*> wait_objects_for_debugging;
VAddr mutex_wait_address_for_debugging{}; VAddr mutex_wait_address_for_debugging{};
ThreadWaitReasonForDebugging wait_reason_for_debugging{}; ThreadWaitReasonForDebugging wait_reason_for_debugging{};
uintptr_t argument; uintptr_t argument{};
VAddr stack_top; VAddr stack_top{};
public: public:
using ConditionVariableThreadTreeType = ConditionVariableThreadTree; using ConditionVariableThreadTreeType = ConditionVariableThreadTree;

View file

@ -891,7 +891,7 @@ struct KernelCore::Impl {
Common::ThreadWorker service_threads_manager; Common::ThreadWorker service_threads_manager;
Common::Barrier service_thread_barrier; Common::Barrier service_thread_barrier;
std::array<KThread*, Core::Hardware::NUM_CPU_CORES> shutdown_threads; std::array<KThread*, Core::Hardware::NUM_CPU_CORES> shutdown_threads{};
std::array<std::unique_ptr<Kernel::KScheduler>, Core::Hardware::NUM_CPU_CORES> schedulers{}; std::array<std::unique_ptr<Kernel::KScheduler>, Core::Hardware::NUM_CPU_CORES> schedulers{};
bool is_multicore{}; bool is_multicore{};

View file

@ -85,7 +85,7 @@ private:
std::mutex guard; std::mutex guard;
std::condition_variable on_interrupt; std::condition_variable on_interrupt;
std::unique_ptr<Core::ARM_Interface> arm_interface; std::unique_ptr<Core::ARM_Interface> arm_interface;
bool is_interrupted; bool is_interrupted{};
}; };
} // namespace Kernel } // namespace Kernel