HLE: Fix integer sign inconcistency accross the codebase (#2222)
* Make all title id instances unsigned * Replace address and size with ulong instead of signed types Long overdue change. Also change some logics here and there to optimize with the new memory manager. * Address Ac_K's comments * Remove uneeded cast all around * Fixes some others misalignment
This commit is contained in:
parent
c46f6879ff
commit
305f06eb71
73 changed files with 707 additions and 716 deletions
|
@ -197,28 +197,28 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd
|
|||
return WriteBsdResult(context, _sockets.Count - 1);
|
||||
}
|
||||
|
||||
private IPEndPoint ParseSockAddr(ServiceCtx context, long bufferPosition, long bufferSize)
|
||||
private IPEndPoint ParseSockAddr(ServiceCtx context, ulong bufferPosition, ulong bufferSize)
|
||||
{
|
||||
int size = context.Memory.Read<byte>((ulong)bufferPosition);
|
||||
int family = context.Memory.Read<byte>((ulong)bufferPosition + 1);
|
||||
int port = BinaryPrimitives.ReverseEndianness(context.Memory.Read<ushort>((ulong)bufferPosition + 2));
|
||||
int size = context.Memory.Read<byte>(bufferPosition);
|
||||
int family = context.Memory.Read<byte>(bufferPosition + 1);
|
||||
int port = BinaryPrimitives.ReverseEndianness(context.Memory.Read<ushort>(bufferPosition + 2));
|
||||
|
||||
byte[] rawIp = new byte[4];
|
||||
|
||||
context.Memory.Read((ulong)bufferPosition + 4, rawIp);
|
||||
context.Memory.Read(bufferPosition + 4, rawIp);
|
||||
|
||||
return new IPEndPoint(new IPAddress(rawIp), port);
|
||||
}
|
||||
|
||||
private void WriteSockAddr(ServiceCtx context, long bufferPosition, IPEndPoint endPoint)
|
||||
private void WriteSockAddr(ServiceCtx context, ulong bufferPosition, IPEndPoint endPoint)
|
||||
{
|
||||
context.Memory.Write((ulong)bufferPosition, (byte)0);
|
||||
context.Memory.Write((ulong)bufferPosition + 1, (byte)endPoint.AddressFamily);
|
||||
context.Memory.Write((ulong)bufferPosition + 2, BinaryPrimitives.ReverseEndianness((ushort)endPoint.Port));
|
||||
context.Memory.Write((ulong)bufferPosition + 4, endPoint.Address.GetAddressBytes());
|
||||
context.Memory.Write(bufferPosition, (byte)0);
|
||||
context.Memory.Write(bufferPosition + 1, (byte)endPoint.AddressFamily);
|
||||
context.Memory.Write(bufferPosition + 2, BinaryPrimitives.ReverseEndianness((ushort)endPoint.Port));
|
||||
context.Memory.Write(bufferPosition + 4, endPoint.Address.GetAddressBytes());
|
||||
}
|
||||
|
||||
private void WriteSockAddr(ServiceCtx context, long bufferPosition, BsdSocket socket, bool isRemote)
|
||||
private void WriteSockAddr(ServiceCtx context, ulong bufferPosition, BsdSocket socket, bool isRemote)
|
||||
{
|
||||
IPEndPoint endPoint = (isRemote ? socket.Handle.RemoteEndPoint : socket.Handle.LocalEndPoint) as IPEndPoint;
|
||||
|
||||
|
@ -282,13 +282,13 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd
|
|||
// Open(u32 flags, array<unknown, 0x21> path) -> (i32 ret, u32 bsd_errno)
|
||||
public ResultCode Open(ServiceCtx context)
|
||||
{
|
||||
(long bufferPosition, long bufferSize) = context.Request.GetBufferType0x21();
|
||||
(ulong bufferPosition, ulong bufferSize) = context.Request.GetBufferType0x21();
|
||||
|
||||
int flags = context.RequestData.ReadInt32();
|
||||
|
||||
byte[] rawPath = new byte[bufferSize];
|
||||
|
||||
context.Memory.Read((ulong)bufferPosition, rawPath);
|
||||
context.Memory.Read(bufferPosition, rawPath);
|
||||
|
||||
string path = Encoding.ASCII.GetString(rawPath);
|
||||
|
||||
|
@ -317,10 +317,10 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd
|
|||
int fdsCount = context.RequestData.ReadInt32();
|
||||
int timeout = context.RequestData.ReadInt32();
|
||||
|
||||
(long bufferPosition, long bufferSize) = context.Request.GetBufferType0x21();
|
||||
(ulong bufferPosition, ulong bufferSize) = context.Request.GetBufferType0x21();
|
||||
|
||||
|
||||
if (timeout < -1 || fdsCount < 0 || (fdsCount * 8) > bufferSize)
|
||||
if (timeout < -1 || fdsCount < 0 || (ulong)(fdsCount * 8) > bufferSize)
|
||||
{
|
||||
return WriteBsdResult(context, -1, LinuxError.EINVAL);
|
||||
}
|
||||
|
@ -329,7 +329,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd
|
|||
|
||||
for (int i = 0; i < fdsCount; i++)
|
||||
{
|
||||
int socketFd = context.Memory.Read<int>((ulong)(bufferPosition + i * 8));
|
||||
int socketFd = context.Memory.Read<int>(bufferPosition + (ulong)i * 8);
|
||||
|
||||
BsdSocket socket = RetrieveSocket(socketFd);
|
||||
|
||||
|
@ -337,8 +337,8 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd
|
|||
{
|
||||
return WriteBsdResult(context, -1, LinuxError.EBADF);}
|
||||
|
||||
PollEvent.EventTypeMask inputEvents = (PollEvent.EventTypeMask)context.Memory.Read<short>((ulong)(bufferPosition + i * 8 + 4));
|
||||
PollEvent.EventTypeMask outputEvents = (PollEvent.EventTypeMask)context.Memory.Read<short>((ulong)(bufferPosition + i * 8 + 6));
|
||||
PollEvent.EventTypeMask inputEvents = (PollEvent.EventTypeMask)context.Memory.Read<short>(bufferPosition + (ulong)i * 8 + 4);
|
||||
PollEvent.EventTypeMask outputEvents = (PollEvent.EventTypeMask)context.Memory.Read<short>(bufferPosition + (ulong)i * 8 + 6);
|
||||
|
||||
events[i] = new PollEvent(socketFd, socket, inputEvents, outputEvents);
|
||||
}
|
||||
|
@ -413,8 +413,8 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd
|
|||
for (int i = 0; i < fdsCount; i++)
|
||||
{
|
||||
PollEvent Event = events[i];
|
||||
context.Memory.Write((ulong)(bufferPosition + i * 8), Event.SocketFd);
|
||||
context.Memory.Write((ulong)(bufferPosition + i * 8 + 4), (short)Event.InputEvents);
|
||||
context.Memory.Write(bufferPosition + (ulong)i * 8, Event.SocketFd);
|
||||
context.Memory.Write(bufferPosition + (ulong)i * 8 + 4, (short)Event.InputEvents);
|
||||
|
||||
PollEvent.EventTypeMask outputEvents = 0;
|
||||
|
||||
|
@ -443,7 +443,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd
|
|||
outputEvents |= PollEvent.EventTypeMask.Output;
|
||||
}
|
||||
|
||||
context.Memory.Write((ulong)(bufferPosition + i * 8 + 6), (short)outputEvents);
|
||||
context.Memory.Write(bufferPosition + (ulong)i * 8 + 6, (short)outputEvents);
|
||||
}
|
||||
|
||||
return WriteBsdResult(context, readEvents.Count + writeEvents.Count + errorEvents.Count, LinuxError.SUCCESS);
|
||||
|
@ -467,7 +467,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd
|
|||
int socketFd = context.RequestData.ReadInt32();
|
||||
SocketFlags socketFlags = (SocketFlags)context.RequestData.ReadInt32();
|
||||
|
||||
(long receivePosition, long receiveLength) = context.Request.GetBufferType0x22();
|
||||
(ulong receivePosition, ulong receiveLength) = context.Request.GetBufferType0x22();
|
||||
|
||||
LinuxError errno = LinuxError.EBADF;
|
||||
BsdSocket socket = RetrieveSocket(socketFd);
|
||||
|
@ -489,7 +489,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd
|
|||
result = socket.Handle.Receive(receivedBuffer, socketFlags);
|
||||
errno = SetResultErrno(socket.Handle, result);
|
||||
|
||||
context.Memory.Write((ulong)receivePosition, receivedBuffer);
|
||||
context.Memory.Write(receivePosition, receivedBuffer);
|
||||
}
|
||||
catch (SocketException exception)
|
||||
{
|
||||
|
@ -507,8 +507,8 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd
|
|||
int socketFd = context.RequestData.ReadInt32();
|
||||
SocketFlags socketFlags = (SocketFlags)context.RequestData.ReadInt32();
|
||||
|
||||
(long receivePosition, long receiveLength) = context.Request.GetBufferType0x22();
|
||||
(long sockAddrOutPosition, long sockAddrOutSize) = context.Request.GetBufferType0x22(1);
|
||||
(ulong receivePosition, ulong receiveLength) = context.Request.GetBufferType0x22();
|
||||
(ulong sockAddrOutPosition, ulong sockAddrOutSize) = context.Request.GetBufferType0x22(1);
|
||||
|
||||
LinuxError errno = LinuxError.EBADF;
|
||||
BsdSocket socket = RetrieveSocket(socketFd);
|
||||
|
@ -532,7 +532,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd
|
|||
result = socket.Handle.ReceiveFrom(receivedBuffer, receivedBuffer.Length, socketFlags, ref endPoint);
|
||||
errno = SetResultErrno(socket.Handle, result);
|
||||
|
||||
context.Memory.Write((ulong)receivePosition, receivedBuffer);
|
||||
context.Memory.Write(receivePosition, receivedBuffer);
|
||||
WriteSockAddr(context, sockAddrOutPosition, (IPEndPoint)endPoint);
|
||||
}
|
||||
catch (SocketException exception)
|
||||
|
@ -551,7 +551,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd
|
|||
int socketFd = context.RequestData.ReadInt32();
|
||||
SocketFlags socketFlags = (SocketFlags)context.RequestData.ReadInt32();
|
||||
|
||||
(long sendPosition, long sendSize) = context.Request.GetBufferType0x21();
|
||||
(ulong sendPosition, ulong sendSize) = context.Request.GetBufferType0x21();
|
||||
|
||||
LinuxError errno = LinuxError.EBADF;
|
||||
BsdSocket socket = RetrieveSocket(socketFd);
|
||||
|
@ -569,7 +569,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd
|
|||
|
||||
byte[] sendBuffer = new byte[sendSize];
|
||||
|
||||
context.Memory.Read((ulong)sendPosition, sendBuffer);
|
||||
context.Memory.Read(sendPosition, sendBuffer);
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -593,8 +593,8 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd
|
|||
int socketFd = context.RequestData.ReadInt32();
|
||||
SocketFlags socketFlags = (SocketFlags)context.RequestData.ReadInt32();
|
||||
|
||||
(long sendPosition, long sendSize) = context.Request.GetBufferType0x21();
|
||||
(long bufferPosition, long bufferSize) = context.Request.GetBufferType0x21(1);
|
||||
(ulong sendPosition, ulong sendSize) = context.Request.GetBufferType0x21();
|
||||
(ulong bufferPosition, ulong bufferSize) = context.Request.GetBufferType0x21(1);
|
||||
|
||||
LinuxError errno = LinuxError.EBADF;
|
||||
BsdSocket socket = RetrieveSocket(socketFd);
|
||||
|
@ -612,7 +612,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd
|
|||
|
||||
byte[] sendBuffer = new byte[sendSize];
|
||||
|
||||
context.Memory.Read((ulong)sendPosition, sendBuffer);
|
||||
context.Memory.Read(sendPosition, sendBuffer);
|
||||
|
||||
EndPoint endPoint = ParseSockAddr(context, bufferPosition, bufferSize);
|
||||
|
||||
|
@ -637,7 +637,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd
|
|||
{
|
||||
int socketFd = context.RequestData.ReadInt32();
|
||||
|
||||
(long bufferPos, long bufferSize) = context.Request.GetBufferType0x22();
|
||||
(ulong bufferPos, ulong bufferSize) = context.Request.GetBufferType0x22();
|
||||
|
||||
LinuxError errno = LinuxError.EBADF;
|
||||
BsdSocket socket = RetrieveSocket(socketFd);
|
||||
|
@ -692,7 +692,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd
|
|||
{
|
||||
int socketFd = context.RequestData.ReadInt32();
|
||||
|
||||
(long bufferPos, long bufferSize) = context.Request.GetBufferType0x21();
|
||||
(ulong bufferPos, ulong bufferSize) = context.Request.GetBufferType0x21();
|
||||
|
||||
LinuxError errno = LinuxError.EBADF;
|
||||
BsdSocket socket = RetrieveSocket(socketFd);
|
||||
|
@ -722,7 +722,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd
|
|||
{
|
||||
int socketFd = context.RequestData.ReadInt32();
|
||||
|
||||
(long bufferPos, long bufferSize) = context.Request.GetBufferType0x21();
|
||||
(ulong bufferPos, ulong bufferSize) = context.Request.GetBufferType0x21();
|
||||
|
||||
LinuxError errno = LinuxError.EBADF;
|
||||
BsdSocket socket = RetrieveSocket(socketFd);
|
||||
|
@ -751,7 +751,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd
|
|||
{
|
||||
int socketFd = context.RequestData.ReadInt32();
|
||||
|
||||
(long bufferPos, long bufferSize) = context.Request.GetBufferType0x22();
|
||||
(ulong bufferPos, ulong bufferSize) = context.Request.GetBufferType0x22();
|
||||
|
||||
LinuxError errno = LinuxError.EBADF;
|
||||
BsdSocket socket = RetrieveSocket(socketFd);
|
||||
|
@ -774,7 +774,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd
|
|||
{
|
||||
int socketFd = context.RequestData.ReadInt32();
|
||||
|
||||
(long bufferPos, long bufferSize) = context.Request.GetBufferType0x22();
|
||||
(ulong bufferPos, ulong bufferSize) = context.Request.GetBufferType0x22();
|
||||
|
||||
LinuxError errno = LinuxError.EBADF;
|
||||
BsdSocket socket = RetrieveSocket(socketFd);
|
||||
|
@ -799,7 +799,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd
|
|||
int level = context.RequestData.ReadInt32();
|
||||
int optionName = context.RequestData.ReadInt32();
|
||||
|
||||
(long bufferPosition, long bufferSize) = context.Request.GetBufferType0x22();
|
||||
(ulong bufferPosition, ulong bufferSize) = context.Request.GetBufferType0x22();
|
||||
|
||||
LinuxError errno = LinuxError.EBADF;
|
||||
BsdSocket socket = RetrieveSocket(socketFd);
|
||||
|
@ -866,10 +866,10 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd
|
|||
case BsdIoctl.AtMark:
|
||||
errno = LinuxError.SUCCESS;
|
||||
|
||||
(long bufferPosition, long bufferSize) = context.Request.GetBufferType0x22();
|
||||
(ulong bufferPosition, ulong bufferSize) = context.Request.GetBufferType0x22();
|
||||
|
||||
// FIXME: OOB not implemented.
|
||||
context.Memory.Write((ulong)bufferPosition, 0);
|
||||
context.Memory.Write(bufferPosition, 0);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -917,7 +917,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd
|
|||
return WriteBsdResult(context, result, errno);
|
||||
}
|
||||
|
||||
private LinuxError HandleGetSocketOption(ServiceCtx context, BsdSocket socket, SocketOptionName optionName, long optionValuePosition, long optionValueSize)
|
||||
private LinuxError HandleGetSocketOption(ServiceCtx context, BsdSocket socket, SocketOptionName optionName, ulong optionValuePosition, ulong optionValueSize)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -938,13 +938,13 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd
|
|||
case SocketOptionName.Type:
|
||||
case SocketOptionName.Linger:
|
||||
socket.Handle.GetSocketOption(SocketOptionLevel.Socket, optionName, optionValue);
|
||||
context.Memory.Write((ulong)optionValuePosition, optionValue);
|
||||
context.Memory.Write(optionValuePosition, optionValue);
|
||||
|
||||
return LinuxError.SUCCESS;
|
||||
|
||||
case (SocketOptionName)0x200:
|
||||
socket.Handle.GetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, optionValue);
|
||||
context.Memory.Write((ulong)optionValuePosition, optionValue);
|
||||
context.Memory.Write(optionValuePosition, optionValue);
|
||||
|
||||
return LinuxError.SUCCESS;
|
||||
|
||||
|
@ -960,7 +960,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd
|
|||
}
|
||||
}
|
||||
|
||||
private LinuxError HandleSetSocketOption(ServiceCtx context, BsdSocket socket, SocketOptionName optionName, long optionValuePosition, long optionValueSize)
|
||||
private LinuxError HandleSetSocketOption(ServiceCtx context, BsdSocket socket, SocketOptionName optionName, ulong optionValuePosition, ulong optionValueSize)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -1013,7 +1013,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd
|
|||
int level = context.RequestData.ReadInt32();
|
||||
int optionName = context.RequestData.ReadInt32();
|
||||
|
||||
(long bufferPos, long bufferSize) = context.Request.GetBufferType0x21();
|
||||
(ulong bufferPos, ulong bufferSize) = context.Request.GetBufferType0x21();
|
||||
|
||||
LinuxError errno = LinuxError.EBADF;
|
||||
BsdSocket socket = RetrieveSocket(socketFd);
|
||||
|
@ -1105,7 +1105,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd
|
|||
{
|
||||
int socketFd = context.RequestData.ReadInt32();
|
||||
|
||||
(long sendPosition, long sendSize) = context.Request.GetBufferType0x21();
|
||||
(ulong sendPosition, ulong sendSize) = context.Request.GetBufferType0x21();
|
||||
|
||||
LinuxError errno = LinuxError.EBADF;
|
||||
BsdSocket socket = RetrieveSocket(socketFd);
|
||||
|
@ -1115,7 +1115,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd
|
|||
{
|
||||
byte[] sendBuffer = new byte[sendSize];
|
||||
|
||||
context.Memory.Read((ulong)sendPosition, sendBuffer);
|
||||
context.Memory.Read(sendPosition, sendBuffer);
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -1137,7 +1137,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd
|
|||
{
|
||||
int socketFd = context.RequestData.ReadInt32();
|
||||
|
||||
(long receivePosition, long receiveLength) = context.Request.GetBufferType0x22();
|
||||
(ulong receivePosition, ulong receiveLength) = context.Request.GetBufferType0x22();
|
||||
|
||||
LinuxError errno = LinuxError.EBADF;
|
||||
BsdSocket socket = RetrieveSocket(socketFd);
|
||||
|
@ -1151,7 +1151,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd
|
|||
{
|
||||
result = socket.Handle.Receive(receivedBuffer);
|
||||
errno = SetResultErrno(socket.Handle, result);
|
||||
context.Memory.Write((ulong)receivePosition, receivedBuffer);
|
||||
context.Memory.Write(receivePosition, receivedBuffer);
|
||||
}
|
||||
catch (SocketException exception)
|
||||
{
|
||||
|
|
|
@ -37,7 +37,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Nsd
|
|||
// GetSettingName() -> buffer<unknown<0x100>, 0x16>
|
||||
public ResultCode GetSettingName(ServiceCtx context)
|
||||
{
|
||||
(long outputPosition, long outputSize) = context.Request.GetBufferType0x22();
|
||||
(ulong outputPosition, ulong outputSize) = context.Request.GetBufferType0x22();
|
||||
|
||||
ResultCode result = _fqdnResolver.GetSettingName(context, out string settingName);
|
||||
|
||||
|
@ -45,7 +45,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Nsd
|
|||
{
|
||||
byte[] settingNameBuffer = Encoding.UTF8.GetBytes(settingName + '\0');
|
||||
|
||||
context.Memory.Write((ulong)outputPosition, settingNameBuffer);
|
||||
context.Memory.Write(outputPosition, settingNameBuffer);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
@ -55,7 +55,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Nsd
|
|||
// GetEnvironmentIdentifier() -> buffer<unknown<8>, 0x16>
|
||||
public ResultCode GetEnvironmentIdentifier(ServiceCtx context)
|
||||
{
|
||||
(long outputPosition, long outputSize) = context.Request.GetBufferType0x22();
|
||||
(ulong outputPosition, ulong outputSize) = context.Request.GetBufferType0x22();
|
||||
|
||||
ResultCode result = _fqdnResolver.GetEnvironmentIdentifier(context, out string identifier);
|
||||
|
||||
|
@ -63,7 +63,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Nsd
|
|||
{
|
||||
byte[] identifierBuffer = Encoding.UTF8.GetBytes(identifier + '\0');
|
||||
|
||||
context.Memory.Write((ulong)outputPosition, identifierBuffer);
|
||||
context.Memory.Write(outputPosition, identifierBuffer);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
@ -133,12 +133,12 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Nsd
|
|||
// Resolve(buffer<unknown<0x100>, 0x15>) -> buffer<unknown<0x100>, 0x16>
|
||||
public ResultCode Resolve(ServiceCtx context)
|
||||
{
|
||||
long outputPosition = context.Request.ReceiveBuff[0].Position;
|
||||
long outputSize = context.Request.ReceiveBuff[0].Size;
|
||||
ulong outputPosition = context.Request.ReceiveBuff[0].Position;
|
||||
ulong outputSize = context.Request.ReceiveBuff[0].Size;
|
||||
|
||||
ResultCode result = _fqdnResolver.ResolveEx(context, out _, out string resolvedAddress);
|
||||
|
||||
if (resolvedAddress.Length > outputSize)
|
||||
if ((ulong)resolvedAddress.Length > outputSize)
|
||||
{
|
||||
return ResultCode.InvalidArgument;
|
||||
}
|
||||
|
@ -147,7 +147,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Nsd
|
|||
|
||||
MemoryHelper.FillWithZeros(context.Memory, outputPosition, (int)outputSize);
|
||||
|
||||
context.Memory.Write((ulong)outputPosition, resolvedAddressBuffer);
|
||||
context.Memory.Write(outputPosition, resolvedAddressBuffer);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -156,12 +156,12 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Nsd
|
|||
// ResolveEx(buffer<unknown<0x100>, 0x15>) -> (u32, buffer<unknown<0x100>, 0x16>)
|
||||
public ResultCode ResolveEx(ServiceCtx context)
|
||||
{
|
||||
long outputPosition = context.Request.ReceiveBuff[0].Position;
|
||||
long outputSize = context.Request.ReceiveBuff[0].Size;
|
||||
ulong outputPosition = context.Request.ReceiveBuff[0].Position;
|
||||
ulong outputSize = context.Request.ReceiveBuff[0].Size;
|
||||
|
||||
ResultCode result = _fqdnResolver.ResolveEx(context, out ResultCode errorCode, out string resolvedAddress);
|
||||
|
||||
if (resolvedAddress.Length > outputSize)
|
||||
if ((ulong)resolvedAddress.Length > outputSize)
|
||||
{
|
||||
return ResultCode.InvalidArgument;
|
||||
}
|
||||
|
@ -170,7 +170,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Nsd
|
|||
|
||||
MemoryHelper.FillWithZeros(context.Memory, outputPosition, (int)outputSize);
|
||||
|
||||
context.Memory.Write((ulong)outputPosition, resolvedAddressBuffer);
|
||||
context.Memory.Write(outputPosition, resolvedAddressBuffer);
|
||||
|
||||
context.ResponseData.Write((int)errorCode);
|
||||
|
||||
|
|
|
@ -97,12 +97,12 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Nsd.Manager
|
|||
|
||||
public ResultCode ResolveEx(ServiceCtx context, out ResultCode resultCode, out string resolvedAddress)
|
||||
{
|
||||
long inputPosition = context.Request.SendBuff[0].Position;
|
||||
long inputSize = context.Request.SendBuff[0].Size;
|
||||
ulong inputPosition = context.Request.SendBuff[0].Position;
|
||||
ulong inputSize = context.Request.SendBuff[0].Size;
|
||||
|
||||
byte[] addressBuffer = new byte[inputSize];
|
||||
|
||||
context.Memory.Read((ulong)inputPosition, addressBuffer);
|
||||
context.Memory.Read(inputPosition, addressBuffer);
|
||||
|
||||
string address = Encoding.UTF8.GetString(addressBuffer).TrimEnd('\0');
|
||||
|
||||
|
|
|
@ -24,8 +24,8 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres
|
|||
public ResultCode SetDnsAddressesPrivateRequest(ServiceCtx context)
|
||||
{
|
||||
uint cancelHandleRequest = context.RequestData.ReadUInt32();
|
||||
long bufferPosition = context.Request.SendBuff[0].Position;
|
||||
long bufferSize = context.Request.SendBuff[0].Size;
|
||||
ulong bufferPosition = context.Request.SendBuff[0].Position;
|
||||
ulong bufferSize = context.Request.SendBuff[0].Size;
|
||||
|
||||
// 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 });
|
||||
|
@ -38,8 +38,8 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres
|
|||
public ResultCode GetDnsAddressPrivateRequest(ServiceCtx context)
|
||||
{
|
||||
uint cancelHandleRequest = context.RequestData.ReadUInt32();
|
||||
long bufferPosition = context.Request.ReceiveBuff[0].Position;
|
||||
long bufferSize = context.Request.ReceiveBuff[0].Size;
|
||||
ulong bufferPosition = context.Request.ReceiveBuff[0].Position;
|
||||
ulong bufferSize = context.Request.ReceiveBuff[0].Size;
|
||||
|
||||
// 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 });
|
||||
|
@ -51,11 +51,11 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres
|
|||
// GetHostByNameRequest(u8, u32, u64, pid, buffer<unknown, 5, 0>) -> (u32, u32, u32, buffer<unknown, 6, 0>)
|
||||
public ResultCode GetHostByNameRequest(ServiceCtx context)
|
||||
{
|
||||
long inputBufferPosition = context.Request.SendBuff[0].Position;
|
||||
long inputBufferSize = context.Request.SendBuff[0].Size;
|
||||
ulong inputBufferPosition = context.Request.SendBuff[0].Position;
|
||||
ulong inputBufferSize = context.Request.SendBuff[0].Size;
|
||||
|
||||
long outputBufferPosition = context.Request.ReceiveBuff[0].Position;
|
||||
long outputBufferSize = context.Request.ReceiveBuff[0].Size;
|
||||
ulong outputBufferPosition = context.Request.ReceiveBuff[0].Position;
|
||||
ulong outputBufferSize = context.Request.ReceiveBuff[0].Size;
|
||||
|
||||
return GetHostByNameRequestImpl(context, inputBufferPosition, inputBufferSize, outputBufferPosition, outputBufferSize, 0, 0);
|
||||
}
|
||||
|
@ -64,11 +64,11 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres
|
|||
// GetHostByAddrRequest(u32, u32, u32, u64, pid, buffer<unknown, 5, 0>) -> (u32, u32, u32, buffer<unknown, 6, 0>)
|
||||
public ResultCode GetHostByAddrRequest(ServiceCtx context)
|
||||
{
|
||||
long inputBufferPosition = context.Request.SendBuff[0].Position;
|
||||
long inputBufferSize = context.Request.SendBuff[0].Size;
|
||||
ulong inputBufferPosition = context.Request.SendBuff[0].Position;
|
||||
ulong inputBufferSize = context.Request.SendBuff[0].Size;
|
||||
|
||||
long outputBufferPosition = context.Request.ReceiveBuff[0].Position;
|
||||
long outputBufferSize = context.Request.ReceiveBuff[0].Size;
|
||||
ulong outputBufferPosition = context.Request.ReceiveBuff[0].Position;
|
||||
ulong outputBufferSize = context.Request.ReceiveBuff[0].Size;
|
||||
|
||||
return GetHostByAddrRequestImpl(context, inputBufferPosition, inputBufferSize, outputBufferPosition, outputBufferSize, 0, 0);
|
||||
}
|
||||
|
@ -90,12 +90,12 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres
|
|||
_ => (errorCode <= NetDbError.Internal) ? "Resolver internal error" : "Unknown resolver error"
|
||||
};
|
||||
|
||||
long bufferPosition = context.Request.ReceiveBuff[0].Position;
|
||||
long bufferSize = context.Request.ReceiveBuff[0].Size;
|
||||
ulong bufferPosition = context.Request.ReceiveBuff[0].Position;
|
||||
ulong bufferSize = context.Request.ReceiveBuff[0].Size;
|
||||
|
||||
if (errorString.Length + 1 <= bufferSize)
|
||||
if ((ulong)(errorString.Length + 1) <= bufferSize)
|
||||
{
|
||||
context.Memory.Write((ulong)bufferPosition, Encoding.ASCII.GetBytes(errorString + '\0'));
|
||||
context.Memory.Write(bufferPosition, Encoding.ASCII.GetBytes(errorString + '\0'));
|
||||
|
||||
resultCode = ResultCode.Success;
|
||||
}
|
||||
|
@ -135,12 +135,12 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres
|
|||
_ => "Success"
|
||||
};
|
||||
|
||||
long bufferPosition = context.Request.ReceiveBuff[0].Position;
|
||||
long bufferSize = context.Request.ReceiveBuff[0].Size;
|
||||
ulong bufferPosition = context.Request.ReceiveBuff[0].Position;
|
||||
ulong bufferSize = context.Request.ReceiveBuff[0].Size;
|
||||
|
||||
if (errorString.Length + 1 <= bufferSize)
|
||||
if ((ulong)(errorString.Length + 1) <= bufferSize)
|
||||
{
|
||||
context.Memory.Write((ulong)bufferPosition, Encoding.ASCII.GetBytes(errorString + '\0'));
|
||||
context.Memory.Write(bufferPosition, Encoding.ASCII.GetBytes(errorString + '\0'));
|
||||
|
||||
resultCode = ResultCode.Success;
|
||||
}
|
||||
|
@ -152,8 +152,8 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres
|
|||
// GetAddrInfoRequest(bool enable_nsd_resolve, u32, u64 pid_placeholder, pid, buffer<i8, 5, 0> host, buffer<i8, 5, 0> service, buffer<packed_addrinfo, 5, 0> hints) -> (i32 ret, u32 bsd_errno, u32 packed_addrinfo_size, buffer<packed_addrinfo, 6, 0> response)
|
||||
public ResultCode GetAddrInfoRequest(ServiceCtx context)
|
||||
{
|
||||
long responseBufferPosition = context.Request.ReceiveBuff[0].Position;
|
||||
long responseBufferSize = context.Request.ReceiveBuff[0].Size;
|
||||
ulong responseBufferPosition = context.Request.ReceiveBuff[0].Position;
|
||||
ulong responseBufferSize = context.Request.ReceiveBuff[0].Size;
|
||||
|
||||
return GetAddrInfoRequestImpl(context, responseBufferPosition, responseBufferSize, 0, 0);
|
||||
}
|
||||
|
@ -188,9 +188,9 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres
|
|||
// GetHostByNameRequestWithOptions(u8, u32, u64, pid, buffer<unknown, 21, 0>, buffer<unknown, 21, 0>) -> (u32, u32, u32, buffer<unknown, 22, 0>)
|
||||
public ResultCode GetHostByNameRequestWithOptions(ServiceCtx context)
|
||||
{
|
||||
(long inputBufferPosition, long inputBufferSize) = context.Request.GetBufferType0x21();
|
||||
(long outputBufferPosition, long outputBufferSize) = context.Request.GetBufferType0x22();
|
||||
(long optionsBufferPosition, long optionsBufferSize) = context.Request.GetBufferType0x21();
|
||||
(ulong inputBufferPosition, ulong inputBufferSize) = context.Request.GetBufferType0x21();
|
||||
(ulong outputBufferPosition, ulong outputBufferSize) = context.Request.GetBufferType0x22();
|
||||
(ulong optionsBufferPosition, ulong optionsBufferSize) = context.Request.GetBufferType0x21();
|
||||
|
||||
return GetHostByNameRequestImpl(context, inputBufferPosition, inputBufferSize, outputBufferPosition, outputBufferSize, optionsBufferPosition, optionsBufferSize);
|
||||
}
|
||||
|
@ -199,9 +199,9 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres
|
|||
// GetHostByAddrRequestWithOptions(u32, u32, u32, u64, pid, buffer<unknown, 21, 0>, buffer<unknown, 21, 0>) -> (u32, u32, u32, buffer<unknown, 22, 0>)
|
||||
public ResultCode GetHostByAddrRequestWithOptions(ServiceCtx context)
|
||||
{
|
||||
(long inputBufferPosition, long inputBufferSize) = context.Request.GetBufferType0x21();
|
||||
(long outputBufferPosition, long outputBufferSize) = context.Request.GetBufferType0x22();
|
||||
(long optionsBufferPosition, long optionsBufferSize) = context.Request.GetBufferType0x21();
|
||||
(ulong inputBufferPosition, ulong inputBufferSize) = context.Request.GetBufferType0x21();
|
||||
(ulong outputBufferPosition, ulong outputBufferSize) = context.Request.GetBufferType0x22();
|
||||
(ulong optionsBufferPosition, ulong optionsBufferSize) = context.Request.GetBufferType0x21();
|
||||
|
||||
return GetHostByAddrRequestImpl(context, inputBufferPosition, inputBufferSize, outputBufferPosition, outputBufferSize, optionsBufferPosition, optionsBufferSize);
|
||||
}
|
||||
|
@ -210,17 +210,17 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres
|
|||
// GetAddrInfoRequestWithOptions(bool enable_nsd_resolve, u32, u64 pid_placeholder, pid, buffer<i8, 5, 0> host, buffer<i8, 5, 0> service, buffer<packed_addrinfo, 5, 0> hints, buffer<unknown, 21, 0>) -> (i32 ret, u32 bsd_errno, u32 unknown, u32 packed_addrinfo_size, buffer<packed_addrinfo, 22, 0> response)
|
||||
public ResultCode GetAddrInfoRequestWithOptions(ServiceCtx context)
|
||||
{
|
||||
(long responseBufferPosition, long responseBufferSize) = context.Request.GetBufferType0x22();
|
||||
(long optionsBufferPosition, long optionsBufferSize) = context.Request.GetBufferType0x21();
|
||||
(ulong responseBufferPosition, ulong responseBufferSize) = context.Request.GetBufferType0x22();
|
||||
(ulong optionsBufferPosition, ulong optionsBufferSize) = context.Request.GetBufferType0x21();
|
||||
|
||||
return GetAddrInfoRequestImpl(context, responseBufferPosition, responseBufferSize, optionsBufferPosition, optionsBufferSize);
|
||||
}
|
||||
|
||||
private ResultCode GetHostByNameRequestImpl(ServiceCtx context, long inputBufferPosition, long inputBufferSize, long outputBufferPosition, long outputBufferSize, long optionsBufferPosition, long optionsBufferSize)
|
||||
private ResultCode GetHostByNameRequestImpl(ServiceCtx context, ulong inputBufferPosition, ulong inputBufferSize, ulong outputBufferPosition, ulong outputBufferSize, ulong optionsBufferPosition, ulong optionsBufferSize)
|
||||
{
|
||||
byte[] rawName = new byte[inputBufferSize];
|
||||
|
||||
context.Memory.Read((ulong)inputBufferPosition, rawName);
|
||||
context.Memory.Read(inputBufferPosition, rawName);
|
||||
|
||||
string name = Encoding.ASCII.GetString(rawName).TrimEnd('\0');
|
||||
|
||||
|
@ -238,7 +238,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres
|
|||
|
||||
NetDbError netDbErrorCode = NetDbError.Success;
|
||||
GaiError errno = GaiError.Overflow;
|
||||
long serializedSize = 0;
|
||||
ulong serializedSize = 0;
|
||||
|
||||
if (name.Length <= byte.MaxValue)
|
||||
{
|
||||
|
@ -294,11 +294,11 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres
|
|||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
private ResultCode GetHostByAddrRequestImpl(ServiceCtx context, long inputBufferPosition, long inputBufferSize, long outputBufferPosition, long outputBufferSize, long optionsBufferPosition, long optionsBufferSize)
|
||||
private ResultCode GetHostByAddrRequestImpl(ServiceCtx context, ulong inputBufferPosition, ulong inputBufferSize, ulong outputBufferPosition, ulong outputBufferSize, ulong optionsBufferPosition, ulong optionsBufferSize)
|
||||
{
|
||||
byte[] rawIp = new byte[inputBufferSize];
|
||||
|
||||
context.Memory.Read((ulong)inputBufferPosition, rawIp);
|
||||
context.Memory.Read(inputBufferPosition, rawIp);
|
||||
|
||||
// TODO: Use params.
|
||||
uint socketLength = context.RequestData.ReadUInt32();
|
||||
|
@ -315,7 +315,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres
|
|||
|
||||
NetDbError netDbErrorCode = NetDbError.Success;
|
||||
GaiError errno = GaiError.AddressFamily;
|
||||
long serializedSize = 0;
|
||||
ulong serializedSize = 0;
|
||||
|
||||
if (rawIp.Length == 4)
|
||||
{
|
||||
|
@ -349,59 +349,59 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres
|
|||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
private long SerializeHostEntries(ServiceCtx context, long outputBufferPosition, long outputBufferSize, IPHostEntry hostEntry, IEnumerable<IPAddress> addresses = null)
|
||||
private ulong SerializeHostEntries(ServiceCtx context, ulong outputBufferPosition, ulong outputBufferSize, IPHostEntry hostEntry, IEnumerable<IPAddress> addresses = null)
|
||||
{
|
||||
long originalBufferPosition = outputBufferPosition;
|
||||
long bufferPosition = originalBufferPosition;
|
||||
ulong originalBufferPosition = outputBufferPosition;
|
||||
ulong bufferPosition = originalBufferPosition;
|
||||
|
||||
string hostName = hostEntry.HostName + '\0';
|
||||
|
||||
// h_name
|
||||
context.Memory.Write((ulong)bufferPosition, Encoding.ASCII.GetBytes(hostName));
|
||||
bufferPosition += hostName.Length;
|
||||
context.Memory.Write(bufferPosition, Encoding.ASCII.GetBytes(hostName));
|
||||
bufferPosition += (ulong)hostName.Length;
|
||||
|
||||
// h_aliases list size
|
||||
context.Memory.Write((ulong)bufferPosition, BinaryPrimitives.ReverseEndianness(hostEntry.Aliases.Length));
|
||||
bufferPosition += 4;
|
||||
context.Memory.Write(bufferPosition, BinaryPrimitives.ReverseEndianness(hostEntry.Aliases.Length));
|
||||
bufferPosition += sizeof(int);
|
||||
|
||||
// Actual aliases
|
||||
foreach (string alias in hostEntry.Aliases)
|
||||
{
|
||||
context.Memory.Write((ulong)bufferPosition, Encoding.ASCII.GetBytes(alias + '\0'));
|
||||
bufferPosition += alias.Length + 1;
|
||||
context.Memory.Write(bufferPosition, Encoding.ASCII.GetBytes(alias + '\0'));
|
||||
bufferPosition += (ulong)(alias.Length + 1);
|
||||
}
|
||||
|
||||
// h_addrtype but it's a short (also only support IPv4)
|
||||
context.Memory.Write((ulong)bufferPosition, BinaryPrimitives.ReverseEndianness((short)AddressFamily.InterNetwork));
|
||||
bufferPosition += 2;
|
||||
context.Memory.Write(bufferPosition, BinaryPrimitives.ReverseEndianness((short)AddressFamily.InterNetwork));
|
||||
bufferPosition += sizeof(short);
|
||||
|
||||
// h_length but it's a short
|
||||
context.Memory.Write((ulong)bufferPosition, BinaryPrimitives.ReverseEndianness((short)4));
|
||||
bufferPosition += 2;
|
||||
context.Memory.Write(bufferPosition, BinaryPrimitives.ReverseEndianness((short)4));
|
||||
bufferPosition += sizeof(short);
|
||||
|
||||
// Ip address count, we can only support ipv4 (blame Nintendo)
|
||||
context.Memory.Write((ulong)bufferPosition, addresses != null ? BinaryPrimitives.ReverseEndianness(addresses.Count()) : 0);
|
||||
bufferPosition += 4;
|
||||
context.Memory.Write(bufferPosition, addresses != null ? BinaryPrimitives.ReverseEndianness(addresses.Count()) : 0);
|
||||
bufferPosition += sizeof(int);
|
||||
|
||||
if (addresses != null)
|
||||
{
|
||||
foreach (IPAddress ip in addresses)
|
||||
{
|
||||
context.Memory.Write((ulong)bufferPosition, BinaryPrimitives.ReverseEndianness(BitConverter.ToInt32(ip.GetAddressBytes(), 0)));
|
||||
bufferPosition += 4;
|
||||
context.Memory.Write(bufferPosition, BinaryPrimitives.ReverseEndianness(BitConverter.ToInt32(ip.GetAddressBytes(), 0)));
|
||||
bufferPosition += sizeof(int);
|
||||
}
|
||||
}
|
||||
|
||||
return bufferPosition - originalBufferPosition;
|
||||
}
|
||||
|
||||
private ResultCode GetAddrInfoRequestImpl(ServiceCtx context, long responseBufferPosition, long responseBufferSize, long optionsBufferPosition, long optionsBufferSize)
|
||||
private ResultCode GetAddrInfoRequestImpl(ServiceCtx context, ulong responseBufferPosition, ulong responseBufferSize, ulong optionsBufferPosition, ulong optionsBufferSize)
|
||||
{
|
||||
bool enableNsdResolve = (context.RequestData.ReadInt32() & 1) != 0;
|
||||
uint cancelHandle = context.RequestData.ReadUInt32();
|
||||
|
||||
string host = MemoryHelper.ReadAsciiString(context.Memory, context.Request.SendBuff[0].Position, context.Request.SendBuff[0].Size);
|
||||
string service = MemoryHelper.ReadAsciiString(context.Memory, context.Request.SendBuff[1].Position, context.Request.SendBuff[1].Size);
|
||||
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);
|
||||
|
||||
// NOTE: We ignore hints for now.
|
||||
DeserializeAddrInfos(context.Memory, (ulong)context.Request.SendBuff[2].Position, (ulong)context.Request.SendBuff[2].Size);
|
||||
|
@ -500,7 +500,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres
|
|||
}
|
||||
}
|
||||
|
||||
private ulong SerializeAddrInfos(ServiceCtx context, long responseBufferPosition, long responseBufferSize, IPHostEntry hostEntry, int port)
|
||||
private ulong SerializeAddrInfos(ServiceCtx context, ulong responseBufferPosition, ulong responseBufferSize, IPHostEntry hostEntry, int port)
|
||||
{
|
||||
ulong originalBufferPosition = (ulong)responseBufferPosition;
|
||||
ulong bufferPosition = originalBufferPosition;
|
||||
|
@ -533,7 +533,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres
|
|||
|
||||
// Termination zero value.
|
||||
context.Memory.Write(bufferPosition, 0);
|
||||
bufferPosition += 4;
|
||||
bufferPosition += sizeof(int);
|
||||
|
||||
return bufferPosition - originalBufferPosition;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue