2015-09-17 18:23:43 +02:00
|
|
|
#ifndef REPLAY_INTERNAL_H
|
|
|
|
#define REPLAY_INTERNAL_H
|
|
|
|
|
|
|
|
/*
|
|
|
|
* replay-internal.h
|
|
|
|
*
|
|
|
|
* Copyright (c) 2010-2015 Institute for System Programming
|
|
|
|
* of the Russian Academy of Sciences.
|
|
|
|
*
|
|
|
|
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
|
|
|
* See the COPYING file in the top-level directory.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2022-05-27 12:46:23 +02:00
|
|
|
/* Asynchronous events IDs */
|
|
|
|
|
|
|
|
typedef enum ReplayAsyncEventKind {
|
|
|
|
REPLAY_ASYNC_EVENT_BH,
|
|
|
|
REPLAY_ASYNC_EVENT_BH_ONESHOT,
|
|
|
|
REPLAY_ASYNC_EVENT_INPUT,
|
|
|
|
REPLAY_ASYNC_EVENT_INPUT_SYNC,
|
|
|
|
REPLAY_ASYNC_EVENT_CHAR_READ,
|
|
|
|
REPLAY_ASYNC_EVENT_BLOCK,
|
|
|
|
REPLAY_ASYNC_EVENT_NET,
|
|
|
|
REPLAY_ASYNC_COUNT
|
|
|
|
} ReplayAsyncEventKind;
|
|
|
|
|
2023-12-11 10:13:38 +01:00
|
|
|
/*
|
|
|
|
* Any changes to order/number of events will need to bump
|
|
|
|
* REPLAY_VERSION to prevent confusion with old logs. Also don't
|
|
|
|
* forget to update replay_event_name() to make your debugging life
|
|
|
|
* easier.
|
|
|
|
*/
|
2015-09-17 18:23:54 +02:00
|
|
|
enum ReplayEvents {
|
|
|
|
/* for instruction event */
|
|
|
|
EVENT_INSTRUCTION,
|
2015-09-17 18:24:16 +02:00
|
|
|
/* for software interrupt */
|
|
|
|
EVENT_INTERRUPT,
|
|
|
|
/* for emulated exceptions */
|
|
|
|
EVENT_EXCEPTION,
|
2015-09-17 18:24:22 +02:00
|
|
|
/* for async events */
|
|
|
|
EVENT_ASYNC,
|
2022-05-27 12:46:23 +02:00
|
|
|
EVENT_ASYNC_LAST = EVENT_ASYNC + REPLAY_ASYNC_COUNT - 1,
|
2017-05-15 23:41:12 +02:00
|
|
|
/* for shutdown requests, range allows recovery of ShutdownCause */
|
2015-09-17 18:24:33 +02:00
|
|
|
EVENT_SHUTDOWN,
|
2017-05-15 23:41:12 +02:00
|
|
|
EVENT_SHUTDOWN_LAST = EVENT_SHUTDOWN + SHUTDOWN_CAUSE__MAX,
|
2016-03-14 08:44:36 +01:00
|
|
|
/* for character device write event */
|
|
|
|
EVENT_CHAR_WRITE,
|
|
|
|
/* for character device read all event */
|
|
|
|
EVENT_CHAR_READ_ALL,
|
|
|
|
EVENT_CHAR_READ_ALL_ERROR,
|
2017-02-02 06:50:54 +01:00
|
|
|
/* for audio out event */
|
|
|
|
EVENT_AUDIO_OUT,
|
|
|
|
/* for audio in event */
|
|
|
|
EVENT_AUDIO_IN,
|
2019-12-19 13:50:48 +01:00
|
|
|
/* for random number generator */
|
|
|
|
EVENT_RANDOM,
|
2015-09-17 18:24:28 +02:00
|
|
|
/* for clock read/writes */
|
|
|
|
/* some of greater codes are reserved for clocks */
|
|
|
|
EVENT_CLOCK,
|
|
|
|
EVENT_CLOCK_LAST = EVENT_CLOCK + REPLAY_CLOCK_COUNT - 1,
|
2015-09-17 18:24:44 +02:00
|
|
|
/* for checkpoint event */
|
|
|
|
/* some of greater codes are reserved for checkpoints */
|
|
|
|
EVENT_CHECKPOINT,
|
|
|
|
EVENT_CHECKPOINT_LAST = EVENT_CHECKPOINT + CHECKPOINT_COUNT - 1,
|
2015-09-17 18:25:07 +02:00
|
|
|
/* end of log event */
|
|
|
|
EVENT_END,
|
2015-09-17 18:23:54 +02:00
|
|
|
EVENT_COUNT
|
|
|
|
};
|
|
|
|
|
2023-12-11 10:13:36 +01:00
|
|
|
/**
|
|
|
|
* typedef ReplayState - global tracking Replay state
|
|
|
|
*
|
|
|
|
* This structure tracks where we are in the current ReplayState
|
|
|
|
* including the logged events from the recorded replay stream. Some
|
|
|
|
* of the data is also stored/restored from VMStateDescription when VM
|
|
|
|
* save/restore events take place.
|
|
|
|
*
|
|
|
|
* @cached_clock: Cached clocks values
|
|
|
|
* @current_icount: number of processed instructions
|
|
|
|
* @instruction_count: number of instructions until next event
|
2023-12-11 10:13:38 +01:00
|
|
|
* @current_event: current event index
|
2023-12-11 10:13:36 +01:00
|
|
|
* @data_kind: current event
|
2023-12-11 10:13:37 +01:00
|
|
|
* @has_unread_data: true if event not yet processed
|
2023-12-11 10:13:36 +01:00
|
|
|
* @file_offset: offset into replay log at replay snapshot
|
|
|
|
* @block_request_id: current serialised block request id
|
|
|
|
* @read_event_id: current async read event id
|
|
|
|
*/
|
2015-09-17 18:23:54 +02:00
|
|
|
typedef struct ReplayState {
|
2015-09-17 18:24:28 +02:00
|
|
|
int64_t cached_clock[REPLAY_CLOCK_COUNT];
|
2019-07-25 10:44:43 +02:00
|
|
|
uint64_t current_icount;
|
|
|
|
int instruction_count;
|
2023-12-11 10:13:38 +01:00
|
|
|
unsigned int current_event;
|
2016-09-26 10:08:04 +02:00
|
|
|
unsigned int data_kind;
|
2023-12-11 10:13:37 +01:00
|
|
|
bool has_unread_data;
|
2016-09-26 10:08:10 +02:00
|
|
|
uint64_t file_offset;
|
2016-09-26 10:08:16 +02:00
|
|
|
uint64_t block_request_id;
|
2018-02-27 10:53:22 +01:00
|
|
|
uint64_t read_event_id;
|
2015-09-17 18:23:54 +02:00
|
|
|
} ReplayState;
|
|
|
|
extern ReplayState replay_state;
|
|
|
|
|
2015-09-17 18:23:43 +02:00
|
|
|
/* File for replay writing */
|
|
|
|
extern FILE *replay_file;
|
2020-10-03 19:13:26 +02:00
|
|
|
/* Instruction count of the replay breakpoint */
|
|
|
|
extern uint64_t replay_break_icount;
|
|
|
|
/* Timer for the replay breakpoint callback */
|
|
|
|
extern QEMUTimer *replay_break_timer;
|
2015-09-17 18:23:43 +02:00
|
|
|
|
|
|
|
void replay_put_byte(uint8_t byte);
|
|
|
|
void replay_put_event(uint8_t event);
|
|
|
|
void replay_put_word(uint16_t word);
|
|
|
|
void replay_put_dword(uint32_t dword);
|
|
|
|
void replay_put_qword(int64_t qword);
|
|
|
|
void replay_put_array(const uint8_t *buf, size_t size);
|
|
|
|
|
|
|
|
uint8_t replay_get_byte(void);
|
|
|
|
uint16_t replay_get_word(void);
|
|
|
|
uint32_t replay_get_dword(void);
|
|
|
|
int64_t replay_get_qword(void);
|
|
|
|
void replay_get_array(uint8_t *buf, size_t *size);
|
|
|
|
void replay_get_array_alloc(uint8_t **buf, size_t *size);
|
|
|
|
|
2018-02-27 10:52:42 +01:00
|
|
|
/* Mutex functions for protecting replay log file and ensuring
|
|
|
|
* synchronisation between vCPU and main-loop threads. */
|
2015-09-17 18:23:48 +02:00
|
|
|
|
|
|
|
void replay_mutex_init(void);
|
2018-02-27 10:52:42 +01:00
|
|
|
bool replay_mutex_locked(void);
|
2015-09-17 18:23:48 +02:00
|
|
|
|
2015-09-17 18:23:43 +02:00
|
|
|
/*! Checks error status of the file. */
|
|
|
|
void replay_check_error(void);
|
|
|
|
|
|
|
|
/*! Finishes processing of the replayed event and fetches
|
|
|
|
the next event from the log. */
|
|
|
|
void replay_finish_event(void);
|
|
|
|
/*! Reads data type from the file and stores it in the
|
2016-09-26 10:08:04 +02:00
|
|
|
data_kind variable. */
|
2015-09-17 18:23:43 +02:00
|
|
|
void replay_fetch_data_kind(void);
|
|
|
|
|
2019-07-25 10:44:43 +02:00
|
|
|
/*! Advance replay_state.current_icount to the specified value. */
|
|
|
|
void replay_advance_current_icount(uint64_t current_icount);
|
2015-09-17 18:23:54 +02:00
|
|
|
/*! Saves queued events (like instructions and sound). */
|
|
|
|
void replay_save_instructions(void);
|
|
|
|
|
|
|
|
/*! Skips async events until some sync event will be found.
|
|
|
|
\return true, if event was found */
|
|
|
|
bool replay_next_event_is(int event);
|
|
|
|
|
2015-09-17 18:24:28 +02:00
|
|
|
/*! Reads next clock value from the file.
|
|
|
|
If clock kind read from the file is different from the parameter,
|
|
|
|
the value is not used. */
|
2022-11-29 02:05:47 +01:00
|
|
|
void replay_read_next_clock(ReplayClockKind kind);
|
2015-09-17 18:24:28 +02:00
|
|
|
|
2015-09-17 18:24:22 +02:00
|
|
|
/* Asynchronous events queue */
|
|
|
|
|
|
|
|
/*! Initializes events' processing internals */
|
|
|
|
void replay_init_events(void);
|
|
|
|
/*! Clears internal data structures for events handling */
|
|
|
|
void replay_finish_events(void);
|
|
|
|
/*! Returns true if there are any unsaved events in the queue */
|
|
|
|
bool replay_has_events(void);
|
|
|
|
/*! Saves events from queue into the file */
|
2022-05-27 12:46:18 +02:00
|
|
|
void replay_save_events(void);
|
2015-09-17 18:24:22 +02:00
|
|
|
/*! Read events from the file into the input queue */
|
2022-05-27 12:46:18 +02:00
|
|
|
void replay_read_events(void);
|
2016-03-14 08:44:36 +01:00
|
|
|
/*! Adds specified async event to the queue */
|
|
|
|
void replay_add_event(ReplayAsyncEventKind event_kind, void *opaque,
|
|
|
|
void *opaque2, uint64_t id);
|
2015-09-17 18:24:22 +02:00
|
|
|
|
2015-09-17 18:25:24 +02:00
|
|
|
/* Input events */
|
|
|
|
|
|
|
|
/*! Saves input event to the log */
|
|
|
|
void replay_save_input_event(InputEvent *evt);
|
|
|
|
/*! Reads input event from the log */
|
|
|
|
InputEvent *replay_read_input_event(void);
|
|
|
|
/*! Adds input event to the queue */
|
|
|
|
void replay_add_input_event(struct InputEvent *event);
|
|
|
|
/*! Adds input sync event to the queue */
|
|
|
|
void replay_add_input_sync_event(void);
|
|
|
|
|
2016-03-14 08:44:36 +01:00
|
|
|
/* Character devices */
|
|
|
|
|
|
|
|
/*! Called to run char device read event. */
|
|
|
|
void replay_event_char_read_run(void *opaque);
|
|
|
|
/*! Writes char read event to the file. */
|
|
|
|
void replay_event_char_read_save(void *opaque);
|
|
|
|
/*! Reads char event read from the file. */
|
|
|
|
void *replay_event_char_read_load(void);
|
|
|
|
|
2016-09-26 10:08:21 +02:00
|
|
|
/* Network devices */
|
|
|
|
|
|
|
|
/*! Called to run network event. */
|
|
|
|
void replay_event_net_run(void *opaque);
|
|
|
|
/*! Writes network event to the file. */
|
|
|
|
void replay_event_net_save(void *opaque);
|
|
|
|
/*! Reads network from the file. */
|
|
|
|
void *replay_event_net_load(void);
|
|
|
|
|
2023-12-11 10:13:38 +01:00
|
|
|
/* Diagnostics */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* replay_sync_error(): report sync error and exit
|
|
|
|
*
|
|
|
|
* When we reach an error condition we want to report it centrally so
|
|
|
|
* we can also dump some useful information into the logs.
|
|
|
|
*/
|
|
|
|
G_NORETURN void replay_sync_error(const char *error);
|
|
|
|
|
2016-09-26 10:08:10 +02:00
|
|
|
/* VMState-related functions */
|
|
|
|
|
|
|
|
/* Registers replay VMState.
|
|
|
|
Should be called before virtual devices initialization
|
|
|
|
to make cached timers available for post_load functions. */
|
|
|
|
void replay_vmstate_register(void);
|
|
|
|
|
2015-09-17 18:23:43 +02:00
|
|
|
#endif
|