cachepc-qemu

Fork of AMDESE/qemu with changes for cachepc side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-qemu
Log | Files | Refs | Submodules | LICENSE | sfeed.txt

replay.h (8546B)


      1#ifndef REPLAY_H
      2#define REPLAY_H
      3
      4/*
      5 * replay.h
      6 *
      7 * Copyright (c) 2010-2015 Institute for System Programming
      8 *                         of the Russian Academy of Sciences.
      9 *
     10 * This work is licensed under the terms of the GNU GPL, version 2 or later.
     11 * See the COPYING file in the top-level directory.
     12 *
     13 */
     14
     15#include "qapi/qapi-types-misc.h"
     16#include "qapi/qapi-types-run-state.h"
     17#include "qapi/qapi-types-replay.h"
     18#include "qapi/qapi-types-ui.h"
     19#include "block/aio.h"
     20
     21/* replay clock kinds */
     22enum ReplayClockKind {
     23    /* host_clock */
     24    REPLAY_CLOCK_HOST,
     25    /* virtual_rt_clock */
     26    REPLAY_CLOCK_VIRTUAL_RT,
     27    REPLAY_CLOCK_COUNT
     28};
     29typedef enum ReplayClockKind ReplayClockKind;
     30
     31/* IDs of the checkpoints */
     32enum ReplayCheckpoint {
     33    CHECKPOINT_CLOCK_WARP_START,
     34    CHECKPOINT_CLOCK_WARP_ACCOUNT,
     35    CHECKPOINT_RESET_REQUESTED,
     36    CHECKPOINT_SUSPEND_REQUESTED,
     37    CHECKPOINT_CLOCK_VIRTUAL,
     38    CHECKPOINT_CLOCK_HOST,
     39    CHECKPOINT_CLOCK_VIRTUAL_RT,
     40    CHECKPOINT_INIT,
     41    CHECKPOINT_RESET,
     42    CHECKPOINT_COUNT
     43};
     44typedef enum ReplayCheckpoint ReplayCheckpoint;
     45
     46typedef struct ReplayNetState ReplayNetState;
     47
     48extern ReplayMode replay_mode;
     49
     50/* Name of the initial VM snapshot */
     51extern char *replay_snapshot;
     52
     53/* Replay locking
     54 *
     55 * The locks are needed to protect the shared structures and log file
     56 * when doing record/replay. They also are the main sync-point between
     57 * the main-loop thread and the vCPU thread. This was a role
     58 * previously filled by the BQL which has been busy trying to reduce
     59 * its impact across the code. This ensures blocks of events stay
     60 * sequential and reproducible.
     61 */
     62
     63void replay_mutex_lock(void);
     64void replay_mutex_unlock(void);
     65
     66/* Replay process control functions */
     67
     68/*! Enables recording or saving event log with specified parameters */
     69void replay_configure(struct QemuOpts *opts);
     70/*! Initializes timers used for snapshotting and enables events recording */
     71void replay_start(void);
     72/*! Closes replay log file and frees other resources. */
     73void replay_finish(void);
     74/*! Adds replay blocker with the specified error description */
     75void replay_add_blocker(Error *reason);
     76/* Returns name of the replay log file */
     77const char *replay_get_filename(void);
     78/*
     79 * Start making one step in backward direction.
     80 * Used by gdbstub for backwards debugging.
     81 * Returns true on success.
     82 */
     83bool replay_reverse_step(void);
     84/*
     85 * Start searching the last breakpoint/watchpoint.
     86 * Used by gdbstub for backwards debugging.
     87 * Returns true if the process successfully started.
     88 */
     89bool replay_reverse_continue(void);
     90/*
     91 * Returns true if replay module is processing
     92 * reverse_continue or reverse_step request
     93 */
     94bool replay_running_debug(void);
     95/* Called in reverse debugging mode to collect breakpoint information */
     96void replay_breakpoint(void);
     97/* Called when gdb is attached to gdbstub */
     98void replay_gdb_attached(void);
     99
    100/* Processing the instructions */
    101
    102/*! Returns number of executed instructions. */
    103uint64_t replay_get_current_icount(void);
    104/*! Returns number of instructions to execute in replay mode. */
    105int replay_get_instructions(void);
    106/*! Updates instructions counter in replay mode. */
    107void replay_account_executed_instructions(void);
    108
    109/* Interrupts and exceptions */
    110
    111/*! Called by exception handler to write or read
    112    exception processing events. */
    113bool replay_exception(void);
    114/*! Used to determine that exception is pending.
    115    Does not proceed to the next event in the log. */
    116bool replay_has_exception(void);
    117/*! Called by interrupt handlers to write or read
    118    interrupt processing events.
    119    \return true if interrupt should be processed */
    120bool replay_interrupt(void);
    121/*! Tries to read interrupt event from the file.
    122    Returns true, when interrupt request is pending */
    123bool replay_has_interrupt(void);
    124
    125/* Processing clocks and other time sources */
    126
    127/*! Save the specified clock */
    128int64_t replay_save_clock(ReplayClockKind kind, int64_t clock,
    129                          int64_t raw_icount);
    130/*! Read the specified clock from the log or return cached data */
    131int64_t replay_read_clock(ReplayClockKind kind, int64_t raw_icount);
    132/*! Saves or reads the clock depending on the current replay mode. */
    133#define REPLAY_CLOCK(clock, value)                                      \
    134    (replay_mode == REPLAY_MODE_PLAY                                    \
    135        ? replay_read_clock((clock), icount_get_raw())                  \
    136        : replay_mode == REPLAY_MODE_RECORD                             \
    137            ? replay_save_clock((clock), (value), icount_get_raw())     \
    138            : (value))
    139#define REPLAY_CLOCK_LOCKED(clock, value)                               \
    140    (replay_mode == REPLAY_MODE_PLAY                                    \
    141        ? replay_read_clock((clock), icount_get_raw_locked())           \
    142        : replay_mode == REPLAY_MODE_RECORD                             \
    143            ? replay_save_clock((clock), (value), icount_get_raw_locked()) \
    144            : (value))
    145
    146/* Processing data from random generators */
    147
    148/* Saves the values from the random number generator */
    149void replay_save_random(int ret, void *buf, size_t len);
    150/* Loads the saved values for the random number generator */
    151int replay_read_random(void *buf, size_t len);
    152
    153/* Events */
    154
    155/*! Called when qemu shutdown is requested. */
    156void replay_shutdown_request(ShutdownCause cause);
    157/*! Should be called at check points in the execution.
    158    These check points are skipped, if they were not met.
    159    Saves checkpoint in the SAVE mode and validates in the PLAY mode.
    160    Returns 0 in PLAY mode if checkpoint was not found.
    161    Returns 1 in all other cases. */
    162bool replay_checkpoint(ReplayCheckpoint checkpoint);
    163/*! Used to determine that checkpoint is pending.
    164    Does not proceed to the next event in the log. */
    165bool replay_has_checkpoint(void);
    166
    167/* Asynchronous events queue */
    168
    169/*! Disables storing events in the queue */
    170void replay_disable_events(void);
    171/*! Enables storing events in the queue */
    172void replay_enable_events(void);
    173/*! Returns true when saving events is enabled */
    174bool replay_events_enabled(void);
    175/* Flushes events queue */
    176void replay_flush_events(void);
    177/*! Adds bottom half event to the queue */
    178void replay_bh_schedule_event(QEMUBH *bh);
    179/* Adds oneshot bottom half event to the queue */
    180void replay_bh_schedule_oneshot_event(AioContext *ctx,
    181    QEMUBHFunc *cb, void *opaque);
    182/*! Adds input event to the queue */
    183void replay_input_event(QemuConsole *src, InputEvent *evt);
    184/*! Adds input sync event to the queue */
    185void replay_input_sync_event(void);
    186/*! Adds block layer event to the queue */
    187void replay_block_event(QEMUBH *bh, uint64_t id);
    188/*! Returns ID for the next block event */
    189uint64_t blkreplay_next_id(void);
    190
    191/* Character device */
    192
    193/*! Registers char driver to save it's events */
    194void replay_register_char_driver(struct Chardev *chr);
    195/*! Saves write to char device event to the log */
    196void replay_chr_be_write(struct Chardev *s, uint8_t *buf, int len);
    197/*! Writes char write return value to the replay log. */
    198void replay_char_write_event_save(int res, int offset);
    199/*! Reads char write return value from the replay log. */
    200void replay_char_write_event_load(int *res, int *offset);
    201/*! Reads information about read_all character event. */
    202int replay_char_read_all_load(uint8_t *buf);
    203/*! Writes character read_all error code into the replay log. */
    204void replay_char_read_all_save_error(int res);
    205/*! Writes character read_all execution result into the replay log. */
    206void replay_char_read_all_save_buf(uint8_t *buf, int offset);
    207
    208/* Network */
    209
    210/*! Registers replay network filter attached to some backend. */
    211ReplayNetState *replay_register_net(NetFilterState *nfs);
    212/*! Unregisters replay network filter. */
    213void replay_unregister_net(ReplayNetState *rns);
    214/*! Called to write network packet to the replay log. */
    215void replay_net_packet_event(ReplayNetState *rns, unsigned flags,
    216                             const struct iovec *iov, int iovcnt);
    217
    218/* Audio */
    219
    220/*! Saves/restores number of played samples of audio out operation. */
    221void replay_audio_out(size_t *played);
    222/*! Saves/restores recorded samples of audio in operation. */
    223void replay_audio_in(size_t *recorded, void *samples, size_t *wpos, size_t size);
    224
    225/* VM state operations */
    226
    227/*! Called at the start of execution.
    228    Loads or saves initial vmstate depending on execution mode. */
    229void replay_vmstate_init(void);
    230/*! Called to ensure that replay state is consistent and VM snapshot
    231    can be created */
    232bool replay_can_snapshot(void);
    233
    234#endif