From patchwork Thu Jul 5 16:03:19 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: 141192 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2125409ljj; Thu, 5 Jul 2018 09:12:14 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcWznWF2YLDxj/O8Awbuw0J3chsB0gwN7bVXJ9lXzJCD9kavkdYjzr9t8EuUDmr4e9DtPMU X-Received: by 2002:a37:65d8:: with SMTP id z207-v6mr5314863qkb.81.1530807134441; Thu, 05 Jul 2018 09:12:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530807134; cv=none; d=google.com; s=arc-20160816; b=0+hiwrITJQ0ESxlE5x3G0QRgZHyICNl6yrY8Ue6u9h4qWfvW9zsDboOGmlFDHXlgkR AHx9lT88s+JP97Qj+37jEZlsrrRCk8tnhNX/2YYnAQLhvTt7aujrzFwrIeiihsdm1+j4 JVf1/ksY3n8Yr+TUivELow9fl9rFM5qfaMR7qttABDOuisJfQJaTH/fjooZxlY7TAunF chWvYEpGWIFBvTknEOlikNPrHAB54OuM7YYLZRz5QmmhHpBMGrBOHwc4QUwXOzEzXe5k emB7Av2Z6TCk+eE3SwAMk7DjOs0NYfqUekKpj1zs2Rj/dRf5M59gxtP8dPU1dYvCR+0P ailA== 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=7lUnldhhTj3qPr3tQFlZRzfuhm3U44xJ124drmSuK44=; b=TYGexee23E7IXdn2RvH2/tbk0/ly6dvUBVuHuFZreZyldqeSE9BLJ/4cRX9j6+WrX/ y2N1Z3Okiz+NR6OiRmCttDBwH1M/J73vnKi8IvrhILqeayLDMNK2X9E7JhkUqP1Lkck6 BSXDHEfExVp9ANUdVIe2cz39lgF/MvoBkutZBc97icHr67GtkVo+ZoJ4QHIDbvSsTvqD uoD/QzP4rdufSfBLxdIOW2y8kM67k7fnfAA+InS00/N3JwLEDoyOcQh5SIeq1yZyWuVt T/GTB1dHVP7uPH2KAoSPN27m94RXYjOORCPJas1W8eRK86VS1qm0jL1gXq4SHd1DUF2Y FDPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=dqwDqhWo; 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 q3-v6si2573434qtc.166.2018.07.05.09.12.14 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 05 Jul 2018 09:12:14 -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=dqwDqhWo; 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]:53546 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fb6rd-0006yp-TR for patch@linaro.org; Thu, 05 Jul 2018 12:12:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54907) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fb6jQ-0008Qf-Ow for qemu-devel@nongnu.org; Thu, 05 Jul 2018 12:03:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fb6jO-00082Y-5X for qemu-devel@nongnu.org; Thu, 05 Jul 2018 12:03:44 -0400 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]:50631) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fb6jN-000824-Vk for qemu-devel@nongnu.org; Thu, 05 Jul 2018 12:03:42 -0400 Received: by mail-wm0-x241.google.com with SMTP id v25-v6so12157167wmc.0 for ; Thu, 05 Jul 2018 09:03:41 -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=7lUnldhhTj3qPr3tQFlZRzfuhm3U44xJ124drmSuK44=; b=dqwDqhWoD6kPvrAYQFOjmEPfPLLqDpjgHjMBjCFqt7vw9KtC8oqAk0TfBwMR0PAlmk EDyjGLP49WVPK8FF7sGQKD/AjU7PR62mhcOBWi4L3VKGZdfN6/+oPAciRitW/6OUGSkX u78OQTMOIzMs6PkZ+ptICzXsTrE4qArkFTpL0= 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=7lUnldhhTj3qPr3tQFlZRzfuhm3U44xJ124drmSuK44=; b=h9PGzDkDxFCcI5Z9UeUsXBkV4R3s+4vVEiyhgRTHVprDwxxhLmbsxl4noVel2mDOIy /G2amKSy31S0VsFyofEDkNf1WUfj74uBA6Zaa0htqYqguYYjEsksbNkkYNCsmS0wxT1C Cdfk+r40yqTKEYXWSv+DdV4r9CusNrBB+FtQDo35le8nqVMc58s+49pnn5z7h/5/SCnU 06CygDmQWWVsPvlL2+jJkz8feLJXdngI8B44iEI/Xn3SgaFyZXDKWLE6eUTBrh5Ap7Vb TaVtIsy22Uk1wHQdNeLyVmjZFrZXlKhM+UZ4KgihIkg9hdI8rfAjiUiEZgmbJi6xJI8v PFwQ== X-Gm-Message-State: APt69E2TSUVlR5I7cQ60RXFHUgBemORKLcutvOaMRnAIrxYY4AvnsUs6 eqxu/mOivyFJYMqKS+OD0LIhJg== X-Received: by 2002:a1c:149:: with SMTP id 70-v6mr4790967wmb.2.1530806620869; Thu, 05 Jul 2018 09:03:40 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id x12-v6sm11224506wre.27.2018.07.05.09.03.32 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 05 Jul 2018 09:03:37 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 274623E0B46; Thu, 5 Jul 2018 17:03:30 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: peter.maydell@linaro.org Date: Thu, 5 Jul 2018 17:03:19 +0100 Message-Id: <20180705160329.30386-11-alex.bennee@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180705160329.30386-1-alex.bennee@linaro.org> References: <20180705160329.30386-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:c09::241 Subject: [Qemu-devel] [PULL v3 10/20] 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: Riku Voipio , =?utf-8?q?Alex_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 -- 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 50e20fb659..5822e03e28 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -8022,10 +8022,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; @@ -10131,10 +10128,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