qemu/include/exec/plugin-gen.h
<<
>>
Prefs
   1/*
   2 * Copyright (C) 2017, Emilio G. Cota <cota@braap.org>
   3 *
   4 * License: GNU GPL, version 2 or later.
   5 *   See the COPYING file in the top-level directory.
   6 *
   7 * plugin-gen.h - TCG-dependent definitions for generating plugin code
   8 *
   9 * This header should be included only from plugin.c and C files that emit
  10 * TCG code.
  11 */
  12#ifndef QEMU_PLUGIN_GEN_H
  13#define QEMU_PLUGIN_GEN_H
  14
  15#include "qemu/plugin.h"
  16#include "tcg/tcg.h"
  17
  18struct DisasContextBase;
  19
  20#ifdef CONFIG_PLUGIN
  21
  22bool plugin_gen_tb_start(CPUState *cpu, const struct DisasContextBase *db,
  23                         bool supress);
  24void plugin_gen_tb_end(CPUState *cpu);
  25void plugin_gen_insn_start(CPUState *cpu, const struct DisasContextBase *db);
  26void plugin_gen_insn_end(void);
  27
  28void plugin_gen_disable_mem_helpers(void);
  29void plugin_gen_empty_mem_callback(TCGv addr, uint32_t info);
  30
  31static inline void plugin_insn_append(abi_ptr pc, const void *from, size_t size)
  32{
  33    struct qemu_plugin_insn *insn = tcg_ctx->plugin_insn;
  34    abi_ptr off;
  35
  36    if (insn == NULL) {
  37        return;
  38    }
  39    off = pc - insn->vaddr;
  40    if (off < insn->data->len) {
  41        g_byte_array_set_size(insn->data, off);
  42    } else if (off > insn->data->len) {
  43        /* we have an unexpected gap */
  44        g_assert_not_reached();
  45    }
  46
  47    insn->data = g_byte_array_append(insn->data, from, size);
  48}
  49
  50#else /* !CONFIG_PLUGIN */
  51
  52static inline bool
  53plugin_gen_tb_start(CPUState *cpu, const struct DisasContextBase *db, bool sup)
  54{
  55    return false;
  56}
  57
  58static inline
  59void plugin_gen_insn_start(CPUState *cpu, const struct DisasContextBase *db)
  60{ }
  61
  62static inline void plugin_gen_insn_end(void)
  63{ }
  64
  65static inline void plugin_gen_tb_end(CPUState *cpu)
  66{ }
  67
  68static inline void plugin_gen_disable_mem_helpers(void)
  69{ }
  70
  71static inline void plugin_gen_empty_mem_callback(TCGv addr, uint32_t info)
  72{ }
  73
  74static inline void plugin_insn_append(abi_ptr pc, const void *from, size_t size)
  75{ }
  76
  77#endif /* CONFIG_PLUGIN */
  78
  79#endif /* QEMU_PLUGIN_GEN_H */
  80
  81