From bda89b5d1ed646a2239dc3087404459547e61a25 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Sun, 15 Jun 2025 19:48:05 +0200 Subject: [PATCH] Add more syscalls --- src/common/platform/kernel_mapped.hpp | 35 ++++++++++++++ src/windows-emulator/syscalls.cpp | 6 +++ src/windows-emulator/syscalls/object.cpp | 60 +++++++++++++++++++++++- 3 files changed, 100 insertions(+), 1 deletion(-) diff --git a/src/common/platform/kernel_mapped.hpp b/src/common/platform/kernel_mapped.hpp index 9a082611..21231d16 100644 --- a/src/common/platform/kernel_mapped.hpp +++ b/src/common/platform/kernel_mapped.hpp @@ -957,4 +957,39 @@ struct PROCESS_TLS_INFO static_assert(sizeof(PROCESS_TLS_INFO) - sizeof(THREAD_TLS_INFO) == 0x10); +struct EMU_GENERIC_MAPPING +{ + ACCESS_MASK GenericRead; + ACCESS_MASK GenericWrite; + ACCESS_MASK GenericExecute; + ACCESS_MASK GenericAll; +}; + +struct OBJECT_TYPE_INFORMATION +{ + STRING64 TypeName; + ULONG TotalNumberOfObjects; + ULONG TotalNumberOfHandles; + ULONG TotalPagedPoolUsage; + ULONG TotalNonPagedPoolUsage; + ULONG TotalNamePoolUsage; + ULONG TotalHandleTableUsage; + ULONG HighWaterNumberOfObjects; + ULONG HighWaterNumberOfHandles; + ULONG HighWaterPagedPoolUsage; + ULONG HighWaterNonPagedPoolUsage; + ULONG HighWaterNamePoolUsage; + ULONG HighWaterHandleTableUsage; + ULONG InvalidAttributes; + EMU_GENERIC_MAPPING GenericMapping; + ULONG ValidAccessMask; + BOOLEAN SecurityRequired; + BOOLEAN MaintainHandleCount; + UCHAR TypeIndex; // since WINBLUE + CHAR ReservedByte; + ULONG PoolType; + ULONG DefaultPagedPoolCharge; + ULONG DefaultNonPagedPoolCharge; +}; + // NOLINTEND(modernize-use-using,cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) diff --git a/src/windows-emulator/syscalls.cpp b/src/windows-emulator/syscalls.cpp index cb07797c..abba7931 100644 --- a/src/windows-emulator/syscalls.cpp +++ b/src/windows-emulator/syscalls.cpp @@ -611,6 +611,11 @@ namespace syscalls return STATUS_NOT_SUPPORTED; } + NTSTATUS handle_NtCreateDebugObject() + { + return STATUS_NOT_SUPPORTED; + } + NTSTATUS handle_NtAddAtomEx(const syscall_context& c, const uint64_t atom_name, const ULONG length, const emulator_object atom, const ULONG /*flags*/) { @@ -1179,6 +1184,7 @@ void syscall_dispatcher::add_handlers(std::map& ha add_handler(NtQuerySecurityObject); add_handler(NtQueryEvent); add_handler(NtRemoveIoCompletionEx); + add_handler(NtCreateDebugObject); #undef add_handler } diff --git a/src/windows-emulator/syscalls/object.cpp b/src/windows-emulator/syscalls/object.cpp index 5d17be4a..cf8d9da7 100644 --- a/src/windows-emulator/syscalls/object.cpp +++ b/src/windows-emulator/syscalls/object.cpp @@ -63,6 +63,43 @@ namespace syscalls return STATUS_SUCCESS; } + std::u16string get_type_name(const handle_types::type type) + { + switch (type) + { + case handle_types::file: + return u"File"; + case handle_types::device: + return u"Device"; + case handle_types::event: + return u"Event"; + case handle_types::section: + return u"Section"; + case handle_types::symlink: + return u"Symlink"; + case handle_types::directory: + return u"Directory"; + case handle_types::semaphore: + return u"Semaphore"; + case handle_types::port: + return u"Port"; + case handle_types::thread: + return u"Thread"; + case handle_types::registry: + return u"Registry"; + case handle_types::mutant: + return u"Mutant"; + case handle_types::token: + return u"Token"; + case handle_types::window: + return u"Window"; + case handle_types::timer: + return u"Timer"; + default: + return u""; + } + } + NTSTATUS handle_NtQueryObject(const syscall_context& c, const handle handle, const OBJECT_INFORMATION_CLASS object_information_class, const emulator_pointer object_information, const ULONG object_information_length, @@ -100,7 +137,7 @@ namespace syscalls } const auto required_size = sizeof(UNICODE_STRING>) + (device_path.size() + 1) * 2; - return_length.write(static_cast(required_size)); + return_length.write_if_valid(static_cast(required_size)); if (required_size > object_information_length) { @@ -113,6 +150,27 @@ namespace syscalls return STATUS_SUCCESS; } + if (object_information_class == ObjectTypeInformation) + { + const auto name = get_type_name(static_cast(handle.value.type)); + + const auto required_size = sizeof(OBJECT_TYPE_INFORMATION) + (name.size() + 1) * 2; + return_length.write_if_valid(static_cast(required_size)); + + if (required_size > object_information_length) + { + return STATUS_BUFFER_TOO_SMALL; + } + + emulator_allocator allocator(c.emu, object_information, object_information_length); + const auto info = allocator.reserve(); + info.access([&](OBJECT_TYPE_INFORMATION& i) { + allocator.make_unicode_string(i.TypeName, name); // + }); + + return STATUS_SUCCESS; + } + if (object_information_class == ObjectHandleFlagInformation) { return handle_query(c.emu, object_information, object_information_length,