Skip to content

Commit

Permalink
Small fixes and additions
Browse files Browse the repository at this point in the history
  • Loading branch information
momo5502 committed Nov 23, 2024
1 parent 2c421df commit 84a0aed
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 17 deletions.
18 changes: 9 additions & 9 deletions src/emulator/address_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,43 +13,43 @@ const T* offset_pointer(const void* data, const size_t offset)
return reinterpret_cast<const T*>(static_cast<const uint8_t*>(data) + offset);
}

inline bool is_within_start_and_end(const uint64_t value, const uint64_t start, const uint64_t end)
constexpr bool is_within_start_and_end(const uint64_t value, const uint64_t start, const uint64_t end)
{
return value >= start && value < end;
}

inline bool is_within_start_and_length(const uint64_t value, const uint64_t start, const uint64_t length)
constexpr bool is_within_start_and_length(const uint64_t value, const uint64_t start, const uint64_t length)
{
return is_within_start_and_end(value, start, start + length);
}

inline bool regions_intersect(const uint64_t start1, const uint64_t end1, const uint64_t start2, const uint64_t end2)
constexpr bool regions_intersect(const uint64_t start1, const uint64_t end1, const uint64_t start2, const uint64_t end2)
{
return start1 < end2 && start2 < end1;
}

inline bool regions_with_length_intersect(const uint64_t start1, const uint64_t length1, const uint64_t start2,
const uint64_t length2)
constexpr bool regions_with_length_intersect(const uint64_t start1, const uint64_t length1, const uint64_t start2,
const uint64_t length2)
{
return regions_intersect(start1, start1 + length1, start2, start2 + length2);
}

inline uint64_t align_down(const uint64_t value, const uint64_t alignment)
constexpr uint64_t align_down(const uint64_t value, const uint64_t alignment)
{
return value & ~(alignment - 1);
}

inline uint64_t align_up(const uint64_t value, const uint64_t alignment)
constexpr uint64_t align_up(const uint64_t value, const uint64_t alignment)
{
return align_down(value + (alignment - 1), alignment);
}

inline uint64_t page_align_down(const uint64_t value, const uint64_t page_size = 0x1000)
constexpr uint64_t page_align_down(const uint64_t value, const uint64_t page_size = 0x1000)
{
return align_down(value, page_size);
}

inline uint64_t page_align_up(const uint64_t value, const uint64_t page_size = 0x1000)
constexpr uint64_t page_align_up(const uint64_t value, const uint64_t page_size = 0x1000)
{
return align_up(value, page_size);
}
20 changes: 13 additions & 7 deletions src/windows-emulator/emulator_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,23 @@
// TODO: Replace with pointer handling structure for future 32 bit support
using emulator_pointer = uint64_t;

class x64_emulator_wrapper
template<typename T>
class object_wrapper
{
x64_emulator* emu_;
T* obj_;

public:
x64_emulator_wrapper(x64_emulator& emu)
: emu_(&emu)
object_wrapper(T& obj)
: obj_(&obj)
{
}

x64_emulator& get() const
T& get() const
{
return *this->emu_;
return *this->obj_;
}

operator x64_emulator&() const
operator T&() const
{
return this->get();
}
Expand All @@ -34,6 +35,11 @@ class x64_emulator_wrapper
}
};

class windows_emulator;

using x64_emulator_wrapper = object_wrapper<x64_emulator>;
using windows_emulator_wrapper = object_wrapper<windows_emulator>;

template <typename T>
class emulator_object
{
Expand Down
2 changes: 1 addition & 1 deletion src/windows-emulator/syscall_dispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void syscall_dispatcher::add_handlers()
{
std::map<std::string, syscall_handler> handler_mapping{};

this->add_handlers(handler_mapping);
syscall_dispatcher::add_handlers(handler_mapping);

for (auto& entry : this->handlers_)
{
Expand Down
5 changes: 5 additions & 0 deletions src/windows-emulator/windows_emulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1051,6 +1051,11 @@ void windows_emulator::deserialize(utils::buffer_deserializer& buffer)
return x64_emulator_wrapper{this->emu()};
});

buffer.register_factory<windows_emulator_wrapper>([this]
{
return windows_emulator_wrapper{*this};
});

buffer.read(this->use_relative_time_);

this->emu().deserialize(buffer);
Expand Down

0 comments on commit 84a0aed

Please sign in to comment.