]> Git Repo - qemu.git/blame - replay/replay-internal.h
replay: vmstate for replay module
[qemu.git] / replay / replay-internal.h
CommitLineData
c92079f4
PD
1#ifndef REPLAY_INTERNAL_H
2#define REPLAY_INTERNAL_H
3
4/*
5 * replay-internal.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
c92079f4 15
26bc60ac
PD
16enum ReplayEvents {
17 /* for instruction event */
18 EVENT_INSTRUCTION,
6f060969
PD
19 /* for software interrupt */
20 EVENT_INTERRUPT,
21 /* for emulated exceptions */
22 EVENT_EXCEPTION,
c0c071d0
PD
23 /* for async events */
24 EVENT_ASYNC,
b60c48a7
PD
25 /* for shutdown request */
26 EVENT_SHUTDOWN,
33577b47
PD
27 /* for character device write event */
28 EVENT_CHAR_WRITE,
29 /* for character device read all event */
30 EVENT_CHAR_READ_ALL,
31 EVENT_CHAR_READ_ALL_ERROR,
8eda206e
PD
32 /* for clock read/writes */
33 /* some of greater codes are reserved for clocks */
34 EVENT_CLOCK,
35 EVENT_CLOCK_LAST = EVENT_CLOCK + REPLAY_CLOCK_COUNT - 1,
8bd7f71d
PD
36 /* for checkpoint event */
37 /* some of greater codes are reserved for checkpoints */
38 EVENT_CHECKPOINT,
39 EVENT_CHECKPOINT_LAST = EVENT_CHECKPOINT + CHECKPOINT_COUNT - 1,
7615936e
PD
40 /* end of log event */
41 EVENT_END,
26bc60ac
PD
42 EVENT_COUNT
43};
44
c0c071d0
PD
45/* Asynchronous events IDs */
46
47enum ReplayAsyncEventKind {
8a354bd9 48 REPLAY_ASYNC_EVENT_BH,
ee312992
PD
49 REPLAY_ASYNC_EVENT_INPUT,
50 REPLAY_ASYNC_EVENT_INPUT_SYNC,
33577b47 51 REPLAY_ASYNC_EVENT_CHAR_READ,
63785678 52 REPLAY_ASYNC_EVENT_BLOCK,
c0c071d0
PD
53 REPLAY_ASYNC_COUNT
54};
55
56typedef enum ReplayAsyncEventKind ReplayAsyncEventKind;
57
26bc60ac 58typedef struct ReplayState {
8eda206e
PD
59 /*! Cached clock values. */
60 int64_t cached_clock[REPLAY_CLOCK_COUNT];
26bc60ac
PD
61 /*! Current step - number of processed instructions and timer events. */
62 uint64_t current_step;
63 /*! Number of instructions to be executed before other events happen. */
64 int instructions_count;
f186d64d
PD
65 /*! Type of the currently executed event. */
66 unsigned int data_kind;
67 /*! Flag which indicates that event is not processed yet. */
68 unsigned int has_unread_data;
306e196f
PD
69 /*! Temporary variable for saving current log offset. */
70 uint64_t file_offset;
26bc60ac
PD
71} ReplayState;
72extern ReplayState replay_state;
73
c92079f4
PD
74/* File for replay writing */
75extern FILE *replay_file;
76
77void replay_put_byte(uint8_t byte);
78void replay_put_event(uint8_t event);
79void replay_put_word(uint16_t word);
80void replay_put_dword(uint32_t dword);
81void replay_put_qword(int64_t qword);
82void replay_put_array(const uint8_t *buf, size_t size);
83
84uint8_t replay_get_byte(void);
85uint16_t replay_get_word(void);
86uint32_t replay_get_dword(void);
87int64_t replay_get_qword(void);
88void replay_get_array(uint8_t *buf, size_t *size);
89void replay_get_array_alloc(uint8_t **buf, size_t *size);
90
c16861ef
PD
91/* Mutex functions for protecting replay log file */
92
93void replay_mutex_init(void);
94void replay_mutex_destroy(void);
95void replay_mutex_lock(void);
96void replay_mutex_unlock(void);
97
c92079f4
PD
98/*! Checks error status of the file. */
99void replay_check_error(void);
100
101/*! Finishes processing of the replayed event and fetches
102 the next event from the log. */
103void replay_finish_event(void);
104/*! Reads data type from the file and stores it in the
f186d64d 105 data_kind variable. */
c92079f4
PD
106void replay_fetch_data_kind(void);
107
26bc60ac
PD
108/*! Saves queued events (like instructions and sound). */
109void replay_save_instructions(void);
110
111/*! Skips async events until some sync event will be found.
112 \return true, if event was found */
113bool replay_next_event_is(int event);
114
8eda206e
PD
115/*! Reads next clock value from the file.
116 If clock kind read from the file is different from the parameter,
117 the value is not used. */
118void replay_read_next_clock(unsigned int kind);
119
c0c071d0
PD
120/* Asynchronous events queue */
121
122/*! Initializes events' processing internals */
123void replay_init_events(void);
124/*! Clears internal data structures for events handling */
125void replay_finish_events(void);
126/*! Enables storing events in the queue */
127void replay_enable_events(void);
128/*! Flushes events queue */
129void replay_flush_events(void);
130/*! Clears events list before loading new VM state */
131void replay_clear_events(void);
132/*! Returns true if there are any unsaved events in the queue */
133bool replay_has_events(void);
134/*! Saves events from queue into the file */
135void replay_save_events(int checkpoint);
136/*! Read events from the file into the input queue */
137void replay_read_events(int checkpoint);
33577b47
PD
138/*! Adds specified async event to the queue */
139void replay_add_event(ReplayAsyncEventKind event_kind, void *opaque,
140 void *opaque2, uint64_t id);
c0c071d0 141
ee312992
PD
142/* Input events */
143
144/*! Saves input event to the log */
145void replay_save_input_event(InputEvent *evt);
146/*! Reads input event from the log */
147InputEvent *replay_read_input_event(void);
148/*! Adds input event to the queue */
149void replay_add_input_event(struct InputEvent *event);
150/*! Adds input sync event to the queue */
151void replay_add_input_sync_event(void);
152
33577b47
PD
153/* Character devices */
154
155/*! Called to run char device read event. */
156void replay_event_char_read_run(void *opaque);
157/*! Writes char read event to the file. */
158void replay_event_char_read_save(void *opaque);
159/*! Reads char event read from the file. */
160void *replay_event_char_read_load(void);
161
306e196f
PD
162/* VMState-related functions */
163
164/* Registers replay VMState.
165 Should be called before virtual devices initialization
166 to make cached timers available for post_load functions. */
167void replay_vmstate_register(void);
168
c92079f4 169#endif
This page took 0.094618 seconds and 4 git commands to generate.