Merge pull request #9559 from iwubcode/gdb-stub-raii
Common / Core: add raii object that cleans up WSA on destruction in gdb-stub
This commit is contained in:
commit
fc86e554e0
|
@ -110,6 +110,8 @@ add_library(common
|
|||
SettingsHandler.h
|
||||
SFMLHelper.cpp
|
||||
SFMLHelper.h
|
||||
SocketContext.cpp
|
||||
SocketContext.h
|
||||
SPSCQueue.h
|
||||
StringUtil.cpp
|
||||
StringUtil.h
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
// Copyright 2021 Dolphin Emulator Project
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include "Common/SocketContext.h"
|
||||
|
||||
namespace Common
|
||||
{
|
||||
#ifdef _WIN32
|
||||
SocketContext::SocketContext()
|
||||
{
|
||||
static_cast<void>(WSAStartup(MAKEWORD(2, 2), &m_data));
|
||||
}
|
||||
SocketContext::~SocketContext()
|
||||
{
|
||||
WSACleanup();
|
||||
}
|
||||
#else
|
||||
SocketContext::SocketContext() = default;
|
||||
SocketContext::~SocketContext() = default;
|
||||
#endif
|
||||
} // namespace Common
|
|
@ -0,0 +1,30 @@
|
|||
// Copyright 2021 Dolphin Emulator Project
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <WinSock2.h>
|
||||
#endif
|
||||
|
||||
namespace Common
|
||||
{
|
||||
class SocketContext
|
||||
{
|
||||
public:
|
||||
SocketContext();
|
||||
~SocketContext();
|
||||
|
||||
SocketContext(const SocketContext&) = delete;
|
||||
SocketContext(SocketContext&&) = delete;
|
||||
|
||||
SocketContext& operator=(const SocketContext&) = delete;
|
||||
SocketContext& operator=(SocketContext&&) = delete;
|
||||
|
||||
private:
|
||||
#ifdef _WIN32
|
||||
WSADATA m_data;
|
||||
#endif
|
||||
};
|
||||
} // namespace Common
|
|
@ -65,17 +65,6 @@ enum SOResultCode : s32
|
|||
NetIPTopDevice::NetIPTopDevice(Kernel& ios, const std::string& device_name)
|
||||
: Device(ios, device_name)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
const int ret = WSAStartup(MAKEWORD(2, 2), &InitData);
|
||||
INFO_LOG_FMT(IOS_NET, "WSAStartup: {}", ret);
|
||||
#endif
|
||||
}
|
||||
|
||||
NetIPTopDevice::~NetIPTopDevice()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
WSACleanup();
|
||||
#endif
|
||||
}
|
||||
|
||||
void NetIPTopDevice::DoState(PointerWrap& p)
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include <string>
|
||||
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "Common/SocketContext.h"
|
||||
#include "Core/IOS/Device.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
|
@ -65,7 +66,6 @@ class NetIPTopDevice : public Device
|
|||
{
|
||||
public:
|
||||
NetIPTopDevice(Kernel& ios, const std::string& device_name);
|
||||
virtual ~NetIPTopDevice();
|
||||
|
||||
void DoState(PointerWrap& p) override;
|
||||
std::optional<IPCReply> IOCtl(const IOCtlRequest& request) override;
|
||||
|
@ -99,8 +99,6 @@ private:
|
|||
IPCReply HandleGetAddressInfoRequest(const IOCtlVRequest& request);
|
||||
IPCReply HandleICMPPingRequest(const IOCtlVRequest& request);
|
||||
|
||||
#ifdef _WIN32
|
||||
WSADATA InitData;
|
||||
#endif
|
||||
Common::SocketContext m_socket_context;
|
||||
};
|
||||
} // namespace IOS::HLE
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
// Originally written by Sven Peter <sven@fail0verflow.com> for anergistic.
|
||||
|
||||
#include <optional>
|
||||
#include <signal.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
@ -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<Common::SocketContext> 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()
|
||||
|
|
|
@ -142,6 +142,7 @@
|
|||
<ClInclude Include="Common\Semaphore.h" />
|
||||
<ClInclude Include="Common\SettingsHandler.h" />
|
||||
<ClInclude Include="Common\SFMLHelper.h" />
|
||||
<ClInclude Include="Common\SocketContext.h" />
|
||||
<ClInclude Include="Common\SPSCQueue.h" />
|
||||
<ClInclude Include="Common\StringUtil.h" />
|
||||
<ClInclude Include="Common\Swap.h" />
|
||||
|
@ -718,6 +719,7 @@
|
|||
<ClCompile Include="Common\SDCardUtil.cpp" />
|
||||
<ClCompile Include="Common\SettingsHandler.cpp" />
|
||||
<ClCompile Include="Common\SFMLHelper.cpp" />
|
||||
<ClCompile Include="Common\SocketContext.cpp" />
|
||||
<ClCompile Include="Common\StringUtil.cpp" />
|
||||
<ClCompile Include="Common\SymbolDB.cpp" />
|
||||
<ClCompile Include="Common\Thread.cpp" />
|
||||
|
|
Loading…
Reference in New Issue