mirror of
https://git.ryujinx.app/ryubing/ryujinx.git
synced 2026-05-12 16:25:46 +00:00
Structural and Memory Safety Improvements, Analyzer Cleanup (ryubing/ryujinx!47)
See merge request ryubing/ryujinx!47
This commit is contained in:
@@ -353,9 +353,8 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd
|
||||
int timeout = context.RequestData.ReadInt32();
|
||||
|
||||
(ulong inputBufferPosition, ulong inputBufferSize) = context.Request.GetBufferType0x21();
|
||||
#pragma warning disable IDE0059 // Remove unnecessary value assignment
|
||||
(ulong outputBufferPosition, ulong outputBufferSize) = context.Request.GetBufferType0x22();
|
||||
#pragma warning restore IDE0059
|
||||
|
||||
(ulong outputBufferPosition, _) = context.Request.GetBufferType0x22();
|
||||
|
||||
if (timeout < -1 || fdsCount < 0 || (ulong)(fdsCount * 8) > inputBufferSize)
|
||||
{
|
||||
@@ -603,9 +602,8 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd
|
||||
BsdSocketFlags socketFlags = (BsdSocketFlags)context.RequestData.ReadInt32();
|
||||
|
||||
(ulong sendPosition, ulong sendSize) = context.Request.GetBufferType0x21(0);
|
||||
#pragma warning disable IDE0059 // Remove unnecessary value assignment
|
||||
(ulong bufferPosition, ulong bufferSize) = context.Request.GetBufferType0x21(1);
|
||||
#pragma warning restore IDE0059
|
||||
|
||||
(ulong bufferPosition, _) = context.Request.GetBufferType0x21(1);
|
||||
|
||||
ReadOnlySpan<byte> sendBuffer = context.Memory.GetSpan(sendPosition, (int)sendSize);
|
||||
|
||||
@@ -634,9 +632,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd
|
||||
{
|
||||
int socketFd = context.RequestData.ReadInt32();
|
||||
|
||||
#pragma warning disable IDE0059 // Remove unnecessary value assignment
|
||||
(ulong bufferPos, ulong bufferSize) = context.Request.GetBufferType0x22();
|
||||
#pragma warning restore IDE0059
|
||||
(ulong bufferPos, _) = context.Request.GetBufferType0x22();
|
||||
|
||||
LinuxError errno = LinuxError.EBADF;
|
||||
ISocket socket = _context.RetrieveSocket(socketFd);
|
||||
@@ -679,9 +675,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd
|
||||
{
|
||||
int socketFd = context.RequestData.ReadInt32();
|
||||
|
||||
#pragma warning disable IDE0059 // Remove unnecessary value assignment
|
||||
(ulong bufferPosition, ulong bufferSize) = context.Request.GetBufferType0x21();
|
||||
#pragma warning restore IDE0059
|
||||
(ulong bufferPosition, _) = context.Request.GetBufferType0x21();
|
||||
|
||||
LinuxError errno = LinuxError.EBADF;
|
||||
ISocket socket = _context.RetrieveSocket(socketFd);
|
||||
@@ -702,9 +696,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd
|
||||
{
|
||||
int socketFd = context.RequestData.ReadInt32();
|
||||
|
||||
#pragma warning disable IDE0059 // Remove unnecessary value assignment
|
||||
(ulong bufferPosition, ulong bufferSize) = context.Request.GetBufferType0x21();
|
||||
#pragma warning restore IDE0059
|
||||
(ulong bufferPosition, _) = context.Request.GetBufferType0x21();
|
||||
|
||||
LinuxError errno = LinuxError.EBADF;
|
||||
ISocket socket = _context.RetrieveSocket(socketFd);
|
||||
@@ -725,9 +717,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd
|
||||
{
|
||||
int socketFd = context.RequestData.ReadInt32();
|
||||
|
||||
#pragma warning disable IDE0059 // Remove unnecessary value assignment
|
||||
(ulong bufferPosition, ulong bufferSize) = context.Request.GetBufferType0x22();
|
||||
#pragma warning restore IDE0059
|
||||
(ulong bufferPosition, _) = context.Request.GetBufferType0x22();
|
||||
|
||||
LinuxError errno = LinuxError.EBADF;
|
||||
ISocket socket = _context.RetrieveSocket(socketFd);
|
||||
@@ -754,9 +744,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd
|
||||
{
|
||||
int socketFd = context.RequestData.ReadInt32();
|
||||
|
||||
#pragma warning disable IDE0059 // Remove unnecessary value assignment
|
||||
(ulong bufferPos, ulong bufferSize) = context.Request.GetBufferType0x22();
|
||||
#pragma warning restore IDE0059
|
||||
(ulong bufferPos, _) = context.Request.GetBufferType0x22();
|
||||
|
||||
LinuxError errno = LinuxError.EBADF;
|
||||
ISocket socket = _context.RetrieveSocket(socketFd);
|
||||
@@ -828,9 +816,8 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd
|
||||
{
|
||||
int socketFd = context.RequestData.ReadInt32();
|
||||
BsdIoctl cmd = (BsdIoctl)context.RequestData.ReadInt32();
|
||||
#pragma warning disable IDE0059 // Remove unnecessary value assignment
|
||||
int bufferCount = context.RequestData.ReadInt32();
|
||||
#pragma warning restore IDE0059
|
||||
|
||||
_ = context.RequestData.ReadInt32(); // buffer count
|
||||
|
||||
LinuxError errno = LinuxError.EBADF;
|
||||
ISocket socket = _context.RetrieveSocket(socketFd);
|
||||
@@ -842,9 +829,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd
|
||||
case BsdIoctl.AtMark:
|
||||
errno = LinuxError.SUCCESS;
|
||||
|
||||
#pragma warning disable IDE0059 // Remove unnecessary value assignment
|
||||
(ulong bufferPosition, ulong bufferSize) = context.Request.GetBufferType0x22();
|
||||
#pragma warning restore IDE0059
|
||||
(ulong bufferPosition, _) = context.Request.GetBufferType0x22();
|
||||
|
||||
// FIXME: OOB not implemented.
|
||||
context.Memory.Write(bufferPosition, 0);
|
||||
@@ -1036,9 +1021,8 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd
|
||||
public ResultCode DuplicateSocket(ServiceCtx context)
|
||||
{
|
||||
int fd = context.RequestData.ReadInt32();
|
||||
#pragma warning disable IDE0059 // Remove unnecessary value assignment
|
||||
ulong reserved = context.RequestData.ReadUInt64();
|
||||
#pragma warning restore IDE0059
|
||||
|
||||
_ = context.RequestData.ReadUInt64(); // Padding, not used.
|
||||
|
||||
LinuxError errno = LinuxError.ENOENT;
|
||||
int newSockFd = -1;
|
||||
@@ -1065,9 +1049,9 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd
|
||||
int socketFd = context.RequestData.ReadInt32();
|
||||
int vlen = context.RequestData.ReadInt32();
|
||||
BsdSocketFlags socketFlags = (BsdSocketFlags)context.RequestData.ReadInt32();
|
||||
#pragma warning disable IDE0059 // Remove unnecessary value assignment
|
||||
uint reserved = context.RequestData.ReadUInt32();
|
||||
#pragma warning restore IDE0059
|
||||
|
||||
_ = context.RequestData.ReadUInt32(); // Padding, not used.
|
||||
|
||||
TimeVal timeout = context.RequestData.ReadStruct<TimeVal>();
|
||||
|
||||
ulong receivePosition = context.Request.ReceiveBuff[0].Position;
|
||||
|
||||
@@ -2,7 +2,6 @@ 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;
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd.Impl
|
||||
{
|
||||
enum WsaError
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd.Types
|
||||
{
|
||||
enum BsdSocketOption
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd.Types
|
||||
{
|
||||
enum LinuxError
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,10 +28,6 @@ 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 });
|
||||
@@ -44,10 +40,6 @@ 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 });
|
||||
@@ -170,9 +162,8 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres
|
||||
// GetCancelHandleRequest(u64, pid) -> u32
|
||||
public ResultCode GetCancelHandleRequest(ServiceCtx context)
|
||||
{
|
||||
#pragma warning disable IDE0059 // Remove unnecessary value assignment
|
||||
ulong pidPlaceHolder = context.RequestData.ReadUInt64();
|
||||
#pragma warning restore IDE0059
|
||||
_ = context.RequestData.ReadUInt64(); // pid
|
||||
|
||||
uint cancelHandleRequest = 0;
|
||||
|
||||
context.ResponseData.Write(cancelHandleRequest);
|
||||
@@ -187,9 +178,8 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres
|
||||
public ResultCode CancelRequest(ServiceCtx context)
|
||||
{
|
||||
uint cancelHandleRequest = context.RequestData.ReadUInt32();
|
||||
#pragma warning disable IDE0059 // Remove unnecessary value assignment
|
||||
ulong pidPlaceHolder = context.RequestData.ReadUInt64();
|
||||
#pragma warning restore IDE0059
|
||||
|
||||
_ = context.RequestData.ReadUInt64(); // pid
|
||||
|
||||
Logger.Stub?.PrintStub(LogClass.ServiceSfdnsres, new { cancelHandleRequest });
|
||||
|
||||
@@ -303,10 +293,9 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres
|
||||
|
||||
// TODO: Use params.
|
||||
bool enableNsdResolve = (context.RequestData.ReadInt32() & 1) != 0;
|
||||
#pragma warning disable IDE0059 // Remove unnecessary value assignment
|
||||
int timeOut = context.RequestData.ReadInt32();
|
||||
ulong pidPlaceholder = context.RequestData.ReadUInt64();
|
||||
#pragma warning restore IDE0059
|
||||
|
||||
_ = context.RequestData.ReadInt32(); // Timeout
|
||||
_ = context.RequestData.ReadUInt64(); // pid
|
||||
|
||||
if (withOptions)
|
||||
{
|
||||
@@ -403,12 +392,10 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres
|
||||
context.Memory.Read(inputBufferPosition, rawIp);
|
||||
|
||||
// TODO: Use params.
|
||||
#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
|
||||
_ = context.RequestData.ReadUInt32(); // socket length
|
||||
_ = context.RequestData.ReadUInt32(); // type
|
||||
_ = context.RequestData.ReadInt32(); // timeout
|
||||
_ = context.RequestData.ReadUInt64(); // pid placeholder
|
||||
|
||||
if (withOptions)
|
||||
{
|
||||
@@ -506,9 +493,8 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres
|
||||
ulong optionsBufferSize)
|
||||
{
|
||||
bool enableNsdResolve = (context.RequestData.ReadInt32() & 1) != 0;
|
||||
#pragma warning disable IDE0059 // Remove unnecessary value assignment
|
||||
uint cancelHandle = context.RequestData.ReadUInt32();
|
||||
#pragma warning restore IDE0059
|
||||
|
||||
_ = context.RequestData.ReadUInt32(); // Cancel handle request
|
||||
|
||||
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);
|
||||
@@ -523,21 +509,15 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres
|
||||
}
|
||||
|
||||
// NOTE: We ignore hints for now.
|
||||
#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
|
||||
_ = DeserializeAddrInfos(context.Memory, context.Request.SendBuff[2].Position, context.Request.SendBuff[2].Size); // hints
|
||||
|
||||
if (withOptions)
|
||||
{
|
||||
// TODO: Find unknown, Parse and use options.
|
||||
#pragma warning disable IDE0059 // Remove unnecessary value assignment
|
||||
uint unknown = context.RequestData.ReadUInt32();
|
||||
#pragma warning restore IDE0059
|
||||
_ = context.RequestData.ReadUInt32(); // unknown
|
||||
}
|
||||
|
||||
#pragma warning disable IDE0059 // Remove unnecessary value assignment
|
||||
ulong pidPlaceHolder = context.RequestData.ReadUInt64();
|
||||
#pragma warning restore IDE0059
|
||||
_ = context.RequestData.ReadUInt64(); // pid
|
||||
|
||||
IPHostEntry hostEntry = null;
|
||||
|
||||
@@ -625,13 +605,6 @@ 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;
|
||||
|
||||
Reference in New Issue
Block a user