]> git.ipfire.org Git - thirdparty/valgrind.git/commit
s390x: Fix PC calculations with EX/EXRL
authorAndreas Arnez <arnez@linux.ibm.com>
Mon, 19 Aug 2024 13:22:40 +0000 (15:22 +0200)
committerAndreas Arnez <arnez@linux.ibm.com>
Mon, 19 Aug 2024 13:22:40 +0000 (15:22 +0200)
commit1375f1d0b3f1f50feb2315b00517126f27f9776e
tree2e96a03a28882a7f6563ba2bb5ef29ca7409646e
parent033baf8f18c602b943b637c2f9f25abc0b3d7667
s390x: Fix PC calculations with EX/EXRL

When executing under EX or EXRL, some instructions yield wrong results
under Valgrind.  This affects

* PC-relative instructions such as LARL or BRC

* instructions that set a link register, such as BASR

The issue is caused by confusions about the various instruction addresses
involved.  When executing an instruction under EX or EXRL, the following
addresses are relevant:

(1) The address of the execute instruction (guest_IA_curr_instr).  This is
needed when restarting the instruction or iterating over it.

(2) The address following the execute instruction (guest_IA_next_instr).
This is what a link register needs to be set to.

(3) The address of the target instruction.  This is the base for relative
addressing.

The latter isn't handled at all when translating for EX/EXRL.  And the
instructions that set a link register don't use guest_IA_next_instr, but
add their own instruction length to guest_IA_curr_instr.  This is wrong
whenever the target instruction and the EX/EXRL instruction have different
lengths.

Fix all this and enhance the test cases accordingly.  The updated test
cases fail before this patch and succeed afterwards.
VEX/priv/guest_s390_defs.h
VEX/priv/guest_s390_helpers.c
VEX/priv/guest_s390_toIR.c
none/tests/s390x/ex.c
none/tests/s390x/ex.stdout.exp
none/tests/s390x/exrl.c
none/tests/s390x/exrl.stdout.exp