Skip to content

Commit

Permalink
New guess: the definition of size_t varies?
Browse files Browse the repository at this point in the history
  • Loading branch information
TomHarte committed Nov 17, 2023
1 parent fbe02e3 commit 3f27338
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 20 deletions.
24 changes: 6 additions & 18 deletions InstructionSets/x86/Decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
using namespace InstructionSet::x86;

template <Model model>
std::pair<int, typename Decoder<model>::InstructionT> Decoder<model>::decode(const uint8_t *source, size_t length) {
std::pair<int, typename Decoder<model>::InstructionT> Decoder<model>::decode(const uint8_t *source, uint32_t length) {
// Instruction length limits:
//
// 8086/80186: none*
Expand All @@ -26,8 +26,8 @@ std::pair<int, typename Decoder<model>::InstructionT> Decoder<model>::decode(con
// be back to wherever it started, so it's safe to spit out a NOP and reset parsing
// without any loss of context. This reduces the risk of the decoder tricking a caller into
// an infinite loop.
constexpr int max_instruction_length = model >= Model::i80386 ? 15 : (model == Model::i80286 ? 10 : 65536);
const uint8_t *const end = source + std::min(length, size_t(max_instruction_length - consumed_));
constexpr uint32_t max_instruction_length = model >= Model::i80386 ? 15 : (model == Model::i80286 ? 10 : 65536);
const uint8_t *const end = source + std::min(length, max_instruction_length - consumed_);

// MARK: - Prefixes (if present) and the opcode.

Expand Down Expand Up @@ -1119,19 +1119,7 @@ template <Model model> void Decoder<model>::set_32bit_protected_mode(bool enable
}

// Ensure all possible decoders are built.
//template class InstructionSet::x86::Decoder<InstructionSet::x86::Model::i8086>;
//template class InstructionSet::x86::Decoder<InstructionSet::x86::Model::i80186>;
//template class InstructionSet::x86::Decoder<InstructionSet::x86::Model::i80286>;
template class InstructionSet::x86::Decoder<InstructionSet::x86::Model::i8086>;
template class InstructionSet::x86::Decoder<InstructionSet::x86::Model::i80186>;
template class InstructionSet::x86::Decoder<InstructionSet::x86::Model::i80286>;
template class InstructionSet::x86::Decoder<InstructionSet::x86::Model::i80386>;

template
std::pair<int, typename Decoder<InstructionSet::x86::Model::i8086>::InstructionT>
Decoder<InstructionSet::x86::Model::i8086>::decode(const uint8_t *, size_t);

template
std::pair<int, typename Decoder<InstructionSet::x86::Model::i80186>::InstructionT>
Decoder<InstructionSet::x86::Model::i80186>::decode(const uint8_t *, size_t);

template
std::pair<int, typename Decoder<InstructionSet::x86::Model::i80286>::InstructionT>
Decoder<InstructionSet::x86::Model::i80286>::decode(const uint8_t *, size_t);
4 changes: 2 additions & 2 deletions InstructionSets/x86/Decoder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ template <Model model> class Decoder {
The 80286 and 80386 have instruction length limits of 10 and 15 bytes respectively, so
cannot overflow the field.
*/
std::pair<int, InstructionT> decode(const uint8_t *source, size_t length);
std::pair<int, InstructionT> decode(const uint8_t *source, uint32_t length);

/*!
Enables or disables 32-bit protected mode. Meaningful only if the @c Model supports it.
Expand Down Expand Up @@ -173,7 +173,7 @@ template <Model model> class Decoder {

// Ephemeral decoding state.
Operation operation_ = Operation::Invalid;
int consumed_ = 0, operand_bytes_ = 0;
uint32_t consumed_ = 0, operand_bytes_ = 0;

// Source and destination locations.
Source source_ = Source::None;
Expand Down

0 comments on commit 3f27338

Please sign in to comment.