Merge tag 'pull-loongarch-20241016' of https://gitlab.com/gaosong/qemu into staging
[qemu/armbru.git] / tests / tcg / x86_64 / noexec.c
blob9b124901be402b12328e6c91df6b5b8a4e350608
1 #include "../multiarch/noexec.c.inc"
3 static void *arch_mcontext_pc(const mcontext_t *ctx)
5 return (void *)ctx->gregs[REG_RIP];
8 int arch_mcontext_arg(const mcontext_t *ctx)
10 return ctx->gregs[REG_RDI];
13 static void arch_flush(void *p, int len)
17 extern char noexec_1[];
18 extern char noexec_2[];
19 extern char noexec_end[];
21 asm("noexec_1:\n"
22 " movq $1,%rdi\n" /* %rdi is 0 on entry, set 1. */
23 "noexec_2:\n"
24 " movq $2,%rdi\n" /* %rdi is 0/1; set 2. */
25 " ret\n"
26 "noexec_end:");
28 int main(void)
30 struct noexec_test noexec_tests[] = {
32 .name = "fallthrough",
33 .test_code = noexec_1,
34 .test_len = noexec_end - noexec_1,
35 .page_ofs = noexec_1 - noexec_2,
36 .entry_ofs = noexec_1 - noexec_2,
37 .expected_si_ofs = 0,
38 .expected_pc_ofs = 0,
39 .expected_arg = 1,
42 .name = "jump",
43 .test_code = noexec_1,
44 .test_len = noexec_end - noexec_1,
45 .page_ofs = noexec_1 - noexec_2,
46 .entry_ofs = 0,
47 .expected_si_ofs = 0,
48 .expected_pc_ofs = 0,
49 .expected_arg = 0,
52 .name = "fallthrough [cross]",
53 .test_code = noexec_1,
54 .test_len = noexec_end - noexec_1,
55 .page_ofs = noexec_1 - noexec_2 - 2,
56 .entry_ofs = noexec_1 - noexec_2 - 2,
57 .expected_si_ofs = 0,
58 .expected_pc_ofs = -2,
59 .expected_arg = 1,
62 .name = "jump [cross]",
63 .test_code = noexec_1,
64 .test_len = noexec_end - noexec_1,
65 .page_ofs = noexec_1 - noexec_2 - 2,
66 .entry_ofs = -2,
67 .expected_si_ofs = 0,
68 .expected_pc_ofs = -2,
69 .expected_arg = 0,
73 return test_noexec(noexec_tests,
74 sizeof(noexec_tests) / sizeof(noexec_tests[0]));