From e0cb85691a99fb06dbce5e802ae756a944b1a66c Mon Sep 17 00:00:00 2001 From: bunnei Date: Mon, 27 Apr 2015 22:01:48 -0400 Subject: [PATCH] Services: Initialize all state variables at bootup. --- src/core/hle/service/apt/apt.cpp | 17 +++++++++++------ src/core/hle/service/cfg/cfg.cpp | 2 +- src/core/hle/service/dsp_dsp.cpp | 2 +- src/core/hle/service/hid/hid.cpp | 22 ++++++++++++++-------- src/core/hle/service/ir/ir.cpp | 6 ++++-- src/core/hle/service/nwm_uds.cpp | 2 +- src/core/hle/service/ptm/ptm.cpp | 7 +++++-- src/core/hle/service/y2r_u.cpp | 2 +- 8 files changed, 38 insertions(+), 22 deletions(-) diff --git a/src/core/hle/service/apt/apt.cpp b/src/core/hle/service/apt/apt.cpp index 190c5df7a9..98ae80b3a8 100644 --- a/src/core/hle/service/apt/apt.cpp +++ b/src/core/hle/service/apt/apt.cpp @@ -28,15 +28,15 @@ namespace APT { static const VAddr SHARED_FONT_VADDR = 0x18000000; /// Handle to shared memory region designated to for shared system font -static Kernel::SharedPtr shared_font_mem = nullptr; +static Kernel::SharedPtr shared_font_mem; -static Kernel::SharedPtr lock = nullptr; -static Kernel::SharedPtr notification_event = nullptr; ///< APT notification event -static Kernel::SharedPtr start_event = nullptr; ///< APT start event +static Kernel::SharedPtr lock; +static Kernel::SharedPtr notification_event; ///< APT notification event +static Kernel::SharedPtr start_event; ///< APT start event static std::vector shared_font; -static u32 cpu_percent = 0; ///< CPU time available to the running application +static u32 cpu_percent; ///< CPU time available to the running application void Initialize(Service::Interface* self) { u32* cmd_buff = Kernel::GetCommandBuffer(); @@ -309,6 +309,7 @@ void Init() { } lock = Kernel::Mutex::Create(false, "APT_U:Lock"); + cpu_percent = 0; // TODO(bunnei): Check if these are created in Initialize or on APT process startup. @@ -317,7 +318,11 @@ void Init() { } void Shutdown() { - + shared_font.clear(); + shared_font_mem = nullptr; + lock = nullptr; + notification_event = nullptr; + start_event = nullptr; } } // namespace APT diff --git a/src/core/hle/service/cfg/cfg.cpp b/src/core/hle/service/cfg/cfg.cpp index 6af0352ac6..5eccdecf7d 100644 --- a/src/core/hle/service/cfg/cfg.cpp +++ b/src/core/hle/service/cfg/cfg.cpp @@ -207,6 +207,7 @@ void Init() { // Initialize the Username block // TODO(Subv): Initialize this directly in the variable when MSVC supports char16_t string literals + memset(&CONSOLE_USERNAME_BLOCK, 0, sizeof(CONSOLE_USERNAME_BLOCK)); CONSOLE_USERNAME_BLOCK.ng_word = 0; CONSOLE_USERNAME_BLOCK.zero = 0; @@ -219,7 +220,6 @@ void Init() { } void Shutdown() { - } } // namespace CFG diff --git a/src/core/hle/service/dsp_dsp.cpp b/src/core/hle/service/dsp_dsp.cpp index 4d6c70f4d3..2e759a3e34 100644 --- a/src/core/hle/service/dsp_dsp.cpp +++ b/src/core/hle/service/dsp_dsp.cpp @@ -11,7 +11,7 @@ namespace DSP_DSP { -static u32 read_pipe_count = 0; +static u32 read_pipe_count; static Kernel::SharedPtr semaphore_event; static Kernel::SharedPtr interrupt_event; diff --git a/src/core/hle/service/hid/hid.cpp b/src/core/hle/service/hid/hid.cpp index 9ca5d13d40..0f30f743a7 100644 --- a/src/core/hle/service/hid/hid.cpp +++ b/src/core/hle/service/hid/hid.cpp @@ -20,17 +20,17 @@ namespace HID { static const int MAX_CIRCLEPAD_POS = 0x9C; ///< Max value for a circle pad position // Handle to shared memory region designated to HID_User service -static Kernel::SharedPtr shared_mem = nullptr; +static Kernel::SharedPtr shared_mem; // Event handles -static Kernel::SharedPtr event_pad_or_touch_1 = nullptr; -static Kernel::SharedPtr event_pad_or_touch_2 = nullptr; -static Kernel::SharedPtr event_accelerometer = nullptr; -static Kernel::SharedPtr event_gyroscope = nullptr; -static Kernel::SharedPtr event_debug_pad = nullptr; +static Kernel::SharedPtr event_pad_or_touch_1; +static Kernel::SharedPtr event_pad_or_touch_2; +static Kernel::SharedPtr event_accelerometer; +static Kernel::SharedPtr event_gyroscope; +static Kernel::SharedPtr event_debug_pad; -static u32 next_pad_index = 0; -static u32 next_touch_index = 0; +static u32 next_pad_index; +static u32 next_touch_index; // TODO(peachum): // Add a method for setting analog input from joystick device for the circle Pad. @@ -175,6 +175,12 @@ void Init() { } void Shutdown() { + shared_mem = nullptr; + event_pad_or_touch_1 = nullptr; + event_pad_or_touch_2 = nullptr; + event_accelerometer = nullptr; + event_gyroscope = nullptr; + event_debug_pad = nullptr; } } // namespace HID diff --git a/src/core/hle/service/ir/ir.cpp b/src/core/hle/service/ir/ir.cpp index 58dfd8e1a4..15ac477efa 100644 --- a/src/core/hle/service/ir/ir.cpp +++ b/src/core/hle/service/ir/ir.cpp @@ -15,8 +15,8 @@ namespace Service { namespace IR { -static Kernel::SharedPtr handle_event = nullptr; -static Kernel::SharedPtr shared_memory = nullptr; +static Kernel::SharedPtr handle_event; +static Kernel::SharedPtr shared_memory; void GetHandles(Service::Interface* self) { u32* cmd_buff = Kernel::GetCommandBuffer(); @@ -41,6 +41,8 @@ void Init() { } void Shutdown() { + shared_memory = nullptr; + handle_event = nullptr; } } // namespace IR diff --git a/src/core/hle/service/nwm_uds.cpp b/src/core/hle/service/nwm_uds.cpp index 1cee81ab24..4b06efc3a1 100644 --- a/src/core/hle/service/nwm_uds.cpp +++ b/src/core/hle/service/nwm_uds.cpp @@ -11,7 +11,7 @@ namespace NWM_UDS { -static Kernel::SharedPtr handle_event = nullptr; +static Kernel::SharedPtr handle_event; /** * NWM_UDS::Shutdown service function diff --git a/src/core/hle/service/ptm/ptm.cpp b/src/core/hle/service/ptm/ptm.cpp index 57a301bec3..d44510c1b6 100644 --- a/src/core/hle/service/ptm/ptm.cpp +++ b/src/core/hle/service/ptm/ptm.cpp @@ -18,9 +18,9 @@ static const GameCoin default_game_coin = { 0x4F00, 42, 0, 0, 0, 2014, 12, 29 }; /// Id of the SharedExtData archive used by the PTM process static const std::vector ptm_shared_extdata_id = {0, 0, 0, 0, 0x0B, 0, 0, 0xF0, 0, 0, 0, 0}; -static bool shell_open = true; +static bool shell_open; -static bool battery_is_charging = true; +static bool battery_is_charging; u32 GetAdapterState() { // TODO(purpasmart96): This function is only a stub, @@ -43,6 +43,9 @@ void Init() { AddService(new PTM_Sysm_Interface); AddService(new PTM_U_Interface); + shell_open = true; + battery_is_charging = true; + // Open the SharedExtSaveData archive 0xF000000B and create the gamecoin.dat file if it doesn't exist FileSys::Path archive_path(ptm_shared_extdata_id); auto archive_result = Service::FS::OpenArchive(Service::FS::ArchiveIdCode::SharedExtSaveData, archive_path); diff --git a/src/core/hle/service/y2r_u.cpp b/src/core/hle/service/y2r_u.cpp index 6607965e1f..33ecf64a26 100644 --- a/src/core/hle/service/y2r_u.cpp +++ b/src/core/hle/service/y2r_u.cpp @@ -11,7 +11,7 @@ namespace Y2R_U { -static Kernel::SharedPtr completion_event = 0; +static Kernel::SharedPtr completion_event; /** * Y2R_U::IsBusyConversion service function