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:
Mr. Big Britches
2026-10-15 16:39:40 -07:00
committed by GitHub
parent 57c4a6ee11
commit 6568fe9a84
3 changed files with 44 additions and 8 deletions
+2
View File
@@ -1147,6 +1147,8 @@ LIB_DEFINE(InitAudio_1_Ngs2) {
LIB_FUNC("mPYgU4oYpuY", Ngs2::Ngs2SystemCreateWithAllocator);
LIB_FUNC("u-WrYDaJA3k", Ngs2::Ngs2SystemDestroy);
LIB_FUNC("vU7TQ62pItw", Ngs2::Ngs2SystemGetInfo);
LIB_FUNC("gThZqM5PYlQ", Ngs2::Ngs2SystemLock);
LIB_FUNC("JXRC5n0RQls", Ngs2::Ngs2SystemUnlock);
LIB_FUNC("U546k6orxQo", Ngs2::Ngs2RackCreateWithAllocator);
LIB_FUNC("cLV4aiT9JpA", Ngs2::Ngs2RackCreate);
LIB_FUNC("0eFLVCfWVds", Ngs2::Ngs2RackQueryBufferSize);
+40 -8
View File
@@ -28,6 +28,8 @@ namespace 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 =
static_cast<int32_t>(0x804a8010u);
constexpr int32_t NGS2_ERROR_INVALID_NUM_WAVEFORM_BLOCKS =
@@ -889,6 +891,15 @@ static Ngs2Internal* Ngs2CreateSystemInternal(const Ngs2SystemOption* optio
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) {
switch (type) {
case Ngs2RackType::CustomSubmixer:
@@ -1110,7 +1121,6 @@ int KYTY_SYSV_ABI Ngs2SystemGetInfo(uintptr_t system_handle, Ngs2SystemInfo* inf
size_t info_size) {
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_SYSTEM_HANDLE = static_cast<int32_t>(0x804a8201u);
if (info == nullptr) {
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;
}
auto* ngs = reinterpret_cast<Ngs2Internal*>(system_handle);
auto* current = g_ngs_list;
while (current != nullptr && current != ngs) {
current = current->next;
}
if (current == nullptr) {
return ERROR_INVALID_SYSTEM_HANDLE;
auto* ngs = Ngs2FindSystem(system_handle);
if (ngs == nullptr) {
return NGS2_ERROR_INVALID_SYSTEM_HANDLE;
}
Common::LockGuard lock(ngs->mutex);
@@ -2625,6 +2631,32 @@ int KYTY_SYSV_ABI Ngs2VoiceGetStateFlags(uintptr_t voice_handle, uint32_t* state
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 Libs::Audio
+2
View File
@@ -33,6 +33,8 @@ int KYTY_SYSV_ABI Ngs2SystemCreate(const Ngs2SystemOption* option,
const Ngs2ContextBufferInfo* buffer_info, uintptr_t* handle);
int KYTY_SYSV_ABI Ngs2SystemGetInfo(uintptr_t system_handle, Ngs2SystemInfo* info,
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 Ngs2RackQueryBufferSize(uint32_t rack_id, const Ngs2RackOption* option,
Ngs2ContextBufferInfo* buffer_info);