1313#include "../include/asm/inat.h"
1414#include "../include/asm/insn.h"
1515
16+ #include "../include/asm/emulate_prefix.h"
17+
1618/* Verify next sizeof(t) bytes can be on the same instruction */
1719#define validate_next (t , insn , n ) \
1820 ((insn)->next_byte + sizeof(t) + n <= (insn)->end_kaddr)
@@ -58,6 +60,36 @@ void insn_init(struct insn *insn, const void *kaddr, int buf_len, int x86_64)
5860 insn -> addr_bytes = 4 ;
5961}
6062
63+ static const insn_byte_t xen_prefix [] = { __XEN_EMULATE_PREFIX };
64+ static const insn_byte_t kvm_prefix [] = { __KVM_EMULATE_PREFIX };
65+
66+ static int __insn_get_emulate_prefix (struct insn * insn ,
67+ const insn_byte_t * prefix , size_t len )
68+ {
69+ size_t i ;
70+
71+ for (i = 0 ; i < len ; i ++ ) {
72+ if (peek_nbyte_next (insn_byte_t , insn , i ) != prefix [i ])
73+ goto err_out ;
74+ }
75+
76+ insn -> emulate_prefix_size = len ;
77+ insn -> next_byte += len ;
78+
79+ return 1 ;
80+
81+ err_out :
82+ return 0 ;
83+ }
84+
85+ static void insn_get_emulate_prefix (struct insn * insn )
86+ {
87+ if (__insn_get_emulate_prefix (insn , xen_prefix , sizeof (xen_prefix )))
88+ return ;
89+
90+ __insn_get_emulate_prefix (insn , kvm_prefix , sizeof (kvm_prefix ));
91+ }
92+
6193/**
6294 * insn_get_prefixes - scan x86 instruction prefix bytes
6395 * @insn: &struct insn containing instruction
@@ -76,6 +108,8 @@ void insn_get_prefixes(struct insn *insn)
76108 if (prefixes -> got )
77109 return ;
78110
111+ insn_get_emulate_prefix (insn );
112+
79113 nb = 0 ;
80114 lb = 0 ;
81115 b = peek_next (insn_byte_t , insn );
0 commit comments