1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/types.h>
6 static bool opcode_is_prefix(uint8_t b)
10 b == 0xf0 || b == 0xf2 || b == 0xf3
12 || b == 0x2e || b == 0x36 || b == 0x3e || b == 0x26
13 || b == 0x64 || b == 0x65
21 static bool opcode_is_rex_prefix(uint8_t b)
23 return (b & 0xf0) == 0x40;
26 static bool opcode_is_rex_prefix(uint8_t b)
32 #define REX_W (1 << 3)
35 * This is a VERY crude opcode decoder. We only need to find the size of the
36 * load/store that caused our #PF and this should work for all the opcodes
37 * that we care about. Moreover, the ones who invented this instruction set
40 void kmemcheck_opcode_decode(const uint8_t *op, unsigned int *size)
42 /* Default operand size */
43 int operand_size_override = 4;
46 for (; opcode_is_prefix(*op); ++op) {
48 operand_size_override = 2;
52 if (opcode_is_rex_prefix(*op)) {
88 * This is move with zero-extend and sign-extend, respectively;
89 * we don't have to think about 0xb6/0xbe, because this is
90 * already handled in the conditional below.
92 if (*op == 0xb7 || *op == 0xbf)
93 operand_size_override = 2;
96 *size = (*op & 1) ? operand_size_override : 1;
99 const uint8_t *kmemcheck_opcode_get_primary(const uint8_t *op)
102 while (opcode_is_prefix(*op))
104 if (opcode_is_rex_prefix(*op))