Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions ps2xRuntime/src/lib/Kernel/Syscalls/Sync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,8 @@ namespace ps2_syscalls
}
sema->cv.notify_all();

setReturnS32(ctx, KE_OK);
// PS2 EE BIOS returns sid on success.
setReturnS32(ctx, sid);
}

void iDeleteSema(uint8_t *rdram, R5900Context *ctx, PS2Runtime *runtime)
Expand All @@ -236,7 +237,8 @@ namespace ps2_syscalls
return;
}

int ret = KE_OK;
// PS2 EE BIOS returns sid on success; KE_SEMA_OVF overrides on overflow.
int ret = sid;
int beforeCount = 0;
int afterCount = 0;
{
Expand Down Expand Up @@ -286,7 +288,7 @@ namespace ps2_syscalls
auto info = ensureCurrentThreadInfo(ctx);
throwIfTerminated(info);
std::unique_lock<std::mutex> lock(sema->m);
int ret = 0;
int ret = sid; // PS2 EE BIOS returns sid on success.

if (sema->count == 0)
{
Expand Down Expand Up @@ -318,7 +320,7 @@ namespace ps2_syscalls
{
bool forced = info ? info->forceRelease.load() : false;
bool terminated = info ? info->terminated.load() : false;
return sema->count > 0 || sema->deleted || forced || terminated; //
return sema->count > 0 || sema->deleted || forced || terminated;
});
}
sema->waiters--;
Expand Down Expand Up @@ -346,7 +348,7 @@ namespace ps2_syscalls
}
}

if (ret == 0 && sema->count > 0)
if (ret == sid && sema->count > 0)
{
sema->count--;
}
Expand Down Expand Up @@ -380,7 +382,7 @@ namespace ps2_syscalls
if (sema->count > 0)
{
sema->count--;
setReturnS32(ctx, KE_OK);
setReturnS32(ctx, sid); // PS2 EE BIOS returns sid on success.
return;
}

Expand Down
4 changes: 2 additions & 2 deletions ps2xTest/src/ps2_runtime_expansion_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -942,7 +942,7 @@ void register_ps2_runtime_expansion_tests()
R5900Context pollCtx{};
setRegU32(pollCtx, 4, static_cast<uint32_t>(sid));
PollSema(rdram.data(), &pollCtx, &runtime);
if (getRegS32(pollCtx, 2) == KE_OK)
if (getRegS32(pollCtx, 2) == sid)
{
pollOkCount.fetch_add(1, std::memory_order_relaxed);
}
Expand All @@ -963,7 +963,7 @@ void register_ps2_runtime_expansion_tests()
R5900Context signalCtx{};
setRegU32(signalCtx, 4, static_cast<uint32_t>(sid));
SignalSema(rdram.data(), &signalCtx, &runtime);
if (getRegS32(signalCtx, 2) == KE_OK)
if (getRegS32(signalCtx, 2) == sid)
{
signalOkCount.fetch_add(1, std::memory_order_relaxed);
}
Expand Down
Loading