Index: compiler-rt/test/builtins/Unit/clear_cache_test.c
===================================================================
--- compiler-rt/test/builtins/Unit/clear_cache_test.c
+++ compiler-rt/test/builtins/Unit/clear_cache_test.c
@@ -51,24 +51,29 @@
 #endif
 }
 
-unsigned char execution_buffer[128] __attribute__((aligned(8)));
-
 int main()
 {
+#if !defined(_WIN32)
+    int *execution_buffer = mmap(0, 128, PROT_READ | PROT_WRITE | PROT_EXEC,
+                                 MAP_ANON | MAP_PRIVATE, 0, 0);
+    if (execution_buffer == MAP_FAILED)
+      return 1;
+#else
+    HANDLE mapping = CreateFileMapping(INVALID_HANDLE_VALUE, NULL,
+                                       PAGE_EXECUTE_READWRITE, 0, 128, NULL);
+    if (mapping == NULL)
+        return 1;
+
+    uint8_t* execution_buffer = MapViewOfFile(
+        mapping, FILE_MAP_ALL_ACCESS | FILE_MAP_EXECUTE, 0, 0, 0);
+    if (execution_buffer == NULL)
+        return 1;
+#endif
+
     // make executable the page containing execution_buffer 
     uintptr_t page_size = get_page_size();
     char* start = (char*)((uintptr_t)execution_buffer & (-page_size));
     char* end = (char*)((uintptr_t)(&execution_buffer[128+page_size]) & (-page_size));
-#if defined(_WIN32)
-    DWORD dummy_oldProt;
-    MEMORY_BASIC_INFORMATION b;
-    if (!VirtualQuery(start, &b, sizeof(b)))
-        return 1;
-    if (!VirtualProtect(b.BaseAddress, b.RegionSize, PAGE_EXECUTE_READWRITE, &b.Protect))
-#else
-    if (mprotect(start, end-start, PROT_READ|PROT_WRITE|PROT_EXEC) != 0)
-#endif
-        return 1;
 
     // verify you can copy and execute a function
     pfunc f1 = (pfunc)memcpy_f(execution_buffer, func1, 128);