Thread handle fixes (#125)

This commit is contained in:
Maurice Heumann
2025-02-04 20:57:04 +01:00
committed by GitHub
2 changed files with 13 additions and 2 deletions

View File

@@ -347,7 +347,7 @@ class moved_marker
bool was_moved_{false}; bool was_moved_{false};
}; };
class emulator_thread : ref_counted_object class emulator_thread : public ref_counted_object
{ {
public: public:
emulator_thread(x64_emulator& emu) emulator_thread(x64_emulator& emu)

View File

@@ -430,6 +430,16 @@ namespace
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
if (h.value.type == handle_types::thread)
{
const auto t = c.proc.threads.get(h);
if (t == c.proc.active_thread && t->ref_count == 1)
{
// TODO: Better handle ref counting
return STATUS_SUCCESS;
}
}
auto* handle_store = get_handle_store(c.proc, h); auto* handle_store = get_handle_store(c.proc, h);
if (handle_store && handle_store->erase(h)) if (handle_store && handle_store->erase(h))
{ {
@@ -3519,10 +3529,11 @@ namespace
} }
bool return_next_thread = thread_handle == NULL_HANDLE; bool return_next_thread = thread_handle == NULL_HANDLE;
for (const auto& t : c.proc.threads) for (auto& t : c.proc.threads)
{ {
if (return_next_thread && !t.second.is_terminated()) if (return_next_thread && !t.second.is_terminated())
{ {
++t.second.ref_count;
new_thread_handle.write(c.proc.threads.make_handle(t.first)); new_thread_handle.write(c.proc.threads.make_handle(t.first));
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }