ios: treat return values as s32

This commit is contained in:
Shawn Hoffman 2017-06-07 04:27:32 -07:00
parent 5b5c630afb
commit 983f70c9ea
9 changed files with 59 additions and 52 deletions

View File

@ -14,6 +14,7 @@
#include "Common/CommonTypes.h"
#include "Core/CoreTiming.h"
#include "Core/HW/Memmap.h"
#include "Core/HW/SystemTimers.h"
#include "Core/IOS/IOSC.h"
@ -82,6 +83,12 @@ enum ProcessId : u32
PID_UNKNOWN = 19,
};
template <typename T>
void WriteReturnValue(T value, u32 address)
{
Memory::Write_U32(static_cast<u32>(value), address);
}
// HLE for the IOS kernel: IPC, device management, syscalls, and Dolphin-specific, IOS-wide calls.
class Kernel
{

View File

@ -13,7 +13,7 @@ namespace HLE
{
namespace NWC24
{
enum ErrorCode : int
enum ErrorCode : s32
{
WC24_OK = 0,
WC24_ERR_FATAL = -1,

View File

@ -41,7 +41,7 @@ IPCCommandResult NetKDRequest::IOCtl(const IOCtlRequest& request)
case IOCTL_NWC24_SUSPEND_SCHEDULAR:
// NWC24iResumeForCloseLib from NWC24SuspendScheduler (Input: none, Output: 32 bytes)
INFO_LOG(IOS_WC24, "NET_KD_REQ: IOCTL_NWC24_SUSPEND_SCHEDULAR - NI");
Memory::Write_U32(0, request.buffer_out); // no error
WriteReturnValue(0, request.buffer_out); // no error
break;
case IOCTL_NWC24_EXEC_TRY_SUSPEND_SCHEDULAR: // NWC24iResumeForCloseLib
@ -50,11 +50,11 @@ IPCCommandResult NetKDRequest::IOCtl(const IOCtlRequest& request)
case IOCTL_NWC24_EXEC_RESUME_SCHEDULAR: // NWC24iResumeForCloseLib
INFO_LOG(IOS_WC24, "NET_KD_REQ: IOCTL_NWC24_EXEC_RESUME_SCHEDULAR - NI");
Memory::Write_U32(0, request.buffer_out); // no error
WriteReturnValue(0, request.buffer_out); // no error
break;
case IOCTL_NWC24_STARTUP_SOCKET: // NWC24iStartupSocket
Memory::Write_U32(0, request.buffer_out);
WriteReturnValue(0, request.buffer_out);
Memory::Write_U32(0, request.buffer_out + 4);
return_value = 0;
INFO_LOG(IOS_WC24, "NET_KD_REQ: IOCTL_NWC24_STARTUP_SOCKET - NI");
@ -74,7 +74,7 @@ IPCCommandResult NetKDRequest::IOCtl(const IOCtlRequest& request)
case IOCTL_NWC24_REQUEST_REGISTER_USER_ID:
INFO_LOG(IOS_WC24, "NET_KD_REQ: IOCTL_NWC24_REQUEST_REGISTER_USER_ID");
Memory::Write_U32(0, request.buffer_out);
WriteReturnValue(0, request.buffer_out);
Memory::Write_U32(0, request.buffer_out + 4);
break;
@ -110,20 +110,20 @@ IPCCommandResult NetKDRequest::IOCtl(const IOCtlRequest& request)
config.SetCreationStage(NWC24::NWC24Config::NWC24_IDCS_GENERATED);
config.WriteConfig();
Memory::Write_U32(ret, request.buffer_out);
WriteReturnValue(ret, request.buffer_out);
}
else
{
Memory::Write_U32(NWC24::WC24_ERR_FATAL, request.buffer_out);
WriteReturnValue(NWC24::WC24_ERR_FATAL, request.buffer_out);
}
}
else if (config.CreationStage() == NWC24::NWC24Config::NWC24_IDCS_GENERATED)
{
Memory::Write_U32(NWC24::WC24_ERR_ID_GENERATED, request.buffer_out);
WriteReturnValue(NWC24::WC24_ERR_ID_GENERATED, request.buffer_out);
}
else if (config.CreationStage() == NWC24::NWC24Config::NWC24_IDCS_REGISTERED)
{
Memory::Write_U32(NWC24::WC24_ERR_ID_REGISTERED, request.buffer_out);
WriteReturnValue(NWC24::WC24_ERR_ID_REGISTERED, request.buffer_out);
}
Memory::Write_U64(config.Id(), request.buffer_out + 4);
Memory::Write_U32(config.CreationStage(), request.buffer_out + 0xC);

View File

@ -221,12 +221,12 @@ IPCCommandResult NetSSL::IOCtlV(const IOCtlVRequest& request)
mbedtls_ssl_set_hostname(&ssl->ctx, ssl->hostname.c_str());
ssl->active = true;
Memory::Write_U32(freeSSL, BufferIn);
WriteReturnValue(freeSSL, BufferIn);
}
else
{
_SSL_NEW_ERROR:
Memory::Write_U32(SSL_ERR_FAILED, BufferIn);
WriteReturnValue(SSL_ERR_FAILED, BufferIn);
}
INFO_LOG(IOS_SSL, "IOCTLV_NET_SSL_NEW (%d, %s) "
@ -260,11 +260,11 @@ IPCCommandResult NetSSL::IOCtlV(const IOCtlVRequest& request)
ssl->active = false;
Memory::Write_U32(SSL_OK, BufferIn);
WriteReturnValue(SSL_OK, BufferIn);
}
else
{
Memory::Write_U32(SSL_ERR_ID, BufferIn);
WriteReturnValue(SSL_ERR_ID, BufferIn);
}
INFO_LOG(IOS_SSL, "IOCTLV_NET_SSL_SHUTDOWN "
"BufferIn: (%08x, %i), BufferIn2: (%08x, %i), "
@ -298,19 +298,19 @@ IPCCommandResult NetSSL::IOCtlV(const IOCtlVRequest& request)
if (ret)
{
Memory::Write_U32(SSL_ERR_FAILED, BufferIn);
WriteReturnValue(SSL_ERR_FAILED, BufferIn);
}
else
{
mbedtls_ssl_conf_ca_chain(&ssl->config, &ssl->cacert, nullptr);
Memory::Write_U32(SSL_OK, BufferIn);
WriteReturnValue(SSL_OK, BufferIn);
}
INFO_LOG(IOS_SSL, "IOCTLV_NET_SSL_SETROOTCA = %d", ret);
}
else
{
Memory::Write_U32(SSL_ERR_ID, BufferIn);
WriteReturnValue(SSL_ERR_ID, BufferIn);
}
break;
}
@ -339,19 +339,19 @@ IPCCommandResult NetSSL::IOCtlV(const IOCtlVRequest& request)
{
mbedtls_x509_crt_free(&ssl->clicert);
mbedtls_pk_free(&ssl->pk);
Memory::Write_U32(SSL_ERR_FAILED, BufferIn);
WriteReturnValue(SSL_ERR_FAILED, BufferIn);
}
else
{
mbedtls_ssl_conf_own_cert(&ssl->config, &ssl->clicert, &ssl->pk);
Memory::Write_U32(SSL_OK, BufferIn);
WriteReturnValue(SSL_OK, BufferIn);
}
INFO_LOG(IOS_SSL, "IOCTLV_NET_SSL_SETBUILTINCLIENTCERT = (%d, %d)", ret, pk_ret);
}
else
{
Memory::Write_U32(SSL_ERR_ID, BufferIn);
WriteReturnValue(SSL_ERR_ID, BufferIn);
INFO_LOG(IOS_SSL, "IOCTLV_NET_SSL_SETBUILTINCLIENTCERT invalid sslID = %d", sslID);
}
break;
@ -373,11 +373,11 @@ IPCCommandResult NetSSL::IOCtlV(const IOCtlVRequest& request)
mbedtls_pk_free(&ssl->pk);
mbedtls_ssl_conf_own_cert(&ssl->config, nullptr, nullptr);
Memory::Write_U32(SSL_OK, BufferIn);
WriteReturnValue(SSL_OK, BufferIn);
}
else
{
Memory::Write_U32(SSL_ERR_ID, BufferIn);
WriteReturnValue(SSL_ERR_ID, BufferIn);
INFO_LOG(IOS_SSL, "IOCTLV_NET_SSL_SETBUILTINCLIENTCERT invalid sslID = %d", sslID);
}
break;
@ -395,18 +395,18 @@ IPCCommandResult NetSSL::IOCtlV(const IOCtlVRequest& request)
if (ret)
{
mbedtls_x509_crt_free(&ssl->clicert);
Memory::Write_U32(SSL_ERR_FAILED, BufferIn);
WriteReturnValue(SSL_ERR_FAILED, BufferIn);
}
else
{
mbedtls_ssl_conf_ca_chain(&ssl->config, &ssl->cacert, nullptr);
Memory::Write_U32(SSL_OK, BufferIn);
WriteReturnValue(SSL_OK, BufferIn);
}
INFO_LOG(IOS_SSL, "IOCTLV_NET_SSL_SETBUILTINROOTCA = %d", ret);
}
else
{
Memory::Write_U32(SSL_ERR_ID, BufferIn);
WriteReturnValue(SSL_ERR_ID, BufferIn);
}
INFO_LOG(IOS_SSL, "IOCTLV_NET_SSL_SETBUILTINROOTCA "
"BufferIn: (%08x, %i), BufferIn2: (%08x, %i), "
@ -428,11 +428,11 @@ IPCCommandResult NetSSL::IOCtlV(const IOCtlVRequest& request)
ssl->hostfd = sm.GetHostSocket(ssl->sockfd);
INFO_LOG(IOS_SSL, "IOCTLV_NET_SSL_CONNECT socket = %d", ssl->sockfd);
mbedtls_ssl_set_bio(&ssl->ctx, &ssl->hostfd, mbedtls_net_send, mbedtls_net_recv, nullptr);
Memory::Write_U32(SSL_OK, BufferIn);
WriteReturnValue(SSL_OK, BufferIn);
}
else
{
Memory::Write_U32(SSL_ERR_ID, BufferIn);
WriteReturnValue(SSL_ERR_ID, BufferIn);
}
INFO_LOG(IOS_SSL, "IOCTLV_NET_SSL_CONNECT "
"BufferIn: (%08x, %i), BufferIn2: (%08x, %i), "
@ -453,7 +453,7 @@ IPCCommandResult NetSSL::IOCtlV(const IOCtlVRequest& request)
}
else
{
Memory::Write_U32(SSL_ERR_ID, BufferIn);
WriteReturnValue(SSL_ERR_ID, BufferIn);
}
break;
}
@ -468,7 +468,7 @@ IPCCommandResult NetSSL::IOCtlV(const IOCtlVRequest& request)
}
else
{
Memory::Write_U32(SSL_ERR_ID, BufferIn);
WriteReturnValue(SSL_ERR_ID, BufferIn);
}
INFO_LOG(IOS_SSL, "IOCTLV_NET_SSL_WRITE "
"BufferIn: (%08x, %i), BufferIn2: (%08x, %i), "
@ -491,7 +491,7 @@ IPCCommandResult NetSSL::IOCtlV(const IOCtlVRequest& request)
}
else
{
Memory::Write_U32(SSL_ERR_ID, BufferIn);
WriteReturnValue(SSL_ERR_ID, BufferIn);
}
INFO_LOG(IOS_SSL, "IOCTLV_NET_SSL_READ(%d)"
@ -507,11 +507,11 @@ IPCCommandResult NetSSL::IOCtlV(const IOCtlVRequest& request)
int sslID = Memory::Read_U32(BufferOut) - 1;
if (SSLID_VALID(sslID))
{
Memory::Write_U32(SSL_OK, BufferIn);
WriteReturnValue(SSL_OK, BufferIn);
}
else
{
Memory::Write_U32(SSL_ERR_ID, BufferIn);
WriteReturnValue(SSL_ERR_ID, BufferIn);
}
INFO_LOG(IOS_SSL, "IOCTLV_NET_SSL_SETROOTCADEFAULT "
"BufferIn: (%08x, %i), BufferIn2: (%08x, %i), "
@ -533,11 +533,11 @@ IPCCommandResult NetSSL::IOCtlV(const IOCtlVRequest& request)
int sslID = Memory::Read_U32(BufferOut) - 1;
if (SSLID_VALID(sslID))
{
Memory::Write_U32(SSL_OK, BufferIn);
WriteReturnValue(SSL_OK, BufferIn);
}
else
{
Memory::Write_U32(SSL_ERR_ID, BufferIn);
WriteReturnValue(SSL_ERR_ID, BufferIn);
}
break;
}

View File

@ -32,7 +32,7 @@ namespace HLE
#define SSLID_VALID(x) \
(x >= 0 && x < NET_SSL_MAXINSTANCES && ::IOS::HLE::Device::NetSSL::_SSL[x].active)
enum ssl_err_t
enum ssl_err_t : s32
{
SSL_OK = 0,
SSL_ERR_FAILED = -1,

View File

@ -335,15 +335,15 @@ void WiiSocket::Update(bool read, bool write, bool except)
switch (ret)
{
case 0:
Memory::Write_U32(SSL_OK, BufferIn);
WriteReturnValue(SSL_OK, BufferIn);
break;
case MBEDTLS_ERR_SSL_WANT_READ:
Memory::Write_U32(SSL_ERR_RAGAIN, BufferIn);
WriteReturnValue(SSL_ERR_RAGAIN, BufferIn);
if (!nonBlock)
ReturnValue = SSL_ERR_RAGAIN;
break;
case MBEDTLS_ERR_SSL_WANT_WRITE:
Memory::Write_U32(SSL_ERR_WAGAIN, BufferIn);
WriteReturnValue(SSL_ERR_WAGAIN, BufferIn);
if (!nonBlock)
ReturnValue = SSL_ERR_WAGAIN;
break;
@ -366,13 +366,13 @@ void WiiSocket::Update(bool read, bool write, bool except)
else
res = SSL_ERR_FAILED;
Memory::Write_U32(res, BufferIn);
WriteReturnValue(res, BufferIn);
if (!nonBlock)
ReturnValue = res;
break;
}
default:
Memory::Write_U32(SSL_ERR_FAILED, BufferIn);
WriteReturnValue(SSL_ERR_FAILED, BufferIn);
break;
}
@ -412,24 +412,24 @@ void WiiSocket::Update(bool read, bool write, bool except)
if (ret >= 0)
{
// Return bytes written or SSL_ERR_ZERO if none
Memory::Write_U32((ret == 0) ? SSL_ERR_ZERO : ret, BufferIn);
WriteReturnValue((ret == 0) ? SSL_ERR_ZERO : ret, BufferIn);
}
else
{
switch (ret)
{
case MBEDTLS_ERR_SSL_WANT_READ:
Memory::Write_U32(SSL_ERR_RAGAIN, BufferIn);
WriteReturnValue(SSL_ERR_RAGAIN, BufferIn);
if (!nonBlock)
ReturnValue = SSL_ERR_RAGAIN;
break;
case MBEDTLS_ERR_SSL_WANT_WRITE:
Memory::Write_U32(SSL_ERR_WAGAIN, BufferIn);
WriteReturnValue(SSL_ERR_WAGAIN, BufferIn);
if (!nonBlock)
ReturnValue = SSL_ERR_WAGAIN;
break;
default:
Memory::Write_U32(SSL_ERR_FAILED, BufferIn);
WriteReturnValue(SSL_ERR_FAILED, BufferIn);
break;
}
}
@ -450,24 +450,24 @@ void WiiSocket::Update(bool read, bool write, bool except)
if (ret >= 0)
{
// Return bytes read or SSL_ERR_ZERO if none
Memory::Write_U32((ret == 0) ? SSL_ERR_ZERO : ret, BufferIn);
WriteReturnValue((ret == 0) ? SSL_ERR_ZERO : ret, BufferIn);
}
else
{
switch (ret)
{
case MBEDTLS_ERR_SSL_WANT_READ:
Memory::Write_U32(SSL_ERR_RAGAIN, BufferIn);
WriteReturnValue(SSL_ERR_RAGAIN, BufferIn);
if (!nonBlock)
ReturnValue = SSL_ERR_RAGAIN;
break;
case MBEDTLS_ERR_SSL_WANT_WRITE:
Memory::Write_U32(SSL_ERR_WAGAIN, BufferIn);
WriteReturnValue(SSL_ERR_WAGAIN, BufferIn);
if (!nonBlock)
ReturnValue = SSL_ERR_WAGAIN;
break;
default:
Memory::Write_U32(SSL_ERR_FAILED, BufferIn);
WriteReturnValue(SSL_ERR_FAILED, BufferIn);
break;
}
}
@ -479,7 +479,7 @@ void WiiSocket::Update(bool read, bool write, bool except)
}
else
{
Memory::Write_U32(SSL_ERR_ID, BufferIn);
WriteReturnValue(SSL_ERR_ID, BufferIn);
}
}
else

View File

@ -134,7 +134,7 @@ IPCCommandResult SDIOSlot0::IOCtlV(const IOCtlVRequest& request)
return GetDefaultReply(IPC_SUCCESS);
}
u32 SDIOSlot0::ExecuteCommand(const Request& request, u32 _BufferIn, u32 _BufferInSize,
s32 SDIOSlot0::ExecuteCommand(const Request& request, u32 _BufferIn, u32 _BufferInSize,
u32 _rwBuffer, u32 _rwBufferSize, u32 _BufferOut, u32 _BufferOutSize)
{
// The game will send us a SendCMD with this information. To be able to read and write
@ -164,7 +164,7 @@ u32 SDIOSlot0::ExecuteCommand(const Request& request, u32 _BufferIn, u32 _Buffer
// Note: req.addr is the virtual address of _rwBuffer
u32 ret = RET_OK;
s32 ret = RET_OK;
switch (req.command)
{

View File

@ -128,7 +128,7 @@ private:
IPCCommandResult SendCommand(const IOCtlVRequest& request);
u32 ExecuteCommand(const Request& request, u32 BufferIn, u32 BufferInSize, u32 BufferIn2,
s32 ExecuteCommand(const Request& request, u32 BufferIn, u32 BufferInSize, u32 BufferIn2,
u32 BufferInSize2, u32 _BufferOut, u32 BufferOutSize);
void OpenInternal();

View File

@ -86,7 +86,7 @@ WFSI::WFSI(Kernel& ios, const std::string& device_name) : Device(ios, device_nam
IPCCommandResult WFSI::IOCtl(const IOCtlRequest& request)
{
u32 return_error_code = IPC_SUCCESS;
s32 return_error_code = IPC_SUCCESS;
switch (request.request)
{