From 2a2e76c802d1e0905442b555388f9035118e64c3 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Tue, 21 Jul 2020 16:28:44 +0200 Subject: [PATCH] UserspaceEmulator: Mark mmap and shbuf regions as initialized up front A lot of software relies on the fact that mmap and shbuf memory is zeroed out by the kernel, so we should consider it initialized from the shadow bit perspective as well. --- DevTools/UserspaceEmulator/MmapRegion.cpp | 4 +++- DevTools/UserspaceEmulator/SharedBufferRegion.cpp | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/DevTools/UserspaceEmulator/MmapRegion.cpp b/DevTools/UserspaceEmulator/MmapRegion.cpp index 278776ab3c..3abe4092e7 100644 --- a/DevTools/UserspaceEmulator/MmapRegion.cpp +++ b/DevTools/UserspaceEmulator/MmapRegion.cpp @@ -26,6 +26,7 @@ #include "MmapRegion.h" #include "Emulator.h" +#include #include namespace UserspaceEmulator { @@ -51,7 +52,8 @@ MmapRegion::MmapRegion(u32 base, u32 size, int prot) : Region(base, size) , m_prot(prot) { - m_shadow_data = (u8*)calloc(1, size); + m_shadow_data = (u8*)malloc(size); + memset(m_shadow_data, 1, size); } MmapRegion::~MmapRegion() diff --git a/DevTools/UserspaceEmulator/SharedBufferRegion.cpp b/DevTools/UserspaceEmulator/SharedBufferRegion.cpp index d6e2e4b1ea..02c4cfbb8f 100644 --- a/DevTools/UserspaceEmulator/SharedBufferRegion.cpp +++ b/DevTools/UserspaceEmulator/SharedBufferRegion.cpp @@ -28,6 +28,7 @@ #include "Emulator.h" #include #include +#include #include namespace UserspaceEmulator { @@ -42,7 +43,8 @@ SharedBufferRegion::SharedBufferRegion(u32 base, u32 size, int shbuf_id, u8* hos , m_data(host_data) , m_shbuf_id(shbuf_id) { - m_shadow_data = (u8*)calloc(1, size); + m_shadow_data = (u8*)malloc(size); + memset(m_shadow_data, 1, size); } SharedBufferRegion::~SharedBufferRegion()