Skip to content

Commit

Permalink
Replace constructor function with actual constructor call
Browse files Browse the repository at this point in the history
  • Loading branch information
momo5502 committed Nov 23, 2024
1 parent ce6718e commit 325e811
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 33 deletions.
14 changes: 4 additions & 10 deletions src/emulator/serialization.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,9 @@ namespace utils
{
};

template <typename, typename = void>
struct has_construct_function : std::false_type
{
};

template <typename T>
struct has_construct_function<T, std::void_t<decltype(T::construct(
std::declval<buffer_deserializer&>()))>>
: std::bool_constant<std::is_same_v<decltype(T::construct(std::declval<buffer_deserializer&>())), T>>
struct has_deserializer_constructor
: std::bool_constant<std::is_constructible_v<T, buffer_deserializer&>>
{
};
}
Expand Down Expand Up @@ -303,9 +297,9 @@ namespace utils
template <typename T>
T construct_object()
{
if constexpr (detail::has_construct_function<T>::value)
if constexpr (detail::has_deserializer_constructor<T>::value)
{
return T::construct(*this);
return T(*this);
}
else if constexpr (std::is_default_constructible_v<T>)
{
Expand Down
14 changes: 8 additions & 6 deletions src/windows-emulator/io_device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ struct io_device_context
emulator_pointer output_buffer{};
ULONG output_buffer_length{};

static io_device_context construct(utils::buffer_deserializer& buffer)
io_device_context(x64_emulator& emu)
: io_status_block(emu)
{
}

io_device_context(utils::buffer_deserializer& buffer)
: io_device_context(buffer.read<x64_emulator_wrapper>().get())
{
const auto wrapper = buffer.read<x64_emulator_wrapper>();
return io_device_context{
.io_status_block = wrapper.get(),
};
}

void serialize(utils::buffer_serializer& buffer) const
Expand Down Expand Up @@ -129,7 +131,7 @@ struct stateless_device : io_device
}
};

std::unique_ptr<io_device> create_device(const std::wstring_view device);
std::unique_ptr<io_device> create_device(std::wstring_view device);

class io_device_container : public io_device
{
Expand Down
11 changes: 5 additions & 6 deletions src/windows-emulator/process_context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,11 @@ class emulator_thread : ref_counted_object
{
}

emulator_thread(utils::buffer_deserializer& buffer)
: emulator_thread(buffer.read<x64_emulator_wrapper>().get())
{
}

emulator_thread(x64_emulator& emu, const process_context& context, uint64_t start_address, uint64_t argument,
uint64_t stack_size, uint32_t id);

Expand All @@ -202,12 +207,6 @@ class emulator_thread : ref_counted_object
this->release();
}

static emulator_thread construct(utils::buffer_deserializer& buffer)
{
const auto wrapper = buffer.read<x64_emulator_wrapper>();
return {wrapper.get()};
}

moved_marker marker{};

x64_emulator* emu_ptr{};
Expand Down
21 changes: 10 additions & 11 deletions src/windows-emulator/syscalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1677,17 +1677,16 @@ namespace
return STATUS_INVALID_HANDLE;
}

const io_device_context context{
.event = event,
.apc_routine = apc_routine,
.apc_context = apc_context,
.io_status_block = io_status_block,
.io_control_code = io_control_code,
.input_buffer = input_buffer,
.input_buffer_length = input_buffer_length,
.output_buffer = output_buffer,
.output_buffer_length = output_buffer_length,
};
io_device_context context{c.emu};
context.event = event;
context.apc_routine = apc_routine;
context.apc_context = apc_context;
context.io_status_block = io_status_block;
context.io_control_code = io_control_code;
context.input_buffer = input_buffer;
context.input_buffer_length = input_buffer_length;
context.output_buffer = output_buffer;
context.output_buffer_length = output_buffer_length;

return device->execute_ioctl(c.win_emu, context);
}
Expand Down

0 comments on commit 325e811

Please sign in to comment.