]>
git.proxmox.com Git - mirror_qemu.git/blob - replay/replay-internal.c
4 * Copyright (c) 2010-2015 Institute for System Programming
5 * of the Russian Academy of Sciences.
7 * This work is licensed under the terms of the GNU GPL, version 2 or later.
8 * See the COPYING file in the top-level directory.
12 #include "qemu-common.h"
13 #include "replay-internal.h"
14 #include "qemu/error-report.h"
15 #include "sysemu/sysemu.h"
17 unsigned int replay_data_kind
= -1;
18 static unsigned int replay_has_unread_data
;
20 /* File for replay writing */
23 void replay_put_byte(uint8_t byte
)
26 putc(byte
, replay_file
);
30 void replay_put_event(uint8_t event
)
32 replay_put_byte(event
);
36 void replay_put_word(uint16_t word
)
38 replay_put_byte(word
>> 8);
39 replay_put_byte(word
);
42 void replay_put_dword(uint32_t dword
)
44 replay_put_word(dword
>> 16);
45 replay_put_word(dword
);
48 void replay_put_qword(int64_t qword
)
50 replay_put_dword(qword
>> 32);
51 replay_put_dword(qword
);
54 void replay_put_array(const uint8_t *buf
, size_t size
)
57 replay_put_dword(size
);
58 fwrite(buf
, 1, size
, replay_file
);
62 uint8_t replay_get_byte(void)
66 byte
= getc(replay_file
);
71 uint16_t replay_get_word(void)
75 word
= replay_get_byte();
76 word
= (word
<< 8) + replay_get_byte();
82 uint32_t replay_get_dword(void)
86 dword
= replay_get_word();
87 dword
= (dword
<< 16) + replay_get_word();
93 int64_t replay_get_qword(void)
97 qword
= replay_get_dword();
98 qword
= (qword
<< 32) + replay_get_dword();
104 void replay_get_array(uint8_t *buf
, size_t *size
)
107 *size
= replay_get_dword();
108 if (fread(buf
, 1, *size
, replay_file
) != *size
) {
109 error_report("replay read error");
114 void replay_get_array_alloc(uint8_t **buf
, size_t *size
)
117 *size
= replay_get_dword();
118 *buf
= g_malloc(*size
);
119 if (fread(*buf
, 1, *size
, replay_file
) != *size
) {
120 error_report("replay read error");
125 void replay_check_error(void)
128 if (feof(replay_file
)) {
129 error_report("replay file is over");
130 qemu_system_vmstop_request_prepare();
131 qemu_system_vmstop_request(RUN_STATE_PAUSED
);
132 } else if (ferror(replay_file
)) {
133 error_report("replay file is over or something goes wrong");
134 qemu_system_vmstop_request_prepare();
135 qemu_system_vmstop_request(RUN_STATE_INTERNAL_ERROR
);
140 void replay_fetch_data_kind(void)
143 if (!replay_has_unread_data
) {
144 replay_data_kind
= replay_get_byte();
145 replay_check_error();
146 replay_has_unread_data
= 1;
151 void replay_finish_event(void)
153 replay_has_unread_data
= 0;
154 replay_fetch_data_kind();