mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-04-28 13:28:01 +03:00

Replaces `std::shared_pointer` with `stx::atomic_ptr` and `stx::shared_ptr`. Notes to programmers: * This pr kills the use of `dynamic_cast`, `std::dynamic_pointer_cast` and `std::weak_ptr` on IDM objects, possible replacement is to save the object ID on the base object, then use idm::check/get_unlocked to the destination type via the saved ID which may be null. Null pointer check is how you can tell type mismatch (as dynamic cast) or object destruction (as weak_ptr locking). * Double-inheritance on IDM objects should be used with care, `stx::shared_ptr` does not support constant-evaluated pointer offsetting to parent/child type. * `idm::check/get_unlocked` can now be used anywhere. Misc fixes: * Fixes some segfaults with RPCN with interaction with IDM. * Fix deadlocks in access violation handler due locking recursion. * Fixes race condition in process exit-spawn on memory containers read. * Fix bug that theoretically can prevent RPCS3 from booting - fix `id_manager::typeinfo` comparison to compare members instead of `memcmp` which can fail spuriously on padding bytes. * Ensure all IDM inherited types of base, either has `id_base` or `id_type` defined locally, this allows to make getters such as `idm::get_unlocked<lv2_socket, lv2_socket_raw>()` which were broken before. (requires save-states invalidation) * Removes broken operator[] overload of `stx::shared_ptr` and `stx::single_ptr` for non-array types.
77 lines
2.3 KiB
C++
77 lines
2.3 KiB
C++
|
|
#pragma once
|
|
|
|
#ifdef _WIN32
|
|
#include <winsock2.h>
|
|
#include <WS2tcpip.h>
|
|
#else
|
|
#ifdef __clang__
|
|
#pragma GCC diagnostic push
|
|
#pragma GCC diagnostic ignored "-Wold-style-cast"
|
|
#endif
|
|
#include <errno.h>
|
|
#include <sys/time.h>
|
|
#include <sys/types.h>
|
|
#include <sys/socket.h>
|
|
#include <netinet/in.h>
|
|
#include <netinet/ip.h>
|
|
#include <netinet/tcp.h>
|
|
#include <arpa/inet.h>
|
|
#include <unistd.h>
|
|
#include <fcntl.h>
|
|
#include <poll.h>
|
|
#ifdef __clang__
|
|
#pragma GCC diagnostic pop
|
|
#endif
|
|
#endif
|
|
|
|
#include "lv2_socket.h"
|
|
|
|
class lv2_socket_native final : public lv2_socket
|
|
{
|
|
public:
|
|
static constexpr u32 id_type = 1;
|
|
|
|
lv2_socket_native(lv2_socket_family family, lv2_socket_type type, lv2_ip_protocol protocol);
|
|
lv2_socket_native(utils::serial& ar, lv2_socket_type type);
|
|
void save(utils::serial& ar);
|
|
~lv2_socket_native();
|
|
s32 create_socket();
|
|
|
|
std::tuple<bool, s32, shared_ptr<lv2_socket>, sys_net_sockaddr> accept(bool is_lock = true) override;
|
|
s32 bind(const sys_net_sockaddr& addr) override;
|
|
|
|
std::optional<s32> connect(const sys_net_sockaddr& addr) override;
|
|
s32 connect_followup() override;
|
|
|
|
std::pair<s32, sys_net_sockaddr> getpeername() override;
|
|
std::pair<s32, sys_net_sockaddr> getsockname() override;
|
|
std::tuple<s32, sockopt_data, u32> getsockopt(s32 level, s32 optname, u32 len) override;
|
|
s32 setsockopt(s32 level, s32 optname, const std::vector<u8>& optval) override;
|
|
std::optional<std::tuple<s32, std::vector<u8>, sys_net_sockaddr>> recvfrom(s32 flags, u32 len, bool is_lock = true) override;
|
|
std::optional<s32> sendto(s32 flags, const std::vector<u8>& buf, std::optional<sys_net_sockaddr> opt_sn_addr, bool is_lock = true) override;
|
|
std::optional<s32> sendmsg(s32 flags, const sys_net_msghdr& msg, bool is_lock = true) override;
|
|
|
|
s32 poll(sys_net_pollfd& sn_pfd, pollfd& native_pfd) override;
|
|
std::tuple<bool, bool, bool> select(bs_t<poll_t> selected, pollfd& native_pfd) override;
|
|
|
|
bool is_socket_connected();
|
|
|
|
s32 listen(s32 backlog) override;
|
|
void close() override;
|
|
s32 shutdown(s32 how) override;
|
|
|
|
private:
|
|
void set_socket(socket_type socket, lv2_socket_family family, lv2_socket_type type, lv2_ip_protocol protocol);
|
|
void set_default_buffers();
|
|
void set_non_blocking();
|
|
|
|
private:
|
|
// Value keepers
|
|
#ifdef _WIN32
|
|
s32 so_reuseaddr = 0;
|
|
s32 so_reuseport = 0;
|
|
#endif
|
|
u16 bound_port = 0;
|
|
bool feign_tcp_conn_failure = false; // Savestate load related
|
|
};
|