xref: /qemu/replay/replay-internal.h (revision 4f7ab0cd)
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 clock read/writes */
28     /* some of greater codes are reserved for clocks */
29     EVENT_CLOCK,
30     EVENT_CLOCK_LAST = EVENT_CLOCK + REPLAY_CLOCK_COUNT - 1,
31     /* for checkpoint event */
32     /* some of greater codes are reserved for checkpoints */
33     EVENT_CHECKPOINT,
34     EVENT_CHECKPOINT_LAST = EVENT_CHECKPOINT + CHECKPOINT_COUNT - 1,
35     /* end of log event */
36     EVENT_END,
37     EVENT_COUNT
38 };
39 
40 /* Asynchronous events IDs */
41 
42 enum ReplayAsyncEventKind {
43     REPLAY_ASYNC_EVENT_BH,
44     REPLAY_ASYNC_EVENT_INPUT,
45     REPLAY_ASYNC_EVENT_INPUT_SYNC,
46     REPLAY_ASYNC_COUNT
47 };
48 
49 typedef enum ReplayAsyncEventKind ReplayAsyncEventKind;
50 
51 typedef struct ReplayState {
52     /*! Cached clock values. */
53     int64_t cached_clock[REPLAY_CLOCK_COUNT];
54     /*! Current step - number of processed instructions and timer events. */
55     uint64_t current_step;
56     /*! Number of instructions to be executed before other events happen. */
57     int instructions_count;
58 } ReplayState;
59 extern ReplayState replay_state;
60 
61 extern unsigned int replay_data_kind;
62 
63 /* File for replay writing */
64 extern FILE *replay_file;
65 
66 void replay_put_byte(uint8_t byte);
67 void replay_put_event(uint8_t event);
68 void replay_put_word(uint16_t word);
69 void replay_put_dword(uint32_t dword);
70 void replay_put_qword(int64_t qword);
71 void replay_put_array(const uint8_t *buf, size_t size);
72 
73 uint8_t replay_get_byte(void);
74 uint16_t replay_get_word(void);
75 uint32_t replay_get_dword(void);
76 int64_t replay_get_qword(void);
77 void replay_get_array(uint8_t *buf, size_t *size);
78 void replay_get_array_alloc(uint8_t **buf, size_t *size);
79 
80 /* Mutex functions for protecting replay log file */
81 
82 void replay_mutex_init(void);
83 void replay_mutex_destroy(void);
84 void replay_mutex_lock(void);
85 void replay_mutex_unlock(void);
86 
87 /*! Checks error status of the file. */
88 void replay_check_error(void);
89 
90 /*! Finishes processing of the replayed event and fetches
91     the next event from the log. */
92 void replay_finish_event(void);
93 /*! Reads data type from the file and stores it in the
94     replay_data_kind variable. */
95 void replay_fetch_data_kind(void);
96 
97 /*! Saves queued events (like instructions and sound). */
98 void replay_save_instructions(void);
99 
100 /*! Skips async events until some sync event will be found.
101     \return true, if event was found */
102 bool replay_next_event_is(int event);
103 
104 /*! Reads next clock value from the file.
105     If clock kind read from the file is different from the parameter,
106     the value is not used. */
107 void replay_read_next_clock(unsigned int kind);
108 
109 /* Asynchronous events queue */
110 
111 /*! Initializes events' processing internals */
112 void replay_init_events(void);
113 /*! Clears internal data structures for events handling */
114 void replay_finish_events(void);
115 /*! Enables storing events in the queue */
116 void replay_enable_events(void);
117 /*! Flushes events queue */
118 void replay_flush_events(void);
119 /*! Clears events list before loading new VM state */
120 void replay_clear_events(void);
121 /*! Returns true if there are any unsaved events in the queue */
122 bool replay_has_events(void);
123 /*! Saves events from queue into the file */
124 void replay_save_events(int checkpoint);
125 /*! Read events from the file into the input queue */
126 void replay_read_events(int checkpoint);
127 
128 /* Input events */
129 
130 /*! Saves input event to the log */
131 void replay_save_input_event(InputEvent *evt);
132 /*! Reads input event from the log */
133 InputEvent *replay_read_input_event(void);
134 /*! Adds input event to the queue */
135 void replay_add_input_event(struct InputEvent *event);
136 /*! Adds input sync event to the queue */
137 void replay_add_input_sync_event(void);
138 
139 #endif
140