Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.33) id 1C3dHs-0002vs-3Y for qemu-devel@nongnu.org; Sat, 04 Sep 2004 12:21:12 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.33) id 1C3dHr-0002vg-8K for qemu-devel@nongnu.org; Sat, 04 Sep 2004 12:21:11 -0400 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1C3dHr-0002vd-52 for qemu-devel@nongnu.org; Sat, 04 Sep 2004 12:21:11 -0400 Received: from [195.250.128.75] (helo=smtp2.vol.cz) by monty-python.gnu.org with esmtp (TLSv1:DES-CBC3-SHA:168) (Exim 4.34) id 1C3dCd-0005lj-DM for qemu-devel@nongnu.org; Sat, 04 Sep 2004 12:15:47 -0400 Received: from [83.148.10.67] (a6prg-67.dialup.vol.cz [83.148.10.67]) by smtp2.vol.cz (8.12.9p2/8.12.9) with ESMTP id i84GFji8059206 for ; Sat, 4 Sep 2004 18:15:45 +0200 (CEST) (envelope-from xnavara@volny.cz) Message-ID: <4139EA33.5020502@volny.cz> Date: Sat, 04 Sep 2004 18:15:47 +0200 From: Filip Navara MIME-Version: 1.0 Subject: Re: [Qemu-devel] Re: [PATCH] fix interaction with noexecstack References: <20040904000017.GA27986@xi.wantstofly.org> <41399DC2.2030404@bellard.org> <4139B2C3.6000203@volny.cz> In-Reply-To: Content-Type: multipart/mixed; boundary="------------090901080308010904000100" Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org This is a multi-part message in MIME format. --------------090901080308010904000100 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable X-MIME-Autoconverted: from 8bit to quoted-printable by smtp2.vol.cz id i84GFji8059206 Ronald wrote: >Tested, need to include (and ). >gcc juste produce a warning with VirtualProtect: >/home/ronald/Prog/Win32/combo/qemu/exec.c: Dans la fonction =AB page_ini= t =BB: >/home/ronald/Prog/Win32/combo/qemu/exec.c:155: AVERTISSEMENT: passage de >arg 1 de =AB VirtualProtect =BB 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. > =20 > Thanks much for testing it, now I got a minute to test it on my box. The=20 attach patch adds the #include, fixes the warning and also dynamicly=20 detects the page size. These changes are actually needed when running=20 QEMU on WinXP SP2 on AMD64. I'm quite not happy with the (original)=20 patch yet, because it uses "unsigned long" for storing pointer and this=20 will *break any 64-bit build* on non-Windows platforms. It would be nice=20 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. > =20 > Sorry, my mail client messed that up. --------------090901080308010904000100 Content-Type: text/x-patch; name="exec.diff" Content-Disposition: inline; filename="exec.diff" Content-Transfer-Encoding: 7bit --- 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 +#endif #include #include #include @@ -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) --------------090901080308010904000100--