From 0aade9ad631f21b9d0e72c4896858c107f5a167a Mon Sep 17 00:00:00 2001
From: Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
Date: Sat, 20 Jun 2015 20:10:44 +0100
Subject: [PATCH 01/19] Common: Remove unused fifo_queue.h.

---
 src/common/CMakeLists.txt |   1 -
 src/common/fifo_queue.h   | 111 --------------------------------------
 2 files changed, 112 deletions(-)
 delete mode 100644 src/common/fifo_queue.h

diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt
index e78f4f1441..f025e1186a 100644
--- a/src/common/CMakeLists.txt
+++ b/src/common/CMakeLists.txt
@@ -31,7 +31,6 @@ set(HEADERS
             cpu_detect.h
             debug_interface.h
             emu_window.h
-            fifo_queue.h
             file_util.h
             key_map.h
             linear_disk_cache.h
diff --git a/src/common/fifo_queue.h b/src/common/fifo_queue.h
deleted file mode 100644
index b426e65963..0000000000
--- a/src/common/fifo_queue.h
+++ /dev/null
@@ -1,111 +0,0 @@
-#pragma once
-
-// a simple lockless thread-safe,
-// single reader, single writer queue
-
-#include "common/atomic.h"
-
-namespace Common
-{
-
-template <typename T>
-class FifoQueue
-{
-public:
-    FifoQueue() : m_size(0)
-    {
-         m_write_ptr = m_read_ptr = new ElementPtr();
-    }
-
-    ~FifoQueue()
-    {
-        // this will empty out the whole queue
-        delete m_read_ptr;
-    }
-
-    u32 Size() const
-    {
-        return m_size;
-    }
-
-    bool Empty() const
-    {
-        //return (m_read_ptr == m_write_ptr);
-        return (0 == m_size);
-    }
-
-    T& Front() const
-    {
-        return *m_read_ptr->current;
-    }
-
-    template <typename Arg>
-    void Push(Arg&& t)
-    {
-        // create the element, add it to the queue
-        m_write_ptr->current = new T(std::forward<Arg>(t));
-        // set the next pointer to a new element ptr
-        // then advance the write pointer
-        m_write_ptr = m_write_ptr->next = new ElementPtr();
-        Common::AtomicIncrement(m_size);
-    }
-
-    void Pop()
-    {
-        Common::AtomicDecrement(m_size);
-        ElementPtr *const tmpptr = m_read_ptr;
-        // advance the read pointer
-        m_read_ptr = m_read_ptr->next;
-        // set the next element to NULL to stop the recursive deletion
-        tmpptr->next = nullptr;
-        delete tmpptr;    // this also deletes the element
-    }
-
-    bool Pop(T& t)
-    {
-        if (Empty())
-            return false;
-
-        t = std::move(Front());
-        Pop();
-
-        return true;
-    }
-
-    // not thread-safe
-    void Clear()
-    {
-        m_size = 0;
-        delete m_read_ptr;
-        m_write_ptr = m_read_ptr = new ElementPtr();
-    }
-
-private:
-    // stores a pointer to element
-    // and a pointer to the next ElementPtr
-    class ElementPtr
-    {
-    public:
-        ElementPtr() : current(nullptr), next(nullptr) {}
-
-        ~ElementPtr()
-        {
-            if (current)
-            {
-                delete current;
-                // recusion ftw
-                if (next)
-                    delete next;
-            }
-        }
-
-        T *volatile current;
-        ElementPtr *volatile next;
-    };
-
-    ElementPtr *volatile m_write_ptr;
-    ElementPtr *volatile m_read_ptr;
-    volatile u32 m_size;
-};
-
-}

From c34524743168af08812894ae635cd837fc77d403 Mon Sep 17 00:00:00 2001
From: Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
Date: Sat, 20 Jun 2015 20:11:32 +0100
Subject: [PATCH 02/19] Services: Use the standard _WIN32 define in soc:U
 instead of our own EMU_PLATFORM.

---
 src/core/hle/service/soc_u.cpp | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/src/core/hle/service/soc_u.cpp b/src/core/hle/service/soc_u.cpp
index 1e0f5df9ba..6a2cab4143 100644
--- a/src/core/hle/service/soc_u.cpp
+++ b/src/core/hle/service/soc_u.cpp
@@ -3,9 +3,8 @@
 // Refer to the license.txt file included.
 
 #include "common/logging/log.h"
-#include "common/platform.h"
 
-#if EMU_PLATFORM == PLATFORM_WINDOWS
+#ifdef _WIN32
 #include <winsock2.h>
 #include <ws2tcpip.h>
 
@@ -35,7 +34,7 @@
 #include "core/hle/service/soc_u.h"
 #include <unordered_map>
 
-#if EMU_PLATFORM == PLATFORM_WINDOWS
+#ifdef _WIN32
 #    define WSAEAGAIN      WSAEWOULDBLOCK
 #    define WSAEMULTIHOP   -1 // Invalid dummy value
 #    define ERRNO(x)       WSA##x
@@ -369,7 +368,7 @@ static void Fcntl(Service::Interface* self) {
     });
 
     if (ctr_cmd == 3) { // F_GETFL
-#if EMU_PLATFORM == PLATFORM_WINDOWS
+#ifdef _WIN32
         posix_ret = 0;
         auto iter = open_sockets.find(socket_handle);
         if (iter != open_sockets.end() && iter->second.blocking == false)
@@ -386,7 +385,7 @@ static void Fcntl(Service::Interface* self) {
             posix_ret |= 4; // O_NONBLOCK
 #endif
     } else if (ctr_cmd == 4) { // F_SETFL
-#if EMU_PLATFORM == PLATFORM_WINDOWS
+#ifdef _WIN32
         unsigned long tmp = (ctr_arg & 4 /* O_NONBLOCK */) ? 1 : 0;
         int ret = ioctlsocket(socket_handle, FIONBIO, &tmp);
         if (ret == SOCKET_ERROR_VALUE) {
@@ -675,7 +674,7 @@ static void Connect(Service::Interface* self) {
 
 static void InitializeSockets(Service::Interface* self) {
     // TODO(Subv): Implement
-#if EMU_PLATFORM == PLATFORM_WINDOWS
+#ifdef _WIN32
     WSADATA data;
     WSAStartup(MAKEWORD(2, 2), &data);
 #endif
@@ -688,7 +687,7 @@ static void ShutdownSockets(Service::Interface* self) {
     // TODO(Subv): Implement
     CleanupSockets();
 
-#if EMU_PLATFORM == PLATFORM_WINDOWS
+#ifdef _WIN32
     WSACleanup();
 #endif
 
@@ -739,7 +738,7 @@ Interface::Interface() {
 
 Interface::~Interface() {
     CleanupSockets();
-#if EMU_PLATFORM == PLATFORM_WINDOWS
+#ifdef _WIN32
     WSACleanup();
 #endif
 }

From 82718c4a41d141b524026af4d70af167965e5a1c Mon Sep 17 00:00:00 2001
From: Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
Date: Sat, 20 Jun 2015 20:13:06 +0100
Subject: [PATCH 03/19] Common: Remove unused SSE version checking and a GCC
 macro.

---
 src/common/platform.h | 25 -------------------------
 1 file changed, 25 deletions(-)

diff --git a/src/common/platform.h b/src/common/platform.h
index df780ac6f0..bda3e7be79 100644
--- a/src/common/platform.h
+++ b/src/common/platform.h
@@ -62,28 +62,3 @@
 #elif defined(__i386) || defined(_M_IX86) || defined(__arm__) || defined(_M_ARM)
     #define EMU_ARCH_BITS 32
 #endif
-
-////////////////////////////////////////////////////////////////////////////////////////////////////
-// Feature detection
-
-#if defined _M_GENERIC
-#  define _M_SSE 0x0
-#elif defined __GNUC__
-# if defined __SSE4_2__
-#  define _M_SSE 0x402
-# elif defined __SSE4_1__
-#  define _M_SSE 0x401
-# elif defined __SSSE3__
-#  define _M_SSE 0x301
-# elif defined __SSE3__
-#  define _M_SSE 0x300
-# endif
-#elif (_MSC_VER >= 1500) || __INTEL_COMPILER // Visual Studio 2008
-#  define _M_SSE 0x402
-#endif
-
-////////////////////////////////////////////////////////////////////////////////////////////////////
-// Compiler-Specific Definitions
-
-#define GCC_VERSION_AVAILABLE(major, minor) (defined(__GNUC__) &&  (__GNUC__ > (major) || \
-    (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))))

From ce0cfd62d95cdc46f4517ad16a0396a5815cb595 Mon Sep 17 00:00:00 2001
From: Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
Date: Sat, 20 Jun 2015 20:14:43 +0100
Subject: [PATCH 04/19] Common: Remove now-unused EMU_PLATFORM define, fixes
 issue #373.

---
 src/citra_qt/main.cpp |  4 ----
 src/common/platform.h | 30 ------------------------------
 2 files changed, 34 deletions(-)

diff --git a/src/citra_qt/main.cpp b/src/citra_qt/main.cpp
index 8041816a0b..43b80a34a9 100644
--- a/src/citra_qt/main.cpp
+++ b/src/citra_qt/main.cpp
@@ -18,10 +18,6 @@
 #include "common/platform.h"
 #include "common/scope_exit.h"
 
-#if EMU_PLATFORM == PLATFORM_LINUX
-#include <unistd.h>
-#endif
-
 #include "bootmanager.h"
 #include "hotkeys.h"
 
diff --git a/src/common/platform.h b/src/common/platform.h
index bda3e7be79..0a912dda31 100644
--- a/src/common/platform.h
+++ b/src/common/platform.h
@@ -24,39 +24,9 @@
 
 #pragma once
 
-#include "common/common_types.h"
-
-////////////////////////////////////////////////////////////////////////////////////////////////////
-// Platform definitions
-
-/// Enumeration for defining the supported platforms
-#define PLATFORM_NULL 0
-#define PLATFORM_WINDOWS 1
-#define PLATFORM_MACOSX 2
-#define PLATFORM_LINUX 3
-#define PLATFORM_ANDROID 4
-
 ////////////////////////////////////////////////////////////////////////////////////////////////////
 // Platform detection
 
-#ifndef EMU_PLATFORM
-
-#if defined( __WIN32__ ) || defined( _WIN32 )
-#define EMU_PLATFORM PLATFORM_WINDOWS
-
-#elif defined( __APPLE__ ) || defined( __APPLE_CC__ )
-#define EMU_PLATFORM PLATFORM_MACOSX
-
-#elif defined(__linux__)
-#define EMU_PLATFORM PLATFORM_LINUX
-
-#else // Assume linux otherwise
-#define EMU_PLATFORM PLATFORM_LINUX
-
-#endif
-
-#endif
-
 #if defined(__x86_64__) || defined(_M_X64) || defined(__aarch64__)
     #define EMU_ARCH_BITS 64
 #elif defined(__i386) || defined(_M_IX86) || defined(__arm__) || defined(_M_ARM)

From 79aa1b0808e8561560b58dab950ba4cd36e6aabb Mon Sep 17 00:00:00 2001
From: Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
Date: Sat, 20 Jun 2015 20:34:41 +0100
Subject: [PATCH 05/19] Citra: Fix the includes a bit, thanks to
 include-what-you-use.

---
 src/citra/citra.cpp                      |  4 +---
 src/citra/config.cpp                     |  3 ++-
 src/citra/config.h                       |  6 ++----
 src/citra/emu_window/emu_window_glfw.cpp | 12 ++++++++++++
 src/citra/emu_window/emu_window_glfw.h   |  2 ++
 5 files changed, 19 insertions(+), 8 deletions(-)

diff --git a/src/citra/citra.cpp b/src/citra/citra.cpp
index ce8d7dd258..a59726c787 100644
--- a/src/citra/citra.cpp
+++ b/src/citra/citra.cpp
@@ -2,13 +2,11 @@
 // Licensed under GPLv2 or any later version
 // Refer to the license.txt file included.
 
-#include <thread>
+#include <string>
 
 #include "common/logging/log.h"
-#include "common/logging/text_formatter.h"
 #include "common/logging/backend.h"
 #include "common/logging/filter.h"
-#include "common/scope_exit.h"
 
 #include "core/settings.h"
 #include "core/system.h"
diff --git a/src/citra/config.cpp b/src/citra/config.cpp
index 1378567c16..506cb7939c 100644
--- a/src/citra/config.cpp
+++ b/src/citra/config.cpp
@@ -2,7 +2,9 @@
 // Licensed under GPLv2 or any later version
 // Refer to the license.txt file included.
 
+#define GLFW_INCLUDE_NONE
 #include <GLFW/glfw3.h>
+#include <inih/cpp/INIReader.h>
 
 #include "citra/default_ini.h"
 
@@ -10,7 +12,6 @@
 #include "common/logging/log.h"
 
 #include "core/settings.h"
-#include "core/core.h"
 
 #include "config.h"
 
diff --git a/src/citra/config.h b/src/citra/config.h
index 0eb176c7d2..c326ec6696 100644
--- a/src/citra/config.h
+++ b/src/citra/config.h
@@ -4,11 +4,9 @@
 
 #pragma once
 
-#include <map>
+#include <string>
 
-#include <inih/cpp/INIReader.h>
-
-#include "common/common_types.h"
+class INIReader;
 
 class Config {
     INIReader* glfw_config;
diff --git a/src/citra/emu_window/emu_window_glfw.cpp b/src/citra/emu_window/emu_window_glfw.cpp
index 341b48d2a8..42fb683a94 100644
--- a/src/citra/emu_window/emu_window_glfw.cpp
+++ b/src/citra/emu_window/emu_window_glfw.cpp
@@ -2,13 +2,25 @@
 // Licensed under GPLv2 or any later version
 // Refer to the license.txt file included.
 
+#include <algorithm>
+#include <cstdlib>
+#include <string>
+
+// Let’s use our own GL header, instead of one from GLFW.
+#include "video_core/renderer_opengl/generated/gl_3_2_core.h"
+#define GLFW_INCLUDE_NONE
 #include <GLFW/glfw3.h>
 
+#include "common/assert.h"
+#include "common/key_map.h"
 #include "common/logging/log.h"
+#include "common/scm_rev.h"
+#include "common/string_util.h"
 
 #include "video_core/video_core.h"
 
 #include "core/settings.h"
+#include "core/hle/service/hid/hid.h"
 
 #include "citra/emu_window/emu_window_glfw.h"
 
diff --git a/src/citra/emu_window/emu_window_glfw.h b/src/citra/emu_window/emu_window_glfw.h
index 16c109b792..7ccd5e6aa6 100644
--- a/src/citra/emu_window/emu_window_glfw.h
+++ b/src/citra/emu_window/emu_window_glfw.h
@@ -4,6 +4,8 @@
 
 #pragma once
 
+#include <utility>
+
 #include "common/emu_window.h"
 
 struct GLFWwindow;

From 8cf9eb7f431e235a39f380118cfd081a604ea1c9 Mon Sep 17 00:00:00 2001
From: Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
Date: Sat, 20 Jun 2015 22:24:01 +0100
Subject: [PATCH 06/19] Common: Fix FileUtil includes, and everything relying
 on those.

---
 src/common/chunk_file.h                       |  7 ++++---
 src/common/file_util.cpp                      | 11 +++++++++--
 src/common/file_util.h                        |  3 +--
 src/core/arm/disassembler/load_symbol_map.cpp |  1 +
 src/core/core_timing.cpp                      |  1 +
 src/core/file_sys/archive_extsavedata.cpp     |  1 +
 src/core/file_sys/archive_savedata.cpp        |  1 +
 src/core/file_sys/archive_savedatacheck.cpp   |  1 +
 src/core/file_sys/archive_systemsavedata.cpp  |  1 +
 src/core/loader/loader.cpp                    |  1 +
 10 files changed, 21 insertions(+), 7 deletions(-)

diff --git a/src/common/chunk_file.h b/src/common/chunk_file.h
index dcd80525ef..ee9f3d7c09 100644
--- a/src/common/chunk_file.h
+++ b/src/common/chunk_file.h
@@ -26,13 +26,14 @@
 // - Zero backwards/forwards compatibility
 // - Serialization code for anything complex has to be manually written.
 
-#include <map>
-#include <vector>
+#include <cstring>
 #include <deque>
-#include <string>
 #include <list>
+#include <map>
 #include <set>
+#include <string>
 #include <type_traits>
+#include <vector>
 
 #include "common/common_types.h"
 #include "common/file_util.h"
diff --git a/src/common/file_util.cpp b/src/common/file_util.cpp
index 24648ea33b..836b58d527 100644
--- a/src/common/file_util.cpp
+++ b/src/common/file_util.cpp
@@ -17,6 +17,8 @@
     #include <direct.h> // getcwd
     #include <tchar.h>
 
+    #include "common/string_util.h"
+
     // 64 bit offsets for windows
     #define fseeko _fseeki64
     #define ftello _ftelli64
@@ -25,8 +27,13 @@
     #define fstat64 _fstat64
     #define fileno _fileno
 #else
-    #include <sys/param.h>
-    #include <sys/types.h>
+    #ifdef __APPLE__
+        #include <sys/param.h>
+    #endif
+    #include <cctype>
+    #include <cerrno>
+    #include <cstdlib>
+    #include <cstring>
     #include <dirent.h>
     #include <pwd.h>
     #include <unistd.h>
diff --git a/src/common/file_util.h b/src/common/file_util.h
index b65829291e..8fe772aee2 100644
--- a/src/common/file_util.h
+++ b/src/common/file_util.h
@@ -6,13 +6,12 @@
 
 #include <array>
 #include <fstream>
+#include <cstddef>
 #include <cstdio>
-#include <cstring>
 #include <string>
 #include <vector>
 
 #include "common/common_types.h"
-#include "common/string_util.h"
 
 // User directory indices for GetUserPath
 enum {
diff --git a/src/core/arm/disassembler/load_symbol_map.cpp b/src/core/arm/disassembler/load_symbol_map.cpp
index 13d26d1709..eb20bf6f76 100644
--- a/src/core/arm/disassembler/load_symbol_map.cpp
+++ b/src/core/arm/disassembler/load_symbol_map.cpp
@@ -2,6 +2,7 @@
 // Licensed under GPLv2 or any later version
 // Refer to the license.txt file included.
 
+#include <sstream>
 #include <string>
 #include <vector>
 
diff --git a/src/core/core_timing.cpp b/src/core/core_timing.cpp
index e53c2e6068..0eb717c8dd 100644
--- a/src/core/core_timing.cpp
+++ b/src/core/core_timing.cpp
@@ -9,6 +9,7 @@
 
 #include "common/assert.h"
 #include "common/chunk_file.h"
+#include "common/string_util.h"
 
 #include "core/arm/arm_interface.h"
 #include "core/core.h"
diff --git a/src/core/file_sys/archive_extsavedata.cpp b/src/core/file_sys/archive_extsavedata.cpp
index e50c58a52f..ce26e6bee5 100644
--- a/src/core/file_sys/archive_extsavedata.cpp
+++ b/src/core/file_sys/archive_extsavedata.cpp
@@ -8,6 +8,7 @@
 #include "common/file_util.h"
 #include "common/logging/log.h"
 #include "common/make_unique.h"
+#include "common/string_util.h"
 
 #include "core/file_sys/archive_extsavedata.h"
 #include "core/file_sys/disk_archive.h"
diff --git a/src/core/file_sys/archive_savedata.cpp b/src/core/file_sys/archive_savedata.cpp
index a92309377b..f8acec9771 100644
--- a/src/core/file_sys/archive_savedata.cpp
+++ b/src/core/file_sys/archive_savedata.cpp
@@ -8,6 +8,7 @@
 #include "common/file_util.h"
 #include "common/logging/log.h"
 #include "common/make_unique.h"
+#include "common/string_util.h"
 
 #include "core/file_sys/archive_savedata.h"
 #include "core/file_sys/disk_archive.h"
diff --git a/src/core/file_sys/archive_savedatacheck.cpp b/src/core/file_sys/archive_savedatacheck.cpp
index e7e4fbf1d9..def85d4c38 100644
--- a/src/core/file_sys/archive_savedatacheck.cpp
+++ b/src/core/file_sys/archive_savedatacheck.cpp
@@ -5,6 +5,7 @@
 #include "common/file_util.h"
 #include "common/logging/log.h"
 #include "common/make_unique.h"
+#include "common/string_util.h"
 
 #include "core/file_sys/archive_savedatacheck.h"
 #include "core/hle/service/fs/archive.h"
diff --git a/src/core/file_sys/archive_systemsavedata.cpp b/src/core/file_sys/archive_systemsavedata.cpp
index 4fe785c975..9a9182afc9 100644
--- a/src/core/file_sys/archive_systemsavedata.cpp
+++ b/src/core/file_sys/archive_systemsavedata.cpp
@@ -7,6 +7,7 @@
 #include "common/common_types.h"
 #include "common/file_util.h"
 #include "common/make_unique.h"
+#include "common/string_util.h"
 
 #include "core/file_sys/archive_systemsavedata.h"
 #include "core/hle/service/fs/archive.h"
diff --git a/src/core/loader/loader.cpp b/src/core/loader/loader.cpp
index 8b14edf00d..6e608a8589 100644
--- a/src/core/loader/loader.cpp
+++ b/src/core/loader/loader.cpp
@@ -6,6 +6,7 @@
 
 #include "common/logging/log.h"
 #include "common/make_unique.h"
+#include "common/string_util.h"
 
 #include "core/file_sys/archive_romfs.h"
 #include "core/hle/kernel/process.h"

From 13e6876463078ee0597b3677a26ccaa2a5ff8b35 Mon Sep 17 00:00:00 2001
From: Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
Date: Sat, 20 Jun 2015 22:33:54 +0100
Subject: [PATCH 07/19] Common: Fix string_util includes.

---
 src/common/string_util.cpp | 9 +++++++--
 src/common/string_util.h   | 3 ++-
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/src/common/string_util.cpp b/src/common/string_util.cpp
index 7dc0ba7baf..2e80809abe 100644
--- a/src/common/string_util.cpp
+++ b/src/common/string_util.cpp
@@ -2,9 +2,13 @@
 // Licensed under GPLv2 or any later version
 // Refer to the license.txt file included.
 
-#include <boost/range/algorithm.hpp>
+#include <cctype>
+#include <cerrno>
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
+#include <boost/range/algorithm/transform.hpp>
 
-#include "common/common_funcs.h"
 #include "common/common_paths.h"
 #include "common/logging/log.h"
 #include "common/string_util.h"
@@ -12,6 +16,7 @@
 #ifdef _MSC_VER
     #include <Windows.h>
     #include <codecvt>
+    #include "common/common_funcs.h"
 #else
     #include <iconv.h>
 #endif
diff --git a/src/common/string_util.h b/src/common/string_util.h
index fdc4104998..c5c474c6fe 100644
--- a/src/common/string_util.h
+++ b/src/common/string_util.h
@@ -5,9 +5,10 @@
 #pragma once
 
 #include <cstdarg>
+#include <cstddef>
 #include <iomanip>
-#include <string>
 #include <sstream>
+#include <string>
 #include <vector>
 
 #include "common/common_types.h"

From 2a36edfd86cc15829b113466845ccab759731793 Mon Sep 17 00:00:00 2001
From: Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
Date: Sat, 20 Jun 2015 22:45:15 +0100
Subject: [PATCH 08/19] Common: Cleanup thread includes.

---
 src/common/thread.cpp | 17 +++++++++++++----
 src/common/thread.h   | 16 ++--------------
 2 files changed, 15 insertions(+), 18 deletions(-)

diff --git a/src/common/thread.cpp b/src/common/thread.cpp
index 8bf0058574..7bbf080bc0 100644
--- a/src/common/thread.cpp
+++ b/src/common/thread.cpp
@@ -5,11 +5,20 @@
 #include "common/thread.h"
 
 #ifdef __APPLE__
-#include <mach/mach.h>
-#elif defined(BSD4_4) || defined(__OpenBSD__)
-#include <pthread_np.h>
+    #include <mach/mach.h>
 #elif defined(_WIN32)
-#include <Windows.h>
+    #include <Windows.h>
+#else
+    #if defined(BSD4_4) || defined(__OpenBSD__)
+        #include <pthread_np.h>
+    #else
+        #include <pthread.h>
+    #endif
+    #include <sched.h>
+#endif
+
+#ifndef _WIN32
+    #include <unistd.h>
 #endif
 
 namespace Common
diff --git a/src/common/thread.h b/src/common/thread.h
index 7bc419497b..8255ee6d31 100644
--- a/src/common/thread.h
+++ b/src/common/thread.h
@@ -4,24 +4,12 @@
 
 #pragma once
 
-#include "common/common_types.h"
-#include <cstdio>
-#include <cstring>
+#include <cstddef>
 #include <thread>
 #include <condition_variable>
 #include <mutex>
 
-// This may not be defined outside _WIN32
-#ifndef _WIN32
-#ifndef INFINITE
-#define INFINITE 0xffffffff
-#endif
-
-//for gettimeofday and struct time(spec|val)
-#include <time.h>
-#include <sys/time.h>
-#include <unistd.h>
-#endif
+#include "common/common_types.h"
 
 // Support for C++11's thread_local keyword was surprisingly spotty in compilers until very
 // recently. Fortunately, thread local variables have been well supported for compilers for a while,

From 3a771a13dcfd1de061e886e081393fca1fd1e689 Mon Sep 17 00:00:00 2001
From: Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
Date: Sat, 20 Jun 2015 23:36:19 +0100
Subject: [PATCH 09/19] Common: Cleanup profiler includes.

---
 src/common/assert.h               |  1 -
 src/common/profiler.cpp           | 11 ++++++++---
 src/common/profiler_reporting.h   |  4 +---
 src/common/synchronized_wrapper.h |  1 +
 4 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/src/common/assert.h b/src/common/assert.h
index 7b7d8bf28c..6849778b79 100644
--- a/src/common/assert.h
+++ b/src/common/assert.h
@@ -4,7 +4,6 @@
 
 #pragma once
 
-#include <cstdio>
 #include <cstdlib>
 
 #include "common/common_funcs.h"
diff --git a/src/common/profiler.cpp b/src/common/profiler.cpp
index cf6b6b258d..7792edd2fc 100644
--- a/src/common/profiler.cpp
+++ b/src/common/profiler.cpp
@@ -2,13 +2,18 @@
 // Licensed under GPLv2 or any later version
 // Refer to the license.txt file included.
 
+#include <algorithm>
+#include <cstddef>
+#include <vector>
+
+#include "common/assert.h"
 #include "common/profiler.h"
 #include "common/profiler_reporting.h"
-#include "common/assert.h"
+#include "common/synchronized_wrapper.h"
 
 #if defined(_MSC_VER) && _MSC_VER <= 1800 // MSVC 2013.
-#define WIN32_LEAN_AND_MEAN
-#include <Windows.h> // For QueryPerformanceCounter/Frequency
+    #define WIN32_LEAN_AND_MEAN
+    #include <Windows.h> // For QueryPerformanceCounter/Frequency
 #endif
 
 namespace Common {
diff --git a/src/common/profiler_reporting.h b/src/common/profiler_reporting.h
index 3abb733155..ab60cfb16c 100644
--- a/src/common/profiler_reporting.h
+++ b/src/common/profiler_reporting.h
@@ -4,10 +4,8 @@
 
 #pragma once
 
-#include <array>
 #include <chrono>
-#include <mutex>
-#include <utility>
+#include <cstddef>
 #include <vector>
 
 #include "common/profiler.h"
diff --git a/src/common/synchronized_wrapper.h b/src/common/synchronized_wrapper.h
index 946252b8c1..ae5e8b1ed5 100644
--- a/src/common/synchronized_wrapper.h
+++ b/src/common/synchronized_wrapper.h
@@ -4,6 +4,7 @@
 
 #pragma once
 
+#include <algorithm>
 #include <mutex>
 
 namespace Common {

From 2d044a67c932403b81fdde6f81d461c6e7c11efe Mon Sep 17 00:00:00 2001
From: Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
Date: Sun, 21 Jun 2015 13:12:49 +0100
Subject: [PATCH 10/19] Common: Cleanup memory and misc includes.

---
 src/common/common_funcs.h        |  4 ----
 src/common/common_types.h        |  2 --
 src/common/logging/log.h         |  4 ----
 src/common/memory_util.cpp       | 11 +++++++----
 src/common/memory_util.h         |  4 +---
 src/common/misc.cpp              |  5 +++--
 src/common/swap.h                | 10 +++++++---
 src/core/file_sys/file_backend.h |  2 ++
 src/core/memory.cpp              |  3 ---
 src/core/memory.h                |  2 ++
 10 files changed, 22 insertions(+), 25 deletions(-)

diff --git a/src/common/common_funcs.h b/src/common/common_funcs.h
index 91b74c6bcd..cc74a228ea 100644
--- a/src/common/common_funcs.h
+++ b/src/common/common_funcs.h
@@ -5,8 +5,6 @@
 #pragma once
 
 #include "common_types.h"
-#include <cstdlib>
-
 
 #define b2(x)   (   (x) | (   (x) >> 1) )
 #define b4(x)   ( b2(x) | ( b2(x) >> 2) )
@@ -43,8 +41,6 @@
 
 #ifndef _MSC_VER
 
-#include <errno.h>
-
 #if defined(__x86_64__) || defined(_M_X64)
 #define Crash() __asm__ __volatile__("int $3")
 #elif defined(_M_ARM)
diff --git a/src/common/common_types.h b/src/common/common_types.h
index f6de0adfc1..ebfd7824a3 100644
--- a/src/common/common_types.h
+++ b/src/common/common_types.h
@@ -24,9 +24,7 @@
 
 #pragma once
 
-#include <cmath>
 #include <cstdint>
-#include <cstdlib>
 
 #ifdef _MSC_VER
 #ifndef __func__
diff --git a/src/common/logging/log.h b/src/common/logging/log.h
index 5b3a731e9b..e16dde7fce 100644
--- a/src/common/logging/log.h
+++ b/src/common/logging/log.h
@@ -4,10 +4,6 @@
 
 #pragma once
 
-#include <cassert>
-#include <chrono>
-#include <string>
-
 #include "common/common_types.h"
 
 namespace Log {
diff --git a/src/common/memory_util.cpp b/src/common/memory_util.cpp
index 20b791a101..2b3ace5288 100644
--- a/src/common/memory_util.cpp
+++ b/src/common/memory_util.cpp
@@ -3,14 +3,17 @@
 // Refer to the license.txt file included.
 
 
-#include "common/common_funcs.h"
 #include "common/logging/log.h"
 #include "common/memory_util.h"
-#include "common/string_util.h"
 
 #ifdef _WIN32
-#include <windows.h>
-#include <psapi.h>
+    #include <windows.h>
+    #include <psapi.h>
+    #include "common/common_funcs.h"
+    #include "common/string_util.h"
+#else
+    #include <cstdlib>
+    #include <sys/mman.h>
 #endif
 
 #if !defined(_WIN32) && defined(__x86_64__) && !defined(MAP_32BIT)
diff --git a/src/common/memory_util.h b/src/common/memory_util.h
index 9fdbf1f121..9bf37c44fd 100644
--- a/src/common/memory_util.h
+++ b/src/common/memory_util.h
@@ -4,9 +4,7 @@
 
 #pragma once
 
-#ifndef _WIN32
-#include <sys/mman.h>
-#endif
+#include <cstddef>
 #include <string>
 
 void* AllocateExecutableMemory(size_t size, bool low = true);
diff --git a/src/common/misc.cpp b/src/common/misc.cpp
index 53cacf37cf..d2a049b636 100644
--- a/src/common/misc.cpp
+++ b/src/common/misc.cpp
@@ -2,12 +2,13 @@
 // Licensed under GPLv2 or any later version
 // Refer to the license.txt file included.
 
-#include "common/common_funcs.h"
+#include <cstddef>
 
 #ifdef _WIN32
 #include <windows.h>
 #else
-#include <string.h>
+#include <cerrno>
+#include <cstring>
 #endif
 
 // Neither Android nor OS X support TLS
diff --git a/src/common/swap.h b/src/common/swap.h
index 588cebc708..b92e5bfa49 100644
--- a/src/common/swap.h
+++ b/src/common/swap.h
@@ -17,12 +17,16 @@
 
 #pragma once
 
-#if defined(__linux__)
-#include <byteswap.h>
+#if defined(_MSC_VER)
+    #include <cstdlib>
+#elif defined(__linux__)
+    #include <byteswap.h>
 #elif defined(__FreeBSD__)
-#include <sys/endian.h>
+    #include <sys/endian.h>
 #endif
 
+#include "common/common_types.h"
+
 // GCC 4.6+
 #if __GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
 
diff --git a/src/core/file_sys/file_backend.h b/src/core/file_sys/file_backend.h
index 0fcff18454..f5f72c722d 100644
--- a/src/core/file_sys/file_backend.h
+++ b/src/core/file_sys/file_backend.h
@@ -4,6 +4,8 @@
 
 #pragma once
 
+#include <cstddef>
+
 #include "common/common_types.h"
 
 ////////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/core/memory.cpp b/src/core/memory.cpp
index 28844a9154..172ae90546 100644
--- a/src/core/memory.cpp
+++ b/src/core/memory.cpp
@@ -9,9 +9,6 @@
 #include "common/logging/log.h"
 #include "common/swap.h"
 
-#include "core/hle/config_mem.h"
-#include "core/hle/shared_page.h"
-#include "core/hw/hw.h"
 #include "core/mem_map.h"
 #include "core/memory.h"
 #include "core/memory_setup.h"
diff --git a/src/core/memory.h b/src/core/memory.h
index 0b8ff9ec4e..418609de07 100644
--- a/src/core/memory.h
+++ b/src/core/memory.h
@@ -4,6 +4,8 @@
 
 #pragma once
 
+#include <cstddef>
+
 #include "common/common_types.h"
 
 namespace Memory {

From 596b7c4f63e38d275b6a056d6125c0027a1376e7 Mon Sep 17 00:00:00 2001
From: Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
Date: Sun, 21 Jun 2015 13:40:28 +0100
Subject: [PATCH 11/19] Common: Cleanup key_map includes.

---
 src/common/bit_field.h                           |  1 +
 src/core/hle/hle.cpp                             |  1 -
 src/core/hle/kernel/kernel.cpp                   |  2 --
 src/core/hle/kernel/kernel.h                     |  7 +++----
 src/core/hle/kernel/session.h                    |  6 ++++++
 src/core/hle/kernel/thread.h                     |  1 +
 src/core/hle/result.h                            |  2 +-
 src/core/hle/service/hid/hid.h                   | 16 +++++++++-------
 src/core/hle/service/service.h                   |  1 -
 src/core/loader/loader.cpp                       |  1 +
 src/core/loader/loader.h                         |  1 +
 src/video_core/renderer_opengl/gl_rasterizer.cpp |  8 +++++---
 src/video_core/renderer_opengl/gl_rasterizer.h   |  4 ++++
 13 files changed, 32 insertions(+), 19 deletions(-)

diff --git a/src/common/bit_field.h b/src/common/bit_field.h
index 1f3ecf8441..6595b5ba40 100644
--- a/src/common/bit_field.h
+++ b/src/common/bit_field.h
@@ -32,6 +32,7 @@
 
 #pragma once
 
+#include <cstddef>
 #include <limits>
 #include <type_traits>
 
diff --git a/src/core/hle/hle.cpp b/src/core/hle/hle.cpp
index fdeb9a0285..cd0a400dcf 100644
--- a/src/core/hle/hle.cpp
+++ b/src/core/hle/hle.cpp
@@ -10,7 +10,6 @@
 #include "core/hle/hle.h"
 #include "core/hle/config_mem.h"
 #include "core/hle/shared_page.h"
-#include "core/hle/kernel/thread.h"
 #include "core/hle/service/service.h"
 
 ////////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp
index 20e11da164..5711c0405c 100644
--- a/src/core/hle/kernel/kernel.cpp
+++ b/src/core/hle/kernel/kernel.cpp
@@ -7,8 +7,6 @@
 #include "common/assert.h"
 #include "common/logging/log.h"
 
-#include "core/arm/arm_interface.h"
-#include "core/core.h"
 #include "core/hle/kernel/kernel.h"
 #include "core/hle/kernel/resource_limit.h"
 #include "core/hle/kernel/process.h"
diff --git a/src/core/hle/kernel/kernel.h b/src/core/hle/kernel/kernel.h
index 64595f7581..b29260b5df 100644
--- a/src/core/hle/kernel/kernel.h
+++ b/src/core/hle/kernel/kernel.h
@@ -4,10 +4,11 @@
 
 #pragma once
 
-#include <boost/intrusive_ptr.hpp>
+#include <boost/smart_ptr/intrusive_ptr.hpp>
 
+#include <algorithm>
 #include <array>
-#include <memory>
+#include <cstddef>
 #include <string>
 #include <vector>
 
@@ -16,8 +17,6 @@
 #include "core/hle/hle.h"
 #include "core/hle/result.h"
 
-struct ApplicationInfo;
-
 namespace Kernel {
 
 class Thread;
diff --git a/src/core/hle/kernel/session.h b/src/core/hle/kernel/session.h
index 257da9105b..adaffcafe8 100644
--- a/src/core/hle/kernel/session.h
+++ b/src/core/hle/kernel/session.h
@@ -4,8 +4,14 @@
 
 #pragma once
 
+#include <string>
+
+#include "common/assert.h"
+#include "common/common_types.h"
+
 #include "core/hle/kernel/kernel.h"
 #include "core/hle/kernel/thread.h"
+#include "core/hle/result.h"
 #include "core/memory.h"
 
 namespace IPC {
diff --git a/src/core/hle/kernel/thread.h b/src/core/hle/kernel/thread.h
index b8160bb2c7..1ff1d9b979 100644
--- a/src/core/hle/kernel/thread.h
+++ b/src/core/hle/kernel/thread.h
@@ -13,6 +13,7 @@
 
 #include "core/core.h"
 
+#include "core/hle/hle.h"
 #include "core/hle/kernel/kernel.h"
 #include "core/hle/result.h"
 
diff --git a/src/core/hle/result.h b/src/core/hle/result.h
index ce633d8415..cb2d681e00 100644
--- a/src/core/hle/result.h
+++ b/src/core/hle/result.h
@@ -4,7 +4,7 @@
 
 #pragma once
 
-#include <cstddef>
+#include <new>
 #include <type_traits>
 #include <utility>
 
diff --git a/src/core/hle/service/hid/hid.h b/src/core/hle/service/hid/hid.h
index 68e2bcee02..d50d479f81 100644
--- a/src/core/hle/service/hid/hid.h
+++ b/src/core/hle/service/hid/hid.h
@@ -6,16 +6,18 @@
 
 #include <array>
 
-#include "core/hle/kernel/kernel.h"
-#include "core/hle/service/service.h"
-#include "common/bit_field.h"
+#ifndef _MSC_VER
+#include <cstddef>
+#endif
 
-namespace Kernel {
-    class SharedMemory;
-    class Event;
-}
+#include "common/bit_field.h"
+#include "common/common_funcs.h"
+#include "common/common_types.h"
 
 namespace Service {
+
+class Interface;
+
 namespace HID {
 
 /**
diff --git a/src/core/hle/service/service.h b/src/core/hle/service/service.h
index 77bfb9ff13..af299ac219 100644
--- a/src/core/hle/service/service.h
+++ b/src/core/hle/service/service.h
@@ -11,7 +11,6 @@
 
 #include "common/common_types.h"
 
-#include "core/hle/kernel/kernel.h"
 #include "core/hle/kernel/session.h"
 
 ////////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/core/loader/loader.cpp b/src/core/loader/loader.cpp
index 6e608a8589..2e450fce4d 100644
--- a/src/core/loader/loader.cpp
+++ b/src/core/loader/loader.cpp
@@ -2,6 +2,7 @@
 // Licensed under GPLv2 or any later version
 // Refer to the license.txt file included.
 
+#include <memory>
 #include <string>
 
 #include "common/logging/log.h"
diff --git a/src/core/loader/loader.h b/src/core/loader/loader.h
index 87e16fb986..1c33b1c161 100644
--- a/src/core/loader/loader.h
+++ b/src/core/loader/loader.h
@@ -4,6 +4,7 @@
 
 #pragma once
 
+#include <memory>
 #include <vector>
 
 #include "common/common_types.h"
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp
index 518f79331e..2edc38ac53 100644
--- a/src/video_core/renderer_opengl/gl_rasterizer.cpp
+++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp
@@ -2,10 +2,14 @@
 // Licensed under GPLv2 or any later version
 // Refer to the license.txt file included.
 
+#include <cstring>
+#include <memory>
+
 #include "common/color.h"
 
-#include "core/settings.h"
 #include "core/hw/gpu.h"
+#include "core/memory.h"
+#include "core/settings.h"
 
 #include "video_core/pica.h"
 #include "video_core/utils.h"
@@ -16,8 +20,6 @@
 
 #include "generated/gl_3_2_core.h"
 
-#include <memory>
-
 static bool IsPassThroughTevStage(const Pica::Regs::TevStageConfig& stage) {
     return (stage.color_op == Pica::Regs::TevStageConfig::Operation::Replace &&
             stage.alpha_op == Pica::Regs::TevStageConfig::Operation::Replace &&
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.h b/src/video_core/renderer_opengl/gl_rasterizer.h
index d7d422b1f2..911ae8c361 100644
--- a/src/video_core/renderer_opengl/gl_rasterizer.h
+++ b/src/video_core/renderer_opengl/gl_rasterizer.h
@@ -4,6 +4,10 @@
 
 #pragma once
 
+#include <vector>
+
+#include "common/common_types.h"
+
 #include "video_core/hwrasterizer_base.h"
 
 #include "gl_state.h"

From 1775adc34c588c8c37ef8c07dc0c3ff2358d5a31 Mon Sep 17 00:00:00 2001
From: Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
Date: Sun, 21 Jun 2015 13:52:08 +0100
Subject: [PATCH 12/19] Common: Remove unused ROUND_UP_POW2 macro.

---
 src/common/common_funcs.h | 7 -------
 1 file changed, 7 deletions(-)

diff --git a/src/common/common_funcs.h b/src/common/common_funcs.h
index cc74a228ea..c4fb3d9ccb 100644
--- a/src/common/common_funcs.h
+++ b/src/common/common_funcs.h
@@ -6,13 +6,6 @@
 
 #include "common_types.h"
 
-#define b2(x)   (   (x) | (   (x) >> 1) )
-#define b4(x)   ( b2(x) | ( b2(x) >> 2) )
-#define b8(x)   ( b4(x) | ( b4(x) >> 4) )
-#define b16(x)  ( b8(x) | ( b8(x) >> 8) )
-#define b32(x)  (b16(x) | (b16(x) >>16) )
-#define ROUND_UP_POW2(x)    (b32(x - 1) + 1)
-
 #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
 
 /// Textually concatenates two tokens. The double-expansion is required by the C preprocessor.

From 22ae87530b11226895a6a3682b9e75c5f5b9045d Mon Sep 17 00:00:00 2001
From: Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
Date: Sun, 21 Jun 2015 14:02:11 +0100
Subject: [PATCH 13/19] Common: Cleanup emu_window includes.

---
 src/common/emu_window.cpp      |  6 ++++++
 src/common/emu_window.h        | 12 +++++++++---
 src/video_core/pica.h          |  6 +++---
 src/video_core/vertex_shader.h |  5 ++---
 src/video_core/video_core.h    |  7 +++----
 5 files changed, 23 insertions(+), 13 deletions(-)

diff --git a/src/common/emu_window.cpp b/src/common/emu_window.cpp
index 43facb85c0..b69b05cb9a 100644
--- a/src/common/emu_window.cpp
+++ b/src/common/emu_window.cpp
@@ -2,6 +2,12 @@
 // Licensed under GPLv2 or any later version
 // Refer to the license.txt file included.
 
+#include <algorithm>
+#include <cmath>
+
+#include "common/assert.h"
+#include "common/key_map.h"
+
 #include "emu_window.h"
 #include "video_core/video_core.h"
 
diff --git a/src/common/emu_window.h b/src/common/emu_window.h
index 8eca6b5d5d..a0ae4c9fad 100644
--- a/src/common/emu_window.h
+++ b/src/common/emu_window.h
@@ -4,11 +4,17 @@
 
 #pragma once
 
+#include <tuple>
+#include <utility>
+
 #include "common/common_types.h"
-#include "common/key_map.h"
 #include "common/math_util.h"
-#include "common/scm_rev.h"
-#include "common/string_util.h"
+
+#include "core/hle/service/hid/hid.h"
+
+namespace KeyMap {
+struct HostDeviceKey;
+}
 
 /**
  * Abstraction class used to provide an interface between emulation code and the frontend
diff --git a/src/video_core/pica.h b/src/video_core/pica.h
index 9628a75896..be8ff7590c 100644
--- a/src/video_core/pica.h
+++ b/src/video_core/pica.h
@@ -5,10 +5,10 @@
 #pragma once
 
 #include <array>
+#include <cmath>
 #include <cstddef>
-#include <initializer_list>
 #include <map>
-#include <vector>
+#include <string>
 
 #include "common/assert.h"
 #include "common/bit_field.h"
@@ -1014,7 +1014,7 @@ struct float24 {
             u32 mantissa = hex & 0xFFFF;
             u32 exponent = (hex >> 16) & 0x7F;
             u32 sign = hex >> 23;
-            ret.value = powf(2.0f, (float)exponent-63.0f) * (1.0f + mantissa * powf(2.0f, -16.f));
+            ret.value = std::pow(2.0f, (float)exponent-63.0f) * (1.0f + mantissa * std::pow(2.0f, -16.f));
             if (sign)
                 ret.value = -ret.value;
         }
diff --git a/src/video_core/vertex_shader.h b/src/video_core/vertex_shader.h
index 7471a6de8e..c997e6a779 100644
--- a/src/video_core/vertex_shader.h
+++ b/src/video_core/vertex_shader.h
@@ -4,11 +4,10 @@
 
 #pragma once
 
-#include <initializer_list>
+#include <type_traits>
 
-#include <common/common_types.h>
+#include "common/vector_math.h"
 
-#include "math.h"
 #include "pica.h"
 
 namespace Pica {
diff --git a/src/video_core/video_core.h b/src/video_core/video_core.h
index 3f24df7bd6..14b33c9ddf 100644
--- a/src/video_core/video_core.h
+++ b/src/video_core/video_core.h
@@ -4,12 +4,11 @@
 
 #pragma once
 
-#include "common/emu_window.h"
-
-#include "renderer_base.h"
-
 #include <atomic>
 
+class EmuWindow;
+class RendererBase;
+
 ////////////////////////////////////////////////////////////////////////////////////////////////////
 // Video Core namespace
 

From 45c4781544624c85a8178c6ee445cfe6a4751910 Mon Sep 17 00:00:00 2001
From: Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
Date: Sun, 21 Jun 2015 14:58:59 +0100
Subject: [PATCH 14/19] CitraQt: Cleanup includes.

---
 src/citra_qt/bootmanager.cpp               |  4 ++++
 src/citra_qt/config.cpp                    |  2 +-
 src/citra_qt/config.h                      |  4 ++--
 src/citra_qt/debugger/disassembler.cpp     |  2 ++
 src/citra_qt/hotkeys.cpp                   |  5 ++++-
 src/citra_qt/hotkeys.h                     |  4 ++--
 src/citra_qt/main.cpp                      |  2 ++
 src/common/logging/filter.h                |  1 +
 src/common/profiler_reporting.h            |  1 -
 src/core/file_sys/ivfc_archive.cpp         |  1 +
 src/core/hle/service/gsp_gpu.cpp           |  4 +++-
 src/core/hle/service/hid/hid.cpp           |  1 +
 src/core/hle/service/y2r_u.cpp             |  1 +
 src/core/hw/gpu.cpp                        |  1 +
 src/core/loader/elf.cpp                    |  3 ++-
 src/core/loader/loader.h                   |  7 ++++++-
 src/core/loader/ncch.cpp                   |  3 ++-
 src/video_core/command_processor.cpp       | 16 +++++++++-------
 src/video_core/debug_utils/debug_utils.cpp |  1 +
 src/video_core/renderer_base.h             |  2 ++
 20 files changed, 47 insertions(+), 18 deletions(-)

diff --git a/src/citra_qt/bootmanager.cpp b/src/citra_qt/bootmanager.cpp
index 3db09c65b9..9d36364ddb 100644
--- a/src/citra_qt/bootmanager.cpp
+++ b/src/citra_qt/bootmanager.cpp
@@ -11,6 +11,10 @@
 #include "bootmanager.h"
 #include "main.h"
 
+#include "common/string_util.h"
+#include "common/scm_rev.h"
+#include "common/key_map.h"
+
 #include "core/core.h"
 #include "core/settings.h"
 #include "core/system.h"
diff --git a/src/citra_qt/config.cpp b/src/citra_qt/config.cpp
index 2a9af1f38b..5c056446e4 100644
--- a/src/citra_qt/config.cpp
+++ b/src/citra_qt/config.cpp
@@ -2,11 +2,11 @@
 // Licensed under GPLv2 or any later version
 // Refer to the license.txt file included.
 
+#include <QSettings>
 #include <QString>
 #include <QStringList>
 
 #include "core/settings.h"
-#include "core/core.h"
 #include "common/file_util.h"
 
 #include "config.h"
diff --git a/src/citra_qt/config.h b/src/citra_qt/config.h
index 4485cae735..dd0b2ef0b4 100644
--- a/src/citra_qt/config.h
+++ b/src/citra_qt/config.h
@@ -4,9 +4,9 @@
 
 #pragma once
 
-#include <QSettings>
+#include <string>
 
-#include "common/common_types.h"
+class QSettings;
 
 class Config {
     QSettings* qt_config;
diff --git a/src/citra_qt/debugger/disassembler.cpp b/src/citra_qt/debugger/disassembler.cpp
index e99ec1b308..b41c40a0e2 100644
--- a/src/citra_qt/debugger/disassembler.cpp
+++ b/src/citra_qt/debugger/disassembler.cpp
@@ -2,6 +2,8 @@
 // Licensed under GPLv2 or any later version
 // Refer to the license.txt file included.
 
+#include <QShortcut>
+
 #include "disassembler.h"
 
 #include "../bootmanager.h"
diff --git a/src/citra_qt/hotkeys.cpp b/src/citra_qt/hotkeys.cpp
index 322c25c9ee..5ed6cf0b14 100644
--- a/src/citra_qt/hotkeys.cpp
+++ b/src/citra_qt/hotkeys.cpp
@@ -2,10 +2,13 @@
 // Licensed under GPLv2 or any later version
 // Refer to the license.txt file included.
 
+#include <map>
+
 #include <QKeySequence>
 #include <QSettings>
+#include <QShortcut>
+
 #include "hotkeys.h"
-#include <map>
 
 struct Hotkey
 {
diff --git a/src/citra_qt/hotkeys.h b/src/citra_qt/hotkeys.h
index 75c7cc6251..2317f8188b 100644
--- a/src/citra_qt/hotkeys.h
+++ b/src/citra_qt/hotkeys.h
@@ -2,12 +2,12 @@
 // Licensed under GPLv2 or any later version
 // Refer to the license.txt file included.
 
-#include <QShortcut>
-#include <QDialog>
 #include "ui_hotkeys.h"
 
+class QDialog;
 class QKeySequence;
 class QSettings;
+class QShortcut;
 
 /**
  * Register a hotkey.
diff --git a/src/citra_qt/main.cpp b/src/citra_qt/main.cpp
index 43b80a34a9..d23bafafc1 100644
--- a/src/citra_qt/main.cpp
+++ b/src/citra_qt/main.cpp
@@ -10,12 +10,14 @@
 #include "qhexedit.h"
 #include "main.h"
 
+#include "common/string_util.h"
 #include "common/logging/text_formatter.h"
 #include "common/logging/log.h"
 #include "common/logging/backend.h"
 #include "common/logging/filter.h"
 #include "common/make_unique.h"
 #include "common/platform.h"
+#include "common/scm_rev.h"
 #include "common/scope_exit.h"
 
 #include "bootmanager.h"
diff --git a/src/common/logging/filter.h b/src/common/logging/filter.h
index 0b71ea3b21..a2b4eca430 100644
--- a/src/common/logging/filter.h
+++ b/src/common/logging/filter.h
@@ -5,6 +5,7 @@
 #pragma once
 
 #include <array>
+#include <cstddef>
 #include <string>
 
 #include "common/logging/log.h"
diff --git a/src/common/profiler_reporting.h b/src/common/profiler_reporting.h
index ab60cfb16c..df98e05b78 100644
--- a/src/common/profiler_reporting.h
+++ b/src/common/profiler_reporting.h
@@ -4,7 +4,6 @@
 
 #pragma once
 
-#include <chrono>
 #include <cstddef>
 #include <vector>
 
diff --git a/src/core/file_sys/ivfc_archive.cpp b/src/core/file_sys/ivfc_archive.cpp
index 2d2509d16d..d11d42bb97 100644
--- a/src/core/file_sys/ivfc_archive.cpp
+++ b/src/core/file_sys/ivfc_archive.cpp
@@ -2,6 +2,7 @@
 // Licensed under GPLv2 or any later version
 // Refer to the license.txt file included.
 
+#include <cstring>
 #include <memory>
 
 #include "common/common_types.h"
diff --git a/src/core/hle/service/gsp_gpu.cpp b/src/core/hle/service/gsp_gpu.cpp
index 4b0b4229d9..f56bbe50f3 100644
--- a/src/core/hle/service/gsp_gpu.cpp
+++ b/src/core/hle/service/gsp_gpu.cpp
@@ -9,14 +9,16 @@
 #include "core/hle/kernel/event.h"
 #include "core/hle/kernel/shared_memory.h"
 #include "core/hle/result.h"
-#include "gsp_gpu.h"
 #include "core/hw/hw.h"
 #include "core/hw/gpu.h"
 #include "core/hw/lcd.h"
 
 #include "video_core/gpu_debugger.h"
+#include "video_core/renderer_base.h"
 #include "video_core/video_core.h"
 
+#include "gsp_gpu.h"
+
 // Main graphics debugger object - TODO: Here is probably not the best place for this
 GraphicsDebugger g_debugger;
 
diff --git a/src/core/hle/service/hid/hid.cpp b/src/core/hle/service/hid/hid.cpp
index c7c1bb5ab4..70caa7d802 100644
--- a/src/core/hle/service/hid/hid.cpp
+++ b/src/core/hle/service/hid/hid.cpp
@@ -3,6 +3,7 @@
 // Refer to the license.txt file included.
 
 #include "common/logging/log.h"
+#include "common/emu_window.h"
 
 #include "core/hle/service/service.h"
 #include "core/hle/service/hid/hid.h"
diff --git a/src/core/hle/service/y2r_u.cpp b/src/core/hle/service/y2r_u.cpp
index ac1967da8b..e121a54e33 100644
--- a/src/core/hle/service/y2r_u.cpp
+++ b/src/core/hle/service/y2r_u.cpp
@@ -12,6 +12,7 @@
 #include "core/hw/y2r.h"
 #include "core/mem_map.h"
 
+#include "video_core/renderer_base.h"
 #include "video_core/utils.h"
 #include "video_core/video_core.h"
 
diff --git a/src/core/hw/gpu.cpp b/src/core/hw/gpu.cpp
index 7471def578..bdceb6984e 100644
--- a/src/core/hw/gpu.cpp
+++ b/src/core/hw/gpu.cpp
@@ -21,6 +21,7 @@
 #include "core/hw/gpu.h"
 
 #include "video_core/command_processor.h"
+#include "video_core/renderer_base.h"
 #include "video_core/utils.h"
 #include "video_core/video_core.h"
 
diff --git a/src/core/loader/elf.cpp b/src/core/loader/elf.cpp
index f00753a79d..a7eea78aaf 100644
--- a/src/core/loader/elf.cpp
+++ b/src/core/loader/elf.cpp
@@ -2,6 +2,7 @@
 // Licensed under GPLv2 or any later version
 // Refer to the license.txt file included.
 
+#include <cstring>
 #include <string>
 #include <memory>
 
@@ -10,7 +11,7 @@
 #include "common/logging/log.h"
 #include "common/symbols.h"
 
-#include "core/hle/kernel/kernel.h"
+#include "core/hle/kernel/process.h"
 #include "core/hle/kernel/resource_limit.h"
 #include "core/loader/elf.h"
 #include "core/memory.h"
diff --git a/src/core/loader/loader.h b/src/core/loader/loader.h
index 1c33b1c161..52bbf35b89 100644
--- a/src/core/loader/loader.h
+++ b/src/core/loader/loader.h
@@ -4,13 +4,18 @@
 
 #pragma once
 
+#include <algorithm>
+#include <initializer_list>
 #include <memory>
+#include <string>
 #include <vector>
 
 #include "common/common_types.h"
 #include "common/file_util.h"
 
-#include "core/hle/kernel/process.h"
+namespace Kernel {
+struct AddressMapping;
+}
 
 ////////////////////////////////////////////////////////////////////////////////////////////////////
 // Loader namespace
diff --git a/src/core/loader/ncch.cpp b/src/core/loader/ncch.cpp
index 08993c4fae..a8f8f78b76 100644
--- a/src/core/loader/ncch.cpp
+++ b/src/core/loader/ncch.cpp
@@ -3,6 +3,7 @@
 // Refer to the license.txt file included.
 
 #include <algorithm>
+#include <cstring>
 #include <memory>
 
 #include "common/logging/log.h"
@@ -10,7 +11,7 @@
 #include "common/string_util.h"
 #include "common/swap.h"
 
-#include "core/hle/kernel/kernel.h"
+#include "core/hle/kernel/process.h"
 #include "core/hle/kernel/resource_limit.h"
 #include "core/loader/ncch.h"
 #include "core/memory.h"
diff --git a/src/video_core/command_processor.cpp b/src/video_core/command_processor.cpp
index b46fadd9f1..110caec76e 100644
--- a/src/video_core/command_processor.cpp
+++ b/src/video_core/command_processor.cpp
@@ -6,19 +6,21 @@
 
 #include "common/profiler.h"
 
-#include "clipper.h"
-#include "command_processor.h"
-#include "math.h"
-#include "pica.h"
-#include "primitive_assembly.h"
-#include "vertex_shader.h"
-#include "video_core.h"
 #include "core/hle/service/gsp_gpu.h"
 #include "core/hw/gpu.h"
 #include "core/settings.h"
 
 #include "debug_utils/debug_utils.h"
 
+#include "clipper.h"
+#include "command_processor.h"
+#include "math.h"
+#include "pica.h"
+#include "primitive_assembly.h"
+#include "renderer_base.h"
+#include "vertex_shader.h"
+#include "video_core.h"
+
 namespace Pica {
 
 namespace CommandProcessor {
diff --git a/src/video_core/debug_utils/debug_utils.cpp b/src/video_core/debug_utils/debug_utils.cpp
index 7b8ab72b6e..d24c0f11e2 100644
--- a/src/video_core/debug_utils/debug_utils.cpp
+++ b/src/video_core/debug_utils/debug_utils.cpp
@@ -23,6 +23,7 @@
 #include "common/vector_math.h"
 
 #include "video_core/pica.h"
+#include "video_core/renderer_base.h"
 #include "video_core/utils.h"
 #include "video_core/video_core.h"
 
diff --git a/src/video_core/renderer_base.h b/src/video_core/renderer_base.h
index 5757ac75d6..fbbf17db45 100644
--- a/src/video_core/renderer_base.h
+++ b/src/video_core/renderer_base.h
@@ -4,6 +4,8 @@
 
 #pragma once
 
+#include <memory>
+
 #include "common/common_types.h"
 
 #include "video_core/hwrasterizer_base.h"

From aea15f5c731b325be48ea4900ae3eca341ac03cd Mon Sep 17 00:00:00 2001
From: Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
Date: Sun, 21 Jun 2015 15:11:32 +0100
Subject: [PATCH 15/19] Core: Cleanup core includes.

---
 src/common/chunk_file.h            | 3 ++-
 src/core/arm/dyncom/arm_dyncom.h   | 5 +++++
 src/core/core.cpp                  | 3 ---
 src/core/core_timing.cpp           | 3 +--
 src/core/hle/kernel/vm_manager.cpp | 2 ++
 src/core/hle/kernel/vm_manager.h   | 1 -
 src/core/hle/shared_page.cpp       | 6 ------
 src/core/hle/shared_page.h         | 3 +++
 src/core/mem_map.cpp               | 5 +++--
 9 files changed, 16 insertions(+), 15 deletions(-)

diff --git a/src/common/chunk_file.h b/src/common/chunk_file.h
index ee9f3d7c09..8be0b11094 100644
--- a/src/common/chunk_file.h
+++ b/src/common/chunk_file.h
@@ -33,10 +33,11 @@
 #include <set>
 #include <string>
 #include <type_traits>
+#include <utility>
 #include <vector>
 
+#include "common/assert.h"
 #include "common/common_types.h"
-#include "common/file_util.h"
 #include "common/logging/log.h"
 
 template <class T>
diff --git a/src/core/arm/dyncom/arm_dyncom.h b/src/core/arm/dyncom/arm_dyncom.h
index 2488c879c0..cc93557222 100644
--- a/src/core/arm/dyncom/arm_dyncom.h
+++ b/src/core/arm/dyncom/arm_dyncom.h
@@ -10,6 +10,11 @@
 
 #include "core/arm/arm_interface.h"
 #include "core/arm/skyeye_common/armdefs.h"
+#include "core/arm/skyeye_common/arm_regformat.h"
+
+namespace Core {
+struct ThreadContext;
+}
 
 class ARM_DynCom final : virtual public ARM_Interface {
 public:
diff --git a/src/core/core.cpp b/src/core/core.cpp
index 79038cd529..dddc16708e 100644
--- a/src/core/core.cpp
+++ b/src/core/core.cpp
@@ -2,15 +2,12 @@
 // Licensed under GPLv2 or any later version
 // Refer to the license.txt file included.
 
-#include "common/common_types.h"
 #include "common/logging/log.h"
 
 #include "core/core.h"
 #include "core/core_timing.h"
 
-#include "core/settings.h"
 #include "core/arm/arm_interface.h"
-#include "core/arm/disassembler/arm_disasm.h"
 #include "core/arm/dyncom/arm_dyncom.h"
 #include "core/hle/hle.h"
 #include "core/hle/kernel/thread.h"
diff --git a/src/core/core_timing.cpp b/src/core/core_timing.cpp
index 0eb717c8dd..72006a53e9 100644
--- a/src/core/core_timing.cpp
+++ b/src/core/core_timing.cpp
@@ -3,12 +3,11 @@
 // Refer to the license.txt file included.
 
 #include <atomic>
-#include <cstdio>
 #include <mutex>
 #include <vector>
 
-#include "common/assert.h"
 #include "common/chunk_file.h"
+#include "common/logging/log.h"
 #include "common/string_util.h"
 
 #include "core/arm/arm_interface.h"
diff --git a/src/core/hle/kernel/vm_manager.cpp b/src/core/hle/kernel/vm_manager.cpp
index b2dd21542f..ec437cd61e 100644
--- a/src/core/hle/kernel/vm_manager.cpp
+++ b/src/core/hle/kernel/vm_manager.cpp
@@ -2,6 +2,8 @@
 // Licensed under GPLv2 or any later version
 // Refer to the license.txt file included.
 
+#include <iterator>
+
 #include "common/assert.h"
 
 #include "core/hle/kernel/vm_manager.h"
diff --git a/src/core/hle/kernel/vm_manager.h b/src/core/hle/kernel/vm_manager.h
index 22b7246039..271e2333e5 100644
--- a/src/core/hle/kernel/vm_manager.h
+++ b/src/core/hle/kernel/vm_manager.h
@@ -6,7 +6,6 @@
 
 #include <map>
 #include <memory>
-#include <string>
 #include <vector>
 
 #include "common/common_types.h"
diff --git a/src/core/hle/shared_page.cpp b/src/core/hle/shared_page.cpp
index 4014eee98e..26d87c7e2f 100644
--- a/src/core/hle/shared_page.cpp
+++ b/src/core/hle/shared_page.cpp
@@ -4,12 +4,6 @@
 
 #include <cstring>
 
-#include "common/common_types.h"
-#include "common/common_funcs.h"
-
-#include "core/core.h"
-#include "core/memory.h"
-#include "core/hle/config_mem.h"
 #include "core/hle/shared_page.h"
 
 ////////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/core/hle/shared_page.h b/src/core/hle/shared_page.h
index fd2ab66a29..db6a5340be 100644
--- a/src/core/hle/shared_page.h
+++ b/src/core/hle/shared_page.h
@@ -10,9 +10,12 @@
  * write access, according to 3dbrew; this is not emulated)
  */
 
+#include "common/common_funcs.h"
 #include "common/common_types.h"
 #include "common/swap.h"
 
+#include "core/memory.h"
+
 ////////////////////////////////////////////////////////////////////////////////////////////////////
 
 namespace SharedPage {
diff --git a/src/core/mem_map.cpp b/src/core/mem_map.cpp
index bf814b945a..d8cae50dd8 100644
--- a/src/core/mem_map.cpp
+++ b/src/core/mem_map.cpp
@@ -3,13 +3,14 @@
 // Refer to the license.txt file included.
 
 #include <map>
+#include <memory>
+#include <utility>
+#include <vector>
 
 #include "common/common_types.h"
 #include "common/logging/log.h"
 
 #include "core/hle/config_mem.h"
-#include "core/hle/kernel/kernel.h"
-#include "core/hle/kernel/shared_memory.h"
 #include "core/hle/kernel/vm_manager.h"
 #include "core/hle/result.h"
 #include "core/hle/shared_page.h"

From e5fcabdd698b7c5e8fe8c0903ed2b3babcb75a17 Mon Sep 17 00:00:00 2001
From: Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
Date: Sun, 21 Jun 2015 15:44:11 +0100
Subject: [PATCH 16/19] Core: Cleanup file_sys includes.

---
 src/common/make_unique.h                     |  1 +
 src/core/file_sys/archive_backend.cpp        |  2 ++
 src/core/file_sys/archive_extsavedata.cpp    |  4 ++--
 src/core/file_sys/archive_extsavedata.h      |  7 +++++--
 src/core/file_sys/archive_romfs.cpp          |  3 ++-
 src/core/file_sys/archive_romfs.h            |  4 +++-
 src/core/file_sys/archive_savedata.cpp       |  3 +--
 src/core/file_sys/archive_savedata.h         |  7 ++++---
 src/core/file_sys/archive_savedatacheck.cpp  |  5 +++++
 src/core/file_sys/archive_savedatacheck.h    |  9 ++++-----
 src/core/file_sys/archive_sdmc.cpp           |  3 +--
 src/core/file_sys/archive_sdmc.h             |  7 ++++---
 src/core/file_sys/archive_systemsavedata.cpp |  5 +++--
 src/core/file_sys/archive_systemsavedata.h   |  7 +++++--
 src/core/file_sys/disk_archive.cpp           |  4 ++--
 src/core/file_sys/disk_archive.h             |  7 ++++++-
 src/core/file_sys/ivfc_archive.cpp           |  1 -
 src/core/file_sys/ivfc_archive.h             |  4 +++-
 src/core/hle/kernel/process.h                |  3 ++-
 src/core/hle/service/fs/archive.cpp          | 10 ++++++++--
 src/core/hle/service/fs/archive.h            | 13 ++++++++-----
 src/core/hle/service/service.h               |  2 ++
 22 files changed, 73 insertions(+), 38 deletions(-)

diff --git a/src/common/make_unique.h b/src/common/make_unique.h
index 2a7b764124..f6e7f017cd 100644
--- a/src/common/make_unique.h
+++ b/src/common/make_unique.h
@@ -4,6 +4,7 @@
 
 #pragma once
 
+#include <algorithm>
 #include <memory>
 
 namespace Common {
diff --git a/src/core/file_sys/archive_backend.cpp b/src/core/file_sys/archive_backend.cpp
index 45a559ce87..3f81447dfd 100644
--- a/src/core/file_sys/archive_backend.cpp
+++ b/src/core/file_sys/archive_backend.cpp
@@ -2,6 +2,8 @@
 // Licensed under GPLv2 or any later version
 // Refer to the license.txt file included.
 
+#include <cstddef>
+#include <iomanip>
 #include <sstream>
 
 #include "common/logging/log.h"
diff --git a/src/core/file_sys/archive_extsavedata.cpp b/src/core/file_sys/archive_extsavedata.cpp
index ce26e6bee5..92dad8e6f1 100644
--- a/src/core/file_sys/archive_extsavedata.cpp
+++ b/src/core/file_sys/archive_extsavedata.cpp
@@ -2,7 +2,8 @@
 // Licensed under GPLv2 or any later version
 // Refer to the license.txt file included.
 
-#include <sys/stat.h>
+#include <algorithm>
+#include <vector>
 
 #include "common/common_types.h"
 #include "common/file_util.h"
@@ -13,7 +14,6 @@
 #include "core/file_sys/archive_extsavedata.h"
 #include "core/file_sys/disk_archive.h"
 #include "core/hle/service/fs/archive.h"
-#include "core/settings.h"
 
 ////////////////////////////////////////////////////////////////////////////////////////////////////
 // FileSys namespace
diff --git a/src/core/file_sys/archive_extsavedata.h b/src/core/file_sys/archive_extsavedata.h
index ef0b27bdee..ec8d770fc0 100644
--- a/src/core/file_sys/archive_extsavedata.h
+++ b/src/core/file_sys/archive_extsavedata.h
@@ -4,10 +4,13 @@
 
 #pragma once
 
+#include <memory>
+#include <string>
+
 #include "common/common_types.h"
 
-#include "core/file_sys/disk_archive.h"
-#include "core/loader/loader.h"
+#include "core/file_sys/archive_backend.h"
+#include "core/hle/result.h"
 
 ////////////////////////////////////////////////////////////////////////////////////////////////////
 // FileSys namespace
diff --git a/src/core/file_sys/archive_romfs.cpp b/src/core/file_sys/archive_romfs.cpp
index d4a12ed103..c1e45dfeb2 100644
--- a/src/core/file_sys/archive_romfs.cpp
+++ b/src/core/file_sys/archive_romfs.cpp
@@ -2,14 +2,15 @@
 // Licensed under GPLv2 or any later version
 // Refer to the license.txt file included.
 
+#include <algorithm>
 #include <memory>
 
 #include "common/common_types.h"
-#include "common/file_util.h"
 #include "common/logging/log.h"
 #include "common/make_unique.h"
 
 #include "core/file_sys/archive_romfs.h"
+#include "core/file_sys/ivfc_archive.h"
 
 ////////////////////////////////////////////////////////////////////////////////////////////////////
 // FileSys namespace
diff --git a/src/core/file_sys/archive_romfs.h b/src/core/file_sys/archive_romfs.h
index 409bc670aa..c69ff91c31 100644
--- a/src/core/file_sys/archive_romfs.h
+++ b/src/core/file_sys/archive_romfs.h
@@ -5,11 +5,13 @@
 #pragma once
 
 #include <memory>
+#include <string>
 #include <vector>
 
 #include "common/common_types.h"
 
-#include "core/file_sys/ivfc_archive.h"
+#include "core/file_sys/archive_backend.h"
+#include "core/hle/result.h"
 #include "core/loader/loader.h"
 
 ////////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/core/file_sys/archive_savedata.cpp b/src/core/file_sys/archive_savedata.cpp
index f8acec9771..98823aec33 100644
--- a/src/core/file_sys/archive_savedata.cpp
+++ b/src/core/file_sys/archive_savedata.cpp
@@ -2,7 +2,7 @@
 // Licensed under GPLv2 or any later version
 // Refer to the license.txt file included.
 
-#include <sys/stat.h>
+#include <algorithm>
 
 #include "common/common_types.h"
 #include "common/file_util.h"
@@ -14,7 +14,6 @@
 #include "core/file_sys/disk_archive.h"
 #include "core/hle/kernel/process.h"
 #include "core/hle/service/fs/archive.h"
-#include "core/settings.h"
 
 ////////////////////////////////////////////////////////////////////////////////////////////////////
 // FileSys namespace
diff --git a/src/core/file_sys/archive_savedata.h b/src/core/file_sys/archive_savedata.h
index db17afc92a..1f65297ddc 100644
--- a/src/core/file_sys/archive_savedata.h
+++ b/src/core/file_sys/archive_savedata.h
@@ -4,10 +4,11 @@
 
 #pragma once
 
-#include "common/common_types.h"
+#include <memory>
+#include <string>
 
-#include "core/file_sys/disk_archive.h"
-#include "core/loader/loader.h"
+#include "core/file_sys/archive_backend.h"
+#include "core/hle/result.h"
 
 ////////////////////////////////////////////////////////////////////////////////////////////////////
 // FileSys namespace
diff --git a/src/core/file_sys/archive_savedatacheck.cpp b/src/core/file_sys/archive_savedatacheck.cpp
index def85d4c38..dec838caee 100644
--- a/src/core/file_sys/archive_savedatacheck.cpp
+++ b/src/core/file_sys/archive_savedatacheck.cpp
@@ -2,12 +2,17 @@
 // Licensed under GPLv2 or any later version
 // Refer to the license.txt file included.
 
+#include <algorithm>
+#include <vector>
+
+#include "common/common_types.h"
 #include "common/file_util.h"
 #include "common/logging/log.h"
 #include "common/make_unique.h"
 #include "common/string_util.h"
 
 #include "core/file_sys/archive_savedatacheck.h"
+#include "core/file_sys/ivfc_archive.h"
 #include "core/hle/service/fs/archive.h"
 
 ////////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/core/file_sys/archive_savedatacheck.h b/src/core/file_sys/archive_savedatacheck.h
index f78a6f02ee..b14aefe8bc 100644
--- a/src/core/file_sys/archive_savedatacheck.h
+++ b/src/core/file_sys/archive_savedatacheck.h
@@ -4,12 +4,11 @@
 
 #pragma once
 
-#include <vector>
+#include <memory>
+#include <string>
 
-#include "common/common_types.h"
-
-#include "core/file_sys/ivfc_archive.h"
-#include "core/loader/loader.h"
+#include "core/file_sys/archive_backend.h"
+#include "core/hle/result.h"
 
 ////////////////////////////////////////////////////////////////////////////////////////////////////
 // FileSys namespace
diff --git a/src/core/file_sys/archive_sdmc.cpp b/src/core/file_sys/archive_sdmc.cpp
index c1234a1862..5c825f4296 100644
--- a/src/core/file_sys/archive_sdmc.cpp
+++ b/src/core/file_sys/archive_sdmc.cpp
@@ -2,9 +2,8 @@
 // Licensed under GPLv2 or any later version
 // Refer to the license.txt file included.
 
-#include <sys/stat.h>
+#include <algorithm>
 
-#include "common/common_types.h"
 #include "common/file_util.h"
 #include "common/logging/log.h"
 #include "common/make_unique.h"
diff --git a/src/core/file_sys/archive_sdmc.h b/src/core/file_sys/archive_sdmc.h
index 1becf6c0f2..10b273bdba 100644
--- a/src/core/file_sys/archive_sdmc.h
+++ b/src/core/file_sys/archive_sdmc.h
@@ -4,10 +4,11 @@
 
 #pragma once
 
-#include "common/common_types.h"
+#include <memory>
+#include <string>
 
-#include "core/file_sys/disk_archive.h"
-#include "core/loader/loader.h"
+#include "core/file_sys/archive_backend.h"
+#include "core/hle/result.h"
 
 ////////////////////////////////////////////////////////////////////////////////////////////////////
 // FileSys namespace
diff --git a/src/core/file_sys/archive_systemsavedata.cpp b/src/core/file_sys/archive_systemsavedata.cpp
index 9a9182afc9..896f895295 100644
--- a/src/core/file_sys/archive_systemsavedata.cpp
+++ b/src/core/file_sys/archive_systemsavedata.cpp
@@ -2,7 +2,8 @@
 // Licensed under GPLv2 or any later version
 // Refer to the license.txt file included.
 
-#include <sys/stat.h>
+#include <algorithm>
+#include <vector>
 
 #include "common/common_types.h"
 #include "common/file_util.h"
@@ -10,8 +11,8 @@
 #include "common/string_util.h"
 
 #include "core/file_sys/archive_systemsavedata.h"
+#include "core/file_sys/disk_archive.h"
 #include "core/hle/service/fs/archive.h"
-#include "core/settings.h"
 
 ////////////////////////////////////////////////////////////////////////////////////////////////////
 // FileSys namespace
diff --git a/src/core/file_sys/archive_systemsavedata.h b/src/core/file_sys/archive_systemsavedata.h
index 3431fed880..afc689848a 100644
--- a/src/core/file_sys/archive_systemsavedata.h
+++ b/src/core/file_sys/archive_systemsavedata.h
@@ -4,10 +4,13 @@
 
 #pragma once
 
+#include <memory>
+#include <string>
+
 #include "common/common_types.h"
 
-#include "core/file_sys/disk_archive.h"
-#include "core/loader/loader.h"
+#include "core/file_sys/archive_backend.h"
+#include "core/hle/result.h"
 
 ////////////////////////////////////////////////////////////////////////////////////////////////////
 // FileSys namespace
diff --git a/src/core/file_sys/disk_archive.cpp b/src/core/file_sys/disk_archive.cpp
index 9980cced10..85151a311b 100644
--- a/src/core/file_sys/disk_archive.cpp
+++ b/src/core/file_sys/disk_archive.cpp
@@ -2,7 +2,8 @@
 // Licensed under GPLv2 or any later version
 // Refer to the license.txt file included.
 
-#include <sys/stat.h>
+#include <algorithm>
+#include <cstdio>
 
 #include "common/common_types.h"
 #include "common/file_util.h"
@@ -10,7 +11,6 @@
 #include "common/make_unique.h"
 
 #include "core/file_sys/disk_archive.h"
-#include "core/settings.h"
 
 ////////////////////////////////////////////////////////////////////////////////////////////////////
 // FileSys namespace
diff --git a/src/core/file_sys/disk_archive.h b/src/core/file_sys/disk_archive.h
index a22d3837a4..5cfcddf6ca 100644
--- a/src/core/file_sys/disk_archive.h
+++ b/src/core/file_sys/disk_archive.h
@@ -4,13 +4,18 @@
 
 #pragma once
 
+#include <cstddef>
+#include <memory>
+#include <string>
+#include <vector>
+
 #include "common/common_types.h"
 #include "common/file_util.h"
 
 #include "core/file_sys/archive_backend.h"
 #include "core/file_sys/directory_backend.h"
 #include "core/file_sys/file_backend.h"
-#include "core/loader/loader.h"
+#include "core/hle/result.h"
 
 ////////////////////////////////////////////////////////////////////////////////////////////////////
 // FileSys namespace
diff --git a/src/core/file_sys/ivfc_archive.cpp b/src/core/file_sys/ivfc_archive.cpp
index d11d42bb97..c88b39bcd6 100644
--- a/src/core/file_sys/ivfc_archive.cpp
+++ b/src/core/file_sys/ivfc_archive.cpp
@@ -6,7 +6,6 @@
 #include <memory>
 
 #include "common/common_types.h"
-#include "common/file_util.h"
 #include "common/logging/log.h"
 #include "common/make_unique.h"
 
diff --git a/src/core/file_sys/ivfc_archive.h b/src/core/file_sys/ivfc_archive.h
index 10415798d5..1850b3b173 100644
--- a/src/core/file_sys/ivfc_archive.h
+++ b/src/core/file_sys/ivfc_archive.h
@@ -4,7 +4,9 @@
 
 #pragma once
 
+#include <cstddef>
 #include <memory>
+#include <string>
 #include <vector>
 
 #include "common/common_types.h"
@@ -12,7 +14,7 @@
 #include "core/file_sys/archive_backend.h"
 #include "core/file_sys/directory_backend.h"
 #include "core/file_sys/file_backend.h"
-#include "core/loader/loader.h"
+#include "core/hle/result.h"
 
 ////////////////////////////////////////////////////////////////////////////////////////////////////
 // FileSys namespace
diff --git a/src/core/hle/kernel/process.h b/src/core/hle/kernel/process.h
index 7b8a686106..674f5093ad 100644
--- a/src/core/hle/kernel/process.h
+++ b/src/core/hle/kernel/process.h
@@ -5,6 +5,8 @@
 #pragma once
 
 #include <bitset>
+#include <cstddef>
+#include <string>
 
 #include <boost/container/static_vector.hpp>
 
@@ -12,7 +14,6 @@
 #include "common/common_types.h"
 
 #include "core/hle/kernel/kernel.h"
-#include "core/hle/result.h"
 
 namespace Kernel {
 
diff --git a/src/core/hle/service/fs/archive.cpp b/src/core/hle/service/fs/archive.cpp
index 4e275cb13a..ba272f05f3 100644
--- a/src/core/hle/service/fs/archive.cpp
+++ b/src/core/hle/service/fs/archive.cpp
@@ -2,29 +2,35 @@
 // Licensed under GPLv2 or any later version
 // Refer to the license.txt file included.
 
+#include <cstddef>
+#include <system_error>
+#include <type_traits>
 #include <memory>
 #include <unordered_map>
+#include <utility>
 
 #include <boost/container/flat_map.hpp>
 
+#include "common/assert.h"
 #include "common/common_types.h"
 #include "common/file_util.h"
 #include "common/logging/log.h"
 #include "common/make_unique.h"
-#include "common/math_util.h"
 
 #include "core/file_sys/archive_backend.h"
 #include "core/file_sys/archive_extsavedata.h"
-#include "core/file_sys/archive_romfs.h"
 #include "core/file_sys/archive_savedata.h"
 #include "core/file_sys/archive_savedatacheck.h"
 #include "core/file_sys/archive_sdmc.h"
 #include "core/file_sys/archive_systemsavedata.h"
 #include "core/file_sys/directory_backend.h"
+#include "core/file_sys/file_backend.h"
+#include "core/hle/hle.h"
 #include "core/hle/service/service.h"
 #include "core/hle/service/fs/archive.h"
 #include "core/hle/service/fs/fs_user.h"
 #include "core/hle/result.h"
+#include "core/memory.h"
 
 // Specializes std::hash for ArchiveIdCode, so that we can use it in std::unordered_map.
 // Workaroung for libstdc++ bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60970
diff --git a/src/core/hle/service/fs/archive.h b/src/core/hle/service/fs/archive.h
index 357b6b0969..f611259537 100644
--- a/src/core/hle/service/fs/archive.h
+++ b/src/core/hle/service/fs/archive.h
@@ -4,22 +4,25 @@
 
 #pragma once
 
+#include <memory>
+#include <string>
+
 #include "common/common_types.h"
 
 #include "core/file_sys/archive_backend.h"
-#include "core/hle/kernel/kernel.h"
 #include "core/hle/kernel/session.h"
 #include "core/hle/result.h"
 
+namespace FileSys {
+class DirectoryBackend;
+class FileBackend;
+}
+
 /// The unique system identifier hash, also known as ID0
 extern const std::string SYSTEM_ID;
 /// The scrambled SD card CID, also known as ID1
 extern const std::string SDCARD_ID;
 
-namespace Kernel {
-    class Session;
-}
-
 namespace Service {
 namespace FS {
 
diff --git a/src/core/hle/service/service.h b/src/core/hle/service/service.h
index af299ac219..f311352120 100644
--- a/src/core/hle/service/service.h
+++ b/src/core/hle/service/service.h
@@ -4,6 +4,7 @@
 
 #pragma once
 
+#include <cstddef>
 #include <string>
 #include <unordered_map>
 
@@ -12,6 +13,7 @@
 #include "common/common_types.h"
 
 #include "core/hle/kernel/session.h"
+#include "core/hle/result.h"
 
 ////////////////////////////////////////////////////////////////////////////////////////////////////
 // Namespace Service

From f48b28ad271c6759868f55cc429e02098576857e Mon Sep 17 00:00:00 2001
From: Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
Date: Sun, 21 Jun 2015 17:47:21 +0100
Subject: [PATCH 17/19] Core, VideoCore: Replace or fix exit() calls.

---
 src/core/arm/skyeye_common/vfp/vfp.cpp            |  6 +++---
 src/core/arm/skyeye_common/vfp/vfpsingle.cpp      |  4 +++-
 .../renderer_opengl/renderer_opengl.cpp           | 15 +++++++++------
 3 files changed, 15 insertions(+), 10 deletions(-)

diff --git a/src/core/arm/skyeye_common/vfp/vfp.cpp b/src/core/arm/skyeye_common/vfp/vfp.cpp
index 571d6c2f27..bbe11f690c 100644
--- a/src/core/arm/skyeye_common/vfp/vfp.cpp
+++ b/src/core/arm/skyeye_common/vfp/vfp.cpp
@@ -20,6 +20,7 @@
 
 /* Note: this file handles interface with arm core and vfp registers */
 
+#include "common/common_funcs.h"
 #include "common/logging/log.h"
 
 #include "core/arm/skyeye_common/armdefs.h"
@@ -153,9 +154,8 @@ void vfp_raise_exceptions(ARMul_State* state, u32 exceptions, u32 inst, u32 fpsc
     LOG_TRACE(Core_ARM11, "VFP: raising exceptions %08x\n", exceptions);
 
     if (exceptions == VFP_EXCEPTION_ERROR) {
-        LOG_TRACE(Core_ARM11, "unhandled bounce %x\n", inst);
-        exit(-1);
-        return;
+        LOG_CRITICAL(Core_ARM11, "unhandled bounce %x\n", inst);
+        Crash();
     }
 
     /*
diff --git a/src/core/arm/skyeye_common/vfp/vfpsingle.cpp b/src/core/arm/skyeye_common/vfp/vfpsingle.cpp
index 5a655a6f20..e5d3392520 100644
--- a/src/core/arm/skyeye_common/vfp/vfpsingle.cpp
+++ b/src/core/arm/skyeye_common/vfp/vfpsingle.cpp
@@ -53,6 +53,8 @@
 
 #include <cinttypes>
 
+#include "common/common_funcs.h"
+#include "common/common_types.h"
 #include "common/logging/log.h"
 
 #include "core/arm/skyeye_common/vfp/vfp_helper.h"
@@ -1246,7 +1248,7 @@ u32 vfp_single_cpdo(ARMul_State* state, u32 inst, u32 fpscr)
 
     if (!fop->fn) {
         LOG_CRITICAL(Core_ARM11, "could not find single op %d, inst=0x%x@0x%x", FEXT_TO_IDX(inst), inst, state->Reg[15]);
-        exit(-1);
+        Crash();
         goto invalid;
     }
 
diff --git a/src/video_core/renderer_opengl/renderer_opengl.cpp b/src/video_core/renderer_opengl/renderer_opengl.cpp
index 3399ca1230..9799f74faf 100644
--- a/src/video_core/renderer_opengl/renderer_opengl.cpp
+++ b/src/video_core/renderer_opengl/renderer_opengl.cpp
@@ -2,23 +2,26 @@
 // Licensed under GPLv2 or any later version
 // Refer to the license.txt file included.
 
+#include <algorithm>
+#include <cstddef>
+#include <cstdlib>
+
+#include "common/assert.h"
+#include "common/emu_window.h"
+#include "common/logging/log.h"
+#include "common/profiler_reporting.h"
+
 #include "core/hw/gpu.h"
 #include "core/hw/hw.h"
 #include "core/hw/lcd.h"
 #include "core/memory.h"
 #include "core/settings.h"
 
-#include "common/emu_window.h"
-#include "common/logging/log.h"
-#include "common/profiler_reporting.h"
-
 #include "video_core/video_core.h"
 #include "video_core/renderer_opengl/renderer_opengl.h"
 #include "video_core/renderer_opengl/gl_shader_util.h"
 #include "video_core/renderer_opengl/gl_shaders.h"
 
-#include <algorithm>
-
 /**
  * Vertex structure that the drawn screen rectangles are composed of.
  */

From 7b746914b929df4ed6aacaa13af8e35815be0bf1 Mon Sep 17 00:00:00 2001
From: Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
Date: Sun, 21 Jun 2015 18:14:20 +0100
Subject: [PATCH 18/19] Core: Cleanup soc:U includes.

---
 src/core/hle/service/soc_u.cpp | 58 +++++++++++++++++++---------------
 src/core/hle/service/soc_u.h   |  2 ++
 2 files changed, 35 insertions(+), 25 deletions(-)

diff --git a/src/core/hle/service/soc_u.cpp b/src/core/hle/service/soc_u.cpp
index 6a2cab4143..5b2a643d83 100644
--- a/src/core/hle/service/soc_u.cpp
+++ b/src/core/hle/service/soc_u.cpp
@@ -2,38 +2,46 @@
 // Licensed under GPLv2 or any later version
 // Refer to the license.txt file included.
 
+#include <algorithm>
+#include <cstring>
+#include <unordered_map>
+
+#include "common/assert.h"
+#include "common/bit_field.h"
+#include "common/common_types.h"
 #include "common/logging/log.h"
+#include "common/scope_exit.h"
+
+#include "core/hle/kernel/session.h"
+#include "core/hle/result.h"
+#include "core/hle/service/soc_u.h"
+#include "core/memory.h"
 
 #ifdef _WIN32
-#include <winsock2.h>
-#include <ws2tcpip.h>
-
-// MinGW does not define several errno constants
-#ifndef _MSC_VER
-#define EBADMSG 104
-#define ENODATA 120
-#define ENOMSG  122
-#define ENOSR   124
-#define ENOSTR  125
-#define ETIME   137
-#define EIDRM   2001
-#define ENOLINK 2002
-#endif // _MSC_VER
+    #include <winsock2.h>
+    #include <ws2tcpip.h>
 
+    // MinGW does not define several errno constants
+    #ifndef _MSC_VER
+        #define EBADMSG 104
+        #define ENODATA 120
+        #define ENOMSG  122
+        #define ENOSR   124
+        #define ENOSTR  125
+        #define ETIME   137
+        #define EIDRM   2001
+        #define ENOLINK 2002
+    #endif // _MSC_VER
 #else
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <netdb.h>
-#include <arpa/inet.h>
-#include <fcntl.h>
-#include <poll.h>
+    #include <cerrno>
+    #include <fcntl.h>
+    #include <netinet/in.h>
+    #include <netdb.h>
+    #include <poll.h>
+    #include <sys/socket.h>
+    #include <unistd.h>
 #endif
 
-#include "common/scope_exit.h"
-#include "core/hle/hle.h"
-#include "core/hle/service/soc_u.h"
-#include <unordered_map>
-
 #ifdef _WIN32
 #    define WSAEAGAIN      WSAEWOULDBLOCK
 #    define WSAEMULTIHOP   -1 // Invalid dummy value
diff --git a/src/core/hle/service/soc_u.h b/src/core/hle/service/soc_u.h
index 483b3111b7..a091f597cc 100644
--- a/src/core/hle/service/soc_u.h
+++ b/src/core/hle/service/soc_u.h
@@ -4,6 +4,8 @@
 
 #pragma once
 
+#include <string>
+
 #include "core/hle/service/service.h"
 
 ////////////////////////////////////////////////////////////////////////////////////////////////////

From 4964a359e1a82f87a9772140fd1d933c5812c2e7 Mon Sep 17 00:00:00 2001
From: Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
Date: Sat, 27 Jun 2015 17:56:17 +0100
Subject: [PATCH 19/19] Core: Cleanup hw includes.

---
 src/core/hle/service/dsp_dsp.h                   |  2 ++
 src/core/hle/service/gsp_gpu.h                   |  3 +++
 src/core/hle/service/y2r_u.h                     |  2 ++
 src/core/hw/gpu.cpp                              | 10 ++++++----
 src/core/hw/gpu.h                                |  1 +
 src/core/hw/lcd.cpp                              |  2 --
 src/core/hw/lcd.h                                |  1 +
 src/core/hw/y2r.cpp                              |  4 +++-
 src/video_core/command_processor.h               |  4 ++--
 src/video_core/hwrasterizer_base.h               |  9 +++++++--
 src/video_core/renderer_base.h                   |  2 ++
 src/video_core/renderer_opengl/gl_rasterizer.cpp |  1 +
 src/video_core/renderer_opengl/gl_rasterizer.h   |  1 +
 13 files changed, 31 insertions(+), 11 deletions(-)

diff --git a/src/core/hle/service/dsp_dsp.h b/src/core/hle/service/dsp_dsp.h
index fa13bfb7c9..54109b2a9e 100644
--- a/src/core/hle/service/dsp_dsp.h
+++ b/src/core/hle/service/dsp_dsp.h
@@ -4,6 +4,8 @@
 
 #pragma once
 
+#include <string>
+
 #include "core/hle/service/service.h"
 
 ////////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/core/hle/service/gsp_gpu.h b/src/core/hle/service/gsp_gpu.h
index a435d418aa..d9e9a1a608 100644
--- a/src/core/hle/service/gsp_gpu.h
+++ b/src/core/hle/service/gsp_gpu.h
@@ -5,8 +5,11 @@
 #pragma once
 
 #include <cstddef>
+#include <string>
 
 #include "common/bit_field.h"
+#include "common/common_types.h"
+
 #include "core/hle/service/service.h"
 
 ////////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/core/hle/service/y2r_u.h b/src/core/hle/service/y2r_u.h
index 7df47fcb92..9454e5aabe 100644
--- a/src/core/hle/service/y2r_u.h
+++ b/src/core/hle/service/y2r_u.h
@@ -5,9 +5,11 @@
 #pragma once
 
 #include <array>
+#include <string>
 
 #include "common/common_types.h"
 
+#include "core/hle/result.h"
 #include "core/hle/service/service.h"
 
 ////////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/core/hw/gpu.cpp b/src/core/hw/gpu.cpp
index bdceb6984e..901519a8b4 100644
--- a/src/core/hw/gpu.cpp
+++ b/src/core/hw/gpu.cpp
@@ -2,17 +2,18 @@
 // Licensed under GPLv2 or any later version
 // Refer to the license.txt file included.
 
+#include <cstring>
+#include <type_traits>
+
 #include "common/color.h"
 #include "common/common_types.h"
-
-#include "core/arm/arm_interface.h"
+#include "common/logging/log.h"
+#include "common/vector_math.h"
 
 #include "core/settings.h"
-#include "core/core.h"
 #include "core/memory.h"
 #include "core/core_timing.h"
 
-#include "core/hle/hle.h"
 #include "core/hle/service/gsp_gpu.h"
 #include "core/hle/service/dsp_dsp.h"
 #include "core/hle/service/hid/hid.h"
@@ -21,6 +22,7 @@
 #include "core/hw/gpu.h"
 
 #include "video_core/command_processor.h"
+#include "video_core/hwrasterizer_base.h"
 #include "video_core/renderer_base.h"
 #include "video_core/utils.h"
 #include "video_core/video_core.h"
diff --git a/src/core/hw/gpu.h b/src/core/hw/gpu.h
index 699bcd2a56..5b8c43f8be 100644
--- a/src/core/hw/gpu.h
+++ b/src/core/hw/gpu.h
@@ -5,6 +5,7 @@
 #pragma once
 
 #include <cstddef>
+#include <type_traits>
 
 #include "common/assert.h"
 #include "common/bit_field.h"
diff --git a/src/core/hw/lcd.cpp b/src/core/hw/lcd.cpp
index 963c8d9810..cdb757a18e 100644
--- a/src/core/hw/lcd.cpp
+++ b/src/core/hw/lcd.cpp
@@ -7,8 +7,6 @@
 #include "common/common_types.h"
 #include "common/logging/log.h"
 
-#include "core/arm/arm_interface.h"
-#include "core/hle/hle.h"
 #include "core/hw/hw.h"
 #include "core/hw/lcd.h"
 
diff --git a/src/core/hw/lcd.h b/src/core/hw/lcd.h
index 8631eb201a..bcce6d8cfb 100644
--- a/src/core/hw/lcd.h
+++ b/src/core/hw/lcd.h
@@ -5,6 +5,7 @@
 #pragma once
 
 #include <cstddef>
+#include <type_traits>
 
 #include "common/bit_field.h"
 #include "common/common_funcs.h"
diff --git a/src/core/hw/y2r.cpp b/src/core/hw/y2r.cpp
index 5b7fb39e17..b40f13caed 100644
--- a/src/core/hw/y2r.cpp
+++ b/src/core/hw/y2r.cpp
@@ -2,8 +2,10 @@
 // Licensed under GPLv2 or any later version
 // Refer to the license.txt file included.
 
+#include <algorithm>
 #include <array>
-#include <numeric>
+#include <cstddef>
+#include <memory>
 
 #include "common/assert.h"
 #include "common/color.h"
diff --git a/src/video_core/command_processor.h b/src/video_core/command_processor.h
index bb3d4150fe..022a71f5ec 100644
--- a/src/video_core/command_processor.h
+++ b/src/video_core/command_processor.h
@@ -4,11 +4,11 @@
 
 #pragma once
 
+#include <type_traits>
+
 #include "common/bit_field.h"
 #include "common/common_types.h"
 
-#include "pica.h"
-
 namespace Pica {
 
 namespace CommandProcessor {
diff --git a/src/video_core/hwrasterizer_base.h b/src/video_core/hwrasterizer_base.h
index dec193f8b2..c8746c608a 100644
--- a/src/video_core/hwrasterizer_base.h
+++ b/src/video_core/hwrasterizer_base.h
@@ -4,8 +4,13 @@
 
 #pragma once
 
-#include "common/emu_window.h"
-#include "video_core/vertex_shader.h"
+#include "common/common_types.h"
+
+namespace Pica {
+namespace VertexShader {
+struct OutputVertex;
+}
+}
 
 class HWRasterizer {
 public:
diff --git a/src/video_core/renderer_base.h b/src/video_core/renderer_base.h
index fbbf17db45..6587bcf271 100644
--- a/src/video_core/renderer_base.h
+++ b/src/video_core/renderer_base.h
@@ -10,6 +10,8 @@
 
 #include "video_core/hwrasterizer_base.h"
 
+class EmuWindow;
+
 class RendererBase : NonCopyable {
 public:
 
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp
index 2edc38ac53..935a9f2818 100644
--- a/src/video_core/renderer_opengl/gl_rasterizer.cpp
+++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp
@@ -6,6 +6,7 @@
 #include <memory>
 
 #include "common/color.h"
+#include "common/math_util.h"
 
 #include "core/hw/gpu.h"
 #include "core/memory.h"
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.h b/src/video_core/renderer_opengl/gl_rasterizer.h
index 911ae8c361..ae7b26fc66 100644
--- a/src/video_core/renderer_opengl/gl_rasterizer.h
+++ b/src/video_core/renderer_opengl/gl_rasterizer.h
@@ -9,6 +9,7 @@
 #include "common/common_types.h"
 
 #include "video_core/hwrasterizer_base.h"
+#include "video_core/vertex_shader.h"
 
 #include "gl_state.h"
 #include "gl_rasterizer_cache.h"