1 #include <linux/types.h>
5 static bool opcode_is_prefix(uint8_t b
)
9 b
== 0xf0 || b
== 0xf2 || b
== 0xf3
11 || b
== 0x2e || b
== 0x36 || b
== 0x3e || b
== 0x26
12 || b
== 0x64 || b
== 0x65 || b
== 0x2e || b
== 0x3e
19 static bool opcode_is_rex_prefix(uint8_t b
)
21 return (b
& 0xf0) == 0x40;
24 #define REX_W (1 << 3)
27 * This is a VERY crude opcode decoder. We only need to find the size of the
28 * load/store that caused our #PF and this should work for all the opcodes
29 * that we care about. Moreover, the ones who invented this instruction set
32 void kmemcheck_opcode_decode(const uint8_t *op
, unsigned int *size
)
34 /* Default operand size */
35 int operand_size_override
= 4;
38 for (; opcode_is_prefix(*op
); ++op
) {
40 operand_size_override
= 2;
45 if (opcode_is_rex_prefix(*op
)) {
82 * This is move with zero-extend and sign-extend, respectively;
83 * we don't have to think about 0xb6/0xbe, because this is
84 * already handled in the conditional below.
86 if (*op
== 0xb7 || *op
== 0xbf)
87 operand_size_override
= 2;
90 *size
= (*op
& 1) ? operand_size_override
: 1;
93 const uint8_t *kmemcheck_opcode_get_primary(const uint8_t *op
)
96 while (opcode_is_prefix(*op
))
98 if (opcode_is_rex_prefix(*op
))