From d08bcbae9c96fbafd43f80c56f9bd0340e72532f Mon Sep 17 00:00:00 2001 From: momo5502 Date: Sun, 18 May 2025 09:13:26 +0200 Subject: [PATCH] Add window object --- src/windows-emulator/handles.hpp | 13 +++++----- src/windows-emulator/process_context.hpp | 1 + src/windows-emulator/syscalls/thread.cpp | 13 ++++++++++ src/windows-emulator/windows_objects.hpp | 33 ++++++++++++++++++++++++ 4 files changed, 54 insertions(+), 6 deletions(-) diff --git a/src/windows-emulator/handles.hpp b/src/windows-emulator/handles.hpp index 963bfcae..1efcce77 100644 --- a/src/windows-emulator/handles.hpp +++ b/src/windows-emulator/handles.hpp @@ -19,6 +19,7 @@ struct handle_types registry, mutant, token, + window, }; }; @@ -238,7 +239,7 @@ class handle_store : public generic_handle_store return h; } - bool erase(const typename value_map::iterator& entry) + std::pair erase(const typename value_map::iterator& entry) { if (this->block_mutation_) { @@ -247,25 +248,25 @@ class handle_store : public generic_handle_store if (entry == this->store_.end()) { - return false; + return {entry, false}; } if constexpr (handle_detail::has_deleter_function()) { if (!T::deleter(entry->second)) { - return true; + return {entry, true}; } } - this->store_.erase(entry); - return true; + auto new_iter = this->store_.erase(entry); + return {new_iter, true}; } bool erase(const handle_value h) { const auto entry = this->get_iterator(h); - return this->erase(entry); + return this->erase(entry).second; } bool erase(const handle h) override diff --git a/src/windows-emulator/process_context.hpp b/src/windows-emulator/process_context.hpp index 2cacaf58..5c41be57 100644 --- a/src/windows-emulator/process_context.hpp +++ b/src/windows-emulator/process_context.hpp @@ -109,6 +109,7 @@ struct process_context handle_store semaphores{}; handle_store ports{}; handle_store mutants{}; + handle_store windows{}; handle_store registry_keys{}; std::map atoms{}; diff --git a/src/windows-emulator/syscalls/thread.cpp b/src/windows-emulator/syscalls/thread.cpp index a0f4af92..b34aa3d3 100644 --- a/src/windows-emulator/syscalls/thread.cpp +++ b/src/windows-emulator/syscalls/thread.cpp @@ -279,6 +279,19 @@ namespace syscalls thread->exit_status = exit_status; c.win_emu.callbacks.on_thread_terminated(thread_handle, *thread); + + for (auto i = c.proc.windows.begin(); i != c.proc.windows.end();) + { + if (i->second.thread_id != thread->id) + { + ++i; + continue; + } + + i->second.ref_count = 1; + i = c.proc.windows.erase(i).first; + } + if (thread == c.proc.active_thread) { c.win_emu.yield_thread(); diff --git a/src/windows-emulator/windows_objects.hpp b/src/windows-emulator/windows_objects.hpp index e51143b1..0795e6e0 100644 --- a/src/windows-emulator/windows_objects.hpp +++ b/src/windows-emulator/windows_objects.hpp @@ -39,6 +39,39 @@ struct event : ref_counted_object } }; +struct window : ref_counted_object +{ + uint32_t thread_id{}; + std::u16string name{}; + std::u16string class_name{}; + uint32_t width; + uint32_t height; + uint32_t x; + uint32_t y; + + void serialize_object(utils::buffer_serializer& buffer) const override + { + buffer.write(this->thread_id); + buffer.write(this->name); + buffer.write(this->class_name); + buffer.write(this->width); + buffer.write(this->height); + buffer.write(this->x); + buffer.write(this->y); + } + + void deserialize_object(utils::buffer_deserializer& buffer) override + { + buffer.read(this->thread_id); + buffer.read(this->name); + buffer.read(this->class_name); + buffer.read(this->width); + buffer.read(this->height); + buffer.read(this->x); + buffer.read(this->y); + } +}; + struct mutant : ref_counted_object { uint32_t locked_count{0};