[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [RFC PATCH v2 22/49] replay: internal functions for replay
From: |
Pavel Dovgalyuk |
Subject: |
[Qemu-devel] [RFC PATCH v2 22/49] replay: internal functions for replay log |
Date: |
Thu, 17 Jul 2014 15:04:02 +0400 |
User-agent: |
StGit/0.16 |
This patch adds functions to perform read and write operations
with replay log.
Signed-off-by: Pavel Dovgalyuk <address@hidden>
---
replay/Makefile.objs | 1
replay/replay-internal.c | 141 ++++++++++++++++++++++++++++++++++++++++++++++
replay/replay-internal.h | 50 ++++++++++++++++
replay/replay.c | 6 ++
4 files changed, 198 insertions(+), 0 deletions(-)
create mode 100755 replay/replay-internal.c
create mode 100755 replay/replay-internal.h
diff --git a/replay/Makefile.objs b/replay/Makefile.objs
index 7ea860f..1148f45 100755
--- a/replay/Makefile.objs
+++ b/replay/Makefile.objs
@@ -1 +1,2 @@
obj-y += replay.o
+obj-y += replay-internal.o
diff --git a/replay/replay-internal.c b/replay/replay-internal.c
new file mode 100755
index 0000000..706b46b
--- /dev/null
+++ b/replay/replay-internal.c
@@ -0,0 +1,141 @@
+/*
+ * replay-internal.c
+ *
+ * Copyright (c) 2010-2014 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-common.h"
+#include "replay-internal.h"
+
+volatile unsigned int replay_data_kind = -1;
+volatile unsigned int replay_has_unread_data;
+
+/* File for replay writing */
+FILE *replay_file;
+
+void replay_put_byte(unsigned char byte)
+{
+ if (replay_file) {
+ fwrite(&byte, sizeof(byte), 1, replay_file);
+ }
+}
+
+void replay_put_event(unsigned char event)
+{
+ replay_put_byte(event);
+}
+
+
+void replay_put_word(uint16_t word)
+{
+ if (replay_file) {
+ fwrite(&word, sizeof(word), 1, replay_file);
+ }
+}
+
+void replay_put_dword(unsigned int dword)
+{
+ if (replay_file) {
+ fwrite(&dword, sizeof(dword), 1, replay_file);
+ }
+}
+
+void replay_put_qword(int64_t qword)
+{
+ if (replay_file) {
+ fwrite(&qword, sizeof(qword), 1, replay_file);
+ }
+}
+
+void replay_put_array(const uint8_t *buf, size_t size)
+{
+ if (replay_file) {
+ fwrite(&size, sizeof(size), 1, replay_file);
+ fwrite(buf, 1, size, replay_file);
+ }
+}
+
+unsigned char replay_get_byte(void)
+{
+ unsigned char byte;
+ if (replay_file) {
+ fread(&byte, sizeof(byte), 1, replay_file);
+ }
+ return byte;
+}
+
+uint16_t replay_get_word(void)
+{
+ uint16_t word;
+ if (replay_file) {
+ fread(&word, sizeof(word), 1, replay_file);
+ }
+
+ return word;
+}
+
+unsigned int replay_get_dword(void)
+{
+ unsigned int dword;
+ if (replay_file) {
+ fread(&dword, sizeof(dword), 1, replay_file);
+ }
+
+ return dword;
+}
+
+int64_t replay_get_qword(void)
+{
+ int64_t qword;
+ if (replay_file) {
+ fread(&qword, sizeof(qword), 1, replay_file);
+ }
+
+ return qword;
+}
+
+void replay_get_array(uint8_t *buf, size_t *size)
+{
+ if (replay_file) {
+ fread(size, sizeof(*size), 1, replay_file);
+ fread(buf, 1, *size, replay_file);
+ }
+}
+
+void replay_get_array_alloc(uint8_t **buf, size_t *size)
+{
+ if (replay_file) {
+ fread(size, sizeof(*size), 1, replay_file);
+ *buf = g_malloc(*size);
+ fread(*buf, 1, *size, replay_file);
+ }
+}
+
+void replay_check_error(void)
+{
+ if (replay_file) {
+ if (feof(replay_file)) {
+ fprintf(stderr, "replay file is over\n");
+ exit(1);
+ } else if (ferror(replay_file)) {
+ fprintf(stderr, "replay file is over or something goes wrong\n");
+ exit(1);
+ }
+ }
+}
+
+void replay_fetch_data_kind(void)
+{
+ if (replay_file) {
+ if (!replay_has_unread_data) {
+ replay_data_kind = replay_get_byte();
+ replay_check_error();
+ replay_has_unread_data = 1;
+ }
+ }
+}
diff --git a/replay/replay-internal.h b/replay/replay-internal.h
new file mode 100755
index 0000000..b959bca
--- /dev/null
+++ b/replay/replay-internal.h
@@ -0,0 +1,50 @@
+#ifndef REPLAY_INTERNAL_H
+#define REPLAY_INTERNAL_H
+
+/*
+ * replay-internal.h
+ *
+ * Copyright (c) 2010-2014 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 <stdio.h>
+
+extern volatile unsigned int replay_data_kind;
+extern volatile unsigned int replay_has_unread_data;
+
+/* File for replay writing */
+extern FILE *replay_file;
+
+void replay_put_byte(unsigned char byte);
+void replay_put_event(unsigned char event);
+void replay_put_word(uint16_t word);
+void replay_put_dword(unsigned int dword);
+void replay_put_qword(int64_t qword);
+void replay_put_array(const uint8_t *buf, size_t size);
+
+unsigned char replay_get_byte(void);
+uint16_t replay_get_word(void);
+unsigned int replay_get_dword(void);
+int64_t replay_get_qword(void);
+void replay_get_array(uint8_t *buf, size_t *size);
+void replay_get_array_alloc(uint8_t **buf, size_t *size);
+
+/*! Checks error status of the file. */
+void replay_check_error(void);
+
+/*! Reads data type from the file and stores it in the
+ replay_data_kind variable. */
+void replay_fetch_data_kind(void);
+
+/*! Saves queued events (like instructions and sound). */
+void replay_save_instructions(void);
+/*! Checks that the next data is corresponding to the desired kind.
+ Terminates the program in case of error. */
+void validate_data_kind(int kind);
+
+#endif
diff --git a/replay/replay.c b/replay/replay.c
index 5a69465..2961e17 100755
--- a/replay/replay.c
+++ b/replay/replay.c
@@ -17,3 +17,9 @@ int play_submode = REPLAY_PLAY_UNKNOWN;
/* Suffix for the disk images filenames */
char *replay_image_suffix;
+
+
+int replay_get_play_submode(void)
+{
+ return play_submode;
+}
- [Qemu-devel] [RFC PATCH v2 40/49] replay: recording of the user input, (continued)
- [Qemu-devel] [RFC PATCH v2 40/49] replay: recording of the user input, Pavel Dovgalyuk, 2014/07/17
- [Qemu-devel] [RFC PATCH v2 34/49] replay: replay aio requests, Pavel Dovgalyuk, 2014/07/17
- [Qemu-devel] [RFC PATCH v2 21/49] sysemu: system functions for replay, Pavel Dovgalyuk, 2014/07/17
- [Qemu-devel] [RFC PATCH v2 23/49] cpu: invent instruction count for accurate replay, Pavel Dovgalyuk, 2014/07/17
- [Qemu-devel] [RFC PATCH v2 16/49] target: save cpu state fields, Pavel Dovgalyuk, 2014/07/17
- [Qemu-devel] [RFC PATCH v2 29/49] replay: recording and replaying clock ticks, Pavel Dovgalyuk, 2014/07/17
- [Qemu-devel] [RFC PATCH v2 12/49] mc146818rtc: add missed field to vmstate, Pavel Dovgalyuk, 2014/07/17
- [Qemu-devel] [RFC PATCH v2 24/49] target-arm: instructions counting code for replay, Pavel Dovgalyuk, 2014/07/17
- [Qemu-devel] [RFC PATCH v2 33/49] replay: bottom halves, Pavel Dovgalyuk, 2014/07/17
- [Qemu-devel] [RFC PATCH v2 22/49] replay: internal functions for replay log,
Pavel Dovgalyuk <=
- [Qemu-devel] [RFC PATCH v2 31/49] replay: shutdown event, Pavel Dovgalyuk, 2014/07/17
- [Qemu-devel] [RFC PATCH v2 38/49] replay: command line options, Pavel Dovgalyuk, 2014/07/17
- [Qemu-devel] [RFC PATCH v2 20/49] block: add suffix parameter to bdrv_open functions, Pavel Dovgalyuk, 2014/07/17
- [Qemu-devel] [RFC PATCH v2 39/49] replay: snapshotting the virtual machine, Pavel Dovgalyuk, 2014/07/17
- [Qemu-devel] [RFC PATCH v2 13/49] pl031: add missed field to vmstate, Pavel Dovgalyuk, 2014/07/17
- [Qemu-devel] [RFC PATCH v2 18/49] migration: add vmstate for int8 and char arrays, Pavel Dovgalyuk, 2014/07/17
- Re: [Qemu-devel] [RFC PATCH v2 00/49] Series short description, Frederic Konrad, 2014/07/18
- Re: [Qemu-devel] [RFC PATCH v2 00/49] Series short description, Paolo Bonzini, 2014/07/24