Merge pull request #15619 from XairRrR/fix-libsceult-trylock-nonrecursive

fix(libSceUlt): return a state error when the owner try-locks a non-recursive mutex
This commit is contained in:
Adrià authored and GitHub committed 2026-11-07 21:48:58 +01:00
commit 4204951e77
3 files changed
+14 -1

No files matched your search

+3
View File
@@ -403,6 +403,9 @@ int APS5_VABI sceUltMutexTryLock(void* mutex) {
return ULT_ERROR_STATE;
}
if (state->_owner == self) {
if (state->_attribute == 0) {
return ULT_ERROR_STATE;
}
++state->_lockCount;
return ULT_OK;
}
+10
View File
@@ -61,6 +61,16 @@ void MutexTryLock() {
CHECK(sceUltMutexUnlock(&mutex) == Ok);
CHECK(sceUltMutexDestroy(&mutex) == Ok);
CHECK(sceUltMutexTryLock(&mutex) == State);
CHECK(sceUltMutexCreate(&mutex, "plain", nullptr, nullptr, 0) == Ok);
CHECK(sceUltMutexTryLock(&mutex) == Ok);
CHECK(sceUltMutexTryLock(&mutex) == State);
CHECK(sceUltMutexUnlock(&mutex) == Ok);
std::thread([&] {
other = sceUltMutexTryLock(&mutex);
if (other == Ok) other = sceUltMutexUnlock(&mutex);
}).join();
CHECK(other == Ok);
CHECK(sceUltMutexDestroy(&mutex) == Ok);
}
void MutexAndRuntimeOptParams() {
+1 -1
View File
@@ -12,7 +12,7 @@
- [Mutex and reader-writer status queries](../../../core/libs/prx/libSceUlt/src/ReaderWriterLock.cpp) throw for held recursive mutexes and ulthread-owned mutexes or write locks: recursive counts and ulthread owner encoding remain unverified. [Firmware 13.42 observations](https://github.com/boykopovar/AnyPS5/pull/9975#issuecomment-6417685562), from native x86-64 module runs with stubbed imports rather than PS5 hardware, supply `lockType` 1/2/0 for read/write/free, pthread `owner` from the thread block's first 8 bytes, `ownerType` 1 and default mutex `lockCount` 0 when held once. Both queries reject any supplied waiting record whose `size` is not 64 with `ULT_ERROR_INVALID` before writing output, as observed without waiters. Validation precedence and record-size checks for the other queries remain unverified.
- [Ult factory and creation exports](../../../core/libs/prx/libSceUlt/Export.cpp) without a leading underscore are absent from the supplied module; their signatures remain unresolved. Diagnostic signatures and synchronization argument lists are recovered.
- [sceUltMutexTryLock, the reader-writer lock and sceUltUlthreadGetSelf, sceUltUlthreadYield and sceUltUlthreadExit](../../../core/libs/prx/libSceUlt/src/ReaderWriterLock.cpp) (libSceUlt) - the signatures follow the PS Vita libult in [RPCS3](https://github.com/RPCS3/rpcs3/blob/13aa88c3c4d66ea8799e987f7d762d90943ab17b/rpcs3/Emu/PSP2/Modules/sceUlt.cpp) (a 256-byte lock and 128-byte option structures), not a PS5 binary. The rules are assumed: readers may take the lock while a writer waits, a thread that holds the write lock gets `ULT_ERROR_STATE` for any further lock instead of waiting on itself, a reader asking for the write lock waits on its own read lock, and the try forms return `ULT_ERROR_BUSY`. Outside an ulthread, `sceUltUlthreadGetSelf`, `sceUltUlthreadYield` and `sceUltUlthreadExit` return `ULT_ERROR_STATE`; inside one they act on the guest thread it runs on, since ulthreads are not scheduled cooperatively here
- [sceUltMutexTryLock, the reader-writer lock and sceUltUlthreadGetSelf, sceUltUlthreadYield and sceUltUlthreadExit](../../../core/libs/prx/libSceUlt/src/ReaderWriterLock.cpp) (libSceUlt) - the signatures follow the PS Vita libult in [RPCS3](https://github.com/RPCS3/rpcs3/blob/13aa88c3c4d66ea8799e987f7d762d90943ab17b/rpcs3/Emu/PSP2/Modules/sceUlt.cpp) (a 256-byte lock and 128-byte option structures), not a PS5 binary. The rules are assumed: readers may take the lock while a writer waits, a thread that holds the write lock or a non-recursive mutex gets `ULT_ERROR_STATE` for any further lock instead of waiting on itself, a reader asking for the write lock waits on its own read lock, and the try forms return `ULT_ERROR_BUSY`. Outside an ulthread, `sceUltUlthreadGetSelf`, `sceUltUlthreadYield` and `sceUltUlthreadExit` return `ULT_ERROR_STATE`; inside one they act on the guest thread it runs on, since ulthreads are not scheduled cooperatively here
- [_sceUltWaitingQueueResourcePoolOptParamInitialize, _sceUltSemaphoreOptParamInitialize, _sceUltQueueDataResourcePoolOptParamInitialize, _sceUltQueueOptParamInitialize and _sceUltUlthreadOptParamInitialize](../../../core/libs/prx/libSceUlt/Export.cpp) and [_sceUltReaderWriterLockOptParamInitialize and _sceUltReaderWriterLockCreate](../../../core/libs/prx/libSceUlt/src/ReaderWriterLock.cpp) (libSceUlt) forward to the exports without the underscore; that their argument lists match is inferred from the other underscore Ult exports, not measured
### Functional