[4654] Multithreaded locking for mmap().
Revision: 4654
http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=4654 Author: pbrook Date: 2008-06-02 16:16:42 +0000 (Mon, 02 Jun 2008)
Log Message:
-----------
Multithreaded locking for mmap().
Modified Paths:
--------------
trunk/exec.c
trunk/linux-user/mmap.c
trunk/linux-user/qemu.h
Modified: trunk/exec.c
===================================================================
exec.c +19 -1
@@ -234,6 +234,7 @@FILE *f;int n; +mmap_lock (); last_brk = (unsigned long )sbrk (0 ); f =fopen ("/proc/self/maps" ,"r" );if (f) {
@@ -251,6 +252,7 @@ } while (!feof(f));fclose (f); } +mmap_unlock (); }#endif }
@@ -326,6 +328,8 @@static void tlb_protect_code (ram_addr_t ram_addr);static void tlb_unprotect_code_phys (CPUState *env,ram_addr_t ram_addr,target_ulong vaddr); +#define mmap_lock () do { } while(0) +#define mmap_unlock () do { } while(0)#endif #define DEFAULT_CODE_GEN_BUFFER_SIZE (32 * 1024 * 1024)
@@ -1049,6 +1053,9 @@unsigned int h;TranslationBlock **ptb; +/* Grab the mmap lock to stop another thread invalidating this TB +before we are done. */ +mmap_lock ();/* add in the physical hash table */ h =tb_phys_hash_func (phys_pc); ptb = &tb_phys_hash[h];
@@ -1075,6 +1082,7 @@#ifdef DEBUG_TB_CHECK tb_page_check ();#endif +mmap_unlock (); }/* find the TB 'tb' such that tb[0].tc_ptr <= tc_ptr <
@@ -2002,6 +2010,7 @@PageDesc *p;target_ulong addr; +/* mmap_lock should already be held. */ start = start &TARGET_PAGE_MASK ; end =TARGET_PAGE_ALIGN (end);if (flags &PAGE_WRITE )
@@ -2065,11 +2074,18 @@PageDesc *p, *p1;target_ulong host_start, host_end, addr; +/* Technically this isn't safe inside a signal handler. However we +know this only ever happens in a synchronous SEGV handler, so in +practice it seems to be ok. */ +mmap_lock (); + host_start = address & qemu_host_page_mask; page_index = host_start >>TARGET_PAGE_BITS ; p1 =page_find (page_index); -if (!p1) +if (!p1) { +mmap_unlock ();return 0 ; + } host_end = host_start + qemu_host_page_size; p = p1; prot =0 ;
@@ -2091,9 +2107,11 @@#ifdef DEBUG_TB_CHECK tb_invalidate_check (address);#endif +mmap_unlock ();return 1 ; } } +mmap_unlock ();return 0 ; }
Modified: trunk/linux-user/mmap.c
===================================================================
linux-user/mmap.c +73 -27
242 lines not on this page · raw message
Modified: trunk/linux-user/qemu.h
===================================================================
linux-user/qemu.h +6 -0
@@ -233,6 +233,8 @@ abi_ulong new_addr);int target_msync (abi_ulong start,abi_ulong len,int flags);extern unsigned long last_brk; +void mmap_lock (void ); +void mmap_unlock (void );/* user access */
@@ -423,4 +425,8 @@#define unlock_user_struct (host_ptr, guest_addr, copy) \ unlock_user(host_ptr, guest_addr, (copy) ? sizeof(*host_ptr) : 0) +#if defined(USE_NPTL ) +#include <pthread.h> +#endif +#endif /* QEMU_H */