mirror of
https://github.com/KytyPS5/KytyPS5.git
synced 2026-10-20 02:47:02 +02:00
Implement Missing NGS2 System Functions Lock & Unlock (#1542)
* Implement NGS2 SystemLock * Implement NGS2 SystemUnlock * Add guard for system_handle value of 0 * Return correct error code from system_handle guard * Validate NGS2 system handles before locking --------- Co-authored-by: nmzik <Nmzik@mail.ru>
This commit is contained in:
@@ -1147,6 +1147,8 @@ LIB_DEFINE(InitAudio_1_Ngs2) {
|
|||||||
LIB_FUNC("mPYgU4oYpuY", Ngs2::Ngs2SystemCreateWithAllocator);
|
LIB_FUNC("mPYgU4oYpuY", Ngs2::Ngs2SystemCreateWithAllocator);
|
||||||
LIB_FUNC("u-WrYDaJA3k", Ngs2::Ngs2SystemDestroy);
|
LIB_FUNC("u-WrYDaJA3k", Ngs2::Ngs2SystemDestroy);
|
||||||
LIB_FUNC("vU7TQ62pItw", Ngs2::Ngs2SystemGetInfo);
|
LIB_FUNC("vU7TQ62pItw", Ngs2::Ngs2SystemGetInfo);
|
||||||
|
LIB_FUNC("gThZqM5PYlQ", Ngs2::Ngs2SystemLock);
|
||||||
|
LIB_FUNC("JXRC5n0RQls", Ngs2::Ngs2SystemUnlock);
|
||||||
LIB_FUNC("U546k6orxQo", Ngs2::Ngs2RackCreateWithAllocator);
|
LIB_FUNC("U546k6orxQo", Ngs2::Ngs2RackCreateWithAllocator);
|
||||||
LIB_FUNC("cLV4aiT9JpA", Ngs2::Ngs2RackCreate);
|
LIB_FUNC("cLV4aiT9JpA", Ngs2::Ngs2RackCreate);
|
||||||
LIB_FUNC("0eFLVCfWVds", Ngs2::Ngs2RackQueryBufferSize);
|
LIB_FUNC("0eFLVCfWVds", Ngs2::Ngs2RackQueryBufferSize);
|
||||||
|
|||||||
+40
-8
@@ -28,6 +28,8 @@ namespace Ngs2 {
|
|||||||
|
|
||||||
LIB_NAME("Ngs2", "Ngs2");
|
LIB_NAME("Ngs2", "Ngs2");
|
||||||
|
|
||||||
|
constexpr int32_t NGS2_ERROR_INVALID_SYSTEM_HANDLE =
|
||||||
|
static_cast<int32_t>(0x804a8201u);
|
||||||
constexpr int32_t NGS2_ERROR_INVALID_OUT_ADDRESS =
|
constexpr int32_t NGS2_ERROR_INVALID_OUT_ADDRESS =
|
||||||
static_cast<int32_t>(0x804a8010u);
|
static_cast<int32_t>(0x804a8010u);
|
||||||
constexpr int32_t NGS2_ERROR_INVALID_NUM_WAVEFORM_BLOCKS =
|
constexpr int32_t NGS2_ERROR_INVALID_NUM_WAVEFORM_BLOCKS =
|
||||||
@@ -889,6 +891,15 @@ static Ngs2Internal* Ngs2CreateSystemInternal(const Ngs2SystemOption* optio
|
|||||||
return ngs;
|
return ngs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Ngs2Internal* Ngs2FindSystem(uintptr_t system_handle) {
|
||||||
|
for (auto* ngs = g_ngs_list; ngs != nullptr; ngs = ngs->next) {
|
||||||
|
if (reinterpret_cast<uintptr_t>(ngs) == system_handle) {
|
||||||
|
return ngs;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
static bool Ngs2RackIsCustom(Ngs2RackType type) {
|
static bool Ngs2RackIsCustom(Ngs2RackType type) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case Ngs2RackType::CustomSubmixer:
|
case Ngs2RackType::CustomSubmixer:
|
||||||
@@ -1110,7 +1121,6 @@ int KYTY_SYSV_ABI Ngs2SystemGetInfo(uintptr_t system_handle, Ngs2SystemInfo* inf
|
|||||||
size_t info_size) {
|
size_t info_size) {
|
||||||
constexpr int32_t ERROR_INVALID_OUT_ADDRESS = static_cast<int32_t>(0x804a8010u);
|
constexpr int32_t ERROR_INVALID_OUT_ADDRESS = static_cast<int32_t>(0x804a8010u);
|
||||||
constexpr int32_t ERROR_INVALID_OUT_SIZE = static_cast<int32_t>(0x804a8011u);
|
constexpr int32_t ERROR_INVALID_OUT_SIZE = static_cast<int32_t>(0x804a8011u);
|
||||||
constexpr int32_t ERROR_INVALID_SYSTEM_HANDLE = static_cast<int32_t>(0x804a8201u);
|
|
||||||
|
|
||||||
if (info == nullptr) {
|
if (info == nullptr) {
|
||||||
return ERROR_INVALID_OUT_ADDRESS;
|
return ERROR_INVALID_OUT_ADDRESS;
|
||||||
@@ -1119,13 +1129,9 @@ int KYTY_SYSV_ABI Ngs2SystemGetInfo(uintptr_t system_handle, Ngs2SystemInfo* inf
|
|||||||
return ERROR_INVALID_OUT_SIZE;
|
return ERROR_INVALID_OUT_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto* ngs = reinterpret_cast<Ngs2Internal*>(system_handle);
|
auto* ngs = Ngs2FindSystem(system_handle);
|
||||||
auto* current = g_ngs_list;
|
if (ngs == nullptr) {
|
||||||
while (current != nullptr && current != ngs) {
|
return NGS2_ERROR_INVALID_SYSTEM_HANDLE;
|
||||||
current = current->next;
|
|
||||||
}
|
|
||||||
if (current == nullptr) {
|
|
||||||
return ERROR_INVALID_SYSTEM_HANDLE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Common::LockGuard lock(ngs->mutex);
|
Common::LockGuard lock(ngs->mutex);
|
||||||
@@ -2625,6 +2631,32 @@ int KYTY_SYSV_ABI Ngs2VoiceGetStateFlags(uintptr_t voice_handle, uint32_t* state
|
|||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int KYTY_SYSV_ABI Ngs2SystemLock(uintptr_t system_handle) {
|
||||||
|
PRINT_NAME();
|
||||||
|
|
||||||
|
auto* ngs = Ngs2FindSystem(system_handle);
|
||||||
|
if (ngs == nullptr) {
|
||||||
|
return NGS2_ERROR_INVALID_SYSTEM_HANDLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
ngs->mutex.Lock();
|
||||||
|
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
int KYTY_SYSV_ABI Ngs2SystemUnlock(uintptr_t system_handle) {
|
||||||
|
PRINT_NAME();
|
||||||
|
|
||||||
|
auto* ngs = Ngs2FindSystem(system_handle);
|
||||||
|
if (ngs == nullptr) {
|
||||||
|
return NGS2_ERROR_INVALID_SYSTEM_HANDLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
ngs->mutex.Unlock();
|
||||||
|
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Ngs2
|
} // namespace Ngs2
|
||||||
|
|
||||||
} // namespace Libs::Audio
|
} // namespace Libs::Audio
|
||||||
|
|||||||
@@ -33,6 +33,8 @@ int KYTY_SYSV_ABI Ngs2SystemCreate(const Ngs2SystemOption* option,
|
|||||||
const Ngs2ContextBufferInfo* buffer_info, uintptr_t* handle);
|
const Ngs2ContextBufferInfo* buffer_info, uintptr_t* handle);
|
||||||
int KYTY_SYSV_ABI Ngs2SystemGetInfo(uintptr_t system_handle, Ngs2SystemInfo* info,
|
int KYTY_SYSV_ABI Ngs2SystemGetInfo(uintptr_t system_handle, Ngs2SystemInfo* info,
|
||||||
size_t info_size);
|
size_t info_size);
|
||||||
|
int KYTY_SYSV_ABI Ngs2SystemLock(uintptr_t system_handle);
|
||||||
|
int KYTY_SYSV_ABI Ngs2SystemUnlock(uintptr_t system_handle);
|
||||||
int KYTY_SYSV_ABI Ngs2SystemSetGrainSamples(uintptr_t system_handle, uint32_t num_samples);
|
int KYTY_SYSV_ABI Ngs2SystemSetGrainSamples(uintptr_t system_handle, uint32_t num_samples);
|
||||||
int KYTY_SYSV_ABI Ngs2RackQueryBufferSize(uint32_t rack_id, const Ngs2RackOption* option,
|
int KYTY_SYSV_ABI Ngs2RackQueryBufferSize(uint32_t rack_id, const Ngs2RackOption* option,
|
||||||
Ngs2ContextBufferInfo* buffer_info);
|
Ngs2ContextBufferInfo* buffer_info);
|
||||||
|
|||||||
Reference in New Issue
Block a user