[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 15/33] tests/tcg: Add the PROT_NONE gdbstub test
From: |
Richard Henderson |
Subject: |
[PATCH 15/33] tests/tcg: Add the PROT_NONE gdbstub test |
Date: |
Sun, 28 Jan 2024 14:41:55 +1000 |
From: Ilya Leoshkevich <iii@linux.ibm.com>
Make sure that qemu gdbstub, like gdbserver, allows reading from and
writing to PROT_NONE pages.
Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
Message-Id: <20240109230808.583012-4-iii@linux.ibm.com>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
tests/tcg/multiarch/prot-none.c | 40 ++++++++++++++++++++++++
tests/tcg/multiarch/Makefile.target | 9 +++++-
tests/tcg/multiarch/gdbstub/prot-none.py | 22 +++++++++++++
3 files changed, 70 insertions(+), 1 deletion(-)
create mode 100644 tests/tcg/multiarch/prot-none.c
create mode 100644 tests/tcg/multiarch/gdbstub/prot-none.py
diff --git a/tests/tcg/multiarch/prot-none.c b/tests/tcg/multiarch/prot-none.c
new file mode 100644
index 0000000000..dc56aadb3c
--- /dev/null
+++ b/tests/tcg/multiarch/prot-none.c
@@ -0,0 +1,40 @@
+/*
+ * Test that GDB can access PROT_NONE pages.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+#include <assert.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/mman.h>
+#include <unistd.h>
+
+void break_here(void *q)
+{
+}
+
+int main(void)
+{
+ long pagesize = sysconf(_SC_PAGESIZE);
+ void *p, *q;
+ int err;
+
+ p = mmap(NULL, pagesize * 2, PROT_READ | PROT_WRITE,
+ MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+ assert(p != MAP_FAILED);
+ q = p + pagesize - 1;
+ strcpy(q, "42");
+
+ err = mprotect(p, pagesize * 2, PROT_NONE);
+ assert(err == 0);
+
+ break_here(q);
+
+ err = mprotect(p, pagesize * 2, PROT_READ);
+ assert(err == 0);
+ if (getenv("PROT_NONE_PY")) {
+ assert(strcmp(q, "24") == 0);
+ }
+
+ return EXIT_SUCCESS;
+}
diff --git a/tests/tcg/multiarch/Makefile.target
b/tests/tcg/multiarch/Makefile.target
index d31ba8d6ae..315a2e1358 100644
--- a/tests/tcg/multiarch/Makefile.target
+++ b/tests/tcg/multiarch/Makefile.target
@@ -101,13 +101,20 @@ run-gdbstub-registers: sha512
--bin $< --test $(MULTIARCH_SRC)/gdbstub/registers.py, \
checking register enumeration)
+run-gdbstub-prot-none: prot-none
+ $(call run-test, $@, env PROT_NONE_PY=1 $(GDB_SCRIPT) \
+ --gdb $(GDB) \
+ --qemu $(QEMU) --qargs "$(QEMU_OPTS)" \
+ --bin $< --test $(MULTIARCH_SRC)/gdbstub/prot-none.py, \
+ accessing PROT_NONE memory)
+
else
run-gdbstub-%:
$(call skip-test, "gdbstub test $*", "need working gdb with $(patsubst
-%,,$(TARGET_NAME)) support")
endif
EXTRA_RUNS += run-gdbstub-sha1 run-gdbstub-qxfer-auxv-read \
run-gdbstub-proc-mappings run-gdbstub-thread-breakpoint \
- run-gdbstub-registers
+ run-gdbstub-registers run-gdbstub-prot-none
# ARM Compatible Semi Hosting Tests
#
diff --git a/tests/tcg/multiarch/gdbstub/prot-none.py
b/tests/tcg/multiarch/gdbstub/prot-none.py
new file mode 100644
index 0000000000..f1f1dd82cb
--- /dev/null
+++ b/tests/tcg/multiarch/gdbstub/prot-none.py
@@ -0,0 +1,22 @@
+"""Test that GDB can access PROT_NONE pages.
+
+This runs as a sourced script (via -x, via run-test.py).
+
+SPDX-License-Identifier: GPL-2.0-or-later
+"""
+from test_gdbstub import main, report
+
+
+def run_test():
+ """Run through the tests one by one"""
+ gdb.Breakpoint("break_here")
+ gdb.execute("continue")
+ val = gdb.parse_and_eval("*(char[2] *)q").string()
+ report(val == "42", "{} == 42".format(val))
+ gdb.execute("set *(char[3] *)q = \"24\"")
+ gdb.execute("continue")
+ exitcode = int(gdb.parse_and_eval("$_exitcode"))
+ report(exitcode == 0, "{} == 0".format(exitcode))
+
+
+main(run_test)
--
2.34.1
- Re: [PATCH 07/33] target: Uninline cpu_mmu_index(), (continued)
- [PATCH 09/33] include/exec: Move PAGE_* macros to common header, Richard Henderson, 2024/01/27
- [PATCH 08/33] target: Uninline cpu_get_tb_cpu_state(), Richard Henderson, 2024/01/27
- [PATCH 10/33] include/exec: Move cpu_*()/cpu_env() to common header, Richard Henderson, 2024/01/27
- [PATCH 11/33] include/hw/core: Move do_interrupt in TCGCPUOps, Richard Henderson, 2024/01/27
- [PATCH 12/33] include/hw/core: Remove i386 conditional on fake_user_interrupt, Richard Henderson, 2024/01/27
- [PATCH 13/33] linux-user: Allow gdbstub to ignore page protection, Richard Henderson, 2024/01/27
- [PATCH 14/33] tests/tcg: Factor out gdbstub test functions, Richard Henderson, 2024/01/27
- [PATCH 15/33] tests/tcg: Add the PROT_NONE gdbstub test,
Richard Henderson <=
- [PATCH 16/33] accel/tcg/cpu-exec: Use RCU_READ_LOCK_GUARD, Richard Henderson, 2024/01/27
- [PATCH 17/33] target: Make qemu_target_page_mask() available for *-user, Richard Henderson, 2024/01/27
- [PATCH 18/33] accel/tcg: Make use of qemu_target_page_mask() in perf.c, Richard Henderson, 2024/01/27
- [PATCH 19/33] tcg: Make tb_cflags() usable from target-agnostic code, Richard Henderson, 2024/01/27
- [PATCH 20/33] accel/tcg: Remove #ifdef TARGET_I386 from perf.c, Richard Henderson, 2024/01/27
- [PATCH 21/33] accel/tcg: Move perf and debuginfo support to tcg/, Richard Henderson, 2024/01/27
- [PATCH 22/33] accel/tcg: Rename tcg_ss[] -> tcg_specific_ss[] in meson, Richard Henderson, 2024/01/27
- [PATCH 23/33] accel/tcg: Rename tcg_cpus_destroy() -> tcg_cpu_destroy(), Richard Henderson, 2024/01/27
- [PATCH 24/33] accel/tcg: Rename tcg_cpus_exec() -> tcg_cpu_exec(), Richard Henderson, 2024/01/27