diff --git a/src/kernel/pthread.cpp b/src/kernel/pthread.cpp index 75dfdf9c2..58fb6fe96 100644 --- a/src/kernel/pthread.cpp +++ b/src/kernel/pthread.cpp @@ -2277,7 +2277,10 @@ int KYTY_SYSV_ABI PthreadRwlockDestroy(PthreadRwlock* rwlock) { return KERNEL_ERROR_EINVAL; } - EXIT_NOT_IMPLEMENTED(*rwlock == nullptr); + // SCE_PTHREAD_RWLOCK_INITIALIZER has no allocated resources until first use. + if (*rwlock == nullptr) { + return OK; + } { std::lock_guard lock((*rwlock)->m); diff --git a/tests/KernelFileSystemTests.cpp b/tests/KernelFileSystemTests.cpp index c548983c5..234215c36 100644 --- a/tests/KernelFileSystemTests.cpp +++ b/tests/KernelFileSystemTests.cpp @@ -101,6 +101,17 @@ void WaitForMutexTest(Predicate ready) { } } +void TestStaticRwlockDestroy() { + using namespace Libs::LibKernel; + PthreadRwlock rwlock = nullptr; + Check(PthreadRwlockDestroy(nullptr) == KERNEL_ERROR_EINVAL && + PthreadRwlockDestroy(&rwlock) == OK && rwlock == nullptr, + "destroy an untouched static rwlock without allocating it"); + Check(PthreadRwlockRdlock(&rwlock) == OK && PthreadRwlockUnlock(&rwlock) == OK && + PthreadRwlockDestroy(&rwlock) == OK, + "static rwlock remains usable after destroying its untouched initializer"); +} + struct MutexWaiter { Libs::LibKernel::PthreadMutex *mutex; Libs::LibKernel::KernelUseconds timeout = 0; @@ -2723,6 +2734,7 @@ int main(int argc, char** argv) { } TestMutexHandoff(); + TestStaticRwlockDestroy(); if (argc == 2 && std::string_view(argv[1]) == "--mutex-only") { subsystems.Destroy(); std::printf("KernelFileSystemTests: mutex cases passed\n");