From patchwork Fri Jan 18 21:30:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 156060 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp3734200jaa; Fri, 18 Jan 2019 13:41:29 -0800 (PST) X-Google-Smtp-Source: ALg8bN5Rg5d/zYcskKowt6hXgeK+PvRr+wQTbKabQbNpXuw+GfboibTSCD7SJAdIEk6Sb2Rcc3A5 X-Received: by 2002:adf:fc89:: with SMTP id g9mr17702075wrr.96.1547847689090; Fri, 18 Jan 2019 13:41:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547847689; cv=none; d=google.com; s=arc-20160816; b=HyTbf2pdFmymhTdSM32s+j29V6k3pxNVYEASWrqDEbUbnar1t9YGAtc1UmgVv4QOxO H/gT2bPoLRgwwINkmN0BJf4WAv/HGpTnqEPV4ruwSLMGuoXO94eXgHsc65XPejFS+Fac KcsY3qc7szDkdW1dtMjZb0H6HkbgSAmJSjGdzRDUcxDIiNk3aOUq1hM4FbM4wvXf9BcE DMMGNbCG2Fzo9hiaQd+KYDDtmqBSiXsNz8CQA/vAm4ya5Ivbms+dbhpnP+QAlxShV7Ci ygRh96tvS4Fc3asFdDnyQo/U70Jd1D5V68isqG9Feqe/MwqVLwPSuYo6Gw8uIe7v2Qy/ wNdA== 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=IEs81U6tUCmwElYln5xMlJL31vkwoJDM0cxjxPoE4mA=; b=Orjxf49fcwGHZia+eWDBck5PUbScayuYWd0Nqj1aoktWFgz+84K6Nbh4nStLtBWINR amBRiMItinSfgEROUrGEVSWNloPqiSWaY2xmg+sgS0KNnW03eIz4xpuZlyMsRwd02ZQF qZo3jrDtZtJEKEzIVwhDwSc1t9NVCkKiM7nTN5svCK01kjCmN8lrqeeb4Nv2cRdXXH7U jju2yGSXCGflNDBPsROItoq1yPzdg0Xn6C1SbXAwc51zNiKF4yWw8YrhcNtlkhWmPOOU YRQ9gdUuUAN4kxCgFjkmErGGbX7itdlMx6O53NIRIAzq+zCnPSDrjaln5RucKijvoX2H F05Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Dw9pimRz; 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 v10si27826737wrm.125.2019.01.18.13.41.28 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 18 Jan 2019 13:41:29 -0800 (PST) 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=Dw9pimRz; 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]:47522 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gkbtH-00048l-Vp for patch@linaro.org; Fri, 18 Jan 2019 16:41:28 -0500 Received: from eggs.gnu.org ([209.51.188.92]:55911) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gkbkF-00053A-Nh for qemu-devel@nongnu.org; Fri, 18 Jan 2019 16:32:11 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gkbkE-0004W1-N4 for qemu-devel@nongnu.org; Fri, 18 Jan 2019 16:32:07 -0500 Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]:44425) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gkbkE-0004VE-HH for qemu-devel@nongnu.org; Fri, 18 Jan 2019 16:32:06 -0500 Received: by mail-pf1-x443.google.com with SMTP id u6so7187532pfh.11 for ; Fri, 18 Jan 2019 13:32:06 -0800 (PST) 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=IEs81U6tUCmwElYln5xMlJL31vkwoJDM0cxjxPoE4mA=; b=Dw9pimRzOCnCIj7bLqPuvsGtiN/9tg7qfN1Bq7d0FarjImv4mVIZamJ4zlNVR2soBW hmCMtbP3lRSRj4gFa0Y5ZcBDc2zouR8jOui67zMXobaMv+mMsD/0ArJXwwqCNGapzj5k euteBlCnbQElLZ8J+m6jCHlHgmKVwwnhrUvoY= 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=IEs81U6tUCmwElYln5xMlJL31vkwoJDM0cxjxPoE4mA=; b=Uv7HJNC8gobSFh2/Kscwj5lgUyz/sOhQqmGF4xt2nzvEshrJgKWTXTuMRZ6FbHZvX2 CQpvMi+mJI130RSRHRW/LgbeWa6N8rp1N2p0jz98THugKzI5yzPHxv158UNYj3BeVOjG 5asz+2KhzjkAJskHjh3LzIiBHL0yCqIocSXXd+VdEyir7qbVcreP+Ku4CcR4C/7eEblT C2taJiF4J4IFLS2kl2pgojdUC3SB+sl1S+ZKgIC0tmUeo4uhJLAQHSLmX0QTRR/I4fTo tcnwx3FyJEz1L5biRWEl/3Bb7f0P5mbmmvFSZ9oqGvA4oKKEwtZwmC50mfQnjkJkhj/d QZnA== X-Gm-Message-State: AJcUukf4cD1mYGxodczdqK0j+f4zCCfjUWlDM686U/+UDh3fttQUSSxq 8MeV5ySapsflrWj1LpdswogqewoQ8mM= X-Received: by 2002:a62:6408:: with SMTP id y8mr20802491pfb.202.1547847125269; Fri, 18 Jan 2019 13:32:05 -0800 (PST) Received: from cloudburst.twiddle.net ([2001:8000:10e0:a000:c673:a6b6:fdef:1933]) by smtp.gmail.com with ESMTPSA id v12sm5833667pgg.41.2019.01.18.13.32.03 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 18 Jan 2019 13:32:04 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Sat, 19 Jan 2019 08:30:49 +1100 Message-Id: <20190118213122.22865-16-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190118213122.22865-1-richard.henderson@linaro.org> References: <20190118213122.22865-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::443 Subject: [Qemu-devel] [PATCH v6 16/49] 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.2 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 142654a0a0..02010f9ae0 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -5626,43 +5626,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 @@ -9884,6 +9847,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