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