From patchwork Sun May 19 20:36:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 164498 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp4781913ili; Sun, 19 May 2019 13:44:28 -0700 (PDT) X-Google-Smtp-Source: APXvYqxstxWYY6GPvoF+3kVi75XkZYeiryQuS8sHtAF4tLJXOZHuAQ0lQ9/ehkxFoCuFJRojnNTZ X-Received: by 2002:a17:906:8613:: with SMTP id o19mr31111514ejx.126.1558298668601; Sun, 19 May 2019 13:44:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558298668; cv=none; d=google.com; s=arc-20160816; b=O3Bzv6DrxA7QKrErtf76msKXXr6wrVPFHHV51h4lDDoWvQVoH3BVPUjW/U4wNoZ+Yz Ier01nbaJ8PjwBpDSHG2Xzsaak0rcatGc6RBKmB9//EG8lDLnIiD78r8/BiyHQ6he2pG FZxhiPOfJQ2NKKefOM9WFW1+FHLSOxMnGPc+1kJrpOQbDIvxVTHDGAOs1B7DFtdiqMMm 7EvQhb6dbslj+n81l/U56f6icSUcuxwkinE+jS9Gn/avqrVSIabm8QRryTE3gyM4Yo31 ilomU7QkcIKwev+1p9hGfhkJNsLyUcWLu3PAhpoEy43WXbA7dCgA83kQ1p2r2NNbFOHp pH4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=VSlxea5X8kmlG4BCCYdaO6spDVy0J4IfrRmHvvWJsEo=; b=AL1LvW97FP5vw2/3Pl2lQ6ZbcK+q5mI7Yrrc23l5AJeE7sJ7Zldcfc5vgK3SkIVMra JxnjE5vCOUsFK0ImjnNrB12x+GerMosFJZ/QkzxtM+SUKQULoAahNEmDPUDbnMPs5I5m P85xp0XdNv8xsNXMS6XQej5lw6tagpRT7447QVPNs05ReyT1bKoAnF87VHXEvgbP6frp gY2azn3LWT2PMMCcM64n9TK+pDX/XPaA6va7FQZC2rIpFn91KUu83QRWcceVmaYMxziW YjMc1JMxv8LQa8rBbbC9O5JpNvbJtwa+//qCAjkZCPUBzDHHhLv9gDDEU9kKR4iDUDFr +pUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=h9mbQQ3S; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id m18si1150041edm.173.2019.05.19.13.44.28 for (version=TLS1 cipher=AES128-SHA bits=128/128); Sun, 19 May 2019 13:44:28 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=h9mbQQ3S; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1]:53193 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hSSfT-0008Ln-De for patch@linaro.org; Sun, 19 May 2019 16:44:27 -0400 Received: from eggs.gnu.org ([209.51.188.92]:50275) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hSSZ6-000347-6c for qemu-devel@nongnu.org; Sun, 19 May 2019 16:37:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hSSZ4-0003id-PS for qemu-devel@nongnu.org; Sun, 19 May 2019 16:37:52 -0400 Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]:35573) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hSSZ4-0003hq-JB for qemu-devel@nongnu.org; Sun, 19 May 2019 16:37:50 -0400 Received: by mail-pl1-x644.google.com with SMTP id p1so336283plo.2 for ; Sun, 19 May 2019 13:37:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=VSlxea5X8kmlG4BCCYdaO6spDVy0J4IfrRmHvvWJsEo=; b=h9mbQQ3SGTfIiYm6DeVYwSPJhUaB8QQBVG94ifShCK+mh+hBW7yDCIxug4QxQNRwtE 5n4KFaTt2nNUgT6++NfshS0weturRSOcJGQp8c5UHxko9TmrdeEnLbayqooSdX4SPHRi sp2xjIfb3WInVj5vUBSOX7G1YZN8GwSAnaiXImnMHlyn1lyZh/sr1tNKIu7c6TM9Xbjc 8nIRGRtDOLxNoDcfUnaOcCIaEtAwZG7c5SRQBsWkDPFRIR6/EduXcaf8OOdzPP3XPvcc yIgjCScjNkpUWUutc88dU4HtEtp1p3JgdSZXdb47hjE7D+G3QyLVFlPVJOYWBoNGzmLp 5+uQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=VSlxea5X8kmlG4BCCYdaO6spDVy0J4IfrRmHvvWJsEo=; b=ZAh6P6iK1EGuuyYK8ccvnlYLRyAXHcAF615HReNxyLPQTEVsDoXFt7VaGtStiVRpfL g2aV86Q+3z3YZKTASBz0yBPHemEYiCQHJqcdTZJx58e5vFUeWXcUPByrL3qy76EEvlGI 7TYBP7lBbRTrO92WyUEYjs9Y0clCN7wGv/l2JZOMfmRbDFOSFXYKQEH0lfyFxIsGFF1z Ao0fjhithkkiN3RMKNQZE9BtodmZl/8yjXAhJPZKZVVkMEX2q/5SOtGgLoWlKU84t7B7 duHx5kdY7ajKzDp2lH0SMHBtMfBnTi6wUMoJMwwfURDcVW5zPgBB7c3XaJmBGrsf5Zme IiuQ== X-Gm-Message-State: APjAAAVyF6WRKgfPJpZLrJ7tWbBu3SqP+/JHi3xWH8Z62LCXaju/00jL nKBXpK+kXHbReqzq+SZHdBjsV5fT+fM= X-Received: by 2002:a17:902:74c6:: with SMTP id f6mr13664060plt.335.1558298269373; Sun, 19 May 2019 13:37:49 -0700 (PDT) Received: from localhost.localdomain (97-113-13-231.tukw.qwest.net. [97.113.13.231]) by smtp.gmail.com with ESMTPSA id i7sm11397448pfo.19.2019.05.19.13.37.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 19 May 2019 13:37:48 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Sun, 19 May 2019 13:36:27 -0700 Message-Id: <20190519203726.20729-16-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190519203726.20729-1-richard.henderson@linaro.org> References: <20190519203726.20729-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::644 Subject: [Qemu-devel] [PATCH v7 15/74] linux-user: Split out exit X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Richard Henderson --- linux-user/syscall-defs.h | 1 + linux-user/syscall-proc.inc.c | 61 +++++++++++++++++++++++++++++++++++ linux-user/syscall.c | 38 +--------------------- 3 files changed, 63 insertions(+), 37 deletions(-) create mode 100644 linux-user/syscall-proc.inc.c -- 2.17.1 diff --git a/linux-user/syscall-defs.h b/linux-user/syscall-defs.h index 88f433e998..88aa1a6bfd 100644 --- a/linux-user/syscall-defs.h +++ b/linux-user/syscall-defs.h @@ -17,6 +17,7 @@ */ SYSCALL_DEF(close, ARG_DEC); +SYSCALL_DEF(exit, ARG_DEC); #ifdef TARGET_NR_ipc SYSCALL_DEF_ARGS(ipc, ARG_HEX, ARG_DEC, ARG_DEC, ARG_HEX, ARG_PTR, ARG_HEX); #endif diff --git a/linux-user/syscall-proc.inc.c b/linux-user/syscall-proc.inc.c new file mode 100644 index 0000000000..96ad363c1a --- /dev/null +++ b/linux-user/syscall-proc.inc.c @@ -0,0 +1,61 @@ +/* + * Linux process related syscalls + * Copyright (c) 2003 Fabrice Bellard + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + + +SYSCALL_IMPL(exit) +{ + CPUState *cpu = ENV_GET_CPU(cpu_env); + int status = arg1; + + /* + * 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. + */ + if (block_signals()) { + return -TARGET_ERESTARTSYS; + } + + cpu_list_lock(); + + if (CPU_NEXT(first_cpu)) { + TaskState *ts; + + /* Remove the CPU from the list. */ + QTAILQ_REMOVE_RCU(&cpus, cpu, node); + + cpu_list_unlock(); + + ts = cpu->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_cpu = NULL; + object_unref(OBJECT(cpu)); + g_free(ts); + rcu_unregister_thread(); + pthread_exit(NULL); + } + + cpu_list_unlock(); + preexit_cleanup(cpu_env, status); + _exit(status); +} diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 876426dd9c..c72d24aa76 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -5681,43 +5681,6 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, void *p; switch(num) { - case TARGET_NR_exit: - /* 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. */ - - if (block_signals()) { - return -TARGET_ERESTARTSYS; - } - - cpu_list_lock(); - - if (CPU_NEXT(first_cpu)) { - TaskState *ts; - - /* Remove the CPU from the list. */ - QTAILQ_REMOVE_RCU(&cpus, cpu, node); - - cpu_list_unlock(); - - ts = cpu->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_cpu = NULL; - object_unref(OBJECT(cpu)); - g_free(ts); - rcu_unregister_thread(); - pthread_exit(NULL); - } - - cpu_list_unlock(); - preexit_cleanup(cpu_env, arg1); - _exit(arg1); - return 0; /* avoid warning */ case TARGET_NR_brk: return do_brk(arg1); #ifdef TARGET_NR_fork @@ -9975,6 +9938,7 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, #include "syscall-file.inc.c" #include "syscall-ipc.inc.c" #include "syscall-mem.inc.c" +#include "syscall-proc.inc.c" #undef SYSCALL_IMPL #undef SYSCALL_ARGS