Skip to content

Commit

Permalink
Multiple smaller HLE improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Exzap committed Dec 7, 2024
1 parent 87253c8 commit a568a08
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/Cafe/OS/RPL/rpl_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ typedef struct
/* +0x34 */ uint32be ukn34;
/* +0x38 */ uint32be ukn38;
/* +0x3C */ uint32be ukn3C;
/* +0x40 */ uint32be toolkitVersion;
/* +0x40 */ uint32be minimumToolkitVersion;
/* +0x44 */ uint32be ukn44;
/* +0x48 */ uint32be ukn48;
/* +0x4C */ uint32be ukn4C;
Expand Down
14 changes: 13 additions & 1 deletion src/Cafe/OS/libs/coreinit/coreinit_GHS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,22 @@ namespace coreinit
return &currentThread->crt.eh_mem_manage;
}

void* __gh_errno_ptr()
sint32be* __gh_errno_ptr()
{
OSThread_t* currentThread = coreinit::OSGetCurrentThread();
return &currentThread->context.ghs_errno;
}

void __gh_set_errno(sint32 errNo)
{
*__gh_errno_ptr() = errNo;
}

sint32 __gh_get_errno()
{
return *__gh_errno_ptr();
}

void* __get_eh_store_globals()
{
OSThread_t* currentThread = coreinit::OSGetCurrentThread();
Expand Down Expand Up @@ -272,6 +282,8 @@ namespace coreinit
cafeExportRegister("coreinit", __get_eh_globals, LogType::Placeholder);
cafeExportRegister("coreinit", __get_eh_mem_manage, LogType::Placeholder);
cafeExportRegister("coreinit", __gh_errno_ptr, LogType::Placeholder);
cafeExportRegister("coreinit", __gh_set_errno, LogType::Placeholder);
cafeExportRegister("coreinit", __gh_get_errno, LogType::Placeholder);
cafeExportRegister("coreinit", __get_eh_store_globals, LogType::Placeholder);
cafeExportRegister("coreinit", __get_eh_store_globals_tdeh, LogType::Placeholder);

Expand Down
4 changes: 4 additions & 0 deletions src/Cafe/OS/libs/coreinit/coreinit_GHS.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,9 @@ namespace coreinit
{
void PrepareGHSRuntime();

sint32be* __gh_errno_ptr();
void __gh_set_errno(sint32 errNo);
sint32 __gh_get_errno();

void InitializeGHS();
};
2 changes: 1 addition & 1 deletion src/Cafe/OS/libs/coreinit/coreinit_Thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ struct OSContext_t
/* +0x1E0 */ uint64be fp_ps1[32];
/* +0x2E0 */ uint64be coretime[3];
/* +0x2F8 */ uint64be starttime;
/* +0x300 */ uint32be ghs_errno; // returned by __gh_errno_ptr() (used by socketlasterr)
/* +0x300 */ sint32be ghs_errno; // returned by __gh_errno_ptr() (used by socketlasterr)
/* +0x304 */ uint32be affinity;
/* +0x308 */ uint32be upmc1;
/* +0x30C */ uint32be upmc2;
Expand Down
6 changes: 6 additions & 0 deletions src/Cafe/OS/libs/gx2/GX2_Resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ namespace GX2
return true;
}

void GX2RSetBufferName(GX2RBuffer* buffer, const char* name)
{
// no-op in production builds
}

void* GX2RLockBufferEx(GX2RBuffer* buffer, uint32 resFlags)
{
return buffer->GetPtr();
Expand Down Expand Up @@ -226,6 +231,7 @@ namespace GX2
cafeExportRegister("gx2", GX2RCreateBufferUserMemory, LogType::GX2);
cafeExportRegister("gx2", GX2RDestroyBufferEx, LogType::GX2);
cafeExportRegister("gx2", GX2RBufferExists, LogType::GX2);
cafeExportRegister("gx2", GX2RSetBufferName, LogType::GX2);
cafeExportRegister("gx2", GX2RLockBufferEx, LogType::GX2);
cafeExportRegister("gx2", GX2RUnlockBufferEx, LogType::GX2);
cafeExportRegister("gx2", GX2RInvalidateBuffer, LogType::GX2);
Expand Down
11 changes: 3 additions & 8 deletions src/Cafe/OS/libs/nsysnet/nsysnet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "Cafe/OS/libs/coreinit/coreinit_Thread.h"
#include "Cafe/IOSU/legacy/iosu_crypto.h"
#include "Cafe/OS/libs/coreinit/coreinit_Time.h"
#include "Cafe/OS/libs/coreinit/coreinit_GHS.h"

#include "Common/socket.h"

Expand Down Expand Up @@ -117,20 +118,14 @@ void nsysnetExport_socket_lib_finish(PPCInterpreter_t* hCPU)
osLib_returnFromFunction(hCPU, 0); // 0 -> Success
}

static uint32be* __gh_errno_ptr()
{
OSThread_t* osThread = coreinit::OSGetCurrentThread();
return &osThread->context.ghs_errno;
}

void _setSockError(sint32 errCode)
{
*(uint32be*)__gh_errno_ptr() = (uint32)errCode;
coreinit::__gh_set_errno(errCode);
}

sint32 _getSockError()
{
return (sint32)*(uint32be*)__gh_errno_ptr();
return coreinit::__gh_get_errno();
}

// error translation modes for _translateError
Expand Down

0 comments on commit a568a08

Please sign in to comment.