On 2/24/26 7:52 AM, Florian Hofhammer wrote:
The test executes a non-existent syscall, which the syscall plugin
intercepts and redirects to a clean exit.
Due to architecture-specific quirks, the architecture-specific Makefiles
require setting specific compiler and linker flags in some cases.

Signed-off-by: Florian Hofhammer <[email protected]>
---
  tests/tcg/arm/Makefile.target                 |  6 +++++
  tests/tcg/hexagon/Makefile.target             |  7 +++++
  tests/tcg/mips/Makefile.target                |  6 ++++-
  tests/tcg/mips64/Makefile.target              | 15 +++++++++++
  tests/tcg/mips64el/Makefile.target            | 15 +++++++++++
  tests/tcg/mipsel/Makefile.target              | 15 +++++++++++
  tests/tcg/multiarch/Makefile.target           | 22 ++++++++++++++--
  .../{ => plugin}/check-plugin-output.sh       |  0
  .../{ => plugin}/test-plugin-mem-access.c     |  0
  .../plugin/test-plugin-skip-syscalls.c        | 26 +++++++++++++++++++
  tests/tcg/plugins/syscall.c                   |  6 +++++
  tests/tcg/sparc64/Makefile.target             | 16 ++++++++++++
  12 files changed, 131 insertions(+), 3 deletions(-)
  create mode 100644 tests/tcg/mips64/Makefile.target
  create mode 100644 tests/tcg/mips64el/Makefile.target
  create mode 100644 tests/tcg/mipsel/Makefile.target
  rename tests/tcg/multiarch/{ => plugin}/check-plugin-output.sh (100%)
  rename tests/tcg/multiarch/{ => plugin}/test-plugin-mem-access.c (100%)
  create mode 100644 tests/tcg/multiarch/plugin/test-plugin-skip-syscalls.c
  create mode 100644 tests/tcg/sparc64/Makefile.target

+++ b/tests/tcg/multiarch/plugin/test-plugin-skip-syscalls.c
@@ -0,0 +1,26 @@
+/*
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ *
+ * This test attempts to execute an invalid syscall. The syscall test plugin
+ * should intercept this.
+ */
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+void exit_success(void) __attribute__((section(".redirect"), noinline,
+                                       noreturn, used));
+
+void exit_success(void) {
+    _exit(EXIT_SUCCESS);
+}
+
+int main(int argc, char *argv[]) {
+    long ret = syscall(0xc0deUL);
+    if (ret != 0L) {
+        perror("");
+    }
+    /* We should never get here */
+    return EXIT_FAILURE;
+}
After reviewing patch 2, I think it could be nice to test also the path redirecting pc not from a syscall, in addition to what this test already does.

You can reuse syscall mechanic to communicate with plugin to share address that should crash and which destination it should reach instead.

And while at it, you can add the same thing from a signal handler (reusing syscall trick), so it should cover most of "special" cases.

You can merge all test cases in a single test.c.
Also, you can create a new set_pc plugin combining all this, because other test cases don't really belong to tests/tcg/plugins/syscall.c.

test.c:
int main(int argc, char *argv[]) {
  syscall(..., &&skip, &&dest);
error:
  g_assert_not_reached();
dest:
  return EXIT_SUCCESS;
}

plugin.c:
static void* error;
static void* dest;

void on_syscall(num, a1, a2) {
  if (num == magic) {
    error = a1;
    dest = a2;
  }
  return true;
}

void insn_exec(..., void* pc) {
  if (pc == error) {
    qemu_plugin_set_pc(dest);
  }
}

Regards,
Pierrick

Reply via email to