Revert "Structural and Memory Safety Improvements, Analyzer Cleanup (ryubing/ryujinx!47)"

This reverts merge request !47
This commit is contained in:
GreemDev
2025-06-15 20:45:26 -05:00
parent faf9e3cdd7
commit 77a797f154
307 changed files with 1245 additions and 1016 deletions

View File

@@ -353,8 +353,9 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd
int timeout = context.RequestData.ReadInt32();
(ulong inputBufferPosition, ulong inputBufferSize) = context.Request.GetBufferType0x21();
(ulong outputBufferPosition, _) = context.Request.GetBufferType0x22();
#pragma warning disable IDE0059 // Remove unnecessary value assignment
(ulong outputBufferPosition, ulong outputBufferSize) = context.Request.GetBufferType0x22();
#pragma warning restore IDE0059
if (timeout < -1 || fdsCount < 0 || (ulong)(fdsCount * 8) > inputBufferSize)
{
@@ -602,8 +603,9 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd
BsdSocketFlags socketFlags = (BsdSocketFlags)context.RequestData.ReadInt32();
(ulong sendPosition, ulong sendSize) = context.Request.GetBufferType0x21(0);
(ulong bufferPosition, _) = context.Request.GetBufferType0x21(1);
#pragma warning disable IDE0059 // Remove unnecessary value assignment
(ulong bufferPosition, ulong bufferSize) = context.Request.GetBufferType0x21(1);
#pragma warning restore IDE0059
ReadOnlySpan<byte> sendBuffer = context.Memory.GetSpan(sendPosition, (int)sendSize);
@@ -632,7 +634,9 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd
{
int socketFd = context.RequestData.ReadInt32();
(ulong bufferPos, _) = context.Request.GetBufferType0x22();
#pragma warning disable IDE0059 // Remove unnecessary value assignment
(ulong bufferPos, ulong bufferSize) = context.Request.GetBufferType0x22();
#pragma warning restore IDE0059
LinuxError errno = LinuxError.EBADF;
ISocket socket = _context.RetrieveSocket(socketFd);
@@ -675,7 +679,9 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd
{
int socketFd = context.RequestData.ReadInt32();
(ulong bufferPosition, _) = context.Request.GetBufferType0x21();
#pragma warning disable IDE0059 // Remove unnecessary value assignment
(ulong bufferPosition, ulong bufferSize) = context.Request.GetBufferType0x21();
#pragma warning restore IDE0059
LinuxError errno = LinuxError.EBADF;
ISocket socket = _context.RetrieveSocket(socketFd);
@@ -696,7 +702,9 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd
{
int socketFd = context.RequestData.ReadInt32();
(ulong bufferPosition, _) = context.Request.GetBufferType0x21();
#pragma warning disable IDE0059 // Remove unnecessary value assignment
(ulong bufferPosition, ulong bufferSize) = context.Request.GetBufferType0x21();
#pragma warning restore IDE0059
LinuxError errno = LinuxError.EBADF;
ISocket socket = _context.RetrieveSocket(socketFd);
@@ -717,7 +725,9 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd
{
int socketFd = context.RequestData.ReadInt32();
(ulong bufferPosition, _) = context.Request.GetBufferType0x22();
#pragma warning disable IDE0059 // Remove unnecessary value assignment
(ulong bufferPosition, ulong bufferSize) = context.Request.GetBufferType0x22();
#pragma warning restore IDE0059
LinuxError errno = LinuxError.EBADF;
ISocket socket = _context.RetrieveSocket(socketFd);
@@ -744,7 +754,9 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd
{
int socketFd = context.RequestData.ReadInt32();
(ulong bufferPos, _) = context.Request.GetBufferType0x22();
#pragma warning disable IDE0059 // Remove unnecessary value assignment
(ulong bufferPos, ulong bufferSize) = context.Request.GetBufferType0x22();
#pragma warning restore IDE0059
LinuxError errno = LinuxError.EBADF;
ISocket socket = _context.RetrieveSocket(socketFd);
@@ -816,8 +828,9 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd
{
int socketFd = context.RequestData.ReadInt32();
BsdIoctl cmd = (BsdIoctl)context.RequestData.ReadInt32();
_ = context.RequestData.ReadInt32(); // buffer count
#pragma warning disable IDE0059 // Remove unnecessary value assignment
int bufferCount = context.RequestData.ReadInt32();
#pragma warning restore IDE0059
LinuxError errno = LinuxError.EBADF;
ISocket socket = _context.RetrieveSocket(socketFd);
@@ -829,7 +842,9 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd
case BsdIoctl.AtMark:
errno = LinuxError.SUCCESS;
(ulong bufferPosition, _) = context.Request.GetBufferType0x22();
#pragma warning disable IDE0059 // Remove unnecessary value assignment
(ulong bufferPosition, ulong bufferSize) = context.Request.GetBufferType0x22();
#pragma warning restore IDE0059
// FIXME: OOB not implemented.
context.Memory.Write(bufferPosition, 0);
@@ -1021,8 +1036,9 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd
public ResultCode DuplicateSocket(ServiceCtx context)
{
int fd = context.RequestData.ReadInt32();
_ = context.RequestData.ReadUInt64(); // Padding, not used.
#pragma warning disable IDE0059 // Remove unnecessary value assignment
ulong reserved = context.RequestData.ReadUInt64();
#pragma warning restore IDE0059
LinuxError errno = LinuxError.ENOENT;
int newSockFd = -1;
@@ -1049,9 +1065,9 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd
int socketFd = context.RequestData.ReadInt32();
int vlen = context.RequestData.ReadInt32();
BsdSocketFlags socketFlags = (BsdSocketFlags)context.RequestData.ReadInt32();
_ = context.RequestData.ReadUInt32(); // Padding, not used.
#pragma warning disable IDE0059 // Remove unnecessary value assignment
uint reserved = context.RequestData.ReadUInt32();
#pragma warning restore IDE0059
TimeVal timeout = context.RequestData.ReadStruct<TimeVal>();
ulong receivePosition = context.Request.ReceiveBuff[0].Position;

View File

@@ -2,6 +2,7 @@ using Ryujinx.Common.Logging;
using Ryujinx.HLE.HOS.Services.Sockets.Bsd.Proxy;
using Ryujinx.HLE.HOS.Services.Sockets.Bsd.Types;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Net;
using System.Net.Sockets;

View File

@@ -1,3 +1,5 @@
using System.Diagnostics.CodeAnalysis;
namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd.Impl
{
enum WsaError

View File

@@ -1,3 +1,5 @@
using System.Diagnostics.CodeAnalysis;
namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd.Types
{
enum BsdSocketOption

View File

@@ -1,3 +1,5 @@
using System.Diagnostics.CodeAnalysis;
namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd.Types
{
enum LinuxError

View File

@@ -2,10 +2,10 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd.Types
{
struct PollEventData
{
#pragma warning disable CS0649 // Field is never assigned to
public int SocketFd;
public PollEventTypeMask InputEvents;
#pragma warning restore CS0649
public PollEventTypeMask OutputEvents;
}
}

View File

@@ -28,6 +28,10 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres
public ResultCode SetDnsAddressesPrivateRequest(ServiceCtx context)
{
uint cancelHandleRequest = context.RequestData.ReadUInt32();
#pragma warning disable IDE0059 // Remove unnecessary value assignment
ulong bufferPosition = context.Request.SendBuff[0].Position;
ulong bufferSize = context.Request.SendBuff[0].Size;
#pragma warning restore IDE0059
// TODO: This is stubbed in 2.0.0+, reverse 1.0.0 version for the sake of completeness.
Logger.Stub?.PrintStub(LogClass.ServiceSfdnsres, new { cancelHandleRequest });
@@ -40,6 +44,10 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres
public ResultCode GetDnsAddressPrivateRequest(ServiceCtx context)
{
uint cancelHandleRequest = context.RequestData.ReadUInt32();
#pragma warning disable IDE0059 // Remove unnecessary value assignment
ulong bufferPosition = context.Request.ReceiveBuff[0].Position;
ulong bufferSize = context.Request.ReceiveBuff[0].Size;
#pragma warning restore IDE0059
// TODO: This is stubbed in 2.0.0+, reverse 1.0.0 version for the sake of completeness.
Logger.Stub?.PrintStub(LogClass.ServiceSfdnsres, new { cancelHandleRequest });
@@ -162,8 +170,9 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres
// GetCancelHandleRequest(u64, pid) -> u32
public ResultCode GetCancelHandleRequest(ServiceCtx context)
{
_ = context.RequestData.ReadUInt64(); // pid
#pragma warning disable IDE0059 // Remove unnecessary value assignment
ulong pidPlaceHolder = context.RequestData.ReadUInt64();
#pragma warning restore IDE0059
uint cancelHandleRequest = 0;
context.ResponseData.Write(cancelHandleRequest);
@@ -178,8 +187,9 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres
public ResultCode CancelRequest(ServiceCtx context)
{
uint cancelHandleRequest = context.RequestData.ReadUInt32();
_ = context.RequestData.ReadUInt64(); // pid
#pragma warning disable IDE0059 // Remove unnecessary value assignment
ulong pidPlaceHolder = context.RequestData.ReadUInt64();
#pragma warning restore IDE0059
Logger.Stub?.PrintStub(LogClass.ServiceSfdnsres, new { cancelHandleRequest });
@@ -293,9 +303,10 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres
// TODO: Use params.
bool enableNsdResolve = (context.RequestData.ReadInt32() & 1) != 0;
_ = context.RequestData.ReadInt32(); // Timeout
_ = context.RequestData.ReadUInt64(); // pid
#pragma warning disable IDE0059 // Remove unnecessary value assignment
int timeOut = context.RequestData.ReadInt32();
ulong pidPlaceholder = context.RequestData.ReadUInt64();
#pragma warning restore IDE0059
if (withOptions)
{
@@ -392,10 +403,12 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres
context.Memory.Read(inputBufferPosition, rawIp);
// TODO: Use params.
_ = context.RequestData.ReadUInt32(); // socket length
_ = context.RequestData.ReadUInt32(); // type
_ = context.RequestData.ReadInt32(); // timeout
_ = context.RequestData.ReadUInt64(); // pid placeholder
#pragma warning disable IDE0059 // Remove unnecessary value assignment
uint socketLength = context.RequestData.ReadUInt32();
uint type = context.RequestData.ReadUInt32();
int timeOut = context.RequestData.ReadInt32();
ulong pidPlaceholder = context.RequestData.ReadUInt64();
#pragma warning restore IDE0059
if (withOptions)
{
@@ -493,8 +506,9 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres
ulong optionsBufferSize)
{
bool enableNsdResolve = (context.RequestData.ReadInt32() & 1) != 0;
_ = context.RequestData.ReadUInt32(); // Cancel handle request
#pragma warning disable IDE0059 // Remove unnecessary value assignment
uint cancelHandle = context.RequestData.ReadUInt32();
#pragma warning restore IDE0059
string host = MemoryHelper.ReadAsciiString(context.Memory, context.Request.SendBuff[0].Position, (long)context.Request.SendBuff[0].Size);
string service = MemoryHelper.ReadAsciiString(context.Memory, context.Request.SendBuff[1].Position, (long)context.Request.SendBuff[1].Size);
@@ -509,15 +523,21 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres
}
// NOTE: We ignore hints for now.
_ = DeserializeAddrInfos(context.Memory, context.Request.SendBuff[2].Position, context.Request.SendBuff[2].Size); // hints
#pragma warning disable IDE0059 // Remove unnecessary value assignment
List<AddrInfoSerialized> hints = DeserializeAddrInfos(context.Memory, context.Request.SendBuff[2].Position, context.Request.SendBuff[2].Size);
#pragma warning restore IDE0059
if (withOptions)
{
// TODO: Find unknown, Parse and use options.
_ = context.RequestData.ReadUInt32(); // unknown
#pragma warning disable IDE0059 // Remove unnecessary value assignment
uint unknown = context.RequestData.ReadUInt32();
#pragma warning restore IDE0059
}
_ = context.RequestData.ReadUInt64(); // pid
#pragma warning disable IDE0059 // Remove unnecessary value assignment
ulong pidPlaceHolder = context.RequestData.ReadUInt64();
#pragma warning restore IDE0059
IPHostEntry hostEntry = null;
@@ -605,6 +625,13 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres
private static int SerializeAddrInfos(ServiceCtx context, ulong responseBufferPosition, ulong responseBufferSize, IPHostEntry hostEntry, int port)
{
ulong originalBufferPosition = responseBufferPosition;
#pragma warning disable IDE0059 // Remove unnecessary value assignment
ulong bufferPosition = originalBufferPosition;
byte[] hostName = Encoding.ASCII.GetBytes(hostEntry.HostName + '\0');
#pragma warning restore IDE0059
using WritableRegion region = context.Memory.GetWritableRegion(responseBufferPosition, (int)responseBufferSize);
Span<byte> data = region.Memory.Span;