diff options
author | David 'Digit' Turner <digit@google.com> | 2011-10-11 03:02:41 +0200 |
---|---|---|
committer | Vladimir Chtchetkine <vchtchetkine@google.com> | 2011-11-08 11:41:10 -0800 |
commit | 3e92c2d49cb0e8752ce8c9a3c879c84ac3299061 (patch) | |
tree | 2b098d2ce7857f14550b688c0678a53732430cbd /savevm.c | |
parent | c53b475e5bf2301da452cd2c81fed7c1fea2ec2a (diff) | |
download | external_qemu-3e92c2d49cb0e8752ce8c9a3c879c84ac3299061.zip external_qemu-3e92c2d49cb0e8752ce8c9a3c879c84ac3299061.tar.gz external_qemu-3e92c2d49cb0e8752ce8c9a3c879c84ac3299061.tar.bz2 |
Fix snapshot crash
- Add snapshot load/save support to QEMU Pipes
This adds the ability to save and load QEMU Pipe connections
with snapshots. Note that by default, all loaded pipe client
connections are force-fully closed on load.
We don't have a good way to save the state of network
connections to persistent storage.
Properly implements snapshot save / load for qemu pipe clients.
Change-Id: Ie5767f8ce40c8341b958cc5844e724dd4fc1ed2b
Diffstat (limited to 'savevm.c')
-rw-r--r-- | savevm.c | 40 |
1 files changed, 38 insertions, 2 deletions
@@ -567,6 +567,37 @@ int qemu_get_byte(QEMUFile *f) return f->buf[f->buf_index++]; } +#ifdef CONFIG_ANDROID +void qemu_put_string(QEMUFile *f, const char* str) +{ + /* We will encode NULL and the empty string in the same way */ + int slen; + if (str == NULL) { + str = ""; + } + slen = strlen(str); + qemu_put_be32(f, slen); + qemu_put_buffer(f, (const uint8_t*)str, slen); +} + +char* qemu_get_string(QEMUFile *f) +{ + int slen = qemu_get_be32(f); + char* str; + if (slen == 0) + return NULL; + + str = qemu_malloc(slen+1); + if (qemu_get_buffer(f, (uint8_t*)str, slen) != slen) { + qemu_free(str); + return NULL; + } + str[slen] = '\0'; + return str; +} +#endif + + int64_t qemu_ftell(QEMUFile *f) { return f->buf_offset - f->buf_size + f->buf_index; @@ -858,7 +889,7 @@ void unregister_savevm(const char *idstr, void *opaque) #define QEMU_VM_FILE_MAGIC 0x5145564d #define QEMU_VM_FILE_VERSION_COMPAT 0x00000002 -#define QEMU_VM_FILE_VERSION 0x00000003 +#define QEMU_VM_FILE_VERSION 0x00000004 #define QEMU_VM_EOF 0x00 #define QEMU_VM_SECTION_START 0x01 @@ -1075,8 +1106,13 @@ int qemu_loadvm_state(QEMUFile *f) v = qemu_get_be32(f); if (v == QEMU_VM_FILE_VERSION_COMPAT) return qemu_loadvm_state_v2(f); - if (v != QEMU_VM_FILE_VERSION) + if (v < QEMU_VM_FILE_VERSION) { + fprintf(stderr, "Snapshot format %d is too old for this version of the emulator, please create a new one.\n", v); + return -ENOTSUP; + } else if (v > QEMU_VM_FILE_VERSION) { + fprintf(stderr, "Snapshot format %d is more recent than the emulator, please update your Android SDK Tools.\n", v); return -ENOTSUP; + } while ((section_type = qemu_get_byte(f)) != QEMU_VM_EOF) { uint32_t instance_id, version_id, section_id; |