Skip to contentSkip to conversation

[6735] The _exit syscall is used for both thread termination in NPTL applications ,

Qemu-devel Paul Brook 2 participants 2 messages Mar 7, 2009 – Mar 10, 2009

lore
Share & tools
lore

Paul Brook

author
#0 lore raw

Revision: 6735

          http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=6735
Author:   pbrook
Date:     2009-03-07 15:24:59 +0000 (Sat, 07 Mar 2009)

Log Message:
-----------
The _exit syscall is used for both thread termination in NPTL applications, and process termination in legacy applications. Try to guess which we want based on the presence of multiple threads.

Also implement locking when modifying the CPU list.

Modified Paths:
--------------

    trunk/cpu-defs.h
    trunk/exec.c
    trunk/linux-user/main.c
    trunk/linux-user/qemu.h
    trunk/linux-user/signal.c
    trunk/linux-user/syscall.c
    trunk/target-alpha/cpu.h
    trunk/target-arm/cpu.h
    trunk/target-cris/cpu.h
    trunk/target-i386/cpu.h
    trunk/target-m68k/cpu.h
    trunk/target-mips/cpu.h
    trunk/target-ppc/cpu.h
    trunk/target-sh4/cpu.h
    trunk/target-sparc/cpu.h

Modified: trunk/cpu-defs.h
===================================================================

cpu-defs.h +1 -1
@@ -203,7 +203,7 @@
     jmp_buf jmp_env;                                                    \
     int exception_index;                                                \
                                                                         \
-    void *next_cpu; /* next CPU sharing TB cache */                     \
+    CPUState *next_cpu; /* next CPU sharing TB cache */                 \
     int cpu_index; /* CPU index (informative) */                        \
     int running; /* Nonzero if cpu is currently running(usermode).  */  \
     /* user data */                                                     \

Modified: trunk/exec.c
===================================================================

exec.c +6 -0
@@ -534,6 +534,9 @@
     CPUState **penv;
     int cpu_index;
 
+#if defined(CONFIG_USER_ONLY)
+    cpu_list_lock();
+#endif
     env->next_cpu = NULL;
     penv = &first_cpu;
     cpu_index = 0;
@@ -545,6 +548,9 @@
     TAILQ_INIT(&env->breakpoints);
     TAILQ_INIT(&env->watchpoints);
     *penv = env;
+#if defined(CONFIG_USER_ONLY)
+    cpu_list_unlock();
+#endif
 #if defined(CPU_SAVE_VERSION) && !defined(CONFIG_USER_ONLY)
     register_savevm("cpu_common", cpu_index, CPU_COMMON_SAVE_VERSION,
                     cpu_common_save, cpu_common_load, env);

Modified: trunk/linux-user/main.c
===================================================================

linux-user/main.c +20 -0
@@ -143,6 +143,7 @@
    We don't require a full sync, only that no cpus are executing guest code.
    The alternative is to map target atomic ops onto host equivalents,
    which requires quite a lot of per host/target work.  */
+static pthread_mutex_t cpu_list_mutex = PTHREAD_MUTEX_INITIALIZER;
 static pthread_mutex_t exclusive_lock = PTHREAD_MUTEX_INITIALIZER;
 static pthread_cond_t exclusive_cond = PTHREAD_COND_INITIALIZER;
 static pthread_cond_t exclusive_resume = PTHREAD_COND_INITIALIZER;
@@ -165,6 +166,7 @@
         thread_env->next_cpu = NULL;
         pending_cpus = 0;
         pthread_mutex_init(&exclusive_lock, NULL);
+        pthread_mutex_init(&cpu_list_mutex, NULL);
         pthread_cond_init(&exclusive_cond, NULL);
         pthread_cond_init(&exclusive_resume, NULL);
         pthread_mutex_init(&tb_lock, NULL);
@@ -237,6 +239,16 @@
     exclusive_idle();
     pthread_mutex_unlock(&exclusive_lock);
 }
+
+void cpu_list_lock(void)
+{
+    pthread_mutex_lock(&cpu_list_mutex);
+}
+
+void cpu_list_unlock(void)
+{
+    pthread_mutex_unlock(&cpu_list_mutex);
+}
 #else /* if !USE_NPTL */
 /* These are no-ops because we are not threadsafe.  */
 static inline void cpu_exec_start(CPUState *env)
@@ -265,6 +277,14 @@
         gdbserver_fork(thread_env);
     }
 }
+
+void cpu_list_lock(void)
+{
+}
+
+void cpu_list_unlock(void)
+{
+}
 #endif
 
 

Modified: trunk/linux-user/qemu.h
===================================================================

linux-user/qemu.h +5 -0
@@ -100,6 +100,9 @@
     uint32_t v86flags;
     uint32_t v86mask;
 #endif
+#ifdef USE_NPTL
+    abi_ulong child_tidptr;
+#endif
 #ifdef TARGET_M68K
     int sim_syscalls;
 #endif
@@ -225,6 +228,8 @@
 extern unsigned long last_brk;
 void mmap_lock(void);
 void mmap_unlock(void);
+void cpu_list_lock(void);
+void cpu_list_unlock(void);
 #if defined(USE_NPTL)
 void mmap_fork_start(void);
 void mmap_fork_end(int child);

Modified: trunk/linux-user/signal.c
===================================================================

linux-user/signal.c +1 -1
@@ -2691,7 +2691,7 @@
     return err;
 }
 
-static int restore_sigcontext(struct CPUState *regs,
+static int restore_sigcontext(CPUState *regs,
 			      struct target_sigcontext *sc)
 {
     unsigned int err = 0;

Modified: trunk/linux-user/syscall.c
===================================================================

linux-user/syscall.c +43 -6

89 lines not on this page · raw message

Modified: trunk/target-alpha/cpu.h
===================================================================

target-alpha/cpu.h +2 -1
@@ -25,6 +25,8 @@
 
 #define TARGET_LONG_BITS 64
 
+#define CPUState struct CPUAlphaState
+
 #include "cpu-defs.h"
 
 #include <setjmp.h>
@@ -291,7 +293,6 @@
     pal_handler_t *pal_handler;
 };
 
-#define CPUState CPUAlphaState
 #define cpu_init cpu_alpha_init
 #define cpu_exec cpu_alpha_exec
 #define cpu_gen_code cpu_alpha_gen_code

Modified: trunk/target-arm/cpu.h
===================================================================

target-arm/cpu.h +2 -1
@@ -24,6 +24,8 @@
 
 #define ELF_MACHINE	EM_ARM
 
+#define CPUState struct CPUARMState
+
 #include "cpu-defs.h"
 
 #include "softfloat.h"
@@ -398,7 +400,6 @@
 #define TARGET_PAGE_BITS 10
 #endif
 
-#define CPUState CPUARMState
 #define cpu_init cpu_arm_init
 #define cpu_exec cpu_arm_exec
 #define cpu_gen_code cpu_arm_gen_code

Modified: trunk/target-cris/cpu.h
===================================================================

target-cris/cpu.h +2 -1
@@ -23,6 +23,8 @@
 
 #define TARGET_LONG_BITS 32
 
+#define CPUState struct CPUCRISState
+
 #include "cpu-defs.h"
 
 #define TARGET_HAS_ICE 1
@@ -199,7 +201,6 @@
 #define TARGET_PAGE_BITS 13
 #define MMAP_SHIFT TARGET_PAGE_BITS
 
-#define CPUState CPUCRISState
 #define cpu_init cpu_cris_init
 #define cpu_exec cpu_cris_exec
 #define cpu_gen_code cpu_cris_gen_code

Modified: trunk/target-i386/cpu.h
===================================================================

target-i386/cpu.h +2 -1
@@ -42,6 +42,8 @@
 #define ELF_MACHINE	EM_386
 #endif
 
+#define CPUState struct CPUX86State
+
 #include "cpu-defs.h"
 
 #include "softfloat.h"
@@ -828,7 +830,6 @@
 
 #define TARGET_PAGE_BITS 12
 
-#define CPUState CPUX86State
 #define cpu_init cpu_x86_init
 #define cpu_exec cpu_x86_exec
 #define cpu_gen_code cpu_x86_gen_code

Modified: trunk/target-m68k/cpu.h
===================================================================

target-m68k/cpu.h +2 -1
@@ -23,6 +23,8 @@
 
 #define TARGET_LONG_BITS 32
 
+#define CPUState struct CPUM68KState
+
 #include "cpu-defs.h"
 
 #include "softfloat.h"
@@ -207,7 +209,6 @@
 #define TARGET_PAGE_BITS 10
 #endif
 
-#define CPUState CPUM68KState
 #define cpu_init cpu_m68k_init
 #define cpu_exec cpu_m68k_exec
 #define cpu_gen_code cpu_m68k_gen_code

Modified: trunk/target-mips/cpu.h
===================================================================

target-mips/cpu.h +2 -1
@@ -5,6 +5,8 @@
 
 #define ELF_MACHINE	EM_MIPS
 
+#define CPUState struct CPUMIPSState
+
 #include "config.h"
 #include "mips-defs.h"
 #include "cpu-defs.h"
@@ -473,7 +475,6 @@
 void do_unassigned_access(target_phys_addr_t addr, int is_write, int is_exec,
                           int unused, int size);
 
-#define CPUState CPUMIPSState
 #define cpu_init cpu_mips_init
 #define cpu_exec cpu_mips_exec
 #define cpu_gen_code cpu_mips_gen_code

Modified: trunk/target-ppc/cpu.h
===================================================================

target-ppc/cpu.h +2 -1
@@ -54,6 +54,8 @@
 
 #endif /* defined (TARGET_PPC64) */
 
+#define CPUState struct CPUPPCState
+
 #include "cpu-defs.h"
 
 #define REGX "%016" PRIx64
@@ -786,7 +788,6 @@
 int ppc_dcr_read (ppc_dcr_t *dcr_env, int dcrn, target_ulong *valp);
 int ppc_dcr_write (ppc_dcr_t *dcr_env, int dcrn, target_ulong val);
 
-#define CPUState CPUPPCState
 #define cpu_init cpu_ppc_init
 #define cpu_exec cpu_ppc_exec
 #define cpu_gen_code cpu_ppc_gen_code

Modified: trunk/target-sh4/cpu.h
===================================================================

target-sh4/cpu.h +2 -1
@@ -37,6 +37,8 @@
 #define SH_CPU_SH7750_ALL (SH_CPU_SH7750 | SH_CPU_SH7750S | SH_CPU_SH7750R)
 #define SH_CPU_SH7751_ALL (SH_CPU_SH7751 | SH_CPU_SH7751R)
 
+#define CPUState struct CPUSH4State
+
 #include "cpu-defs.h"
 
 #include "softfloat.h"
@@ -169,7 +171,6 @@
 
 #include "softfloat.h"
 
-#define CPUState CPUSH4State
 #define cpu_init cpu_sh4_init
 #define cpu_exec cpu_sh4_exec
 #define cpu_gen_code cpu_sh4_gen_code

Modified: trunk/target-sparc/cpu.h
===================================================================

target-sparc/cpu.h +2 -1
@@ -15,6 +15,8 @@
 
 #define TARGET_PHYS_ADDR_BITS 64
 
+#define CPUState struct CPUSPARCState
+
 #include "cpu-defs.h"
 
 #include "softfloat.h"
@@ -436,7 +438,6 @@
                           int is_asi, int size);
 int cpu_sparc_signal_handler(int host_signum, void *pinfo, void *puc);
 
-#define CPUState CPUSPARCState
 #define cpu_init cpu_sparc_init
 #define cpu_exec cpu_sparc_exec
 #define cpu_gen_code cpu_sparc_gen_code
#1 lore raw
Quoted 11 lines · Paul Brook

Revision: 6735
         http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=6735
Author:   pbrook
Date:     2009-03-07 15:24:59 +0000 (Sat, 07 Mar 2009)
Log Message:
-----------
The _exit syscall is used for both thread termination in NPTL applications, and process termination in legacy applications.  Try to guess which we want based on the presence of multiple threads.

Also implement locking when modifying the CPU list.

This fixes a regression in arm-linux-user, it should be pushed into the stable branch, right?

Signature · 1 line
Felipe Contreras