Commit 0776590d70565df4165b328f3cb80d29d21d52a5

Authored by pbrook
1 parent 1090e7a2

Mark host brk() area as reserved.


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@4637 c046a42c-6fe2-441c-8c8c-71466251a162
@@ -234,6 +234,7 @@ static void page_init(void) @@ -234,6 +234,7 @@ static void page_init(void)
234 FILE *f; 234 FILE *f;
235 int n; 235 int n;
236 236
  237 + last_brk = (unsigned long)sbrk(0);
237 f = fopen("/proc/self/maps", "r"); 238 f = fopen("/proc/self/maps", "r");
238 if (f) { 239 if (f) {
239 do { 240 do {
linux-user/mmap.c
@@ -157,6 +157,8 @@ static abi_ulong mmap_next_start = 0x18000000; @@ -157,6 +157,8 @@ static abi_ulong mmap_next_start = 0x18000000;
157 static abi_ulong mmap_next_start = 0x40000000; 157 static abi_ulong mmap_next_start = 0x40000000;
158 #endif 158 #endif
159 159
  160 +unsigned long last_brk;
  161 +
160 /* find a free memory area of size 'size'. The search starts at 162 /* find a free memory area of size 'size'. The search starts at
161 'start'. If 'start' == 0, then a default start address is used. 163 'start'. If 'start' == 0, then a default start address is used.
162 Return -1 if error. 164 Return -1 if error.
@@ -167,6 +169,20 @@ static abi_ulong mmap_find_vma(abi_ulong start, abi_ulong size) @@ -167,6 +169,20 @@ static abi_ulong mmap_find_vma(abi_ulong start, abi_ulong size)
167 { 169 {
168 abi_ulong addr, addr1, addr_start; 170 abi_ulong addr, addr1, addr_start;
169 int prot; 171 int prot;
  172 + unsigned long new_brk;
  173 +
  174 + new_brk = (unsigned long)sbrk(0);
  175 + if (last_brk && last_brk < new_brk && last_brk == (target_ulong)last_brk) {
  176 + /* This is a hack to catch the host allocating memory with brk().
  177 + If it uses mmap then we loose.
  178 + FIXME: We really want to avoid the host allocating memory in
  179 + the first place, and maybe leave some slack to avoid switching
  180 + to mmap. */
  181 + page_set_flags(last_brk & TARGET_PAGE_MASK,
  182 + TARGET_PAGE_ALIGN(new_brk),
  183 + PAGE_RESERVED);
  184 + }
  185 + last_brk = new_brk;
170 186
171 size = HOST_PAGE_ALIGN(size); 187 size = HOST_PAGE_ALIGN(size);
172 start = start & qemu_host_page_mask; 188 start = start & qemu_host_page_mask;
linux-user/qemu.h
@@ -232,6 +232,7 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size, @@ -232,6 +232,7 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size,
232 abi_ulong new_size, unsigned long flags, 232 abi_ulong new_size, unsigned long flags,
233 abi_ulong new_addr); 233 abi_ulong new_addr);
234 int target_msync(abi_ulong start, abi_ulong len, int flags); 234 int target_msync(abi_ulong start, abi_ulong len, int flags);
  235 +extern unsigned long last_brk;
235 236
236 /* user access */ 237 /* user access */
237 238