From d3c2f9a4a4c48e4571cd693a0c1801b665819cdf Mon Sep 17 00:00:00 2001
From: bunnei <bunneidev@gmail.com>
Date: Mon, 27 Apr 2015 22:45:43 -0400
Subject: [PATCH] HLE: Properly initialize and shutdown remaining modules.

---
 src/core/hle/config_mem.cpp  | 5 +++++
 src/core/hle/config_mem.h    | 2 ++
 src/core/hle/hle.cpp         | 9 ++++++---
 src/core/hle/shared_page.cpp | 5 +++++
 src/core/hle/shared_page.h   | 2 ++
 5 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/src/core/hle/config_mem.cpp b/src/core/hle/config_mem.cpp
index 30d73adac2..9fcfcc285e 100644
--- a/src/core/hle/config_mem.cpp
+++ b/src/core/hle/config_mem.cpp
@@ -61,6 +61,8 @@ template void Read<u16>(u16 &var, const u32 addr);
 template void Read<u8>(u8 &var, const u32 addr);
 
 void Init() {
+    memset(&config_mem, 0, sizeof(config_mem));
+
     config_mem.update_flag = 0; // No update
     config_mem.sys_core_ver = 0x2;
     config_mem.unit_info = 0x1; // Bit 0 set for Retail
@@ -76,4 +78,7 @@ void Init() {
     config_mem.firm_sys_core_ver = 0x2;
 }
 
+void Shutdown() {
+}
+
 } // namespace
diff --git a/src/core/hle/config_mem.h b/src/core/hle/config_mem.h
index 94853901a9..cbb478fb32 100644
--- a/src/core/hle/config_mem.h
+++ b/src/core/hle/config_mem.h
@@ -20,4 +20,6 @@ void Read(T &var, const u32 addr);
 
 void Init();
 
+void Shutdown();
+
 } // namespace
diff --git a/src/core/hle/hle.cpp b/src/core/hle/hle.cpp
index c645d6563b..191d0411eb 100644
--- a/src/core/hle/hle.cpp
+++ b/src/core/hle/hle.cpp
@@ -23,7 +23,7 @@ Common::Profiling::TimingCategory profiler_svc("SVC Calls");
 
 static std::vector<ModuleDef> g_module_db;
 
-bool g_reschedule = false;  ///< If true, immediately reschedules the CPU to a new thread
+bool g_reschedule; ///< If true, immediately reschedules the CPU to a new thread
 
 static const FunctionDef* GetSVCInfo(u32 opcode) {
     u32 func_num = opcode & 0xFFFFFF; // 8 bits
@@ -73,17 +73,20 @@ static void RegisterAllModules() {
 }
 
 void Init() {
-    Service::Init();
-
     RegisterAllModules();
 
+    Service::Init();
     ConfigMem::Init();
     SharedPage::Init();
 
+    g_reschedule = false;
+
     LOG_DEBUG(Kernel, "initialized OK");
 }
 
 void Shutdown() {
+    ConfigMem::Shutdown();
+    SharedPage::Shutdown();
     Service::Shutdown();
 
     g_module_db.clear();
diff --git a/src/core/hle/shared_page.cpp b/src/core/hle/shared_page.cpp
index 568dad6845..94fae25516 100644
--- a/src/core/hle/shared_page.cpp
+++ b/src/core/hle/shared_page.cpp
@@ -62,6 +62,8 @@ template void Read<u16>(u16 &var, const u32 addr);
 template void Read<u8>(u8 &var, const u32 addr);
 
 void Set3DSlider(float amount) {
+    memset(&shared_page, 0, sizeof(shared_page));
+
     shared_page.sliderstate_3d = amount;
     shared_page.ledstate_3d = (amount == 0.0f); // off when non-zero
 }
@@ -71,4 +73,7 @@ void Init() {
     Set3DSlider(0.0f);
 }
 
+void Shutdown() {
+}
+
 } // namespace
diff --git a/src/core/hle/shared_page.h b/src/core/hle/shared_page.h
index 8f93545ec6..1b6e4e5815 100644
--- a/src/core/hle/shared_page.h
+++ b/src/core/hle/shared_page.h
@@ -23,4 +23,6 @@ void Set3DSlider(float amount);
 
 void Init();
 
+void Shutdown();
+
 } // namespace