qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] Re: [PATCH] fix interaction with noexecstack


From: Filip Navara
Subject: Re: [Qemu-devel] Re: [PATCH] fix interaction with noexecstack
Date: Sat, 04 Sep 2004 18:15:47 +0200
User-agent: Mozilla Thunderbird 0.7.3 (Windows/20040803)

Ronald wrote:

Tested, need to include <winbase.h> (and <windows.h>).
gcc juste produce a warning with VirtualProtect:
/home/ronald/Prog/Win32/combo/qemu/exec.c: Dans la fonction « page_init »:
/home/ronald/Prog/Win32/combo/qemu/exec.c:155: AVERTISSEMENT: passage de
arg 1 de « VirtualProtect » transforme en pointeur un entier sans
transtypage

aproximative translation: in function page_init passing arg1 of
VirtualProtect is making pointer from integer without a cast.
Thanks much for testing it, now I got a minute to test it on my box. The attach patch adds the #include, fixes the warning and also dynamicly detects the page size. These changes are actually needed when running QEMU on WinXP SP2 on AMD64. I'm quite not happy with the (original) patch yet, because it uses "unsigned long" for storing pointer and this will *break any 64-bit build* on non-Windows platforms. It would be nice if someone can solve it.

(My only hope is that the MinGW build of QEMU will not be broken...)

Regards,
Filip

Note: with **VirtualProtect or *VirtualProtect make is aborting, I have
used VirtualProtect.
Sorry, my mail client messed that up.
--- qemu/exec.c Sat Sep  4 15:51:23 2004
+++ qemu/exec.c Sat Sep  4 16:12:05 2004
@@ -18,6 +18,9 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 #include "config.h"
+#ifdef _WIN32
+#include <windows.h>
+#endif
 #include <stdlib.h>
 #include <stdio.h>
 #include <stdarg.h>
@@ -127,13 +130,35 @@
 
 static void page_init(void)
 {
+#ifdef _WIN32
+    SYSTEM_INFO system_info;
+    DWORD old_protect;
+#else
+    unsigned long address;
+    unsigned long length;
+#endif
+
     /* NOTE: we can always suppose that qemu_host_page_size >=
        TARGET_PAGE_SIZE */
 #ifdef _WIN32
-    qemu_real_host_page_size = 4096;
+    GetSystemInfo(&system_info);
+    qemu_real_host_page_size = system_info.dwPageSize;
+
+    VirtualProtect(code_gen_buffer, sizeof(code_gen_buffer),
+                   PAGE_EXECUTE_READWRITE, &old_protect);
 #else
     qemu_real_host_page_size = getpagesize();
+
+    address = (unsigned long)code_gen_buffer;
+    address &= ~(qemu_real_host_page_size - 1);
+
+    length = sizeof(code_gen_buffer);
+    length += qemu_real_host_page_size - 1;
+    length &= ~(qemu_real_host_page_size - 1);
+
+    mprotect(address, length, PROT_READ | PROT_WRITE | PROT_EXEC);
 #endif
+
     if (qemu_host_page_size == 0)
         qemu_host_page_size = qemu_real_host_page_size;
     if (qemu_host_page_size < TARGET_PAGE_SIZE)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]