From 15d3e69c4c614dffb5705a75b136109123533fe2 Mon Sep 17 00:00:00 2001 From: ANR2ME Date: Thu, 23 Sep 2021 12:22:57 +0700 Subject: [PATCH 1/3] Fix possible crash issue --- Core/HLE/proAdhoc.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Core/HLE/proAdhoc.cpp b/Core/HLE/proAdhoc.cpp index ff5646513b..35002fc512 100644 --- a/Core/HLE/proAdhoc.cpp +++ b/Core/HLE/proAdhoc.cpp @@ -667,6 +667,9 @@ s32_le countChildren(SceNetAdhocMatchingContext * context, const bool excludeTim */ SceNetAdhocMatchingMemberInternal * findPeer(SceNetAdhocMatchingContext * context, SceNetEtherAddr * mac) { + if (mac == NULL) + return NULL; + // Iterate Peer List for Matching Target SceNetAdhocMatchingMemberInternal * peer = context->peerlist; for (; peer != NULL; peer = peer->next) From 73b2070821384cc3cc2eb8246dada46ce565af93 Mon Sep 17 00:00:00 2001 From: ANR2ME Date: Thu, 23 Sep 2021 12:29:51 +0700 Subject: [PATCH 2/3] Temporary fix to avoid a crash that happened due to trying to logs a syscall's argument when being Logged from another thread (AdhocMatchingInput thread) --- Core/HLE/sceNetAdhoc.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Core/HLE/sceNetAdhoc.cpp b/Core/HLE/sceNetAdhoc.cpp index 0fdb251b73..af5fb857da 100644 --- a/Core/HLE/sceNetAdhoc.cpp +++ b/Core/HLE/sceNetAdhoc.cpp @@ -1809,7 +1809,8 @@ static int sceNetAdhocPdpRecv(int id, void *addr, void * port, void *buf, void * return WaitBlockingAdhocSocket(threadSocketId, PDP_RECV, id, buf, len, timeout, saddr, sport, "pdp recv"); } - return hleLogSuccessVerboseX(SCENET, ERROR_NET_ADHOC_WOULD_BLOCK, "would block"); + VERBOSE_LOG(SCENET, "%08x=sceNetAdhocPdpRecv: would block", ERROR_NET_ADHOC_WOULD_BLOCK); // Temporary fix to avoid a crash on the Logs due to trying to Logs syscall's argument from another thread (ie. AdhocMatchingInput thread) + return ERROR_NET_ADHOC_WOULD_BLOCK; // hleLogSuccessVerboseX(SCENET, ERROR_NET_ADHOC_WOULD_BLOCK, "would block"); } hleEatMicro(50); From 4741357befbcee25f079605c832008658b875153 Mon Sep 17 00:00:00 2001 From: ANR2ME Date: Thu, 23 Sep 2021 12:32:16 +0700 Subject: [PATCH 3/3] Fix possible race condition issue when sending AdhocMatching data --- Core/HLE/sceNetAdhoc.cpp | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/Core/HLE/sceNetAdhoc.cpp b/Core/HLE/sceNetAdhoc.cpp index af5fb857da..e13dda5a6a 100644 --- a/Core/HLE/sceNetAdhoc.cpp +++ b/Core/HLE/sceNetAdhoc.cpp @@ -6137,6 +6137,9 @@ void broadcastHelloMessage(SceNetAdhocMatchingContext * context) */ void sendAcceptPacket(SceNetAdhocMatchingContext * context, SceNetEtherAddr * mac, int optlen, void * opt) { + // Lock the peer + std::lock_guard peer_guard(peerlock); + // Find Peer SceNetAdhocMatchingMemberInternal * peer = findPeer(context, mac); @@ -6218,6 +6221,9 @@ void sendAcceptPacket(SceNetAdhocMatchingContext * context, SceNetEtherAddr * ma */ void sendJoinPacket(SceNetAdhocMatchingContext * context, SceNetEtherAddr * mac, int optlen, void * opt) { + // Lock the peer + std::lock_guard peer_guard(peerlock); + // Find Peer SceNetAdhocMatchingMemberInternal * peer = findPeer(context, mac); @@ -6259,6 +6265,9 @@ void sendJoinPacket(SceNetAdhocMatchingContext * context, SceNetEtherAddr * mac, */ void sendCancelPacket(SceNetAdhocMatchingContext * context, SceNetEtherAddr * mac, int optlen, void * opt) { + // Lock the peer + std::lock_guard peer_guard(peerlock); + // Allocate Cancel Message Buffer uint8_t * cancel = (uint8_t *)malloc(5LL + optlen); @@ -6283,7 +6292,6 @@ void sendCancelPacket(SceNetAdhocMatchingContext * context, SceNetEtherAddr * ma free(cancel); } - peerlock.lock(); // Find Peer SceNetAdhocMatchingMemberInternal * peer = findPeer(context, mac); @@ -6300,7 +6308,6 @@ void sendCancelPacket(SceNetAdhocMatchingContext * context, SceNetEtherAddr * ma // Delete Peer else deletePeer(context, peer); } - peerlock.unlock(); } /** @@ -6312,6 +6319,9 @@ void sendCancelPacket(SceNetAdhocMatchingContext * context, SceNetEtherAddr * ma */ void sendBulkDataPacket(SceNetAdhocMatchingContext * context, SceNetEtherAddr * mac, int datalen, void * data) { + // Lock the peer + std::lock_guard peer_guard(peerlock); + // Find Peer SceNetAdhocMatchingMemberInternal * peer = findPeer(context, mac); @@ -6360,6 +6370,9 @@ void sendBulkDataPacket(SceNetAdhocMatchingContext * context, SceNetEtherAddr * */ void sendBirthPacket(SceNetAdhocMatchingContext * context, SceNetEtherAddr * mac) { + // Lock the peer + std::lock_guard peer_guard(peerlock); + // Find Newborn Child SceNetAdhocMatchingMemberInternal * newborn = findPeer(context, mac); @@ -6407,6 +6420,9 @@ void sendBirthPacket(SceNetAdhocMatchingContext * context, SceNetEtherAddr * mac */ void sendDeathPacket(SceNetAdhocMatchingContext * context, SceNetEtherAddr * mac) { + // Lock the peer + std::lock_guard peer_guard(peerlock); + // Find abandoned Child SceNetAdhocMatchingMemberInternal * deadkid = findPeer(context, mac); @@ -6458,6 +6474,9 @@ void sendDeathPacket(SceNetAdhocMatchingContext * context, SceNetEtherAddr * mac */ void sendByePacket(SceNetAdhocMatchingContext * context) { + // Lock the peer + std::lock_guard peer_guard(peerlock); + // Iterate Peers SceNetAdhocMatchingMemberInternal * peer = context->peerlist; for (; peer != NULL; peer = peer->next)