aboutsummaryrefslogtreecommitdiff
path: root/replay/replay-internal.c
diff options
context:
space:
mode:
Diffstat (limited to 'replay/replay-internal.c')
-rw-r--r--replay/replay-internal.c43
1 files changed, 35 insertions, 8 deletions
diff --git a/replay/replay-internal.c b/replay/replay-internal.c
index fca8514012..b077cb5fd5 100644
--- a/replay/replay-internal.c
+++ b/replay/replay-internal.c
@@ -24,12 +24,23 @@
static QemuMutex lock;
/* File for replay writing */
+static bool write_error;
FILE *replay_file;
+static void replay_write_error(void)
+{
+ if (!write_error) {
+ error_report("replay write error");
+ write_error = true;
+ }
+}
+
void replay_put_byte(uint8_t byte)
{
if (replay_file) {
- putc(byte, replay_file);
+ if (putc(byte, replay_file) == EOF) {
+ replay_write_error();
+ }
}
}
@@ -62,7 +73,9 @@ void replay_put_array(const uint8_t *buf, size_t size)
{
if (replay_file) {
replay_put_dword(size);
- fwrite(buf, 1, size, replay_file);
+ if (fwrite(buf, 1, size, replay_file) != size) {
+ replay_write_error();
+ }
}
}
@@ -169,31 +182,46 @@ void replay_finish_event(void)
replay_fetch_data_kind();
}
+static __thread bool replay_locked;
+
void replay_mutex_init(void)
{
qemu_mutex_init(&lock);
+ /* Hold the mutex while we start-up */
+ qemu_mutex_lock(&lock);
+ replay_locked = true;
}
-void replay_mutex_destroy(void)
+bool replay_mutex_locked(void)
{
- qemu_mutex_destroy(&lock);
+ return replay_locked;
}
+/* Ordering constraints, replay_lock must be taken before BQL */
void replay_mutex_lock(void)
{
- qemu_mutex_lock(&lock);
+ if (replay_mode != REPLAY_MODE_NONE) {
+ g_assert(!qemu_mutex_iothread_locked());
+ g_assert(!replay_mutex_locked());
+ qemu_mutex_lock(&lock);
+ replay_locked = true;
+ }
}
void replay_mutex_unlock(void)
{
- qemu_mutex_unlock(&lock);
+ if (replay_mode != REPLAY_MODE_NONE) {
+ g_assert(replay_mutex_locked());
+ replay_locked = false;
+ qemu_mutex_unlock(&lock);
+ }
}
/*! Saves cached instructions. */
void replay_save_instructions(void)
{
if (replay_file && replay_mode == REPLAY_MODE_RECORD) {
- replay_mutex_lock();
+ g_assert(replay_mutex_locked());
int diff = (int)(replay_get_current_step() - replay_state.current_step);
/* Time can only go forward */
@@ -204,6 +232,5 @@ void replay_save_instructions(void)
replay_put_dword(diff);
replay_state.current_step += diff;
}
- replay_mutex_unlock();
}
}