From patchwork Fri Oct 12 18:24:38 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Riku Voipio X-Patchwork-Id: 191175 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 24A052C0083 for ; Sat, 13 Oct 2012 05:32:56 +1100 (EST) Received: from localhost ([::1]:49222 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TMjvL-0004Ih-BH for incoming@patchwork.ozlabs.org; Fri, 12 Oct 2012 14:25:27 -0400 Received: from eggs.gnu.org ([208.118.235.92]:51060) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TMjui-0002mG-UL for qemu-devel@nongnu.org; Fri, 12 Oct 2012 14:24:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TMjue-0006LI-Sw for qemu-devel@nongnu.org; Fri, 12 Oct 2012 14:24:48 -0400 Received: from afflict.kos.to ([92.243.29.197]:33084) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TMjue-0006KX-I7 for qemu-devel@nongnu.org; Fri, 12 Oct 2012 14:24:44 -0400 Received: by afflict.kos.to (Postfix, from userid 1000) id 5AAC9264C3; Fri, 12 Oct 2012 20:24:42 +0200 (CEST) From: riku.voipio@linaro.org To: qemu-devel@nongnu.org Date: Fri, 12 Oct 2012 21:24:38 +0300 Message-Id: <266abe097ce7b655bd1605d190188e8653a71b56.1350063473.git.riku.voipio@linaro.org> X-Mailer: git-send-email 1.7.2.5 In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 92.243.29.197 Cc: Riku Voipio Subject: [Qemu-devel] [PATCH 1/5] linux-user: move exit to own function X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Riku Voipio In preparations for for refactoring the main switch/case out Signed-off-by: Riku Voipio --- linux-user/syscall.c | 92 ++++++++++++++++++++++++++------------------------ 1 file changed, 48 insertions(+), 44 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 471d060..0b077e7 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -5083,6 +5083,53 @@ static int do_open(void *cpu_env, const char *pathname, int flags, mode_t mode) return get_errno(open(path(pathname), flags, mode)); } +static void do_exit(void *, abi_long) __attribute__ ((noreturn)); +static void do_exit(void *cpu_env, abi_long arg1) +{ +#ifdef CONFIG_USE_NPTL + /* In old applications this may be used to implement _exit(2). + However in threaded applictions it is used for thread termination, + and _exit_group is used for application termination. + Do thread termination if we have more then one thread. */ + /* FIXME: This probably breaks if a signal arrives. We should probably + be disabling signals. */ + if (first_cpu->next_cpu) { + TaskState *ts; + CPUArchState **lastp; + CPUArchState *p; + + cpu_list_lock(); + lastp = &first_cpu; + p = first_cpu; + while (p && p != (CPUArchState *)cpu_env) { + lastp = &p->next_cpu; + p = p->next_cpu; + } + /* If we didn't find the CPU for this thread then something is + horribly wrong. */ + if (!p) + abort(); + /* Remove the CPU from the list. */ + *lastp = p->next_cpu; + cpu_list_unlock(); + ts = ((CPUArchState *)cpu_env)->opaque; + if (ts->child_tidptr) { + put_user_u32(0, ts->child_tidptr); + sys_futex(g2h(ts->child_tidptr), FUTEX_WAKE, INT_MAX, + NULL, NULL, 0); + } + thread_env = NULL; + object_delete(OBJECT(ENV_GET_CPU(cpu_env))); + g_free(ts); + pthread_exit(NULL); + } +#endif +#ifdef TARGET_GPROF + _mcleanup(); +#endif + gdb_exit(cpu_env, arg1); + _exit(arg1); +} /* do_syscall() should always have a single exit point at the end so that actions, such as logging of syscall results, can be performed. @@ -5105,50 +5152,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, switch(num) { case TARGET_NR_exit: -#ifdef CONFIG_USE_NPTL - /* In old applications this may be used to implement _exit(2). - However in threaded applictions it is used for thread termination, - and _exit_group is used for application termination. - Do thread termination if we have more then one thread. */ - /* FIXME: This probably breaks if a signal arrives. We should probably - be disabling signals. */ - if (first_cpu->next_cpu) { - TaskState *ts; - CPUArchState **lastp; - CPUArchState *p; - - cpu_list_lock(); - lastp = &first_cpu; - p = first_cpu; - while (p && p != (CPUArchState *)cpu_env) { - lastp = &p->next_cpu; - p = p->next_cpu; - } - /* If we didn't find the CPU for this thread then something is - horribly wrong. */ - if (!p) - abort(); - /* Remove the CPU from the list. */ - *lastp = p->next_cpu; - cpu_list_unlock(); - ts = ((CPUArchState *)cpu_env)->opaque; - if (ts->child_tidptr) { - put_user_u32(0, ts->child_tidptr); - sys_futex(g2h(ts->child_tidptr), FUTEX_WAKE, INT_MAX, - NULL, NULL, 0); - } - thread_env = NULL; - object_delete(OBJECT(ENV_GET_CPU(cpu_env))); - g_free(ts); - pthread_exit(NULL); - } -#endif -#ifdef TARGET_GPROF - _mcleanup(); -#endif - gdb_exit(cpu_env, arg1); - _exit(arg1); - ret = 0; /* avoid warning */ + do_exit(cpu_env, arg1); break; case TARGET_NR_read: if (arg3 == 0)