================
@@ -1,9 +1,76 @@
-#include <stdio.h>
-#include <stdint.h>
-
-int main (int argc, char const *argv[])
-{
-    const char* stringdata = "hello world; I like to write text in const char 
pointers";
-    uint8_t bytedata[] = 
{0xAA,0xBB,0xCC,0xDD,0xEE,0xFF,0x00,0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88,0x99};
-    return 0; // break here
+#include <cstdint>
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
+#include <initializer_list>
+#include <iostream>
+
+#ifdef _WIN32
+#include "Windows.h"
+
+int getpagesize() {
+  SYSTEM_INFO system_info;
+  GetSystemInfo(&system_info);
+  return system_info.dwPageSize;
+}
+
+char *allocate_memory_with_holes() {
+  int pagesize = getpagesize();
+  void *mem = VirtualAlloc(nullptr, 5 * pagesize, MEM_RESERVE, PAGE_NOACCESS);
+  if (!mem) {
+    std::cerr << std::system_category().message(GetLastError()) << std::endl;
+    exit(1);
+  }
+  char *bytes = static_cast<char *>(mem);
+  for (int page : {0, 2, 4}) {
+    if (!VirtualAlloc(bytes + page * pagesize, pagesize, MEM_COMMIT,
----------------
labath wrote:

Added a comment at the top. Definitely not a Windows expert here, but my 
understanding is that the main difference is due to the MEM_RESERVE/MEM_COMMIT. 
MEM_RESERVE does not actually allocate any memory. It just marks the range as 
in use ("reserved") so that it is won't be taken by other allocation calls. 
MEM_COMMIT is what actually allocates the page.

https://github.com/llvm/llvm-project/pull/104193
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to