2
0

plugin.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * Plugin Shared Internal Functions
  3. *
  4. * Copyright (C) 2019, Linaro
  5. *
  6. * License: GNU GPL, version 2 or later.
  7. * See the COPYING file in the top-level directory.
  8. *
  9. * SPDX-License-Identifier: GPL-2.0-or-later
  10. */
  11. #ifndef _PLUGIN_INTERNAL_H_
  12. #define _PLUGIN_INTERNAL_H_
  13. #include <gmodule.h>
  14. #define QEMU_PLUGIN_MIN_VERSION 0
  15. /* global state */
  16. struct qemu_plugin_state {
  17. QTAILQ_HEAD(, qemu_plugin_ctx) ctxs;
  18. QLIST_HEAD(, qemu_plugin_cb) cb_lists[QEMU_PLUGIN_EV_MAX];
  19. /*
  20. * Use the HT as a hash map by inserting k == v, which saves memory as
  21. * documented by GLib. The parent struct is obtained with container_of().
  22. */
  23. GHashTable *id_ht;
  24. /*
  25. * Use the HT as a hash map. Note that we could use a list here,
  26. * but with the HT we avoid adding a field to CPUState.
  27. */
  28. GHashTable *cpu_ht;
  29. DECLARE_BITMAP(mask, QEMU_PLUGIN_EV_MAX);
  30. /*
  31. * @lock protects the struct as well as ctx->uninstalling.
  32. * The lock must be acquired by all API ops.
  33. * The lock is recursive, which greatly simplifies things, e.g.
  34. * callback registration from qemu_plugin_vcpu_for_each().
  35. */
  36. QemuRecMutex lock;
  37. /*
  38. * HT of callbacks invoked from helpers. All entries are freed when
  39. * the code cache is flushed.
  40. */
  41. struct qht dyn_cb_arr_ht;
  42. };
  43. struct qemu_plugin_ctx {
  44. GModule *handle;
  45. qemu_plugin_id_t id;
  46. struct qemu_plugin_cb *callbacks[QEMU_PLUGIN_EV_MAX];
  47. QTAILQ_ENTRY(qemu_plugin_ctx) entry;
  48. /*
  49. * keep a reference to @desc until uninstall, so that plugins do not have
  50. * to strdup plugin args.
  51. */
  52. struct qemu_plugin_desc *desc;
  53. bool installing;
  54. bool uninstalling;
  55. bool resetting;
  56. };
  57. struct qemu_plugin_ctx *plugin_id_to_ctx_locked(qemu_plugin_id_t id);
  58. void plugin_register_inline_op(GArray **arr,
  59. enum qemu_plugin_mem_rw rw,
  60. enum qemu_plugin_op op, void *ptr,
  61. uint64_t imm);
  62. void plugin_reset_uninstall(qemu_plugin_id_t id,
  63. qemu_plugin_simple_cb_t cb,
  64. bool reset);
  65. void plugin_register_cb(qemu_plugin_id_t id, enum qemu_plugin_event ev,
  66. void *func);
  67. void plugin_unregister_cb__locked(struct qemu_plugin_ctx *ctx,
  68. enum qemu_plugin_event ev);
  69. void
  70. plugin_register_cb_udata(qemu_plugin_id_t id, enum qemu_plugin_event ev,
  71. void *func, void *udata);
  72. void
  73. plugin_register_dyn_cb__udata(GArray **arr,
  74. qemu_plugin_vcpu_udata_cb_t cb,
  75. enum qemu_plugin_cb_flags flags, void *udata);
  76. void plugin_register_vcpu_mem_cb(GArray **arr,
  77. void *cb,
  78. enum qemu_plugin_cb_flags flags,
  79. enum qemu_plugin_mem_rw rw,
  80. void *udata);
  81. void exec_inline_op(struct qemu_plugin_dyn_cb *cb);
  82. #endif /* _PLUGIN_INTERNAL_H_ */