Merge pull request #12441 from lioncash/ios

Core/IOS/IOS: Remove global system accessors
This commit is contained in:
Admiral H. Curtiss 2023-12-18 23:30:38 +01:00 committed by GitHub
commit 57b4379364
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 118 additions and 125 deletions

View File

@ -572,7 +572,7 @@ bool CBoot::BootUp(Core::System& system, const Core::CPUThreadGuard& guard,
// Because there is no TMD to get the requested system (IOS) version from, // Because there is no TMD to get the requested system (IOS) version from,
// we default to IOS58, which is the version used by the Homebrew Channel. // we default to IOS58, which is the version used by the Homebrew Channel.
SetupWiiMemory(system, IOS::HLE::IOSC::ConsoleType::Retail); SetupWiiMemory(system, IOS::HLE::IOSC::ConsoleType::Retail);
IOS::HLE::GetIOS()->BootIOS(system, Titles::IOS(58)); IOS::HLE::GetIOS()->BootIOS(Titles::IOS(58));
} }
else else
{ {

View File

@ -559,7 +559,7 @@ bool CBoot::EmulatedBS2_Wii(Core::System& system, const Core::CPUThreadGuard& gu
const u64 ios = ios_override >= 0 ? Titles::IOS(static_cast<u32>(ios_override)) : tmd.GetIOSId(); const u64 ios = ios_override >= 0 ? Titles::IOS(static_cast<u32>(ios_override)) : tmd.GetIOSId();
const auto console_type = volume.GetTicket(data_partition).GetConsoleType(); const auto console_type = volume.GetTicket(data_partition).GetConsoleType();
if (!SetupWiiMemory(system, console_type) || !IOS::HLE::GetIOS()->BootIOS(system, ios)) if (!SetupWiiMemory(system, console_type) || !IOS::HLE::GetIOS()->BootIOS(ios))
return false; return false;
auto di = auto di =
@ -592,7 +592,7 @@ bool CBoot::EmulatedBS2_Wii(Core::System& system, const Core::CPUThreadGuard& gu
return false; return false;
// The Apploader probably just overwrote values needed for RAM Override. Run this again! // The Apploader probably just overwrote values needed for RAM Override. Run this again!
IOS::HLE::RAMOverrideForIOSMemoryValues(IOS::HLE::MemorySetupType::IOSReload); IOS::HLE::RAMOverrideForIOSMemoryValues(memory, IOS::HLE::MemorySetupType::IOSReload);
// Warning: This call will set incorrect running game metadata if our volume parameter // Warning: This call will set incorrect running game metadata if our volume parameter
// doesn't point to the same disc as the one that's inserted in the emulated disc drive! // doesn't point to the same disc as the one that's inserted in the emulated disc drive!

View File

@ -57,7 +57,7 @@ void Init(Core::System& system, const Sram* override_sram)
if (SConfig::GetInstance().bWii) if (SConfig::GetInstance().bWii)
{ {
IOS::Init(); IOS::Init();
IOS::HLE::Init(); // Depends on Memory IOS::HLE::Init(system); // Depends on Memory
} }
} }

View File

@ -120,7 +120,7 @@ private:
}; };
friend class ::CBoot; friend class ::CBoot;
friend void ::IOS::HLE::Init(); friend void ::IOS::HLE::Init(Core::System&);
void ProcessQueuedIOCtl(); void ProcessQueuedIOCtl();
std::optional<DIResult> StartIOCtl(const IOCtlRequest& request); std::optional<DIResult> StartIOCtl(const IOCtlRequest& request);

View File

@ -374,7 +374,7 @@ bool ESDevice::LaunchIOS(u64 ios_title_id, HangPPC hang_ppc)
const ES::TicketReader ticket = m_core.FindSignedTicket(ios_title_id); const ES::TicketReader ticket = m_core.FindSignedTicket(ios_title_id);
ES::Content content; ES::Content content;
if (!tmd.IsValid() || !ticket.IsValid() || !tmd.GetContent(tmd.GetBootIndex(), &content) || if (!tmd.IsValid() || !ticket.IsValid() || !tmd.GetContent(tmd.GetBootIndex(), &content) ||
!GetEmulationKernel().BootIOS(GetSystem(), ios_title_id, hang_ppc, !GetEmulationKernel().BootIOS(ios_title_id, hang_ppc,
m_core.GetContentPath(ios_title_id, content))) m_core.GetContentPath(ios_title_id, content)))
{ {
PanicAlertFmtT("Could not launch IOS {0:016x} because it is missing from the NAND.\n" PanicAlertFmtT("Could not launch IOS {0:016x} because it is missing from the NAND.\n"
@ -385,7 +385,7 @@ bool ESDevice::LaunchIOS(u64 ios_title_id, HangPPC hang_ppc)
return true; return true;
} }
return GetEmulationKernel().BootIOS(GetSystem(), ios_title_id, hang_ppc); return GetEmulationKernel().BootIOS(ios_title_id, hang_ppc);
} }
s32 ESDevice::WriteLaunchFile(const ES::TMDReader& tmd, Ticks ticks) s32 ESDevice::WriteLaunchFile(const ES::TMDReader& tmd, Ticks ticks)
@ -490,8 +490,7 @@ bool ESDevice::LaunchPPCTitle(u64 title_id)
bool ESDevice::BootstrapPPC() bool ESDevice::BootstrapPPC()
{ {
const bool result = const bool result = GetEmulationKernel().BootstrapPPC(m_pending_ppc_boot_content_path);
GetEmulationKernel().BootstrapPPC(GetSystem(), m_pending_ppc_boot_content_path);
m_pending_ppc_boot_content_path = {}; m_pending_ppc_boot_content_path = {};
return result; return result;
} }

View File

@ -105,11 +105,8 @@ constexpr u32 ADDR_DEVKIT_BOOT_PROGRAM_VERSION = 0x315e;
constexpr u32 ADDR_SYSMENU_SYNC = 0x3160; constexpr u32 ADDR_SYSMENU_SYNC = 0x3160;
constexpr u32 PLACEHOLDER = 0xDEADBEEF; constexpr u32 PLACEHOLDER = 0xDEADBEEF;
static bool SetupMemory(u64 ios_title_id, MemorySetupType setup_type) static bool SetupMemory(Memory::MemoryManager& memory, u64 ios_title_id, MemorySetupType setup_type)
{ {
auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory();
auto target_imv = std::find_if( auto target_imv = std::find_if(
GetMemoryValues().begin(), GetMemoryValues().end(), GetMemoryValues().begin(), GetMemoryValues().end(),
[&](const MemoryValues& imv) { return imv.ios_number == (ios_title_id & 0xffff); }); [&](const MemoryValues& imv) { return imv.ios_number == (ios_title_id & 0xffff); });
@ -143,8 +140,7 @@ static bool SetupMemory(u64 ios_title_id, MemorySetupType setup_type)
memory.Write_U32(target_imv->ios_reserved_begin, ADDR_IOS_RESERVED_BEGIN); memory.Write_U32(target_imv->ios_reserved_begin, ADDR_IOS_RESERVED_BEGIN);
memory.Write_U32(target_imv->ios_reserved_end, ADDR_IOS_RESERVED_END); memory.Write_U32(target_imv->ios_reserved_end, ADDR_IOS_RESERVED_END);
RAMOverrideForIOSMemoryValues(setup_type); RAMOverrideForIOSMemoryValues(memory, setup_type);
return true; return true;
} }
@ -187,8 +183,7 @@ static bool SetupMemory(u64 ios_title_id, MemorySetupType setup_type)
memory.Write_U32(target_imv->mem1_arena_end, ADDR_LEGACY_ARENA_HIGH); memory.Write_U32(target_imv->mem1_arena_end, ADDR_LEGACY_ARENA_HIGH);
memory.Write_U32(target_imv->mem1_simulated_size, ADDR_LEGACY_MEM_SIM_SIZE); memory.Write_U32(target_imv->mem1_simulated_size, ADDR_LEGACY_MEM_SIM_SIZE);
RAMOverrideForIOSMemoryValues(setup_type); RAMOverrideForIOSMemoryValues(memory, setup_type);
return true; return true;
} }
@ -196,22 +191,21 @@ static bool SetupMemory(u64 ios_title_id, MemorySetupType setup_type)
// by asserting the PPC's HRESET signal (via HW_RESETS). // by asserting the PPC's HRESET signal (via HW_RESETS).
// We will simulate that by resetting MSR and putting the PPC into an infinite loop. // We will simulate that by resetting MSR and putting the PPC into an infinite loop.
// The memory write will not be observable since the PPC is not running any code... // The memory write will not be observable since the PPC is not running any code...
static void ResetAndPausePPC() static void ResetAndPausePPC(Core::System& system)
{ {
// This should be cleared when the PPC is released so that the write is not observable. // This should be cleared when the PPC is released so that the write is not observable.
auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory(); auto& memory = system.GetMemory();
memory.Write_U32(0x48000000, 0x00000000); // b 0x0
auto& power_pc = system.GetPowerPC(); auto& power_pc = system.GetPowerPC();
memory.Write_U32(0x48000000, 0x00000000); // b 0x0
power_pc.Reset(); power_pc.Reset();
power_pc.GetPPCState().pc = 0; power_pc.GetPPCState().pc = 0;
} }
static void ReleasePPC() static void ReleasePPC(Core::System& system)
{ {
auto& system = Core::System::GetInstance(); system.GetMemory().Write_U32(0, 0);
auto& memory = system.GetMemory();
memory.Write_U32(0, 0);
// HLE the bootstub that jumps to 0x3400. // HLE the bootstub that jumps to 0x3400.
// NAND titles start with address translation off at 0x3400 (via the PPC bootstub) // NAND titles start with address translation off at 0x3400 (via the PPC bootstub)
// The state of other CPU registers (like the BAT registers) doesn't matter much // The state of other CPU registers (like the BAT registers) doesn't matter much
@ -219,26 +213,22 @@ static void ReleasePPC()
system.GetPPCState().pc = 0x3400; system.GetPPCState().pc = 0x3400;
} }
static void ReleasePPCAncast() static void ReleasePPCAncast(Core::System& system)
{ {
auto& system = Core::System::GetInstance(); system.GetMemory().Write_U32(0, 0);
auto& memory = system.GetMemory();
memory.Write_U32(0, 0);
// On a real console the Espresso verifies and decrypts the Ancast image, // On a real console the Espresso verifies and decrypts the Ancast image,
// then jumps to the decrypted ancast body. // then jumps to the decrypted ancast body.
// The Ancast loader already did this, so just jump to the decrypted body. // The Ancast loader already did this, so just jump to the decrypted body.
system.GetPPCState().pc = ESPRESSO_ANCAST_LOCATION_VIRT + sizeof(EspressoAncastHeader); system.GetPPCState().pc = ESPRESSO_ANCAST_LOCATION_VIRT + sizeof(EspressoAncastHeader);
} }
void RAMOverrideForIOSMemoryValues(MemorySetupType setup_type) void RAMOverrideForIOSMemoryValues(Memory::MemoryManager& memory, MemorySetupType setup_type)
{ {
// Don't touch anything if the feature isn't enabled. // Don't touch anything if the feature isn't enabled.
if (!Config::Get(Config::MAIN_RAM_OVERRIDE_ENABLE)) if (!Config::Get(Config::MAIN_RAM_OVERRIDE_ENABLE))
return; return;
auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory();
// Some unstated constants that can be inferred. // Some unstated constants that can be inferred.
const u32 ipc_buffer_size = const u32 ipc_buffer_size =
memory.Read_U32(ADDR_IPC_BUFFER_END) - memory.Read_U32(ADDR_IPC_BUFFER_BEGIN); memory.Read_U32(ADDR_IPC_BUFFER_END) - memory.Read_U32(ADDR_IPC_BUFFER_BEGIN);
@ -285,10 +275,8 @@ void RAMOverrideForIOSMemoryValues(MemorySetupType setup_type)
memory.Write_U32(ios_reserved_end, ADDR_IOS_RESERVED_END); memory.Write_U32(ios_reserved_end, ADDR_IOS_RESERVED_END);
} }
void WriteReturnValue(s32 value, u32 address) void WriteReturnValue(Memory::MemoryManager& memory, s32 value, u32 address)
{ {
auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory();
memory.Write_U32(static_cast<u32>(value), address); memory.Write_U32(static_cast<u32>(value), address);
} }
@ -324,7 +312,7 @@ EmulationKernel::EmulationKernel(Core::System& system, u64 title_id)
{ {
INFO_LOG_FMT(IOS, "Starting IOS {:016x}", title_id); INFO_LOG_FMT(IOS, "Starting IOS {:016x}", title_id);
if (!SetupMemory(title_id, MemorySetupType::IOSReload)) if (!SetupMemory(m_system.GetMemory(), title_id, MemorySetupType::IOSReload))
WARN_LOG_FMT(IOS, "No information about this IOS -- cannot set up memory values"); WARN_LOG_FMT(IOS, "No information about this IOS -- cannot set up memory values");
if (title_id == Titles::MIOS) if (title_id == Titles::MIOS)
@ -349,7 +337,7 @@ EmulationKernel::EmulationKernel(Core::System& system, u64 title_id)
EmulationKernel::~EmulationKernel() EmulationKernel::~EmulationKernel()
{ {
Core::System::GetInstance().GetCoreTiming().RemoveAllEvents(s_event_enqueue); m_system.GetCoreTiming().RemoveAllEvents(s_event_enqueue);
m_device_map.clear(); m_device_map.clear();
m_socket_manager.reset(); m_socket_manager.reset();
@ -434,7 +422,7 @@ static std::vector<u8> ReadBootContent(FSCore& fs, const std::string& path, size
// This corresponds to syscall 0x41, which loads a binary from the NAND and bootstraps the PPC. // This corresponds to syscall 0x41, which loads a binary from the NAND and bootstraps the PPC.
// Unlike 0x42, IOS will set up some constants in memory before booting the PPC. // Unlike 0x42, IOS will set up some constants in memory before booting the PPC.
bool EmulationKernel::BootstrapPPC(Core::System& system, const std::string& boot_content_path) bool EmulationKernel::BootstrapPPC(const std::string& boot_content_path)
{ {
// Seeking and processing overhead is ignored as most time is spent reading from the NAND. // Seeking and processing overhead is ignored as most time is spent reading from the NAND.
u64 ticks = 0; u64 ticks = 0;
@ -444,20 +432,20 @@ bool EmulationKernel::BootstrapPPC(Core::System& system, const std::string& boot
if (!dol.IsValid()) if (!dol.IsValid())
return false; return false;
if (!SetupMemory(m_title_id, MemorySetupType::Full)) if (!SetupMemory(m_system.GetMemory(), m_title_id, MemorySetupType::Full))
return false; return false;
// Reset the PPC and pause its execution until we're ready. // Reset the PPC and pause its execution until we're ready.
ResetAndPausePPC(); ResetAndPausePPC(m_system);
if (dol.IsAncast()) if (dol.IsAncast())
INFO_LOG_FMT(IOS, "BootstrapPPC: Loading ancast image"); INFO_LOG_FMT(IOS, "BootstrapPPC: Loading ancast image");
if (!dol.LoadIntoMemory(system)) if (!dol.LoadIntoMemory(m_system))
return false; return false;
INFO_LOG_FMT(IOS, "BootstrapPPC: {}", boot_content_path); INFO_LOG_FMT(IOS, "BootstrapPPC: {}", boot_content_path);
system.GetCoreTiming().ScheduleEvent(ticks, s_event_finish_ppc_bootstrap, dol.IsAncast()); m_system.GetCoreTiming().ScheduleEvent(ticks, s_event_finish_ppc_bootstrap, dol.IsAncast());
return true; return true;
} }
@ -508,7 +496,7 @@ static constexpr SystemTimers::TimeBaseTick GetIOSBootTicks(u32 version)
// Passing a boot content path is optional because we do not require IOSes // Passing a boot content path is optional because we do not require IOSes
// to be installed at the moment. If one is passed, the boot binary must exist // to be installed at the moment. If one is passed, the boot binary must exist
// on the NAND, or the call will fail like on a Wii. // on the NAND, or the call will fail like on a Wii.
bool EmulationKernel::BootIOS(Core::System& system, const u64 ios_title_id, HangPPC hang_ppc, bool EmulationKernel::BootIOS(const u64 ios_title_id, HangPPC hang_ppc,
const std::string& boot_content_path) const std::string& boot_content_path)
{ {
// IOS suspends regular PPC<->ARM IPC before loading a new IOS. // IOS suspends regular PPC<->ARM IPC before loading a new IOS.
@ -525,21 +513,21 @@ bool EmulationKernel::BootIOS(Core::System& system, const u64 ios_title_id, Hang
return false; return false;
ElfReader elf{binary.GetElf()}; ElfReader elf{binary.GetElf()};
if (!elf.LoadIntoMemory(system, true)) if (!elf.LoadIntoMemory(m_system, true))
return false; return false;
} }
if (hang_ppc == HangPPC::Yes) if (hang_ppc == HangPPC::Yes)
ResetAndPausePPC(); ResetAndPausePPC(m_system);
if (Core::IsRunningAndStarted()) if (Core::IsRunningAndStarted())
{ {
system.GetCoreTiming().ScheduleEvent(GetIOSBootTicks(GetVersion()), s_event_finish_ios_boot, m_system.GetCoreTiming().ScheduleEvent(GetIOSBootTicks(GetVersion()), s_event_finish_ios_boot,
ios_title_id); ios_title_id);
} }
else else
{ {
FinishIOSBoot(system, ios_title_id); FinishIOSBoot(m_system, ios_title_id);
} }
return true; return true;
@ -950,9 +938,9 @@ static void FinishPPCBootstrap(Core::System& system, u64 userdata, s64 cycles_la
// See Kernel::BootstrapPPC // See Kernel::BootstrapPPC
const bool is_ancast = userdata == 1; const bool is_ancast = userdata == 1;
if (is_ancast) if (is_ancast)
ReleasePPCAncast(); ReleasePPCAncast(system);
else else
ReleasePPC(); ReleasePPC(system);
ASSERT(Core::IsCPUThread()); ASSERT(Core::IsCPUThread());
Core::CPUThreadGuard guard(system); Core::CPUThreadGuard guard(system);
@ -961,9 +949,8 @@ static void FinishPPCBootstrap(Core::System& system, u64 userdata, s64 cycles_la
INFO_LOG_FMT(IOS, "Bootstrapping done."); INFO_LOG_FMT(IOS, "Bootstrapping done.");
} }
void Init() void Init(Core::System& system)
{ {
auto& system = Core::System::GetInstance();
auto& core_timing = system.GetCoreTiming(); auto& core_timing = system.GetCoreTiming();
s_event_enqueue = s_event_enqueue =
@ -991,7 +978,7 @@ void Init()
// This means that the constants in the 0x3100 region are always set up by the time // This means that the constants in the 0x3100 region are always set up by the time
// a game is launched. This is necessary because booting games from the game list skips // a game is launched. This is necessary because booting games from the game list skips
// a significant part of a Wii's boot process. // a significant part of a Wii's boot process.
SetupMemory(Titles::SYSTEM_MENU_IOS, MemorySetupType::Full); SetupMemory(system.GetMemory(), Titles::SYSTEM_MENU_IOS, MemorySetupType::Full);
} }
void Shutdown() void Shutdown()

View File

@ -23,6 +23,10 @@ namespace Core
{ {
class System; class System;
} }
namespace Memory
{
class MemoryManager;
}
namespace IOS::HLE namespace IOS::HLE
{ {
@ -109,9 +113,9 @@ enum class HangPPC : bool
Yes = true, Yes = true,
}; };
void RAMOverrideForIOSMemoryValues(MemorySetupType setup_type); void RAMOverrideForIOSMemoryValues(Memory::MemoryManager& memory, MemorySetupType setup_type);
void WriteReturnValue(s32 value, u32 address); void WriteReturnValue(Memory::MemoryManager& memory, s32 value, u32 address);
// HLE for the IOS kernel: IPC, device management, syscalls, and Dolphin-specific, IOS-wide calls. // HLE for the IOS kernel: IPC, device management, syscalls, and Dolphin-specific, IOS-wide calls.
class Kernel class Kernel
@ -177,8 +181,8 @@ public:
void SetGidForPPC(u16 gid); void SetGidForPPC(u16 gid);
u16 GetGidForPPC() const; u16 GetGidForPPC() const;
bool BootstrapPPC(Core::System& system, const std::string& boot_content_path); bool BootstrapPPC(const std::string& boot_content_path);
bool BootIOS(Core::System& system, u64 ios_title_id, HangPPC hang_ppc = HangPPC::No, bool BootIOS(u64 ios_title_id, HangPPC hang_ppc = HangPPC::No,
const std::string& boot_content_path = {}); const std::string& boot_content_path = {});
void InitIPC(); void InitIPC();
@ -212,7 +216,7 @@ private:
}; };
// Used for controlling and accessing an IOS instance that is tied to emulation. // Used for controlling and accessing an IOS instance that is tied to emulation.
void Init(); void Init(Core::System& system);
void Shutdown(); void Shutdown();
EmulationKernel* GetIOS(); EmulationKernel* GetIOS();

View File

@ -779,21 +779,21 @@ NWC24::ErrorCode NetKDRequestDevice::KDDownload(const u16 entry_index,
IPCReply NetKDRequestDevice::HandleNWC24CheckMailNow(const IOCtlRequest& request) IPCReply NetKDRequestDevice::HandleNWC24CheckMailNow(const IOCtlRequest& request)
{ {
auto& system = GetSystem();
auto& memory = system.GetMemory();
if (!m_handle_mail) if (!m_handle_mail)
{ {
LogError(ErrorType::CheckMail, NWC24::WC24_ERR_BROKEN); LogError(ErrorType::CheckMail, NWC24::WC24_ERR_BROKEN);
WriteReturnValue(NWC24::WC24_ERR_BROKEN, request.buffer_out); WriteReturnValue(memory, NWC24::WC24_ERR_BROKEN, request.buffer_out);
return IPCReply(IPC_SUCCESS); return IPCReply(IPC_SUCCESS);
} }
auto& system = GetSystem();
auto& memory = system.GetMemory();
u32 mail_flag{}; u32 mail_flag{};
u32 interval{}; u32 interval{};
const NWC24::ErrorCode reply = KDCheckMail(&mail_flag, &interval); const NWC24::ErrorCode reply = KDCheckMail(&mail_flag, &interval);
WriteReturnValue(reply, request.buffer_out); WriteReturnValue(memory, reply, request.buffer_out);
memory.Write_U32(mail_flag, request.buffer_out + 4); memory.Write_U32(mail_flag, request.buffer_out + 4);
memory.Write_U32(interval, request.buffer_out + 8); memory.Write_U32(interval, request.buffer_out + 8);
return IPCReply(IPC_SUCCESS); return IPCReply(IPC_SUCCESS);
@ -801,23 +801,26 @@ IPCReply NetKDRequestDevice::HandleNWC24CheckMailNow(const IOCtlRequest& request
IPCReply NetKDRequestDevice::HandleNWC24SendMailNow(const IOCtlRequest& request) IPCReply NetKDRequestDevice::HandleNWC24SendMailNow(const IOCtlRequest& request)
{ {
auto& memory = GetSystem().GetMemory();
const NWC24::ErrorCode reply = KDSendMail(); const NWC24::ErrorCode reply = KDSendMail();
WriteReturnValue(reply, request.buffer_out); WriteReturnValue(memory, reply, request.buffer_out);
return IPCReply(IPC_SUCCESS); return IPCReply(IPC_SUCCESS);
} }
IPCReply NetKDRequestDevice::HandleNWC24DownloadNowEx(const IOCtlRequest& request) IPCReply NetKDRequestDevice::HandleNWC24DownloadNowEx(const IOCtlRequest& request)
{ {
auto& system = GetSystem();
auto& memory = system.GetMemory();
if (m_dl_list.IsDisabled() || !m_dl_list.ReadDlList()) if (m_dl_list.IsDisabled() || !m_dl_list.ReadDlList())
{ {
// Signal that the DL List is broken. // Signal that the DL List is broken.
LogError(ErrorType::KD_Download, NWC24::WC24_ERR_BROKEN); LogError(ErrorType::KD_Download, NWC24::WC24_ERR_BROKEN);
WriteReturnValue(NWC24::WC24_ERR_BROKEN, request.buffer_out); WriteReturnValue(memory, NWC24::WC24_ERR_BROKEN, request.buffer_out);
return IPCReply(IPC_SUCCESS); return IPCReply(IPC_SUCCESS);
} }
auto& system = GetSystem();
auto& memory = system.GetMemory();
const u32 flags = memory.Read_U32(request.buffer_in); const u32 flags = memory.Read_U32(request.buffer_in);
// Nintendo converts the entry ID between a u32 and u16 // Nintendo converts the entry ID between a u32 and u16
// several times, presumably for alignment purposes. // several times, presumably for alignment purposes.
@ -833,7 +836,7 @@ IPCReply NetKDRequestDevice::HandleNWC24DownloadNowEx(const IOCtlRequest& reques
{ {
ERROR_LOG_FMT(IOS_WC24, "NET_KD_REQ: Entry index out of range."); ERROR_LOG_FMT(IOS_WC24, "NET_KD_REQ: Entry index out of range.");
LogError(ErrorType::KD_Download, NWC24::WC24_ERR_INVALID_VALUE); LogError(ErrorType::KD_Download, NWC24::WC24_ERR_INVALID_VALUE);
WriteReturnValue(NWC24::WC24_ERR_INVALID_VALUE, request.buffer_out); WriteReturnValue(memory, NWC24::WC24_ERR_INVALID_VALUE, request.buffer_out);
return IPCReply(IPC_SUCCESS); return IPCReply(IPC_SUCCESS);
} }
@ -841,7 +844,7 @@ IPCReply NetKDRequestDevice::HandleNWC24DownloadNowEx(const IOCtlRequest& reques
{ {
ERROR_LOG_FMT(IOS_WC24, "NET_KD_REQ: Requested entry does not exist in download list!"); ERROR_LOG_FMT(IOS_WC24, "NET_KD_REQ: Requested entry does not exist in download list!");
LogError(ErrorType::KD_Download, NWC24::WC24_ERR_NOT_FOUND); LogError(ErrorType::KD_Download, NWC24::WC24_ERR_NOT_FOUND);
WriteReturnValue(NWC24::WC24_ERR_NOT_FOUND, request.buffer_out); WriteReturnValue(memory, NWC24::WC24_ERR_NOT_FOUND, request.buffer_out);
return IPCReply(IPC_SUCCESS); return IPCReply(IPC_SUCCESS);
} }
@ -871,7 +874,7 @@ IPCReply NetKDRequestDevice::HandleNWC24DownloadNowEx(const IOCtlRequest& reques
reply = KDDownload(entry_index, std::nullopt); reply = KDDownload(entry_index, std::nullopt);
} }
WriteReturnValue(reply, request.buffer_out); WriteReturnValue(memory, reply, request.buffer_out);
return IPCReply(IPC_SUCCESS); return IPCReply(IPC_SUCCESS);
} }
@ -887,14 +890,14 @@ IPCReply NetKDRequestDevice::HandleRequestRegisterUserId(const IOS::HLE::IOCtlRe
// First check if the message config file is in the correct state to handle this. // First check if the message config file is in the correct state to handle this.
if (m_config.IsRegistered()) if (m_config.IsRegistered())
{ {
WriteReturnValue(NWC24::WC24_ERR_ID_REGISTERED, request.buffer_out); WriteReturnValue(memory, NWC24::WC24_ERR_ID_REGISTERED, request.buffer_out);
LogError(ErrorType::Account, NWC24::WC24_ERR_ID_REGISTERED); LogError(ErrorType::Account, NWC24::WC24_ERR_ID_REGISTERED);
return IPCReply{IPC_SUCCESS}; return IPCReply{IPC_SUCCESS};
} }
if (!m_config.IsGenerated()) if (!m_config.IsGenerated())
{ {
WriteReturnValue(NWC24::WC24_ERR_ID_NOT_GENERATED, request.buffer_out); WriteReturnValue(memory, NWC24::WC24_ERR_ID_NOT_GENERATED, request.buffer_out);
LogError(ErrorType::Account, NWC24::WC24_ERR_ID_NOT_GENERATED); LogError(ErrorType::Account, NWC24::WC24_ERR_ID_NOT_GENERATED);
return IPCReply{IPC_SUCCESS}; return IPCReply{IPC_SUCCESS};
} }
@ -905,7 +908,7 @@ IPCReply NetKDRequestDevice::HandleRequestRegisterUserId(const IOS::HLE::IOCtlRe
const auto file = m_ios.GetFS()->OpenFile(PID_KD, PID_KD, settings_file_path, FS::Mode::Read); const auto file = m_ios.GetFS()->OpenFile(PID_KD, PID_KD, settings_file_path, FS::Mode::Read);
if (!file) if (!file)
{ {
WriteReturnValue(NWC24::WC24_ERR_FILE_OPEN, request.buffer_out); WriteReturnValue(memory, NWC24::WC24_ERR_FILE_OPEN, request.buffer_out);
LogError(ErrorType::Account, NWC24::WC24_ERR_FILE_OPEN); LogError(ErrorType::Account, NWC24::WC24_ERR_FILE_OPEN);
return IPCReply{IPC_SUCCESS}; return IPCReply{IPC_SUCCESS};
} }
@ -913,7 +916,7 @@ IPCReply NetKDRequestDevice::HandleRequestRegisterUserId(const IOS::HLE::IOCtlRe
Common::SettingsHandler::Buffer data; Common::SettingsHandler::Buffer data;
if (!file->Read(data.data(), data.size())) if (!file->Read(data.data(), data.size()))
{ {
WriteReturnValue(NWC24::WC24_ERR_FILE_READ, request.buffer_out); WriteReturnValue(memory, NWC24::WC24_ERR_FILE_READ, request.buffer_out);
LogError(ErrorType::Account, NWC24::WC24_ERR_FILE_READ); LogError(ErrorType::Account, NWC24::WC24_ERR_FILE_READ);
return IPCReply{IPC_SUCCESS}; return IPCReply{IPC_SUCCESS};
} }
@ -929,7 +932,7 @@ IPCReply NetKDRequestDevice::HandleRequestRegisterUserId(const IOS::HLE::IOCtlRe
ERROR_LOG_FMT(IOS_WC24, ERROR_LOG_FMT(IOS_WC24,
"NET_KD_REQ: IOCTL_NWC24_REQUEST_REGISTER_USER_ID: Failed to request data at {}.", "NET_KD_REQ: IOCTL_NWC24_REQUEST_REGISTER_USER_ID: Failed to request data at {}.",
m_config.GetAccountURL()); m_config.GetAccountURL());
WriteReturnValue(NWC24::WC24_ERR_SERVER, request.buffer_out); WriteReturnValue(memory, NWC24::WC24_ERR_SERVER, request.buffer_out);
LogError(ErrorType::Account, NWC24::WC24_ERR_SERVER); LogError(ErrorType::Account, NWC24::WC24_ERR_SERVER);
return IPCReply{IPC_SUCCESS}; return IPCReply{IPC_SUCCESS};
} }
@ -942,7 +945,7 @@ IPCReply NetKDRequestDevice::HandleRequestRegisterUserId(const IOS::HLE::IOCtlRe
"NET_KD_REQ: IOCTL_NWC24_REQUEST_REGISTER_USER_ID: Mail server returned " "NET_KD_REQ: IOCTL_NWC24_REQUEST_REGISTER_USER_ID: Mail server returned "
"non-success code: {}", "non-success code: {}",
code); code);
WriteReturnValue(NWC24::WC24_ERR_SERVER, request.buffer_out); WriteReturnValue(memory, NWC24::WC24_ERR_SERVER, request.buffer_out);
LogError(ErrorType::Account, NWC24::WC24_ERR_SERVER); LogError(ErrorType::Account, NWC24::WC24_ERR_SERVER);
return IPCReply{IPC_SUCCESS}; return IPCReply{IPC_SUCCESS};
} }
@ -955,7 +958,7 @@ IPCReply NetKDRequestDevice::HandleRequestRegisterUserId(const IOS::HLE::IOCtlRe
"NET_KD_REQ: IOCTL_NWC24_REQUEST_REGISTER_USER_ID: Mail server returned invalid " "NET_KD_REQ: IOCTL_NWC24_REQUEST_REGISTER_USER_ID: Mail server returned invalid "
"mlchkid: {}", "mlchkid: {}",
mail_check_id); mail_check_id);
WriteReturnValue(NWC24::WC24_ERR_SERVER, request.buffer_out); WriteReturnValue(memory, NWC24::WC24_ERR_SERVER, request.buffer_out);
LogError(ErrorType::Account, NWC24::WC24_ERR_SERVER); LogError(ErrorType::Account, NWC24::WC24_ERR_SERVER);
return IPCReply{IPC_SUCCESS}; return IPCReply{IPC_SUCCESS};
} }
@ -967,7 +970,7 @@ IPCReply NetKDRequestDevice::HandleRequestRegisterUserId(const IOS::HLE::IOCtlRe
m_config.WriteConfig(); m_config.WriteConfig();
m_config.WriteCBK(); m_config.WriteCBK();
WriteReturnValue(NWC24::WC24_OK, request.buffer_out); WriteReturnValue(memory, NWC24::WC24_OK, request.buffer_out);
return IPCReply{IPC_SUCCESS}; return IPCReply{IPC_SUCCESS};
} }
@ -1008,7 +1011,7 @@ std::optional<IPCReply> NetKDRequestDevice::IOCtl(const IOCtlRequest& request)
case IOCTL_NWC24_SUSPEND_SCHEDULER: case IOCTL_NWC24_SUSPEND_SCHEDULER:
// NWC24iResumeForCloseLib from NWC24SuspendScheduler (Input: none, Output: 32 bytes) // NWC24iResumeForCloseLib from NWC24SuspendScheduler (Input: none, Output: 32 bytes)
INFO_LOG_FMT(IOS_WC24, "NET_KD_REQ: IOCTL_NWC24_SUSPEND_SCHEDULER - NI"); INFO_LOG_FMT(IOS_WC24, "NET_KD_REQ: IOCTL_NWC24_SUSPEND_SCHEDULER - NI");
WriteReturnValue(0, request.buffer_out); // no error WriteReturnValue(memory, 0, request.buffer_out); // no error
break; break;
case IOCTL_NWC24_EXEC_TRY_SUSPEND_SCHEDULER: // NWC24iResumeForCloseLib case IOCTL_NWC24_EXEC_TRY_SUSPEND_SCHEDULER: // NWC24iResumeForCloseLib
@ -1017,11 +1020,11 @@ std::optional<IPCReply> NetKDRequestDevice::IOCtl(const IOCtlRequest& request)
case IOCTL_NWC24_EXEC_RESUME_SCHEDULER: // NWC24iResumeForCloseLib case IOCTL_NWC24_EXEC_RESUME_SCHEDULER: // NWC24iResumeForCloseLib
INFO_LOG_FMT(IOS_WC24, "NET_KD_REQ: IOCTL_NWC24_EXEC_RESUME_SCHEDULER - NI"); INFO_LOG_FMT(IOS_WC24, "NET_KD_REQ: IOCTL_NWC24_EXEC_RESUME_SCHEDULER - NI");
WriteReturnValue(0, request.buffer_out); // no error WriteReturnValue(memory, 0, request.buffer_out); // no error
break; break;
case IOCTL_NWC24_STARTUP_SOCKET: // NWC24iStartupSocket case IOCTL_NWC24_STARTUP_SOCKET: // NWC24iStartupSocket
WriteReturnValue(0, request.buffer_out); WriteReturnValue(memory, 0, request.buffer_out);
memory.Write_U32(0, request.buffer_out + 4); memory.Write_U32(0, request.buffer_out + 4);
return_value = 0; return_value = 0;
INFO_LOG_FMT(IOS_WC24, "NET_KD_REQ: IOCTL_NWC24_STARTUP_SOCKET - NI"); INFO_LOG_FMT(IOS_WC24, "NET_KD_REQ: IOCTL_NWC24_STARTUP_SOCKET - NI");
@ -1080,21 +1083,21 @@ std::optional<IPCReply> NetKDRequestDevice::IOCtl(const IOCtlRequest& request)
m_config.WriteConfig(); m_config.WriteConfig();
m_config.WriteCBK(); m_config.WriteCBK();
WriteReturnValue(ret, request.buffer_out); WriteReturnValue(memory, ret, request.buffer_out);
} }
else else
{ {
LogError(ErrorType::Account, NWC24::WC24_ERR_INVALID_VALUE); LogError(ErrorType::Account, NWC24::WC24_ERR_INVALID_VALUE);
WriteReturnValue(NWC24::WC24_ERR_FATAL, request.buffer_out); WriteReturnValue(memory, NWC24::WC24_ERR_FATAL, request.buffer_out);
} }
} }
else if (m_config.IsGenerated()) else if (m_config.IsGenerated())
{ {
WriteReturnValue(NWC24::WC24_ERR_ID_GENERATED, request.buffer_out); WriteReturnValue(memory, NWC24::WC24_ERR_ID_GENERATED, request.buffer_out);
} }
else if (m_config.IsRegistered()) else if (m_config.IsRegistered())
{ {
WriteReturnValue(NWC24::WC24_ERR_ID_REGISTERED, request.buffer_out); WriteReturnValue(memory, NWC24::WC24_ERR_ID_REGISTERED, request.buffer_out);
} }
memory.Write_U64(m_config.Id(), request.buffer_out + 4); memory.Write_U64(m_config.Id(), request.buffer_out + 4);
memory.Write_U32(u32(m_config.CreationStage()), request.buffer_out + 0xC); memory.Write_U32(u32(m_config.CreationStage()), request.buffer_out + 0xC);

View File

@ -281,12 +281,12 @@ std::optional<IPCReply> NetSSLDevice::IOCtlV(const IOCtlVRequest& request)
ssl->hostname = hostname; ssl->hostname = hostname;
ssl->active = true; ssl->active = true;
WriteReturnValue(freeSSL, BufferIn); WriteReturnValue(memory, freeSSL, BufferIn);
} }
else else
{ {
_SSL_NEW_ERROR: _SSL_NEW_ERROR:
WriteReturnValue(SSL_ERR_FAILED, BufferIn); WriteReturnValue(memory, SSL_ERR_FAILED, BufferIn);
} }
INFO_LOG_FMT(IOS_SSL, INFO_LOG_FMT(IOS_SSL,
@ -321,11 +321,11 @@ std::optional<IPCReply> NetSSLDevice::IOCtlV(const IOCtlVRequest& request)
ssl->active = false; ssl->active = false;
WriteReturnValue(SSL_OK, BufferIn); WriteReturnValue(memory, SSL_OK, BufferIn);
} }
else else
{ {
WriteReturnValue(SSL_ERR_ID, BufferIn); WriteReturnValue(memory, SSL_ERR_ID, BufferIn);
} }
INFO_LOG_FMT(IOS_SSL, INFO_LOG_FMT(IOS_SSL,
"IOCTLV_NET_SSL_SHUTDOWN " "IOCTLV_NET_SSL_SHUTDOWN "
@ -361,19 +361,19 @@ std::optional<IPCReply> NetSSLDevice::IOCtlV(const IOCtlVRequest& request)
if (ret) if (ret)
{ {
WriteReturnValue(SSL_ERR_FAILED, BufferIn); WriteReturnValue(memory, SSL_ERR_FAILED, BufferIn);
} }
else else
{ {
mbedtls_ssl_conf_ca_chain(&ssl->config, &ssl->cacert, nullptr); mbedtls_ssl_conf_ca_chain(&ssl->config, &ssl->cacert, nullptr);
WriteReturnValue(SSL_OK, BufferIn); WriteReturnValue(memory, SSL_OK, BufferIn);
} }
INFO_LOG_FMT(IOS_SSL, "IOCTLV_NET_SSL_SETROOTCA = {}", ret); INFO_LOG_FMT(IOS_SSL, "IOCTLV_NET_SSL_SETROOTCA = {}", ret);
} }
else else
{ {
WriteReturnValue(SSL_ERR_ID, BufferIn); WriteReturnValue(memory, SSL_ERR_ID, BufferIn);
} }
break; break;
} }
@ -407,19 +407,19 @@ std::optional<IPCReply> NetSSLDevice::IOCtlV(const IOCtlVRequest& request)
{ {
mbedtls_x509_crt_free(&ssl->clicert); mbedtls_x509_crt_free(&ssl->clicert);
mbedtls_pk_free(&ssl->pk); mbedtls_pk_free(&ssl->pk);
WriteReturnValue(SSL_ERR_FAILED, BufferIn); WriteReturnValue(memory, SSL_ERR_FAILED, BufferIn);
} }
else else
{ {
mbedtls_ssl_conf_own_cert(&ssl->config, &ssl->clicert, &ssl->pk); mbedtls_ssl_conf_own_cert(&ssl->config, &ssl->clicert, &ssl->pk);
WriteReturnValue(SSL_OK, BufferIn); WriteReturnValue(memory, SSL_OK, BufferIn);
} }
INFO_LOG_FMT(IOS_SSL, "IOCTLV_NET_SSL_SETBUILTINCLIENTCERT = ({}, {})", ret, pk_ret); INFO_LOG_FMT(IOS_SSL, "IOCTLV_NET_SSL_SETBUILTINCLIENTCERT = ({}, {})", ret, pk_ret);
} }
else else
{ {
WriteReturnValue(SSL_ERR_ID, BufferIn); WriteReturnValue(memory, SSL_ERR_ID, BufferIn);
INFO_LOG_FMT(IOS_SSL, "IOCTLV_NET_SSL_SETBUILTINCLIENTCERT invalid sslID = {}", sslID); INFO_LOG_FMT(IOS_SSL, "IOCTLV_NET_SSL_SETBUILTINCLIENTCERT invalid sslID = {}", sslID);
} }
break; break;
@ -442,11 +442,11 @@ std::optional<IPCReply> NetSSLDevice::IOCtlV(const IOCtlVRequest& request)
mbedtls_pk_free(&ssl->pk); mbedtls_pk_free(&ssl->pk);
mbedtls_ssl_conf_own_cert(&ssl->config, nullptr, nullptr); mbedtls_ssl_conf_own_cert(&ssl->config, nullptr, nullptr);
WriteReturnValue(SSL_OK, BufferIn); WriteReturnValue(memory, SSL_OK, BufferIn);
} }
else else
{ {
WriteReturnValue(SSL_ERR_ID, BufferIn); WriteReturnValue(memory, SSL_ERR_ID, BufferIn);
INFO_LOG_FMT(IOS_SSL, "IOCTLV_NET_SSL_SETBUILTINCLIENTCERT invalid sslID = {}", sslID); INFO_LOG_FMT(IOS_SSL, "IOCTLV_NET_SSL_SETBUILTINCLIENTCERT invalid sslID = {}", sslID);
} }
break; break;
@ -467,18 +467,18 @@ std::optional<IPCReply> NetSSLDevice::IOCtlV(const IOCtlVRequest& request)
if (ret) if (ret)
{ {
mbedtls_x509_crt_free(&ssl->clicert); mbedtls_x509_crt_free(&ssl->clicert);
WriteReturnValue(SSL_ERR_FAILED, BufferIn); WriteReturnValue(memory, SSL_ERR_FAILED, BufferIn);
} }
else else
{ {
mbedtls_ssl_conf_ca_chain(&ssl->config, &ssl->cacert, nullptr); mbedtls_ssl_conf_ca_chain(&ssl->config, &ssl->cacert, nullptr);
WriteReturnValue(SSL_OK, BufferIn); WriteReturnValue(memory, SSL_OK, BufferIn);
} }
INFO_LOG_FMT(IOS_SSL, "IOCTLV_NET_SSL_SETBUILTINROOTCA = {}", ret); INFO_LOG_FMT(IOS_SSL, "IOCTLV_NET_SSL_SETBUILTINROOTCA = {}", ret);
} }
else else
{ {
WriteReturnValue(SSL_ERR_ID, BufferIn); WriteReturnValue(memory, SSL_ERR_ID, BufferIn);
} }
INFO_LOG_FMT(IOS_SSL, INFO_LOG_FMT(IOS_SSL,
"IOCTLV_NET_SSL_SETBUILTINROOTCA " "IOCTLV_NET_SSL_SETBUILTINROOTCA "
@ -500,11 +500,11 @@ std::optional<IPCReply> NetSSLDevice::IOCtlV(const IOCtlVRequest& request)
ssl->hostfd = GetEmulationKernel().GetSocketManager()->GetHostSocket(ssl->sockfd); ssl->hostfd = GetEmulationKernel().GetSocketManager()->GetHostSocket(ssl->sockfd);
INFO_LOG_FMT(IOS_SSL, "IOCTLV_NET_SSL_CONNECT socket = {}", ssl->sockfd); INFO_LOG_FMT(IOS_SSL, "IOCTLV_NET_SSL_CONNECT socket = {}", ssl->sockfd);
mbedtls_ssl_set_bio(&ssl->ctx, ssl, SSLSendWithoutSNI, SSLRecv, nullptr); mbedtls_ssl_set_bio(&ssl->ctx, ssl, SSLSendWithoutSNI, SSLRecv, nullptr);
WriteReturnValue(SSL_OK, BufferIn); WriteReturnValue(memory, SSL_OK, BufferIn);
} }
else else
{ {
WriteReturnValue(SSL_ERR_ID, BufferIn); WriteReturnValue(memory, SSL_ERR_ID, BufferIn);
} }
INFO_LOG_FMT(IOS_SSL, INFO_LOG_FMT(IOS_SSL,
"IOCTLV_NET_SSL_CONNECT " "IOCTLV_NET_SSL_CONNECT "
@ -526,7 +526,7 @@ std::optional<IPCReply> NetSSLDevice::IOCtlV(const IOCtlVRequest& request)
} }
else else
{ {
WriteReturnValue(SSL_ERR_ID, BufferIn); WriteReturnValue(memory, SSL_ERR_ID, BufferIn);
} }
break; break;
} }
@ -541,7 +541,7 @@ std::optional<IPCReply> NetSSLDevice::IOCtlV(const IOCtlVRequest& request)
} }
else else
{ {
WriteReturnValue(SSL_ERR_ID, BufferIn); WriteReturnValue(memory, SSL_ERR_ID, BufferIn);
} }
INFO_LOG_FMT(IOS_SSL, INFO_LOG_FMT(IOS_SSL,
"IOCTLV_NET_SSL_WRITE " "IOCTLV_NET_SSL_WRITE "
@ -565,7 +565,7 @@ std::optional<IPCReply> NetSSLDevice::IOCtlV(const IOCtlVRequest& request)
} }
else else
{ {
WriteReturnValue(SSL_ERR_ID, BufferIn); WriteReturnValue(memory, SSL_ERR_ID, BufferIn);
} }
INFO_LOG_FMT(IOS_SSL, INFO_LOG_FMT(IOS_SSL,
@ -582,11 +582,11 @@ std::optional<IPCReply> NetSSLDevice::IOCtlV(const IOCtlVRequest& request)
int sslID = memory.Read_U32(BufferOut) - 1; int sslID = memory.Read_U32(BufferOut) - 1;
if (IsSSLIDValid(sslID)) if (IsSSLIDValid(sslID))
{ {
WriteReturnValue(SSL_OK, BufferIn); WriteReturnValue(memory, SSL_OK, BufferIn);
} }
else else
{ {
WriteReturnValue(SSL_ERR_ID, BufferIn); WriteReturnValue(memory, SSL_ERR_ID, BufferIn);
} }
INFO_LOG_FMT(IOS_SSL, INFO_LOG_FMT(IOS_SSL,
"IOCTLV_NET_SSL_SETROOTCADEFAULT " "IOCTLV_NET_SSL_SETROOTCADEFAULT "
@ -610,11 +610,11 @@ std::optional<IPCReply> NetSSLDevice::IOCtlV(const IOCtlVRequest& request)
int sslID = memory.Read_U32(BufferOut) - 1; int sslID = memory.Read_U32(BufferOut) - 1;
if (IsSSLIDValid(sslID)) if (IsSSLIDValid(sslID))
{ {
WriteReturnValue(SSL_OK, BufferIn); WriteReturnValue(memory, SSL_OK, BufferIn);
} }
else else
{ {
WriteReturnValue(SSL_ERR_ID, BufferIn); WriteReturnValue(memory, SSL_ERR_ID, BufferIn);
} }
break; break;
} }

View File

@ -397,14 +397,14 @@ void WiiSocket::Update(bool read, bool write, bool except)
connecting_state = GetConnectingState(); connecting_state = GetConnectingState();
if (connecting_state == ConnectingState::Connecting) if (connecting_state == ConnectingState::Connecting)
{ {
WriteReturnValue(SSL_ERR_RAGAIN, BufferIn); WriteReturnValue(memory, SSL_ERR_RAGAIN, BufferIn);
ReturnValue = SSL_ERR_RAGAIN; ReturnValue = SSL_ERR_RAGAIN;
break; break;
} }
else if (connecting_state == ConnectingState::None || else if (connecting_state == ConnectingState::None ||
connecting_state == ConnectingState::Error) connecting_state == ConnectingState::Error)
{ {
WriteReturnValue(SSL_ERR_SYSCALL, BufferIn); WriteReturnValue(memory, SSL_ERR_SYSCALL, BufferIn);
ReturnValue = SSL_ERR_SYSCALL; ReturnValue = SSL_ERR_SYSCALL;
break; break;
} }
@ -420,15 +420,15 @@ void WiiSocket::Update(bool read, bool write, bool except)
switch (ret) switch (ret)
{ {
case 0: case 0:
WriteReturnValue(SSL_OK, BufferIn); WriteReturnValue(memory, SSL_OK, BufferIn);
break; break;
case MBEDTLS_ERR_SSL_WANT_READ: case MBEDTLS_ERR_SSL_WANT_READ:
WriteReturnValue(SSL_ERR_RAGAIN, BufferIn); WriteReturnValue(memory, SSL_ERR_RAGAIN, BufferIn);
if (!nonBlock) if (!nonBlock)
ReturnValue = SSL_ERR_RAGAIN; ReturnValue = SSL_ERR_RAGAIN;
break; break;
case MBEDTLS_ERR_SSL_WANT_WRITE: case MBEDTLS_ERR_SSL_WANT_WRITE:
WriteReturnValue(SSL_ERR_WAGAIN, BufferIn); WriteReturnValue(memory, SSL_ERR_WAGAIN, BufferIn);
if (!nonBlock) if (!nonBlock)
ReturnValue = SSL_ERR_WAGAIN; ReturnValue = SSL_ERR_WAGAIN;
break; break;
@ -451,13 +451,13 @@ void WiiSocket::Update(bool read, bool write, bool except)
else else
res = SSL_ERR_FAILED; res = SSL_ERR_FAILED;
WriteReturnValue(res, BufferIn); WriteReturnValue(memory, res, BufferIn);
if (!nonBlock) if (!nonBlock)
ReturnValue = res; ReturnValue = res;
break; break;
} }
default: default:
WriteReturnValue(SSL_ERR_FAILED, BufferIn); WriteReturnValue(memory, SSL_ERR_FAILED, BufferIn);
break; break;
} }
@ -495,24 +495,24 @@ void WiiSocket::Update(bool read, bool write, bool except)
system.GetPowerPC().GetDebugInterface().NetworkLogger()->LogSSLWrite( system.GetPowerPC().GetDebugInterface().NetworkLogger()->LogSSLWrite(
memory.GetPointer(BufferOut2), ret, ssl->hostfd); memory.GetPointer(BufferOut2), ret, ssl->hostfd);
// Return bytes written or SSL_ERR_ZERO if none // Return bytes written or SSL_ERR_ZERO if none
WriteReturnValue((ret == 0) ? SSL_ERR_ZERO : ret, BufferIn); WriteReturnValue(memory, (ret == 0) ? SSL_ERR_ZERO : ret, BufferIn);
} }
else else
{ {
switch (ret) switch (ret)
{ {
case MBEDTLS_ERR_SSL_WANT_READ: case MBEDTLS_ERR_SSL_WANT_READ:
WriteReturnValue(SSL_ERR_RAGAIN, BufferIn); WriteReturnValue(memory, SSL_ERR_RAGAIN, BufferIn);
if (!nonBlock) if (!nonBlock)
ReturnValue = SSL_ERR_RAGAIN; ReturnValue = SSL_ERR_RAGAIN;
break; break;
case MBEDTLS_ERR_SSL_WANT_WRITE: case MBEDTLS_ERR_SSL_WANT_WRITE:
WriteReturnValue(SSL_ERR_WAGAIN, BufferIn); WriteReturnValue(memory, SSL_ERR_WAGAIN, BufferIn);
if (!nonBlock) if (!nonBlock)
ReturnValue = SSL_ERR_WAGAIN; ReturnValue = SSL_ERR_WAGAIN;
break; break;
default: default:
WriteReturnValue(SSL_ERR_FAILED, BufferIn); WriteReturnValue(memory, SSL_ERR_FAILED, BufferIn);
break; break;
} }
} }
@ -529,24 +529,24 @@ void WiiSocket::Update(bool read, bool write, bool except)
system.GetPowerPC().GetDebugInterface().NetworkLogger()->LogSSLRead( system.GetPowerPC().GetDebugInterface().NetworkLogger()->LogSSLRead(
memory.GetPointer(BufferIn2), ret, ssl->hostfd); memory.GetPointer(BufferIn2), ret, ssl->hostfd);
// Return bytes read or SSL_ERR_ZERO if none // Return bytes read or SSL_ERR_ZERO if none
WriteReturnValue((ret == 0) ? SSL_ERR_ZERO : ret, BufferIn); WriteReturnValue(memory, (ret == 0) ? SSL_ERR_ZERO : ret, BufferIn);
} }
else else
{ {
switch (ret) switch (ret)
{ {
case MBEDTLS_ERR_SSL_WANT_READ: case MBEDTLS_ERR_SSL_WANT_READ:
WriteReturnValue(SSL_ERR_RAGAIN, BufferIn); WriteReturnValue(memory, SSL_ERR_RAGAIN, BufferIn);
if (!nonBlock) if (!nonBlock)
ReturnValue = SSL_ERR_RAGAIN; ReturnValue = SSL_ERR_RAGAIN;
break; break;
case MBEDTLS_ERR_SSL_WANT_WRITE: case MBEDTLS_ERR_SSL_WANT_WRITE:
WriteReturnValue(SSL_ERR_WAGAIN, BufferIn); WriteReturnValue(memory, SSL_ERR_WAGAIN, BufferIn);
if (!nonBlock) if (!nonBlock)
ReturnValue = SSL_ERR_WAGAIN; ReturnValue = SSL_ERR_WAGAIN;
break; break;
default: default:
WriteReturnValue(SSL_ERR_FAILED, BufferIn); WriteReturnValue(memory, SSL_ERR_FAILED, BufferIn);
break; break;
} }
} }
@ -558,7 +558,7 @@ void WiiSocket::Update(bool read, bool write, bool except)
} }
else else
{ {
WriteReturnValue(SSL_ERR_ID, BufferIn); WriteReturnValue(memory, SSL_ERR_ID, BufferIn);
} }
} }
else else