From patchwork Fri Jun 29 20:52:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 140647 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp1304935ljj; Fri, 29 Jun 2018 14:02:36 -0700 (PDT) X-Google-Smtp-Source: AAOMgpesKI25j9rAsSM/0eBOV/mVr+pBqn6YB4S6o9w4pQhW+KHX8lk0Ms++fpcl0IL9ZIGh1lvy X-Received: by 2002:ac8:8d3:: with SMTP id y19-v6mr12838389qth.112.1530306155901; Fri, 29 Jun 2018 14:02:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530306155; cv=none; d=google.com; s=arc-20160816; b=QelhtvIbbpNMTH2roMtjFDIDaB91NzKujbNfJlzKSOjEGw1WHmvjzo0vSs/bBocjty fLz4Pmou0BQzeQUqxehEDSeUacG4THRWIlU7NHubJlk+T07JgTC0M+RG1eL9puqAFnSh YJYLFe1YZPtl1Tvv3ZgSwgfi/BLanxRWrYCIIsxpSyZyoao/MuiSQtnFzugYwp6uwftB HIFkmcXNbILKTjRoBxTrzuo3SSmrRLg2Ior0poL9LFqHy38C8tMTkNzp9zc0zWiHYRie /SMLmP3xm7U9FJsLliANpc88VJsYf/5OdsNp5b5Md3BjLNCpqLvz+1jqF29SmrNNwHMr YCzg== 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 :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=zKvfgaXYdJINmHzOqmZqPpLa383uDorjeNqDKhLCuZc=; b=eLoKplgI73EdfFa85kbq7gWZtoZO/sFSmBs3FGLAntWSc+fBH3If6vsmPA3tSkMde7 Xgkq6t8OcfjkbT154D9lN+VAciN8UuGz/wyGxrP8c2NHstFOVtkjcCkefYxWrHAqYQ9r 0FWQPjEvbuTZ5Kk/F6cDhu2jPCMWlsGTISffWzHAhkI0wbdHeIQAQ3kqh2V9914ty4tO Do4H4TIky7oN3KUvRqIZT0kfXGU9X6cxkVns0hDe2jFcPVI0QPHSdRXTegAjJvZAudYk lt3U00aXZjr2yq2M1iRAIWIKCoUjwm0yWanU1QSb5KL6USh3YEINcEPVpNeOol7LK2kN E5gA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="ZShci/lq"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 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. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id u23-v6si3621610qki.144.2018.06.29.14.02.35 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 29 Jun 2018 14:02:35 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="ZShci/lq"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 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 ([::1]:44468 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fZ0XL-0001UC-9s for patch@linaro.org; Fri, 29 Jun 2018 17:02:35 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56292) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fZ0Nv-0008Cu-6m for qemu-devel@nongnu.org; Fri, 29 Jun 2018 16:52:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fZ0Nr-0006Yy-8U for qemu-devel@nongnu.org; Fri, 29 Jun 2018 16:52:51 -0400 Received: from mail-wr0-x242.google.com ([2a00:1450:400c:c0c::242]:37482) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fZ0Nr-0006Xv-1h for qemu-devel@nongnu.org; Fri, 29 Jun 2018 16:52:47 -0400 Received: by mail-wr0-x242.google.com with SMTP id k6-v6so9981879wrp.4 for ; Fri, 29 Jun 2018 13:52:46 -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 :mime-version:content-transfer-encoding; bh=zKvfgaXYdJINmHzOqmZqPpLa383uDorjeNqDKhLCuZc=; b=ZShci/lqTs1MaCgIC4tJ3wwKDPGRXD1e5cZYoFOrCZz5dhvQyH4R6lif7D1i4GG6Uh K1fvpc9dSNihS3kEPGZIqUUrnuzt2kUVlPd+Msab6glIa+7ltkFA/najlDJ3iym0CpcO fy0ZQOSjS5ZVaUFbURxdKKIonwpPeXXv3l2HI= 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:mime-version:content-transfer-encoding; bh=zKvfgaXYdJINmHzOqmZqPpLa383uDorjeNqDKhLCuZc=; b=UKk+Wao+eTudtpkpx46ZdxuJ+R3anu/NZ4Gq5S/Md3fgoRo8NicHiRsKikVUs6vurF 8b/4rJVzCN1njaXDXutQr25GI7Qh7SLwPCxWqbqz2tqyXSmm1+2hFjRIcaHrPmJmiBPe tmmjNl5uAZo9jUey2kgBtKx0Bj1mvRsH9gF8yIMrr/KXE6EU2qmxnHjRCyloTenr3YJE dD9NVQ1XxlL/dIPJdF9FRPUWJTcClO0WKaUgwK8bwDVzRwc1Qworu4VWjyC24iJ+ov4E TE+4dsZtK/ulG05rOjlS1dqQ7NgVz+wE1J3NmOSP+Jz4mIl9Be7xCY6yeHqgHqd7X1rs EVOg== X-Gm-Message-State: APt69E2XY9ps01xpvny0aEMNsiZ0GEmvLskeyGRsrZdnTPJhbHle+Jvg yfdynJ7QGgRmVUtQ+hq7zhLlQg== X-Received: by 2002:adf:f002:: with SMTP id j2-v6mr3880118wro.260.1530305565840; Fri, 29 Jun 2018 13:52:45 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id a17-v6sm7419253wrr.81.2018.06.29.13.52.36 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 29 Jun 2018 13:52:40 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 7F79B3E075D; Fri, 29 Jun 2018 21:52:33 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: cota@braap.org, famz@redhat.com, berrange@redhat.com, f4bug@amsat.org, richard.henderson@linaro.org, balrogg@gmail.com, aurelien@aurel32.net, agraf@suse.de Date: Fri, 29 Jun 2018 21:52:20 +0100 Message-Id: <20180629205232.27190-10-alex.bennee@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180629205232.27190-1-alex.bennee@linaro.org> References: <20180629205232.27190-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::242 Subject: [Qemu-devel] [PATCH v2 09/21] linux-user: introduce preexit_cleanup 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: pbonzini@redhat.com, Riku Voipio , =?utf-8?q?Alex_?= =?utf-8?q?Benn=C3=A9e?= , qemu-devel@nongnu.org, Laurent Vivier Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" To avoid repeating ourselves move our preexit clean-up code into a helper function. I figured the continuing effort to split of the syscalls made it worthwhile creating a new file for it now. Signed-off-by: Alex Bennée Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Daniel P. Berrangé Reviewed-by: Laurent Vivier --- linux-user/Makefile.objs | 2 +- linux-user/exit.c | 28 ++++++++++++++++++++++++++++ linux-user/qemu.h | 8 ++++++++ linux-user/syscall.c | 10 ++-------- 4 files changed, 39 insertions(+), 9 deletions(-) create mode 100644 linux-user/exit.c -- 2.17.1 diff --git a/linux-user/Makefile.objs b/linux-user/Makefile.objs index 59a5c17354..b5dfb71f25 100644 --- a/linux-user/Makefile.objs +++ b/linux-user/Makefile.objs @@ -1,7 +1,7 @@ obj-y = main.o syscall.o strace.o mmap.o signal.o \ elfload.o linuxload.o uaccess.o uname.o \ safe-syscall.o $(TARGET_ABI_DIR)/signal.o \ - $(TARGET_ABI_DIR)/cpu_loop.o + $(TARGET_ABI_DIR)/cpu_loop.o exit.o obj-$(TARGET_HAS_BFLT) += flatload.o obj-$(TARGET_I386) += vm86.o diff --git a/linux-user/exit.c b/linux-user/exit.c new file mode 100644 index 0000000000..aed8713fae --- /dev/null +++ b/linux-user/exit.c @@ -0,0 +1,28 @@ +/* + * exit support for qemu + * + * Copyright (c) 2018 Alex Bennée + * + * 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 . + */ +#include "qemu/osdep.h" +#include "qemu.h" + +void preexit_cleanup(CPUArchState *env, int code) +{ +#ifdef TARGET_GPROF + _mcleanup(); +#endif + gdb_exit(env, code); +} diff --git a/linux-user/qemu.h b/linux-user/qemu.h index 793cd4df04..bb85c81aa4 100644 --- a/linux-user/qemu.h +++ b/linux-user/qemu.h @@ -623,6 +623,14 @@ static inline int is_error(abi_long ret) return (abi_ulong)ret >= (abi_ulong)(-4096); } +/** + * preexit_cleanup: housekeeping before the guest exits + * + * env: the CPU state + * code: the exit code + */ +void preexit_cleanup(CPUArchState *env, int code); + /* Include target-specific struct and function definitions; * they may need access to the target-independent structures * above, so include them last. diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 2117fb13b4..7c66442357 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -8018,10 +8018,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, } cpu_list_unlock(); -#ifdef TARGET_GPROF - _mcleanup(); -#endif - gdb_exit(cpu_env, arg1); + preexit_cleanup(cpu_env, arg1); _exit(arg1); ret = 0; /* avoid warning */ break; @@ -10127,10 +10124,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, #ifdef __NR_exit_group /* new thread calls */ case TARGET_NR_exit_group: -#ifdef TARGET_GPROF - _mcleanup(); -#endif - gdb_exit(cpu_env, arg1); + preexit_cleanup(cpu_env, arg1); ret = get_errno(exit_group(arg1)); break; #endif