2017-08-31 01:39:53 +03:00
/*
* Plugin Shared Internal Functions
*
* Copyright ( C ) 2019 , Linaro
*
* License : GNU GPL , version 2 or later .
* See the COPYING file in the top - level directory .
*
* SPDX - License - Identifier : GPL - 2.0 - or - later
*/
2022-05-06 16:49:08 +03:00
# ifndef PLUGIN_H
# define PLUGIN_H
2017-08-31 01:39:53 +03:00
# include <gmodule.h>
2021-05-24 20:04:52 +03:00
# include "qemu/qht.h"
2017-08-31 01:39:53 +03:00
2024-02-27 17:43:21 +03:00
# define QEMU_PLUGIN_MIN_VERSION 2
2019-11-04 16:18:36 +03:00
2017-08-31 01:39:53 +03:00
/* global state */
struct qemu_plugin_state {
QTAILQ_HEAD ( , qemu_plugin_ctx ) ctxs ;
QLIST_HEAD ( , qemu_plugin_cb ) cb_lists [ QEMU_PLUGIN_EV_MAX ] ;
/*
* Use the HT as a hash map by inserting k = = v , which saves memory as
* documented by GLib . The parent struct is obtained with container_of ( ) .
*/
GHashTable * id_ht ;
/*
* Use the HT as a hash map . Note that we could use a list here ,
* but with the HT we avoid adding a field to CPUState .
*/
GHashTable * cpu_ht ;
2024-03-05 15:09:50 +03:00
QLIST_HEAD ( , qemu_plugin_scoreboard ) scoreboards ;
size_t scoreboard_alloc_size ;
2017-08-31 01:39:53 +03:00
DECLARE_BITMAP ( mask , QEMU_PLUGIN_EV_MAX ) ;
/*
* @ lock protects the struct as well as ctx - > uninstalling .
* The lock must be acquired by all API ops .
* The lock is recursive , which greatly simplifies things , e . g .
* callback registration from qemu_plugin_vcpu_for_each ( ) .
*/
QemuRecMutex lock ;
/*
* HT of callbacks invoked from helpers . All entries are freed when
* the code cache is flushed .
*/
struct qht dyn_cb_arr_ht ;
2024-02-27 17:43:22 +03:00
/* How many vcpus were started */
int num_vcpus ;
2017-08-31 01:39:53 +03:00
} ;
struct qemu_plugin_ctx {
GModule * handle ;
qemu_plugin_id_t id ;
struct qemu_plugin_cb * callbacks [ QEMU_PLUGIN_EV_MAX ] ;
QTAILQ_ENTRY ( qemu_plugin_ctx ) entry ;
/*
* keep a reference to @ desc until uninstall , so that plugins do not have
* to strdup plugin args .
*/
struct qemu_plugin_desc * desc ;
bool installing ;
bool uninstalling ;
bool resetting ;
} ;
struct qemu_plugin_ctx * plugin_id_to_ctx_locked ( qemu_plugin_id_t id ) ;
2024-03-05 15:09:53 +03:00
void plugin_register_inline_op_on_entry ( GArray * * arr ,
enum qemu_plugin_mem_rw rw ,
enum qemu_plugin_op op ,
qemu_plugin_u64 entry ,
uint64_t imm ) ;
2017-08-31 01:39:53 +03:00
void plugin_reset_uninstall ( qemu_plugin_id_t id ,
qemu_plugin_simple_cb_t cb ,
bool reset ) ;
void plugin_register_cb ( qemu_plugin_id_t id , enum qemu_plugin_event ev ,
void * func ) ;
void plugin_unregister_cb__locked ( struct qemu_plugin_ctx * ctx ,
enum qemu_plugin_event ev ) ;
void
plugin_register_cb_udata ( qemu_plugin_id_t id , enum qemu_plugin_event ev ,
void * func , void * udata ) ;
void
plugin_register_dyn_cb__udata ( GArray * * arr ,
qemu_plugin_vcpu_udata_cb_t cb ,
enum qemu_plugin_cb_flags flags , void * udata ) ;
2024-05-14 20:42:49 +03:00
void
plugin_register_dyn_cond_cb__udata ( GArray * * arr ,
qemu_plugin_vcpu_udata_cb_t cb ,
enum qemu_plugin_cb_flags flags ,
enum qemu_plugin_cond cond ,
qemu_plugin_u64 entry ,
uint64_t imm ,
void * udata ) ;
2017-08-31 01:39:53 +03:00
void plugin_register_vcpu_mem_cb ( GArray * * arr ,
void * cb ,
enum qemu_plugin_cb_flags flags ,
enum qemu_plugin_mem_rw rw ,
void * udata ) ;
2024-05-14 20:42:53 +03:00
void exec_inline_op ( enum plugin_dyn_cb_type type ,
struct qemu_plugin_inline_cb * cb ,
int cpu_index ) ;
2017-08-31 01:39:53 +03:00
2024-02-27 17:43:22 +03:00
int plugin_num_vcpus ( void ) ;
2024-03-05 15:09:50 +03:00
struct qemu_plugin_scoreboard * plugin_scoreboard_new ( size_t element_size ) ;
void plugin_scoreboard_free ( struct qemu_plugin_scoreboard * score ) ;
2022-05-06 16:49:08 +03:00
# endif /* PLUGIN_H */