Make sure fetch_instruction exist before calling it
PATCH 1/1 Make sure fetch_instruction exist before calling it
From: Nguyen Dinh Phi <[email protected]>
Currently, this function is only available in MSHV. If a different accelerator is used, and the code jumps to this section, a segfault will occur. (I ran into this with HVF)
--- target/i386/emulate/x86_decode.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
target/i386/emulate/x86_decode.c +5 -1
@@ -77,7 +77,11 @@ static inline uint64_t decode_bytes(CPUX86State *env, struct x86_decode *decode,memcpy (&val, decode->stream->bytes + decode->len, size); }else {target_ulong va =linear_rip (env_cpu (env), env->eip) + decode->len; - emul_ops->fetch_instruction (env_cpu (env), &val, va, size); +if (emul_ops->fetch_instruction) { + emul_ops->fetch_instruction (env_cpu (env), &val, va, size); + }else { + emul_ops->read_mem (env_cpu (env), &val, va, size); + } } decode->len += size;
Signature · 1 line
2.50.1 (Apple Git-155)
Paolo Bonzini
AppliedQuoted 7 lines · On 11/14/25 09:29, [email protected] wrote:
From: Nguyen Dinh Phi <[email protected]>
Currently, this function is only available in MSHV. If a different accelerator is used, and the code jumps to this section, a segfault will occur. (I ran into this with HVF)
Signed-off-by Nguyen Dinh Phi <[email protected]>
Applied, thanks.
Paolo
Quoted 21 lines
--- target/i386/emulate/x86_decode.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)target/i386/emulate/x86_decode.c +5
-1@@ -77,7 +77,11 @@ static inline uint64_t decode_bytes(CPUX86State *env, struct x86_decode *decode,memcpy (&val, decode->stream->bytes + decode->len, size); }else {target_ulong va =linear_rip (env_cpu (env), env->eip) + decode->len; - emul_ops->fetch_instruction (env_cpu (env), &val, va, size); +if (emul_ops->fetch_instruction) { + emul_ops->fetch_instruction (env_cpu (env), &val, va, size); + }else { + emul_ops->read_mem (env_cpu (env), &val, va, size); + } } decode->len += size;
Quoted 6 lines · On 14/11/25 09:29, [email protected] wrote:
From: Nguyen Dinh Phi <[email protected]>
Currently, this function is only available in MSHV. If a different accelerator is used, and the code jumps to this section, a segfault will occur. (I ran into this with HVF)
Quoted 22 lines
Signed-off-by Nguyen Dinh Phi <[email protected]>--- target/i386/emulate/x86_decode.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)target/i386/emulate/x86_decode.c +5
-1@@ -77,7 +77,11 @@ static inline uint64_t decode_bytes(CPUX86State *env, struct x86_decode *decode,memcpy (&val, decode->stream->bytes + decode->len, size); }else {target_ulong va =linear_rip (env_cpu (env), env->eip) + decode->len; - emul_ops->fetch_instruction (env_cpu (env), &val, va, size); +if (emul_ops->fetch_instruction) { + emul_ops->fetch_instruction (env_cpu (env), &val, va, size); + }else { + emul_ops->read_mem (env_cpu (env), &val, va, size); + } } decode->len += size;
Quoted 18 lines · On 11/14/25 09:29, [email protected] wrote:
From: Nguyen Dinh Phi <[email protected]>
Currently, this function is only available in MSHV. If a different accelerator is used, and the code jumps to this section, a segfault will occur. (I ran into this with HVF)
Signed-off-by Nguyen Dinh Phi <[email protected]>--- target/i386/emulate/x86_decode.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)target/i386/emulate/x86_decode.c +0
-0@@ -77,7 +77,11 @@ static inline uint64_t decode_bytes(CPUX86State *env, struct x86_decode *decode,memcpy (&val, decode->stream->bytes + decode->len, size); }else {
target/i386/emulate/x86_decode.c static inline uint64_t decode_bytes(CPUX86State *env, struct x86_decode *decode, · line 87
Quoted 10 lines
target/i386/emulate/x86_decode.c +5
-1target_ulong va =linear_rip (env_cpu (env), env->eip) + decode->len; - emul_ops->fetch_instruction (env_cpu (env), &val, va, size); +if (emul_ops->fetch_instruction) { + emul_ops->fetch_instruction (env_cpu (env), &val, va, size); + }else { + emul_ops->read_mem (env_cpu (env), &val, va, size); + } } decode->len += size;
We should instead have fetch_instruction == read_mem for the cases that do not require a specialized version.
r~
Quoted 5 lines · On 11/14/25 11:29, [email protected] wrote:
From: Nguyen Dinh Phi <[email protected]>
Currently, this function is only available in MSHV. If a different accelerator is used, and the code jumps to this section, a segfault will occur. (I ran into this with HVF)
Is it a qemu-stable material? It looks like it is. Please let me know if it isn't.
Thanks,
/mjt
Quoted 22 lines
Signed-off-by Nguyen Dinh Phi <[email protected]>--- target/i386/emulate/x86_decode.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)target/i386/emulate/x86_decode.c +5
-1@@ -77,7 +77,11 @@ static inline uint64_t decode_bytes(CPUX86State *env, struct x86_decode *decode,memcpy (&val, decode->stream->bytes + decode->len, size); }else {target_ulong va =linear_rip (env_cpu (env), env->eip) + decode->len; - emul_ops->fetch_instruction (env_cpu (env), &val, va, size); +if (emul_ops->fetch_instruction) { + emul_ops->fetch_instruction (env_cpu (env), &val, va, size); + }else { + emul_ops->read_mem (env_cpu (env), &val, va, size); + } } decode->len += size;
Quoted 9 lines · Michael Tokarev
Quoted 5 lines · On 11/14/25 11:29, [email protected] wrote:
From: Nguyen Dinh Phi <[email protected]>
Currently, this function is only available in MSHV. If a different accelerator is used, and the code jumps to this section, a segfault will occur. (I ran into this with HVF)
Is it a qemu-stable material? It looks like it is. Please let me know if it isn't.
Ah, n/m. This one fixes a commit which were added after 10.1 (so not in any stable release), --
1e25327b24 target/i386/emulate: Allow instruction decoding from stream
Sorry for the noise.
/mjt