From e4f74bea42b0d76357ac1e1f3adbd601cf8df66b Mon Sep 17 00:00:00 2001 From: iwubcode Date: Wed, 3 Mar 2021 20:06:54 -0600 Subject: [PATCH] Core: Use RAII winsock object to cleanly create and destroy WSA in gdb-stub --- Source/Core/Core/PowerPC/GDBStub.cpp | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/Source/Core/Core/PowerPC/GDBStub.cpp b/Source/Core/Core/PowerPC/GDBStub.cpp index 20a0ed5939..8b2293d132 100644 --- a/Source/Core/Core/PowerPC/GDBStub.cpp +++ b/Source/Core/Core/PowerPC/GDBStub.cpp @@ -4,6 +4,7 @@ // Originally written by Sven Peter for anergistic. +#include #include #include #include @@ -23,6 +24,7 @@ typedef SSIZE_T ssize_t; #endif #include "Common/Logging/Log.h" +#include "Common/SocketContext.h" #include "Core/HW/CPU.h" #include "Core/HW/Memmap.h" #include "Core/Host.h" @@ -31,6 +33,11 @@ typedef SSIZE_T ssize_t; #include "Core/PowerPC/PPCCache.h" #include "Core/PowerPC/PowerPC.h" +namespace +{ +std::optional s_socket_context; +} // namespace + #define GDB_BFR_MAX 10000 #define GDB_MAX_BP 10 @@ -791,10 +798,6 @@ void gdb_handle_exception() } } -#ifdef _WIN32 -WSADATA InitData; -#endif - // exported functions static void gdb_init_generic(int domain, const sockaddr* server_addr, socklen_t server_addrlen, @@ -833,10 +836,7 @@ void gdb_init(u32 port) static void gdb_init_generic(int domain, const sockaddr* server_addr, socklen_t server_addrlen, sockaddr* client_addr, socklen_t* client_addrlen) { -#ifdef _WIN32 - WSAStartup(MAKEWORD(2, 2), &InitData); -#endif - + s_socket_context.emplace(); memset(bp_x, 0, sizeof bp_x); memset(bp_r, 0, sizeof bp_r); memset(bp_w, 0, sizeof bp_w); @@ -884,9 +884,7 @@ void gdb_deinit() sock = -1; } -#ifdef _WIN32 - WSACleanup(); -#endif + s_socket_context.reset(); } bool gdb_active()