From 48eed78d1a05fecdf752e63a70daecf59dab6d57 Mon Sep 17 00:00:00 2001 From: Zephyron Date: Fri, 25 Apr 2025 14:38:28 +1000 Subject: [PATCH] socket: Implement missing errno values and improve network error handling Add support for missing errno values needed by TOTK: - Add BUSY (16) for "Device or resource busy" errors - Add NOTSOCK (88) for "Socket operation on non-socket" errors Improvements: - Update TranslateNativeError on both Windows and Unix to handle new error codes - Change socket error logging for NOTSOCK from WARNING to DEBUG level - Fix formatting in Unix errno translation code - Update shader storage buffer tracking range to accommodate TOTK buffers - Add hex format to storage buffer logging for easier comparison with bias range - Change storage buffer tracking log level from WARNING to DEBUG These changes help prevent error messages in games that use network features not fully implemented in the emulator yet. Signed-off-by: Zephyron --- src/core/hle/service/sockets/sockets.h | 3 +++ .../hle/service/sockets/sockets_translate.cpp | 5 ++++ src/core/internal_network/network.cpp | 25 ++++++++++++++++--- src/core/internal_network/network.h | 3 +++ .../global_memory_to_storage_buffer_pass.cpp | 6 ++--- 5 files changed, 36 insertions(+), 6 deletions(-) diff --git a/src/core/hle/service/sockets/sockets.h b/src/core/hle/service/sockets/sockets.h index 23c4fd640..17649149e 100644 --- a/src/core/hle/service/sockets/sockets.h +++ b/src/core/hle/service/sockets/sockets.h @@ -1,4 +1,5 @@ // SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project +// SPDX-FileCopyrightText: Copyright 2025 citron Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later #pragma once @@ -17,9 +18,11 @@ enum class Errno : u32 { BADF = 9, AGAIN = 11, NOMEM = 12, + BUSY = 16, INVAL = 22, MFILE = 24, PIPE = 32, + NOTSOCK = 88, MSGSIZE = 90, CONNABORTED = 103, CONNRESET = 104, diff --git a/src/core/hle/service/sockets/sockets_translate.cpp b/src/core/hle/service/sockets/sockets_translate.cpp index b9a3ba029..448c5f135 100644 --- a/src/core/hle/service/sockets/sockets_translate.cpp +++ b/src/core/hle/service/sockets/sockets_translate.cpp @@ -1,4 +1,5 @@ // SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project +// SPDX-FileCopyrightText: Copyright 2025 citron Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later #include @@ -39,6 +40,10 @@ Errno Translate(Network::Errno value) { return Errno::INPROGRESS; case Network::Errno::NOMEM: return Errno::NOMEM; + case Network::Errno::BUSY: + return Errno::BUSY; + case Network::Errno::NOTSOCK: + return Errno::NOTSOCK; default: UNIMPLEMENTED_MSG("Unimplemented errno={}", value); return Errno::SUCCESS; diff --git a/src/core/internal_network/network.cpp b/src/core/internal_network/network.cpp index c150ac8a4..c47893e1b 100644 --- a/src/core/internal_network/network.cpp +++ b/src/core/internal_network/network.cpp @@ -1,4 +1,5 @@ // SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project +// SPDX-FileCopyrightText: Copyright 2025 citron Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later #include @@ -156,6 +157,10 @@ Errno TranslateNativeError(int e, CallType call_type = CallType::Other) { return Errno::TIMEDOUT; case WSAEINPROGRESS: return Errno::INPROGRESS; + case WSAENOTSOCK: + return Errno::NOTSOCK; + case WSAEBUSY: + return Errno::BUSY; default: UNIMPLEMENTED_MSG("Unimplemented errno={}", e); return Errno::OTHER; @@ -273,14 +278,14 @@ Errno TranslateNativeError(int e, CallType call_type = CallType::Other) { return Errno::MFILE; case EPIPE: return Errno::PIPE; - case ECONNABORTED: - return Errno::CONNABORTED; case ENOTCONN: return Errno::NOTCONN; case EAGAIN: return Errno::AGAIN; case ECONNREFUSED: return Errno::CONNREFUSED; + case ECONNABORTED: + return Errno::CONNABORTED; case ECONNRESET: return Errno::CONNRESET; case EHOSTUNREACH: @@ -295,8 +300,14 @@ Errno TranslateNativeError(int e, CallType call_type = CallType::Other) { return Errno::TIMEDOUT; case EINPROGRESS: return Errno::INPROGRESS; + case ENOMEM: + return Errno::NOMEM; + case EBUSY: + return Errno::BUSY; + case ENOTSOCK: + return Errno::NOTSOCK; default: - UNIMPLEMENTED_MSG("Unimplemented errno={} ({})", e, strerror(e)); + UNIMPLEMENTED_MSG("Unimplemented errno={}", e); return Errno::OTHER; } } @@ -315,6 +326,14 @@ Errno GetAndLogLastError(CallType call_type = CallType::Other) { LOG_DEBUG(Network, "Socket operation error: {}", Common::NativeErrorToString(e)); return err; } + + if (err == Errno::NOTSOCK) { + // This is a common error when network functionality is not fully implemented + LOG_DEBUG(Network, "Socket operation error: An operation was attempted on something that is not a socket. " + "This may indicate the game is using network features not fully supported. "); + return err; + } + LOG_ERROR(Network, "Socket operation error: {}", Common::NativeErrorToString(e)); return err; } diff --git a/src/core/internal_network/network.h b/src/core/internal_network/network.h index abb355b96..b339bc3ef 100644 --- a/src/core/internal_network/network.h +++ b/src/core/internal_network/network.h @@ -1,4 +1,5 @@ // SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project +// SPDX-FileCopyrightText: Copyright 2025 citron Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later #pragma once @@ -47,6 +48,8 @@ enum class Errno { INPROGRESS, OTHER, NOMEM, + BUSY, + NOTSOCK, }; enum class GetAddrInfoError { diff --git a/src/shader_recompiler/ir_opt/global_memory_to_storage_buffer_pass.cpp b/src/shader_recompiler/ir_opt/global_memory_to_storage_buffer_pass.cpp index 67fae7f19..8849a7a73 100644 --- a/src/shader_recompiler/ir_opt/global_memory_to_storage_buffer_pass.cpp +++ b/src/shader_recompiler/ir_opt/global_memory_to_storage_buffer_pass.cpp @@ -381,7 +381,7 @@ void CollectStorageBuffers(IR::Block& block, IR::Inst& inst, StorageInfo& info) static constexpr Bias nvn_bias{ .index = 0, .offset_begin = 0x100, // Expanded from 0x110 to catch more potential storage buffers - .offset_end = 0x800, // Expanded from 0x610 to include a wider range + .offset_end = 0x1000, // Substantially expanded to include all TOTK storage buffers .alignment = 32, // Increased from 16 to optimize memory access patterns }; // Track the low address of the instruction @@ -402,8 +402,8 @@ void CollectStorageBuffers(IR::Block& block, IR::Inst& inst, StorageInfo& info) LOG_WARNING(Shader, "Storage buffer failed to track, using global memory fallbacks"); return; } - LOG_WARNING(Shader, "Storage buffer tracked without bias, index {} offset {}", - storage_buffer->index, storage_buffer->offset); + LOG_DEBUG(Shader, "Storage buffer tracked without bias, index {} offset 0x{:X}", + storage_buffer->index, storage_buffer->offset); } // Collect storage buffer and the instruction if (IsGlobalMemoryWrite(inst)) {