Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1K2U1k-0007Wr-Cp for qemu-devel@nongnu.org; Sat, 31 May 2008 12:33:56 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1K2U1j-0007Wd-T3 for qemu-devel@nongnu.org; Sat, 31 May 2008 12:33:56 -0400 Received: from [199.232.76.173] (port=35889 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1K2U1j-0007WY-NS for qemu-devel@nongnu.org; Sat, 31 May 2008 12:33:55 -0400 Received: from savannah.gnu.org ([199.232.41.3]:36098 helo=sv.gnu.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1K2U1j-0002vP-7B for qemu-devel@nongnu.org; Sat, 31 May 2008 12:33:55 -0400 Received: from cvs.savannah.gnu.org ([199.232.41.69]) by sv.gnu.org with esmtp (Exim 4.63) (envelope-from ) id 1K2U1i-000811-GO for qemu-devel@nongnu.org; Sat, 31 May 2008 16:33:54 +0000 Received: from pbrook by cvs.savannah.gnu.org with local (Exim 4.63) (envelope-from ) id 1K2U1i-00080x-8G for qemu-devel@nongnu.org; Sat, 31 May 2008 16:33:54 +0000 MIME-Version: 1.0 Errors-To: pbrook Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Paul Brook Message-Id: Date: Sat, 31 May 2008 16:33:54 +0000 Subject: [Qemu-devel] [4637] Mark host brk() area as reserved. 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 Revision: 4637 http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=4637 Author: pbrook Date: 2008-05-31 16:33:53 +0000 (Sat, 31 May 2008) Log Message: ----------- Mark host brk() area as reserved. Modified Paths: -------------- trunk/exec.c trunk/linux-user/mmap.c trunk/linux-user/qemu.h Modified: trunk/exec.c =================================================================== --- trunk/exec.c 2008-05-31 16:21:33 UTC (rev 4636) +++ trunk/exec.c 2008-05-31 16:33:53 UTC (rev 4637) @@ -234,6 +234,7 @@ FILE *f; int n; + last_brk = (unsigned long)sbrk(0); f = fopen("/proc/self/maps", "r"); if (f) { do { Modified: trunk/linux-user/mmap.c =================================================================== --- trunk/linux-user/mmap.c 2008-05-31 16:21:33 UTC (rev 4636) +++ trunk/linux-user/mmap.c 2008-05-31 16:33:53 UTC (rev 4637) @@ -157,6 +157,8 @@ static abi_ulong mmap_next_start = 0x40000000; #endif +unsigned long last_brk; + /* find a free memory area of size 'size'. The search starts at 'start'. If 'start' == 0, then a default start address is used. Return -1 if error. @@ -167,7 +169,21 @@ { abi_ulong addr, addr1, addr_start; int prot; + unsigned long new_brk; + new_brk = (unsigned long)sbrk(0); + if (last_brk && last_brk < new_brk && last_brk == (target_ulong)last_brk) { + /* This is a hack to catch the host allocating memory with brk(). + If it uses mmap then we loose. + FIXME: We really want to avoid the host allocating memory in + the first place, and maybe leave some slack to avoid switching + to mmap. */ + page_set_flags(last_brk & TARGET_PAGE_MASK, + TARGET_PAGE_ALIGN(new_brk), + PAGE_RESERVED); + } + last_brk = new_brk; + size = HOST_PAGE_ALIGN(size); start = start & qemu_host_page_mask; addr = start; Modified: trunk/linux-user/qemu.h =================================================================== --- trunk/linux-user/qemu.h 2008-05-31 16:21:33 UTC (rev 4636) +++ trunk/linux-user/qemu.h 2008-05-31 16:33:53 UTC (rev 4637) @@ -232,6 +232,7 @@ abi_ulong new_size, unsigned long flags, abi_ulong new_addr); int target_msync(abi_ulong start, abi_ulong len, int flags); +extern unsigned long last_brk; /* user access */