瀏覽代碼

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.
Andreas Kling 5 年之前
父節點
當前提交
2a2e76c802
共有 2 個文件被更改,包括 6 次插入2 次删除
  1. 3 1
      DevTools/UserspaceEmulator/MmapRegion.cpp
  2. 3 1
      DevTools/UserspaceEmulator/SharedBufferRegion.cpp

+ 3 - 1
DevTools/UserspaceEmulator/MmapRegion.cpp

@@ -26,6 +26,7 @@
 
 
 #include "MmapRegion.h"
 #include "MmapRegion.h"
 #include "Emulator.h"
 #include "Emulator.h"
+#include <string.h>
 #include <sys/mman.h>
 #include <sys/mman.h>
 
 
 namespace UserspaceEmulator {
 namespace UserspaceEmulator {
@@ -51,7 +52,8 @@ MmapRegion::MmapRegion(u32 base, u32 size, int prot)
     : Region(base, size)
     : Region(base, size)
     , m_prot(prot)
     , m_prot(prot)
 {
 {
-    m_shadow_data = (u8*)calloc(1, size);
+    m_shadow_data = (u8*)malloc(size);
+    memset(m_shadow_data, 1, size);
 }
 }
 
 
 MmapRegion::~MmapRegion()
 MmapRegion::~MmapRegion()

+ 3 - 1
DevTools/UserspaceEmulator/SharedBufferRegion.cpp

@@ -28,6 +28,7 @@
 #include "Emulator.h"
 #include "Emulator.h"
 #include <Kernel/API/Syscall.h>
 #include <Kernel/API/Syscall.h>
 #include <serenity.h>
 #include <serenity.h>
+#include <string.h>
 #include <sys/mman.h>
 #include <sys/mman.h>
 
 
 namespace UserspaceEmulator {
 namespace UserspaceEmulator {
@@ -42,7 +43,8 @@ SharedBufferRegion::SharedBufferRegion(u32 base, u32 size, int shbuf_id, u8* hos
     , m_data(host_data)
     , m_data(host_data)
     , m_shbuf_id(shbuf_id)
     , 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()
 SharedBufferRegion::~SharedBufferRegion()