Matthias Weckbecker | 279d0a5 | 2021-03-12 17:28:08 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2020, Matthias Weckbecker <matthias@weckbecker.name> |
| 3 | * |
| 4 | * License: GNU GPL, version 2 or later. |
| 5 | * See the COPYING file in the top-level directory. |
| 6 | */ |
| 7 | #include <inttypes.h> |
| 8 | #include <assert.h> |
| 9 | #include <stdlib.h> |
| 10 | #include <string.h> |
| 11 | #include <unistd.h> |
| 12 | #include <stdio.h> |
| 13 | #include <glib.h> |
| 14 | |
| 15 | #include <qemu-plugin.h> |
| 16 | |
| 17 | QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION; |
| 18 | |
| 19 | static void vcpu_syscall(qemu_plugin_id_t id, unsigned int vcpu_index, |
| 20 | int64_t num, uint64_t a1, uint64_t a2, |
| 21 | uint64_t a3, uint64_t a4, uint64_t a5, |
| 22 | uint64_t a6, uint64_t a7, uint64_t a8) |
| 23 | { |
| 24 | g_autofree gchar *out = g_strdup_printf("syscall #%" PRIi64 "\n", num); |
| 25 | qemu_plugin_outs(out); |
| 26 | } |
| 27 | |
| 28 | static void vcpu_syscall_ret(qemu_plugin_id_t id, unsigned int vcpu_idx, |
| 29 | int64_t num, int64_t ret) |
| 30 | { |
| 31 | g_autofree gchar *out; |
| 32 | out = g_strdup_printf("syscall #%" PRIi64 " returned -> %" PRIi64 "\n", |
| 33 | num, ret); |
| 34 | qemu_plugin_outs(out); |
| 35 | } |
| 36 | |
| 37 | /* ************************************************************************* */ |
| 38 | |
| 39 | static void plugin_exit(qemu_plugin_id_t id, void *p) {} |
| 40 | |
| 41 | QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id, |
| 42 | const qemu_info_t *info, |
| 43 | int argc, char **argv) |
| 44 | { |
| 45 | qemu_plugin_register_vcpu_syscall_cb(id, vcpu_syscall); |
| 46 | qemu_plugin_register_vcpu_syscall_ret_cb(id, vcpu_syscall_ret); |
| 47 | qemu_plugin_register_atexit_cb(id, plugin_exit, NULL); |
| 48 | return 0; |
| 49 | } |