Commit 4369415f1e62eff10201f20c984e02490c846046

Authored by bellard
1 parent fbb4a2e3

keep static code gen buffer for user mode - mark user mode reserved pages after all big allocations

git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@4611 c046a42c-6fe2-441c-8c8c-71466251a162
Showing 1 changed file with 29 additions and 5 deletions
... ... @@ -187,14 +187,15 @@ static void map_exec(void *addr, long size)
187 187 #else
188 188 static void map_exec(void *addr, long size)
189 189 {
190   - unsigned long start, end;
  190 + unsigned long start, end, page_size;
191 191  
  192 + page_size = getpagesize();
192 193 start = (unsigned long)addr;
193   - start &= ~(qemu_real_host_page_size - 1);
  194 + start &= ~(page_size - 1);
194 195  
195 196 end = (unsigned long)addr + size;
196   - end += qemu_real_host_page_size - 1;
197   - end &= ~(qemu_real_host_page_size - 1);
  197 + end += page_size - 1;
  198 + end &= ~(page_size - 1);
198 199  
199 200 mprotect((void *)start, end - start,
200 201 PROT_READ | PROT_WRITE | PROT_EXEC);
... ... @@ -326,12 +327,34 @@ static void tlb_unprotect_code_phys(CPUState *env, ram_addr_t ram_addr,
326 327 target_ulong vaddr);
327 328 #endif
328 329  
  330 +#define DEFAULT_CODE_GEN_BUFFER_SIZE (32 * 1024 * 1024)
  331 +
  332 +#if defined(CONFIG_USER_ONLY)
  333 +/* Currently it is not recommanded to allocate big chunks of data in
  334 + user mode. It will change when a dedicated libc will be used */
  335 +#define USE_STATIC_CODE_GEN_BUFFER
  336 +#endif
  337 +
  338 +#ifdef USE_STATIC_CODE_GEN_BUFFER
  339 +static uint8_t static_code_gen_buffer[DEFAULT_CODE_GEN_BUFFER_SIZE];
  340 +#endif
  341 +
329 342 void code_gen_alloc(unsigned long tb_size)
330 343 {
  344 +#ifdef USE_STATIC_CODE_GEN_BUFFER
  345 + code_gen_buffer = static_code_gen_buffer;
  346 + code_gen_buffer_size = DEFAULT_CODE_GEN_BUFFER_SIZE;
  347 + map_exec(code_gen_buffer, code_gen_buffer_size);
  348 +#else
331 349 code_gen_buffer_size = tb_size;
332 350 if (code_gen_buffer_size == 0) {
  351 +#if defined(CONFIG_USER_ONLY)
  352 + /* in user mode, phys_ram_size is not meaningful */
  353 + code_gen_buffer_size = DEFAULT_CODE_GEN_BUFFER_SIZE;
  354 +#else
333 355 /* XXX: needs ajustments */
334 356 code_gen_buffer_size = (int)(phys_ram_size / 4);
  357 +#endif
335 358 }
336 359 if (code_gen_buffer_size < MIN_CODE_GEN_BUFFER_SIZE)
337 360 code_gen_buffer_size = MIN_CODE_GEN_BUFFER_SIZE;
... ... @@ -363,6 +386,7 @@ void code_gen_alloc(unsigned long tb_size)
363 386 }
364 387 map_exec(code_gen_buffer, code_gen_buffer_size);
365 388 #endif
  389 +#endif /* !USE_STATIC_CODE_GEN_BUFFER */
366 390 map_exec(code_gen_prologue, sizeof(code_gen_prologue));
367 391 code_gen_buffer_max_size = code_gen_buffer_size -
368 392 code_gen_max_block_size();
... ... @@ -375,10 +399,10 @@ void code_gen_alloc(unsigned long tb_size)
375 399 size. */
376 400 void cpu_exec_init_all(unsigned long tb_size)
377 401 {
378   - page_init();
379 402 cpu_gen_init();
380 403 code_gen_alloc(tb_size);
381 404 code_gen_ptr = code_gen_buffer;
  405 + page_init();
382 406 io_mem_init();
383 407 }
384 408  
... ...