target/i386: Generate #UD for LOCK on a register increment

Fix a TCG crash due to attempting an atomic increment
operation without having set up the address first.
This is a similar case to that dealt with in commit
e84fcd7f662a0d8198703, and we fix it in the same way.

Fixes: https://bugs.launchpad.net/qemu/+bug/1807675

Backports commit 8cb2ca3d7479748587313f0b34034a3f8aa08c92 from qemu
This commit is contained in:
Peter Maydell 2019-04-09 09:28:32 -04:00 committed by Lioncash
parent 1a50ee5826
commit 6b413ffa97
No known key found for this signature in database
GPG key ID: 4E3C3CC1031BA9C7

View file

@ -1564,6 +1564,11 @@ static void gen_inc(DisasContext *s, TCGMemOp ot, int d, int c)
TCGv cpu_cc_src = tcg_ctx->cpu_cc_src;
if (s->prefix & PREFIX_LOCK) {
if (d != OR_TMP0) {
/* Lock prefix when destination is not memory */
gen_illegal_opcode(s1);
return;
}
tcg_gen_movi_tl(tcg_ctx, s->T0, c > 0 ? 1 : -1);
tcg_gen_atomic_add_fetch_tl(tcg_ctx, s->T0, s->A0, s->T0,
s->mem_index, ot | MO_LE);