aboutsummaryrefslogtreecommitdiff
path: root/tests/tcg/s390x/noexec.c
diff options
context:
space:
mode:
authorIlya Leoshkevich <iii@linux.ibm.com>2022-08-17 17:05:04 +0200
committerRichard Henderson <richard.henderson@linaro.org>2022-09-06 08:04:26 +0100
commitab12c95d3f1999648d70bca54ebcc0588a07dd3e (patch)
tree45299ea36740d14226b4cf37d2bb6aedd5b53f4e /tests/tcg/s390x/noexec.c
parent50627f1b7b1b1db60166a670fbc17623c7d7243e (diff)
downloadqemu-ab12c95d3f1999648d70bca54ebcc0588a07dd3e.zip
qemu-ab12c95d3f1999648d70bca54ebcc0588a07dd3e.tar.gz
qemu-ab12c95d3f1999648d70bca54ebcc0588a07dd3e.tar.bz2
target/s390x: Make translator stop before the end of a page
Right now translator stops right *after* the end of a page, which breaks reporting of fault locations when the last instruction of a multi-insn translation block crosses a page boundary. Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Message-Id: <20220817150506.592862-3-iii@linux.ibm.com> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Diffstat (limited to 'tests/tcg/s390x/noexec.c')
-rw-r--r--tests/tcg/s390x/noexec.c106
1 files changed, 106 insertions, 0 deletions
diff --git a/tests/tcg/s390x/noexec.c b/tests/tcg/s390x/noexec.c
new file mode 100644
index 0000000..15d007d
--- /dev/null
+++ b/tests/tcg/s390x/noexec.c
@@ -0,0 +1,106 @@
+#include "../multiarch/noexec.c.inc"
+
+static void *arch_mcontext_pc(const mcontext_t *ctx)
+{
+ return (void *)ctx->psw.addr;
+}
+
+static int arch_mcontext_arg(const mcontext_t *ctx)
+{
+ return ctx->gregs[2];
+}
+
+static void arch_flush(void *p, int len)
+{
+}
+
+extern char noexec_1[];
+extern char noexec_2[];
+extern char noexec_end[];
+
+asm("noexec_1:\n"
+ " lgfi %r2,1\n" /* %r2 is 0 on entry, set 1. */
+ "noexec_2:\n"
+ " lgfi %r2,2\n" /* %r2 is 0/1; set 2. */
+ " br %r14\n" /* return */
+ "noexec_end:");
+
+extern char exrl_1[];
+extern char exrl_2[];
+extern char exrl_end[];
+
+asm("exrl_1:\n"
+ " exrl %r0, exrl_2\n"
+ " br %r14\n"
+ "exrl_2:\n"
+ " lgfi %r2,2\n"
+ "exrl_end:");
+
+int main(void)
+{
+ struct noexec_test noexec_tests[] = {
+ {
+ .name = "fallthrough",
+ .test_code = noexec_1,
+ .test_len = noexec_end - noexec_1,
+ .page_ofs = noexec_1 - noexec_2,
+ .entry_ofs = noexec_1 - noexec_2,
+ .expected_si_ofs = 0,
+ .expected_pc_ofs = 0,
+ .expected_arg = 1,
+ },
+ {
+ .name = "jump",
+ .test_code = noexec_1,
+ .test_len = noexec_end - noexec_1,
+ .page_ofs = noexec_1 - noexec_2,
+ .entry_ofs = 0,
+ .expected_si_ofs = 0,
+ .expected_pc_ofs = 0,
+ .expected_arg = 0,
+ },
+ {
+ .name = "exrl",
+ .test_code = exrl_1,
+ .test_len = exrl_end - exrl_1,
+ .page_ofs = exrl_1 - exrl_2,
+ .entry_ofs = exrl_1 - exrl_2,
+ .expected_si_ofs = 0,
+ .expected_pc_ofs = exrl_1 - exrl_2,
+ .expected_arg = 0,
+ },
+ {
+ .name = "fallthrough [cross]",
+ .test_code = noexec_1,
+ .test_len = noexec_end - noexec_1,
+ .page_ofs = noexec_1 - noexec_2 - 2,
+ .entry_ofs = noexec_1 - noexec_2 - 2,
+ .expected_si_ofs = 0,
+ .expected_pc_ofs = -2,
+ .expected_arg = 1,
+ },
+ {
+ .name = "jump [cross]",
+ .test_code = noexec_1,
+ .test_len = noexec_end - noexec_1,
+ .page_ofs = noexec_1 - noexec_2 - 2,
+ .entry_ofs = -2,
+ .expected_si_ofs = 0,
+ .expected_pc_ofs = -2,
+ .expected_arg = 0,
+ },
+ {
+ .name = "exrl [cross]",
+ .test_code = exrl_1,
+ .test_len = exrl_end - exrl_1,
+ .page_ofs = exrl_1 - exrl_2 - 2,
+ .entry_ofs = exrl_1 - exrl_2 - 2,
+ .expected_si_ofs = 0,
+ .expected_pc_ofs = exrl_1 - exrl_2 - 2,
+ .expected_arg = 0,
+ },
+ };
+
+ return test_noexec(noexec_tests,
+ sizeof(noexec_tests) / sizeof(noexec_tests[0]));
+}