summaryrefslogtreecommitdiff
path: root/replay
diff options
context:
space:
mode:
Diffstat (limited to 'replay')
-rw-r--r--replay/Makefile.objs3
-rw-r--r--replay/replay-internal.h2
-rw-r--r--replay/replay-random.c44
-rw-r--r--replay/replay.c2
4 files changed, 49 insertions, 2 deletions
diff --git a/replay/Makefile.objs b/replay/Makefile.objs
index cee6539a23..939be964a9 100644
--- a/replay/Makefile.objs
+++ b/replay/Makefile.objs
@@ -6,4 +6,5 @@ common-obj-y += replay-input.o
common-obj-y += replay-char.o
common-obj-y += replay-snapshot.o
common-obj-y += replay-net.o
-common-obj-y += replay-audio.o \ No newline at end of file
+common-obj-y += replay-audio.o
+common-obj-y += replay-random.o
diff --git a/replay/replay-internal.h b/replay/replay-internal.h
index 55fca1ac6b..33ac551e78 100644
--- a/replay/replay-internal.h
+++ b/replay/replay-internal.h
@@ -34,6 +34,8 @@ enum ReplayEvents {
EVENT_AUDIO_OUT,
/* for audio in event */
EVENT_AUDIO_IN,
+ /* for random number generator */
+ EVENT_RANDOM,
/* for clock read/writes */
/* some of greater codes are reserved for clocks */
EVENT_CLOCK,
diff --git a/replay/replay-random.c b/replay/replay-random.c
new file mode 100644
index 0000000000..afc7a0fccc
--- /dev/null
+++ b/replay/replay-random.c
@@ -0,0 +1,44 @@
+/*
+ * replay-random.c
+ *
+ * Copyright (c) 2010-2020 Institute for System Programming
+ * of the Russian Academy of Sciences.
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ *
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/error-report.h"
+#include "sysemu/replay.h"
+#include "replay-internal.h"
+
+void replay_save_random(int ret, void *buf, size_t len)
+{
+ g_assert(replay_mutex_locked());
+
+ replay_save_instructions();
+ replay_put_event(EVENT_RANDOM);
+ replay_put_dword(ret);
+ replay_put_array(buf, len);
+}
+
+int replay_read_random(void *buf, size_t len)
+{
+ int ret = 0;
+ g_assert(replay_mutex_locked());
+
+ replay_account_executed_instructions();
+ if (replay_next_event_is(EVENT_RANDOM)) {
+ size_t buf_size = 0;
+ ret = replay_get_dword();
+ replay_get_array(buf, &buf_size);
+ replay_finish_event();
+ g_assert(buf_size == len);
+ } else {
+ error_report("Missing random event in the replay log");
+ exit(1);
+ }
+ return ret;
+}
diff --git a/replay/replay.c b/replay/replay.c
index 5cc25bd2f8..706c7b4f4b 100644
--- a/replay/replay.c
+++ b/replay/replay.c
@@ -22,7 +22,7 @@
/* Current version of the replay mechanism.
Increase it when file format changes. */
-#define REPLAY_VERSION 0xe02008
+#define REPLAY_VERSION 0xe02009
/* Size of replay log header */
#define HEADER_SIZE (sizeof(uint32_t) + sizeof(uint64_t))