qmp: Fix higher half vaddrs for [p]memsave

Fixes higher-half address parsing for QMP commands
`[p]memsave`.

Signed-off-by: Josh Junon <junon@oro.sh>
Message-ID: <20240802140704.13591-1-junon@oro.sh>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
[Subject tweaked, and one PRId64 updated to PRIu64]
Signed-off-by: Markus Armbruster <armbru@redhat.com>
This commit is contained in:
Josh Junon 2024-08-02 16:07:03 +02:00 committed by Markus Armbruster
parent 01bed0ff14
commit ef71d8209f
2 changed files with 15 additions and 8 deletions

View File

@ -852,7 +852,11 @@
# <- { "return": {} } # <- { "return": {} }
## ##
{ 'command': 'memsave', { 'command': 'memsave',
'data': {'val': 'int', 'size': 'int', 'filename': 'str', '*cpu-index': 'int'} } 'data': {
'val': 'uint64',
'size': 'size',
'filename': 'str',
'*cpu-index': 'int' } }
## ##
# @pmemsave: # @pmemsave:
@ -878,7 +882,10 @@
# <- { "return": {} } # <- { "return": {} }
## ##
{ 'command': 'pmemsave', { 'command': 'pmemsave',
'data': {'val': 'int', 'size': 'int', 'filename': 'str'} } 'data': {
'val': 'uint64',
'size': 'size',
'filename': 'str' } }
## ##
# @Memdev: # @Memdev:

View File

@ -792,14 +792,14 @@ int vm_stop_force_state(RunState state)
} }
} }
void qmp_memsave(int64_t addr, int64_t size, const char *filename, void qmp_memsave(uint64_t addr, uint64_t size, const char *filename,
bool has_cpu, int64_t cpu_index, Error **errp) bool has_cpu, int64_t cpu_index, Error **errp)
{ {
FILE *f; FILE *f;
uint32_t l; uint64_t l;
CPUState *cpu; CPUState *cpu;
uint8_t buf[1024]; uint8_t buf[1024];
int64_t orig_addr = addr, orig_size = size; uint64_t orig_addr = addr, orig_size = size;
if (!has_cpu) { if (!has_cpu) {
cpu_index = 0; cpu_index = 0;
@ -823,7 +823,7 @@ void qmp_memsave(int64_t addr, int64_t size, const char *filename,
if (l > size) if (l > size)
l = size; l = size;
if (cpu_memory_rw_debug(cpu, addr, buf, l, 0) != 0) { if (cpu_memory_rw_debug(cpu, addr, buf, l, 0) != 0) {
error_setg(errp, "Invalid addr 0x%016" PRIx64 "/size %" PRId64 error_setg(errp, "Invalid addr 0x%016" PRIx64 "/size %" PRIu64
" specified", orig_addr, orig_size); " specified", orig_addr, orig_size);
goto exit; goto exit;
} }
@ -840,11 +840,11 @@ exit:
fclose(f); fclose(f);
} }
void qmp_pmemsave(int64_t addr, int64_t size, const char *filename, void qmp_pmemsave(uint64_t addr, uint64_t size, const char *filename,
Error **errp) Error **errp)
{ {
FILE *f; FILE *f;
uint32_t l; uint64_t l;
uint8_t buf[1024]; uint8_t buf[1024];
f = fopen(filename, "wb"); f = fopen(filename, "wb");