Commit 779c6befc03122c819d2f81a2052fac6a4a43536
1 parent
95533d5f
Make sure to zero out memory before calling madvise to increase robustness
Avi pointed out that it's not entirely safe to rely on madvise zeroing out memory. So let's do it explicitly before calling madvise. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Showing
1 changed file
with
3 additions
and
3 deletions
vl.c
... | ... | @@ -3358,13 +3358,13 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id) |
3358 | 3358 | |
3359 | 3359 | if (flags & RAM_SAVE_FLAG_COMPRESS) { |
3360 | 3360 | uint8_t ch = qemu_get_byte(f); |
3361 | -#if defined(__linux__) | |
3361 | + memset(qemu_get_ram_ptr(addr), ch, TARGET_PAGE_SIZE); | |
3362 | +#ifndef _WIN32 | |
3362 | 3363 | if (ch == 0 && |
3363 | 3364 | (!kvm_enabled() || kvm_has_sync_mmu())) { |
3364 | 3365 | madvise(qemu_get_ram_ptr(addr), TARGET_PAGE_SIZE, MADV_DONTNEED); |
3365 | - } else | |
3366 | + } | |
3366 | 3367 | #endif |
3367 | - memset(qemu_get_ram_ptr(addr), ch, TARGET_PAGE_SIZE); | |
3368 | 3368 | } else if (flags & RAM_SAVE_FLAG_PAGE) |
3369 | 3369 | qemu_get_buffer(f, qemu_get_ram_ptr(addr), TARGET_PAGE_SIZE); |
3370 | 3370 | } while (!(flags & RAM_SAVE_FLAG_EOS)); | ... | ... |