Files
AnyPS5/core/libs/prx/libSceLibcInternal/Mutex.cpp
T
JJenkxandClaude Opus 5.5 b792fe2346 feat(libSceLibcInternal): implement std::_Mtx_init_with_default_name_override
The __sce_v236 export (NID naKdJL9d3nE) threw NotImplemented. It now forwards to libc's __sce_v219 _Mtx_init_with_name with the same type and name: a kernel mutex under the given name, recursive when the type asks for it, unnamed for a null or empty name. Whether the console substitutes a default name for a null one is not measured (technical debt).

Test: guest_libc_internal_mtx (a named recursive mutex locks twice, is held against another thread and is destroyed; an unnamed plain one refuses a second lock).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-05 06:27:47 -05:00

53 lines
1.7 KiB
C++

#include "prx/libkernel/Pthread/include/Mutex.hpp"
#include "prx/libkernel/include/Api.hpp"
#include "prx/libSceLibcInternal/include/Api.hpp"
#include "prx/libc/include/Api.hpp"
#include "prx/libc/include/general/VabiMacros.hpp"
#include "SceTypes.hpp"
#include <cstddef>
#include <cstdio>
namespace {
constexpr int MutexTypeRecursive = 2;
constexpr std::size_t MutexNameSize = 32;
}
extern "C" {
int APS5_VABI _Mtxinit_nid_postfix(PthreadMutex* mutex, const char* name) {
char mutexName[MutexNameSize];
if (name != nullptr)
std::snprintf(mutexName, sizeof(mutexName), "SceLibcI_%s", name);
else
std::snprintf(mutexName, sizeof(mutexName), "SceLibcI");
PthreadMutexattr attr = nullptr;
if (scePthreadMutexattrInit(&attr) != 0) return 1;
if (scePthreadMutexattrSettype(&attr, MutexTypeRecursive) != 0) {
scePthreadMutexattrDestroy(&attr);
return 1;
}
const int initialized = scePthreadMutexInit(mutex, &attr, mutexName);
const int released = scePthreadMutexattrDestroy(&attr);
return initialized != 0 || released != 0;
}
int APS5_VABI _ZNSt8__sce_v236_Mtx_init_with_default_name_overrideEPP13pthread_mutexiPKc_nid_postfix(void** mutex, int type, const char* name) {
return _ZNSt8__sce_v219_Mtx_init_with_nameEPP13pthread_mutexiPKc_nid_postfix(mutex, type, name);
}
int APS5_VABI _Mtxlock_nid_postfix(PthreadMutex* mutex) {
return pthread_mutex_lock_nid_postfix(mutex) != 0;
}
int APS5_VABI _Mtxunlock_nid_postfix(PthreadMutex* mutex) {
return pthread_mutex_unlock_nid_postfix(mutex) != 0;
}
int APS5_VABI _Mtxdst_nid_postfix(PthreadMutex* mutex) {
return pthread_mutex_destroy_nid_postfix(mutex) != 0;
}
}