]>
Commit | Line | Data |
---|---|---|
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 | ||
15 | ||
16 | enum ReplayEvents { | |
17 | /* for instruction event */ | |
18 | EVENT_INSTRUCTION, | |
19 | /* for software interrupt */ | |
20 | EVENT_INTERRUPT, | |
21 | /* for emulated exceptions */ | |
22 | EVENT_EXCEPTION, | |
23 | /* for async events */ | |
24 | EVENT_ASYNC, | |
25 | /* for shutdown request */ | |
26 | EVENT_SHUTDOWN, | |
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, | |
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, | |
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, | |
40 | /* end of log event */ | |
41 | EVENT_END, | |
42 | EVENT_COUNT | |
43 | }; | |
44 | ||
45 | /* Asynchronous events IDs */ | |
46 | ||
47 | enum ReplayAsyncEventKind { | |
48 | REPLAY_ASYNC_EVENT_BH, | |
49 | REPLAY_ASYNC_EVENT_INPUT, | |
50 | REPLAY_ASYNC_EVENT_INPUT_SYNC, | |
51 | REPLAY_ASYNC_EVENT_CHAR_READ, | |
52 | REPLAY_ASYNC_EVENT_BLOCK, | |
53 | REPLAY_ASYNC_EVENT_NET, | |
54 | REPLAY_ASYNC_COUNT | |
55 | }; | |
56 | ||
57 | typedef enum ReplayAsyncEventKind ReplayAsyncEventKind; | |
58 | ||
59 | typedef struct ReplayState { | |
60 | /*! Cached clock values. */ | |
61 | int64_t cached_clock[REPLAY_CLOCK_COUNT]; | |
62 | /*! Current step - number of processed instructions and timer events. */ | |
63 | uint64_t current_step; | |
64 | /*! Number of instructions to be executed before other events happen. */ | |
65 | int instructions_count; | |
66 | /*! Type of the currently executed event. */ | |
67 | unsigned int data_kind; | |
68 | /*! Flag which indicates that event is not processed yet. */ | |
69 | unsigned int has_unread_data; | |
70 | /*! Temporary variable for saving current log offset. */ | |
71 | uint64_t file_offset; | |
72 | /*! Next block operation id. | |
73 | This counter is global, because requests from different | |
74 | block devices should not get overlapping ids. */ | |
75 | uint64_t block_request_id; | |
76 | } ReplayState; | |
77 | extern ReplayState replay_state; | |
78 | ||
79 | /* File for replay writing */ | |
80 | extern FILE *replay_file; | |
81 | ||
82 | void replay_put_byte(uint8_t byte); | |
83 | void replay_put_event(uint8_t event); | |
84 | void replay_put_word(uint16_t word); | |
85 | void replay_put_dword(uint32_t dword); | |
86 | void replay_put_qword(int64_t qword); | |
87 | void replay_put_array(const uint8_t *buf, size_t size); | |
88 | ||
89 | uint8_t replay_get_byte(void); | |
90 | uint16_t replay_get_word(void); | |
91 | uint32_t replay_get_dword(void); | |
92 | int64_t replay_get_qword(void); | |
93 | void replay_get_array(uint8_t *buf, size_t *size); | |
94 | void replay_get_array_alloc(uint8_t **buf, size_t *size); | |
95 | ||
96 | /* Mutex functions for protecting replay log file */ | |
97 | ||
98 | void replay_mutex_init(void); | |
99 | void replay_mutex_destroy(void); | |
100 | void replay_mutex_lock(void); | |
101 | void replay_mutex_unlock(void); | |
102 | ||
103 | /*! Checks error status of the file. */ | |
104 | void replay_check_error(void); | |
105 | ||
106 | /*! Finishes processing of the replayed event and fetches | |
107 | the next event from the log. */ | |
108 | void replay_finish_event(void); | |
109 | /*! Reads data type from the file and stores it in the | |
110 | data_kind variable. */ | |
111 | void replay_fetch_data_kind(void); | |
112 | ||
113 | /*! Saves queued events (like instructions and sound). */ | |
114 | void replay_save_instructions(void); | |
115 | ||
116 | /*! Skips async events until some sync event will be found. | |
117 | \return true, if event was found */ | |
118 | bool replay_next_event_is(int event); | |
119 | ||
120 | /*! Reads next clock value from the file. | |
121 | If clock kind read from the file is different from the parameter, | |
122 | the value is not used. */ | |
123 | void replay_read_next_clock(unsigned int kind); | |
124 | ||
125 | /* Asynchronous events queue */ | |
126 | ||
127 | /*! Initializes events' processing internals */ | |
128 | void replay_init_events(void); | |
129 | /*! Clears internal data structures for events handling */ | |
130 | void replay_finish_events(void); | |
131 | /*! Flushes events queue */ | |
132 | void replay_flush_events(void); | |
133 | /*! Clears events list before loading new VM state */ | |
134 | void replay_clear_events(void); | |
135 | /*! Returns true if there are any unsaved events in the queue */ | |
136 | bool replay_has_events(void); | |
137 | /*! Saves events from queue into the file */ | |
138 | void replay_save_events(int checkpoint); | |
139 | /*! Read events from the file into the input queue */ | |
140 | void replay_read_events(int checkpoint); | |
141 | /*! Adds specified async event to the queue */ | |
142 | void replay_add_event(ReplayAsyncEventKind event_kind, void *opaque, | |
143 | void *opaque2, uint64_t id); | |
144 | ||
145 | /* Input events */ | |
146 | ||
147 | /*! Saves input event to the log */ | |
148 | void replay_save_input_event(InputEvent *evt); | |
149 | /*! Reads input event from the log */ | |
150 | InputEvent *replay_read_input_event(void); | |
151 | /*! Adds input event to the queue */ | |
152 | void replay_add_input_event(struct InputEvent *event); | |
153 | /*! Adds input sync event to the queue */ | |
154 | void replay_add_input_sync_event(void); | |
155 | ||
156 | /* Character devices */ | |
157 | ||
158 | /*! Called to run char device read event. */ | |
159 | void replay_event_char_read_run(void *opaque); | |
160 | /*! Writes char read event to the file. */ | |
161 | void replay_event_char_read_save(void *opaque); | |
162 | /*! Reads char event read from the file. */ | |
163 | void *replay_event_char_read_load(void); | |
164 | ||
165 | /* Network devices */ | |
166 | ||
167 | /*! Called to run network event. */ | |
168 | void replay_event_net_run(void *opaque); | |
169 | /*! Writes network event to the file. */ | |
170 | void replay_event_net_save(void *opaque); | |
171 | /*! Reads network from the file. */ | |
172 | void *replay_event_net_load(void); | |
173 | ||
174 | /* VMState-related functions */ | |
175 | ||
176 | /* Registers replay VMState. | |
177 | Should be called before virtual devices initialization | |
178 | to make cached timers available for post_load functions. */ | |
179 | void replay_vmstate_register(void); | |
180 | ||
181 | #endif |